| … | … | @@ -1,29 +1,3073 @@ |
| 1 | | /* esm.sh - esbuild bundle(@jsr/std__yaml@1.0.5) es2022 production */ |
| 2 | | function m(e){return e===10||e===13}function E(e){return e===9||e===32}function g(e){return E(e)||m(e)}function y(e){return e===44||e===91||e===93||e===123||e===125}var W=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= |
| 3 | | \r`;function Zt(e){if(e===null)return!1;let t,i=0,n=e.length,r=W;for(let s=0;s<n;s++)if(t=r.indexOf(e.charAt(s)),!(t>64)){if(t<0)return!1;i+=6}return i%8===0}function Jt(e){let t=e.replace(/[\r\n=]/g,""),i=t.length,n=W,r=[],s=0;for(let l=0;l<i;l++)l%4===0&&l&&(r.push(s>>16&255),r.push(s>>8&255),r.push(s&255)),s=s<<6|n.indexOf(t.charAt(l));let o=i%4*6;return o===0?(r.push(s>>16&255),r.push(s>>8&255),r.push(s&255)):o===18?(r.push(s>>10&255),r.push(s>>2&255)):o===12&&r.push(s>>4&255),new Uint8Array(r)}function te(e){let t=e.length,i=W,n="",r=0;for(let o=0;o<t;o++)o%3===0&&o&&(n+=i[r>>18&63],n+=i[r>>12&63],n+=i[r>>6&63],n+=i[r&63]),r=(r<<8)+e[o];let s=t%3;return s===0?(n+=i[r>>18&63],n+=i[r>>12&63],n+=i[r>>6&63],n+=i[r&63]):s===2?(n+=i[r>>10&63],n+=i[r>>4&63],n+=i[r<<2&63],n+=i[64]):s===1&&(n+=i[r>>2&63],n+=i[r<<4&63],n+=i[64],n+=i[64]),n}function ee(e){return e instanceof Uint8Array}var rt={tag:"tag:yaml.org,2002:binary",construct:Jt,kind:"scalar",predicate:ee,represent:te,resolve:Zt};var nt=["true","True","TRUE"],ie=["false","False","FALSE"],re=[...nt,...ie],st={tag:"tag:yaml.org,2002:bool",kind:"scalar",defaultStyle:"lowercase",predicate:e=>typeof e=="boolean"||e instanceof Boolean,construct:e=>nt.includes(e),resolve:e=>re.includes(e),represent:{lowercase:e=>(e instanceof Boolean?e.valueOf():e)?"true":"false",uppercase:e=>(e instanceof Boolean?e.valueOf():e)?"TRUE":"FALSE",camelcase:e=>(e instanceof Boolean?e.valueOf():e)?"True":"False"}};function M(e){return e!==null&&typeof e=="object"}function O(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}function k(e){return Object.prototype.toString.call(e)==="[object Object]"}var ne=new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");function se(e){return!(!ne.test(e)||e[e.length-1]==="_")}function oe(e){let t=e.replace(/_/g,"").toLowerCase(),i=t[0]==="-"?-1:1;return t[0]&&"+-".includes(t[0])&&(t=t.slice(1)),t===".inf"?i===1?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:t===".nan"?NaN:i*parseFloat(t)}var ae=/^[-+]?[0-9]+e/;function le(e,t){let i=e instanceof Number?e.valueOf():e;if(isNaN(i))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===i)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===i)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(O(i))return"-0.0";let n=i.toString(10);return ae.test(n)?n.replace("e",".e"):n}function he(e){return e instanceof Number&&(e=e.valueOf()),typeof e=="number"&&(e%1!==0||O(e))}var ot={tag:"tag:yaml.org,2002:float",construct:oe,defaultStyle:"lowercase",kind:"scalar",predicate:he,represent:le,resolve:se};function R(e,t,i){return t<=e&&e<=i}function ce(e){return R(e,48,57)||R(e,65,70)||R(e,97,102)}function ue(e){return R(e,48,55)}function fe(e){return R(e,48,57)}function pe(e){let t=e.length,i=0,n=!1;if(!t)return!1;let r=e[i];if((r==="-"||r==="+")&&(r=e[++i]),r==="0"){if(i+1===t)return!0;if(r=e[++i],r==="b"){for(i++;i<t;i++)if(r=e[i],r!=="_"){if(r!=="0"&&r!=="1")return!1;n=!0}return n&&r!=="_"}if(r==="x"){for(i++;i<t;i++)if(r=e[i],r!=="_"){if(!ce(e.charCodeAt(i)))return!1;n=!0}return n&&r!=="_"}for(;i<t;i++)if(r=e[i],r!=="_"){if(!ue(e.charCodeAt(i)))return!1;n=!0}return n&&r!=="_"}if(r==="_")return!1;for(;i<t;i++)if(r=e[i],r!=="_"){if(!fe(e.charCodeAt(i)))return!1;n=!0}return!n||r==="_"?!1:/^(:[0-5]?[0-9])+$/.test(e.slice(i))}function de(e){let t=e;t.includes("_")&&(t=t.replace(/_/g,""));let i=1,n=t[0];return(n==="-"||n==="+")&&(n==="-"&&(i=-1),t=t.slice(1),n=t[0]),t==="0"?0:n==="0"?t[1]==="b"?i*parseInt(t.slice(2),2):t[1]==="x"?i*parseInt(t,16):i*parseInt(t,8):i*parseInt(t,10)}function xe(e){return e instanceof Number&&(e=e.valueOf()),typeof e=="number"&&e%1===0&&!O(e)}var at={tag:"tag:yaml.org,2002:int",construct:de,defaultStyle:"decimal",kind:"scalar",predicate:xe,represent:{binary(e){let t=e instanceof Number?e.valueOf():e;return t>=0?`0b${t.toString(2)}`:`-0b${t.toString(2).slice(1)}`},octal(e){let t=e instanceof Number?e.valueOf():e;return t>=0?`0${t.toString(8)}`:`-0${t.toString(8).slice(1)}`},decimal(e){return(e instanceof Number?e.valueOf():e).toString(10)},hexadecimal(e){let t=e instanceof Number?e.valueOf():e;return t>=0?`0x${t.toString(16).toUpperCase()}`:`-0x${t.toString(16).toUpperCase().slice(1)}`}},resolve:pe};var lt={tag:"tag:yaml.org,2002:map",resolve(){return!0},construct(e){return e!==null?e:{}},kind:"mapping"};var ht={tag:"tag:yaml.org,2002:merge",kind:"scalar",resolve:e=>e==="<<"||e===null,construct:e=>e};var ct={tag:"tag:yaml.org,2002:null",kind:"scalar",defaultStyle:"lowercase",predicate:e=>e===null,construct:()=>null,resolve:e=>e==="~"||e==="null"||e==="Null"||e==="NULL",represent:{lowercase:()=>"null",uppercase:()=>"NULL",camelcase:()=>"Null"}};function ge(e){let t=new Set;for(let i of e){if(!k(i))return!1;let n=Object.keys(i);if(n.length!==1)return!1;for(let r of n){if(t.has(r))return!1;t.add(r)}}return!0}var ut={tag:"tag:yaml.org,2002:omap",kind:"sequence",resolve:ge,construct(e){return e}};function me(e){return e===null?!0:e.every(t=>k(t)&&Object.keys(t).length===1)}var ft={tag:"tag:yaml.org,2002:pairs",construct(e){return e?.flatMap(Object.entries)??[]},kind:"sequence",resolve:me};var pt=/^\/(?<regexp>[\s\S]+)\/(?<modifiers>[gismuy]*)$/,dt={tag:"tag:yaml.org,2002:js/regexp",kind:"scalar",resolve(e){if(e===null||!e.length)return!1;if(e.charAt(0)==="/"){let t=e.match(pt)?.groups;if(!t)return!1;let i=t.modifiers??"";if(new Set(i).size<i.length)return!1}return!0},construct(e){let{regexp:t=e,modifiers:i=""}=e.match(pt)?.groups??{};return new RegExp(t,i)},predicate:e=>e instanceof RegExp,represent:e=>e.toString()};var xt={tag:"tag:yaml.org,2002:seq",kind:"sequence",resolve:()=>!0,construct:e=>e!==null?e:[]};var gt={tag:"tag:yaml.org,2002:set",kind:"mapping",construct:e=>e!==null?e:{},resolve:e=>e===null?!0:Object.values(e).every(t=>t===null)};var mt={tag:"tag:yaml.org,2002:str",kind:"scalar",resolve:()=>!0,construct:e=>e!==null?e:""};var Et=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),St=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");function Ee(e){return e===null?!1:Et.exec(e)!==null||St.exec(e)!==null}function Se(e){let t=Et.exec(e);if(t===null&&(t=St.exec(e)),t===null)throw new Error("Cannot construct YAML timestamp: date resolve error");let i=+t[1],n=+t[2]-1,r=+t[3];if(!t[4])return new Date(Date.UTC(i,n,r));let s=+t[4],o=+t[5],l=+t[6],a=0;if(t[7]){let c=t[7].slice(0,3);for(;c.length<3;)c+="0";a=+c}let h=null;if(t[9]&&t[10]){let c=+t[10],f=+(t[11]||0);h=(c*60+f)*6e4,t[9]==="-"&&(h=-h)}let u=new Date(Date.UTC(i,n,r,s,o,l,a));return h&&u.setTime(u.getTime()-h),u}function Ae(e){return e.toISOString()}var At={tag:"tag:yaml.org,2002:timestamp",construct:Se,predicate(e){return e instanceof Date},kind:"scalar",represent:Ae,resolve:Ee};var wt={tag:"tag:yaml.org,2002:js/undefined",kind:"scalar",resolve(){return!0},construct(){},predicate(e){return typeof e>"u"},represent(){return""}};function we(e,t){let i={fallback:new Map,mapping:new Map,scalar:new Map,sequence:new Map},n=i.fallback;for(let r of[...e,...t])i[r.kind].set(r.tag,r),n.set(r.tag,r);return i}function b({explicitTypes:e=[],implicitTypes:t=[],include:i}){i&&(t.push(...i.implicitTypes),e.push(...i.explicitTypes));let n=we(t,e);return{implicitTypes:t,explicitTypes:e,typeMap:n}}var yt=b({explicitTypes:[mt,xt,lt]}),kt=b({implicitTypes:[ct,st,at,ot],include:yt}),Tt=b({include:kt}),C=b({explicitTypes:[rt,ut,ft,gt],implicitTypes:[At,ht],include:Tt}),ye=b({explicitTypes:[dt,wt],include:C}),F=new Map([["core",Tt],["default",C],["failsafe",yt],["json",kt],["extended",ye]]);var $=1,Nt=2,Mt=3,v=4,X=1,Ce=2,Ot=3,_e=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,Le=/[\x85\u2028\u2029]/,Ie=/[,\[\]\{\}]/,Rt=/^(?:!|!!|![a-z\-]+!)$/i,bt=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i,Ne=new Map([[120,2],[117,4],[85,8]]),Ft=new Map([[48,"\0"],[97,"\x07"],[98,"\b"],[116," "],[9," "],[110,` |
| 4 | | `],[118,"\v"],[102,"\f"],[114,"\r"],[101,"\x1B"],[32," "],[34,'"'],[47,"/"],[92,"\\"],[78,"\x85"],[95,"\xA0"],[76,"\u2028"],[80,"\u2029"]]);function Me(e){if(48<=e&&e<=57)return e-48;let t=e|32;return 97<=t&&t<=102?t-97+10:-1}function Oe(e){return 48<=e&&e<=57?e-48:-1}function Re(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}var Pt=4,Bt=75,Dt=`\0\r |
| 5 | | \x85\u2028\u2029`;function be(e,t){if(!e)return null;let i=t,n=t,r="",s="";for(;i>0&&!Dt.includes(e.charAt(i-1));)if(i--,t-i>Bt/2-1){r=" ... ",i+=5;break}for(;n<e.length&&!Dt.includes(e.charAt(n));)if(n++,n-t>Bt/2-1){s=" ... ",n-=5;break}let o=e.slice(i,n),l=" ".repeat(Pt),a=" ".repeat(Pt+t-i+r.length);return`${l+r+o+s} |
| 6 | | ${a}^`}function Fe(e,t,i,n){let r=`at line ${i+1}, column ${n+1}`,s=be(e,t);return s&&(r+=`: |
| 7 | | ${s}`),r}var D=class{input;length;lineIndent=0;lineStart=0;position=0;line=0;onWarning;allowDuplicateKeys;implicitTypes;typeMap;version;checkLineBreaks=!1;tagMap=new Map;anchorMap=new Map;tag;anchor;kind;result="";constructor(t,{schema:i=C,onWarning:n,allowDuplicateKeys:r=!1}){this.input=t,this.onWarning=n,this.allowDuplicateKeys=r,this.implicitTypes=i.implicitTypes,this.typeMap=i.typeMap,this.length=t.length,this.version=null,this.readIndent()}readIndent(){let t=this.peek();for(;t===32;)this.lineIndent+=1,t=this.next()}peek(t=0){return this.input.charCodeAt(this.position+t)}next(){return this.position+=1,this.peek()}#t(t){let i=Fe(this.input,this.position,this.line,this.position-this.lineStart);return new SyntaxError(`${t} ${i}`)}throwError(t){throw this.#t(t)}dispatchWarning(t){let i=this.#t(t);this.onWarning?.(i)}yamlDirectiveHandler(...t){if(this.version!==null)return this.throwError("Cannot handle YAML directive: duplication of %YAML directive");if(t.length!==1)return this.throwError("Cannot handle YAML directive: YAML directive accepts exactly one argument");let i=/^([0-9]+)\.([0-9]+)$/.exec(t[0]);if(i===null)return this.throwError("Cannot handle YAML directive: ill-formed argument");let n=parseInt(i[1],10),r=parseInt(i[2],10);if(n!==1)return this.throwError("Cannot handle YAML directive: unacceptable YAML version");if(this.version=t[0]??null,this.checkLineBreaks=r<2,r!==1&&r!==2)return this.dispatchWarning("Cannot handle YAML directive: unsupported YAML version")}tagDirectiveHandler(...t){if(t.length!==2)return this.throwError(`Cannot handle tag directive: directive accepts exactly two arguments, received ${t.length}`);let i=t[0],n=t[1];if(!Rt.test(i))return this.throwError(`Cannot handle tag directive: ill-formed handle (first argument) in "${i}"`);if(this.tagMap.has(i))return this.throwError(`Cannot handle tag directive: previously declared suffix for "${i}" tag handle`);if(!bt.test(n))return this.throwError("Cannot handle tag directive: ill-formed tag prefix (second argument) of the TAG directive");this.tagMap.set(i,n)}captureSegment(t,i,n){let r;if(t<i){if(r=this.input.slice(t,i),n)for(let s=0;s<r.length;s++){let o=r.charCodeAt(s);if(!(o===9||32<=o&&o<=1114111))return this.throwError(`Expected valid JSON character: received "${o}"`)}else if(_e.test(r))return this.throwError("Stream contains non-printable characters");this.result+=r}}readBlockSequence(t){let i,n,r=!1,s,o=this.tag,l=this.anchor,a=[];for(this.anchor!==null&&typeof this.anchor<"u"&&this.anchorMap.set(this.anchor,a),s=this.peek();s!==0&&!(s!==45||(n=this.peek(1),!g(n)));){if(r=!0,this.position++,this.skipSeparationSpace(!0,-1)&&this.lineIndent<=t){a.push(null),s=this.peek();continue}if(i=this.line,this.composeNode(t,Mt,!1,!0),a.push(this.result),this.skipSeparationSpace(!0,-1),s=this.peek(),(this.line===i||this.lineIndent>t)&&s!==0)return this.throwError("Cannot read block sequence: bad indentation of a sequence entry");if(this.lineIndent<t)break}return r?(this.tag=o,this.anchor=l,this.kind="sequence",this.result=a,!0):!1}mergeMappings(t,i,n){if(!M(i))return this.throwError("Cannot merge mappings: the provided source object is unacceptable");for(let[r,s]of Object.entries(i))Object.hasOwn(t,r)||(Object.defineProperty(t,r,{value:s,writable:!0,enumerable:!0,configurable:!0}),n.add(r))}storeMappingPair(t,i,n,r,s,o,l){if(Array.isArray(r)){r=Array.prototype.slice.call(r);for(let a=0;a<r.length;a++){if(Array.isArray(r[a]))return this.throwError("Cannot store mapping pair: nested arrays are not supported inside keys");typeof r=="object"&&k(r[a])&&(r[a]="[object Object]")}}if(typeof r=="object"&&k(r)&&(r="[object Object]"),r=String(r),n==="tag:yaml.org,2002:merge")if(Array.isArray(s))for(let a=0;a<s.length;a++)this.mergeMappings(t,s[a],i);else this.mergeMappings(t,s,i);else{if(!this.allowDuplicateKeys&&!i.has(r)&&Object.hasOwn(t,r))return this.line=o||this.line,this.position=l||this.position,this.throwError("Cannot store mapping pair: duplicated key");Object.defineProperty(t,r,{value:s,writable:!0,enumerable:!0,configurable:!0}),i.delete(r)}return t}readLineBreak(){let t=this.peek();if(t===10)this.position++;else if(t===13)this.position++,this.peek()===10&&this.position++;else return this.throwError("Cannot read line: line break not found");this.line+=1,this.lineStart=this.position}skipSeparationSpace(t,i){let n=0,r=this.peek();for(;r!==0;){for(;E(r);)r=this.next();if(t&&r===35)do r=this.next();while(r!==10&&r!==13&&r!==0);if(m(r))this.readLineBreak(),r=this.peek(),n++,this.lineIndent=0,this.readIndent(),r=this.peek();else break}return i!==-1&&n!==0&&this.lineIndent<i&&this.dispatchWarning("deficient indentation"),n}testDocumentSeparator(){let t=this.peek();return!!((t===45||t===46)&&t===this.peek(1)&&t===this.peek(2)&&(t=this.peek(3),t===0||g(t)))}writeFoldedLines(t){t===1?this.result+=" ":t>1&&(this.result+=` |
| 8 | | `.repeat(t-1))}readPlainScalar(t,i){let n=this.kind,r=this.result,s=this.peek();if(g(s)||y(s)||s===35||s===38||s===42||s===33||s===124||s===62||s===39||s===34||s===37||s===64||s===96)return!1;let o;if((s===63||s===45)&&(o=this.peek(1),g(o)||i&&y(o)))return!1;this.kind="scalar",this.result="";let l=this.position,a=this.position,h=!1,u=0;for(;s!==0;){if(s===58){if(o=this.peek(1),g(o)||i&&y(o))break}else if(s===35){let c=this.peek(-1);if(g(c))break}else{if(this.position===this.lineStart&&this.testDocumentSeparator()||i&&y(s))break;if(m(s)){u=this.line;let c=this.lineStart,f=this.lineIndent;if(this.skipSeparationSpace(!1,-1),this.lineIndent>=t){h=!0,s=this.peek();continue}else{this.position=l,this.line=u,this.lineStart=c,this.lineIndent=f;break}}}h&&(this.captureSegment(a,l,!1),this.writeFoldedLines(this.line-u),a=l=this.position,h=!1),E(s)||(l=this.position+1),s=this.next()}return this.captureSegment(a,l,!1),this.result?!0:(this.kind=n,this.result=r,!1)}readSingleQuotedScalar(t){let i,n,r;if(i=this.peek(),i!==39)return!1;for(this.kind="scalar",this.result="",this.position++,n=r=this.position;(i=this.peek())!==0;)if(i===39)if(this.captureSegment(n,this.position,!0),i=this.next(),i===39)n=this.position,this.position++,r=this.position;else return!0;else if(m(i))this.captureSegment(n,r,!0),this.writeFoldedLines(this.skipSeparationSpace(!1,t)),n=r=this.position;else{if(this.position===this.lineStart&&this.testDocumentSeparator())return this.throwError("Unexpected end of the document within a single quoted scalar");this.position++,r=this.position}return this.throwError("Unexpected end of the stream within a single quoted scalar")}readDoubleQuotedScalar(t){let i=this.peek();if(i!==34)return!1;this.kind="scalar",this.result="",this.position++;let n=this.position,r=this.position,s;for(;(i=this.peek())!==0;){if(i===34)return this.captureSegment(r,this.position,!0),this.position++,!0;if(i===92){if(this.captureSegment(r,this.position,!0),i=this.next(),m(i))this.skipSeparationSpace(!1,t);else if(i<256&&Ft.has(i))this.result+=Ft.get(i),this.position++;else if((s=Ne.get(i)??0)>0){let o=s,l=0;for(;o>0;o--)if(i=this.next(),(s=Me(i))>=0)l=(l<<4)+s;else return this.throwError("Cannot read double quoted scalar: expected hexadecimal character");this.result+=Re(l),this.position++}else return this.throwError("Cannot read double quoted scalar: unknown escape sequence");r=n=this.position}else if(m(i))this.captureSegment(r,n,!0),this.writeFoldedLines(this.skipSeparationSpace(!1,t)),r=n=this.position;else{if(this.position===this.lineStart&&this.testDocumentSeparator())return this.throwError("Unexpected end of the document within a double quoted scalar");this.position++,n=this.position}}return this.throwError("Unexpected end of the stream within a double quoted scalar")}readFlowCollection(t){let i=this.peek(),n,r=!0,s={};if(i===91)n=93,r=!1,s=[];else if(i===123)n=125;else return!1;this.anchor!==null&&typeof this.anchor<"u"&&this.anchorMap.set(this.anchor,s),i=this.next();let o=this.tag,l=this.anchor,a=!0,h=null,u=null,c=null,f=!1,x=!1,p=0,S=0,d=new Set;for(;i!==0;){if(this.skipSeparationSpace(!0,t),i=this.peek(),i===n)return this.position++,this.tag=o,this.anchor=l,this.kind=r?"mapping":"sequence",this.result=s,!0;if(!a)return this.throwError("Cannot read flow collection: missing comma between flow collection entries");c=u=h=null,x=f=!1,i===63&&(p=this.peek(1),g(p)&&(x=f=!0,this.position++,this.skipSeparationSpace(!0,t))),S=this.line,this.composeNode(t,$,!1,!0),c=this.tag||null,u=this.result,this.skipSeparationSpace(!0,t),i=this.peek(),(f||this.line===S)&&i===58&&(x=!0,i=this.next(),this.skipSeparationSpace(!0,t),this.composeNode(t,$,!1,!0),h=this.result),r?this.storeMappingPair(s,d,c,u,h):x?s.push(this.storeMappingPair({},d,c,u,h)):s.push(u),this.skipSeparationSpace(!0,t),i=this.peek(),i===44?(a=!0,i=this.next()):a=!1}return this.throwError("Cannot read flow collection: unexpected end of the stream within a flow collection")}readBlockScalar(t){let i=X,n=!1,r=!1,s=t,o=0,l=!1,a=this.peek(),h=!1;if(a===124)h=!1;else if(a===62)h=!0;else return!1;this.kind="scalar",this.result="";let u=0;for(;a!==0;)if(a=this.next(),a===43||a===45)if(X===i)i=a===43?Ot:Ce;else return this.throwError("Cannot read block: chomping mode identifier repeated");else if((u=Oe(a))>=0){if(u===0)return this.throwError("Cannot read block: indentation width must be greater than 0");if(!r)s=t+u-1,r=!0;else return this.throwError("Cannot read block: indentation width identifier repeated")}else break;if(E(a)){do a=this.next();while(E(a));if(a===35)do a=this.next();while(!m(a)&&a!==0)}for(;a!==0;){for(this.readLineBreak(),this.lineIndent=0,a=this.peek();(!r||this.lineIndent<s)&&a===32;)this.lineIndent++,a=this.next();if(!r&&this.lineIndent>s&&(s=this.lineIndent),m(a)){o++;continue}if(this.lineIndent<s){i===Ot?this.result+=` |
| 9 | | `.repeat(n?1+o:o):i===X&&n&&(this.result+=` |
| 10 | | `);break}h?E(a)?(l=!0,this.result+=` |
| 11 | | `.repeat(n?1+o:o)):l?(l=!1,this.result+=` |
| 12 | | `.repeat(o+1)):o===0?n&&(this.result+=" "):this.result+=` |
| 13 | | `.repeat(o):this.result+=` |
| 14 | | `.repeat(n?1+o:o),n=!0,r=!0,o=0;let c=this.position;for(;!m(a)&&a!==0;)a=this.next();this.captureSegment(c,this.position,!1)}return!0}readBlockMapping(t,i){let n=this.tag,r=this.anchor,s={},o=new Set,l,a=!1,h,u,c=null,f=null,x=null,p=!1,S=!1,d;for(this.anchor!==null&&typeof this.anchor<"u"&&this.anchorMap.set(this.anchor,s),d=this.peek();d!==0;){if(l=this.peek(1),h=this.line,u=this.position,(d===63||d===58)&&g(l)){if(d===63)p&&(this.storeMappingPair(s,o,c,f,null),c=f=x=null),S=!0,p=!0,a=!0;else if(p)p=!1,a=!0;else return this.throwError("Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line");this.position+=1,d=l}else if(this.composeNode(i,Nt,!1,!0))if(this.line===h){for(d=this.peek();E(d);)d=this.next();if(d===58){if(d=this.next(),!g(d))return this.throwError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");p&&(this.storeMappingPair(s,o,c,f,null),c=f=x=null),S=!0,p=!1,a=!1,c=this.tag,f=this.result}else return S?this.throwError("Cannot read an implicit mapping pair: missing colon"):(this.tag=n,this.anchor=r,!0)}else return S?this.throwError("Cannot read a block mapping entry: a multiline key may not be an implicit key"):(this.tag=n,this.anchor=r,!0);else break;if((this.line===h||this.lineIndent>t)&&(this.composeNode(t,v,!0,a)&&(p?f=this.result:x=this.result),p||(this.storeMappingPair(s,o,c,f,x,h,u),c=f=x=null),this.skipSeparationSpace(!0,-1),d=this.peek()),this.lineIndent>t&&d!==0)return this.throwError("Cannot read block: bad indentation of a mapping entry");if(this.lineIndent<t)break}return p&&this.storeMappingPair(s,o,c,f,null),S&&(this.tag=n,this.anchor=r,this.kind="mapping",this.result=s),S}readTagProperty(){let t,i=!1,n=!1,r="",s,o;if(o=this.peek(),o!==33)return!1;if(this.tag!==null)return this.throwError("Cannot read tag property: duplication of a tag property");if(o=this.next(),o===60?(i=!0,o=this.next()):o===33?(n=!0,r="!!",o=this.next()):r="!",t=this.position,i){do o=this.next();while(o!==0&&o!==62);if(this.position<this.length)s=this.input.slice(t,this.position),o=this.next();else return this.throwError("Cannot read tag property: unexpected end of stream")}else{for(;o!==0&&!g(o);){if(o===33){if(n)return this.throwError("Cannot read tag property: tag suffix cannot contain an exclamation mark");if(r=this.input.slice(t-1,this.position+1),!Rt.test(r))return this.throwError("Cannot read tag property: named tag handle contains invalid characters");n=!0,t=this.position+1}o=this.next()}if(s=this.input.slice(t,this.position),Ie.test(s))return this.throwError("Cannot read tag property: tag suffix cannot contain flow indicator characters")}if(s&&!bt.test(s))return this.throwError(`Cannot read tag property: invalid characters in tag name "${s}"`);if(i)this.tag=s;else if(this.tagMap.has(r))this.tag=this.tagMap.get(r)+s;else if(r==="!")this.tag=`!${s}`;else if(r==="!!")this.tag=`tag:yaml.org,2002:${s}`;else return this.throwError(`Cannot read tag property: undeclared tag handle "${r}"`);return!0}readAnchorProperty(){let t=this.peek();if(t!==38)return!1;if(this.anchor!==null)return this.throwError("Cannot read anchor property: duplicate anchor property");t=this.next();let i=this.position;for(;t!==0&&!g(t)&&!y(t);)t=this.next();return this.position===i?this.throwError("Cannot read anchor property: name of an anchor node must contain at least one character"):(this.anchor=this.input.slice(i,this.position),!0)}readAlias(){if(this.peek()!==42)return!1;let t=this.next(),i=this.position;for(;t!==0&&!g(t)&&!y(t);)t=this.next();if(this.position===i)return this.throwError("Cannot read alias: alias name must contain at least one character");let n=this.input.slice(i,this.position);return this.anchorMap.has(n)?(this.result=this.anchorMap.get(n),this.skipSeparationSpace(!0,-1),!0):this.throwError(`Cannot read alias: unidentified alias "${n}"`)}composeNode(t,i,n,r){let s,o,l=1,a=!1,h=!1,u,c,f;this.tag=null,this.anchor=null,this.kind=null,this.result=null;let x=s=o=v===i||Mt===i;if(n&&this.skipSeparationSpace(!0,-1)&&(a=!0,this.lineIndent>t?l=1:this.lineIndent===t?l=0:this.lineIndent<t&&(l=-1)),l===1)for(;this.readTagProperty()||this.readAnchorProperty();)this.skipSeparationSpace(!0,-1)?(a=!0,o=x,this.lineIndent>t?l=1:this.lineIndent===t?l=0:this.lineIndent<t&&(l=-1)):o=!1;if(o&&(o=a||r),l===1||v===i)if(c=$===i||Nt===i?t:t+1,f=this.position-this.lineStart,l===1)if(o&&(this.readBlockSequence(f)||this.readBlockMapping(f,c))||this.readFlowCollection(c))h=!0;else{if(s&&this.readBlockScalar(c)||this.readSingleQuotedScalar(c)||this.readDoubleQuotedScalar(c))h=!0;else if(this.readAlias()){if(h=!0,this.tag!==null||this.anchor!==null)return this.throwError("Cannot compose node: alias node should not have any properties")}else this.readPlainScalar(c,$===i)&&(h=!0,this.tag===null&&(this.tag="?"));this.anchor!==null&&this.anchorMap.set(this.anchor,this.result)}else l===0&&(h=o&&this.readBlockSequence(f));if(this.tag!==null&&this.tag!=="!")if(this.tag==="?"){for(let p=0;p<this.implicitTypes.length;p++)if(u=this.implicitTypes[p],u.resolve(this.result)){this.result=u.construct(this.result),this.tag=u.tag,this.anchor!==null&&this.anchorMap.set(this.anchor,this.result);break}}else if(this.typeMap[this.kind??"fallback"].has(this.tag)){if(u=this.typeMap[this.kind??"fallback"].get(this.tag),this.result!==null&&u.kind!==this.kind)return this.throwError(`Unacceptable node kind for !<${this.tag}> tag: it should be "${u.kind}", not "${this.kind}"`);if(u.resolve(this.result))this.result=u.construct(this.result),this.anchor!==null&&this.anchorMap.set(this.anchor,this.result);else return this.throwError(`Cannot resolve a node with !<${this.tag}> explicit tag`)}else return this.throwError(`Cannot resolve unknown tag !<${this.tag}>`);return this.tag!==null||this.anchor!==null||h}readDocument(){let t=this.position,i,n,r,s=!1,o;for(this.version=null,this.checkLineBreaks=!1,this.tagMap=new Map,this.anchorMap=new Map;(o=this.peek())!==0&&(this.skipSeparationSpace(!0,-1),o=this.peek(),!(this.lineIndent>0||o!==37));){for(s=!0,o=this.next(),i=this.position;o!==0&&!g(o);)o=this.next();if(n=this.input.slice(i,this.position),r=[],n.length<1)return this.throwError("Cannot read document: directive name length must be greater than zero");for(;o!==0;){for(;E(o);)o=this.next();if(o===35){do o=this.next();while(o!==0&&!m(o));break}if(m(o))break;for(i=this.position;o!==0&&!g(o);)o=this.next();r.push(this.input.slice(i,this.position))}switch(o!==0&&this.readLineBreak(),n){case"YAML":this.yamlDirectiveHandler(...r);break;case"TAG":this.tagDirectiveHandler(...r);break;default:this.dispatchWarning(`unknown document directive "${n}"`);break}}if(this.skipSeparationSpace(!0,-1),this.lineIndent===0&&this.peek()===45&&this.peek(1)===45&&this.peek(2)===45)this.position+=3,this.skipSeparationSpace(!0,-1);else if(s)return this.throwError("Cannot read document: directives end mark is expected");if(this.composeNode(this.lineIndent-1,v,!1,!0),this.skipSeparationSpace(!0,-1),this.checkLineBreaks&&Le.test(this.input.slice(t,this.position))&&this.dispatchWarning("non-ASCII line breaks are interpreted as content"),this.position===this.lineStart&&this.testDocumentSeparator())this.peek()===46&&(this.position+=3,this.skipSeparationSpace(!0,-1));else if(this.position<this.length-1)return this.throwError("Cannot read document: end of the stream or a document separator is expected");return this.result}*readDocuments(){for(;this.position<this.length-1;)yield this.readDocument()}};function $t(e){return e=String(e),e.length>0&&(m(e.charCodeAt(e.length-1))||(e+=` |
| 15 | | `),e.charCodeAt(0)===65279&&(e=e.slice(1))),e+="\0",e}function bi(e,t={}){e=$t(e);let n=new D(e,{...t,schema:F.get(t.schema)}).readDocuments(),r=n.next().value;if(!n.next().done)throw new SyntaxError("Found more than 1 document in the stream: expected a single document");return r??null}function Fi(e,t={}){return e=$t(e),[...new D(e,{...t,schema:F.get(t.schema)}).readDocuments()]}var Qt=1,Wt=2,Xt=3,Vt=4,G=5,Pe=/^\n* /,Be=new Map([[0,"\\0"],[7,"\\a"],[8,"\\b"],[9,"\\t"],[10,"\\n"],[11,"\\v"],[12,"\\f"],[13,"\\r"],[27,"\\e"],[34,'\\"'],[92,"\\\\"],[133,"\\N"],[160,"\\_"],[8232,"\\L"],[8233,"\\P"]]),De=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"];function vt(e){let t=e.toString(16).toUpperCase();if(e<=255)return`\\x${t.padStart(2,"0")}`;if(e<=65535)return`\\u${t.padStart(4,"0")}`;if(e<=4294967295)return`\\U${t.padStart(8,"0")}`;throw new Error("Code point within a string may not be greater than 0xFFFFFFFF")}function $e(e){let t=new Map;for(let i of Object.keys(e)){let n=String(e[i]);i.slice(0,2)==="!!"&&(i=`tag:yaml.org,2002:${i.slice(2)}`),t.set(i,n)}return t}function Ut(e,t){let i=" ".repeat(t);return e.split(` |
| 16 | | `).map(n=>n.length?i+n:n).join(` |
| 17 | | `)}function Yt(e,t){return` |
| 18 | | ${" ".repeat(e*t)}`}function q(e){return 32<=e&&e<=126||161<=e&&e<=55295&&e!==8232&&e!==8233||57344<=e&&e<=65533&&e!==65279||65536<=e&&e<=1114111}function it(e){return q(e)&&e!==65279&&e!==44&&e!==91&&e!==93&&e!==123&&e!==125&&e!==58&&e!==35}function ve(e){return it(e)&&!E(e)&&e!==45&&e!==63&&e!==38&&e!==42&&e!==33&&e!==124&&e!==62&&e!==39&&e!==34&&e!==37&&e!==64&&e!==96}function jt(e){return Pe.test(e)}function Ue(e,t,i,n,r){let s=n!==-1,o=!1,l=!1,a=-1,h=ve(e.charCodeAt(0))&&!E(e.charCodeAt(e.length-1)),u,c;if(t)for(c=0;c<e.length;c++){if(u=e.charCodeAt(c),!q(u))return G;h=h&&it(u)}else{for(c=0;c<e.length;c++){if(u=e.charCodeAt(c),u===10)o=!0,s&&(l=l||c-a-1>n&&e[a+1]!==" ",a=c);else if(!q(u))return G;h=h&&it(u)}l=l||s&&c-a-1>n&&e[a+1]!==" "}return!o&&!l?h&&!r.some(f=>f.resolve(e))?Qt:Wt:i>9&&jt(e)?G:l?Vt:Xt}function Ht(e,t){if(e===""||e[0]===" ")return e;let i=/ [^ ]/g,n=0,r,s=0,o=0,l=[];for(let a of e.matchAll(i))o=a.index,o-n>t&&(r=s>n?s:o,l.push(e.slice(n,r)),n=r+1),s=o;return e.length-n>t&&s>n?(l.push(e.slice(n,s)),l.push(e.slice(s+1))):l.push(e.slice(n)),l.join(` |
| 19 | | `)}function Kt(e){return e.at(-1)===` |
| 20 | | `?e.slice(0,-1):e}function Ye(e,t){let i=/(\n+)([^\n]*)/g,n=(()=>{let l=e.indexOf(` |
| 21 | | `);return l=l!==-1?l:e.length,i.lastIndex=l,Ht(e.slice(0,l),t)})(),r=e[0]===` |
| 22 | | `||e[0]===" ",s,o;for(;o=i.exec(e);){let l=o[1],a=o[2]||"";s=a[0]===" ",n+=l+(!r&&!s&&a!==""?` |
| 23 | | `:"")+Ht(a,t),r=s}return n}function He(e){let t="",i,n,r;for(let s=0;s<e.length;s++){if(i=e.charCodeAt(s),i>=55296&&i<=56319&&(n=e.charCodeAt(s+1),n>=56320&&n<=57343)){t+=vt((i-55296)*1024+n-56320+65536),s++;continue}r=Be.get(i),t+=!r&&q(i)?e[s]:r||vt(i)}return t}function Gt(e,t){let i=jt(e)?String(t):"",n=e[e.length-1]===` |
| 24 | | `,s=n&&(e[e.length-2]===` |
| 25 | | `||e===` |
| 26 | | `)?"+":n?"":"-";return`${i}${s} |
| 27 | | `}function zt(e,t,i){if(!M(e))return;if(t.has(e)){i.add(e);return}t.add(e);let n=Array.isArray(e)?e:Object.values(e);for(let r of n)zt(r,t,i)}var Q=class{indent;arrayIndent;skipInvalid;flowLevel;sortKeys;lineWidth;useAnchors;compatMode;condenseFlow;implicitTypes;explicitTypes;duplicates=[];usedDuplicates=new Set;styleMap=new Map;constructor({schema:t=C,indent:i=2,arrayIndent:n=!0,skipInvalid:r=!1,flowLevel:s=-1,styles:o=void 0,sortKeys:l=!1,lineWidth:a=80,useAnchors:h=!0,compatMode:u=!0,condenseFlow:c=!1}){this.indent=Math.max(1,i),this.arrayIndent=n,this.skipInvalid=r,this.flowLevel=s,o&&(this.styleMap=$e(o)),this.sortKeys=l,this.lineWidth=a,this.useAnchors=h,this.compatMode=u,this.condenseFlow=c,this.implicitTypes=t.implicitTypes,this.explicitTypes=t.explicitTypes}stringifyScalar(t,{level:i,isKey:n}){if(t.length===0)return"''";if(this.compatMode&&De.includes(t))return`'${t}'`;let r=this.indent*Math.max(1,i),s=this.lineWidth===-1?-1:Math.max(Math.min(this.lineWidth,40),this.lineWidth-r),o=n||this.flowLevel>-1&&i>=this.flowLevel;switch(Ue(t,o,this.indent,s,this.implicitTypes)){case Qt:return t;case Wt:return`'${t.replace(/'/g,"''")}'`;case Xt:return`|${Gt(t,this.indent)}${Kt(Ut(t,r))}`;case Vt:return`>${Gt(t,this.indent)}${Kt(Ut(Ye(t,s),r))}`;case G:return`"${He(t)}"`;default:throw new TypeError("Invalid scalar style should be unreachable: please file a bug report against Deno at https://github.com/denoland/std/issues")}}stringifyFlowSequence(t,{level:i}){let n=[];for(let s of t){let o=this.stringifyNode(s,{level:i,block:!1,compact:!1,isKey:!1});o!==null&&n.push(o)}let r=this.condenseFlow?",":", ";return`[${n.join(r)}]`}stringifyBlockSequence(t,{level:i,compact:n}){let r=Yt(this.indent,i),s=n?"":r,o=[];for(let l of t){let a=this.stringifyNode(l,{level:i+1,block:!0,compact:!0,isKey:!1});if(a===null)continue;let h=10===a.charCodeAt(0)?"-":"- ";o.push(`${h}${a}`)}return o.length?s+o.join(r):"[]"}stringifyFlowMapping(t,{level:i}){let n=this.condenseFlow?'"':"",r=this.condenseFlow?":":": ",s=[];for(let[o,l]of Object.entries(t)){let a=this.stringifyNode(o,{level:i,block:!1,compact:!1,isKey:!1});if(a===null)continue;let h=this.stringifyNode(l,{level:i,block:!1,compact:!1,isKey:!1});if(h===null)continue;let u=a.length>1024?"? ":"";s.push(n+u+a+n+r+h)}return`{${s.join(", ")}}`}stringifyBlockMapping(t,{tag:i,level:n,compact:r}){let s=Object.keys(t);if(this.sortKeys===!0)s.sort();else if(typeof this.sortKeys=="function")s.sort(this.sortKeys);else if(this.sortKeys)throw new TypeError(`"sortKeys" must be a boolean or a function: received ${typeof this.sortKeys}`);let o=Yt(this.indent,n),l=[];for(let h of s){let u=t[h],c=this.stringifyNode(h,{level:n+1,block:!0,compact:!0,isKey:!0});if(c===null)continue;let f=i!==null&&i!=="?"||c.length>1024,x=this.stringifyNode(u,{level:n+1,block:!0,compact:f,isKey:!1});if(x===null)continue;let p="";f&&(p+=c.charCodeAt(0)===10?"?":"? "),p+=c,f&&(p+=o),p+=x.charCodeAt(0)===10?":":": ",p+=x,l.push(p)}let a=r?"":o;return l.length?a+l.join(o):"{}"}getTypeRepresentation(t,i){if(!t.represent)return i;let n=this.styleMap.get(t.tag)??t.defaultStyle;if(typeof t.represent=="function")return t.represent(i,n);let r=t.represent[n];if(!r)throw new TypeError(`!<${t.tag}> tag resolver accepts not "${n}" style`);return r(i,n)}detectType(t){for(let i of this.implicitTypes)if(i.predicate?.(t))return t=this.getTypeRepresentation(i,t),{tag:"?",value:t};for(let i of this.explicitTypes)if(i.predicate?.(t))return t=this.getTypeRepresentation(i,t),{tag:i.tag,value:t};return{tag:null,value:t}}stringifyNode(t,{level:i,block:n,compact:r,isKey:s}){let o=this.detectType(t),l=o.tag;if(t=o.value,n&&(n=this.flowLevel<0||this.flowLevel>i),typeof t=="string"||t instanceof String)t=t instanceof String?t.valueOf():t,l!=="?"&&(t=this.stringifyScalar(t,{level:i,isKey:s}));else if(M(t)){let a=this.duplicates.indexOf(t),h=a!==-1;if(h){if(this.usedDuplicates.has(t))return`*ref_${a}`;this.usedDuplicates.add(t)}if((l!==null&&l!=="?"||h||this.indent!==2&&i>0)&&(r=!1),Array.isArray(t)){let u=!this.arrayIndent&&i>0?i-1:i;n&&t.length!==0?(t=this.stringifyBlockSequence(t,{level:u,compact:r}),h&&(t=`&ref_${a}${t}`)):(t=this.stringifyFlowSequence(t,{level:u}),h&&(t=`&ref_${a} ${t}`))}else n&&Object.keys(t).length!==0?(t=this.stringifyBlockMapping(t,{tag:l,level:i,compact:r}),h&&(t=`&ref_${a}${t}`)):(t=this.stringifyFlowMapping(t,{level:i}),h&&(t=`&ref_${a} ${t}`))}else{if(this.skipInvalid)return null;throw new TypeError(`Cannot stringify ${typeof t}`)}return l!==null&&l!=="?"&&(t=`!<${l}> ${t}`),t}stringify(t){if(this.useAnchors){let n=new Set,r=new Set;zt(t,n,r),this.duplicates=[...r],this.usedDuplicates=new Set}let i=this.stringifyNode(t,{level:0,block:!0,compact:!0,isKey:!1});return i!==null?`${i} |
| 28 | | `:""}};function Hi(e,t={}){return new Q({...t,schema:F.get(t.schema)}).stringify(e)}export{bi as parse,Fi as parseAll,Hi as stringify}; |
| 29 | | //# sourceMappingURL=mod.bundle.js.map |
| 1 | // https://jsr.io/@std/yaml/1.0.5/_chars.ts |
| 2 | var BOM = 65279; |
| 3 | var TAB = 9; |
| 4 | var LINE_FEED = 10; |
| 5 | var CARRIAGE_RETURN = 13; |
| 6 | var SPACE = 32; |
| 7 | var EXCLAMATION = 33; |
| 8 | var DOUBLE_QUOTE = 34; |
| 9 | var SHARP = 35; |
| 10 | var PERCENT = 37; |
| 11 | var AMPERSAND = 38; |
| 12 | var SINGLE_QUOTE = 39; |
| 13 | var ASTERISK = 42; |
| 14 | var PLUS = 43; |
| 15 | var COMMA = 44; |
| 16 | var MINUS = 45; |
| 17 | var DOT = 46; |
| 18 | var COLON = 58; |
| 19 | var SMALLER_THAN = 60; |
| 20 | var GREATER_THAN = 62; |
| 21 | var QUESTION = 63; |
| 22 | var COMMERCIAL_AT = 64; |
| 23 | var LEFT_SQUARE_BRACKET = 91; |
| 24 | var BACKSLASH = 92; |
| 25 | var RIGHT_SQUARE_BRACKET = 93; |
| 26 | var GRAVE_ACCENT = 96; |
| 27 | var LEFT_CURLY_BRACKET = 123; |
| 28 | var VERTICAL_LINE = 124; |
| 29 | var RIGHT_CURLY_BRACKET = 125; |
| 30 | function isEOL(c) { |
| 31 | return c === LINE_FEED || c === CARRIAGE_RETURN; |
| 32 | } |
| 33 | function isWhiteSpace(c) { |
| 34 | return c === TAB || c === SPACE; |
| 35 | } |
| 36 | function isWhiteSpaceOrEOL(c) { |
| 37 | return isWhiteSpace(c) || isEOL(c); |
| 38 | } |
| 39 | function isFlowIndicator(c) { |
| 40 | return c === COMMA || c === LEFT_SQUARE_BRACKET || c === RIGHT_SQUARE_BRACKET || c === LEFT_CURLY_BRACKET || c === RIGHT_CURLY_BRACKET; |
| 41 | } |
| 42 | |
| 43 | // https://jsr.io/@std/yaml/1.0.5/_type/binary.ts |
| 44 | var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r"; |
| 45 | function resolveYamlBinary(data) { |
| 46 | if (data === null) return false; |
| 47 | let code; |
| 48 | let bitlen = 0; |
| 49 | const max = data.length; |
| 50 | const map2 = BASE64_MAP; |
| 51 | for (let idx = 0; idx < max; idx++) { |
| 52 | code = map2.indexOf(data.charAt(idx)); |
| 53 | if (code > 64) continue; |
| 54 | if (code < 0) return false; |
| 55 | bitlen += 6; |
| 56 | } |
| 57 | return bitlen % 8 === 0; |
| 58 | } |
| 59 | function constructYamlBinary(data) { |
| 60 | const input = data.replace(/[\r\n=]/g, ""); |
| 61 | const max = input.length; |
| 62 | const map2 = BASE64_MAP; |
| 63 | const result = []; |
| 64 | let bits = 0; |
| 65 | for (let idx = 0; idx < max; idx++) { |
| 66 | if (idx % 4 === 0 && idx) { |
| 67 | result.push(bits >> 16 & 255); |
| 68 | result.push(bits >> 8 & 255); |
| 69 | result.push(bits & 255); |
| 70 | } |
| 71 | bits = bits << 6 | map2.indexOf(input.charAt(idx)); |
| 72 | } |
| 73 | const tailbits = max % 4 * 6; |
| 74 | if (tailbits === 0) { |
| 75 | result.push(bits >> 16 & 255); |
| 76 | result.push(bits >> 8 & 255); |
| 77 | result.push(bits & 255); |
| 78 | } else if (tailbits === 18) { |
| 79 | result.push(bits >> 10 & 255); |
| 80 | result.push(bits >> 2 & 255); |
| 81 | } else if (tailbits === 12) { |
| 82 | result.push(bits >> 4 & 255); |
| 83 | } |
| 84 | return new Uint8Array(result); |
| 85 | } |
| 86 | function representYamlBinary(object) { |
| 87 | const max = object.length; |
| 88 | const map2 = BASE64_MAP; |
| 89 | let result = ""; |
| 90 | let bits = 0; |
| 91 | for (let idx = 0; idx < max; idx++) { |
| 92 | if (idx % 3 === 0 && idx) { |
| 93 | result += map2[bits >> 18 & 63]; |
| 94 | result += map2[bits >> 12 & 63]; |
| 95 | result += map2[bits >> 6 & 63]; |
| 96 | result += map2[bits & 63]; |
| 97 | } |
| 98 | bits = (bits << 8) + object[idx]; |
| 99 | } |
| 100 | const tail = max % 3; |
| 101 | if (tail === 0) { |
| 102 | result += map2[bits >> 18 & 63]; |
| 103 | result += map2[bits >> 12 & 63]; |
| 104 | result += map2[bits >> 6 & 63]; |
| 105 | result += map2[bits & 63]; |
| 106 | } else if (tail === 2) { |
| 107 | result += map2[bits >> 10 & 63]; |
| 108 | result += map2[bits >> 4 & 63]; |
| 109 | result += map2[bits << 2 & 63]; |
| 110 | result += map2[64]; |
| 111 | } else if (tail === 1) { |
| 112 | result += map2[bits >> 2 & 63]; |
| 113 | result += map2[bits << 4 & 63]; |
| 114 | result += map2[64]; |
| 115 | result += map2[64]; |
| 116 | } |
| 117 | return result; |
| 118 | } |
| 119 | function isBinary(obj) { |
| 120 | return obj instanceof Uint8Array; |
| 121 | } |
| 122 | var binary = { |
| 123 | tag: "tag:yaml.org,2002:binary", |
| 124 | construct: constructYamlBinary, |
| 125 | kind: "scalar", |
| 126 | predicate: isBinary, |
| 127 | represent: representYamlBinary, |
| 128 | resolve: resolveYamlBinary |
| 129 | }; |
| 130 | |
| 131 | // https://jsr.io/@std/yaml/1.0.5/_type/bool.ts |
| 132 | var YAML_TRUE_BOOLEANS = ["true", "True", "TRUE"]; |
| 133 | var YAML_FALSE_BOOLEANS = ["false", "False", "FALSE"]; |
| 134 | var YAML_BOOLEANS = [...YAML_TRUE_BOOLEANS, ...YAML_FALSE_BOOLEANS]; |
| 135 | var bool = { |
| 136 | tag: "tag:yaml.org,2002:bool", |
| 137 | kind: "scalar", |
| 138 | defaultStyle: "lowercase", |
| 139 | predicate: (value2) => typeof value2 === "boolean" || value2 instanceof Boolean, |
| 140 | construct: (data) => YAML_TRUE_BOOLEANS.includes(data), |
| 141 | resolve: (data) => YAML_BOOLEANS.includes(data), |
| 142 | represent: { |
| 143 | // deno-lint-ignore ban-types |
| 144 | lowercase: (object) => { |
| 145 | const value2 = object instanceof Boolean ? object.valueOf() : object; |
| 146 | return value2 ? "true" : "false"; |
| 147 | }, |
| 148 | // deno-lint-ignore ban-types |
| 149 | uppercase: (object) => { |
| 150 | const value2 = object instanceof Boolean ? object.valueOf() : object; |
| 151 | return value2 ? "TRUE" : "FALSE"; |
| 152 | }, |
| 153 | // deno-lint-ignore ban-types |
| 154 | camelcase: (object) => { |
| 155 | const value2 = object instanceof Boolean ? object.valueOf() : object; |
| 156 | return value2 ? "True" : "False"; |
| 157 | } |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | // https://jsr.io/@std/yaml/1.0.5/_utils.ts |
| 162 | function isObject(value2) { |
| 163 | return value2 !== null && typeof value2 === "object"; |
| 164 | } |
| 165 | function isNegativeZero(i) { |
| 166 | return i === 0 && Number.NEGATIVE_INFINITY === 1 / i; |
| 167 | } |
| 168 | function isPlainObject(object) { |
| 169 | return Object.prototype.toString.call(object) === "[object Object]"; |
| 170 | } |
| 171 | |
| 172 | // https://jsr.io/@std/yaml/1.0.5/_type/float.ts |
| 173 | var YAML_FLOAT_PATTERN = new RegExp( |
| 174 | // 2.5e4, 2.5 and integers |
| 175 | "^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$" |
| 176 | ); |
| 177 | function resolveYamlFloat(data) { |
| 178 | if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_` |
| 179 | // Probably should update regexp & check speed |
| 180 | data[data.length - 1] === "_") { |
| 181 | return false; |
| 182 | } |
| 183 | return true; |
| 184 | } |
| 185 | function constructYamlFloat(data) { |
| 186 | let value2 = data.replace(/_/g, "").toLowerCase(); |
| 187 | const sign = value2[0] === "-" ? -1 : 1; |
| 188 | if (value2[0] && "+-".includes(value2[0])) { |
| 189 | value2 = value2.slice(1); |
| 190 | } |
| 191 | if (value2 === ".inf") { |
| 192 | return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; |
| 193 | } |
| 194 | if (value2 === ".nan") { |
| 195 | return NaN; |
| 196 | } |
| 197 | return sign * parseFloat(value2); |
| 198 | } |
| 199 | var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/; |
| 200 | function representYamlFloat(object, style) { |
| 201 | const value2 = object instanceof Number ? object.valueOf() : object; |
| 202 | if (isNaN(value2)) { |
| 203 | switch (style) { |
| 204 | case "lowercase": |
| 205 | return ".nan"; |
| 206 | case "uppercase": |
| 207 | return ".NAN"; |
| 208 | case "camelcase": |
| 209 | return ".NaN"; |
| 210 | } |
| 211 | } else if (Number.POSITIVE_INFINITY === value2) { |
| 212 | switch (style) { |
| 213 | case "lowercase": |
| 214 | return ".inf"; |
| 215 | case "uppercase": |
| 216 | return ".INF"; |
| 217 | case "camelcase": |
| 218 | return ".Inf"; |
| 219 | } |
| 220 | } else if (Number.NEGATIVE_INFINITY === value2) { |
| 221 | switch (style) { |
| 222 | case "lowercase": |
| 223 | return "-.inf"; |
| 224 | case "uppercase": |
| 225 | return "-.INF"; |
| 226 | case "camelcase": |
| 227 | return "-.Inf"; |
| 228 | } |
| 229 | } else if (isNegativeZero(value2)) { |
| 230 | return "-0.0"; |
| 231 | } |
| 232 | const res = value2.toString(10); |
| 233 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res; |
| 234 | } |
| 235 | function isFloat(object) { |
| 236 | if (object instanceof Number) object = object.valueOf(); |
| 237 | return typeof object === "number" && (object % 1 !== 0 || isNegativeZero(object)); |
| 238 | } |
| 239 | var float = { |
| 240 | tag: "tag:yaml.org,2002:float", |
| 241 | construct: constructYamlFloat, |
| 242 | defaultStyle: "lowercase", |
| 243 | kind: "scalar", |
| 244 | predicate: isFloat, |
| 245 | represent: representYamlFloat, |
| 246 | resolve: resolveYamlFloat |
| 247 | }; |
| 248 | |
| 249 | // https://jsr.io/@std/yaml/1.0.5/_type/int.ts |
| 250 | function isCharCodeInRange(c, lower, upper) { |
| 251 | return lower <= c && c <= upper; |
| 252 | } |
| 253 | function isHexCode(c) { |
| 254 | return isCharCodeInRange(c, 48, 57) || // 0-9 |
| 255 | isCharCodeInRange(c, 65, 70) || // A-F |
| 256 | isCharCodeInRange(c, 97, 102); |
| 257 | } |
| 258 | function isOctCode(c) { |
| 259 | return isCharCodeInRange(c, 48, 55); |
| 260 | } |
| 261 | function isDecCode(c) { |
| 262 | return isCharCodeInRange(c, 48, 57); |
| 263 | } |
| 264 | function resolveYamlInteger(data) { |
| 265 | const max = data.length; |
| 266 | let index = 0; |
| 267 | let hasDigits = false; |
| 268 | if (!max) return false; |
| 269 | let ch = data[index]; |
| 270 | if (ch === "-" || ch === "+") { |
| 271 | ch = data[++index]; |
| 272 | } |
| 273 | if (ch === "0") { |
| 274 | if (index + 1 === max) return true; |
| 275 | ch = data[++index]; |
| 276 | if (ch === "b") { |
| 277 | index++; |
| 278 | for (; index < max; index++) { |
| 279 | ch = data[index]; |
| 280 | if (ch === "_") continue; |
| 281 | if (ch !== "0" && ch !== "1") return false; |
| 282 | hasDigits = true; |
| 283 | } |
| 284 | return hasDigits && ch !== "_"; |
| 285 | } |
| 286 | if (ch === "x") { |
| 287 | index++; |
| 288 | for (; index < max; index++) { |
| 289 | ch = data[index]; |
| 290 | if (ch === "_") continue; |
| 291 | if (!isHexCode(data.charCodeAt(index))) return false; |
| 292 | hasDigits = true; |
| 293 | } |
| 294 | return hasDigits && ch !== "_"; |
| 295 | } |
| 296 | for (; index < max; index++) { |
| 297 | ch = data[index]; |
| 298 | if (ch === "_") continue; |
| 299 | if (!isOctCode(data.charCodeAt(index))) return false; |
| 300 | hasDigits = true; |
| 301 | } |
| 302 | return hasDigits && ch !== "_"; |
| 303 | } |
| 304 | if (ch === "_") return false; |
| 305 | for (; index < max; index++) { |
| 306 | ch = data[index]; |
| 307 | if (ch === "_") continue; |
| 308 | if (!isDecCode(data.charCodeAt(index))) { |
| 309 | return false; |
| 310 | } |
| 311 | hasDigits = true; |
| 312 | } |
| 313 | if (!hasDigits || ch === "_") return false; |
| 314 | return /^(:[0-5]?[0-9])+$/.test(data.slice(index)); |
| 315 | } |
| 316 | function constructYamlInteger(data) { |
| 317 | let value2 = data; |
| 318 | if (value2.includes("_")) { |
| 319 | value2 = value2.replace(/_/g, ""); |
| 320 | } |
| 321 | let sign = 1; |
| 322 | let ch = value2[0]; |
| 323 | if (ch === "-" || ch === "+") { |
| 324 | if (ch === "-") sign = -1; |
| 325 | value2 = value2.slice(1); |
| 326 | ch = value2[0]; |
| 327 | } |
| 328 | if (value2 === "0") return 0; |
| 329 | if (ch === "0") { |
| 330 | if (value2[1] === "b") return sign * parseInt(value2.slice(2), 2); |
| 331 | if (value2[1] === "x") return sign * parseInt(value2, 16); |
| 332 | return sign * parseInt(value2, 8); |
| 333 | } |
| 334 | return sign * parseInt(value2, 10); |
| 335 | } |
| 336 | function isInteger(object) { |
| 337 | if (object instanceof Number) object = object.valueOf(); |
| 338 | return typeof object === "number" && object % 1 === 0 && !isNegativeZero(object); |
| 339 | } |
| 340 | var int = { |
| 341 | tag: "tag:yaml.org,2002:int", |
| 342 | construct: constructYamlInteger, |
| 343 | defaultStyle: "decimal", |
| 344 | kind: "scalar", |
| 345 | predicate: isInteger, |
| 346 | represent: { |
| 347 | // deno-lint-ignore ban-types |
| 348 | binary(object) { |
| 349 | const value2 = object instanceof Number ? object.valueOf() : object; |
| 350 | return value2 >= 0 ? `0b${value2.toString(2)}` : `-0b${value2.toString(2).slice(1)}`; |
| 351 | }, |
| 352 | // deno-lint-ignore ban-types |
| 353 | octal(object) { |
| 354 | const value2 = object instanceof Number ? object.valueOf() : object; |
| 355 | return value2 >= 0 ? `0${value2.toString(8)}` : `-0${value2.toString(8).slice(1)}`; |
| 356 | }, |
| 357 | // deno-lint-ignore ban-types |
| 358 | decimal(object) { |
| 359 | const value2 = object instanceof Number ? object.valueOf() : object; |
| 360 | return value2.toString(10); |
| 361 | }, |
| 362 | // deno-lint-ignore ban-types |
| 363 | hexadecimal(object) { |
| 364 | const value2 = object instanceof Number ? object.valueOf() : object; |
| 365 | return value2 >= 0 ? `0x${value2.toString(16).toUpperCase()}` : `-0x${value2.toString(16).toUpperCase().slice(1)}`; |
| 366 | } |
| 367 | }, |
| 368 | resolve: resolveYamlInteger |
| 369 | }; |
| 370 | |
| 371 | // https://jsr.io/@std/yaml/1.0.5/_type/map.ts |
| 372 | var map = { |
| 373 | tag: "tag:yaml.org,2002:map", |
| 374 | resolve() { |
| 375 | return true; |
| 376 | }, |
| 377 | construct(data) { |
| 378 | return data !== null ? data : {}; |
| 379 | }, |
| 380 | kind: "mapping" |
| 381 | }; |
| 382 | |
| 383 | // https://jsr.io/@std/yaml/1.0.5/_type/merge.ts |
| 384 | var merge = { |
| 385 | tag: "tag:yaml.org,2002:merge", |
| 386 | kind: "scalar", |
| 387 | resolve: (data) => data === "<<" || data === null, |
| 388 | construct: (data) => data |
| 389 | }; |
| 390 | |
| 391 | // https://jsr.io/@std/yaml/1.0.5/_type/nil.ts |
| 392 | var nil = { |
| 393 | tag: "tag:yaml.org,2002:null", |
| 394 | kind: "scalar", |
| 395 | defaultStyle: "lowercase", |
| 396 | predicate: (object) => object === null, |
| 397 | construct: () => null, |
| 398 | resolve: (data) => { |
| 399 | return data === "~" || data === "null" || data === "Null" || data === "NULL"; |
| 400 | }, |
| 401 | represent: { |
| 402 | lowercase: () => "null", |
| 403 | uppercase: () => "NULL", |
| 404 | camelcase: () => "Null" |
| 405 | } |
| 406 | }; |
| 407 | |
| 408 | // https://jsr.io/@std/yaml/1.0.5/_type/omap.ts |
| 409 | function resolveYamlOmap(data) { |
| 410 | const objectKeys = /* @__PURE__ */ new Set(); |
| 411 | for (const object of data) { |
| 412 | if (!isPlainObject(object)) return false; |
| 413 | const keys = Object.keys(object); |
| 414 | if (keys.length !== 1) return false; |
| 415 | for (const key of keys) { |
| 416 | if (objectKeys.has(key)) return false; |
| 417 | objectKeys.add(key); |
| 418 | } |
| 419 | } |
| 420 | return true; |
| 421 | } |
| 422 | var omap = { |
| 423 | tag: "tag:yaml.org,2002:omap", |
| 424 | kind: "sequence", |
| 425 | resolve: resolveYamlOmap, |
| 426 | construct(data) { |
| 427 | return data; |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | // https://jsr.io/@std/yaml/1.0.5/_type/pairs.ts |
| 432 | function resolveYamlPairs(data) { |
| 433 | if (data === null) return true; |
| 434 | return data.every((it) => isPlainObject(it) && Object.keys(it).length === 1); |
| 435 | } |
| 436 | var pairs = { |
| 437 | tag: "tag:yaml.org,2002:pairs", |
| 438 | construct(data) { |
| 439 | return data?.flatMap(Object.entries) ?? []; |
| 440 | }, |
| 441 | kind: "sequence", |
| 442 | resolve: resolveYamlPairs |
| 443 | }; |
| 444 | |
| 445 | // https://jsr.io/@std/yaml/1.0.5/_type/regexp.ts |
| 446 | var REGEXP = /^\/(?<regexp>[\s\S]+)\/(?<modifiers>[gismuy]*)$/; |
| 447 | var regexp = { |
| 448 | tag: "tag:yaml.org,2002:js/regexp", |
| 449 | kind: "scalar", |
| 450 | resolve(data) { |
| 451 | if (data === null || !data.length) return false; |
| 452 | if (data.charAt(0) === "/") { |
| 453 | const groups = data.match(REGEXP)?.groups; |
| 454 | if (!groups) return false; |
| 455 | const modifiers = groups.modifiers ?? ""; |
| 456 | if (new Set(modifiers).size < modifiers.length) return false; |
| 457 | } |
| 458 | return true; |
| 459 | }, |
| 460 | construct(data) { |
| 461 | const { regexp: regexp2 = data, modifiers = "" } = data.match(REGEXP)?.groups ?? {}; |
| 462 | return new RegExp(regexp2, modifiers); |
| 463 | }, |
| 464 | predicate: (object) => object instanceof RegExp, |
| 465 | represent: (object) => object.toString() |
| 466 | }; |
| 467 | |
| 468 | // https://jsr.io/@std/yaml/1.0.5/_type/seq.ts |
| 469 | var seq = { |
| 470 | tag: "tag:yaml.org,2002:seq", |
| 471 | kind: "sequence", |
| 472 | resolve: () => true, |
| 473 | construct: (data) => data !== null ? data : [] |
| 474 | }; |
| 475 | |
| 476 | // https://jsr.io/@std/yaml/1.0.5/_type/set.ts |
| 477 | var set = { |
| 478 | tag: "tag:yaml.org,2002:set", |
| 479 | kind: "mapping", |
| 480 | construct: (data) => data !== null ? data : {}, |
| 481 | resolve: (data) => { |
| 482 | if (data === null) return true; |
| 483 | return Object.values(data).every((it) => it === null); |
| 484 | } |
| 485 | }; |
| 486 | |
| 487 | // https://jsr.io/@std/yaml/1.0.5/_type/str.ts |
| 488 | var str = { |
| 489 | tag: "tag:yaml.org,2002:str", |
| 490 | kind: "scalar", |
| 491 | resolve: () => true, |
| 492 | construct: (data) => data !== null ? data : "" |
| 493 | }; |
| 494 | |
| 495 | // https://jsr.io/@std/yaml/1.0.5/_type/timestamp.ts |
| 496 | var YAML_DATE_REGEXP = new RegExp( |
| 497 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$" |
| 498 | // [3] day |
| 499 | ); |
| 500 | var YAML_TIMESTAMP_REGEXP = new RegExp( |
| 501 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$" |
| 502 | // [11] tz_minute |
| 503 | ); |
| 504 | function resolveYamlTimestamp(data) { |
| 505 | if (data === null) return false; |
| 506 | if (YAML_DATE_REGEXP.exec(data) !== null) return true; |
| 507 | if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true; |
| 508 | return false; |
| 509 | } |
| 510 | function constructYamlTimestamp(data) { |
| 511 | let match = YAML_DATE_REGEXP.exec(data); |
| 512 | if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data); |
| 513 | if (match === null) { |
| 514 | throw new Error("Cannot construct YAML timestamp: date resolve error"); |
| 515 | } |
| 516 | const year = +match[1]; |
| 517 | const month = +match[2] - 1; |
| 518 | const day = +match[3]; |
| 519 | if (!match[4]) { |
| 520 | return new Date(Date.UTC(year, month, day)); |
| 521 | } |
| 522 | const hour = +match[4]; |
| 523 | const minute = +match[5]; |
| 524 | const second = +match[6]; |
| 525 | let fraction = 0; |
| 526 | if (match[7]) { |
| 527 | let partFraction = match[7].slice(0, 3); |
| 528 | while (partFraction.length < 3) { |
| 529 | partFraction += "0"; |
| 530 | } |
| 531 | fraction = +partFraction; |
| 532 | } |
| 533 | let delta = null; |
| 534 | if (match[9] && match[10]) { |
| 535 | const tzHour = +match[10]; |
| 536 | const tzMinute = +(match[11] || 0); |
| 537 | delta = (tzHour * 60 + tzMinute) * 6e4; |
| 538 | if (match[9] === "-") delta = -delta; |
| 539 | } |
| 540 | const date = new Date( |
| 541 | Date.UTC(year, month, day, hour, minute, second, fraction) |
| 542 | ); |
| 543 | if (delta) date.setTime(date.getTime() - delta); |
| 544 | return date; |
| 545 | } |
| 546 | function representYamlTimestamp(date) { |
| 547 | return date.toISOString(); |
| 548 | } |
| 549 | var timestamp = { |
| 550 | tag: "tag:yaml.org,2002:timestamp", |
| 551 | construct: constructYamlTimestamp, |
| 552 | predicate(object) { |
| 553 | return object instanceof Date; |
| 554 | }, |
| 555 | kind: "scalar", |
| 556 | represent: representYamlTimestamp, |
| 557 | resolve: resolveYamlTimestamp |
| 558 | }; |
| 559 | |
| 560 | // https://jsr.io/@std/yaml/1.0.5/_type/undefined.ts |
| 561 | var undefinedType = { |
| 562 | tag: "tag:yaml.org,2002:js/undefined", |
| 563 | kind: "scalar", |
| 564 | resolve() { |
| 565 | return true; |
| 566 | }, |
| 567 | construct() { |
| 568 | return void 0; |
| 569 | }, |
| 570 | predicate(object) { |
| 571 | return typeof object === "undefined"; |
| 572 | }, |
| 573 | represent() { |
| 574 | return ""; |
| 575 | } |
| 576 | }; |
| 577 | |
| 578 | // https://jsr.io/@std/yaml/1.0.5/_schema.ts |
| 579 | function createTypeMap(implicitTypes, explicitTypes) { |
| 580 | const result = { |
| 581 | fallback: /* @__PURE__ */ new Map(), |
| 582 | mapping: /* @__PURE__ */ new Map(), |
| 583 | scalar: /* @__PURE__ */ new Map(), |
| 584 | sequence: /* @__PURE__ */ new Map() |
| 585 | }; |
| 586 | const fallbackMap = result.fallback; |
| 587 | for (const type of [...implicitTypes, ...explicitTypes]) { |
| 588 | const map2 = result[type.kind]; |
| 589 | map2.set(type.tag, type); |
| 590 | fallbackMap.set(type.tag, type); |
| 591 | } |
| 592 | return result; |
| 593 | } |
| 594 | function createSchema({ explicitTypes = [], implicitTypes = [], include }) { |
| 595 | if (include) { |
| 596 | implicitTypes.push(...include.implicitTypes); |
| 597 | explicitTypes.push(...include.explicitTypes); |
| 598 | } |
| 599 | const typeMap = createTypeMap(implicitTypes, explicitTypes); |
| 600 | return { implicitTypes, explicitTypes, typeMap }; |
| 601 | } |
| 602 | var FAILSAFE_SCHEMA = createSchema({ |
| 603 | explicitTypes: [str, seq, map] |
| 604 | }); |
| 605 | var JSON_SCHEMA = createSchema({ |
| 606 | implicitTypes: [nil, bool, int, float], |
| 607 | include: FAILSAFE_SCHEMA |
| 608 | }); |
| 609 | var CORE_SCHEMA = createSchema({ |
| 610 | include: JSON_SCHEMA |
| 611 | }); |
| 612 | var DEFAULT_SCHEMA = createSchema({ |
| 613 | explicitTypes: [binary, omap, pairs, set], |
| 614 | implicitTypes: [timestamp, merge], |
| 615 | include: CORE_SCHEMA |
| 616 | }); |
| 617 | var EXTENDED_SCHEMA = createSchema({ |
| 618 | explicitTypes: [regexp, undefinedType], |
| 619 | include: DEFAULT_SCHEMA |
| 620 | }); |
| 621 | var SCHEMA_MAP = /* @__PURE__ */ new Map([ |
| 622 | ["core", CORE_SCHEMA], |
| 623 | ["default", DEFAULT_SCHEMA], |
| 624 | ["failsafe", FAILSAFE_SCHEMA], |
| 625 | ["json", JSON_SCHEMA], |
| 626 | ["extended", EXTENDED_SCHEMA] |
| 627 | ]); |
| 628 | |
| 629 | // https://jsr.io/@std/yaml/1.0.5/_loader_state.ts |
| 630 | var CONTEXT_FLOW_IN = 1; |
| 631 | var CONTEXT_FLOW_OUT = 2; |
| 632 | var CONTEXT_BLOCK_IN = 3; |
| 633 | var CONTEXT_BLOCK_OUT = 4; |
| 634 | var CHOMPING_CLIP = 1; |
| 635 | var CHOMPING_STRIP = 2; |
| 636 | var CHOMPING_KEEP = 3; |
| 637 | var PATTERN_NON_PRINTABLE = ( |
| 638 | // deno-lint-ignore no-control-regex |
| 639 | /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/ |
| 640 | ); |
| 641 | var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/; |
| 642 | var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/; |
| 643 | var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i; |
| 644 | var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i; |
| 645 | var ESCAPED_HEX_LENGTHS = /* @__PURE__ */ new Map([ |
| 646 | [120, 2], |
| 647 | // x |
| 648 | [117, 4], |
| 649 | // u |
| 650 | [85, 8] |
| 651 | // U |
| 652 | ]); |
| 653 | var SIMPLE_ESCAPE_SEQUENCES = /* @__PURE__ */ new Map([ |
| 654 | [48, "\0"], |
| 655 | // 0 |
| 656 | [97, "\x07"], |
| 657 | // a |
| 658 | [98, "\b"], |
| 659 | // b |
| 660 | [116, " "], |
| 661 | // t |
| 662 | [9, " "], |
| 663 | // Tab |
| 664 | [110, "\n"], |
| 665 | // n |
| 666 | [118, "\v"], |
| 667 | // v |
| 668 | [102, "\f"], |
| 669 | // f |
| 670 | [114, "\r"], |
| 671 | // r |
| 672 | [101, "\x1B"], |
| 673 | // e |
| 674 | [32, " "], |
| 675 | // Space |
| 676 | [34, '"'], |
| 677 | // " |
| 678 | [47, "/"], |
| 679 | // / |
| 680 | [92, "\\"], |
| 681 | // \ |
| 682 | [78, "\x85"], |
| 683 | // N |
| 684 | [95, "\xA0"], |
| 685 | // _ |
| 686 | [76, "\u2028"], |
| 687 | // L |
| 688 | [80, "\u2029"] |
| 689 | // P |
| 690 | ]); |
| 691 | function hexCharCodeToNumber(charCode) { |
| 692 | if (48 <= charCode && charCode <= 57) return charCode - 48; |
| 693 | const lc = charCode | 32; |
| 694 | if (97 <= lc && lc <= 102) return lc - 97 + 10; |
| 695 | return -1; |
| 696 | } |
| 697 | function decimalCharCodeToNumber(charCode) { |
| 698 | if (48 <= charCode && charCode <= 57) return charCode - 48; |
| 699 | return -1; |
| 700 | } |
| 701 | function codepointToChar(codepoint) { |
| 702 | if (codepoint <= 65535) return String.fromCharCode(codepoint); |
| 703 | return String.fromCharCode( |
| 704 | (codepoint - 65536 >> 10) + 55296, |
| 705 | // High surrogate |
| 706 | (codepoint - 65536 & 1023) + 56320 |
| 707 | // Low surrogate |
| 708 | ); |
| 709 | } |
| 710 | var INDENT = 4; |
| 711 | var MAX_LENGTH = 75; |
| 712 | var DELIMITERS = "\0\r\n\x85\u2028\u2029"; |
| 713 | function getSnippet(buffer, position) { |
| 714 | if (!buffer) return null; |
| 715 | let start = position; |
| 716 | let end = position; |
| 717 | let head = ""; |
| 718 | let tail = ""; |
| 719 | while (start > 0 && !DELIMITERS.includes(buffer.charAt(start - 1))) { |
| 720 | start--; |
| 721 | if (position - start > MAX_LENGTH / 2 - 1) { |
| 722 | head = " ... "; |
| 723 | start += 5; |
| 724 | break; |
| 725 | } |
| 726 | } |
| 727 | while (end < buffer.length && !DELIMITERS.includes(buffer.charAt(end))) { |
| 728 | end++; |
| 729 | if (end - position > MAX_LENGTH / 2 - 1) { |
| 730 | tail = " ... "; |
| 731 | end -= 5; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | const snippet = buffer.slice(start, end); |
| 736 | const indent = " ".repeat(INDENT); |
| 737 | const caretIndent = " ".repeat(INDENT + position - start + head.length); |
| 738 | return `${indent + head + snippet + tail} |
| 739 | ${caretIndent}^`; |
| 740 | } |
| 741 | function markToString(buffer, position, line, column) { |
| 742 | let where = `at line ${line + 1}, column ${column + 1}`; |
| 743 | const snippet = getSnippet(buffer, position); |
| 744 | if (snippet) where += `: |
| 745 | ${snippet}`; |
| 746 | return where; |
| 747 | } |
| 748 | var LoaderState = class { |
| 749 | input; |
| 750 | length; |
| 751 | lineIndent = 0; |
| 752 | lineStart = 0; |
| 753 | position = 0; |
| 754 | line = 0; |
| 755 | onWarning; |
| 756 | allowDuplicateKeys; |
| 757 | implicitTypes; |
| 758 | typeMap; |
| 759 | version; |
| 760 | checkLineBreaks = false; |
| 761 | tagMap = /* @__PURE__ */ new Map(); |
| 762 | anchorMap = /* @__PURE__ */ new Map(); |
| 763 | tag; |
| 764 | anchor; |
| 765 | kind; |
| 766 | result = ""; |
| 767 | constructor(input, { |
| 768 | schema = DEFAULT_SCHEMA, |
| 769 | onWarning, |
| 770 | allowDuplicateKeys = false |
| 771 | }) { |
| 772 | this.input = input; |
| 773 | this.onWarning = onWarning; |
| 774 | this.allowDuplicateKeys = allowDuplicateKeys; |
| 775 | this.implicitTypes = schema.implicitTypes; |
| 776 | this.typeMap = schema.typeMap; |
| 777 | this.length = input.length; |
| 778 | this.version = null; |
| 779 | this.readIndent(); |
| 780 | } |
| 781 | readIndent() { |
| 782 | let char = this.peek(); |
| 783 | while (char === SPACE) { |
| 784 | this.lineIndent += 1; |
| 785 | char = this.next(); |
| 786 | } |
| 787 | } |
| 788 | peek(offset = 0) { |
| 789 | return this.input.charCodeAt(this.position + offset); |
| 790 | } |
| 791 | next() { |
| 792 | this.position += 1; |
| 793 | return this.peek(); |
| 794 | } |
| 795 | #createError(message) { |
| 796 | const mark = markToString( |
| 797 | this.input, |
| 798 | this.position, |
| 799 | this.line, |
| 800 | this.position - this.lineStart |
| 801 | ); |
| 802 | return new SyntaxError(`${message} ${mark}`); |
| 803 | } |
| 804 | throwError(message) { |
| 805 | throw this.#createError(message); |
| 806 | } |
| 807 | dispatchWarning(message) { |
| 808 | const error = this.#createError(message); |
| 809 | this.onWarning?.(error); |
| 810 | } |
| 811 | yamlDirectiveHandler(...args) { |
| 812 | if (this.version !== null) { |
| 813 | return this.throwError( |
| 814 | "Cannot handle YAML directive: duplication of %YAML directive" |
| 815 | ); |
| 816 | } |
| 817 | if (args.length !== 1) { |
| 818 | return this.throwError( |
| 819 | "Cannot handle YAML directive: YAML directive accepts exactly one argument" |
| 820 | ); |
| 821 | } |
| 822 | const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]); |
| 823 | if (match === null) { |
| 824 | return this.throwError( |
| 825 | "Cannot handle YAML directive: ill-formed argument" |
| 826 | ); |
| 827 | } |
| 828 | const major = parseInt(match[1], 10); |
| 829 | const minor = parseInt(match[2], 10); |
| 830 | if (major !== 1) { |
| 831 | return this.throwError( |
| 832 | "Cannot handle YAML directive: unacceptable YAML version" |
| 833 | ); |
| 834 | } |
| 835 | this.version = args[0] ?? null; |
| 836 | this.checkLineBreaks = minor < 2; |
| 837 | if (minor !== 1 && minor !== 2) { |
| 838 | return this.dispatchWarning( |
| 839 | "Cannot handle YAML directive: unsupported YAML version" |
| 840 | ); |
| 841 | } |
| 842 | } |
| 843 | tagDirectiveHandler(...args) { |
| 844 | if (args.length !== 2) { |
| 845 | return this.throwError( |
| 846 | `Cannot handle tag directive: directive accepts exactly two arguments, received ${args.length}` |
| 847 | ); |
| 848 | } |
| 849 | const handle = args[0]; |
| 850 | const prefix = args[1]; |
| 851 | if (!PATTERN_TAG_HANDLE.test(handle)) { |
| 852 | return this.throwError( |
| 853 | `Cannot handle tag directive: ill-formed handle (first argument) in "${handle}"` |
| 854 | ); |
| 855 | } |
| 856 | if (this.tagMap.has(handle)) { |
| 857 | return this.throwError( |
| 858 | `Cannot handle tag directive: previously declared suffix for "${handle}" tag handle` |
| 859 | ); |
| 860 | } |
| 861 | if (!PATTERN_TAG_URI.test(prefix)) { |
| 862 | return this.throwError( |
| 863 | "Cannot handle tag directive: ill-formed tag prefix (second argument) of the TAG directive" |
| 864 | ); |
| 865 | } |
| 866 | this.tagMap.set(handle, prefix); |
| 867 | } |
| 868 | captureSegment(start, end, checkJson) { |
| 869 | let result; |
| 870 | if (start < end) { |
| 871 | result = this.input.slice(start, end); |
| 872 | if (checkJson) { |
| 873 | for (let position = 0; position < result.length; position++) { |
| 874 | const character2 = result.charCodeAt(position); |
| 875 | if (!(character2 === 9 || 32 <= character2 && character2 <= 1114111)) { |
| 876 | return this.throwError( |
| 877 | `Expected valid JSON character: received "${character2}"` |
| 878 | ); |
| 879 | } |
| 880 | } |
| 881 | } else if (PATTERN_NON_PRINTABLE.test(result)) { |
| 882 | return this.throwError("Stream contains non-printable characters"); |
| 883 | } |
| 884 | this.result += result; |
| 885 | } |
| 886 | } |
| 887 | readBlockSequence(nodeIndent) { |
| 888 | let line; |
| 889 | let following; |
| 890 | let detected = false; |
| 891 | let ch; |
| 892 | const tag = this.tag; |
| 893 | const anchor = this.anchor; |
| 894 | const result = []; |
| 895 | if (this.anchor !== null && typeof this.anchor !== "undefined") { |
| 896 | this.anchorMap.set(this.anchor, result); |
| 897 | } |
| 898 | ch = this.peek(); |
| 899 | while (ch !== 0) { |
| 900 | if (ch !== MINUS) { |
| 901 | break; |
| 902 | } |
| 903 | following = this.peek(1); |
| 904 | if (!isWhiteSpaceOrEOL(following)) { |
| 905 | break; |
| 906 | } |
| 907 | detected = true; |
| 908 | this.position++; |
| 909 | if (this.skipSeparationSpace(true, -1)) { |
| 910 | if (this.lineIndent <= nodeIndent) { |
| 911 | result.push(null); |
| 912 | ch = this.peek(); |
| 913 | continue; |
| 914 | } |
| 915 | } |
| 916 | line = this.line; |
| 917 | this.composeNode(nodeIndent, CONTEXT_BLOCK_IN, false, true); |
| 918 | result.push(this.result); |
| 919 | this.skipSeparationSpace(true, -1); |
| 920 | ch = this.peek(); |
| 921 | if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) { |
| 922 | return this.throwError( |
| 923 | "Cannot read block sequence: bad indentation of a sequence entry" |
| 924 | ); |
| 925 | } else if (this.lineIndent < nodeIndent) { |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | if (detected) { |
| 930 | this.tag = tag; |
| 931 | this.anchor = anchor; |
| 932 | this.kind = "sequence"; |
| 933 | this.result = result; |
| 934 | return true; |
| 935 | } |
| 936 | return false; |
| 937 | } |
| 938 | mergeMappings(destination, source, overridableKeys) { |
| 939 | if (!isObject(source)) { |
| 940 | return this.throwError( |
| 941 | "Cannot merge mappings: the provided source object is unacceptable" |
| 942 | ); |
| 943 | } |
| 944 | for (const [key, value2] of Object.entries(source)) { |
| 945 | if (Object.hasOwn(destination, key)) continue; |
| 946 | Object.defineProperty(destination, key, { |
| 947 | value: value2, |
| 948 | writable: true, |
| 949 | enumerable: true, |
| 950 | configurable: true |
| 951 | }); |
| 952 | overridableKeys.add(key); |
| 953 | } |
| 954 | } |
| 955 | storeMappingPair(result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) { |
| 956 | if (Array.isArray(keyNode)) { |
| 957 | keyNode = Array.prototype.slice.call(keyNode); |
| 958 | for (let index = 0; index < keyNode.length; index++) { |
| 959 | if (Array.isArray(keyNode[index])) { |
| 960 | return this.throwError( |
| 961 | "Cannot store mapping pair: nested arrays are not supported inside keys" |
| 962 | ); |
| 963 | } |
| 964 | if (typeof keyNode === "object" && isPlainObject(keyNode[index])) { |
| 965 | keyNode[index] = "[object Object]"; |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | if (typeof keyNode === "object" && isPlainObject(keyNode)) { |
| 970 | keyNode = "[object Object]"; |
| 971 | } |
| 972 | keyNode = String(keyNode); |
| 973 | if (keyTag === "tag:yaml.org,2002:merge") { |
| 974 | if (Array.isArray(valueNode)) { |
| 975 | for (let index = 0; index < valueNode.length; index++) { |
| 976 | this.mergeMappings(result, valueNode[index], overridableKeys); |
| 977 | } |
| 978 | } else { |
| 979 | this.mergeMappings( |
| 980 | result, |
| 981 | valueNode, |
| 982 | overridableKeys |
| 983 | ); |
| 984 | } |
| 985 | } else { |
| 986 | if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) { |
| 987 | this.line = startLine || this.line; |
| 988 | this.position = startPos || this.position; |
| 989 | return this.throwError("Cannot store mapping pair: duplicated key"); |
| 990 | } |
| 991 | Object.defineProperty(result, keyNode, { |
| 992 | value: valueNode, |
| 993 | writable: true, |
| 994 | enumerable: true, |
| 995 | configurable: true |
| 996 | }); |
| 997 | overridableKeys.delete(keyNode); |
| 998 | } |
| 999 | return result; |
| 1000 | } |
| 1001 | readLineBreak() { |
| 1002 | const ch = this.peek(); |
| 1003 | if (ch === LINE_FEED) { |
| 1004 | this.position++; |
| 1005 | } else if (ch === CARRIAGE_RETURN) { |
| 1006 | this.position++; |
| 1007 | if (this.peek() === LINE_FEED) { |
| 1008 | this.position++; |
| 1009 | } |
| 1010 | } else { |
| 1011 | return this.throwError("Cannot read line: line break not found"); |
| 1012 | } |
| 1013 | this.line += 1; |
| 1014 | this.lineStart = this.position; |
| 1015 | } |
| 1016 | skipSeparationSpace(allowComments, checkIndent) { |
| 1017 | let lineBreaks = 0; |
| 1018 | let ch = this.peek(); |
| 1019 | while (ch !== 0) { |
| 1020 | while (isWhiteSpace(ch)) { |
| 1021 | ch = this.next(); |
| 1022 | } |
| 1023 | if (allowComments && ch === SHARP) { |
| 1024 | do { |
| 1025 | ch = this.next(); |
| 1026 | } while (ch !== LINE_FEED && ch !== CARRIAGE_RETURN && ch !== 0); |
| 1027 | } |
| 1028 | if (isEOL(ch)) { |
| 1029 | this.readLineBreak(); |
| 1030 | ch = this.peek(); |
| 1031 | lineBreaks++; |
| 1032 | this.lineIndent = 0; |
| 1033 | this.readIndent(); |
| 1034 | ch = this.peek(); |
| 1035 | } else { |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | if (checkIndent !== -1 && lineBreaks !== 0 && this.lineIndent < checkIndent) { |
| 1040 | this.dispatchWarning("deficient indentation"); |
| 1041 | } |
| 1042 | return lineBreaks; |
| 1043 | } |
| 1044 | testDocumentSeparator() { |
| 1045 | let ch = this.peek(); |
| 1046 | if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) { |
| 1047 | ch = this.peek(3); |
| 1048 | if (ch === 0 || isWhiteSpaceOrEOL(ch)) { |
| 1049 | return true; |
| 1050 | } |
| 1051 | } |
| 1052 | return false; |
| 1053 | } |
| 1054 | writeFoldedLines(count) { |
| 1055 | if (count === 1) { |
| 1056 | this.result += " "; |
| 1057 | } else if (count > 1) { |
| 1058 | this.result += "\n".repeat(count - 1); |
| 1059 | } |
| 1060 | } |
| 1061 | readPlainScalar(nodeIndent, withinFlowCollection) { |
| 1062 | const kind = this.kind; |
| 1063 | const result = this.result; |
| 1064 | let ch = this.peek(); |
| 1065 | if (isWhiteSpaceOrEOL(ch) || isFlowIndicator(ch) || ch === SHARP || ch === AMPERSAND || ch === ASTERISK || ch === EXCLAMATION || ch === VERTICAL_LINE || ch === GREATER_THAN || ch === SINGLE_QUOTE || ch === DOUBLE_QUOTE || ch === PERCENT || ch === COMMERCIAL_AT || ch === GRAVE_ACCENT) { |
| 1066 | return false; |
| 1067 | } |
| 1068 | let following; |
| 1069 | if (ch === QUESTION || ch === MINUS) { |
| 1070 | following = this.peek(1); |
| 1071 | if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) { |
| 1072 | return false; |
| 1073 | } |
| 1074 | } |
| 1075 | this.kind = "scalar"; |
| 1076 | this.result = ""; |
| 1077 | let captureEnd = this.position; |
| 1078 | let captureStart = this.position; |
| 1079 | let hasPendingContent = false; |
| 1080 | let line = 0; |
| 1081 | while (ch !== 0) { |
| 1082 | if (ch === COLON) { |
| 1083 | following = this.peek(1); |
| 1084 | if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) { |
| 1085 | break; |
| 1086 | } |
| 1087 | } else if (ch === SHARP) { |
| 1088 | const preceding = this.peek(-1); |
| 1089 | if (isWhiteSpaceOrEOL(preceding)) { |
| 1090 | break; |
| 1091 | } |
| 1092 | } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) { |
| 1093 | break; |
| 1094 | } else if (isEOL(ch)) { |
| 1095 | line = this.line; |
| 1096 | const lineStart = this.lineStart; |
| 1097 | const lineIndent = this.lineIndent; |
| 1098 | this.skipSeparationSpace(false, -1); |
| 1099 | if (this.lineIndent >= nodeIndent) { |
| 1100 | hasPendingContent = true; |
| 1101 | ch = this.peek(); |
| 1102 | continue; |
| 1103 | } else { |
| 1104 | this.position = captureEnd; |
| 1105 | this.line = line; |
| 1106 | this.lineStart = lineStart; |
| 1107 | this.lineIndent = lineIndent; |
| 1108 | break; |
| 1109 | } |
| 1110 | } |
| 1111 | if (hasPendingContent) { |
| 1112 | this.captureSegment(captureStart, captureEnd, false); |
| 1113 | this.writeFoldedLines(this.line - line); |
| 1114 | captureStart = captureEnd = this.position; |
| 1115 | hasPendingContent = false; |
| 1116 | } |
| 1117 | if (!isWhiteSpace(ch)) { |
| 1118 | captureEnd = this.position + 1; |
| 1119 | } |
| 1120 | ch = this.next(); |
| 1121 | } |
| 1122 | this.captureSegment(captureStart, captureEnd, false); |
| 1123 | if (this.result) { |
| 1124 | return true; |
| 1125 | } |
| 1126 | this.kind = kind; |
| 1127 | this.result = result; |
| 1128 | return false; |
| 1129 | } |
| 1130 | readSingleQuotedScalar(nodeIndent) { |
| 1131 | let ch; |
| 1132 | let captureStart; |
| 1133 | let captureEnd; |
| 1134 | ch = this.peek(); |
| 1135 | if (ch !== SINGLE_QUOTE) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | this.kind = "scalar"; |
| 1139 | this.result = ""; |
| 1140 | this.position++; |
| 1141 | captureStart = captureEnd = this.position; |
| 1142 | while ((ch = this.peek()) !== 0) { |
| 1143 | if (ch === SINGLE_QUOTE) { |
| 1144 | this.captureSegment(captureStart, this.position, true); |
| 1145 | ch = this.next(); |
| 1146 | if (ch === SINGLE_QUOTE) { |
| 1147 | captureStart = this.position; |
| 1148 | this.position++; |
| 1149 | captureEnd = this.position; |
| 1150 | } else { |
| 1151 | return true; |
| 1152 | } |
| 1153 | } else if (isEOL(ch)) { |
| 1154 | this.captureSegment(captureStart, captureEnd, true); |
| 1155 | this.writeFoldedLines(this.skipSeparationSpace(false, nodeIndent)); |
| 1156 | captureStart = captureEnd = this.position; |
| 1157 | } else if (this.position === this.lineStart && this.testDocumentSeparator()) { |
| 1158 | return this.throwError( |
| 1159 | "Unexpected end of the document within a single quoted scalar" |
| 1160 | ); |
| 1161 | } else { |
| 1162 | this.position++; |
| 1163 | captureEnd = this.position; |
| 1164 | } |
| 1165 | } |
| 1166 | return this.throwError( |
| 1167 | "Unexpected end of the stream within a single quoted scalar" |
| 1168 | ); |
| 1169 | } |
| 1170 | readDoubleQuotedScalar(nodeIndent) { |
| 1171 | let ch = this.peek(); |
| 1172 | if (ch !== DOUBLE_QUOTE) { |
| 1173 | return false; |
| 1174 | } |
| 1175 | this.kind = "scalar"; |
| 1176 | this.result = ""; |
| 1177 | this.position++; |
| 1178 | let captureEnd = this.position; |
| 1179 | let captureStart = this.position; |
| 1180 | let tmp; |
| 1181 | while ((ch = this.peek()) !== 0) { |
| 1182 | if (ch === DOUBLE_QUOTE) { |
| 1183 | this.captureSegment(captureStart, this.position, true); |
| 1184 | this.position++; |
| 1185 | return true; |
| 1186 | } |
| 1187 | if (ch === BACKSLASH) { |
| 1188 | this.captureSegment(captureStart, this.position, true); |
| 1189 | ch = this.next(); |
| 1190 | if (isEOL(ch)) { |
| 1191 | this.skipSeparationSpace(false, nodeIndent); |
| 1192 | } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) { |
| 1193 | this.result += SIMPLE_ESCAPE_SEQUENCES.get(ch); |
| 1194 | this.position++; |
| 1195 | } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) { |
| 1196 | let hexLength = tmp; |
| 1197 | let hexResult = 0; |
| 1198 | for (; hexLength > 0; hexLength--) { |
| 1199 | ch = this.next(); |
| 1200 | if ((tmp = hexCharCodeToNumber(ch)) >= 0) { |
| 1201 | hexResult = (hexResult << 4) + tmp; |
| 1202 | } else { |
| 1203 | return this.throwError( |
| 1204 | "Cannot read double quoted scalar: expected hexadecimal character" |
| 1205 | ); |
| 1206 | } |
| 1207 | } |
| 1208 | this.result += codepointToChar(hexResult); |
| 1209 | this.position++; |
| 1210 | } else { |
| 1211 | return this.throwError( |
| 1212 | "Cannot read double quoted scalar: unknown escape sequence" |
| 1213 | ); |
| 1214 | } |
| 1215 | captureStart = captureEnd = this.position; |
| 1216 | } else if (isEOL(ch)) { |
| 1217 | this.captureSegment(captureStart, captureEnd, true); |
| 1218 | this.writeFoldedLines(this.skipSeparationSpace(false, nodeIndent)); |
| 1219 | captureStart = captureEnd = this.position; |
| 1220 | } else if (this.position === this.lineStart && this.testDocumentSeparator()) { |
| 1221 | return this.throwError( |
| 1222 | "Unexpected end of the document within a double quoted scalar" |
| 1223 | ); |
| 1224 | } else { |
| 1225 | this.position++; |
| 1226 | captureEnd = this.position; |
| 1227 | } |
| 1228 | } |
| 1229 | return this.throwError( |
| 1230 | "Unexpected end of the stream within a double quoted scalar" |
| 1231 | ); |
| 1232 | } |
| 1233 | readFlowCollection(nodeIndent) { |
| 1234 | let ch = this.peek(); |
| 1235 | let terminator; |
| 1236 | let isMapping = true; |
| 1237 | let result = {}; |
| 1238 | if (ch === LEFT_SQUARE_BRACKET) { |
| 1239 | terminator = RIGHT_SQUARE_BRACKET; |
| 1240 | isMapping = false; |
| 1241 | result = []; |
| 1242 | } else if (ch === LEFT_CURLY_BRACKET) { |
| 1243 | terminator = RIGHT_CURLY_BRACKET; |
| 1244 | } else { |
| 1245 | return false; |
| 1246 | } |
| 1247 | if (this.anchor !== null && typeof this.anchor !== "undefined") { |
| 1248 | this.anchorMap.set(this.anchor, result); |
| 1249 | } |
| 1250 | ch = this.next(); |
| 1251 | const tag = this.tag; |
| 1252 | const anchor = this.anchor; |
| 1253 | let readNext = true; |
| 1254 | let valueNode = null; |
| 1255 | let keyNode = null; |
| 1256 | let keyTag = null; |
| 1257 | let isExplicitPair = false; |
| 1258 | let isPair = false; |
| 1259 | let following = 0; |
| 1260 | let line = 0; |
| 1261 | const overridableKeys = /* @__PURE__ */ new Set(); |
| 1262 | while (ch !== 0) { |
| 1263 | this.skipSeparationSpace(true, nodeIndent); |
| 1264 | ch = this.peek(); |
| 1265 | if (ch === terminator) { |
| 1266 | this.position++; |
| 1267 | this.tag = tag; |
| 1268 | this.anchor = anchor; |
| 1269 | this.kind = isMapping ? "mapping" : "sequence"; |
| 1270 | this.result = result; |
| 1271 | return true; |
| 1272 | } |
| 1273 | if (!readNext) { |
| 1274 | return this.throwError( |
| 1275 | "Cannot read flow collection: missing comma between flow collection entries" |
| 1276 | ); |
| 1277 | } |
| 1278 | keyTag = keyNode = valueNode = null; |
| 1279 | isPair = isExplicitPair = false; |
| 1280 | if (ch === QUESTION) { |
| 1281 | following = this.peek(1); |
| 1282 | if (isWhiteSpaceOrEOL(following)) { |
| 1283 | isPair = isExplicitPair = true; |
| 1284 | this.position++; |
| 1285 | this.skipSeparationSpace(true, nodeIndent); |
| 1286 | } |
| 1287 | } |
| 1288 | line = this.line; |
| 1289 | this.composeNode(nodeIndent, CONTEXT_FLOW_IN, false, true); |
| 1290 | keyTag = this.tag || null; |
| 1291 | keyNode = this.result; |
| 1292 | this.skipSeparationSpace(true, nodeIndent); |
| 1293 | ch = this.peek(); |
| 1294 | if ((isExplicitPair || this.line === line) && ch === COLON) { |
| 1295 | isPair = true; |
| 1296 | ch = this.next(); |
| 1297 | this.skipSeparationSpace(true, nodeIndent); |
| 1298 | this.composeNode(nodeIndent, CONTEXT_FLOW_IN, false, true); |
| 1299 | valueNode = this.result; |
| 1300 | } |
| 1301 | if (isMapping) { |
| 1302 | this.storeMappingPair( |
| 1303 | result, |
| 1304 | overridableKeys, |
| 1305 | keyTag, |
| 1306 | keyNode, |
| 1307 | valueNode |
| 1308 | ); |
| 1309 | } else if (isPair) { |
| 1310 | result.push( |
| 1311 | this.storeMappingPair( |
| 1312 | {}, |
| 1313 | overridableKeys, |
| 1314 | keyTag, |
| 1315 | keyNode, |
| 1316 | valueNode |
| 1317 | ) |
| 1318 | ); |
| 1319 | } else { |
| 1320 | result.push(keyNode); |
| 1321 | } |
| 1322 | this.skipSeparationSpace(true, nodeIndent); |
| 1323 | ch = this.peek(); |
| 1324 | if (ch === COMMA) { |
| 1325 | readNext = true; |
| 1326 | ch = this.next(); |
| 1327 | } else { |
| 1328 | readNext = false; |
| 1329 | } |
| 1330 | } |
| 1331 | return this.throwError( |
| 1332 | "Cannot read flow collection: unexpected end of the stream within a flow collection" |
| 1333 | ); |
| 1334 | } |
| 1335 | // Handles block scaler styles: e.g. '|', '>', '|-' and '>-'. |
| 1336 | // https://yaml.org/spec/1.2.2/#81-block-scalar-styles |
| 1337 | readBlockScalar(nodeIndent) { |
| 1338 | let chomping = CHOMPING_CLIP; |
| 1339 | let didReadContent = false; |
| 1340 | let detectedIndent = false; |
| 1341 | let textIndent = nodeIndent; |
| 1342 | let emptyLines = 0; |
| 1343 | let atMoreIndented = false; |
| 1344 | let ch = this.peek(); |
| 1345 | let folding = false; |
| 1346 | if (ch === VERTICAL_LINE) { |
| 1347 | folding = false; |
| 1348 | } else if (ch === GREATER_THAN) { |
| 1349 | folding = true; |
| 1350 | } else { |
| 1351 | return false; |
| 1352 | } |
| 1353 | this.kind = "scalar"; |
| 1354 | this.result = ""; |
| 1355 | let tmp = 0; |
| 1356 | while (ch !== 0) { |
| 1357 | ch = this.next(); |
| 1358 | if (ch === PLUS || ch === MINUS) { |
| 1359 | if (CHOMPING_CLIP === chomping) { |
| 1360 | chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP; |
| 1361 | } else { |
| 1362 | return this.throwError( |
| 1363 | "Cannot read block: chomping mode identifier repeated" |
| 1364 | ); |
| 1365 | } |
| 1366 | } else if ((tmp = decimalCharCodeToNumber(ch)) >= 0) { |
| 1367 | if (tmp === 0) { |
| 1368 | return this.throwError( |
| 1369 | "Cannot read block: indentation width must be greater than 0" |
| 1370 | ); |
| 1371 | } else if (!detectedIndent) { |
| 1372 | textIndent = nodeIndent + tmp - 1; |
| 1373 | detectedIndent = true; |
| 1374 | } else { |
| 1375 | return this.throwError( |
| 1376 | "Cannot read block: indentation width identifier repeated" |
| 1377 | ); |
| 1378 | } |
| 1379 | } else { |
| 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | if (isWhiteSpace(ch)) { |
| 1384 | do { |
| 1385 | ch = this.next(); |
| 1386 | } while (isWhiteSpace(ch)); |
| 1387 | if (ch === SHARP) { |
| 1388 | do { |
| 1389 | ch = this.next(); |
| 1390 | } while (!isEOL(ch) && ch !== 0); |
| 1391 | } |
| 1392 | } |
| 1393 | while (ch !== 0) { |
| 1394 | this.readLineBreak(); |
| 1395 | this.lineIndent = 0; |
| 1396 | ch = this.peek(); |
| 1397 | while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) { |
| 1398 | this.lineIndent++; |
| 1399 | ch = this.next(); |
| 1400 | } |
| 1401 | if (!detectedIndent && this.lineIndent > textIndent) { |
| 1402 | textIndent = this.lineIndent; |
| 1403 | } |
| 1404 | if (isEOL(ch)) { |
| 1405 | emptyLines++; |
| 1406 | continue; |
| 1407 | } |
| 1408 | if (this.lineIndent < textIndent) { |
| 1409 | if (chomping === CHOMPING_KEEP) { |
| 1410 | this.result += "\n".repeat( |
| 1411 | didReadContent ? 1 + emptyLines : emptyLines |
| 1412 | ); |
| 1413 | } else if (chomping === CHOMPING_CLIP) { |
| 1414 | if (didReadContent) { |
| 1415 | this.result += "\n"; |
| 1416 | } |
| 1417 | } |
| 1418 | break; |
| 1419 | } |
| 1420 | if (folding) { |
| 1421 | if (isWhiteSpace(ch)) { |
| 1422 | atMoreIndented = true; |
| 1423 | this.result += "\n".repeat( |
| 1424 | didReadContent ? 1 + emptyLines : emptyLines |
| 1425 | ); |
| 1426 | } else if (atMoreIndented) { |
| 1427 | atMoreIndented = false; |
| 1428 | this.result += "\n".repeat(emptyLines + 1); |
| 1429 | } else if (emptyLines === 0) { |
| 1430 | if (didReadContent) { |
| 1431 | this.result += " "; |
| 1432 | } |
| 1433 | } else { |
| 1434 | this.result += "\n".repeat(emptyLines); |
| 1435 | } |
| 1436 | } else { |
| 1437 | this.result += "\n".repeat( |
| 1438 | didReadContent ? 1 + emptyLines : emptyLines |
| 1439 | ); |
| 1440 | } |
| 1441 | didReadContent = true; |
| 1442 | detectedIndent = true; |
| 1443 | emptyLines = 0; |
| 1444 | const captureStart = this.position; |
| 1445 | while (!isEOL(ch) && ch !== 0) { |
| 1446 | ch = this.next(); |
| 1447 | } |
| 1448 | this.captureSegment(captureStart, this.position, false); |
| 1449 | } |
| 1450 | return true; |
| 1451 | } |
| 1452 | readBlockMapping(nodeIndent, flowIndent) { |
| 1453 | const tag = this.tag; |
| 1454 | const anchor = this.anchor; |
| 1455 | const result = {}; |
| 1456 | const overridableKeys = /* @__PURE__ */ new Set(); |
| 1457 | let following; |
| 1458 | let allowCompact = false; |
| 1459 | let line; |
| 1460 | let pos; |
| 1461 | let keyTag = null; |
| 1462 | let keyNode = null; |
| 1463 | let valueNode = null; |
| 1464 | let atExplicitKey = false; |
| 1465 | let detected = false; |
| 1466 | let ch; |
| 1467 | if (this.anchor !== null && typeof this.anchor !== "undefined") { |
| 1468 | this.anchorMap.set(this.anchor, result); |
| 1469 | } |
| 1470 | ch = this.peek(); |
| 1471 | while (ch !== 0) { |
| 1472 | following = this.peek(1); |
| 1473 | line = this.line; |
| 1474 | pos = this.position; |
| 1475 | if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) { |
| 1476 | if (ch === QUESTION) { |
| 1477 | if (atExplicitKey) { |
| 1478 | this.storeMappingPair( |
| 1479 | result, |
| 1480 | overridableKeys, |
| 1481 | keyTag, |
| 1482 | keyNode, |
| 1483 | null |
| 1484 | ); |
| 1485 | keyTag = keyNode = valueNode = null; |
| 1486 | } |
| 1487 | detected = true; |
| 1488 | atExplicitKey = true; |
| 1489 | allowCompact = true; |
| 1490 | } else if (atExplicitKey) { |
| 1491 | atExplicitKey = false; |
| 1492 | allowCompact = true; |
| 1493 | } else { |
| 1494 | return this.throwError( |
| 1495 | "Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line" |
| 1496 | ); |
| 1497 | } |
| 1498 | this.position += 1; |
| 1499 | ch = following; |
| 1500 | } else if (this.composeNode(flowIndent, CONTEXT_FLOW_OUT, false, true)) { |
| 1501 | if (this.line === line) { |
| 1502 | ch = this.peek(); |
| 1503 | while (isWhiteSpace(ch)) { |
| 1504 | ch = this.next(); |
| 1505 | } |
| 1506 | if (ch === COLON) { |
| 1507 | ch = this.next(); |
| 1508 | if (!isWhiteSpaceOrEOL(ch)) { |
| 1509 | return this.throwError( |
| 1510 | "Cannot read block: a whitespace character is expected after the key-value separator within a block mapping" |
| 1511 | ); |
| 1512 | } |
| 1513 | if (atExplicitKey) { |
| 1514 | this.storeMappingPair( |
| 1515 | result, |
| 1516 | overridableKeys, |
| 1517 | keyTag, |
| 1518 | keyNode, |
| 1519 | null |
| 1520 | ); |
| 1521 | keyTag = keyNode = valueNode = null; |
| 1522 | } |
| 1523 | detected = true; |
| 1524 | atExplicitKey = false; |
| 1525 | allowCompact = false; |
| 1526 | keyTag = this.tag; |
| 1527 | keyNode = this.result; |
| 1528 | } else if (detected) { |
| 1529 | return this.throwError( |
| 1530 | "Cannot read an implicit mapping pair: missing colon" |
| 1531 | ); |
| 1532 | } else { |
| 1533 | this.tag = tag; |
| 1534 | this.anchor = anchor; |
| 1535 | return true; |
| 1536 | } |
| 1537 | } else if (detected) { |
| 1538 | return this.throwError( |
| 1539 | "Cannot read a block mapping entry: a multiline key may not be an implicit key" |
| 1540 | ); |
| 1541 | } else { |
| 1542 | this.tag = tag; |
| 1543 | this.anchor = anchor; |
| 1544 | return true; |
| 1545 | } |
| 1546 | } else { |
| 1547 | break; |
| 1548 | } |
| 1549 | if (this.line === line || this.lineIndent > nodeIndent) { |
| 1550 | if (this.composeNode(nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { |
| 1551 | if (atExplicitKey) { |
| 1552 | keyNode = this.result; |
| 1553 | } else { |
| 1554 | valueNode = this.result; |
| 1555 | } |
| 1556 | } |
| 1557 | if (!atExplicitKey) { |
| 1558 | this.storeMappingPair( |
| 1559 | result, |
| 1560 | overridableKeys, |
| 1561 | keyTag, |
| 1562 | keyNode, |
| 1563 | valueNode, |
| 1564 | line, |
| 1565 | pos |
| 1566 | ); |
| 1567 | keyTag = keyNode = valueNode = null; |
| 1568 | } |
| 1569 | this.skipSeparationSpace(true, -1); |
| 1570 | ch = this.peek(); |
| 1571 | } |
| 1572 | if (this.lineIndent > nodeIndent && ch !== 0) { |
| 1573 | return this.throwError( |
| 1574 | "Cannot read block: bad indentation of a mapping entry" |
| 1575 | ); |
| 1576 | } else if (this.lineIndent < nodeIndent) { |
| 1577 | break; |
| 1578 | } |
| 1579 | } |
| 1580 | if (atExplicitKey) { |
| 1581 | this.storeMappingPair( |
| 1582 | result, |
| 1583 | overridableKeys, |
| 1584 | keyTag, |
| 1585 | keyNode, |
| 1586 | null |
| 1587 | ); |
| 1588 | } |
| 1589 | if (detected) { |
| 1590 | this.tag = tag; |
| 1591 | this.anchor = anchor; |
| 1592 | this.kind = "mapping"; |
| 1593 | this.result = result; |
| 1594 | } |
| 1595 | return detected; |
| 1596 | } |
| 1597 | readTagProperty() { |
| 1598 | let position; |
| 1599 | let isVerbatim = false; |
| 1600 | let isNamed = false; |
| 1601 | let tagHandle = ""; |
| 1602 | let tagName; |
| 1603 | let ch; |
| 1604 | ch = this.peek(); |
| 1605 | if (ch !== EXCLAMATION) return false; |
| 1606 | if (this.tag !== null) { |
| 1607 | return this.throwError( |
| 1608 | "Cannot read tag property: duplication of a tag property" |
| 1609 | ); |
| 1610 | } |
| 1611 | ch = this.next(); |
| 1612 | if (ch === SMALLER_THAN) { |
| 1613 | isVerbatim = true; |
| 1614 | ch = this.next(); |
| 1615 | } else if (ch === EXCLAMATION) { |
| 1616 | isNamed = true; |
| 1617 | tagHandle = "!!"; |
| 1618 | ch = this.next(); |
| 1619 | } else { |
| 1620 | tagHandle = "!"; |
| 1621 | } |
| 1622 | position = this.position; |
| 1623 | if (isVerbatim) { |
| 1624 | do { |
| 1625 | ch = this.next(); |
| 1626 | } while (ch !== 0 && ch !== GREATER_THAN); |
| 1627 | if (this.position < this.length) { |
| 1628 | tagName = this.input.slice(position, this.position); |
| 1629 | ch = this.next(); |
| 1630 | } else { |
| 1631 | return this.throwError( |
| 1632 | "Cannot read tag property: unexpected end of stream" |
| 1633 | ); |
| 1634 | } |
| 1635 | } else { |
| 1636 | while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) { |
| 1637 | if (ch === EXCLAMATION) { |
| 1638 | if (!isNamed) { |
| 1639 | tagHandle = this.input.slice(position - 1, this.position + 1); |
| 1640 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) { |
| 1641 | return this.throwError( |
| 1642 | "Cannot read tag property: named tag handle contains invalid characters" |
| 1643 | ); |
| 1644 | } |
| 1645 | isNamed = true; |
| 1646 | position = this.position + 1; |
| 1647 | } else { |
| 1648 | return this.throwError( |
| 1649 | "Cannot read tag property: tag suffix cannot contain an exclamation mark" |
| 1650 | ); |
| 1651 | } |
| 1652 | } |
| 1653 | ch = this.next(); |
| 1654 | } |
| 1655 | tagName = this.input.slice(position, this.position); |
| 1656 | if (PATTERN_FLOW_INDICATORS.test(tagName)) { |
| 1657 | return this.throwError( |
| 1658 | "Cannot read tag property: tag suffix cannot contain flow indicator characters" |
| 1659 | ); |
| 1660 | } |
| 1661 | } |
| 1662 | if (tagName && !PATTERN_TAG_URI.test(tagName)) { |
| 1663 | return this.throwError( |
| 1664 | `Cannot read tag property: invalid characters in tag name "${tagName}"` |
| 1665 | ); |
| 1666 | } |
| 1667 | if (isVerbatim) { |
| 1668 | this.tag = tagName; |
| 1669 | } else if (this.tagMap.has(tagHandle)) { |
| 1670 | this.tag = this.tagMap.get(tagHandle) + tagName; |
| 1671 | } else if (tagHandle === "!") { |
| 1672 | this.tag = `!${tagName}`; |
| 1673 | } else if (tagHandle === "!!") { |
| 1674 | this.tag = `tag:yaml.org,2002:${tagName}`; |
| 1675 | } else { |
| 1676 | return this.throwError( |
| 1677 | `Cannot read tag property: undeclared tag handle "${tagHandle}"` |
| 1678 | ); |
| 1679 | } |
| 1680 | return true; |
| 1681 | } |
| 1682 | readAnchorProperty() { |
| 1683 | let ch = this.peek(); |
| 1684 | if (ch !== AMPERSAND) return false; |
| 1685 | if (this.anchor !== null) { |
| 1686 | return this.throwError( |
| 1687 | "Cannot read anchor property: duplicate anchor property" |
| 1688 | ); |
| 1689 | } |
| 1690 | ch = this.next(); |
| 1691 | const position = this.position; |
| 1692 | while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) { |
| 1693 | ch = this.next(); |
| 1694 | } |
| 1695 | if (this.position === position) { |
| 1696 | return this.throwError( |
| 1697 | "Cannot read anchor property: name of an anchor node must contain at least one character" |
| 1698 | ); |
| 1699 | } |
| 1700 | this.anchor = this.input.slice(position, this.position); |
| 1701 | return true; |
| 1702 | } |
| 1703 | readAlias() { |
| 1704 | if (this.peek() !== ASTERISK) return false; |
| 1705 | let ch = this.next(); |
| 1706 | const position = this.position; |
| 1707 | while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) { |
| 1708 | ch = this.next(); |
| 1709 | } |
| 1710 | if (this.position === position) { |
| 1711 | return this.throwError( |
| 1712 | "Cannot read alias: alias name must contain at least one character" |
| 1713 | ); |
| 1714 | } |
| 1715 | const alias = this.input.slice(position, this.position); |
| 1716 | if (!this.anchorMap.has(alias)) { |
| 1717 | return this.throwError( |
| 1718 | `Cannot read alias: unidentified alias "${alias}"` |
| 1719 | ); |
| 1720 | } |
| 1721 | this.result = this.anchorMap.get(alias); |
| 1722 | this.skipSeparationSpace(true, -1); |
| 1723 | return true; |
| 1724 | } |
| 1725 | composeNode(parentIndent, nodeContext, allowToSeek, allowCompact) { |
| 1726 | let allowBlockScalars; |
| 1727 | let allowBlockCollections; |
| 1728 | let indentStatus = 1; |
| 1729 | let atNewLine = false; |
| 1730 | let hasContent = false; |
| 1731 | let type; |
| 1732 | let flowIndent; |
| 1733 | let blockIndent; |
| 1734 | this.tag = null; |
| 1735 | this.anchor = null; |
| 1736 | this.kind = null; |
| 1737 | this.result = null; |
| 1738 | const allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext; |
| 1739 | if (allowToSeek) { |
| 1740 | if (this.skipSeparationSpace(true, -1)) { |
| 1741 | atNewLine = true; |
| 1742 | if (this.lineIndent > parentIndent) { |
| 1743 | indentStatus = 1; |
| 1744 | } else if (this.lineIndent === parentIndent) { |
| 1745 | indentStatus = 0; |
| 1746 | } else if (this.lineIndent < parentIndent) { |
| 1747 | indentStatus = -1; |
| 1748 | } |
| 1749 | } |
| 1750 | } |
| 1751 | if (indentStatus === 1) { |
| 1752 | while (this.readTagProperty() || this.readAnchorProperty()) { |
| 1753 | if (this.skipSeparationSpace(true, -1)) { |
| 1754 | atNewLine = true; |
| 1755 | allowBlockCollections = allowBlockStyles; |
| 1756 | if (this.lineIndent > parentIndent) { |
| 1757 | indentStatus = 1; |
| 1758 | } else if (this.lineIndent === parentIndent) { |
| 1759 | indentStatus = 0; |
| 1760 | } else if (this.lineIndent < parentIndent) { |
| 1761 | indentStatus = -1; |
| 1762 | } |
| 1763 | } else { |
| 1764 | allowBlockCollections = false; |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | if (allowBlockCollections) { |
| 1769 | allowBlockCollections = atNewLine || allowCompact; |
| 1770 | } |
| 1771 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) { |
| 1772 | const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext; |
| 1773 | flowIndent = cond ? parentIndent : parentIndent + 1; |
| 1774 | blockIndent = this.position - this.lineStart; |
| 1775 | if (indentStatus === 1) { |
| 1776 | if (allowBlockCollections && (this.readBlockSequence(blockIndent) || this.readBlockMapping(blockIndent, flowIndent)) || this.readFlowCollection(flowIndent)) { |
| 1777 | hasContent = true; |
| 1778 | } else { |
| 1779 | if (allowBlockScalars && this.readBlockScalar(flowIndent) || this.readSingleQuotedScalar(flowIndent) || this.readDoubleQuotedScalar(flowIndent)) { |
| 1780 | hasContent = true; |
| 1781 | } else if (this.readAlias()) { |
| 1782 | hasContent = true; |
| 1783 | if (this.tag !== null || this.anchor !== null) { |
| 1784 | return this.throwError( |
| 1785 | "Cannot compose node: alias node should not have any properties" |
| 1786 | ); |
| 1787 | } |
| 1788 | } else if (this.readPlainScalar(flowIndent, CONTEXT_FLOW_IN === nodeContext)) { |
| 1789 | hasContent = true; |
| 1790 | if (this.tag === null) { |
| 1791 | this.tag = "?"; |
| 1792 | } |
| 1793 | } |
| 1794 | if (this.anchor !== null) { |
| 1795 | this.anchorMap.set(this.anchor, this.result); |
| 1796 | } |
| 1797 | } |
| 1798 | } else if (indentStatus === 0) { |
| 1799 | hasContent = allowBlockCollections && this.readBlockSequence(blockIndent); |
| 1800 | } |
| 1801 | } |
| 1802 | if (this.tag !== null && this.tag !== "!") { |
| 1803 | if (this.tag === "?") { |
| 1804 | for (let typeIndex = 0; typeIndex < this.implicitTypes.length; typeIndex++) { |
| 1805 | type = this.implicitTypes[typeIndex]; |
| 1806 | if (type.resolve(this.result)) { |
| 1807 | this.result = type.construct(this.result); |
| 1808 | this.tag = type.tag; |
| 1809 | if (this.anchor !== null) { |
| 1810 | this.anchorMap.set(this.anchor, this.result); |
| 1811 | } |
| 1812 | break; |
| 1813 | } |
| 1814 | } |
| 1815 | } else if (this.typeMap[this.kind ?? "fallback"].has(this.tag)) { |
| 1816 | const map2 = this.typeMap[this.kind ?? "fallback"]; |
| 1817 | type = map2.get(this.tag); |
| 1818 | if (this.result !== null && type.kind !== this.kind) { |
| 1819 | return this.throwError( |
| 1820 | `Unacceptable node kind for !<${this.tag}> tag: it should be "${type.kind}", not "${this.kind}"` |
| 1821 | ); |
| 1822 | } |
| 1823 | if (!type.resolve(this.result)) { |
| 1824 | return this.throwError( |
| 1825 | `Cannot resolve a node with !<${this.tag}> explicit tag` |
| 1826 | ); |
| 1827 | } else { |
| 1828 | this.result = type.construct(this.result); |
| 1829 | if (this.anchor !== null) { |
| 1830 | this.anchorMap.set(this.anchor, this.result); |
| 1831 | } |
| 1832 | } |
| 1833 | } else { |
| 1834 | return this.throwError(`Cannot resolve unknown tag !<${this.tag}>`); |
| 1835 | } |
| 1836 | } |
| 1837 | return this.tag !== null || this.anchor !== null || hasContent; |
| 1838 | } |
| 1839 | readDocument() { |
| 1840 | const documentStart = this.position; |
| 1841 | let position; |
| 1842 | let directiveName; |
| 1843 | let directiveArgs; |
| 1844 | let hasDirectives = false; |
| 1845 | let ch; |
| 1846 | this.version = null; |
| 1847 | this.checkLineBreaks = false; |
| 1848 | this.tagMap = /* @__PURE__ */ new Map(); |
| 1849 | this.anchorMap = /* @__PURE__ */ new Map(); |
| 1850 | while ((ch = this.peek()) !== 0) { |
| 1851 | this.skipSeparationSpace(true, -1); |
| 1852 | ch = this.peek(); |
| 1853 | if (this.lineIndent > 0 || ch !== PERCENT) { |
| 1854 | break; |
| 1855 | } |
| 1856 | hasDirectives = true; |
| 1857 | ch = this.next(); |
| 1858 | position = this.position; |
| 1859 | while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) { |
| 1860 | ch = this.next(); |
| 1861 | } |
| 1862 | directiveName = this.input.slice(position, this.position); |
| 1863 | directiveArgs = []; |
| 1864 | if (directiveName.length < 1) { |
| 1865 | return this.throwError( |
| 1866 | "Cannot read document: directive name length must be greater than zero" |
| 1867 | ); |
| 1868 | } |
| 1869 | while (ch !== 0) { |
| 1870 | while (isWhiteSpace(ch)) { |
| 1871 | ch = this.next(); |
| 1872 | } |
| 1873 | if (ch === SHARP) { |
| 1874 | do { |
| 1875 | ch = this.next(); |
| 1876 | } while (ch !== 0 && !isEOL(ch)); |
| 1877 | break; |
| 1878 | } |
| 1879 | if (isEOL(ch)) break; |
| 1880 | position = this.position; |
| 1881 | while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) { |
| 1882 | ch = this.next(); |
| 1883 | } |
| 1884 | directiveArgs.push(this.input.slice(position, this.position)); |
| 1885 | } |
| 1886 | if (ch !== 0) this.readLineBreak(); |
| 1887 | switch (directiveName) { |
| 1888 | case "YAML": |
| 1889 | this.yamlDirectiveHandler(...directiveArgs); |
| 1890 | break; |
| 1891 | case "TAG": |
| 1892 | this.tagDirectiveHandler(...directiveArgs); |
| 1893 | break; |
| 1894 | default: |
| 1895 | this.dispatchWarning( |
| 1896 | `unknown document directive "${directiveName}"` |
| 1897 | ); |
| 1898 | break; |
| 1899 | } |
| 1900 | } |
| 1901 | this.skipSeparationSpace(true, -1); |
| 1902 | if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) { |
| 1903 | this.position += 3; |
| 1904 | this.skipSeparationSpace(true, -1); |
| 1905 | } else if (hasDirectives) { |
| 1906 | return this.throwError( |
| 1907 | "Cannot read document: directives end mark is expected" |
| 1908 | ); |
| 1909 | } |
| 1910 | this.composeNode(this.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true); |
| 1911 | this.skipSeparationSpace(true, -1); |
| 1912 | if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test( |
| 1913 | this.input.slice(documentStart, this.position) |
| 1914 | )) { |
| 1915 | this.dispatchWarning("non-ASCII line breaks are interpreted as content"); |
| 1916 | } |
| 1917 | if (this.position === this.lineStart && this.testDocumentSeparator()) { |
| 1918 | if (this.peek() === DOT) { |
| 1919 | this.position += 3; |
| 1920 | this.skipSeparationSpace(true, -1); |
| 1921 | } |
| 1922 | } else if (this.position < this.length - 1) { |
| 1923 | return this.throwError( |
| 1924 | "Cannot read document: end of the stream or a document separator is expected" |
| 1925 | ); |
| 1926 | } |
| 1927 | return this.result; |
| 1928 | } |
| 1929 | *readDocuments() { |
| 1930 | while (this.position < this.length - 1) { |
| 1931 | yield this.readDocument(); |
| 1932 | } |
| 1933 | } |
| 1934 | }; |
| 1935 | |
| 1936 | // https://jsr.io/@std/yaml/1.0.5/parse.ts |
| 1937 | function sanitizeInput(input) { |
| 1938 | input = String(input); |
| 1939 | if (input.length > 0) { |
| 1940 | if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n"; |
| 1941 | if (input.charCodeAt(0) === 65279) input = input.slice(1); |
| 1942 | } |
| 1943 | input += "\0"; |
| 1944 | return input; |
| 1945 | } |
| 1946 | function parse(content, options = {}) { |
| 1947 | content = sanitizeInput(content); |
| 1948 | const state = new LoaderState(content, { |
| 1949 | ...options, |
| 1950 | schema: SCHEMA_MAP.get(options.schema) |
| 1951 | }); |
| 1952 | const documentGenerator = state.readDocuments(); |
| 1953 | const document = documentGenerator.next().value; |
| 1954 | if (!documentGenerator.next().done) { |
| 1955 | throw new SyntaxError( |
| 1956 | "Found more than 1 document in the stream: expected a single document" |
| 1957 | ); |
| 1958 | } |
| 1959 | return document ?? null; |
| 1960 | } |
| 1961 | |
| 1962 | // https://jsr.io/@std/yaml/1.0.5/_dumper_state.ts |
| 1963 | var STYLE_PLAIN = 1; |
| 1964 | var STYLE_SINGLE = 2; |
| 1965 | var STYLE_LITERAL = 3; |
| 1966 | var STYLE_FOLDED = 4; |
| 1967 | var STYLE_DOUBLE = 5; |
| 1968 | var LEADING_SPACE_REGEXP = /^\n* /; |
| 1969 | var ESCAPE_SEQUENCES = /* @__PURE__ */ new Map([ |
| 1970 | [0, "\\0"], |
| 1971 | [7, "\\a"], |
| 1972 | [8, "\\b"], |
| 1973 | [9, "\\t"], |
| 1974 | [10, "\\n"], |
| 1975 | [11, "\\v"], |
| 1976 | [12, "\\f"], |
| 1977 | [13, "\\r"], |
| 1978 | [27, "\\e"], |
| 1979 | [34, '\\"'], |
| 1980 | [92, "\\\\"], |
| 1981 | [133, "\\N"], |
| 1982 | [160, "\\_"], |
| 1983 | [8232, "\\L"], |
| 1984 | [8233, "\\P"] |
| 1985 | ]); |
| 1986 | var DEPRECATED_BOOLEANS_SYNTAX = [ |
| 1987 | "y", |
| 1988 | "Y", |
| 1989 | "yes", |
| 1990 | "Yes", |
| 1991 | "YES", |
| 1992 | "on", |
| 1993 | "On", |
| 1994 | "ON", |
| 1995 | "n", |
| 1996 | "N", |
| 1997 | "no", |
| 1998 | "No", |
| 1999 | "NO", |
| 2000 | "off", |
| 2001 | "Off", |
| 2002 | "OFF" |
| 2003 | ]; |
| 2004 | function charCodeToHexString(charCode) { |
| 2005 | const hexString = charCode.toString(16).toUpperCase(); |
| 2006 | if (charCode <= 255) return `\\x${hexString.padStart(2, "0")}`; |
| 2007 | if (charCode <= 65535) return `\\u${hexString.padStart(4, "0")}`; |
| 2008 | if (charCode <= 4294967295) return `\\U${hexString.padStart(8, "0")}`; |
| 2009 | throw new Error( |
| 2010 | "Code point within a string may not be greater than 0xFFFFFFFF" |
| 2011 | ); |
| 2012 | } |
| 2013 | function createStyleMap(map2) { |
| 2014 | const result = /* @__PURE__ */ new Map(); |
| 2015 | for (let tag of Object.keys(map2)) { |
| 2016 | const style = String(map2[tag]); |
| 2017 | if (tag.slice(0, 2) === "!!") { |
| 2018 | tag = `tag:yaml.org,2002:${tag.slice(2)}`; |
| 2019 | } |
| 2020 | result.set(tag, style); |
| 2021 | } |
| 2022 | return result; |
| 2023 | } |
| 2024 | function indentString(string, spaces) { |
| 2025 | const indent = " ".repeat(spaces); |
| 2026 | return string.split("\n").map((line) => line.length ? indent + line : line).join("\n"); |
| 2027 | } |
| 2028 | function generateNextLine(indent, level) { |
| 2029 | return ` |
| 2030 | ${" ".repeat(indent * level)}`; |
| 2031 | } |
| 2032 | function isPrintable(c) { |
| 2033 | return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== BOM || 65536 <= c && c <= 1114111; |
| 2034 | } |
| 2035 | function isPlainSafe(c) { |
| 2036 | return isPrintable(c) && c !== BOM && c !== COMMA && c !== LEFT_SQUARE_BRACKET && c !== RIGHT_SQUARE_BRACKET && c !== LEFT_CURLY_BRACKET && c !== RIGHT_CURLY_BRACKET && c !== COLON && c !== SHARP; |
| 2037 | } |
| 2038 | function isPlainSafeFirst(c) { |
| 2039 | return isPlainSafe(c) && !isWhiteSpace(c) && c !== MINUS && c !== QUESTION && c !== AMPERSAND && c !== ASTERISK && c !== EXCLAMATION && c !== VERTICAL_LINE && c !== GREATER_THAN && c !== SINGLE_QUOTE && c !== DOUBLE_QUOTE && c !== PERCENT && c !== COMMERCIAL_AT && c !== GRAVE_ACCENT; |
| 2040 | } |
| 2041 | function needIndentIndicator(string) { |
| 2042 | return LEADING_SPACE_REGEXP.test(string); |
| 2043 | } |
| 2044 | function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, implicitTypes) { |
| 2045 | const shouldTrackWidth = lineWidth !== -1; |
| 2046 | let hasLineBreak = false; |
| 2047 | let hasFoldableLine = false; |
| 2048 | let previousLineBreak = -1; |
| 2049 | let plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhiteSpace(string.charCodeAt(string.length - 1)); |
| 2050 | let char; |
| 2051 | let i; |
| 2052 | if (singleLineOnly) { |
| 2053 | for (i = 0; i < string.length; i++) { |
| 2054 | char = string.charCodeAt(i); |
| 2055 | if (!isPrintable(char)) { |
| 2056 | return STYLE_DOUBLE; |
| 2057 | } |
| 2058 | plain = plain && isPlainSafe(char); |
| 2059 | } |
| 2060 | } else { |
| 2061 | for (i = 0; i < string.length; i++) { |
| 2062 | char = string.charCodeAt(i); |
| 2063 | if (char === LINE_FEED) { |
| 2064 | hasLineBreak = true; |
| 2065 | if (shouldTrackWidth) { |
| 2066 | hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented. |
| 2067 | i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "; |
| 2068 | previousLineBreak = i; |
| 2069 | } |
| 2070 | } else if (!isPrintable(char)) { |
| 2071 | return STYLE_DOUBLE; |
| 2072 | } |
| 2073 | plain = plain && isPlainSafe(char); |
| 2074 | } |
| 2075 | hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "; |
| 2076 | } |
| 2077 | if (!hasLineBreak && !hasFoldableLine) { |
| 2078 | return plain && !implicitTypes.some((type) => type.resolve(string)) ? STYLE_PLAIN : STYLE_SINGLE; |
| 2079 | } |
| 2080 | if (indentPerLevel > 9 && needIndentIndicator(string)) { |
| 2081 | return STYLE_DOUBLE; |
| 2082 | } |
| 2083 | return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; |
| 2084 | } |
| 2085 | function foldLine(line, width) { |
| 2086 | if (line === "" || line[0] === " ") return line; |
| 2087 | const breakRegExp = / [^ ]/g; |
| 2088 | let start = 0; |
| 2089 | let end; |
| 2090 | let curr = 0; |
| 2091 | let next = 0; |
| 2092 | const lines = []; |
| 2093 | for (const match of line.matchAll(breakRegExp)) { |
| 2094 | next = match.index; |
| 2095 | if (next - start > width) { |
| 2096 | end = curr > start ? curr : next; |
| 2097 | lines.push(line.slice(start, end)); |
| 2098 | start = end + 1; |
| 2099 | } |
| 2100 | curr = next; |
| 2101 | } |
| 2102 | if (line.length - start > width && curr > start) { |
| 2103 | lines.push(line.slice(start, curr)); |
| 2104 | lines.push(line.slice(curr + 1)); |
| 2105 | } else { |
| 2106 | lines.push(line.slice(start)); |
| 2107 | } |
| 2108 | return lines.join("\n"); |
| 2109 | } |
| 2110 | function trimTrailingNewline(string) { |
| 2111 | return string.at(-1) === "\n" ? string.slice(0, -1) : string; |
| 2112 | } |
| 2113 | function foldString(string, width) { |
| 2114 | const lineRe = /(\n+)([^\n]*)/g; |
| 2115 | let result = (() => { |
| 2116 | let nextLF = string.indexOf("\n"); |
| 2117 | nextLF = nextLF !== -1 ? nextLF : string.length; |
| 2118 | lineRe.lastIndex = nextLF; |
| 2119 | return foldLine(string.slice(0, nextLF), width); |
| 2120 | })(); |
| 2121 | let prevMoreIndented = string[0] === "\n" || string[0] === " "; |
| 2122 | let moreIndented; |
| 2123 | let match; |
| 2124 | while (match = lineRe.exec(string)) { |
| 2125 | const prefix = match[1]; |
| 2126 | const line = match[2] || ""; |
| 2127 | moreIndented = line[0] === " "; |
| 2128 | result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width); |
| 2129 | prevMoreIndented = moreIndented; |
| 2130 | } |
| 2131 | return result; |
| 2132 | } |
| 2133 | function escapeString(string) { |
| 2134 | let result = ""; |
| 2135 | let char; |
| 2136 | let nextChar; |
| 2137 | let escapeSeq; |
| 2138 | for (let i = 0; i < string.length; i++) { |
| 2139 | char = string.charCodeAt(i); |
| 2140 | if (char >= 55296 && char <= 56319) { |
| 2141 | nextChar = string.charCodeAt(i + 1); |
| 2142 | if (nextChar >= 56320 && nextChar <= 57343) { |
| 2143 | result += charCodeToHexString( |
| 2144 | (char - 55296) * 1024 + nextChar - 56320 + 65536 |
| 2145 | ); |
| 2146 | i++; |
| 2147 | continue; |
| 2148 | } |
| 2149 | } |
| 2150 | escapeSeq = ESCAPE_SEQUENCES.get(char); |
| 2151 | result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || charCodeToHexString(char); |
| 2152 | } |
| 2153 | return result; |
| 2154 | } |
| 2155 | function blockHeader(string, indentPerLevel) { |
| 2156 | const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ""; |
| 2157 | const clip = string[string.length - 1] === "\n"; |
| 2158 | const keep = clip && (string[string.length - 2] === "\n" || string === "\n"); |
| 2159 | const chomp = keep ? "+" : clip ? "" : "-"; |
| 2160 | return `${indentIndicator}${chomp} |
| 2161 | `; |
| 2162 | } |
| 2163 | function inspectNode(object, objects, duplicateObjects) { |
| 2164 | if (!isObject(object)) return; |
| 2165 | if (objects.has(object)) { |
| 2166 | duplicateObjects.add(object); |
| 2167 | return; |
| 2168 | } |
| 2169 | objects.add(object); |
| 2170 | const entries = Array.isArray(object) ? object : Object.values(object); |
| 2171 | for (const value2 of entries) { |
| 2172 | inspectNode(value2, objects, duplicateObjects); |
| 2173 | } |
| 2174 | } |
| 2175 | var DumperState = class { |
| 2176 | indent; |
| 2177 | arrayIndent; |
| 2178 | skipInvalid; |
| 2179 | flowLevel; |
| 2180 | sortKeys; |
| 2181 | lineWidth; |
| 2182 | useAnchors; |
| 2183 | compatMode; |
| 2184 | condenseFlow; |
| 2185 | implicitTypes; |
| 2186 | explicitTypes; |
| 2187 | duplicates = []; |
| 2188 | usedDuplicates = /* @__PURE__ */ new Set(); |
| 2189 | styleMap = /* @__PURE__ */ new Map(); |
| 2190 | constructor({ |
| 2191 | schema = DEFAULT_SCHEMA, |
| 2192 | indent = 2, |
| 2193 | arrayIndent = true, |
| 2194 | skipInvalid = false, |
| 2195 | flowLevel = -1, |
| 2196 | styles = void 0, |
| 2197 | sortKeys = false, |
| 2198 | lineWidth = 80, |
| 2199 | useAnchors = true, |
| 2200 | compatMode = true, |
| 2201 | condenseFlow = false |
| 2202 | }) { |
| 2203 | this.indent = Math.max(1, indent); |
| 2204 | this.arrayIndent = arrayIndent; |
| 2205 | this.skipInvalid = skipInvalid; |
| 2206 | this.flowLevel = flowLevel; |
| 2207 | if (styles) this.styleMap = createStyleMap(styles); |
| 2208 | this.sortKeys = sortKeys; |
| 2209 | this.lineWidth = lineWidth; |
| 2210 | this.useAnchors = useAnchors; |
| 2211 | this.compatMode = compatMode; |
| 2212 | this.condenseFlow = condenseFlow; |
| 2213 | this.implicitTypes = schema.implicitTypes; |
| 2214 | this.explicitTypes = schema.explicitTypes; |
| 2215 | } |
| 2216 | // Note: line breaking/folding is implemented for only the folded style. |
| 2217 | // NB. We drop the last trailing newline (if any) of a returned block scalar |
| 2218 | // since the dumper adds its own newline. This always works: |
| 2219 | // • No ending newline => unaffected; already using strip "-" chomping. |
| 2220 | // • Ending newline => removed then restored. |
| 2221 | // Importantly, this keeps the "+" chomp indicator from gaining an extra line. |
| 2222 | stringifyScalar(string, { level, isKey }) { |
| 2223 | if (string.length === 0) { |
| 2224 | return "''"; |
| 2225 | } |
| 2226 | if (this.compatMode && DEPRECATED_BOOLEANS_SYNTAX.includes(string)) { |
| 2227 | return `'${string}'`; |
| 2228 | } |
| 2229 | const indent = this.indent * Math.max(1, level); |
| 2230 | const lineWidth = this.lineWidth === -1 ? -1 : Math.max(Math.min(this.lineWidth, 40), this.lineWidth - indent); |
| 2231 | const singleLineOnly = isKey || // No block styles in flow mode. |
| 2232 | this.flowLevel > -1 && level >= this.flowLevel; |
| 2233 | const scalarStyle = chooseScalarStyle( |
| 2234 | string, |
| 2235 | singleLineOnly, |
| 2236 | this.indent, |
| 2237 | lineWidth, |
| 2238 | this.implicitTypes |
| 2239 | ); |
| 2240 | switch (scalarStyle) { |
| 2241 | case STYLE_PLAIN: |
| 2242 | return string; |
| 2243 | case STYLE_SINGLE: |
| 2244 | return `'${string.replace(/'/g, "''")}'`; |
| 2245 | case STYLE_LITERAL: |
| 2246 | return `|${blockHeader(string, this.indent)}${trimTrailingNewline(indentString(string, indent))}`; |
| 2247 | case STYLE_FOLDED: |
| 2248 | return `>${blockHeader(string, this.indent)}${trimTrailingNewline( |
| 2249 | indentString(foldString(string, lineWidth), indent) |
| 2250 | )}`; |
| 2251 | case STYLE_DOUBLE: |
| 2252 | return `"${escapeString(string)}"`; |
| 2253 | default: |
| 2254 | throw new TypeError( |
| 2255 | "Invalid scalar style should be unreachable: please file a bug report against Deno at https://github.com/denoland/std/issues" |
| 2256 | ); |
| 2257 | } |
| 2258 | } |
| 2259 | stringifyFlowSequence(array, { level }) { |
| 2260 | const results = []; |
| 2261 | for (const value2 of array) { |
| 2262 | const string = this.stringifyNode(value2, { |
| 2263 | level, |
| 2264 | block: false, |
| 2265 | compact: false, |
| 2266 | isKey: false |
| 2267 | }); |
| 2268 | if (string === null) continue; |
| 2269 | results.push(string); |
| 2270 | } |
| 2271 | const separator = this.condenseFlow ? "," : ", "; |
| 2272 | return `[${results.join(separator)}]`; |
| 2273 | } |
| 2274 | stringifyBlockSequence(array, { level, compact }) { |
| 2275 | const whitespace = generateNextLine(this.indent, level); |
| 2276 | const prefix = compact ? "" : whitespace; |
| 2277 | const results = []; |
| 2278 | for (const value2 of array) { |
| 2279 | const string = this.stringifyNode(value2, { |
| 2280 | level: level + 1, |
| 2281 | block: true, |
| 2282 | compact: true, |
| 2283 | isKey: false |
| 2284 | }); |
| 2285 | if (string === null) continue; |
| 2286 | const linePrefix = LINE_FEED === string.charCodeAt(0) ? "-" : "- "; |
| 2287 | results.push(`${linePrefix}${string}`); |
| 2288 | } |
| 2289 | return results.length ? prefix + results.join(whitespace) : "[]"; |
| 2290 | } |
| 2291 | stringifyFlowMapping(object, { level }) { |
| 2292 | const quote = this.condenseFlow ? '"' : ""; |
| 2293 | const separator = this.condenseFlow ? ":" : ": "; |
| 2294 | const results = []; |
| 2295 | for (const [key, value2] of Object.entries(object)) { |
| 2296 | const keyString = this.stringifyNode(key, { |
| 2297 | level, |
| 2298 | block: false, |
| 2299 | compact: false, |
| 2300 | isKey: false |
| 2301 | }); |
| 2302 | if (keyString === null) continue; |
| 2303 | const valueString = this.stringifyNode(value2, { |
| 2304 | level, |
| 2305 | block: false, |
| 2306 | compact: false, |
| 2307 | isKey: false |
| 2308 | }); |
| 2309 | if (valueString === null) continue; |
| 2310 | const keyPrefix = keyString.length > 1024 ? "? " : ""; |
| 2311 | results.push( |
| 2312 | quote + keyPrefix + keyString + quote + separator + valueString |
| 2313 | ); |
| 2314 | } |
| 2315 | return `{${results.join(", ")}}`; |
| 2316 | } |
| 2317 | stringifyBlockMapping(object, { tag, level, compact }) { |
| 2318 | const keys = Object.keys(object); |
| 2319 | if (this.sortKeys === true) { |
| 2320 | keys.sort(); |
| 2321 | } else if (typeof this.sortKeys === "function") { |
| 2322 | keys.sort(this.sortKeys); |
| 2323 | } else if (this.sortKeys) { |
| 2324 | throw new TypeError( |
| 2325 | `"sortKeys" must be a boolean or a function: received ${typeof this.sortKeys}` |
| 2326 | ); |
| 2327 | } |
| 2328 | const separator = generateNextLine(this.indent, level); |
| 2329 | const results = []; |
| 2330 | for (const key of keys) { |
| 2331 | const value2 = object[key]; |
| 2332 | const keyString = this.stringifyNode(key, { |
| 2333 | level: level + 1, |
| 2334 | block: true, |
| 2335 | compact: true, |
| 2336 | isKey: true |
| 2337 | }); |
| 2338 | if (keyString === null) continue; |
| 2339 | const explicitPair = tag !== null && tag !== "?" || keyString.length > 1024; |
| 2340 | const valueString = this.stringifyNode(value2, { |
| 2341 | level: level + 1, |
| 2342 | block: true, |
| 2343 | compact: explicitPair, |
| 2344 | isKey: false |
| 2345 | }); |
| 2346 | if (valueString === null) continue; |
| 2347 | let pairBuffer = ""; |
| 2348 | if (explicitPair) { |
| 2349 | pairBuffer += keyString.charCodeAt(0) === LINE_FEED ? "?" : "? "; |
| 2350 | } |
| 2351 | pairBuffer += keyString; |
| 2352 | if (explicitPair) pairBuffer += separator; |
| 2353 | pairBuffer += valueString.charCodeAt(0) === LINE_FEED ? ":" : ": "; |
| 2354 | pairBuffer += valueString; |
| 2355 | results.push(pairBuffer); |
| 2356 | } |
| 2357 | const prefix = compact ? "" : separator; |
| 2358 | return results.length ? prefix + results.join(separator) : "{}"; |
| 2359 | } |
| 2360 | getTypeRepresentation(type, value2) { |
| 2361 | if (!type.represent) return value2; |
| 2362 | const style = this.styleMap.get(type.tag) ?? type.defaultStyle; |
| 2363 | if (typeof type.represent === "function") { |
| 2364 | return type.represent(value2, style); |
| 2365 | } |
| 2366 | const represent = type.represent[style]; |
| 2367 | if (!represent) { |
| 2368 | throw new TypeError( |
| 2369 | `!<${type.tag}> tag resolver accepts not "${style}" style` |
| 2370 | ); |
| 2371 | } |
| 2372 | return represent(value2, style); |
| 2373 | } |
| 2374 | detectType(value2) { |
| 2375 | for (const type of this.implicitTypes) { |
| 2376 | if (type.predicate?.(value2)) { |
| 2377 | value2 = this.getTypeRepresentation(type, value2); |
| 2378 | return { tag: "?", value: value2 }; |
| 2379 | } |
| 2380 | } |
| 2381 | for (const type of this.explicitTypes) { |
| 2382 | if (type.predicate?.(value2)) { |
| 2383 | value2 = this.getTypeRepresentation(type, value2); |
| 2384 | return { tag: type.tag, value: value2 }; |
| 2385 | } |
| 2386 | } |
| 2387 | return { tag: null, value: value2 }; |
| 2388 | } |
| 2389 | // Serializes `object` and writes it to global `result`. |
| 2390 | // Returns true on success, or false on invalid object. |
| 2391 | stringifyNode(value2, { level, block, compact, isKey }) { |
| 2392 | const result = this.detectType(value2); |
| 2393 | const tag = result.tag; |
| 2394 | value2 = result.value; |
| 2395 | if (block) { |
| 2396 | block = this.flowLevel < 0 || this.flowLevel > level; |
| 2397 | } |
| 2398 | if (typeof value2 === "string" || value2 instanceof String) { |
| 2399 | value2 = value2 instanceof String ? value2.valueOf() : value2; |
| 2400 | if (tag !== "?") { |
| 2401 | value2 = this.stringifyScalar(value2, { level, isKey }); |
| 2402 | } |
| 2403 | } else if (isObject(value2)) { |
| 2404 | const duplicateIndex = this.duplicates.indexOf(value2); |
| 2405 | const duplicate = duplicateIndex !== -1; |
| 2406 | if (duplicate) { |
| 2407 | if (this.usedDuplicates.has(value2)) return `*ref_${duplicateIndex}`; |
| 2408 | this.usedDuplicates.add(value2); |
| 2409 | } |
| 2410 | if (tag !== null && tag !== "?" || duplicate || this.indent !== 2 && level > 0) { |
| 2411 | compact = false; |
| 2412 | } |
| 2413 | if (Array.isArray(value2)) { |
| 2414 | const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level; |
| 2415 | if (block && value2.length !== 0) { |
| 2416 | value2 = this.stringifyBlockSequence(value2, { |
| 2417 | level: arrayLevel, |
| 2418 | compact |
| 2419 | }); |
| 2420 | if (duplicate) { |
| 2421 | value2 = `&ref_${duplicateIndex}${value2}`; |
| 2422 | } |
| 2423 | } else { |
| 2424 | value2 = this.stringifyFlowSequence(value2, { level: arrayLevel }); |
| 2425 | if (duplicate) { |
| 2426 | value2 = `&ref_${duplicateIndex} ${value2}`; |
| 2427 | } |
| 2428 | } |
| 2429 | } else { |
| 2430 | if (block && Object.keys(value2).length !== 0) { |
| 2431 | value2 = this.stringifyBlockMapping(value2, { tag, level, compact }); |
| 2432 | if (duplicate) { |
| 2433 | value2 = `&ref_${duplicateIndex}${value2}`; |
| 2434 | } |
| 2435 | } else { |
| 2436 | value2 = this.stringifyFlowMapping(value2, { level }); |
| 2437 | if (duplicate) { |
| 2438 | value2 = `&ref_${duplicateIndex} ${value2}`; |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | } else { |
| 2443 | if (this.skipInvalid) return null; |
| 2444 | throw new TypeError(`Cannot stringify ${typeof value2}`); |
| 2445 | } |
| 2446 | if (tag !== null && tag !== "?") { |
| 2447 | value2 = `!<${tag}> ${value2}`; |
| 2448 | } |
| 2449 | return value2; |
| 2450 | } |
| 2451 | stringify(value2) { |
| 2452 | if (this.useAnchors) { |
| 2453 | const values = /* @__PURE__ */ new Set(); |
| 2454 | const duplicateObjects = /* @__PURE__ */ new Set(); |
| 2455 | inspectNode(value2, values, duplicateObjects); |
| 2456 | this.duplicates = [...duplicateObjects]; |
| 2457 | this.usedDuplicates = /* @__PURE__ */ new Set(); |
| 2458 | } |
| 2459 | const string = this.stringifyNode(value2, { |
| 2460 | level: 0, |
| 2461 | block: true, |
| 2462 | compact: true, |
| 2463 | isKey: false |
| 2464 | }); |
| 2465 | if (string !== null) { |
| 2466 | return `${string} |
| 2467 | `; |
| 2468 | } |
| 2469 | return ""; |
| 2470 | } |
| 2471 | }; |
| 2472 | |
| 2473 | // https://jsr.io/@std/yaml/1.0.5/stringify.ts |
| 2474 | function stringify(data, options = {}) { |
| 2475 | const state = new DumperState({ |
| 2476 | ...options, |
| 2477 | schema: SCHEMA_MAP.get(options.schema) |
| 2478 | }); |
| 2479 | return state.stringify(data); |
| 2480 | } |
| 2481 | |
| 2482 | // https://jsr.io/@std/front-matter/1.0.5/_formats.ts |
| 2483 | var BOM2 = "\\ufeff?"; |
| 2484 | var YAML_DELIMITER = "= yaml =|---"; |
| 2485 | var YAML_HEADER = `(---yaml|${YAML_DELIMITER})\\s*`; |
| 2486 | var YAML_FOOTER = `(?:---|${YAML_DELIMITER})`; |
| 2487 | var TOML_DELIMITER = "\\+\\+\\+|= toml ="; |
| 2488 | var TOML_HEADER = `(---toml|${TOML_DELIMITER})\\s*`; |
| 2489 | var TOML_FOOTER = `(?:---|${TOML_DELIMITER})`; |
| 2490 | var JSON_DELIMITER = `= json =`; |
| 2491 | var JSON_HEADER = `(---json|${JSON_DELIMITER})\\s*`; |
| 2492 | var JSON_FOOTER = `(?:---|${JSON_DELIMITER})`; |
| 2493 | var DATA = "([\\s\\S]+?)"; |
| 2494 | var NEWLINE = "\\r?\\n?"; |
| 2495 | var RECOGNIZE_YAML_REGEXP = new RegExp(`^${YAML_HEADER}$`, "im"); |
| 2496 | var RECOGNIZE_TOML_REGEXP = new RegExp(`^${TOML_HEADER}$`, "im"); |
| 2497 | var RECOGNIZE_JSON_REGEXP = new RegExp(`^${JSON_HEADER}$`, "im"); |
| 2498 | var EXTRACT_YAML_REGEXP = new RegExp( |
| 2499 | `^(${BOM2}${YAML_HEADER}$${DATA}^${YAML_FOOTER}\\s*$${NEWLINE})`, |
| 2500 | "im" |
| 2501 | ); |
| 2502 | var EXTRACT_TOML_REGEXP = new RegExp( |
| 2503 | `^(${BOM2}${TOML_HEADER}$${DATA}^${TOML_FOOTER}\\s*$${NEWLINE})`, |
| 2504 | "im" |
| 2505 | ); |
| 2506 | var EXTRACT_JSON_REGEXP = new RegExp( |
| 2507 | `^(${BOM2}${JSON_HEADER}$${DATA}^${JSON_FOOTER}\\s*$${NEWLINE})`, |
| 2508 | "im" |
| 2509 | ); |
| 2510 | |
| 2511 | // https://jsr.io/@std/front-matter/1.0.5/_shared.ts |
| 2512 | function extractAndParse(input, extractRegExp, parse3) { |
| 2513 | const match = extractRegExp.exec(input); |
| 2514 | if (!match || match.index !== 0) { |
| 2515 | throw new TypeError("Unexpected end of input"); |
| 2516 | } |
| 2517 | const frontMatter = match.at(-1)?.replace(/^\s+|\s+$/g, "") ?? ""; |
| 2518 | const attrs = parse3(frontMatter); |
| 2519 | const body = input.replace(match[0], ""); |
| 2520 | return { frontMatter, body, attrs }; |
| 2521 | } |
| 2522 | |
| 2523 | // https://jsr.io/@std/collections/1.0.9/_utils.ts |
| 2524 | function filterInPlace(array, predicate) { |
| 2525 | let outputIndex = 0; |
| 2526 | for (const cur of array) { |
| 2527 | if (!predicate(cur)) { |
| 2528 | continue; |
| 2529 | } |
| 2530 | array[outputIndex] = cur; |
| 2531 | outputIndex += 1; |
| 2532 | } |
| 2533 | array.splice(outputIndex); |
| 2534 | return array; |
| 2535 | } |
| 2536 | |
| 2537 | // https://jsr.io/@std/collections/1.0.9/deep_merge.ts |
| 2538 | function deepMerge(record, other, options) { |
| 2539 | return deepMergeInternal(record, other, /* @__PURE__ */ new Set(), options); |
| 2540 | } |
| 2541 | function deepMergeInternal(record, other, seen, options) { |
| 2542 | const result = {}; |
| 2543 | const keys = /* @__PURE__ */ new Set([ |
| 2544 | ...getKeys(record), |
| 2545 | ...getKeys(other) |
| 2546 | ]); |
| 2547 | for (const key of keys) { |
| 2548 | if (key === "__proto__") { |
| 2549 | continue; |
| 2550 | } |
| 2551 | const a = record[key]; |
| 2552 | if (!Object.hasOwn(other, key)) { |
| 2553 | result[key] = a; |
| 2554 | continue; |
| 2555 | } |
| 2556 | const b = other[key]; |
| 2557 | if (isNonNullObject(a) && isNonNullObject(b) && !seen.has(a) && !seen.has(b)) { |
| 2558 | seen.add(a); |
| 2559 | seen.add(b); |
| 2560 | result[key] = mergeObjects(a, b, seen, options); |
| 2561 | continue; |
| 2562 | } |
| 2563 | result[key] = b; |
| 2564 | } |
| 2565 | return result; |
| 2566 | } |
| 2567 | function mergeObjects(left, right, seen, options = { |
| 2568 | arrays: "merge", |
| 2569 | sets: "merge", |
| 2570 | maps: "merge" |
| 2571 | }) { |
| 2572 | if (isMergeable(left) && isMergeable(right)) { |
| 2573 | return deepMergeInternal(left, right, seen, options); |
| 2574 | } |
| 2575 | if (isIterable(left) && isIterable(right)) { |
| 2576 | if (Array.isArray(left) && Array.isArray(right)) { |
| 2577 | if (options.arrays === "merge") { |
| 2578 | return left.concat(right); |
| 2579 | } |
| 2580 | return right; |
| 2581 | } |
| 2582 | if (left instanceof Map && right instanceof Map) { |
| 2583 | if (options.maps === "merge") { |
| 2584 | return new Map([ |
| 2585 | ...left, |
| 2586 | ...right |
| 2587 | ]); |
| 2588 | } |
| 2589 | return right; |
| 2590 | } |
| 2591 | if (left instanceof Set && right instanceof Set) { |
| 2592 | if (options.sets === "merge") { |
| 2593 | return /* @__PURE__ */ new Set([ |
| 2594 | ...left, |
| 2595 | ...right |
| 2596 | ]); |
| 2597 | } |
| 2598 | return right; |
| 2599 | } |
| 2600 | } |
| 2601 | return right; |
| 2602 | } |
| 2603 | function isMergeable(value2) { |
| 2604 | return Object.getPrototypeOf(value2) === Object.prototype; |
| 2605 | } |
| 2606 | function isIterable(value2) { |
| 2607 | return typeof value2[Symbol.iterator] === "function"; |
| 2608 | } |
| 2609 | function isNonNullObject(value2) { |
| 2610 | return value2 !== null && typeof value2 === "object"; |
| 2611 | } |
| 2612 | function getKeys(record) { |
| 2613 | const result = Object.getOwnPropertySymbols(record); |
| 2614 | filterInPlace( |
| 2615 | result, |
| 2616 | (key) => Object.prototype.propertyIsEnumerable.call(record, key) |
| 2617 | ); |
| 2618 | result.push(...Object.keys(record)); |
| 2619 | return result; |
| 2620 | } |
| 2621 | |
| 2622 | // https://jsr.io/@std/toml/1.0.2/_parser.ts |
| 2623 | function success(body) { |
| 2624 | return { ok: true, body }; |
| 2625 | } |
| 2626 | function failure() { |
| 2627 | return { ok: false }; |
| 2628 | } |
| 2629 | function unflat(keys, values = {}, cObj) { |
| 2630 | const out = {}; |
| 2631 | if (keys.length === 0) { |
| 2632 | return cObj; |
| 2633 | } |
| 2634 | if (!cObj) cObj = values; |
| 2635 | const key = keys[keys.length - 1]; |
| 2636 | if (typeof key === "string") out[key] = cObj; |
| 2637 | return unflat(keys.slice(0, -1), values, out); |
| 2638 | } |
| 2639 | function or(parsers) { |
| 2640 | return (scanner) => { |
| 2641 | for (const parse3 of parsers) { |
| 2642 | const result = parse3(scanner); |
| 2643 | if (result.ok) return result; |
| 2644 | } |
| 2645 | return failure(); |
| 2646 | }; |
| 2647 | } |
| 2648 | function join(parser, separator) { |
| 2649 | const Separator = character(separator); |
| 2650 | return (scanner) => { |
| 2651 | const first = parser(scanner); |
| 2652 | if (!first.ok) return failure(); |
| 2653 | const out = [first.body]; |
| 2654 | while (!scanner.eof()) { |
| 2655 | if (!Separator(scanner).ok) break; |
| 2656 | const result = parser(scanner); |
| 2657 | if (!result.ok) { |
| 2658 | throw new SyntaxError(`Invalid token after "${separator}"`); |
| 2659 | } |
| 2660 | out.push(result.body); |
| 2661 | } |
| 2662 | return success(out); |
| 2663 | }; |
| 2664 | } |
| 2665 | function kv(keyParser, separator, valueParser) { |
| 2666 | const Separator = character(separator); |
| 2667 | return (scanner) => { |
| 2668 | const key = keyParser(scanner); |
| 2669 | if (!key.ok) return failure(); |
| 2670 | const sep = Separator(scanner); |
| 2671 | if (!sep.ok) { |
| 2672 | throw new SyntaxError(`key/value pair doesn't have "${separator}"`); |
| 2673 | } |
| 2674 | const value2 = valueParser(scanner); |
| 2675 | if (!value2.ok) { |
| 2676 | throw new SyntaxError( |
| 2677 | `Value of key/value pair is invalid data format` |
| 2678 | ); |
| 2679 | } |
| 2680 | return success(unflat(key.body, value2.body)); |
| 2681 | }; |
| 2682 | } |
| 2683 | function surround(left, parser, right) { |
| 2684 | const Left = character(left); |
| 2685 | const Right = character(right); |
| 2686 | return (scanner) => { |
| 2687 | if (!Left(scanner).ok) { |
| 2688 | return failure(); |
| 2689 | } |
| 2690 | const result = parser(scanner); |
| 2691 | if (!result.ok) { |
| 2692 | throw new SyntaxError(`Invalid token after "${left}"`); |
| 2693 | } |
| 2694 | if (!Right(scanner).ok) { |
| 2695 | throw new SyntaxError( |
| 2696 | `Not closed by "${right}" after started with "${left}"` |
| 2697 | ); |
| 2698 | } |
| 2699 | return success(result.body); |
| 2700 | }; |
| 2701 | } |
| 2702 | function character(str2) { |
| 2703 | return (scanner) => { |
| 2704 | scanner.nextUntilChar({ inline: true }); |
| 2705 | if (scanner.slice(0, str2.length) !== str2) return failure(); |
| 2706 | scanner.next(str2.length); |
| 2707 | scanner.nextUntilChar({ inline: true }); |
| 2708 | return success(void 0); |
| 2709 | }; |
| 2710 | } |
| 2711 | var BARE_KEY_REGEXP = /[A-Za-z0-9_-]/; |
| 2712 | var FLOAT_REGEXP = /[0-9_\.e+\-]/i; |
| 2713 | var END_OF_VALUE_REGEXP = /[ \t\r\n#,}\]]/; |
| 2714 | function bareKey(scanner) { |
| 2715 | scanner.nextUntilChar({ inline: true }); |
| 2716 | if (!scanner.char() || !BARE_KEY_REGEXP.test(scanner.char())) { |
| 2717 | return failure(); |
| 2718 | } |
| 2719 | const acc = []; |
| 2720 | while (scanner.char() && BARE_KEY_REGEXP.test(scanner.char())) { |
| 2721 | acc.push(scanner.char()); |
| 2722 | scanner.next(); |
| 2723 | } |
| 2724 | const key = acc.join(""); |
| 2725 | return success(key); |
| 2726 | } |
| 2727 | function escapeSequence(scanner) { |
| 2728 | if (scanner.char() !== "\\") return failure(); |
| 2729 | scanner.next(); |
| 2730 | switch (scanner.char()) { |
| 2731 | case "b": |
| 2732 | scanner.next(); |
| 2733 | return success("\b"); |
| 2734 | case "t": |
| 2735 | scanner.next(); |
| 2736 | return success(" "); |
| 2737 | case "n": |
| 2738 | scanner.next(); |
| 2739 | return success("\n"); |
| 2740 | case "f": |
| 2741 | scanner.next(); |
| 2742 | return success("\f"); |
| 2743 | case "r": |
| 2744 | scanner.next(); |
| 2745 | return success("\r"); |
| 2746 | case "u": |
| 2747 | case "U": { |
| 2748 | const codePointLen = scanner.char() === "u" ? 4 : 6; |
| 2749 | const codePoint = parseInt( |
| 2750 | "0x" + scanner.slice(1, 1 + codePointLen), |
| 2751 | 16 |
| 2752 | ); |
| 2753 | const str2 = String.fromCodePoint(codePoint); |
| 2754 | scanner.next(codePointLen + 1); |
| 2755 | return success(str2); |
| 2756 | } |
| 2757 | case '"': |
| 2758 | scanner.next(); |
| 2759 | return success('"'); |
| 2760 | case "\\": |
| 2761 | scanner.next(); |
| 2762 | return success("\\"); |
| 2763 | default: |
| 2764 | throw new SyntaxError( |
| 2765 | `Invalid escape sequence: \\${scanner.char()}` |
| 2766 | ); |
| 2767 | } |
| 2768 | } |
| 2769 | function basicString(scanner) { |
| 2770 | scanner.nextUntilChar({ inline: true }); |
| 2771 | if (scanner.char() !== '"') return failure(); |
| 2772 | scanner.next(); |
| 2773 | const acc = []; |
| 2774 | while (scanner.char() !== '"' && !scanner.eof()) { |
| 2775 | if (scanner.char() === "\n") { |
| 2776 | throw new SyntaxError("Single-line string cannot contain EOL"); |
| 2777 | } |
| 2778 | const escapedChar = escapeSequence(scanner); |
| 2779 | if (escapedChar.ok) { |
| 2780 | acc.push(escapedChar.body); |
| 2781 | } else { |
| 2782 | acc.push(scanner.char()); |
| 2783 | scanner.next(); |
| 2784 | } |
| 2785 | } |
| 2786 | if (scanner.eof()) { |
| 2787 | throw new SyntaxError( |
| 2788 | `Single-line string is not closed: |
| 2789 | ${acc.join("")}` |
| 2790 | ); |
| 2791 | } |
| 2792 | scanner.next(); |
| 2793 | return success(acc.join("")); |
| 2794 | } |
| 2795 | function literalString(scanner) { |
| 2796 | scanner.nextUntilChar({ inline: true }); |
| 2797 | if (scanner.char() !== "'") return failure(); |
| 2798 | scanner.next(); |
| 2799 | const acc = []; |
| 2800 | while (scanner.char() !== "'" && !scanner.eof()) { |
| 2801 | if (scanner.char() === "\n") { |
| 2802 | throw new SyntaxError("Single-line string cannot contain EOL"); |
| 2803 | } |
| 2804 | acc.push(scanner.char()); |
| 2805 | scanner.next(); |
| 2806 | } |
| 2807 | if (scanner.eof()) { |
| 2808 | throw new SyntaxError( |
| 2809 | `Single-line string is not closed: |
| 2810 | ${acc.join("")}` |
| 2811 | ); |
| 2812 | } |
| 2813 | scanner.next(); |
| 2814 | return success(acc.join("")); |
| 2815 | } |
| 2816 | function multilineBasicString(scanner) { |
| 2817 | scanner.nextUntilChar({ inline: true }); |
| 2818 | if (scanner.slice(0, 3) !== '"""') return failure(); |
| 2819 | scanner.next(3); |
| 2820 | if (scanner.char() === "\n") { |
| 2821 | scanner.next(); |
| 2822 | } else if (scanner.slice(0, 2) === "\r\n") { |
| 2823 | scanner.next(2); |
| 2824 | } |
| 2825 | const acc = []; |
| 2826 | while (scanner.slice(0, 3) !== '"""' && !scanner.eof()) { |
| 2827 | if (scanner.slice(0, 2) === "\\\n") { |
| 2828 | scanner.next(); |
| 2829 | scanner.nextUntilChar({ comment: false }); |
| 2830 | continue; |
| 2831 | } else if (scanner.slice(0, 3) === "\\\r\n") { |
| 2832 | scanner.next(); |
| 2833 | scanner.nextUntilChar({ comment: false }); |
| 2834 | continue; |
| 2835 | } |
| 2836 | const escapedChar = escapeSequence(scanner); |
| 2837 | if (escapedChar.ok) { |
| 2838 | acc.push(escapedChar.body); |
| 2839 | } else { |
| 2840 | acc.push(scanner.char()); |
| 2841 | scanner.next(); |
| 2842 | } |
| 2843 | } |
| 2844 | if (scanner.eof()) { |
| 2845 | throw new SyntaxError( |
| 2846 | `Multi-line string is not closed: |
| 2847 | ${acc.join("")}` |
| 2848 | ); |
| 2849 | } |
| 2850 | if (scanner.char(3) === '"') { |
| 2851 | acc.push('"'); |
| 2852 | scanner.next(); |
| 2853 | } |
| 2854 | scanner.next(3); |
| 2855 | return success(acc.join("")); |
| 2856 | } |
| 2857 | function multilineLiteralString(scanner) { |
| 2858 | scanner.nextUntilChar({ inline: true }); |
| 2859 | if (scanner.slice(0, 3) !== "'''") return failure(); |
| 2860 | scanner.next(3); |
| 2861 | if (scanner.char() === "\n") { |
| 2862 | scanner.next(); |
| 2863 | } else if (scanner.slice(0, 2) === "\r\n") { |
| 2864 | scanner.next(2); |
| 2865 | } |
| 2866 | const acc = []; |
| 2867 | while (scanner.slice(0, 3) !== "'''" && !scanner.eof()) { |
| 2868 | acc.push(scanner.char()); |
| 2869 | scanner.next(); |
| 2870 | } |
| 2871 | if (scanner.eof()) { |
| 2872 | throw new SyntaxError( |
| 2873 | `Multi-line string is not closed: |
| 2874 | ${acc.join("")}` |
| 2875 | ); |
| 2876 | } |
| 2877 | if (scanner.char(3) === "'") { |
| 2878 | acc.push("'"); |
| 2879 | scanner.next(); |
| 2880 | } |
| 2881 | scanner.next(3); |
| 2882 | return success(acc.join("")); |
| 2883 | } |
| 2884 | var symbolPairs = [ |
| 2885 | ["true", true], |
| 2886 | ["false", false], |
| 2887 | ["inf", Infinity], |
| 2888 | ["+inf", Infinity], |
| 2889 | ["-inf", -Infinity], |
| 2890 | ["nan", NaN], |
| 2891 | ["+nan", NaN], |
| 2892 | ["-nan", NaN] |
| 2893 | ]; |
| 2894 | function symbols(scanner) { |
| 2895 | scanner.nextUntilChar({ inline: true }); |
| 2896 | const found = symbolPairs.find( |
| 2897 | ([str3]) => scanner.slice(0, str3.length) === str3 |
| 2898 | ); |
| 2899 | if (!found) return failure(); |
| 2900 | const [str2, value2] = found; |
| 2901 | scanner.next(str2.length); |
| 2902 | return success(value2); |
| 2903 | } |
| 2904 | var dottedKey = join(or([bareKey, basicString, literalString]), "."); |
| 2905 | function integer(scanner) { |
| 2906 | scanner.nextUntilChar({ inline: true }); |
| 2907 | const first2 = scanner.slice(0, 2); |
| 2908 | if (first2.length === 2 && /0(?:x|o|b)/i.test(first2)) { |
| 2909 | scanner.next(2); |
| 2910 | const acc2 = [first2]; |
| 2911 | while (/[0-9a-f_]/i.test(scanner.char()) && !scanner.eof()) { |
| 2912 | acc2.push(scanner.char()); |
| 2913 | scanner.next(); |
| 2914 | } |
| 2915 | if (acc2.length === 1) return failure(); |
| 2916 | return success(acc2.join("")); |
| 2917 | } |
| 2918 | const acc = []; |
| 2919 | if (/[+-]/.test(scanner.char())) { |
| 2920 | acc.push(scanner.char()); |
| 2921 | scanner.next(); |
| 2922 | } |
| 2923 | while (/[0-9_]/.test(scanner.char()) && !scanner.eof()) { |
| 2924 | acc.push(scanner.char()); |
| 2925 | scanner.next(); |
| 2926 | } |
| 2927 | if (acc.length === 0 || acc.length === 1 && /[+-]/.test(acc[0])) { |
| 2928 | return failure(); |
| 2929 | } |
| 2930 | const int2 = parseInt(acc.filter((char) => char !== "_").join("")); |
| 2931 | return success(int2); |
| 2932 | } |
| 2933 | function float2(scanner) { |
| 2934 | scanner.nextUntilChar({ inline: true }); |
| 2935 | let position = 0; |
| 2936 | while (scanner.char(position) && !END_OF_VALUE_REGEXP.test(scanner.char(position))) { |
| 2937 | if (!FLOAT_REGEXP.test(scanner.char(position))) return failure(); |
| 2938 | position++; |
| 2939 | } |
| 2940 | const acc = []; |
| 2941 | if (/[+-]/.test(scanner.char())) { |
| 2942 | acc.push(scanner.char()); |
| 2943 | scanner.next(); |
| 2944 | } |
| 2945 | while (FLOAT_REGEXP.test(scanner.char()) && !scanner.eof()) { |
| 2946 | acc.push(scanner.char()); |
| 2947 | scanner.next(); |
| 2948 | } |
| 2949 | if (acc.length === 0) return failure(); |
| 2950 | const float3 = parseFloat(acc.filter((char) => char !== "_").join("")); |
| 2951 | if (isNaN(float3)) return failure(); |
| 2952 | return success(float3); |
| 2953 | } |
| 2954 | function dateTime(scanner) { |
| 2955 | scanner.nextUntilChar({ inline: true }); |
| 2956 | let dateStr = scanner.slice(0, 10); |
| 2957 | if (!/^\d{4}-\d{2}-\d{2}/.test(dateStr)) return failure(); |
| 2958 | scanner.next(10); |
| 2959 | const acc = []; |
| 2960 | while (/[ 0-9TZ.:+-]/.test(scanner.char()) && !scanner.eof()) { |
| 2961 | acc.push(scanner.char()); |
| 2962 | scanner.next(); |
| 2963 | } |
| 2964 | dateStr += acc.join(""); |
| 2965 | const date = new Date(dateStr.trim()); |
| 2966 | if (isNaN(date.getTime())) { |
| 2967 | throw new SyntaxError(`Invalid date string "${dateStr}"`); |
| 2968 | } |
| 2969 | return success(date); |
| 2970 | } |
| 2971 | function localTime(scanner) { |
| 2972 | scanner.nextUntilChar({ inline: true }); |
| 2973 | let timeStr = scanner.slice(0, 8); |
| 2974 | if (!/^(\d{2}):(\d{2}):(\d{2})/.test(timeStr)) return failure(); |
| 2975 | scanner.next(8); |
| 2976 | const acc = []; |
| 2977 | if (scanner.char() !== ".") return success(timeStr); |
| 2978 | acc.push(scanner.char()); |
| 2979 | scanner.next(); |
| 2980 | while (/[0-9]/.test(scanner.char()) && !scanner.eof()) { |
| 2981 | acc.push(scanner.char()); |
| 2982 | scanner.next(); |
| 2983 | } |
| 2984 | timeStr += acc.join(""); |
| 2985 | return success(timeStr); |
| 2986 | } |
| 2987 | function arrayValue(scanner) { |
| 2988 | scanner.nextUntilChar({ inline: true }); |
| 2989 | if (scanner.char() !== "[") return failure(); |
| 2990 | scanner.next(); |
| 2991 | const array = []; |
| 2992 | while (!scanner.eof()) { |
| 2993 | scanner.nextUntilChar(); |
| 2994 | const result = value(scanner); |
| 2995 | if (!result.ok) break; |
| 2996 | array.push(result.body); |
| 2997 | scanner.nextUntilChar({ inline: true }); |
| 2998 | if (scanner.char() !== ",") break; |
| 2999 | scanner.next(); |
| 3000 | } |
| 3001 | scanner.nextUntilChar(); |
| 3002 | if (scanner.char() !== "]") throw new SyntaxError("Array is not closed"); |
| 3003 | scanner.next(); |
| 3004 | return success(array); |
| 3005 | } |
| 3006 | function inlineTable(scanner) { |
| 3007 | scanner.nextUntilChar(); |
| 3008 | if (scanner.char(1) === "}") { |
| 3009 | scanner.next(2); |
| 3010 | return success({}); |
| 3011 | } |
| 3012 | const pairs2 = surround( |
| 3013 | "{", |
| 3014 | join(pair, ","), |
| 3015 | "}" |
| 3016 | )(scanner); |
| 3017 | if (!pairs2.ok) return failure(); |
| 3018 | let table = {}; |
| 3019 | for (const pair2 of pairs2.body) { |
| 3020 | table = deepMerge(table, pair2); |
| 3021 | } |
| 3022 | return success(table); |
| 3023 | } |
| 3024 | var value = or([ |
| 3025 | multilineBasicString, |
| 3026 | multilineLiteralString, |
| 3027 | basicString, |
| 3028 | literalString, |
| 3029 | symbols, |
| 3030 | dateTime, |
| 3031 | localTime, |
| 3032 | float2, |
| 3033 | integer, |
| 3034 | arrayValue, |
| 3035 | inlineTable |
| 3036 | ]); |
| 3037 | var pair = kv(dottedKey, "=", value); |
| 3038 | var tableHeader = surround("[", dottedKey, "]"); |
| 3039 | var tableArrayHeader = surround("[[", dottedKey, "]]"); |
| 3040 | |
| 3041 | // https://jsr.io/@std/front-matter/1.0.5/yaml.ts |
| 3042 | function extract(text) { |
| 3043 | return extractAndParse( |
| 3044 | text, |
| 3045 | EXTRACT_YAML_REGEXP, |
| 3046 | (s) => parse(s) |
| 3047 | ); |
| 3048 | } |
| 3049 | |
| 3050 | // mod.js |
| 3051 | var yaml = { |
| 3052 | create: async (obj, content) => { |
| 3053 | try { |
| 3054 | return `--- |
| 3055 | ${await stringify(obj)}--- |
| 3056 | ${content}`; |
| 3057 | } catch (err) { |
| 3058 | } |
| 3059 | }, |
| 3060 | parse: async (doc) => { |
| 3061 | try { |
| 3062 | const extracted = await extract(doc); |
| 3063 | const front = await parse(extracted.frontMatter); |
| 3064 | front.body = extracted.body; |
| 3065 | return front; |
| 3066 | } catch (err) { |
| 3067 | return { body: doc }; |
| 3068 | } |
| 3069 | } |
| 3070 | }; |
| 3071 | export { |
| 3072 | yaml |
| 3073 | }; |