UNPKG

sea-of-amoebas

Version:

A declarative and event-driven execution framework for building scalable, asynchronous flow systems.

2 lines 115 kB
"use strict";function e({verbose:e=!1}={}){return{log:(...t)=>{e&&console.log(...t)},error:(...t)=>{e&&console.error(...t)}}}Object.defineProperty(exports,"__esModule",{value:!0});const t="Executed",n="Error",s=e=>`${e}.${t}`,i=e=>`${e}.${n}`;class r{constructor({id:t,func:n,eventEmitter:r,storeResults:o=!1,inputEvents:a=[],outputEvents:c=[],stickyInputs:l=!1,triggerMode:u=!1,verbose:f=!1}){if(!t||"string"!=typeof t)throw new Error("Amoeba 'id' is required and must be a string.");if("function"!=typeof n)throw new Error("Amoeba 'func' is required and must be a function.");if(!r||"function"!=typeof r.emit||"function"!=typeof r.on)throw new Error("Amoeba 'eventEmitter' is required and must be a valid EventEmitter instance.");if(!Array.isArray(a)){if(null!=a)throw new Error(`Amoeba '${t}': 'inputEvents' must be an array.`);a=[t]}if(0===a.length&&(a=[t]),!a.every((e=>"string"==typeof e)))throw new Error(`Amoeba '${t}': 'inputEvents' must be an array of strings.`);if(!Array.isArray(c)){if(null!=c)throw new Error(`Amoeba '${t}': 'outputEvents' must be an array.`);c=[]}const h=e=>"string"==typeof e||"object"==typeof e&&"string"==typeof e.event&&(void 0===e.reflexive||"boolean"==typeof e.reflexive);c.forEach(((e,n)=>{if("string"!=typeof e&&"object"!=typeof e)throw new Error(`Amoeba '${t}': 'outputEvents[${n}]' must be a string or an object.`);if("object"==typeof e){if(!e.hasOwnProperty("condition")||!e.hasOwnProperty("then"))throw new Error(`Amoeba '${t}': 'outputEvents[${n}]' must contain 'condition' and 'then'.`);if("function"!=typeof e.condition)throw new Error(`Amoeba '${t}': 'outputEvents[${n}].condition' must be a function.`);if(!Array.isArray(e.then)||!e.then.every(h))throw new Error(`Amoeba '${t}': 'outputEvents[${n}].then' must be an array of strings or objects { event, reflexive? }.`);if(e.hasOwnProperty("else")&&(!Array.isArray(e.else)||!e.else.every(h)))throw new Error(`Amoeba '${t}': 'outputEvents[${n}].else' must be an array of strings or objects { event, reflexive? } if defined.`)}})),this.executedEvent=s(t),this.errorEvent=i(t);const d=c.filter((e=>{let t;if("string"==typeof e)t=e;else{if("object"!=typeof e||!e.event)return!0;t=e.event}return"string"!=typeof t||t!==this.executedEvent&&t!==this.errorEvent}));this.id=t,this.verbose=f,this.logger=e({verbose:f}),this.func=n,this.storeResults=o,this.inputEvents=a,this.stickyInputs=l,this.triggerMode=u,this.lastEventNameReceived=null,this.outputEvents=d,this.eventEmitter=r,this.receivedData=Object.create(null),this.ready=!1,this.executionCount=0,this.lastResult=null,this.executionLog=[],a.forEach((e=>this.eventEmitter.on(e,(t=>this.receive(e,t))))),this.logger.log(`[${this.id}] Created with input events:`,this.inputEvents),this.logger.log(`[${this.id}] Internal events - Executed: ${this.executedEvent}, Error: ${this.errorEvent}`)}setReady(e=!0){this.ready=e}receive(e,t){this.receivedData[e]=t,this.lastEventNameReceived=e,this.logger.log(`[${this.id}] Receive input state:`,this.receivedData),this.checkAndExecute()}async checkAndExecute(){if(!this.ready)return;let e;if(this.triggerMode){if(!this.lastEventNameReceived)return;e=this.inputEvents.map((e=>this.receivedData[e]));if(!e.some((e=>void 0!==e)))return;this.logger.log(`[${this.id}] TriggerMode execution triggered by: ${this.lastEventNameReceived}`),this.logger.log(`[${this.id}] Args:`,e)}else{if(!this.inputEvents.every((e=>e in this.receivedData)))return void this.logger.log(`[${this.id}] Waiting for all inputs. Current:`,Object.keys(this.receivedData));e=this.inputEvents.map((e=>this.receivedData[e])),this.logger.log(`[${this.id}] All inputs received, executing with args:`,e)}try{const t=await this.func(...e);this.storeResults&&(this.lastResult=t,this.executionLog.push({output:t,timestamp:Date.now()})),this.emitSuccess(t)}catch(t){this.emitError(t,e)}finally{this.executionCount++,this.stickyInputs?this.logger.log(`[${this.id}] Keeping receivedData for next execution (sticky mode)`):(this.receivedData=Object.create(null),this.logger.log(`[${this.id}] Cleared receivedData (non-sticky mode)`))}}emitSuccess(e){this.eventEmitter.emit(this.executedEvent,e);let t=!1;this.outputEvents.forEach((n=>{if("string"==typeof n)this.eventEmitter.emit(n,e);else if(n.condition){(n.condition(e)?n.then:n.else||[]).forEach((n=>{"string"==typeof n?this.eventEmitter.emit(n,e):(this.eventEmitter.emit(n.event,e),n.reflexive&&!t&&(this.scheduleReflexiveExecution(n.event,e),t=!0))}))}else this.eventEmitter.emit(n.event,e),n.reflexive&&!t&&(this.scheduleReflexiveExecution(n.event,e),t=!0)}))}scheduleReflexiveExecution(e,t){this.inputEvents.includes(e)||Promise.resolve().then((()=>{this.logger.log(`[${this.id}] Reflexive via .receive(${e})`),this.receive(e,t)}))}emitError(e,t){const n={amoebaId:this.id,error:{name:e.name,message:e.message,stack:e.stack},inputArgs:t,timestamp:Date.now()};this.logger.error(`[${this.id}] Function failed:`,e),this.eventEmitter.emit(this.errorEvent,n)}}class o{constructor({verbose:t=!1}={}){this.events=Object.create(null),this.enableWildcard=!1,this.logger=e(t)}toggleWildcard(e){this.enableWildcard=e,this.logger.log(`[EventEmitter] Wildcard support is now ${e?"enabled":"disabled"}.`)}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].includes(t)||this.events[e].push(t)}once(e,t){const n=s=>{this.off(e,n),t(s)};this.on(e,n)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,t){this.events[e]&&this.events[e].forEach((e=>e(t))),this.enableWildcard&&this.events["*"]&&this.events["*"].forEach((n=>n(e,t)))}clearAll(){this.logger.log("[EventEmitter] Clearing all event listeners."),this.events=Object.create(null)}getListeners(e){return this.events[e]||[]}}const a=new o({verbose:!1}),c="Sea.Ready";class l{constructor({eventEmitter:t=a,storeResults:n=!1,verbose:s=!1}={}){this.amoebas={},this.eventEmitter=t,this.storeResults=n,this.verbose=s,this.logger=e({verbose:s}),this.isReady=!1}addAmoeba({id:e,func:t,inputEvents:n=[],outputEvents:s=[],storeResults:i=null,stickyInputs:o=!1,triggerMode:a=!1,verbose:c=null}){const l=null!==i?i:this.storeResults,u=null!==c?c:this.verbose,f=new r({id:e,func:t,eventEmitter:this.eventEmitter,storeResults:l,inputEvents:n,outputEvents:s,stickyInputs:o,triggerMode:a,verbose:u});this.amoebas[e]=f}finalizeConfiguration(){this.resumeAll(),this.logger.log("[AmoebaSea] Configuration finalized → emitting",c),this.isReady&&this.eventEmitter.emit(c,null)}pauseAll(){this.isReady=!1,this.amoebas&&0!==Object.keys(this.amoebas).length&&Object.values(this.amoebas).forEach((e=>e.setReady(!1)))}resumeAll(){this.amoebas&&0!==Object.keys(this.amoebas).length&&(Object.values(this.amoebas).forEach((e=>e.setReady(!0))),this.isReady=!0)}setInput(e,t){this.isReady||this.resumeAll(),this.logger.log(`[AmoebaSea] Introducing event: "${e}" with data:`,t),this.eventEmitter.emit(e,t)}waitForOutputEvent(e){return new Promise((t=>{const n=s=>{this.eventEmitter.off(e,n),t(s)};this.eventEmitter.on(e,n)}))}waitForAmoebaExecution(e){return this.waitForOutputEvent(s(e))}waitForAmoebaError(e){return this.waitForOutputEvent(i(e))}stopAll(){this.eventEmitter.clearAll()}}const u=Symbol.for("yaml.alias"),f=Symbol.for("yaml.document"),h=Symbol.for("yaml.map"),d=Symbol.for("yaml.pair"),p=Symbol.for("yaml.scalar"),m=Symbol.for("yaml.seq"),y=Symbol.for("yaml.node.type"),g=e=>!!e&&"object"==typeof e&&e[y]===u,b=e=>!!e&&"object"==typeof e&&e[y]===f,v=e=>!!e&&"object"==typeof e&&e[y]===h,w=e=>!!e&&"object"==typeof e&&e[y]===d,k=e=>!!e&&"object"==typeof e&&e[y]===p,E=e=>!!e&&"object"==typeof e&&e[y]===m;function S(e){if(e&&"object"==typeof e)switch(e[y]){case h:case m:return!0}return!1}function A(e){if(e&&"object"==typeof e)switch(e[y]){case u:case h:case p:case m:return!0}return!1}const N=Symbol("break visit"),O=Symbol("skip children"),$=Symbol("remove node");function I(e,t){const n=C(t);if(b(e)){x(null,e.contents,n,Object.freeze([e]))===$&&(e.contents=null)}else x(null,e,n,Object.freeze([]))}function x(e,t,n,s){const i=_(e,t,n,s);if(A(i)||w(i))return j(e,s,i),x(e,i,n,s);if("symbol"!=typeof i)if(S(t)){s=Object.freeze(s.concat(t));for(let e=0;e<t.items.length;++e){const i=x(e,t.items[e],n,s);if("number"==typeof i)e=i-1;else{if(i===N)return N;i===$&&(t.items.splice(e,1),e-=1)}}}else if(w(t)){s=Object.freeze(s.concat(t));const e=x("key",t.key,n,s);if(e===N)return N;e===$&&(t.key=null);const i=x("value",t.value,n,s);if(i===N)return N;i===$&&(t.value=null)}return i}async function T(e,t){const n=C(t);if(b(e)){await L(null,e.contents,n,Object.freeze([e]))===$&&(e.contents=null)}else await L(null,e,n,Object.freeze([]))}async function L(e,t,n,s){const i=await _(e,t,n,s);if(A(i)||w(i))return j(e,s,i),L(e,i,n,s);if("symbol"!=typeof i)if(S(t)){s=Object.freeze(s.concat(t));for(let e=0;e<t.items.length;++e){const i=await L(e,t.items[e],n,s);if("number"==typeof i)e=i-1;else{if(i===N)return N;i===$&&(t.items.splice(e,1),e-=1)}}}else if(w(t)){s=Object.freeze(s.concat(t));const e=await L("key",t.key,n,s);if(e===N)return N;e===$&&(t.key=null);const i=await L("value",t.value,n,s);if(i===N)return N;i===$&&(t.value=null)}return i}function C(e){return"object"==typeof e&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function _(e,t,n,s){return"function"==typeof n?n(e,t,s):v(t)?n.Map?.(e,t,s):E(t)?n.Seq?.(e,t,s):w(t)?n.Pair?.(e,t,s):k(t)?n.Scalar?.(e,t,s):g(t)?n.Alias?.(e,t,s):void 0}function j(e,t,n){const s=t[t.length-1];if(S(s))s.items[e]=n;else if(w(s))"key"===e?s.key=n:s.value=n;else{if(!b(s)){const e=g(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${e} parent`)}s.contents=n}}I.BREAK=N,I.SKIP=O,I.REMOVE=$,T.BREAK=N,T.SKIP=O,T.REMOVE=$;const B={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"};class K{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},K.defaultYaml,e),this.tags=Object.assign({},K.defaultTags,t)}clone(){const e=new K(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){const e=new K(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:K.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},K.defaultTags)}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:K.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},K.defaultTags),this.atNextDocument=!1);const n=e.trim().split(/[ \t]+/),s=n.shift();switch(s){case"%TAG":{if(2!==n.length&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;const[e,s]=n;return this.tags[e]=s,!0}case"%YAML":{if(this.yaml.explicit=!0,1!==n.length)return t(0,"%YAML directive should contain exactly one part"),!1;const[e]=n;if("1.1"===e||"1.2"===e)return this.yaml.version=e,!0;return t(6,`Unsupported YAML version ${e}`,/^\d+\.\d+$/.test(e)),!1}default:return t(0,`Unknown directive ${s}`,!0),!1}}tagName(e,t){if("!"===e)return"!";if("!"!==e[0])return t(`Not a valid tag: ${e}`),null;if("<"===e[1]){const n=e.slice(2,-1);return"!"===n||"!!"===n?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(">"!==e[e.length-1]&&t("Verbatim tags must end with a >"),n)}const[,n,s]=e.match(/^(.*!)([^!]*)$/s);s||t(`The ${e} tag has no suffix`);const i=this.tags[n];if(i)try{return i+decodeURIComponent(s)}catch(e){return t(String(e)),null}return"!"===n?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(const[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+e.substring(n.length).replace(/[!,[\]{}]/g,(e=>B[e]));return"!"===e[0]?e:`!<${e}>`}toString(e){const t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags);let s;if(e&&n.length>0&&A(e.contents)){const t={};I(e.contents,((e,n)=>{A(n)&&n.tag&&(t[n.tag]=!0)})),s=Object.keys(t)}else s=[];for(const[i,r]of n)"!!"===i&&"tag:yaml.org,2002:"===r||e&&!s.some((e=>e.startsWith(r)))||t.push(`%TAG ${i} ${r}`);return t.join("\n")}}function M(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){const t=JSON.stringify(e);throw new Error(`Anchor must not contain whitespace or control characters: ${t}`)}return!0}function D(e){const t=new Set;return I(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function R(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function P(e,t,n,s){if(s&&"object"==typeof s)if(Array.isArray(s))for(let t=0,n=s.length;t<n;++t){const n=s[t],i=P(e,s,String(t),n);void 0===i?delete s[t]:i!==n&&(s[t]=i)}else if(s instanceof Map)for(const t of Array.from(s.keys())){const n=s.get(t),i=P(e,s,t,n);void 0===i?s.delete(t):i!==n&&s.set(t,i)}else if(s instanceof Set)for(const t of Array.from(s)){const n=P(e,s,t,t);void 0===n?s.delete(t):n!==t&&(s.delete(t),s.add(n))}else for(const[t,n]of Object.entries(s)){const i=P(e,s,t,n);void 0===i?delete s[t]:i!==n&&(s[t]=i)}return e.call(t,n,s)}function q(e,t,n){if(Array.isArray(e))return e.map(((e,t)=>q(e,String(t),n)));if(e&&"function"==typeof e.toJSON){if(!n||(!k(s=e)&&!S(s)||!s.anchor))return e.toJSON(t,n);const i={aliasCount:0,count:1,res:void 0};n.anchors.set(e,i),n.onCreate=e=>{i.res=e,delete n.onCreate};const r=e.toJSON(t,n);return n.onCreate&&n.onCreate(r),r}var s;return"bigint"!=typeof e||n?.keep?e:Number(e)}K.defaultYaml={explicit:!1,version:"1.2"},K.defaultTags={"!!":"tag:yaml.org,2002:"};class F{constructor(e){Object.defineProperty(this,y,{value:e})}clone(){const e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:s,reviver:i}={}){if(!b(e))throw new TypeError("A document argument is required");const r={anchors:new Map,doc:e,keep:!0,mapAsMap:!0===t,mapKeyWarned:!1,maxAliasCount:"number"==typeof n?n:100},o=q(this,"",r);if("function"==typeof s)for(const{count:e,res:t}of r.anchors.values())s(t,e);return"function"==typeof i?P(i,{"":o},"",o):o}}class U extends F{constructor(e){super(u),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e){let t;return I(e,{Node:(e,n)=>{if(n===this)return I.BREAK;n.anchor===this.source&&(t=n)}}),t}toJSON(e,t){if(!t)return{source:this.source};const{anchors:n,doc:s,maxAliasCount:i}=t,r=this.resolve(s);if(!r){const e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(e)}let o=n.get(r);if(o||(q(r,null,t),o=n.get(r)),!o||void 0===o.res){throw new ReferenceError("This should not happen: Alias anchor was not resolved?")}if(i>=0&&(o.count+=1,0===o.aliasCount&&(o.aliasCount=V(s,r,n)),o.count*o.aliasCount>i)){throw new ReferenceError("Excessive alias count indicates a resource exhaustion attack")}return o.res}toString(e,t,n){const s=`*${this.source}`;if(e){if(M(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){const e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(e)}if(e.implicitKey)return`${s} `}return s}}function V(e,t,n){if(g(t)){const s=t.resolve(e),i=n&&s&&n.get(s);return i?i.count*i.aliasCount:0}if(S(t)){let s=0;for(const i of t.items){const t=V(e,i,n);t>s&&(s=t)}return s}if(w(t)){const s=V(e,t.key,n),i=V(e,t.value,n);return Math.max(s,i)}return 1}const J=e=>!e||"function"!=typeof e&&"object"!=typeof e;class W extends F{constructor(e){super(p),this.value=e}toJSON(e,t){return t?.keep?this.value:q(this.value,e,t)}toString(){return String(this.value)}}W.BLOCK_FOLDED="BLOCK_FOLDED",W.BLOCK_LITERAL="BLOCK_LITERAL",W.PLAIN="PLAIN",W.QUOTE_DOUBLE="QUOTE_DOUBLE",W.QUOTE_SINGLE="QUOTE_SINGLE";function Y(e,t,n){if(b(e)&&(e=e.contents),A(e))return e;if(w(e)){const t=n.schema[h].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||"undefined"!=typeof BigInt&&e instanceof BigInt)&&(e=e.valueOf());const{aliasDuplicateObjects:s,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=n;let c;if(s&&e&&"object"==typeof e){if(c=a.get(e),c)return c.anchor||(c.anchor=i(e)),new U(c.anchor);c={anchor:null,node:null},a.set(e,c)}t?.startsWith("!!")&&(t="tag:yaml.org,2002:"+t.slice(2));let l=function(e,t,n){if(t){const e=n.filter((e=>e.tag===t)),s=e.find((e=>!e.format))??e[0];if(!s)throw new Error(`Tag ${t} not found`);return s}return n.find((t=>t.identify?.(e)&&!t.format))}(e,t,o.tags);if(!l){if(e&&"function"==typeof e.toJSON&&(e=e.toJSON()),!e||"object"!=typeof e){const t=new W(e);return c&&(c.node=t),t}l=e instanceof Map?o[h]:Symbol.iterator in Object(e)?o[m]:o[h]}r&&(r(l),delete n.onTagObj);const u=l?.createNode?l.createNode(n.schema,e,n):"function"==typeof l?.nodeClass?.from?l.nodeClass.from(n.schema,e,n):new W(e);return t?u.tag=t:l.default||(u.tag=l.tag),c&&(c.node=u),u}function G(e,t,n){let s=n;for(let e=t.length-1;e>=0;--e){const n=t[e];if("number"==typeof n&&Number.isInteger(n)&&n>=0){const e=[];e[n]=s,s=e}else s=new Map([[n,s]])}return Y(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:e,sourceObjects:new Map})}const Q=e=>null==e||"object"==typeof e&&!!e[Symbol.iterator]().next().done;class H extends F{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){const t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map((t=>A(t)||w(t)?t.clone(e):t)),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(Q(e))this.add(t);else{const[n,...s]=e,i=this.get(n,!0);if(S(i))i.addIn(s,t);else{if(void 0!==i||!this.schema)throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`);this.set(n,G(this.schema,s,t))}}}deleteIn(e){const[t,...n]=e;if(0===n.length)return this.delete(t);const s=this.get(t,!0);if(S(s))return s.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){const[n,...s]=e,i=this.get(n,!0);return 0===s.length?!t&&k(i)?i.value:i:S(i)?i.getIn(s,t):void 0}hasAllNullValues(e){return this.items.every((t=>{if(!w(t))return!1;const n=t.value;return null==n||e&&k(n)&&null==n.value&&!n.commentBefore&&!n.comment&&!n.tag}))}hasIn(e){const[t,...n]=e;if(0===n.length)return this.has(t);const s=this.get(t,!0);return!!S(s)&&s.hasIn(n)}setIn(e,t){const[n,...s]=e;if(0===s.length)this.set(n,t);else{const e=this.get(n,!0);if(S(e))e.setIn(s,t);else{if(void 0!==e||!this.schema)throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`);this.set(n,G(this.schema,s,t))}}}}const X=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function z(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const Z=(e,t,n)=>e.endsWith("\n")?z(n,t):n.includes("\n")?"\n"+z(n,t):(e.endsWith(" ")?"":" ")+n,ee="flow",te="block",ne="quoted";function se(e,t,n="flow",{indentAtStart:s,lineWidth:i=80,minContentWidth:r=20,onFold:o,onOverflow:a}={}){if(!i||i<0)return e;i<r&&(r=0);const c=Math.max(1+r,1+i-t.length);if(e.length<=c)return e;const l=[],u={};let f,h,d=i-t.length;"number"==typeof s&&(s>i-Math.max(2,r)?l.push(0):d=i-s);let p=!1,m=-1,y=-1,g=-1;n===te&&(m=ie(e,m,t.length),-1!==m&&(d=m+c));for(let s;s=e[m+=1];){if(n===ne&&"\\"===s){switch(y=m,e[m+1]){case"x":m+=3;break;case"u":m+=5;break;case"U":m+=9;break;default:m+=1}g=m}if("\n"===s)n===te&&(m=ie(e,m,t.length)),d=m+t.length+c,f=void 0;else{if(" "===s&&h&&" "!==h&&"\n"!==h&&"\t"!==h){const t=e[m+1];t&&" "!==t&&"\n"!==t&&"\t"!==t&&(f=m)}if(m>=d)if(f)l.push(f),d=f+c,f=void 0;else if(n===ne){for(;" "===h||"\t"===h;)h=s,s=e[m+=1],p=!0;const t=m>g+1?m-2:y-1;if(u[t])return e;l.push(t),u[t]=!0,d=t+c,f=void 0}else p=!0}h=s}if(p&&a&&a(),0===l.length)return e;o&&o();let b=e.slice(0,l[0]);for(let s=0;s<l.length;++s){const i=l[s],r=l[s+1]||e.length;0===i?b=`\n${t}${e.slice(0,r)}`:(n===ne&&u[i]&&(b+=`${e[i]}\\`),b+=`\n${t}${e.slice(i+1,r)}`)}return b}function ie(e,t,n){let s=t,i=t+1,r=e[i];for(;" "===r||"\t"===r;)if(t<i+n)r=e[++t];else{do{r=e[++t]}while(r&&"\n"!==r);s=t,i=t+1,r=e[i]}return s}const re=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),oe=e=>/^(%|---|\.\.\.)/m.test(e);function ae(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,i=t.options.doubleQuotedMinMultiLineLength,r=t.indent||(oe(e)?"  ":"");let o="",a=0;for(let e=0,t=n[e];t;t=n[++e])if(" "===t&&"\\"===n[e+1]&&"n"===n[e+2]&&(o+=n.slice(a,e)+"\\ ",e+=1,a=e,t="\\"),"\\"===t)switch(n[e+1]){case"u":{o+=n.slice(a,e);const t=n.substr(e+2,4);switch(t){case"0000":o+="\\0";break;case"0007":o+="\\a";break;case"000b":o+="\\v";break;case"001b":o+="\\e";break;case"0085":o+="\\N";break;case"00a0":o+="\\_";break;case"2028":o+="\\L";break;case"2029":o+="\\P";break;default:"00"===t.substr(0,2)?o+="\\x"+t.substr(2):o+=n.substr(e,6)}e+=5,a=e+1}break;case"n":if(s||'"'===n[e+2]||n.length<i)e+=1;else{for(o+=n.slice(a,e)+"\n\n";"\\"===n[e+2]&&"n"===n[e+3]&&'"'!==n[e+4];)o+="\n",e+=2;o+=r," "===n[e+2]&&(o+="\\"),e+=1,a=e+1}break;default:e+=1}return o=a?o+n.slice(a):n,s?o:se(o,r,ne,re(t,!1))}function ce(e,t){if(!1===t.options.singleQuote||t.implicitKey&&e.includes("\n")||/[ \t]\n|\n[ \t]/.test(e))return ae(e,t);const n=t.indent||(oe(e)?"  ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&\n${n}`)+"'";return t.implicitKey?s:se(s,n,ee,re(t,!1))}function le(e,t){const{singleQuote:n}=t.options;let s;if(!1===n)s=ae;else{const t=e.includes('"'),i=e.includes("'");s=t&&!i?ce:i&&!t?ae:n?ce:ae}return s(e,t)}let ue;try{ue=new RegExp("(^|(?<!\n))\n+(?!\n|$)","g")}catch{ue=/\n+(?!\n|$)/g}function fe({comment:e,type:t,value:n},s,i,r){const{blockQuote:o,commentString:a,lineWidth:c}=s.options;if(!o||/\n[\t ]+$/.test(n)||/^\s*$/.test(n))return le(n,s);const l=s.indent||(s.forceBlockIndent||oe(n)?"  ":""),u="literal"===o||"folded"!==o&&t!==W.BLOCK_FOLDED&&(t===W.BLOCK_LITERAL||!function(e,t,n){if(!t||t<0)return!1;const s=t-n,i=e.length;if(i<=s)return!1;for(let t=0,n=0;t<i;++t)if("\n"===e[t]){if(t-n>s)return!0;if(n=t+1,i-n<=s)return!1}return!0}(n,c,l.length));if(!n)return u?"|\n":">\n";let f,h;for(h=n.length;h>0;--h){const e=n[h-1];if("\n"!==e&&"\t"!==e&&" "!==e)break}let d=n.substring(h);const p=d.indexOf("\n");-1===p?f="-":n===d||p!==d.length-1?(f="+",r&&r()):f="",d&&(n=n.slice(0,-d.length),"\n"===d[d.length-1]&&(d=d.slice(0,-1)),d=d.replace(ue,`$&${l}`));let m,y=!1,g=-1;for(m=0;m<n.length;++m){const e=n[m];if(" "===e)y=!0;else{if("\n"!==e)break;g=m}}let b=n.substring(0,g<m?g+1:m);b&&(n=n.substring(b.length),b=b.replace(/\n+/g,`$&${l}`));let v=(y?l?"2":"1":"")+f;if(e&&(v+=" "+a(e.replace(/ ?[\r\n]+/g," ")),i&&i()),!u){const e=n.replace(/\n+/g,"\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${l}`);let i=!1;const r=re(s,!0);"folded"!==o&&t!==W.BLOCK_FOLDED&&(r.onOverflow=()=>{i=!0});const a=se(`${b}${e}${d}`,l,te,r);if(!i)return`>${v}\n${l}${a}`}return`|${v}\n${l}${b}${n=n.replace(/\n+/g,`$&${l}`)}${d}`}function he(e,t,n,s){const{implicitKey:i,inFlow:r}=t,o="string"==typeof e.value?e:Object.assign({},e,{value:String(e.value)});let{type:a}=e;a!==W.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value)&&(a=W.QUOTE_DOUBLE);const c=e=>{switch(e){case W.BLOCK_FOLDED:case W.BLOCK_LITERAL:return i||r?le(o.value,t):fe(o,t,n,s);case W.QUOTE_DOUBLE:return ae(o.value,t);case W.QUOTE_SINGLE:return ce(o.value,t);case W.PLAIN:return function(e,t,n,s){const{type:i,value:r}=e,{actualString:o,implicitKey:a,indent:c,indentStep:l,inFlow:u}=t;if(a&&r.includes("\n")||u&&/[[\]{},]/.test(r))return le(r,t);if(!r||/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(r))return a||u||!r.includes("\n")?le(r,t):fe(e,t,n,s);if(!a&&!u&&i!==W.PLAIN&&r.includes("\n"))return fe(e,t,n,s);if(oe(r)){if(""===c)return t.forceBlockIndent=!0,fe(e,t,n,s);if(a&&c===l)return le(r,t)}const f=r.replace(/\n+/g,`$&\n${c}`);if(o){const e=e=>e.default&&"tag:yaml.org,2002:str"!==e.tag&&e.test?.test(f),{compat:n,tags:s}=t.doc.schema;if(s.some(e)||n?.some(e))return le(r,t)}return a?f:se(f,c,ee,re(t,!1))}(o,t,n,s);default:return null}};let l=c(a);if(null===l){const{defaultKeyType:e,defaultStringType:n}=t.options,s=i&&e||n;if(l=c(s),null===l)throw new Error(`Unsupported default string type ${s}`)}return l}function de(e,t){const n=Object.assign({blockQuote:!0,commentString:X,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trueStr:"true",verifyAliasOrder:!0},e.schema.toStringOptions,t);let s;switch(n.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?" ":"",indent:"",indentStep:"number"==typeof n.indent?" ".repeat(n.indent):"  ",inFlow:s,options:n}}function pe(e,t,n,s){if(w(e))return e.toString(t,n,s);if(g(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw new TypeError("Cannot stringify circular structure without alias nodes");t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=new Set([e]),e=e.resolve(t.doc)}let i;const r=A(e)?e:t.doc.createNode(e,{onTagObj:e=>i=e});i||(i=function(e,t){if(t.tag){const n=e.filter((e=>e.tag===t.tag));if(n.length>0)return n.find((e=>e.format===t.format))??n[0]}let n,s;if(k(t)){s=t.value;let i=e.filter((e=>e.identify?.(s)));if(i.length>1){const e=i.filter((e=>e.test));e.length>0&&(i=e)}n=i.find((e=>e.format===t.format))??i.find((e=>!e.format))}else s=t,n=e.find((e=>e.nodeClass&&s instanceof e.nodeClass));if(!n)throw new Error(`Tag not resolved for ${s?.constructor?.name??typeof s} value`);return n}(t.doc.schema.tags,r));const o=function(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const i=[],r=(k(e)||S(e))&&e.anchor;r&&M(r)&&(n.add(r),i.push(`&${r}`));const o=e.tag?e.tag:t.default?null:t.tag;return o&&i.push(s.directives.tagString(o)),i.join(" ")}(r,i,t);o.length>0&&(t.indentAtStart=(t.indentAtStart??0)+o.length+1);const a="function"==typeof i.stringify?i.stringify(r,t,n,s):k(r)?he(r,t,n,s):r.toString(t,n,s);return o?k(r)||"{"===a[0]||"["===a[0]?`${o} ${a}`:`${o}\n${t.indent}${a}`:a}function me(e,t){"debug"!==e&&"warn"!==e||("undefined"!=typeof process&&process.emitWarning?process.emitWarning(t):console.warn(t))}const ye="<<",ge={identify:e=>e===ye||"symbol"==typeof e&&e.description===ye,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new W(Symbol(ye)),{addToJSMap:be}),stringify:()=>ye};function be(e,t,n){if(n=e&&g(n)?n.resolve(e.doc):n,E(n))for(const s of n.items)ve(e,t,s);else if(Array.isArray(n))for(const s of n)ve(e,t,s);else ve(e,t,n)}function ve(e,t,n){const s=e&&g(n)?n.resolve(e.doc):n;if(!v(s))throw new Error("Merge sources must be maps or map aliases");const i=s.toJSON(null,e,Map);for(const[e,n]of i)t instanceof Map?t.has(e)||t.set(e,n):t instanceof Set?t.add(e):Object.prototype.hasOwnProperty.call(t,e)||Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0});return t}function we(e,t,{key:n,value:s}){if(A(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(((e,t)=>(ge.identify(t)||k(t)&&(!t.type||t.type===W.PLAIN)&&ge.identify(t.value))&&e?.doc.schema.tags.some((e=>e.tag===ge.tag&&e.default)))(e,n))be(e,t,s);else{const i=q(n,"",e);if(t instanceof Map)t.set(i,q(s,i,e));else if(t instanceof Set)t.add(i);else{const r=function(e,t,n){if(null===t)return"";if("object"!=typeof t)return String(t);if(A(e)&&n?.doc){const t=de(n.doc,{});t.anchors=new Set;for(const e of n.anchors.keys())t.anchors.add(e.anchor);t.inFlow=!0,t.inStringifyKey=!0;const s=e.toString(t);if(!n.mapKeyWarned){let e=JSON.stringify(s);e.length>40&&(e=e.substring(0,36)+'..."'),me(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${e}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return s}return JSON.stringify(t)}(n,i,e),o=q(s,r,e);r in t?Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):t[r]=o}}return t}function ke(e,t,n){const s=Y(e,void 0,n),i=Y(t,void 0,n);return new Ee(s,i)}class Ee{constructor(e,t=null){Object.defineProperty(this,y,{value:d}),this.key=e,this.value=t}clone(e){let{key:t,value:n}=this;return A(t)&&(t=t.clone(e)),A(n)&&(n=n.clone(e)),new Ee(t,n)}toJSON(e,t){return we(t,t?.mapAsMap?new Map:{},this)}toString(e,t,n){return e?.doc?function({key:e,value:t},n,s,i){const{allNullValues:r,doc:o,indent:a,indentStep:c,options:{commentString:l,indentSeq:u,simpleKeys:f}}=n;let h=A(e)&&e.comment||null;if(f){if(h)throw new Error("With simple keys, key nodes cannot have comments");if(S(e)||!A(e)&&"object"==typeof e)throw new Error("With simple keys, collection cannot be used as a key value")}let d=!f&&(!e||h&&null==t&&!n.inFlow||S(e)||(k(e)?e.type===W.BLOCK_FOLDED||e.type===W.BLOCK_LITERAL:"object"==typeof e));n=Object.assign({},n,{allNullValues:!1,implicitKey:!d&&(f||!r),indent:a+c});let p,m,y,g=!1,b=!1,v=pe(e,n,(()=>g=!0),(()=>b=!0));if(!d&&!n.inFlow&&v.length>1024){if(f)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");d=!0}if(n.inFlow){if(r||null==t)return g&&s&&s(),""===v?"?":d?`? ${v}`:v}else if(r&&!f||null==t&&d)return v=`? ${v}`,h&&!g?v+=Z(v,n.indent,l(h)):b&&i&&i(),v;g&&(h=null),d?(h&&(v+=Z(v,n.indent,l(h))),v=`? ${v}\n${a}:`):(v=`${v}:`,h&&(v+=Z(v,n.indent,l(h)))),A(t)?(p=!!t.spaceBefore,m=t.commentBefore,y=t.comment):(p=!1,m=null,y=null,t&&"object"==typeof t&&(t=o.createNode(t))),n.implicitKey=!1,d||h||!k(t)||(n.indentAtStart=v.length+1),b=!1,u||!(c.length>=2)||n.inFlow||d||!E(t)||t.flow||t.tag||t.anchor||(n.indent=n.indent.substring(2));let w=!1;const N=pe(t,n,(()=>w=!0),(()=>b=!0));let O=" ";if(h||p||m)O=p?"\n":"",m&&(O+=`\n${z(l(m),n.indent)}`),""!==N||n.inFlow?O+=`\n${n.indent}`:"\n"===O&&(O="\n\n");else if(!d&&S(t)){const e=N[0],s=N.indexOf("\n"),i=-1!==s,r=n.inFlow??t.flow??0===t.items.length;if(i||!r){let t=!1;if(i&&("&"===e||"!"===e)){let n=N.indexOf(" ");"&"===e&&-1!==n&&n<s&&"!"===N[n+1]&&(n=N.indexOf(" ",n+1)),(-1===n||s<n)&&(t=!0)}t||(O=`\n${n.indent}`)}}else""!==N&&"\n"!==N[0]||(O="");return v+=O+N,n.inFlow?w&&s&&s():y&&!w?v+=Z(v,n.indent,l(y)):b&&i&&i(),v}(this,e,t,n):JSON.stringify(this)}}function Se(e,t,n){return(t.inFlow??e.flow?Ne:Ae)(e,t,n)}function Ae({comment:e,items:t},n,{blockItemPrefix:s,flowChars:i,itemIndent:r,onChompKeep:o,onComment:a}){const{indent:c,options:{commentString:l}}=n,u=Object.assign({},n,{indent:r,type:null});let f=!1;const h=[];for(let e=0;e<t.length;++e){const i=t[e];let o=null;if(A(i))!f&&i.spaceBefore&&h.push(""),Oe(n,h,i.commentBefore,f),i.comment&&(o=i.comment);else if(w(i)){const e=A(i.key)?i.key:null;e&&(!f&&e.spaceBefore&&h.push(""),Oe(n,h,e.commentBefore,f))}f=!1;let a=pe(i,u,(()=>o=null),(()=>f=!0));o&&(a+=Z(a,r,l(o))),f&&o&&(f=!1),h.push(s+a)}let d;if(0===h.length)d=i.start+i.end;else{d=h[0];for(let e=1;e<h.length;++e){const t=h[e];d+=t?`\n${c}${t}`:"\n"}}return e?(d+="\n"+z(l(e),c),a&&a()):f&&o&&o(),d}function Ne({items:e},t,{flowChars:n,itemIndent:s}){const{indent:i,indentStep:r,flowCollectionPadding:o,options:{commentString:a}}=t;s+=r;const c=Object.assign({},t,{indent:s,inFlow:!0,type:null});let l=!1,u=0;const f=[];for(let n=0;n<e.length;++n){const i=e[n];let r=null;if(A(i))i.spaceBefore&&f.push(""),Oe(t,f,i.commentBefore,!1),i.comment&&(r=i.comment);else if(w(i)){const e=A(i.key)?i.key:null;e&&(e.spaceBefore&&f.push(""),Oe(t,f,e.commentBefore,!1),e.comment&&(l=!0));const n=A(i.value)?i.value:null;n?(n.comment&&(r=n.comment),n.commentBefore&&(l=!0)):null==i.value&&e?.comment&&(r=e.comment)}r&&(l=!0);let o=pe(i,c,(()=>r=null));n<e.length-1&&(o+=","),r&&(o+=Z(o,s,a(r))),!l&&(f.length>u||o.includes("\n"))&&(l=!0),f.push(o),u=f.length}const{start:h,end:d}=n;if(0===f.length)return h+d;if(!l){const e=f.reduce(((e,t)=>e+t.length+2),2);l=t.options.lineWidth>0&&e>t.options.lineWidth}if(l){let e=h;for(const t of f)e+=t?`\n${r}${i}${t}`:"\n";return`${e}\n${i}${d}`}return`${h}${o}${f.join(" ")}${o}${d}`}function Oe({indent:e,options:{commentString:t}},n,s,i){if(s&&i&&(s=s.replace(/^\n+/,"")),s){const i=z(t(s),e);n.push(i.trimStart())}}function $e(e,t){const n=k(t)?t.value:t;for(const s of e)if(w(s)){if(s.key===t||s.key===n)return s;if(k(s.key)&&s.key.value===n)return s}}class Ie extends H{static get tagName(){return"tag:yaml.org,2002:map"}constructor(e){super(h,e),this.items=[]}static from(e,t,n){const{keepUndefined:s,replacer:i}=n,r=new this(e),o=(e,o)=>{if("function"==typeof i)o=i.call(t,e,o);else if(Array.isArray(i)&&!i.includes(e))return;(void 0!==o||s)&&r.items.push(ke(e,o,n))};if(t instanceof Map)for(const[e,n]of t)o(e,n);else if(t&&"object"==typeof t)for(const e of Object.keys(t))o(e,t[e]);return"function"==typeof e.sortMapEntries&&r.items.sort(e.sortMapEntries),r}add(e,t){let n;n=w(e)?e:e&&"object"==typeof e&&"key"in e?new Ee(e.key,e.value):new Ee(e,e?.value);const s=$e(this.items,n.key),i=this.schema?.sortMapEntries;if(s){if(!t)throw new Error(`Key ${n.key} already set`);k(s.value)&&J(n.value)?s.value.value=n.value:s.value=n.value}else if(i){const e=this.items.findIndex((e=>i(n,e)<0));-1===e?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){const t=$e(this.items,e);if(!t)return!1;return this.items.splice(this.items.indexOf(t),1).length>0}get(e,t){const n=$e(this.items,e),s=n?.value;return(!t&&k(s)?s.value:s)??void 0}has(e){return!!$e(this.items,e)}set(e,t){this.add(new Ee(e,t),!0)}toJSON(e,t,n){const s=n?new n:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(s);for(const e of this.items)we(t,s,e);return s}toString(e,t,n){if(!e)return JSON.stringify(this);for(const e of this.items)if(!w(e))throw new Error(`Map items must all be pairs; found ${JSON.stringify(e)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),Se(this,e,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:e.indent||"",onChompKeep:n,onComment:t})}}const xe={collection:"map",default:!0,nodeClass:Ie,tag:"tag:yaml.org,2002:map",resolve:(e,t)=>(v(e)||t("Expected a mapping for this tag"),e),createNode:(e,t,n)=>Ie.from(e,t,n)};class Te extends H{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(e){super(m,e),this.items=[]}add(e){this.items.push(e)}delete(e){const t=Le(e);if("number"!=typeof t)return!1;return this.items.splice(t,1).length>0}get(e,t){const n=Le(e);if("number"!=typeof n)return;const s=this.items[n];return!t&&k(s)?s.value:s}has(e){const t=Le(e);return"number"==typeof t&&t<this.items.length}set(e,t){const n=Le(e);if("number"!=typeof n)throw new Error(`Expected a valid index, not ${e}.`);const s=this.items[n];k(s)&&J(t)?s.value=t:this.items[n]=t}toJSON(e,t){const n=[];t?.onCreate&&t.onCreate(n);let s=0;for(const e of this.items)n.push(q(e,String(s++),t));return n}toString(e,t,n){return e?Se(this,e,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(e.indent||"")+"  ",onChompKeep:n,onComment:t}):JSON.stringify(this)}static from(e,t,n){const{replacer:s}=n,i=new this(e);if(t&&Symbol.iterator in Object(t)){let e=0;for(let r of t){if("function"==typeof s){const n=t instanceof Set?r:String(e++);r=s.call(t,n,r)}i.items.push(Y(r,void 0,n))}}return i}}function Le(e){let t=k(e)?e.value:e;return t&&"string"==typeof t&&(t=Number(t)),"number"==typeof t&&Number.isInteger(t)&&t>=0?t:null}const Ce={collection:"seq",default:!0,nodeClass:Te,tag:"tag:yaml.org,2002:seq",resolve:(e,t)=>(E(e)||t("Expected a sequence for this tag"),e),createNode:(e,t,n)=>Te.from(e,t,n)},_e={identify:e=>"string"==typeof e,default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:(e,t,n,s)=>he(e,t=Object.assign({actualString:!0},t),n,s)},je={identify:e=>null==e,createNode:()=>new W(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new W(null),stringify:({source:e},t)=>"string"==typeof e&&je.test.test(e)?e:t.options.nullStr},Be={identify:e=>"boolean"==typeof e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new W("t"===e[0]||"T"===e[0]),stringify({source:e,value:t},n){if(e&&Be.test.test(e)){if(t===("t"===e[0]||"T"===e[0]))return e}return t?n.options.trueStr:n.options.falseStr}};function Ke({format:e,minFractionDigits:t,tag:n,value:s}){if("bigint"==typeof s)return String(s);const i="number"==typeof s?s:Number(s);if(!isFinite(i))return isNaN(i)?".nan":i<0?"-.inf":".inf";let r=JSON.stringify(s);if(!e&&t&&(!n||"tag:yaml.org,2002:float"===n)&&/^\d/.test(r)){let e=r.indexOf(".");e<0&&(e=r.length,r+=".");let n=t-(r.length-e-1);for(;n-- >0;)r+="0"}return r}const Me={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>"nan"===e.slice(-3).toLowerCase()?NaN:"-"===e[0]?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Ke},De={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():Ke(e)}},Re={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(e){const t=new W(parseFloat(e)),n=e.indexOf(".");return-1!==n&&"0"===e[e.length-1]&&(t.minFractionDigits=e.length-n-1),t},stringify:Ke},Pe=e=>"bigint"==typeof e||Number.isInteger(e),qe=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function Fe(e,t,n){const{value:s}=e;return Pe(s)&&s>=0?n+s.toString(t):Ke(e)}const Ue={identify:e=>Pe(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>qe(e,2,8,n),stringify:e=>Fe(e,8,"0o")},Ve={identify:Pe,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>qe(e,0,10,n),stringify:Ke},Je={identify:e=>Pe(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>qe(e,2,16,n),stringify:e=>Fe(e,16,"0x")},We=[xe,Ce,_e,je,Be,Ue,Ve,Je,Me,De,Re];function Ye(e){return"bigint"==typeof e||Number.isInteger(e)}const Ge=({value:e})=>JSON.stringify(e),Qe=[xe,Ce].concat([{identify:e=>"string"==typeof e,default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:Ge},{identify:e=>null==e,createNode:()=>new W(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:Ge},{identify:e=>"boolean"==typeof e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:e=>"true"===e,stringify:Ge},{identify:Ye,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>Ye(e)?e.toString():JSON.stringify(e)},{identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:Ge}],{default:!0,tag:"",test:/^/,resolve:(e,t)=>(t(`Unresolved plain scalar ${JSON.stringify(e)}`),e)}),He={identify:e=>e instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(e,t){if("function"==typeof Buffer)return Buffer.from(e,"base64");if("function"==typeof atob){const t=atob(e.replace(/[\n\r]/g,"")),n=new Uint8Array(t.length);for(let e=0;e<t.length;++e)n[e]=t.charCodeAt(e);return n}return t("This environment does not support reading binary tags; either Buffer or atob is required"),e},stringify({comment:e,type:t,value:n},s,i,r){const o=n;let a;if("function"==typeof Buffer)a=o instanceof Buffer?o.toString("base64"):Buffer.from(o.buffer).toString("base64");else{if("function"!=typeof btoa)throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");{let e="";for(let t=0;t<o.length;++t)e+=String.fromCharCode(o[t]);a=btoa(e)}}if(t||(t=W.BLOCK_LITERAL),t!==W.QUOTE_DOUBLE){const e=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),n=Math.ceil(a.length/e),i=new Array(n);for(let t=0,s=0;t<n;++t,s+=e)i[t]=a.substr(s,e);a=i.join(t===W.BLOCK_LITERAL?"\n":" ")}return he({comment:e,type:t,value:a},s,i,r)}};function Xe(e,t){if(E(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!w(s)){if(v(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const e=s.items[0]||new Ee(new W(null));if(s.commentBefore&&(e.key.commentBefore=e.key.commentBefore?`${s.commentBefore}\n${e.key.commentBefore}`:s.commentBefore),s.comment){const t=e.value??e.key;t.comment=t.comment?`${s.comment}\n${t.comment}`:s.comment}s=e}e.items[n]=w(s)?s:new Ee(s)}}else t("Expected a sequence for this tag");return e}function ze(e,t,n){const{replacer:s}=n,i=new Te(e);i.tag="tag:yaml.org,2002:pairs";let r=0;if(t&&Symbol.iterator in Object(t))for(let e of t){let o,a;if("function"==typeof s&&(e=s.call(t,String(r++),e)),Array.isArray(e)){if(2!==e.length)throw new TypeError(`Expected [key, value] tuple: ${e}`);o=e[0],a=e[1]}else if(e&&e instanceof Object){const t=Object.keys(e);if(1!==t.length)throw new TypeError(`Expected tuple with one key, not ${t.length} keys`);o=t[0],a=e[o]}else o=e;i.items.push(ke(o,a,n))}return i}const Ze={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:Xe,createNode:ze};class et extends Te{constructor(){super(),this.add=Ie.prototype.add.bind(this),this.delete=Ie.prototype.delete.bind(this),this.get=Ie.prototype.get.bind(this),this.has=Ie.prototype.has.bind(this),this.set=Ie.prototype.set.bind(this),this.tag=et.tag}toJSON(e,t){if(!t)return super.toJSON(e);const n=new Map;t?.onCreate&&t.onCreate(n);for(const e of this.items){let s,i;if(w(e)?(s=q(e.key,"",t),i=q(e.value,s,t)):s=q(e,"",t),n.has(s))throw new Error("Ordered maps must not include duplicate keys");n.set(s,i)}return n}static from(e,t,n){const s=ze(e,t,n),i=new this;return i.items=s.items,i}}et.tag="tag:yaml.org,2002:omap";const tt={collection:"seq",identify:e=>e instanceof Map,nodeClass:et,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=Xe(e,t),s=[];for(const{key:e}of n.items)k(e)&&(s.includes(e.value)?t(`Ordered maps must not include duplicate keys: ${e.value}`):s.push(e.value));return Object.assign(new et,n)},createNode:(e,t,n)=>et.from(e,t,n)};function nt({value:e,source:t},n){return t&&(e?st:it).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const st={identify:e=>!0===e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new W(!0),stringify:nt},it={identify:e=>!1===e,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new W(!1),stringify:nt},rt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>"nan"===e.slice(-3).toLowerCase()?NaN:"-"===e[0]?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Ke},ot={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,"")),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():Ke(e)}},at={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){const t=new W(parseFloat(e.replace(/_/g,""))),n=e.indexOf(".");if(-1!==n){const s=e.substring(n+1).replace(/_/g,"");"0"===s[s.length-1]&&(t.minFractionDigits=s.length)}return t},stringify:Ke},ct=e=>"bigint"==typeof e||Number.isInteger(e);function lt(e,t,n,{intAsBigInt:s}){const i=e[0];if("-"!==i&&"+"!==i||(t+=1),e=e.substring(t).replace(/_/g,""),s){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`}const t=BigInt(e);return"-"===i?BigInt(-1)*t:t}const r=parseInt(e,n);return"-"===i?-1*r:r}function ut(e,t,n){const{value:s}=e;if(ct(s)){const e=s.toString(t);return s<0?"-"+n+e.substr(1):n+e}return Ke(e)}const ft={identify:ct,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>lt(e,2,2,n),stringify:e=>ut(e,2,"0b")},ht={identify:ct,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>lt(e,1,8,n),stringify:e=>ut(e,8,"0")},dt={identify:ct,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>lt(e,0,10,n),stringify:Ke},pt={identify:ct,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>lt(e,2,16,n),stringify:e=>ut(e,16,"0x")};class mt extends Ie{constructor(e){super(e),this.tag=mt.tag}add(e){let t;t=w(e)?e:e&&"object"==typeof e&&"key"in e&&"value"in e&&null===e.value?new Ee(e.key,null):new Ee(e,null);$e(this.items,t.key)||this.items.push(t)}get(e,t){const n=$e(this.items,e);return!t&&w(n)?k(n.key)?n.key.value:n.key:n}set(e,t){if("boolean"!=typeof t)throw new Error("Expected boolean value for set(key, value) in a YAML set, not "+typeof t);const n=$e(this.items,e);n&&!t?this.items.splice(this.items.indexOf(n),1):!n&&t&&this.items.push(new Ee(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw new Error("Set items must all have null values")}static from(e,t,n){const{replacer:s}=n,i=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)"function"==typeof s&&(e=s.call(t,e,e)),i.items.push(ke(e,null,n));return i}}mt.tag="tag:yaml.org,2002:set";const yt={collection:"map",identify:e=>e instanceof Set,nodeClass:mt,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>mt.from(e,t,n),resolve(e,t){if(v(e)){if(e.hasAllNullValues(!0))return Object.assign(new mt,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function gt(e,t){const n=e[0],s="-"===n||"+"===n?e.substring(1):e,i=e=>t?BigInt(e):Number(e),r=s.replace(/_/g,"").split(":").reduce(((e,t)=>e*i(60)+i(t)),i(0));return"-"===n?i(-1)*r:r}function bt(e){let{value:t}=e,n=e=>e;if("bigint"==typeof t)n=e=>BigInt(e);else if(isNaN(t)||!isFinite(t))return Ke(e);let s="";t<0&&(s="-",t*=n(-1));const i=n(60),r=[t%i];return t<60?r.unshift(0):(t=(t-r[0])/i,r.unshift(t%i),t>=60&&(t=(t-r[0])/i,r.unshift(t))),s+r.map((e=>String(e).padStart(2,"0"))).join(":").replace(/000000\d*$/,"")}const vt={identify:e=>"bigint"==typeof e||Number.isInteger(e),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:n})=>gt(e,n),stringify:bt},wt={identify:e=>"number"==typeof e,default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>gt(e,!1),stringify:bt},kt={identify:e=>e instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(e){const t=e.match(kt.test);if(!t)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");const[,n,s,i,r,o,a]=t.map(Number),c=t[7]?Number((t[7]+"00").substr(1,3)):0;let l=Date.UTC(n,s-1,i,r||0,o||0,a||0,c);const u=t[8];if(u&&"Z"!==u){let e=gt(u,!1);Math.abs(e)<30&&(e*=60),l-=6e4*e}return new Date(l)},stringify:({value:e})=>e.toISOString().replace(/(T00:00:00)?\.000Z$/,"")},Et=[xe,Ce,_e,je,st,it,ft,ht,dt,pt,rt,ot,at,He,ge,tt,Ze,yt,vt,wt,kt],St=new Map([["core",We],["failsafe",[xe,Ce,_e]],["json",Qe],["yaml11",Et],["yaml-1.1",Et]]),At={binary:He,bool:Be,float:Re,floatExp:De,floatNaN:Me,floatTime:wt,int:Ve,intHex:Je,intOct:Ue,intTime:vt,map:xe,merge:ge,null:je,omap:tt,pairs:Ze,seq:Ce,set:yt,timestamp:kt},Nt={"tag:yaml.org,2002:binary":He,"tag:yaml.org,2002:merge":ge,"tag:yaml.org,2002:omap":tt,"tag:yaml.org,2002:pairs":Ze,"tag:yaml.org,2002:set":yt,"tag:yaml.org,2002:timestamp":kt};function Ot(e,t,n){const s=St.get(t);if(s&&!e)return n&&!s.includes(ge)?s.concat(ge):s.slice();let i=s;if(!i){if(!Array.isArray(e)){const e=Array.from(St.keys()).filter((e=>"yaml11"!==e)).map((e=>JSON.stringify(e))).join(", ");throw new Error(`Unknown schema "${t}"; use one of ${e} or define customTags array`)}i=[]}if(Array.isArray(e))for(const t of e)i=i.concat(t);else"function"==typeof e&&(i=e(i.slice()));return n&&(i=i.concat(ge)),i.reduce(((e,t)=>{const n="string"==typeof t?At[t]:t;if(!n){const e=JSON.stringify(t),n=Object.keys(At).map((e=>JSON.stringify(e))).join(", ");throw new Error(`Unknown custom tag ${e}; use one of ${n}`)}return e.includes(n)||e.push(n),e}),[])}const $t=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;class It{constructor({compat:e,customTags:t,merge:n,resolveKnownTags:s,schema:i,sortMapEntries:r,toStringDefaults:o}){this.compat=Array.isArray(e)?Ot(e,"compat"):e?Ot(null,e):null,this.name="string"==typeof i&&i||"core",this.knownTags=s?Nt:{},this.tags=Ot(t,this.name,n),this.toStringOptions=o??null,Object.defineProperty(this,h,{value:xe}),Object.defineProperty(this,p,{value:_e}),Object.defineProperty(this,m,{value:Ce}),this.sortMapEntries="function"==typeof r?r:!0===r?$t:null}clone(){const e=Object.create(It.prototype,Object.getOwnPropertyDescriptors(this));return e.tags=this.tags.slice(),e}}class xt{constructor(e,t,n){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,y,{value:f});let s=null;"function"==typeof t||Array.isArray(t)?s=t:void 0===n&&t&&(n=t,t=void 0);const i=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:"1.2"},n);this.options=i;let{version:r}=i;n?._directives?(this.directives=n._directives.atDocument(),this.directives.yaml.explicit&&(r=this.directives.yaml.version)):this.directives=new K({version:r}),this.setSchema(r,n),this.contents=void 0===e?null:this.createNode(e,s,n)}clone(){const e=Object.create(xt.prototype,{[y]:{value:f}});return e.commentBefore=this.commentBefore,e.comment=this.comment,e.errors=this.errors.slice(),e.warnings=this.warnings.slice(),e.options=Object.assign({},this.options),this.directives&&(e.directives=this.directives.clone()),e.schema=this.schema.clone(),e.contents=A(this.contents)?this.contents.clone(e.schema):this.contents,this.range&&(e.range=this.range.slice()),e}add(e){Tt(this.contents)&&this.contents.add(e)}addIn(e,t){Tt(this.contents)&&this.contents.addIn(e,t)}createAlias(e,t){if(!e.anchor){const n=D(this);e.anchor=!t||n.has(t)?R(t||"a",n):t}return new U(e.anchor)}createNode(e,t,n){let s;if("function"==typeof t)e=t.call({"":e},"",e),s=t;else if(Array.isArray(t)){const e=e=>"number"==typeof e||e instanceof String||e instanceof Number,n=t.filter(e).map(String);n.length>0&&(t=t.concat(n)),s=t}else void 0===n&&t&&(n=t,t=void 0);const{aliasDuplicateObjects:i,anchorPrefix:r,flow:o,keepUndefined:a,onTagObj:c,tag:l}=n??{},{onAnchor:u,setAnchors:f,sourceObjects:h}=function(e,t){const n=[],s=new Map;let i=null;return{onAnchor:s=>{n.push(s),i||(i=D(e));const r=R(t,i);return i.add(r),r},setAnchors:()=>{for(const e of n){const t=s.get(e);if("object"!=typeof t||!t.anchor||!k(t.node)&&!S(t.node)){const t=new Error("Failed to resolve repeated object (this should not happen)");throw t.source=e,t}t.node.anchor=t.anchor}},sourceObjects:s}}(this,r||"a"),d=Y(e,l,{aliasDuplicateObjects:i??!0,keepUndefined:a??!1,onAnchor:u,onTagObj:c,replacer:s,schema:this.schema,sourceObjects:h});return o&&S(d)&&(d.flow=!0),f(),d}createPair(e,t,n={}){const s=this.createNode(e,null,n),i=this.createNode(t,null,n);return new Ee(s,i)}delete(e){return!!Tt(this.contents)&&this.contents.delete(e)}deleteIn(e){return Q(e)?null!=this.contents&&(this.contents=null,!0):!!Tt(this.contents)&&this.contents.deleteIn(e)}get(e,t){return S(this.contents)?this.contents.get(e,t):void 0}getIn(e,t){return Q(e)?!t&&k(this.contents)?this.contents.value:this.contents:S(this.contents)?this.contents.getIn(e,t):void 0}has(e){return!!S(this.contents)&&this.contents.has(e)}hasIn(e){return Q(e)?void 0!==this.contents:!!S(this.contents)&&this.contents.hasIn(e)}set(e,t){null==this.contents?this.contents=G(this.schema,[e],t):Tt(this.contents)&&this.contents.set(e,t)}setIn(e,t){Q(e)?this.contents=t:null==this.contents?this.contents=G(this.schema,Array.from(e),t):Tt(this.contents)&&this.contents.setIn(e,t)}setSchema(e,t={}){let n;switch("number"==typeof e&&(e=String(e)),e){case"1.1":this.directives?this.directives.yaml.version="1.1":this.directives=new K({version:"1.1"}),n={resolveKnownTags:!1,schema:"yaml-1.1"};break;case"1.2":case"next":this.directives?this.directives.yaml.version=e:this.directives=new K({version:e}),n={resolveKnownTags:!0,schema:"core"};break;case null:this.directives&&delete this.directives,n=null;break;default:{const t=JSON.stringify(e);throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${t}`)}}if(t.schema instanceof Object)this.schema=t.schema;else{if(!n)throw new Error("With a null YAML version, the { schema: Schema } option is required");this.schema=new It(Object.assign(n,t))}}toJS({json:e,jsonArg:t,mapAsMap:n,maxAliasCount:s,onAnchor:i,reviver:r}={}){const o={anchors:new Map,doc:this,keep:!e,mapAsMap:!0===n,mapKeyWarned:!1,maxAliasCount:"number"==typeof s?s:100},a=q(this.contents,t??"",o);if("function"==typeof i)for(const{count:e,res:t}of o.anchors.values())i(t,e);return"function"==typeof r?P(r,{"":a},"",a):a}toJSON(e,t){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:t})}toString(e={}){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");if("indent"in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){const t=JSON.stringify(e.indent);throw new Error(`"indent" option must be a positive integer, not ${t}`)}return function(e,t){const n=[];let s=!0===t.directives;if(!1!==t.directives&&e.directives){const t=e.directives.toString(e);t?(n.push(t),s=!0):e.directives.docStart&&(s=!0)}s&&n.push("---");const i=de(e,t),{commentString:r}=i.options;if(e.commentBefore){1!==n.length&&n.unshift("");const t=r(e.commentBefore);n.unshift(z(t,""))}let o=!1,a=null;if(e.contents){if(A(e.contents)){if(e.contents.spaceBefore&&s&&n.push(""),e.contents.commentBefore){const t=r(e.contents.commentBefore);n.push(z(t,""))}i.forceBlockIndent=!!e.comment,a=e.contents.comment}const t=a?void 0:()=>o=!0;let c=pe(e.contents,i,(()=>a=null),t);a&&(c+=Z(c,"",r(a))),"|"!==c[0]&&">"!==c[0]||"---"!==n[n.length-1]?n.push(c):n[n.length-1]=`--- ${c}`}else n.push(pe(e.contents,i));if(e.directives?.docEnd)if(e.comment){const t=r(e.comment);t.includes("\n")?(n.push("..."),n.push(z(t,""))):n.push(`... ${t}`)}else n.push("...");else{let t=e.comment;t&&o&&(t=t.replace(/^\n+/,"")),t&&(o&&!a||""===n[n.length-1]||n.push(""),n.push(z(r(t),"")))}return n.join("\n")+"\n"}(this,e)}}function Tt(e){if(S(e))return!0;throw new Error("Expected a YAML collection as document contents")}class Lt extends Error{constructor(e,t,n,s){super(),this.name=e,this.code=n,this.message=s,this.pos=t}}class Ct extends Lt{constructor(e,t,n){super("YAMLParseError",e,t,n)}}class _t extends Lt{constructor(e,t,n){super("YAMLWarning",e,t,n)}}const jt=(e,t)=>n=>{if(-1===n.pos[0])return;n.linePos=n.pos.map((e=>t.linePos(e)));const{line:s,col:i}=n.linePos[0];n.message+=` at line ${s}, column ${i}`;let r=i-1,o=e.substring(t.lineStarts[s-1],t.lineStarts[s]).replace(/[\n\r]+$/,"");if(r>=60&&o.length>80){const e=Math.min(r-39,o.length-79);o="…"+o.substring(e),r-=e-1}if(o.length>80&&(o=o.substring(0,79)+"…"),s>1&&/^ *$/.test(o.substring(0,r))){let n=e.substring(t.lineStarts[s-2],t.lineStarts[s-1]);n.length>80&&(n=n.substring(0,79)+"…\n"),o=n+o}if(/[^ ]/.test(o)){let e=1;const t=n.linePos[1];t&&t.line===s&&t.col>i&&(e=Math.max(1,Math.min(t.col-i,80-r)));const a=" ".repeat(r)+"^".repeat(e);n.message+=`:\n\n${o}\n${a}\n`}};function Bt(e,{flow:t,indicator:n,next:s,offset:i,onError:r,parentIndent:o,startOnNewline:a}){let c=!1,l=a,u=a,f="",h="",d=!1,p=!1,m=null,y=null,g=null,b=null,v=null,w=null,k=null;for(const i of e)switch(p&&("space"!==i.type&&"newline"!==i.type&&"comma"!==i.type&&r(i.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),p=!1),m&&(l&&"comment"!==i.type&&"newline"!==i.type&&r(m,"TAB_AS_INDENT","Tabs are not allowed as indentation"),m=null),i.type){case"space":t||"doc-start"===n&&"flow-collection"===s?.type||!i.source.includes("\t")||(m=i),u=!0;break;case"comment":{u||r(i,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const e=i.source.substring(1)||" ";f?f+=h+e:f=e,h="",l=!1;break}case"newline":l?f?f+=i.source:c=!0:h+=i.source,l=!0,d=!0,(y||g)&&(b=i),u=!0;break;case"anchor":y&&r(i,"MULTIPLE_ANCHORS","A node can have at most one anchor"),i.source.endsWith(":")&&r(i.offset+i.source.length-1,"BAD_ALIAS","Anchor ending in : is ambiguous",!0),y=i,null===k&&(k=i.offset),l=!1,u=!1,p=!0;break;case"tag":g&&r(i,"MULTIPLE_TAGS","A node can have at most one tag"),g=i,null===k&&(k=i.offset),l=!1,u=!1,p=!0;break;case n:(y||g)&&r(i,"BAD_PROP_ORDER",`Anchors and tags must be after the ${i.source} indicator`),w&&r(i,"UNEXPECTED_TOKEN",`Unexpected ${i.source} in ${t??"collection"}`),w=i,l="seq-item-ind"===n||"explicit-key-ind"===n,u=!1;break;case"comma":if(t){v&&r(i,"UNEXPECTED_TOKEN",`Unexpected , in ${t}`),v=i,l=!1,u=!1;break}default:r(i,"UNEXPECTED_TOKEN",`Unexpected ${i.type} token`),l=!1,u=!1}const E=e[e.length-1],S=E?E.offset+E.source.length:i;return p&&s&&"space"!==s.type&&"newline"!==s.type&&"comma"!==s.type&&("scalar"!==s.type||""!==s.source)&&r(s.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),m&&(l&&m.indent<=o||"block-map"===s?.type||"block-seq"===s?.type)&&r(m,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:v,found:w,spaceBefore:c,comment:f,hasNewline:d,anchor:y,tag:g,newlineAfterProp:b,end:S,start:k??S}}function Kt(e){if(!e)return null;switch(e.type){case"alias":case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":if(e.source.includes("\n"))return!0;if(e.end)for(const t of e.end)if("newline"===t.type)return!0;return!1;case"flow-collection":for(const t of e.items){for(const e of t.start)if("newline"===e.type)return!0;if(t.sep)for(const e of t.sep)if("newline"===e.type)return!0;if(Kt(t.key)||Kt(t.value))return!0}return!1;default:return!0}}function Mt(e,t,n){if("flow-collection"===t?.type){const s=t.end[0];if(s.indent===e&&("]"===s.source||"}"===s.source)&&Kt(t)){n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}}function Dt(e,t,n){const{uniqueKeys:s}=e.options;if(!1===s)return!1;const i="function"==typeof s?s:(e,t)=>e===t||k(e)&&k(t)&&e.value===t.value;return t.some((e=>i(e.key,n)))}const Rt="All mapping items must start at the same column";function Pt(e,t,n,s){let i="";if(e){let r=!1,o="";for(const a of e){const{source:e,type:c}=a;switch(c){case"space":r=!0;break;case"comment":{n&&!r&&s(a,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const t=e.substring(1)||" ";i?i+=o+t:i=t,o="";break}case"newline":i&&(o+=e),r=!0;break;default:s(a,"UNEXPECTED_TOKEN",`Unexpected ${c} at node end`)}t+=e.length}}return{comment:i,offset:t}}const qt="Block collections are not allowed within flow collections",Ft=e=>e&&("block-map"===e.type||"block-seq"===e.type);function Ut(e,t,n,s,i,r){const o="block-map"===n.type?function({composeNode:e,composeEmptyNode:t},n,s,i,r){const o=new(r?.nodeClass??Ie)(n.schema);n.atRoot&&(n.atRoot=!1);let a=s.offset,c=null;for(const r of s.items){const{start:l,key:u,sep:f,value:h}=r,d=Bt(l,{indicator:"explicit-key-ind",next:u??f?.[0],offset:a,onError:i,parentIndent:s.indent,startOnNewline:!0}),p=!d.found;if(p){if(u&&("block-seq"===u.type?i(a,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in u&&u.indent!==s.indent&&i(a,"BAD_INDENT",Rt)),!d.anchor&&!d.tag&&!f){c=d.end,d.comment&&(o.comment?o.comment+="\n"+d.comment:o.comment=d.comment);continue}(d.newlineAfterProp||Kt(u))&&i(u??l[l.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else d.found?.indent!==s.indent&&i(a,"BAD_INDENT",Rt);n.atKey=!0;const m=d.end,y=u?e(n,u,d,i):t(n,m,l,null,d,i);n.schema.compat&&Mt(s.indent,u,i),n.atKey=!1,Dt(n,o.items,y)&&i(m,"DUPLICATE_KEY","Map keys must be unique");const g=Bt(f??[],{indicator:"map-value-ind",next:h,offset:y.range[2],onError:i,parentIndent:s.indent,startOnNewline:!u||"block-scalar"===u.type});if(a=g.end,g.found){p&&("block-map"!==h?.type||g.hasNewline||i(a,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),n.options.strict&&d.start<g.found.offset-1024&&i(y.range,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));const c=h?e(n,h,g,i):t(n,a,f,null,g,i);n.schema.compat&&Mt(s.indent,h,i),a=c.range[2];const l=new Ee(y,c);n.options.keepSourceTokens&&(l.srcToken=r),o.items.push(l)}else{p&&i(y.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),g.comment&&(y.comment?y.comment+="\n"+g.comment:y.comment=g.comment);const e=new Ee(y);n.options.keepSourceTokens&&(e.srcToken=r),o.items.push(e)}}return c&&c<a&&i(c,"IMPOSSIBLE","Map comment with trailing content"),o.range=[s.offset,a,c??a],o}(e,t,n,s,r):"block-seq"===n.type?function({composeNode:e,composeEmptyNode:t},n,s,i,r){const o=new(r?.nodeClass??Te)(n.schema);n.atRoot&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let a=s.offset,c=null;for(const{start:r,value:l}of s.items){const u=Bt(r,{indicator:"seq-item-ind",next:l,offset:a,onError:i,parentIndent:s.indent,startOnNewline:!0});if(!u.found){if(!(u.anchor||u.tag||l)){c=u.end,u.comment&&(o.comment=u.comment);continue}l&&"block-seq"===l.type?i(u.end,"BAD_INDENT","All sequence items must start at the same column"):i(a,"MISSING_CHAR","Sequence item without - indicator")}const f=l?e(n,l,u,i):t(n,u.end,r,null,u,i);n.schema.compat&&Mt(s.indent,l,i),a=f.range[2],o.items.push(f)}return o.range=[s.offset,a,c??a],o}(e,t,n,s,r):function({composeNode:e,composeEmptyNode:t},n,s,i,r){const o="{"===s.start.source,a=o?"flow map":"flow sequence",c=new(r?.nodeClass??(o?Ie:Te))(n.schema);c.flow=!0;const l=n.atRoot;l&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let u=s.offset+s.start.source.length;for(let r=0;r<s.items.length;++r){const l=s.items[r],{start:f,key:h,sep:d,value:p}=l,m=Bt(f,{flow:a,indicator:"explicit-key-ind",next:h??d?.[0],offset:u,onError:i,parentIndent:s.indent,startOnNewline:!1});if(!m.found){if(!(m.anchor||m.tag||d||p)){0===r&&m.comma?i(m.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`):r<s.items.length-1&&i(m.start,"UNEXPECTED_TOKEN",`Unexpected empty item in ${a}`),m.comment&&(c.comment?c.comment+="\n"+m.comment:c.comment=m.comment),u=m.end;continue}!o&&n.options.strict&&Kt(h)&&i(h,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(0===r)m.comma&&i(m.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`);else if(m.comma||i(m.start,"MISSING_CHAR",`Missing , between ${a} items`),m.comment){let e="";e:for(const t of f)switch(t.type){case"comma":case"space":break;case"comment":e=t.source.substring(1);break e;default:break e}if(e){let t=c.items[c.items.length-1];w(t)&&(t=t.value??t.key),t.comment?t.comment+="\n"+e:t.comment=e,m.comment=m.comment.substring(e.length+1)}}if(o||d||m.found){n.atKey=!0;const r=m.end,y=h?e(n,h,m,i):t(n,r,f,null,m,i);Ft(h)&&i(y.range,"BLOCK_IN_FLOW",qt),n.atKey=!1;const g=Bt(d??[],{flow:a,indicator:"map-value-ind",next:p,offset:y.range[2],onError:i,parentIndent:s.indent,startOnNewline:!1});if(g.found){if(!o&&!m.found&&n.options.strict){if(d)for(const e of d){if(e===g.found)break;if("newline"===e.type){i(e,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}m.start<g.found.offset-1024&&i(g.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else p&&("source"in p&&p.source&&":"===p.source[0]?i(p,"MISSING_CHAR",`Missing space after : in ${a}`):i(g.start,"MISSING_CHAR",`Missing , or : between ${a} items`));const b=p?e(n,p,g,i):g.found?t(n,g.end,d,null,g,i):null;b?Ft(p)&&i(b.range,"BLOCK_IN_FLOW",qt):g.comment&&(y.comment?y.comment+="\n"+g.comment:y.comment=g.comment);const v=new Ee(y,b);if(n.options.keepSourceTokens&&(v.srcToken=l),o){const e=c;Dt(n,e.items,y)&&i(r,"DUPLICATE_KEY","Map keys must be unique"),e.items.push(v)}else{const e=new Ie(n.schema);e.flow=!0,e.items.push(v);const t=(b??y).range;e.range=[y.range[0],t[1],t[2]],c.items.push(e)}u=b?b.range[2]:g.end}else{const s=p?e(n,p,m,i):t(n,m.end,d,null,m,i);c.items.push(s),u=s.range[2],Ft(p)&&i(s.range,"BLOCK_IN_FLOW",qt)}}const f=o?"}":"]",[h,...d]=s.end;let p=u;if(h&&h.source===f)p=h.offset+h.source.length;else{const e=a[0].toUpperCase()+a.substring(1);i(u,l?"MISSING_CHAR":"BAD_INDENT",l?`${e} must end with a ${f}`:`${e} in block collection must be sufficiently indented and end with a ${f}`),h&&1!==h.source.length&&d.unshift(h)}if(d.length>0){const e=Pt(d,p,n.options.strict,i);e.comment&&(c.comment?c.comment+="\n"+e.comment:c.comment=e.comment),c.range=[s.offset,p,e.offset]}else c.range=[s.offset,p,p];return c}(e,t,n,s,r),a=o.constructor;return"!"===i||i===a.tagName?(o.tag=a.tagName,o):(i&&(o.tag=i),o)}function Vt(e,t,n){const s=t.offset,i=function({offset:e,props:t},n,s){if("block-scalar-header"!==t[0].type)return s(t[0],"IMPOSSIBLE","Block scalar header not found"),null;const{source:i}=t[0],r=i[0];let o=0,a="",c=-1;for(let t=1;t<i.length;++t){const n=i[t];if(a||"-"!==n&&"+"!==n){const s=Number(n);!o&&s?o=s:-1===c&&(c=e+t)}else a=n}-1!==c&&s(c,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${i}`);let l=!1,u="",f=i.length;for(let e=1;e<t.length;++e){const i=t[e];switch(i.type){case"space":l=!0;case"newline":f+=i.source.length;break;case"comment":if(n&&!l){s(i,"MISSING_CHAR","Comments must be separated from other tokens by white space characters")}f+=i.source.length,u=i.source.substring(1);break;case"error":s(i,"UNEXPECTED_TOKEN",i.message),f+=i.source.length;break;default:{s(i,"UNEXPECTED_TOKEN",`Unexpected token in block scalar header: ${i.type}`);const e=i.source;e&&"string"==typeof e&&(f+=e.length)}}}return{mode:r,indent:o,chomp:a,comment:u,length:f}}(t,e.options.strict,n);if(!i)return{value:"",type:null,comment:"",range:[s,s,s]};const r=">"===i.mode?W.BLOCK_FOLDED:W.BLOCK_LITERAL,o=t.source?function(e){const t=e.split(/\n( *)/),n=t[0],s=n.match(/^( *)/),i=[s?.[1]?[s[1],n.slice(s[1].length)]:["",n]];for(let e=1;e<t.length;e+=2)i.push([t[e],t[e+1]]);return i}(t.source):[];let a=o.length;for(let e=o.length-1;e>=0;--e){const t=o[e][1];if(""!==t&&"\r"!==t)break;a=e}if(0===a){const e="+"===i.chomp&&o.length>0?"\n".repeat(Math.max(1,o.length-1)):"";let n=s+i.length;return t.source&&(n+=t.source.length),{value:e,type:r,comment:i.comment,range:[s,n,n]}}let c=t.indent+i.indent,l=t.offset+i.length,u=0;for(let t=0;t<a;++t){const[s,r]=o[t];if(""!==r&&"\r"!==r){if(s.length<c){const e="Block scalars with more-indented leading empty lines must use an explicit indentation indicator";n(l+s.length,"MISSING_CHAR",e)}if(0===i.indent&&(c=s.length),u=t,0===c&&!e.atRoot){n(l,"BAD_INDENT","Block scalar values in collections must be indented")}break}0===i.indent&&s.length>c&&(c=s.length),l+=s.length+r.length+1}for(let e=o.length-1;e>=a;--e)o[e][0].length>c&&(a=e+1);let f="",h="",d=!1;for(let e=0;e<u;++e)f+=o[e][0].slice(c)+"\n";for(let e=u;e<a;++e){let[t,s]=o[e];l+=t.length+s.length+1;const a="\r"===s[s.length-1];if(a&&(s=s.slice(0,-1)),s&&t.length<c){const e=`Block scalar lines must not be less indented than their ${i.indent?"explicit indentation indicator":"first line"}`;n(l-s.length-(a?2:1),"BAD_INDENT",e),t=""}r===W.BLOCK_LITERAL?(f+=h+t.slice(c)+s,h="\n"):t.length>c||"\t"===s[0]?(" "===h?h="\n":d||"\n"!==h||(h="\n\n"),f+=h+t.slice(c)+s,h="\n",d=!0):""===s?"\n"===h?f+="\n":h="\n":(f+=h+s,h=" ",d=!1)}switch(i.chomp){case"-":break;case"+":for(let e=a;e<o.length;++e)f+="\n"+o[e][0].slice(c);"\n"!==f[f.length-1]&&(f+="\n");break;default:f+="\n"}const p=s+i.length+t.source.length;return{value:f,type:r,comment:i.comment,range:[s,p,p]}}function Jt(e,t,n){const{offset:s,type:i,source:r,end:o}=e;let a,c;const l=(e,t,i)=>n(s+e,t,i);switch(i){case"scalar":a=W.PLAIN,c=function(e,t){let n="";switch(e[0]){case"\t":n="a tab character";break;case",":n="flow indicator character ,";break;case"%":n="directive indicator character %";break;case"|":case">":n=`block scalar indicator ${e[0]}`;break;case"@":case"`":n=`reserved character ${e[0]}`}n&&t(0,"BAD_SCALAR_START",`Plain value cannot start with ${n}`);return Wt(e)}(r,l);break;case"single-quoted-scalar":a=W.QUOTE_SINGLE,c=function(e,t){"'"===e[e.length-1]&&1!==e.length||t(e.length,"MISSING_CHAR","Missing closing 'quote");return Wt(e.slice(1,-1)).replace(/''/g,"'")}(r,l);break;case"double-quoted-scalar":a=W.QUOTE_DOUBLE,c=function(e,t){let n="";for(let s=1;s<e.length-1;++s){const i=e[s];if("\r"!==i||"\n"!==e[s+1])if("\n"===i){const{fold:t,offset:i}=Yt(e,s);n+=t,s=i}else if("\\"===i){let i=e[++s];const r=Gt[i];if(r)n+=r;else if("\n"===i)for(i=e[s+1];" "===i||"\t"===i;)i=e[1+ ++s];else if("\r"===i&&"\n"===e[s+1])for(i=e[1+ ++s];" "===i||"\t"===i;)i=e[1+ ++s];else if("x"===i||"u"===i||"U"===i){const r={x:2,u:4,U:8}[i];n+=Qt(e,s+1,r,t),s+=r}else{const i=e.substr(s-1,2);t(s-1,"BAD_DQ_ESCAPE",`Invalid escape sequence ${i}`),n+=i}}else if(" "===i||"\t"===i){const t=s;let r=e[s+1];for(;" "===r||"\t"===r;)r=e[1+ ++s];"\n"===r||"\r"===r&&"\n"===e[s+2]||(n+=s>t?e.slice(t,s+1):i)}else n+=i}'"'===e[e.length-1]&&1!==e.length||t(e.length,"MISSING_CHAR",'Missing closing "quote');return n}(r,l);break;default:return n(e,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${i}`),{value:"",type:null,comment:"",range:[s,s+r.length,s+r.length]}}const u=s+r.length,f=Pt(o,u,t,n);return{value:c,type:a,comment:f.comment,range:[s,u,f.offset]}}function Wt(e){let t,n;try{t=new RegExp("(.*?)(?<![ \t])[ \t]*\r?\n","sy"),n=new RegExp("[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n","sy")}catch{t=/(.*?)[ \t]*\r?\n/sy,n=/[ \t]*(.*?)[ \t]*\r?\n/sy}let s=t.exec(e);if(!s)return e;let i=s[1],r=" ",o=t.lastIndex;for(n.lastIndex=o;s=n.exec(e);)""===s[1]?"\n"===r?i+=r:r="\n":(i+=r+s[1],r=" "),o=n.lastIndex;const a=/[ \t]*(.*)/sy;return a.lastIndex=o,s=a.exec(e),i+r+(s?.[1]??"")}function Yt(e,t){let n="",s=e[t+1];for(;!(" "!==s&&"\t"!==s&&"\n"!==s&&"\r"!==s||"\r"===s&&"\n"!==e[t+2]);)"\n"===s&&(n+="\n"),s=e[(t+=1)+1];return n||(n=" "),{fold:n,offset:t}}const Gt={0:"\0",a:"",b:"\b",e:"",f:"\f",n:"\n",r:"\r",t:"\t",v:"\v",N:"…",_:" ",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\","\t":"\t"};function Qt(e,t,n,s){const i=e.substr(t,n),r=i.length===n&&/^[0-9a-fA-F]+$/.test(i)?parseInt(i,16):NaN;if(isNaN(r)){const i=e.substr(t-2,n+2);return s(t-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${i}`),i}return String.fromCodePoint(r)}function Ht(e,t,n,s){const{value:i,type:r,comment:o,range:a}="block-scalar"===t.type?Vt(e,t,s):Jt(t,e.options.strict,s),c=n?e.directives.tagName(n.source,(e=>s(n,"TAG_RESOLVE_FAILED",e))):null;let l,u;l=e.options.stringKeys&&e.atKey?e.schema[p]:c?function(e,t,n,s,i){if("!"===n)return e[p];const r=[];for(const t of e.tags)if(!t.collection&&t.tag===n){if(!t.default||!t.test)return t;r.push(t)}for(const e of r)if(e.test?.test(t))return e;const o=e.knownTags[n];if(o&&!o.collection)return e.tags.push(Object.assign({},o,{default:!1,test:void 0})),o;return i(s,"TAG_RESOLVE_FAILED",`Unresolved tag: ${n}`,"tag:yaml.org,2002:str"!==n),e[p]}(e.schema,i,c,n,s):"scalar"===t.type?function({atKey:e,directives:t,schema:n},s,i,r){const o=n.tags.find((t=>(!0===t.default||e&&"key"===t.default)&&t.test?.test(s)))||n[p];if(n.compat){const e=n.compat.find((e=>e.default&&e.test?.test(s)))??n[p];if(o.tag!==e.tag){r(i,"TAG_RESOLVE_FAILED",`Value may be parsed as either ${t.tagString(o.tag)} or ${t.tagString(e.tag)}`,!0)}}return o}(e,i,t,s):e.schema[p];try{const r=l.resolve(i,(e=>s(n??t,"TAG_RESOLVE_FAILED",e)),e.options);u=k(r)?r:new W(r)}catch(e){const r=e instanceof Error?e.message:String(e);s(n??t,"TAG_RESOLVE_FAILED",r),u=new W(i)}return u.range=a,u.source=i,r&&(u.type=r),c&&(u.tag=c),l.format&&(u.format=l.format),o&&(u.comment=o),u}function Xt(e,t,n){if(t){null===n&&(n=t.length);for(let s=n-1;s>=0;--s){let n=t[s];switch(n.type){case"space":case"comment":case"newline":e-=n.source.length;continue}for(n=t[++s];"space"===n?.type;)e+=n.source.length,n=t[++s];break}}return e}const zt={composeNode:Zt,composeEmptyNode:en};function Zt(e,t,n,s){const i=e.atKey,{spaceBefore:r,comment:o,anchor:a,tag:c}=n;let l,u=!0;switch(t.type){case"alias":l=function({options:e},{offset:t,source:n,end:s},i){const r=new U(n.substring(1));""===r.source&&i(t,"BAD_ALIAS","Alias cannot be an empty string");r.source.endsWith(":")&&i(t+n.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",!0);const o=t+n.length,a=Pt(s,o,e.strict,i);r.range=[t,o,a.offset],a.comment&&(r.comment=a.comment);return r}(e,t,s),(a||c)&&s(t,"ALIAS_PROPS","An alias node must not specify any properties");break;case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"block-scalar":l=Ht(e,t,c,s),a&&(l.anchor=a.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":l=function(e,t,n,s,i){const r=s.tag,o=r?t.directives.tagName(r.source,(e=>i(r,"TAG_RESOLVE_FAILED",e))):null;if("block-seq"===n.type){const{anchor:e,newlineAfterProp:t}=s,n=e&&r?e.offset>r.offset?e:r:e??r;n&&(!t||t.offset<n.offset)&&i(n,"MISSING_CHAR","Missing newline after block sequence props")}const a="block-map"===n.type?"map":"block-seq"===n.type?"seq":"{"===n.start.source?"map":"seq";if(!r||!o||"!"===o||o===Ie.tagName&&"map"===a||o===Te.tagName&&"seq"===a)return Ut(e,t,n,i,o);let c=t.schema.tags.find((e=>e.tag===o&&e.collection===a));if(!c){const s=t.schema.knownTags[o];if(!s||s.collection!==a)return s?.collection?i(r,"BAD_COLLECTION_TYPE",`${s.tag} used for ${a} collection, but expects ${s.collection}`,!0):i(r,"TAG_RESOLVE_FAILED",`Unresolved tag: ${o}`,!0),Ut(e,t,n,i,o);t.schema.tags.push(Object.assign({},s,{default:!1})),c=s}const l=Ut(e,t,n,i,o,c),u=c.resolve?.(l,(e=>i(r,"TAG_RESOLVE_FAILED",e)),t.options)??l,f=A(u)?u:new W(u);return f.range=l.range,f.tag=o,c?.format&&(f.format=c.format),f}(zt,e,t,n,s),a&&(l.anchor=a.source.substring(1));break;default:s(t,"UNEXPECTED_TOKEN","error"===t.type?t.message:`Unsupported token (type: ${t.type})`),l=en(e,t.offset,void 0,null,n,s),u=!1}if(a&&""===l.anchor&&s(a,"BAD_ALIAS","Anchor cannot be an empty string"),i&&e.options.stringKeys&&(!k(l)||"string"!=typeof l.value||l.tag&&"tag:yaml.org,2002:str"!==l.tag)){s(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings")}return r&&(l.spaceBefore=!0),o&&("scalar"===t.type&&""===t.source?l.comment=o:l.commentBefore=o),e.options.keepSourceTokens&&u&&(l.srcToken=t),l}function en(e,t,n,s,{spaceBefore:i,comment:r,anchor:o,tag:a,end:c},l){const u=Ht(e,{type:"scalar",offset:Xt(t,n,s),indent:-1,source:""},a,l);return o&&(u.anchor=o.source.substring(1),""===u.anchor&&l(o,"BAD_ALIAS","Anchor cannot be an empty string")),i&&(u.spaceBefore=!0),r&&(u.comment=r,u.range[2]=c),u}function tn(e){if("number"==typeof e)return[e,e+1];if(Array.isArray(e))return 2===e.length?e:[e[0],e[1]];const{offset:t,source:n}=e;return[t,t+("string"==typeof n?n.length:1)]}function nn(e){let t="",n=!1,s=!1;for(let i=0;i<e.length;++i){const r=e[i];switch(r[0]){case"#":t+=(""===t?"":s?"\n\n":"\n")+(r.substring(1)||" "),n=!0,s=!1;break;case"%":"#"!==e[i+1]?.[0]&&(i+=1),n=!1;break;default:n||(s=!0),n=!1}}return{comment:t,afterEmptyLine:s}}class sn{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,t,n,s)=>{const i=tn(e);s?this.warnings.push(new _t(i,t,n)):this.errors.push(new Ct(i,t,n))},this.directives=new K({version:e.version||"1.2"}),this.options=e}decorate(e,t){const{comment:n,afterEmptyLine:s}=nn(this.prelude);if(n){const i=e.contents;if(t)e.comment=e.comment?`${e.comment}\n${n}`:n;else if(s||e.directives.docStart||!i)e.commentBefore=n;else if(S(i)&&!i.flow&&i.items.length>0){let e=i.items[0];w(e)&&(e=e.key);const t=e.commentBefore;e.commentBefore=t?`${n}\n${t}`:n}else{const e=i.commentBefore;i.commentBefore=e?`${n}\n${e}`:n}}t?(Array.prototype.push.apply(e.errors,this.errors),Array.prototype.push.apply(e.warnings,this.warnings)):(e.errors=this.errors,e.warnings=this.warnings),this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:nn(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,n=-1){for(const t of e)yield*this.next(t);yield*this.end(t,n)}*next(e){switch(e.type){case"directive":this.directives.add(e.source,((t,n,s)=>{const i=tn(e);i[0]+=t,this.onError(i,"BAD_DIRECTIVE",n,s)})),this.prelude.push(e.source),this.atDirectives=!0;break;case"document":{const t=function(e,t,{offset:n,start:s,value:i,end:r},o){const a=Object.assign({_directives:t},e),c=new xt(void 0,a),l={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},u=Bt(s,{indicator:"doc-start",next:i??r?.[0],offset:n,onError:o,parentIndent:0,startOnNewline:!0});u.found&&(c.directives.docStart=!0,!i||"block-map"!==i.type&&"block-seq"!==i.type||u.hasNewline||o(u.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=i?Zt(l,i,u,o):en(l,u.end,s,null,u,o);const f=c.contents.range[2],h=Pt(r,f,!1,o);return h.comment&&(c.comment=h.comment),c.range=[n,f,h.offset],c}(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,"MISSING_CHAR","Missing directives-end/doc-start indicator line"),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case"byte-order-mark":case"space":break;case"comment":case"newline":this.prelude.push(e.source);break;case"error":{const t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,n=new Ct(tn(e),"UNEXPECTED_TOKEN",t);this.atDirectives||!this.doc?this.errors.push(n):this.doc.errors.push(n);break}case"doc-end":{if(!this.doc){const t="Unexpected doc-end without preceding document";this.errors.push(new Ct(tn(e),"UNEXPECTED_TOKEN",t));break}this.doc.directives.docEnd=!0;const t=Pt(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){const e=this.doc.comment;this.doc.comment=e?`${e}\n${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new Ct(tn(e),"UNEXPECTED_TOKEN",`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){const e=Object.assign({_directives:this.directives},this.options),n=new xt(void 0,e);this.atDirectives&&this.onError(t,"MISSING_CHAR","Missing directives-end indicator line"),n.range=[0,t,t],this.decorate(n,!1),yield n}}}function rn(e,t){if(t)for(const n of t)switch(n.type){case"space":case"comment":e.push(n);break;case"newline":return e.push(n),!0}return!1}function on(e,t,n){switch(e.type){case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":e.type=n,e.source=t;break;case"block-scalar":{const s=e.props.slice(1);let i=t.length;"block-scalar-header"===e.props[0].type&&(i-=e.props[0].source.length);for(const e of s)e.offset+=i;delete e.props,Object.assign(e,{type:n,source:t,end:s});break}case"block-map":case"block-seq":{const s={type:"newline",offset:e.offset+t.length,indent:e.indent,source:"\n"};delete e.items,Object.assign(e,{type:n,source:t,end:[s]});break}default:{const s="indent"in e?e.indent:-1,i="end"in e&&Array.isArray(e.end)?e.end.filter((e=>"space"===e.type||"comment"===e.type||"newline"===e.type)):[];for(const t of Object.keys(e))"type"!==t&&"offset"!==t&&delete e[t];Object.assign(e,{type:n,indent:s,source:t,end:i})}}}function an(e){switch(e.type){case"block-scalar":{let t="";for(const n of e.props)t+=an(n);return t+e.source}case"block-map":case"block-seq":{let t="";for(const n of e.items)t+=cn(n);return t}case"flow-collection":{let t=e.start.source;for(const n of e.items)t+=cn(n);for(const n of e.end)t+=n.source;return t}case"document":{let t=cn(e);if(e.end)for(const n of e.end)t+=n.source;return t}default:{let t=e.source;if("end"in e&&e.end)for(const n of e.end)t+=n.source;return t}}}function cn({start:e,key:t,sep:n,value:s}){let i="";for(const t of e)i+=t.source;if(t&&(i+=an(t)),n)for(const e of n)i+=e.source;return s&&(i+=an(s)),i}const ln=Symbol("break visit"),un=Symbol("skip children"),fn=Symbol("remove item");function hn(e,t){"type"in e&&"document"===e.type&&(e={start:e.start,value:e.value}),dn(Object.freeze([]),e,t)}function dn(e,t,n){let s=n(t,e);if("symbol"==typeof s)return s;for(const i of["key","value"]){const r=t[i];if(r&&"items"in r){for(let t=0;t<r.items.length;++t){const s=dn(Object.freeze(e.concat([[i,t]])),r.items[t],n);if("number"==typeof s)t=s-1;else{if(s===ln)return ln;s===fn&&(r.items.splice(t,1),t-=1)}}"function"==typeof s&&"key"===i&&(s=s(t,e))}}return"function"==typeof s?s(t,e):s}hn.BREAK=ln,hn.SKIP=un,hn.REMOVE=fn,hn.itemAtPath=(e,t)=>{let n=e;for(const[e,s]of t){const t=n?.[e];if(!t||!("items"in t))return;n=t.items[s]}return n},hn.parentCollection=(e,t)=>{const n=hn.itemAtPath(e,t.slice(0,-1)),s=t[t.length-1][0],i=n?.[s];if(i&&"items"in i)return i;throw new Error("Parent collection not found")};const pn="\ufeff",mn="",yn="",gn="";function bn(e){switch(e){case pn:return"byte-order-mark";case mn:return"doc-mode";case yn:return"flow-error-end";case gn:return"scalar";case"---":return"doc-start";case"...":return"doc-end";case"":case"\n":case"\r\n":return"newline";case"-":return"seq-item-ind";case"?":return"explicit-key-ind";case":":return"map-value-ind";case"{":return"flow-map-start";case"}":return"flow-map-end";case"[":return"flow-seq-start";case"]":return"flow-seq-end";case",":return"comma"}switch(e[0]){case" ":case"\t":return"space";case"#":return"comment";case"%":return"directive-line";case"*":return"alias";case"&":return"anchor";case"!":return"tag";case"'":return"single-quoted-scalar";case'"':return"double-quoted-scalar";case"|":case">":return"block-scalar-header"}return null}var vn=Object.freeze({__proto__:null,BOM:pn,DOCUMENT:mn,FLOW_END:yn,SCALAR:gn,isCollection:e=>!!e&&"items"in e,isScalar:e=>!!e&&("scalar"===e.type||"single-quoted-scalar"===e.type||"double-quoted-scalar"===e.type||"block-scalar"===e.type),prettyToken:function(e){switch(e){case pn:return"<BOM>";case mn:return"<DOC>";case yn:return"<FLOW_END>";case gn:return"<SCALAR>";default:return JSON.stringify(e)}},tokenType:bn,createScalarToken:function(e,t){const{implicitKey:n=!1,indent:s,inFlow:i=!1,offset:r=-1,type:o="PLAIN"}=t,a=he({type:o,value:e},{implicitKey:n,indent:s>0?" ".repeat(s):"",inFlow:i,options:{blockQuote:!0,lineWidth:-1}}),c=t.end??[{type:"newline",offset:-1,indent:s,source:"\n"}];switch(a[0]){case"|":case">":{const e=a.indexOf("\n"),t=a.substring(0,e),n=a.substring(e+1)+"\n",i=[{type:"block-scalar-header",offset:r,indent:s,source:t}];return rn(i,c)||i.push({type:"newline",offset:-1,indent:s,source:"\n"}),{type:"block-scalar",offset:r,indent:s,props:i,source:n}}case'"':return{type:"double-quoted-scalar",offset:r,indent:s,source:a,end:c};case"'":return{type:"single-quoted-scalar",offset:r,indent:s,source:a,end:c};default:return{type:"scalar",offset:r,indent:s,source:a,end:c}}},resolveAsScalar:function(e,t=!0,n){if(e){const s=(e,t,s)=>{const i="number"==typeof e?e:Array.isArray(e)?e[0]:e.offset;if(!n)throw new Ct([i,i+1],t,s);n(i,t,s)};switch(e.type){case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return Jt(e,t,s);case"block-scalar":return Vt({options:{strict:t}},e,s)}}return null},setScalarValue:function(e,t,n={}){let{afterKey:s=!1,implicitKey:i=!1,inFlow:r=!1,type:o}=n,a="indent"in e?e.indent:null;if(s&&"number"==typeof a&&(a+=2),!o)switch(e.type){case"single-quoted-scalar":o="QUOTE_SINGLE";break;case"double-quoted-scalar":o="QUOTE_DOUBLE";break;case"block-scalar":{const t=e.props[0];if("block-scalar-header"!==t.type)throw new Error("Invalid block scalar header");o=">"===t.source[0]?"BLOCK_FOLDED":"BLOCK_LITERAL";break}default:o="PLAIN"}const c=he({type:o,value:t},{implicitKey:i||null===a,indent:null!==a&&a>0?" ".repeat(a):"",inFlow:r,options:{blockQuote:!0,lineWidth:-1}});switch(c[0]){case"|":case">":!function(e,t){const n=t.indexOf("\n"),s=t.substring(0,n),i=t.substring(n+1)+"\n";if("block-scalar"===e.type){const t=e.props[0];if("block-scalar-header"!==t.type)throw new Error("Invalid block scalar header");t.source=s,e.source=i}else{const{offset:t}=e,n="indent"in e?e.indent:-1,r=[{type:"block-scalar-header",offset:t,indent:n,source:s}];rn(r,"end"in e?e.end:void 0)||r.push({type:"newline",offset:-1,indent:n,source:"\n"});for(const t of Object.keys(e))"type"!==t&&"offset"!==t&&delete e[t];Object.assign(e,{type:"block-scalar",indent:n,props:r,source:i})}}(e,c);break;case'"':on(e,c,"double-quoted-scalar");break;case"'":on(e,c,"single-quoted-scalar");break;default:on(e,c,"scalar")}},stringify:e=>"type"in e?an(e):cn(e),visit:hn});function wn(e){switch(e){case void 0:case" ":case"\n":case"\r":case"\t":return!0;default:return!1}}const kn=new Set("0123456789ABCDEFabcdef"),En=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),Sn=new Set(",[]{}"),An=new Set(" ,[]{}\n\r\t"),Nn=e=>!e||An.has(e);class On{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer="",this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if("string"!=typeof e)throw TypeError("source is not a string");this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let n=this.next??"stream";for(;n&&(t||this.hasChars(1));)n=yield*this.parseNext(n)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;" "===t||"\t"===t;)t=this.buffer[++e];return!t||"#"===t||"\n"===t||"\r"===t&&"\n"===this.buffer[e+1]}charAt(e){return this.buffer[this.pos+e]}continueScalar(e){let t=this.buffer[e];if(this.indentNext>0){let n=0;for(;" "===t;)t=this.buffer[++n+e];if("\r"===t){const t=this.buffer[n+e+1];if("\n"===t||!t&&!this.atEnd)return e+n+1}return"\n"===t||n>=this.indentNext||!t&&!this.atEnd?e+n:-1}if("-"===t||"."===t){const t=this.buffer.substr(e,3);if(("---"===t||"..."===t)&&wn(this.buffer[e+3]))return-1}return e}getLine(){let e=this.lineEndPos;return("number"!=typeof e||-1!==e&&e<this.pos)&&(e=this.buffer.indexOf("\n",this.pos),this.lineEndPos=e),-1===e?this.atEnd?this.buffer.substring(this.pos):null:("\r"===this.buffer[e-1]&&(e-=1),this.buffer.substring(this.pos,e))}hasChars(e){return this.pos+e<=this.buffer.length}setNext(e){return this.buffer=this.buffer.substring(this.pos),this.pos=0,this.lineEndPos=null,this.next=e,null}peek(e){return this.buffer.substr(this.pos,e)}*parseNext(e){switch(e){case"stream":return yield*this.parseStream();case"line-start":return yield*this.parseLineStart();case"block-start":return yield*this.parseBlockStart();case"doc":return yield*this.parseDocument();case"flow":return yield*this.parseFlowCollection();case"quoted-scalar":return yield*this.parseQuotedScalar();case"block-scalar":return yield*this.parseBlockScalar();case"plain-scalar":return yield*this.parsePlainScalar()}}*parseStream(){let e=this.getLine();if(null===e)return this.setNext("stream");if(e[0]===pn&&(yield*this.pushCount(1),e=e.substring(1)),"%"===e[0]){let t=e.length,n=e.indexOf("#");for(;-1!==n;){const s=e[n-1];if(" "===s||"\t"===s){t=n-1;break}n=e.indexOf("#",n+1)}for(;;){const n=e[t-1];if(" "!==n&&"\t"!==n)break;t-=1}const s=(yield*this.pushCount(t))+(yield*this.pushSpaces(!0));return yield*this.pushCount(e.length-s),this.pushNewline(),"stream"}if(this.atLineEnd()){const t=yield*this.pushSpaces(!0);return yield*this.pushCount(e.length-t),yield*this.pushNewline(),"stream"}return yield mn,yield*this.parseLineStart()}*parseLineStart(){const e=this.charAt(0);if(!e&&!this.atEnd)return this.setNext("line-start");if("-"===e||"."===e){if(!this.atEnd&&!this.hasChars(4))return this.setNext("line-start");const e=this.peek(3);if(("---"===e||"..."===e)&&wn(this.charAt(3)))return yield*this.pushCount(3),this.indentValue=0,this.indentNext=0,"---"===e?"doc":"stream"}return this.indentValue=yield*this.pushSpaces(!1),this.indentNext>this.indentValue&&!wn(this.charAt(1))&&(this.indentNext=this.indentValue),yield*this.parseBlockStart()}*parseBlockStart(){const[e,t]=this.peek(2);if(!t&&!this.atEnd)return this.setNext("block-start");if(("-"===e||"?"===e||":"===e)&&wn(t)){const e=(yield*this.pushCount(1))+(yield*this.pushSpaces(!0));return this.indentNext=this.indentValue+1,this.indentValue+=e,yield*this.parseBlockStart()}return"doc"}*parseDocument(){yield*this.pushSpaces(!0);const e=this.getLine();if(null===e)return this.setNext("doc");let t=yield*this.pushIndicators();switch(e[t]){case"#":yield*this.pushCount(e.length-t);case void 0:return yield*this.pushNewline(),yield*this.parseLineStart();case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel=1,"flow";case"}":case"]":return yield*this.pushCount(1),"doc";case"*":return yield*this.pushUntil(Nn),"doc";case'"':case"'":return yield*this.parseQuotedScalar();case"|":case">":return t+=(yield*this.parseBlockScalarHeader()),t+=(yield*this.pushSpaces(!0)),yield*this.pushCount(e.length-t),yield*this.pushNewline(),yield*this.parseBlockScalar();default:return yield*this.parsePlainScalar()}}*parseFlowCollection(){let e,t,n=-1;do{e=yield*this.pushNewline(),e>0?(t=yield*this.pushSpaces(!1),this.indentValue=n=t):t=0,t+=(yield*this.pushSpaces(!0))}while(e+t>0);const s=this.getLine();if(null===s)return this.setNext("flow");if(-1!==n&&n<this.indentNext&&"#"!==s[0]||0===n&&(s.startsWith("---")||s.startsWith("..."))&&wn(s[3])){if(!(n===this.indentNext-1&&1===this.flowLevel&&("]"===s[0]||"}"===s[0])))return this.flowLevel=0,yield yn,yield*this.parseLineStart()}let i=0;for(;","===s[i];)i+=(yield*this.pushCount(1)),i+=(yield*this.pushSpaces(!0)),this.flowKey=!1;switch(i+=(yield*this.pushIndicators()),s[i]){case void 0:return"flow";case"#":return yield*this.pushCount(s.length-i),"flow";case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel+=1,"flow";case"}":case"]":return yield*this.pushCount(1),this.flowKey=!0,this.flowLevel-=1,this.flowLevel?"flow":"doc";case"*":return yield*this.pushUntil(Nn),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{const e=this.charAt(1);if(this.flowKey||wn(e)||","===e)return this.flowKey=!1,yield*this.pushCount(1),yield*this.pushSpaces(!0),"flow"}default:return this.flowKey=!1,yield*this.parsePlainScalar()}}*parseQuotedScalar(){const e=this.charAt(0);let t=this.buffer.indexOf(e,this.pos+1);if("'"===e)for(;-1!==t&&"'"===this.buffer[t+1];)t=this.buffer.indexOf("'",t+2);else for(;-1!==t;){let e=0;for(;"\\"===this.buffer[t-1-e];)e+=1;if(e%2==0)break;t=this.buffer.indexOf('"',t+1)}const n=this.buffer.substring(0,t);let s=n.indexOf("\n",this.pos);if(-1!==s){for(;-1!==s;){const e=this.continueScalar(s+1);if(-1===e)break;s=n.indexOf("\n",e)}-1!==s&&(t=s-("\r"===n[s-1]?2:1))}if(-1===t){if(!this.atEnd)return this.setNext("quoted-scalar");t=this.buffer.length}return yield*this.pushToIndex(t+1,!1),this.flowLevel?"flow":"doc"}*parseBlockScalarHeader(){this.blockScalarIndent=-1,this.blockScalarKeep=!1;let e=this.pos;for(;;){const t=this.buffer[++e];if("+"===t)this.blockScalarKeep=!0;else if(t>"0"&&t<="9")this.blockScalarIndent=Number(t)-1;else if("-"!==t)break}return yield*this.pushUntil((e=>wn(e)||"#"===e))}*parseBlockScalar(){let e,t=this.pos-1,n=0;e:for(let s=this.pos;e=this.buffer[s];++s)switch(e){case" ":n+=1;break;case"\n":t=s,n=0;break;case"\r":{const e=this.buffer[s+1];if(!e&&!this.atEnd)return this.setNext("block-scalar");if("\n"===e)break}default:break e}if(!e&&!this.atEnd)return this.setNext("block-scalar");if(n>=this.indentNext){-1===this.blockScalarIndent?this.indentNext=n:this.indentNext=this.blockScalarIndent+(0===this.indentNext?1:this.indentNext);do{const e=this.continueScalar(t+1);if(-1===e)break;t=this.buffer.indexOf("\n",e)}while(-1!==t);if(-1===t){if(!this.atEnd)return this.setNext("block-scalar");t=this.buffer.length}}let s=t+1;for(e=this.buffer[s];" "===e;)e=this.buffer[++s];if("\t"===e){for(;"\t"===e||" "===e||"\r"===e||"\n"===e;)e=this.buffer[++s];t=s-1}else if(!this.blockScalarKeep)for(;;){let e=t-1,s=this.buffer[e];"\r"===s&&(s=this.buffer[--e]);const i=e;for(;" "===s;)s=this.buffer[--e];if(!("\n"===s&&e>=this.pos&&e+1+n>i))break;t=e}return yield gn,yield*this.pushToIndex(t+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){const e=this.flowLevel>0;let t,n=this.pos-1,s=this.pos-1;for(;t=this.buffer[++s];)if(":"===t){const t=this.buffer[s+1];if(wn(t)||e&&Sn.has(t))break;n=s}else if(wn(t)){let i=this.buffer[s+1];if("\r"===t&&("\n"===i?(s+=1,t="\n",i=this.buffer[s+1]):n=s),"#"===i||e&&Sn.has(i))break;if("\n"===t){const e=this.continueScalar(s+1);if(-1===e)break;s=Math.max(s,e-2)}}else{if(e&&Sn.has(t))break;n=s}return t||this.atEnd?(yield gn,yield*this.pushToIndex(n+1,!0),e?"flow":"doc"):this.setNext("plain-scalar")}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){const n=this.buffer.slice(this.pos,e);return n?(yield n,this.pos+=n.length,n.length):(t&&(yield""),0)}*pushIndicators(){switch(this.charAt(0)){case"!":return(yield*this.pushTag())+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators());case"&":return(yield*this.pushUntil(Nn))+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators());case"-":case"?":case":":{const e=this.flowLevel>0,t=this.charAt(1);if(wn(t)||e&&Sn.has(t))return e?this.flowKey&&(this.flowKey=!1):this.indentNext=this.indentValue+1,(yield*this.pushCount(1))+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators())}}return 0}*pushTag(){if("<"===this.charAt(1)){let e=this.pos+2,t=this.buffer[e];for(;!wn(t)&&">"!==t;)t=this.buffer[++e];return yield*this.pushToIndex(">"===t?e+1:e,!1)}{let e=this.pos+1,t=this.buffer[e];for(;t;)if(En.has(t))t=this.buffer[++e];else{if("%"!==t||!kn.has(this.buffer[e+1])||!kn.has(this.buffer[e+2]))break;t=this.buffer[e+=3]}return yield*this.pushToIndex(e,!1)}}*pushNewline(){const e=this.buffer[this.pos];return"\n"===e?yield*this.pushCount(1):"\r"===e&&"\n"===this.charAt(1)?yield*this.pushCount(2):0}*pushSpaces(e){let t,n=this.pos-1;do{t=this.buffer[++n]}while(" "===t||e&&"\t"===t);const s=n-this.pos;return s>0&&(yield this.buffer.substr(this.pos,s),this.pos=n),s}*pushUntil(e){let t=this.pos,n=this.buffer[t];for(;!e(n);)n=this.buffer[++t];return yield*this.pushToIndex(t,!1)}}class $n{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let t=0,n=this.lineStarts.length;for(;t<n;){const s=t+n>>1;this.lineStarts[s]<e?t=s+1:n=s}if(this.lineStarts[t]===e)return{line:t+1,col:1};if(0===t)return{line:0,col:e};return{line:t,col:e-this.lineStarts[t-1]+1}}}}function In(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function xn(e){for(let t=0;t<e.length;++t)switch(e[t].type){case"space":case"comment":case"newline":break;default:return t}return-1}function Tn(e){switch(e?.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"flow-collection":return!0;default:return!1}}function Ln(e){switch(e.type){case"document":return e.start;case"block-map":{const t=e.items[e.items.length-1];return t.sep??t.start}case"block-seq":return e.items[e.items.length-1].start;default:return[]}}function Cn(e){if(0===e.length)return[];let t=e.length;e:for(;--t>=0;)switch(e[t].type){case"doc-start":case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":case"newline":break e}for(;"space"===e[++t]?.type;);return e.splice(t,e.length)}function _n(e){if("flow-seq-start"===e.start.type)for(const t of e.items)!t.sep||t.value||In(t.start,"explicit-key-ind")||In(t.sep,"map-value-ind")||(t.key&&(t.value=t.key),delete t.key,Tn(t.value)?t.value.end?Array.prototype.push.apply(t.value.end,t.sep):t.value.end=t.sep:Array.prototype.push.apply(t.start,t.sep),delete t.sep)}class jn{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source="",this.type="",this.lexer=new On,this.onNewLine=e}*parse(e,t=!1){this.onNewLine&&0===this.offset&&this.onNewLine(0);for(const n of this.lexer.lex(e,t))yield*this.next(n);t||(yield*this.end())}*next(e){if(this.source=e,this.atScalar)return this.atScalar=!1,yield*this.step(),void(this.offset+=e.length);const t=bn(e);if(t)if("scalar"===t)this.atNewLine=!1,this.atScalar=!0,this.type="scalar";else{switch(this.type=t,yield*this.step(),t){case"newline":this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case"space":this.atNewLine&&" "===e[0]&&(this.indent+=e.length);break;case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":this.atNewLine&&(this.indent+=e.length);break;case"doc-mode":case"flow-error-end":return;default:this.atNewLine=!1}this.offset+=e.length}else{const t=`Not a YAML token: ${e}`;yield*this.pop({type:"error",offset:this.offset,message:t,source:e}),this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){const e=this.peek(1);if("doc-end"!==this.type||e&&"doc-end"===e.type){if(!e)return yield*this.stream();switch(e.type){case"document":return yield*this.document(e);case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return yield*this.scalar(e);case"block-scalar":return yield*this.blockScalar(e);case"block-map":return yield*this.blockMap(e);case"block-seq":return yield*this.blockSequence(e);case"flow-collection":return yield*this.flowCollection(e);case"doc-end":return yield*this.documentEnd(e)}yield*this.pop()}else{for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:"doc-end",offset:this.offset,source:this.source})}}peek(e){return this.stack[this.stack.length-e]}*pop(e){const t=e??this.stack.pop();if(t)if(0===this.stack.length)yield t;else{const e=this.peek(1);switch("block-scalar"===t.type?t.indent="indent"in e?e.indent:0:"flow-collection"===t.type&&"document"===e.type&&(t.indent=0),"flow-collection"===t.type&&_n(t),e.type){case"document":e.value=t;break;case"block-scalar":e.props.push(t);break;case"block-map":{const n=e.items[e.items.length-1];if(n.value)return e.items.push({start:[],key:t,sep:[]}),void(this.onKeyLine=!0);if(!n.sep)return Object.assign(n,{key:t,sep:[]}),void(this.onKeyLine=!n.explicitKey);n.value=t;break}case"block-seq":{const n=e.items[e.items.length-1];n.value?e.items.push({start:[],value:t}):n.value=t;break}case"flow-collection":{const n=e.items[e.items.length-1];return void(!n||n.value?e.items.push({start:[],key:t,sep:[]}):n.sep?n.value=t:Object.assign(n,{key:t,sep:[]}))}default:yield*this.pop(),yield*this.pop(t)}if(!("document"!==e.type&&"block-map"!==e.type&&"block-seq"!==e.type||"block-map"!==t.type&&"block-seq"!==t.type)){const n=t.items[t.items.length-1];n&&!n.sep&&!n.value&&n.start.length>0&&-1===xn(n.start)&&(0===t.indent||n.start.every((e=>"comment"!==e.type||e.indent<t.indent)))&&("document"===e.type?e.end=n.start:e.items.push({start:n.start}),t.items.splice(-1,1))}}else{const e="Tried to pop an empty stack";yield{type:"error",offset:this.offset,source:"",message:e}}}*stream(){switch(this.type){case"directive-line":return void(yield{type:"directive",offset:this.offset,source:this.source});case"byte-order-mark":case"space":case"comment":case"newline":return void(yield this.sourceToken);case"doc-mode":case"doc-start":{const e={type:"document",offset:this.offset,start:[]};return"doc-start"===this.type&&e.start.push(this.sourceToken),void this.stack.push(e)}}yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML stream`,source:this.source}}*document(e){if(e.value)return yield*this.lineEnd(e);switch(this.type){case"doc-start":return void(-1!==xn(e.start)?(yield*this.pop(),yield*this.step()):e.start.push(this.sourceToken));case"anchor":case"tag":case"space":case"comment":case"newline":return void e.start.push(this.sourceToken)}const t=this.startBlockValue(e);t?this.stack.push(t):yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML document`,source:this.source}}*scalar(e){if("map-value-ind"===this.type){const t=Cn(Ln(this.peek(2)));let n;e.end?(n=e.end,n.push(this.sourceToken),delete e.end):n=[this.sourceToken];const s={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:t,key:e,sep:n}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=s}else yield*this.lineEnd(e)}*blockScalar(e){switch(this.type){case"space":case"comment":case"newline":return void e.props.push(this.sourceToken);case"scalar":if(e.source=this.source,this.atNewLine=!0,this.indent=0,this.onNewLine){let e=this.source.indexOf("\n")+1;for(;0!==e;)this.onNewLine(this.offset+e),e=this.source.indexOf("\n",e)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){const t=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,t.value){const n="end"in t.value?t.value.end:void 0,s=Array.isArray(n)?n[n.length-1]:void 0;"comment"===s?.type?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){const n=e.items[e.items.length-2],s=n?.value?.end;if(Array.isArray(s))return Array.prototype.push.apply(s,t.start),s.push(this.sourceToken),void e.items.pop()}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){const n=!this.onKeyLine&&this.indent===e.indent,s=n&&(t.sep||t.explicitKey)&&"seq-item-ind"!==this.type;let i=[];if(s&&t.sep&&!t.value){const n=[];for(let s=0;s<t.sep.length;++s){const i=t.sep[s];switch(i.type){case"newline":n.push(s);break;case"space":break;case"comment":i.indent>e.indent&&(n.length=0);break;default:n.length=0}}n.length>=2&&(i=t.sep.splice(n[1]))}switch(this.type){case"anchor":case"tag":return void(s||t.value?(i.push(this.sourceToken),e.items.push({start:i}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken));case"explicit-key-ind":return t.sep||t.explicitKey?s||t.value?(i.push(this.sourceToken),e.items.push({start:i,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}):(t.start.push(this.sourceToken),t.explicitKey=!0),void(this.onKeyLine=!0);case"map-value-ind":if(t.explicitKey)if(t.sep)if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(In(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]});else if(Tn(t.key)&&!In(t.sep,"newline")){const e=Cn(t.start),n=t.key,s=t.sep;s.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:e,key:n,sep:s}]})}else i.length>0?t.sep=t.sep.concat(i,this.sourceToken):t.sep.push(this.sourceToken);else if(In(t.start,"newline"))Object.assign(t,{key:null,sep:[this.sourceToken]});else{const e=Cn(t.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:e,key:null,sep:[this.sourceToken]}]})}else t.sep?t.value||s?e.items.push({start:i,key:null,sep:[this.sourceToken]}):In(t.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return void(this.onKeyLine=!0);case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const n=this.flowScalar(this.type);return void(s||t.value?(e.items.push({start:i,key:n,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(n):(Object.assign(t,{key:n,sep:[]}),this.onKeyLine=!0))}default:{const t=this.startBlockValue(e);if(t)return n&&"block-seq"!==t.type&&e.items.push({start:i}),void this.stack.push(t)}}}yield*this.pop(),yield*this.step()}*blockSequence(e){const t=e.items[e.items.length-1];switch(this.type){case"newline":if(t.value){const n="end"in t.value?t.value.end:void 0,s=Array.isArray(n)?n[n.length-1]:void 0;"comment"===s?.type?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){const n=e.items[e.items.length-2],s=n?.value?.end;if(Array.isArray(s))return Array.prototype.push.apply(s,t.start),s.push(this.sourceToken),void e.items.pop()}t.start.push(this.sourceToken)}return;case"anchor":case"tag":if(t.value||this.indent<=e.indent)break;return void t.start.push(this.sourceToken);case"seq-item-ind":if(this.indent!==e.indent)break;return void(t.value||In(t.start,"seq-item-ind")?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken))}if(this.indent>e.indent){const t=this.startBlockValue(e);if(t)return void this.stack.push(t)}yield*this.pop(),yield*this.step()}*flowCollection(e){const t=e.items[e.items.length-1];if("flow-error-end"===this.type){let e;do{yield*this.pop(),e=this.peek(1)}while(e&&"flow-collection"===e.type)}else if(0===e.end.length){switch(this.type){case"comma":case"explicit-key-ind":return void(!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken));case"map-value-ind":return void(!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]}));case"space":case"comment":case"newline":case"anchor":case"tag":return void(!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken));case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const n=this.flowScalar(this.type);return void(!t||t.value?e.items.push({start:[],key:n,sep:[]}):t.sep?this.stack.push(n):Object.assign(t,{key:n,sep:[]}))}case"flow-map-end":case"flow-seq-end":return void e.end.push(this.sourceToken)}const n=this.startBlockValue(e);n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{const t=this.peek(2);if("block-map"===t.type&&("map-value-ind"===this.type&&t.indent===e.indent||"newline"===this.type&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if("map-value-ind"===this.type&&"flow-collection"!==t.type){const n=Cn(Ln(t));_n(e);const s=e.end.splice(1,e.end.length);s.push(this.sourceToken);const i={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:s}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf("\n")+1;for(;0!==e;)this.onNewLine(this.offset+e),e=this.source.indexOf("\n",e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;const t=Cn(Ln(e));return t.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;const t=Cn(Ln(e));return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return"comment"===this.type&&(!(this.indent<=t)&&e.every((e=>"newline"===e.type||"space"===e.type)))}*documentEnd(e){"doc-mode"!==this.type&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],"newline"===this.type&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],"newline"===this.type&&(yield*this.pop())}}}function Bn(e){const t=!1!==e.prettyErrors;return{lineCounter:e.lineCounter||t&&new $n||null,prettyErrors:t}}function Kn(e,t={}){const{lineCounter:n,prettyErrors:s}=Bn(t),i=new jn(n?.addNewLine),r=new sn(t);let o=null;for(const t of r.compose(i.parse(e),!0,e.length))if(o){if("silent"!==o.options.logLevel){o.errors.push(new Ct(t.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}}else o=t;return s&&n&&(o.errors.forEach(jt(e,n)),o.warnings.forEach(jt(e,n))),o}var Mn=Object.freeze({__proto__:null,CST:vn,Composer:sn,Document:xt,Schema:It,YAMLError:Lt,YAMLParseError:Ct,YAMLWarning:_t,Alias:U,isAlias:g,isCollection:S,isDocument:b,isMap:v,isNode:A,isPair:w,isScalar:k,isSeq:E,Pair:Ee,Scalar:W,YAMLMap:Ie,YAMLSeq:Te,Lexer:On,LineCounter:$n,Parser:jn,parse:function(e,t,n){let s;"function"==typeof t?s=t:void 0===n&&t&&"object"==typeof t&&(n=t);const i=Kn(e,n);if(!i)return null;if(i.warnings.forEach((e=>me(i.options.logLevel,e))),i.errors.length>0){if("silent"!==i.options.logLevel)throw i.errors[0];i.errors=[]}return i.toJS(Object.assign({reviver:s},n))},parseAllDocuments:function(e,t={}){const{lineCounter:n,prettyErrors:s}=Bn(t),i=new jn(n?.addNewLine),r=new sn(t),o=Array.from(r.compose(i.parse(e)));if(s&&n)for(const t of o)t.errors.forEach(jt(e,n)),t.warnings.forEach(jt(e,n));return o.length>0?o:Object.assign([],{empty:!0},r.streamInfo())},parseDocument:Kn,stringify:function(e,t,n){let s=null;if("function"==typeof t||Array.isArray(t)?s=t:void 0===n&&t&&(n=t),"string"==typeof n&&(n=n.length),"number"==typeof n){const e=Math.round(n);n=e<1?void 0:e>8?{indent:8}:{indent:e}}if(void 0===e){const{keepUndefined:e}=n??t??{};if(!e)return}return b(e)&&!s?e.toString(n):new xt(e,s,n).toString(n)},visit:I,visitAsync:T});exports.AmoebaFlowParser=class{static extractAmoebas(e){if(Array.isArray(e.amoebas))return e.amoebas;if(Array.isArray(e.nodes))return e.nodes;throw new Error('Invalid flow structure. Expected key "amoebas" or "nodes" (array).')}static fromObject(e,t=!0){return this.validateStructure(e,t),this.parse(e,t)}static fromJSON(e,t=!0){let n;if("string"==typeof e)try{n=JSON.parse(e)}catch(e){throw new Error(`Invalid JSON string: ${e.message}`)}else{if("object"!=typeof e||null===e)throw new Error("Input must be a valid JSON object or string.");n=e}return this.validateStructure(n,t),this.parse(n,t)}static fromYAML(e,t=!0){try{const n=Mn.parse(e);return this.validateStructure(n,t),this.parse(n,t)}catch(e){throw new Error(`Invalid YAML: ${e.message}`)}}static fromYaml(e,t=!0){return this.fromYAML(e,t)}static validateStructure(e,t){this.extractAmoebas(e).forEach(((e,n)=>{const{id:s,func:i,outputEvents:r}=e;this.validateId(s,n),this.validateFunc(i,s,t),this.validateOutputEvents(r,s,t)}))}static validateId(e,t){if("string"!=typeof e||""===e.trim())throw new Error(`Invalid "id" for amoeba at index ${t}. Expected a non-empty string.`)}static validateFunc(e,t,n){if("function"!=typeof e){if(!n||"string"!=typeof e)throw new Error(`Amoeba "${t}" must have a valid "func" (function or trusted string).`);try{this.resolveFunction(e)}catch(e){throw new Error(`Invalid "func" in amoeba "${t}": ${e.message}`)}}}static validateOutputEvents(e,t,n){if(void 0===e)return;if(!Array.isArray(e))throw new Error(`Amoeba "${t}" must have an "outputEvents" array.`);const s=(e,n,s)=>{if("string"==typeof e){if(this.isReservedEvent(e))throw new Error(`Amoeba "${t}" outputEvents[${n}].${s} action cannot reference auto-generated event "${e}". Use explicit event names instead.`)}else{if("object"!=typeof e)throw new Error(`Amoeba "${t}" outputEvents[${n}].${s} action must be string or object.`);if("string"!=typeof e.event)throw new Error(`Amoeba "${t}" outputEvents[${n}].${s} action must have string "event".`);if(this.isReservedEvent(e.event))throw new Error(`Amoeba "${t}" outputEvents[${n}].${s} action cannot reference auto-generated event "${e.event}". Use explicit event names instead.`);if(e.hasOwnProperty("reflexive")&&"boolean"!=typeof e.reflexive)throw new Error(`Amoeba "${t}" outputEvents[${n}].${s} action.reflexive must be boolean.`)}};e.forEach(((e,i)=>{if("string"!=typeof e){if("object"==typeof e){if(e.hasOwnProperty("condition")){const{condition:r,then:o,else:a}=e;if(void 0===r)throw new Error(`outputEvents[${i}] in "${t}": Missing "condition".`);if("function"!=typeof r&&(!n||"string"!=typeof r))throw new Error(`Invalid "condition" type in outputEvents[${i}] ("${t}").`);if(!Array.isArray(o))throw new Error(`Amoeba "${t}" outputEvents[${i}]: "then" must be an array.`);if(o.forEach((e=>s(e,i,"then"))),void 0!==a){if(!Array.isArray(a))throw new Error(`Amoeba "${t}" outputEvents[${i}]: "else" must be an array if present.`);a.forEach((e=>s(e,i,"else")))}if("string"==typeof r&&n)try{this.resolveFunction(r)}catch(e){throw new Error(`Invalid string condition in outputEvents[${i}] ("${t}"): ${e.message}`)}return}if("string"==typeof e.event){if(e.hasOwnProperty("reflexive")&&"boolean"!=typeof e.reflexive)throw new Error(`Amoeba "${t}" outputEvents[${i}]: "reflexive" must be boolean.`);return}}throw new Error(`Invalid outputEvents[${i}] format in amoeba "${t}".`)}}))}static parse(e,t){const n=new l({eventEmitter:!1===e.useSingletonEmitter?new o:void 0,storeResults:e.storeResults||!1,verbose:!!e.verbose});return this.extractAmoebas(e).forEach((({id:s,func:i,inputEvents:r=[],outputEvents:o=[],storeResults:a=null,stickyInputs:c=!1,triggerMode:l=!1,verbose:u=null})=>{const f="function"==typeof i?i:t?this.resolveFunction(i):()=>{throw new Error("Function execution blocked (untrusted source).")},h=o.map((e=>{if("string"==typeof e)return e;const n="function"==typeof e.condition?e.condition:t?this.resolveFunction(e.condition):()=>{throw new Error("Condition execution blocked (untrusted source).")},s=e=>"string"==typeof e?e:{event:e.event,reflexive:!!e.reflexive};return{...e,condition:n,then:(e.then||[]).map(s),else:(e.else||[]).map(s)}})),d=u??!!e.verbose;n.addAmoeba({id:s,func:f,inputEvents:r,outputEvents:h,storeResults:a,stickyInputs:c,triggerMode:l,verbose:d})})),n}static resolveFunction(e){if("function"==typeof e)return e;if("string"==typeof e)try{return new Function(`return (${e})`)()}catch(e){throw new Error(`Error resolving function: ${e.message}`)}throw new Error(`Invalid function: ${e}`)}static isReservedEvent(e){return"string"==typeof e&&(e.endsWith(t)||e.endsWith(n))}},exports.AmoebaSea=l,exports.ERROR_EVENT_SUFFIX=n,exports.EXECUTED_EVENT_SUFFIX=t,exports.SEA_READY_EVENT=c;