@drincs/pixi-vn-ink 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -3,8 +3,8 @@ export { PixiVNJson, TextReplaces, VariableGetter } from '@drincs/pixi-vn-json';
3
3
  import { StepLabelProps } from '@drincs/pixi-vn';
4
4
  import { PixiVNJsonLabelStep, PixiVNJsonOperation } from '@drincs/pixi-vn-json/schema';
5
5
  import { ZodType } from 'zod';
6
- import { C as CharacterIdSource, L as LoaderSharedType } from './type-D3nJ4LrW.cjs';
7
- import './types-xCqKPbWY.cjs';
6
+ import { C as CharacterIdSource, L as LoaderSharedType } from './type-Br1aIqKp.cjs';
7
+ import './types-B7f5EzP5.cjs';
8
8
  import 'inkjs/engine/Error';
9
9
 
10
10
  /**
@@ -304,7 +304,19 @@ declare namespace HashtagCommands {
304
304
  function convertTagTolist(tag: string, options?: {
305
305
  mergeInkVariables?: boolean;
306
306
  }): string[];
307
- function convertOperation(list: string[], step: PixiVNJsonLabelStep$1): PixiVNJsonOperation$1 | undefined;
307
+ function convertOperation(list: string[], step: PixiVNJsonLabelStep$1, options?: {
308
+ /**
309
+ * When `true`, suppresses the "The operation is not valid" error log on a mapper
310
+ * miss. Callers that only speculatively probe the built-in `.addMapper()` table —
311
+ * e.g. to decide whether a hashtag script can be resolved eagerly at parse time,
312
+ * before falling back to a deferred `operationtoconvert` step that will later be
313
+ * resolved through the full {@link run} pipeline (custom `.add()` handlers included)
314
+ * — should pass `silent: true`. Otherwise every hashtag command registered only via
315
+ * `.add()` (never a mapper) would log a false "not valid" error on every parse, even
316
+ * though it resolves correctly once `run()` reaches it.
317
+ */
318
+ silent?: boolean;
319
+ }): PixiVNJsonOperation$1 | undefined;
308
320
  /**
309
321
  * For example:
310
322
  * Into Ink text:
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { PixiVNJson, TextReplaces, VariableGetter } from '@drincs/pixi-vn-json';
3
3
  import { StepLabelProps } from '@drincs/pixi-vn';
4
4
  import { PixiVNJsonLabelStep, PixiVNJsonOperation } from '@drincs/pixi-vn-json/schema';
5
5
  import { ZodType } from 'zod';
6
- import { C as CharacterIdSource, L as LoaderSharedType } from './type-BmBeTPwm.js';
7
- import './types-xCqKPbWY.js';
6
+ import { C as CharacterIdSource, L as LoaderSharedType } from './type-DIFR_5pl.js';
7
+ import './types-B7f5EzP5.js';
8
8
  import 'inkjs/engine/Error';
9
9
 
10
10
  /**
@@ -304,7 +304,19 @@ declare namespace HashtagCommands {
304
304
  function convertTagTolist(tag: string, options?: {
305
305
  mergeInkVariables?: boolean;
306
306
  }): string[];
307
- function convertOperation(list: string[], step: PixiVNJsonLabelStep$1): PixiVNJsonOperation$1 | undefined;
307
+ function convertOperation(list: string[], step: PixiVNJsonLabelStep$1, options?: {
308
+ /**
309
+ * When `true`, suppresses the "The operation is not valid" error log on a mapper
310
+ * miss. Callers that only speculatively probe the built-in `.addMapper()` table —
311
+ * e.g. to decide whether a hashtag script can be resolved eagerly at parse time,
312
+ * before falling back to a deferred `operationtoconvert` step that will later be
313
+ * resolved through the full {@link run} pipeline (custom `.add()` handlers included)
314
+ * — should pass `silent: true`. Otherwise every hashtag command registered only via
315
+ * `.add()` (never a mapper) would log a false "not valid" error on every parse, even
316
+ * though it resolves correctly once `run()` reaches it.
317
+ */
318
+ silent?: boolean;
319
+ }): PixiVNJsonOperation$1 | undefined;
308
320
  /**
309
321
  * For example:
310
322
  * Into Ink text:
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{a as importInkText,b as importJson}from'./chunk-VGEZJRI2.mjs';import {d,h as h$1,i}from'./chunk-LFOBAFWQ.mjs';export{i as HashtagCommands,c as TextReplaces,e as VariableGetter,m as convertInkText,m as convertInkToJson,j as onInkHashtagScript}from'./chunk-LFOBAFWQ.mjs';function k(e){d.afterToTranslate=n=>T(n,e);}function y(e){d.beforeToTranslate=n=>T(n,e);}function T(e,n){let s=new RegExp(h$1.source,"g"),t=new Set,o=true;for(;o;){o=false;let x=[...e.matchAll(s)],i=new Set;for(let l of x){let a=l[1];if(i.has(a)||t.has(a))continue;i.add(a);let p=n(a);p!==void 0?(e=e.replaceAll(l[0],p),o=true):t.add(a);}}return e}function b(e){d.translate=e;}async function h(e,n={},s={}){let t=[];return e.labels&&Object.values(e.labels).forEach(o=>{t=t.concat(o);}),await d.generateJsonTranslation(t,n,{...s,operationStringConvert:i.run})}export{h as generateJsonInkTranslation,b as onInkTranslate,k as onReplaceTextAfterTranslation,y as onReplaceTextBeforeTranslation};
1
+ export{a as importInkText,b as importJson}from'./chunk-WU3FPOE2.mjs';import {d,h as h$1,i}from'./chunk-3K2SER36.mjs';export{i as HashtagCommands,c as TextReplaces,e as VariableGetter,m as convertInkText,m as convertInkToJson,j as onInkHashtagScript}from'./chunk-3K2SER36.mjs';function k(e){d.afterToTranslate=n=>T(n,e);}function y(e){d.beforeToTranslate=n=>T(n,e);}function T(e,n){let s=new RegExp(h$1.source,"g"),t=new Set,o=true;for(;o;){o=false;let x=[...e.matchAll(s)],i=new Set;for(let l of x){let a=l[1];if(i.has(a)||t.has(a))continue;i.add(a);let p=n(a);p!==void 0?(e=e.replaceAll(l[0],p),o=true):t.add(a);}}return e}function b(e){d.translate=e;}async function h(e,n={},s={}){let t=[];return e.labels&&Object.values(e.labels).forEach(o=>{t=t.concat(o);}),await d.generateJsonTranslation(t,n,{...s,operationStringConvert:i.run})}export{h as generateJsonInkTranslation,b as onInkTranslate,k as onReplaceTextAfterTranslation,y as onReplaceTextBeforeTranslation};
package/dist/mapper.cjs CHANGED
@@ -5,13 +5,13 @@
5
5
  `:case "\r":throw R(D());case "\u2028":case "\u2029":ru(V);break;case void 0:throw R(D())}v+=D();},start(){switch(V){case "{":case "[":return w("punctuator",D())}S="value";},beforePropertyName(){switch(V){case "$":case "_":v=D(),S="identifierName";return;case "\\":D(),S="identifierNameStartEscape";return;case "}":return w("punctuator",D());case '"':case "'":ue=D()==='"',S="string";return}if(k.isIdStartChar(V)){v+=D(),S="identifierName";return}throw R(D())},afterPropertyName(){if(V===":")return w("punctuator",D());throw R(D())},beforePropertyValue(){S="value";},afterPropertyValue(){switch(V){case ",":case "}":return w("punctuator",D())}throw R(D())},beforeArrayValue(){if(V==="]")return w("punctuator",D());S="value";},afterArrayValue(){switch(V){case ",":case "]":return w("punctuator",D())}throw R(D())},end(){throw R(D())}};function w(e,u){return {type:e,value:u,line:z,column:_}}function Y(e){for(let u of e){if($()!==u)throw R(D());D();}}function tu(){switch($()){case "b":return D(),"\b";case "f":return D(),"\f";case "n":return D(),`
6
6
  `;case "r":return D(),"\r";case "t":return D()," ";case "v":return D(),"\v";case "0":if(D(),k.isDigit($()))throw R(D());return "\0";case "x":return D(),nu();case "u":return D(),Ae();case `
7
7
  `:case "\u2028":case "\u2029":return D(),"";case "\r":return D(),$()===`
8
- `&&D(),"";case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":throw R(D());case void 0:throw R(D())}return D()}function nu(){let e="",u=$();if(!k.isHexDigit(u)||(e+=D(),u=$(),!k.isHexDigit(u)))throw R(D());return e+=D(),String.fromCodePoint(parseInt(e,16))}function Ae(){let e="",u=4;for(;u-- >0;){let n=$();if(!k.isHexDigit(n))throw R(D());e+=D();}return String.fromCodePoint(parseInt(e,16))}var iu={start(){if(M.type==="eof")throw Q();fe();},beforePropertyName(){switch(M.type){case "identifier":case "string":ge=M.value,L="afterPropertyName";return;case "punctuator":se();return;case "eof":throw Q()}},afterPropertyName(){if(M.type==="eof")throw Q();L="beforePropertyValue";},beforePropertyValue(){if(M.type==="eof")throw Q();fe();},beforeArrayValue(){if(M.type==="eof")throw Q();if(M.type==="punctuator"&&M.value==="]"){se();return}fe();},afterPropertyValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforePropertyName";return;case "}":se();}},afterArrayValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforeArrayValue";return;case "]":se();}},end(){}};function fe(){let e;switch(M.type){case "punctuator":switch(M.value){case "{":e={};break;case "[":e=[];break}break;case "null":case "boolean":case "numeric":case "string":e=M.value;break}if(te===void 0)te=e;else {let u=W[W.length-1];Array.isArray(u)?u.push(e):Object.defineProperty(u,ge,{value:e,writable:true,enumerable:true,configurable:true});}if(e!==null&&typeof e=="object")W.push(e),Array.isArray(e)?L="beforeArrayValue":L="beforePropertyName";else {let u=W[W.length-1];u==null?L="end":Array.isArray(u)?L="afterArrayValue":L="afterPropertyValue";}}function se(){W.pop();let e=W[W.length-1];e==null?L="end":Array.isArray(e)?L="afterArrayValue":L="afterPropertyValue";}function R(e){return ae(e===void 0?`JSON5: invalid end of input at ${z}:${_}`:`JSON5: invalid character '${ke(e)}' at ${z}:${_}`)}function Q(){return ae(`JSON5: invalid end of input at ${z}:${_}`)}function we(){return _-=5,ae(`JSON5: invalid identifier character at ${z}:${_}`)}function ru(e){console.warn(`JSON5: '${ke(e)}' in strings is not valid ECMAScript; consider escaping`);}function ke(e){let u={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(u[e])return u[e];if(e<" "){let n=e.charCodeAt(0).toString(16);return "\\x"+("00"+n).substring(n.length)}return e}function ae(e){let u=new SyntaxError(e);return u.lineNumber=z,u.columnNumber=_,u}var su=function(u,n,i){let o=[],r="",a,l,c="",p;if(n!=null&&typeof n=="object"&&!Array.isArray(n)&&(i=n.space,p=n.quote,n=n.replacer),typeof n=="function")l=n;else if(Array.isArray(n)){a=[];for(let F of n){let x;typeof F=="string"?x=F:(typeof F=="number"||F instanceof String||F instanceof Number)&&(x=String(F)),x!==void 0&&a.indexOf(x)<0&&a.push(x);}}return i instanceof Number?i=Number(i):i instanceof String&&(i=String(i)),typeof i=="number"?i>0&&(i=Math.min(10,Math.floor(i)),c=" ".substr(0,i)):typeof i=="string"&&(c=i.substr(0,10)),f("",{"":u});function f(F,x){let T=x[F];switch(T!=null&&(typeof T.toJSON5=="function"?T=T.toJSON5(F):typeof T.toJSON=="function"&&(T=T.toJSON(F))),l&&(T=l.call(x,F,T)),T instanceof Number?T=Number(T):T instanceof String?T=String(T):T instanceof Boolean&&(T=T.valueOf()),T){case null:return "null";case true:return "true";case false:return "false"}if(typeof T=="string")return C(T);if(typeof T=="number")return String(T);if(typeof T=="object")return Array.isArray(T)?m(T):A(T)}function C(F){let x={"'":.1,'"':.2},T={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"},P="";for(let h=0;h<F.length;h++){let d=F[h];switch(d){case "'":case '"':x[d]++,P+=d;continue;case "\0":if(k.isDigit(F[h+1])){P+="\\x00";continue}}if(T[d]){P+=T[d];continue}if(d<" "){let g=d.charCodeAt(0).toString(16);P+="\\x"+("00"+g).substring(g.length);continue}P+=d;}let t=p||Object.keys(x).reduce((h,d)=>x[h]<x[d]?h:d);return P=P.replace(new RegExp(t,"g"),T[t]),t+P+t}function A(F){if(o.indexOf(F)>=0)throw TypeError("Converting circular structure to JSON5");o.push(F);let x=r;r=r+c;let T=a||Object.keys(F),P=[];for(let h of T){let d=f(h,F);if(d!==void 0){let g=E(h)+":";c!==""&&(g+=" "),g+=d,P.push(g);}}let t;if(P.length===0)t="{}";else {let h;if(c==="")h=P.join(","),t="{"+h+"}";else {let d=`,
8
+ `&&D(),"";case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":throw R(D());case void 0:throw R(D())}return D()}function nu(){let e="",u=$();if(!k.isHexDigit(u)||(e+=D(),u=$(),!k.isHexDigit(u)))throw R(D());return e+=D(),String.fromCodePoint(parseInt(e,16))}function Ae(){let e="",u=4;for(;u-- >0;){let n=$();if(!k.isHexDigit(n))throw R(D());e+=D();}return String.fromCodePoint(parseInt(e,16))}var iu={start(){if(M.type==="eof")throw Q();fe();},beforePropertyName(){switch(M.type){case "identifier":case "string":ge=M.value,L="afterPropertyName";return;case "punctuator":se();return;case "eof":throw Q()}},afterPropertyName(){if(M.type==="eof")throw Q();L="beforePropertyValue";},beforePropertyValue(){if(M.type==="eof")throw Q();fe();},beforeArrayValue(){if(M.type==="eof")throw Q();if(M.type==="punctuator"&&M.value==="]"){se();return}fe();},afterPropertyValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforePropertyName";return;case "}":se();}},afterArrayValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforeArrayValue";return;case "]":se();}},end(){}};function fe(){let e;switch(M.type){case "punctuator":switch(M.value){case "{":e={};break;case "[":e=[];break}break;case "null":case "boolean":case "numeric":case "string":e=M.value;break}if(te===void 0)te=e;else {let u=W[W.length-1];Array.isArray(u)?u.push(e):Object.defineProperty(u,ge,{value:e,writable:true,enumerable:true,configurable:true});}if(e!==null&&typeof e=="object")W.push(e),Array.isArray(e)?L="beforeArrayValue":L="beforePropertyName";else {let u=W[W.length-1];u==null?L="end":Array.isArray(u)?L="afterArrayValue":L="afterPropertyValue";}}function se(){W.pop();let e=W[W.length-1];e==null?L="end":Array.isArray(e)?L="afterArrayValue":L="afterPropertyValue";}function R(e){return ae(e===void 0?`JSON5: invalid end of input at ${z}:${_}`:`JSON5: invalid character '${ke(e)}' at ${z}:${_}`)}function Q(){return ae(`JSON5: invalid end of input at ${z}:${_}`)}function we(){return _-=5,ae(`JSON5: invalid identifier character at ${z}:${_}`)}function ru(e){console.warn(`JSON5: '${ke(e)}' in strings is not valid ECMAScript; consider escaping`);}function ke(e){let u={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(u[e])return u[e];if(e<" "){let n=e.charCodeAt(0).toString(16);return "\\x"+("00"+n).substring(n.length)}return e}function ae(e){let u=new SyntaxError(e);return u.lineNumber=z,u.columnNumber=_,u}var su=function(u,n,i){let o=[],r="",a,l,c="",p;if(n!=null&&typeof n=="object"&&!Array.isArray(n)&&(i=n.space,p=n.quote,n=n.replacer),typeof n=="function")l=n;else if(Array.isArray(n)){a=[];for(let g of n){let x;typeof g=="string"?x=g:(typeof g=="number"||g instanceof String||g instanceof Number)&&(x=String(g)),x!==void 0&&a.indexOf(x)<0&&a.push(x);}}return i instanceof Number?i=Number(i):i instanceof String&&(i=String(i)),typeof i=="number"?i>0&&(i=Math.min(10,Math.floor(i)),c=" ".substr(0,i)):typeof i=="string"&&(c=i.substr(0,10)),f("",{"":u});function f(g,x){let T=x[g];switch(T!=null&&(typeof T.toJSON5=="function"?T=T.toJSON5(g):typeof T.toJSON=="function"&&(T=T.toJSON(g))),l&&(T=l.call(x,g,T)),T instanceof Number?T=Number(T):T instanceof String?T=String(T):T instanceof Boolean&&(T=T.valueOf()),T){case null:return "null";case true:return "true";case false:return "false"}if(typeof T=="string")return C(T);if(typeof T=="number")return String(T);if(typeof T=="object")return Array.isArray(T)?B(T):A(T)}function C(g){let x={"'":.1,'"':.2},T={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"},P="";for(let h=0;h<g.length;h++){let d=g[h];switch(d){case "'":case '"':x[d]++,P+=d;continue;case "\0":if(k.isDigit(g[h+1])){P+="\\x00";continue}}if(T[d]){P+=T[d];continue}if(d<" "){let F=d.charCodeAt(0).toString(16);P+="\\x"+("00"+F).substring(F.length);continue}P+=d;}let t=p||Object.keys(x).reduce((h,d)=>x[h]<x[d]?h:d);return P=P.replace(new RegExp(t,"g"),T[t]),t+P+t}function A(g){if(o.indexOf(g)>=0)throw TypeError("Converting circular structure to JSON5");o.push(g);let x=r;r=r+c;let T=a||Object.keys(g),P=[];for(let h of T){let d=f(h,g);if(d!==void 0){let F=E(h)+":";c!==""&&(F+=" "),F+=d,P.push(F);}}let t;if(P.length===0)t="{}";else {let h;if(c==="")h=P.join(","),t="{"+h+"}";else {let d=`,
9
9
  `+r;h=P.join(d),t=`{
10
10
  `+r+h+`,
11
- `+x+"}";}}return o.pop(),r=x,t}function E(F){if(F.length===0)return C(F);let x=String.fromCodePoint(F.codePointAt(0));if(!k.isIdStartChar(x))return C(F);for(let T=x.length;T<F.length;T++)if(!k.isIdContinueChar(String.fromCodePoint(F.codePointAt(T))))return C(F);return F}function m(F){if(o.indexOf(F)>=0)throw TypeError("Converting circular structure to JSON5");o.push(F);let x=r;r=r+c;let T=[];for(let t=0;t<F.length;t++){let h=f(String(t),F);T.push(h!==void 0?h:"null");}let P;if(T.length===0)P="[]";else if(c==="")P="["+T.join(",")+"]";else {let t=`,
11
+ `+x+"}";}}return o.pop(),r=x,t}function E(g){if(g.length===0)return C(g);let x=String.fromCodePoint(g.codePointAt(0));if(!k.isIdStartChar(x))return C(g);for(let T=x.length;T<g.length;T++)if(!k.isIdContinueChar(String.fromCodePoint(g.codePointAt(T))))return C(g);return g}function B(g){if(o.indexOf(g)>=0)throw TypeError("Converting circular structure to JSON5");o.push(g);let x=r;r=r+c;let T=[];for(let t=0;t<g.length;t++){let h=f(String(t),g);T.push(h!==void 0?h:"null");}let P;if(T.length===0)P="[]";else if(c==="")P="["+T.join(",")+"]";else {let t=`,
12
12
  `+r,h=T.join(t);P=`[
13
13
  `+r+h+`,
14
- `+x+"]";}return o.pop(),r=x,P}},ou={parse:eu,stringify:su},au=ou,Fe=au;var Me="\xA7SPACE\xA7",Le="\xA7DOUBLE_QUOTES\xA7",_e="\xA7QUOTES\xA7",je="SPECIAL_\xA7QUOTES\xA7",Ie="\xA7CURLY_BRACKETS1\xA7",pu="\xA7INK_VAR\xA7",He="\xA7CURLY_BRACKETS2\xA7",y;(P=>{let e=[],u=[];async function n(t,h){for(let d=0;d<e.length;d++)try{let{validation:g}=e[d].opts;if(g instanceof RegExp){if(!g.test(t.join(" ")))continue}else if(g instanceof s.ZodType&&!g.safeParse(t).success)continue;let B=await e[d].fn(t,h,C);if(B===!0||typeof B=="string")return B}catch{}return false}function i(t,h={name:"custom-command",validation:/^/}){e.unshift({fn:t,opts:h});}P.add=i;function o(){return [...u.map(t=>t.opts),...e.map(t=>t.opts)]}P.info=o;function r(t,h){u.unshift({fn:t,opts:h});}P.addMapper=r;function a(){e.length=0;}P.clear=a;function l(){u.length=0;}P.clearMappers=l;async function c(t,h,d){try{let g=p(t),B=await n(g,d);return B===!0?void 0:typeof B=="string"?(B.startsWith("#")&&(B=B.substring(1)),await P.run(B,h,d)):f(g,h)}catch(g){throw O.error("Error parsing ink hashtag-command",t),g}}P.run=c;function p(t,h){if(t=t.replaceAll('\\"',Le),t=t.replaceAll("\\'",_e),t=t.replaceAll("\\`",je),t=t.replaceAll("\\{",Ie),t=t.replaceAll("\\}",He),h?.mergeInkVariables){let b;do b=t,t=t.replace(/\{[^{}:]*\}/g,pu);while(t!==b)}t=t.replaceAll("{"," { "),t=t.replaceAll("}"," } "),t=t.replaceAll(Ie,"{"),t=t.replaceAll(He,"}");let d=[],g,B="";for(let b=0;b<t.length;b++){let J=t[b];J==='"'||J==="'"||J==="`"?g===void 0?(d.push(B),B="",g=J,B+=J):g===J?(g=void 0,B+=J,d.push(B),B=""):B+=J:B+=J;}return B!==""&&d.push(B),d.forEach((b,J)=>{J%2===1&&(d[J]=b.replaceAll(" ",Me));}),t=d.join(""),d=t.split(" ").filter(b=>b!==""),d=d.map(b=>b.replaceAll(Me," ").replaceAll(Le,'"').replaceAll(_e,"'").replaceAll(je,"`")),d=F(d),d=d.map(b=>b.startsWith('"')&&b.endsWith('"')||b.startsWith("'")&&b.endsWith("'")||b.startsWith("`")&&b.endsWith("`")?b.slice(1,-1):b),d}P.convertTagTolist=p;function f(t,h){for(let d of u){let{validation:g}=d.opts,B=false;if(g instanceof RegExp?B=g.test(t.join(" ")):g instanceof s.ZodType&&(B=g.safeParse(t).success),B)return d.fn(t,h)}O.error("The operation is not valid",t);}P.convertOperation=f;function C(t){return A(t)}P.convertListStringToObj=C;function A(t){if(t.length===0)return {};if(t.length%2!==0)throw O.error("The props list must have a pair number of elements",t),new Error("The props list must have a pair number of elements");let h="{";t.forEach((d,g)=>{if(g%2===0)h+=`"${d}": `;else {switch(d){case "null":case "undefined":case "true":case "false":h+=`${d}`;break;default:m(d)?(d=E(d),h+=`"${d}"`):d.startsWith("{")&&d.endsWith("}")?h+=`${d}`:d.startsWith('"')&&d.endsWith('"')?h+=`${d}`:Number.isNaN(parseFloat(d))?h+=`"${d}"`:h+=`${d}`;}g<t.length-1&&(h+=", ");}}),h+="}";try{return Fe.parse(h)}catch(d){throw O.error("Error parsing ink json",h),d}}function E(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`")?t.substring(1,t.length-1):t}function m(t){return !!(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`"))}function F(t){return x(t).tokens}P.mergeJsonBlocks=F;function x(t){let h=[],d=false;for(let g=0;g<t.length;g++){let B=t[g];if(B!=="{"){h.push(B);continue}let b=T(t,g);if(b===-1){h.push(B);continue}let J=x(t.slice(g+1,b)),Pe=["{",...J.tokens,"}"],Oe=Pe.join(" ");if(!J.hasInvalidMatchedBlock)try{Fe.parse(Oe),h.push(Oe),g=b;continue}catch{}d=true,h.push(...Pe),g=b;}return {tokens:h,hasInvalidMatchedBlock:d}}function T(t,h){let d=0;for(let g=h;g<t.length;g++)if(t[g]==="{")d++;else if(t[g]==="}"&&(d--,d===0))return g;return -1}})(y||={});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"call"},u.goNextStep=void 0;},{name:"Call",description:"Calls the label specified by the second token, then returns to the current position.\n\n```ink\n# call label_name\n```",validation:s__default.default.tuple([s__default.default.literal("call"),s__default.default.string()])});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"jump"},u.goNextStep=void 0;},{name:"Jump",description:"Jumps to the label specified by the second token without returning.\n\n```ink\n# jump label_name\n```",validation:s__default.default.tuple([s__default.default.literal("jump"),s__default.default.string()])});y.addMapper((e,u)=>("dialogue"in u&&delete u.dialogue,"goNextStep"in u&&delete u.goNextStep,{type:"dialogue",operationType:"clean"}),{name:"Pause",description:"Clears the current dialogue and waits for user input before advancing.\n\n```ink\n# pause\n```",validation:s__default.default.tuple([s__default.default.literal("pause")])});y.addMapper((e,u)=>{u.goNextStep=true,u.glueEnabled=false;},{name:"Continue",description:"Forces the story to proceed to the next step automatically.\n\n```ink\n# continue\n```",validation:s__default.default.tuple([s__default.default.literal("continue")])});y.addMapper(e=>({type:"video",operationType:e[0],alias:e[2]}),{name:"Pause/Resume video",description:"Pauses or resumes a video canvas element identified by its alias.\n\n```ink\n# pause video <alias>\n# resume video <alias>\n```",validation:s__default.default.tuple([s__default.default.enum(["pause","resume"]),s__default.default.literal("video"),s__default.default.string()])});y.addMapper(e=>({type:e[1],operationType:e[0],aliases:e.slice(2)}),{name:"Load assets/bundle",description:`Loads (eagerly or lazily) a set of asset or bundle aliases.
14
+ `+x+"]";}return o.pop(),r=x,P}},ou={parse:eu,stringify:su},au=ou,Fe=au;var Me="\xA7SPACE\xA7",Le="\xA7DOUBLE_QUOTES\xA7",_e="\xA7QUOTES\xA7",je="SPECIAL_\xA7QUOTES\xA7",Ie="\xA7CURLY_BRACKETS1\xA7",pu="\xA7INK_VAR\xA7",He="\xA7CURLY_BRACKETS2\xA7",y;(P=>{let e=[],u=[];async function n(t,h){for(let d=0;d<e.length;d++)try{let{validation:F}=e[d].opts;if(F instanceof RegExp){if(!F.test(t.join(" ")))continue}else if(F instanceof s.ZodType&&!F.safeParse(t).success)continue;let m=await e[d].fn(t,h,C);if(m===!0||typeof m=="string")return m}catch{}return false}function i(t,h={name:"custom-command",validation:/^/}){e.unshift({fn:t,opts:h});}P.add=i;function o(){return [...u.map(t=>t.opts),...e.map(t=>t.opts)]}P.info=o;function r(t,h){u.unshift({fn:t,opts:h});}P.addMapper=r;function a(){e.length=0;}P.clear=a;function l(){u.length=0;}P.clearMappers=l;async function c(t,h,d){try{let F=p(t),m=await n(F,d);return m===!0?void 0:typeof m=="string"?(m.startsWith("#")&&(m=m.substring(1)),await P.run(m,h,d)):f(F,h)}catch(F){throw O.error("Error parsing ink hashtag-command",t),F}}P.run=c;function p(t,h){if(t=t.replaceAll('\\"',Le),t=t.replaceAll("\\'",_e),t=t.replaceAll("\\`",je),t=t.replaceAll("\\{",Ie),t=t.replaceAll("\\}",He),h?.mergeInkVariables){let b;do b=t,t=t.replace(/\{[^{}:]*\}/g,pu);while(t!==b)}t=t.replaceAll("{"," { "),t=t.replaceAll("}"," } "),t=t.replaceAll(Ie,"{"),t=t.replaceAll(He,"}");let d=[],F,m="";for(let b=0;b<t.length;b++){let J=t[b];J==='"'||J==="'"||J==="`"?F===void 0?(d.push(m),m="",F=J,m+=J):F===J?(F=void 0,m+=J,d.push(m),m=""):m+=J:m+=J;}return m!==""&&d.push(m),d.forEach((b,J)=>{J%2===1&&(d[J]=b.replaceAll(" ",Me));}),t=d.join(""),d=t.split(" ").filter(b=>b!==""),d=d.map(b=>b.replaceAll(Me," ").replaceAll(Le,'"').replaceAll(_e,"'").replaceAll(je,"`")),d=g(d),d=d.map(b=>b.startsWith('"')&&b.endsWith('"')||b.startsWith("'")&&b.endsWith("'")||b.startsWith("`")&&b.endsWith("`")?b.slice(1,-1):b),d}P.convertTagTolist=p;function f(t,h,d){for(let F of u){let{validation:m}=F.opts,b=false;if(m instanceof RegExp?b=m.test(t.join(" ")):m instanceof s.ZodType&&(b=m.safeParse(t).success),b)return F.fn(t,h)}d?.silent||O.error("The operation is not valid",t);}P.convertOperation=f;function C(t){return A(t)}P.convertListStringToObj=C;function A(t){if(t.length===0)return {};if(t.length%2!==0)throw O.error("The props list must have a pair number of elements",t),new Error("The props list must have a pair number of elements");let h="{";t.forEach((d,F)=>{if(F%2===0)h+=`"${d}": `;else {switch(d){case "null":case "undefined":case "true":case "false":h+=`${d}`;break;default:B(d)?(d=E(d),h+=`"${d}"`):d.startsWith("{")&&d.endsWith("}")?h+=`${d}`:d.startsWith('"')&&d.endsWith('"')?h+=`${d}`:Number.isNaN(parseFloat(d))?h+=`"${d}"`:h+=`${d}`;}F<t.length-1&&(h+=", ");}}),h+="}";try{return Fe.parse(h)}catch(d){throw O.error("Error parsing ink json",h),d}}function E(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`")?t.substring(1,t.length-1):t}function B(t){return !!(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`"))}function g(t){return x(t).tokens}P.mergeJsonBlocks=g;function x(t){let h=[],d=false;for(let F=0;F<t.length;F++){let m=t[F];if(m!=="{"){h.push(m);continue}let b=T(t,F);if(b===-1){h.push(m);continue}let J=x(t.slice(F+1,b)),Pe=["{",...J.tokens,"}"],Oe=Pe.join(" ");if(!J.hasInvalidMatchedBlock)try{Fe.parse(Oe),h.push(Oe),F=b;continue}catch{}d=true,h.push(...Pe),F=b;}return {tokens:h,hasInvalidMatchedBlock:d}}function T(t,h){let d=0;for(let F=h;F<t.length;F++)if(t[F]==="{")d++;else if(t[F]==="}"&&(d--,d===0))return F;return -1}})(y||={});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"call"},u.goNextStep=void 0;},{name:"Call",description:"Calls the label specified by the second token, then returns to the current position.\n\n```ink\n# call label_name\n```",validation:s__default.default.tuple([s__default.default.literal("call"),s__default.default.string()])});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"jump"},u.goNextStep=void 0;},{name:"Jump",description:"Jumps to the label specified by the second token without returning.\n\n```ink\n# jump label_name\n```",validation:s__default.default.tuple([s__default.default.literal("jump"),s__default.default.string()])});y.addMapper((e,u)=>("dialogue"in u&&delete u.dialogue,"goNextStep"in u&&delete u.goNextStep,{type:"dialogue",operationType:"clean"}),{name:"Pause",description:"Clears the current dialogue and waits for user input before advancing.\n\n```ink\n# pause\n```",validation:s__default.default.tuple([s__default.default.literal("pause")])});y.addMapper((e,u)=>{u.goNextStep=true,u.glueEnabled=false;},{name:"Continue",description:"Forces the story to proceed to the next step automatically.\n\n```ink\n# continue\n```",validation:s__default.default.tuple([s__default.default.literal("continue")])});y.addMapper(e=>({type:"video",operationType:e[0],alias:e[2]}),{name:"Pause/Resume video",description:"Pauses or resumes a video canvas element identified by its alias.\n\n```ink\n# pause video <alias>\n# resume video <alias>\n```",validation:s__default.default.tuple([s__default.default.enum(["pause","resume"]),s__default.default.literal("video"),s__default.default.string()])});y.addMapper(e=>({type:e[1],operationType:e[0],aliases:e.slice(2)}),{name:"Load assets/bundle",description:`Loads (eagerly or lazily) a set of asset or bundle aliases.
15
15
 
16
16
  \`\`\`ink
17
17
  # load assets <alias...>
@@ -19,5 +19,5 @@
19
19
  # load bundle <alias...>
20
20
  # lazyload bundle <alias...>
21
21
  \`\`\``,validation:s__default.default.tuple([s__default.default.enum(["load","lazyload"]),s__default.default.enum(["assets","bundle"])]).rest(s__default.default.string())});y.addMapper(e=>({type:"all",operationType:e[0]}),{name:"Pause/Resume/Stop all sounds",description:"Pauses, resumes, or stops all active sounds at once.\n\n```ink\n# pause all sounds\n# resume all sounds\n# stop all sounds\n```",validation:s__default.default.tuple([s__default.default.enum(["pause","resume","stop"]),s__default.default.literal("all"),s__default.default.enum(["sounds","sound"])])});y.addMapper(e=>({type:"sound",operationType:"pause",alias:e[2]}),{name:"Pause sound",description:"Pauses the sound identified by its alias.\n\n```ink\n# pause sound <alias>\n```",validation:s__default.default.tuple([s__default.default.literal("pause"),s__default.default.literal("sound"),s__default.default.string()])});y.addMapper(e=>({type:"channel",operationType:"pause",alias:e[2]}),{name:"Pause channel",description:"Pauses the audio channel identified by its alias.\n\n```ink\n# pause channel <alias>\n```",validation:s__default.default.tuple([s__default.default.literal("pause"),s__default.default.literal("channel"),s__default.default.string()])});y.addMapper(e=>({type:"sound",operationType:"resume",alias:e[2]}),{name:"Resume sound",description:"Resumes the sound identified by its alias.\n\n```ink\n# resume sound <alias>\n```",validation:s__default.default.tuple([s__default.default.literal("resume"),s__default.default.literal("sound"),s__default.default.string()])});y.addMapper(e=>({type:"channel",operationType:"resume",alias:e[2]}),{name:"Resume channel",description:"Resumes the audio channel identified by its alias.\n\n```ink\n# resume channel <alias>\n```",validation:s__default.default.tuple([s__default.default.literal("resume"),s__default.default.literal("channel"),s__default.default.string()])});y.addMapper(e=>({type:"sound",operationType:"stop",alias:e[2]}),{name:"Stop sound",description:"Stops the sound identified by its alias.\n\n```ink\n# stop sound <alias>\n```",validation:s__default.default.tuple([s__default.default.literal("stop"),s__default.default.literal("sound"),s__default.default.string()])});y.addMapper(e=>({type:"sound",operationType:"stop",alias:e[2]}),{name:"Remove sound",description:"Removes (stops) the sound identified by its alias.\n\n```ink\n# remove sound <alias>\n```",deprecated:true,validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("sound"),s__default.default.string()])});y.addMapper(e=>({type:"sound",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit sound",description:"Edits the properties of a sound identified by its alias.\n\n```ink\n# edit sound <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("sound"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>(e.length-3)%2===0)});y.addMapper(e=>{let u=e[2],n={type:"sound",operationType:"play",alias:u,url:u};return e.length>3&&(n.props=y.convertListStringToObj(e.slice(3))),n},{name:"Play sound",description:"Plays a sound using its alias as the URL, with optional key/value properties.\n\n```ink\n# play sound <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("play"),s__default.default.literal("sound"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>(e.length-3)%2===0)});y.addMapper(e=>{let u=e[2],n=e[3],i={type:"sound",operationType:"play",alias:u,url:n};return e.length>4&&(i.props=y.convertListStringToObj(e.slice(4))),i},{name:"Play sound with source",description:"Plays a sound with an explicit source URL and optional key/value properties.\n \n```ink\n# play sound <alias> <source> [<key> <value> \u2026]\n```\n",validation:s__default.default.tuple([s__default.default.literal("play"),s__default.default.literal("sound"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>e.length>3&&(e.length-3)%2!==0)});function j(e){let u=[],n=0,i="";for(let o of e)o.startsWith("{")?(n++,i+=o):o.endsWith("}")&&n>0?(n--,i+=o,n===0&&(u.push(i),i="")):n>0?i+=o:u.push(o);return u}function pe(e,u){switch(e){case "dissolve":case "fade":case "movein":case "moveout":case "zoomin":case "zoomout":case "pushin":case "pushout":break;default:return}let n={type:e};if(u.length>0)try{n.props=y.convertListStringToObj(u);}catch{}return n}function We(e,u,n){let i,o;n.length%2===0?(i=u,o=n):(i=n[0],o=n.slice(1));let r={type:e,operationType:"show",alias:u,url:i};if(o.length>0){if(o.includes("with")&&o.length>o.indexOf("with")+1){let a=o[o.indexOf("with")+1],l=o.slice(o.indexOf("with")+2);o=o.slice(0,o.indexOf("with"));let c=pe(a,l);c!==void 0&&(r.transition=c);}o.length>0&&(r.props=y.convertListStringToObj(o));}return r}function lu(e,u){let n,i;u.length%2===0?(n=e,i=u):(n=u[0],i=u.slice(1));let o={type:"text",operationType:"show",alias:e,text:n};if(i.length>0){if(i.includes("with")&&i.length>i.indexOf("with")+1){let r=i[i.indexOf("with")+1],a=i.slice(i.indexOf("with")+2);i=i.slice(0,i.indexOf("with"));let l=pe(r,a);l!==void 0&&(o.transition=l);}i.length>0&&(o.props=y.convertListStringToObj(i));}return o}function ne(e,u,n){let i={type:e,operationType:"remove",alias:u};if(n.includes("with")&&n.length>n.indexOf("with")+1){let o=n[n.indexOf("with")+1],r=n.slice(n.indexOf("with")+2),a=pe(o,r);a!==void 0&&(i.transition=a);}return i}function he(e,u){let n=c=>c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")||c.startsWith("`")&&c.endsWith("`")?c.substring(1,c.length-1):c,i=[],o=u.findIndex(c=>c.startsWith("[")),r=u.findIndex(c=>c.endsWith("]"));if(o===-1||r===-1){O.error("Show imagecontainer must have a list of image ulrs",u);return}if(i=u.slice(o,r+1),i.length<2){O.error("Show imagecontainer must have a list of image ulrs",u);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let a={type:"imagecontainer",operationType:"show",alias:e,urls:i.map(c=>n(c))},l=u.slice(r+1);if(l.length>0){if(l.includes("with")&&l.length>l.indexOf("with")+1){let c=l[l.indexOf("with")+1],p=l.slice(l.indexOf("with")+2);l=l.slice(0,l.indexOf("with"));let f=pe(c,p);f!==void 0&&(a.transition=f);}l.length>0&&(a.props=y.convertListStringToObj(l));}return a}function Ee(e){let u=e.slice(3),n=u.findIndex(a=>a.startsWith("[")),i=u.findIndex(a=>a.endsWith("]"));if(n===-1||i===-1||i<n)return;let o=u.slice(i+1),r=o.indexOf("with");return r===-1?{beforeWith:o,afterWith:[]}:{beforeWith:o.slice(0,r),afterWith:o.slice(r+1)}}y.addMapper(e=>({alias:e[1],type:"shake",props:y.convertListStringToObj(e.slice(2))}),{name:"Shake",description:"Applies shake effect to a canvas alias with optional key/value parameters.\n\n```ink\n# shake <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("shake"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>(e.length-2)%2===0)});y.addMapper(e=>{let u=e.slice(2),n=u,i=[];if(u.includes("options")){let r=u.indexOf("options");n=u.slice(0,r),i=u.slice(r+1);}return {alias:e[1],type:"animate",keyframes:y.convertListStringToObj(n),options:y.convertListStringToObj(i)}},{name:"Animate",description:"Animates a canvas alias with keyframes and optional options section, both in key/value pairs.\n\n```ink\n# animate <alias> [<key> <value> \u2026] [options <key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("animate"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>{let u=e.slice(2),n=u.indexOf("options");if(n===-1)return u.length%2===0;if(u.lastIndexOf("options")!==n)return false;let i=u.slice(0,n),o=u.slice(n+1);return i.length%2===0&&o.length%2===0})});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return We("image",u,n)},{name:"Show image",description:"Shows an image canvas element with optional source URL, key/value properties, and transition effect.\n\n```ink\n# show image <alias> [<source>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("image"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer",description:"Shows an image-container canvas element with a list of image URLs and optional key/value properties.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("imagecontainer"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length===0&&u.beforeWith.length%2===0})});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer with transition",description:"Shows an image-container canvas element with a list of image URLs, optional properties, and a transition effect.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026] with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("imagecontainer"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length===1&&u.beforeWith.length%2===0})});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer with transition and props",description:"Shows an image-container canvas element with a list of image URLs, optional properties, a transition effect, and transition key/value properties.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026] with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout <key> <value> \u2026\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("imagecontainer"),s__default.default.string()]).rest(s__default.default.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length>1&&(u.afterWith.length-1)%2===0&&u.beforeWith.length%2===0})});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return We("video",u,n)},{name:"Show video",description:"Shows a video canvas element with optional source URL, key/value properties, and transition effect.\n\n```ink\n# show video <alias> [<source>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("video"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2];return lu(u,e.slice(3))},{name:"Show text",description:"Shows a text canvas element with optional text content, key/value properties, and transition effect.\n\n```ink\n# show text <alias> [<text>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("show"),s__default.default.literal("text"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("image",u,n)},{name:"Remove image",description:"Removes an image canvas element with an optional transition effect.\n\n```ink\n# remove image <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("image"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("video",u,n)},{name:"Remove video",description:"Removes a video canvas element with an optional transition effect.\n\n```ink\n# remove video <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("video"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("canvaselement",u,n)},{name:"Remove canvas element",description:"Removes a canvas element with an optional transition effect.\n\n```ink\n# remove canvaselement <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("canvaselement"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("text",u,n)},{name:"Remove text",description:"Removes a text canvas element with an optional transition effect.\n\n```ink\n# remove text <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("text"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("imagecontainer",u,n)},{name:"Remove imagecontainer",description:"Removes an image-container canvas element with an optional transition effect.\n\n```ink\n# remove imagecontainer <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s__default.default.tuple([s__default.default.literal("remove"),s__default.default.literal("imagecontainer"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"image",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit image",description:"Edits the properties of an image canvas element identified by its alias.\n\n```ink\n# edit image <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("image"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"imagecontainer",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit imagecontainer",description:"Edits the properties of an image-container canvas element identified by its alias.\n\n```ink\n# edit imagecontainer <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("imagecontainer"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"canvaselement",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit canvas element",description:"Edits the properties of a canvas element identified by its alias.\n\n```ink\n# edit canvaselement <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("canvaselement"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"video",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit video",description:"Edits the properties of a video canvas element identified by its alias.\n\n```ink\n# edit video <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("video"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"text",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit text",description:"Edits the properties of a text canvas element identified by its alias.\n\n```ink\n# edit text <alias> [<key> <value> \u2026]\n```",validation:s__default.default.tuple([s__default.default.literal("edit"),s__default.default.literal("text"),s__default.default.string()]).rest(s__default.default.string())});y.addMapper(e=>({type:"input",operationType:"request"}),{name:"Request input",description:"Requests player input without any additional constraints.\n\n```ink\n# request input\n```",validation:s__default.default.tuple([s__default.default.literal("request"),s__default.default.literal("input")])});y.addMapper(e=>{let u={type:"input",operationType:"request"};try{let n=y.convertListStringToObj(e.slice(2));"type"in n&&typeof n.type=="string"&&(u.valueType=n.type),"default"in n&&(u.defaultValue=n.default);}catch{}return u},{name:"Request input with params",description:"Requests player input with optional key/value parameters (e.g. type, default).\n\n```ink\n# request input <key> <value> [<key> <value> \u2026]\n# request input type number default 18\n```",validation:s__default.default.tuple([s__default.default.literal("request"),s__default.default.literal("input")]).rest(s__default.default.string()).refine(e=>e.length>2&&(e.length-2)%2===0)});var $e=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],ze=["+","-","/","*","%","POW","RANDOM","L^"],Ue=["INT","FLOOR","FLOAT"];function Z(e,u){if(e.endsWith(".s"))return;if(new RegExp(/.*\.[0-9]+\..*$/).test(e)&&(e=e.split(".").filter(o=>!o.match(/^[0-9]+$/)).join("."),!e.startsWith(".")))return e.replaceAll(".","_|_");if(!new RegExp(/^\.\^.*$/).test(e)&&e.includes("g-")){let i=e.split("g-");return ye(u)+"_|_"+"g-"+i[i.length-1]}let n=0;for(;new RegExp(/^\.\^.*$/).test(e);)n++,e=e.substring(2);if(n=n-1,new RegExp(/^\..*$/).test(e)&&u){let i=e.substring(1);return ye(u,n)+"_|_"+i.replaceAll(".","_|_")}return e.replaceAll(".","_|_")||ye(u,n).replaceAll(".","_|_")}function ye(e,u=0){let n=e.split("_|_");for(;n.length>1&&u>0;)n.pop()?.includes("g-")&&u--,u--;return n.join("_|_")}var qe="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function I(e){return e.startsWith("^")&&(e=e.substring(1)),e=e.replaceAll("\\\\",qe),e=e.replaceAll("\\n",`
22
- `),e=e.replaceAll("\\t"," "),e=e.replaceAll(" "," "),e=e.replaceAll(qe,"\\\\"),e}function U(e,u,n,i){let{functions:o}=i;e=e.map(a=>{if(typeof a=="string")switch(a){case "rnd":return "RANDOM";case "?":return "CONTAINS"}return a});let r=[];return e.forEach(a=>{if(typeof a=="string")switch(a){case "&&":case "||":if(r.length>=2){let l={type:"union",unionType:a==="&&"?"and":"or",conditions:[r[r.length-2],r[r.length-1]]};r.pop(),r.pop(),r.push(l);}break;case "!":if(r.length===0)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"union",unionType:"not",condition:r[r.length-1]};r[r.length-1]=l;}break;case "!?":if(r.length>1){let l={type:"union",unionType:"not",condition:{type:"compare",operator:"CONTAINS",leftValue:r[r.length-2],rightValue:r[r.length-1]}};r.pop(),r.pop(),r.push(l);}else O.error("Error parsing ink file: Conditional statement is not valid",e);break;default:if(pixiVnJson.PixiVNJsonComparationOperators.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"compare",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(ze.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {a==="L^"&&(a="INTERSECTION");let l={type:"arithmetic",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(Ue.includes(a)){let l={type:"arithmeticsingle",operator:a,leftValue:r[r.length-1]};r.pop(),r.push(l);}else a.startsWith("^")&&r.push(I(a));}else if(typeof a=="object"&&"CNT?"in a)if(new RegExp(/.*\.[0-9]\..*/).test(a["CNT?"])){let l=a["CNT?"].split("."),c=l.pop(),p=l.pop();if(p===void 0||c===void 0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let f=Number(p),C=l.join(".");if(C.includes("^.")){let E=C.split("."),m=E[E.length-1].replaceAll(".","_|_");E.pop(),C=`${E.join(".")}.${m}`,c.includes("c-")&&(C=C+"_|_"+c);}else C=C.replaceAll(".","_|_");let A=Z(C,u);if(!A)return;r.push({type:"compare",leftValue:me(A),operator:">=",rightValue:{type:"value",value:f}});}else {let l=Z(a["CNT?"],u);if(!l)return;r.push(me(l));}else if(typeof a=="object"&&"VAR?"in a)r.push(X({key:a["VAR?"],defaultType:"storage"},n));else if(typeof a=="object"&&"f()"in a){let l=a["f()"],c=o.find(f=>f.name===l);if(!c){O.error(`Error parsing ink file: Function ${l} is not defined`,e);return}let p=[];for(let f=0;f<c.args;f++)r.length!==0&&p.push(r.pop());r.push({type:"function",functionName:l,args:p.reverse()});}else if(typeof a=="object"&&"^->"in a)a["^->"].includes("$r")||r.push(a["^->"]);else if(typeof a=="object"&&"list"in a){let l=Object.values(a.list).map(c=>c);r.push(l);}else r.push(a);}),r}function Be(e,u,n,i){return U(e,u,n,i)}function X(e,u,n){let{key:i,defaultType:o}=e,r=u.indexOf(i);return r>=0?{type:"value",storageType:"params",storageOperationType:"get",key:r}:{type:"value",storageOperationType:"get",storageType:o,key:i}}function ie(e,u,n){let{key:i,value:o,defaultType:r,artmeticValue:a}=e,l=u.indexOf(i);if(l>=0)return [{type:"value",storageType:"params",storageOperationType:"set",key:l,value:o}];if(a){if(typeof o=="object"&&"list"in o){let c=Object.values(o.list).map(p=>p);return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:c}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}else if(typeof o=="object"){if("list"in o&&typeof o.list=="object"){if("origins"in o&&Array.isArray(o.origins)&&o.origins.length>0)return o.origins.reduce(c=>(c.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(n.enums[i])}),Object.entries(n.enums[i]).forEach(([p,f])=>{c.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${p}`,value:f});}),c),[]);{let c=new Set,p=Object.entries(o.list).reduce((f,[C,A])=>{let[E,m]=C.split(".");return f.push({type:"value",storageOperationType:"set",storageType:r,key:m,value:A}),c.add(E),f},[]);return c.forEach(f=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:f,value:Object.values(n.enums[f])});}),i in n.enums?Object.entries(n.enums[i]).forEach(([f,C])=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${f}`,value:C});}):p.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(o.list)}),p}}else if(typeof o=="object"&&"VAR?"in o){if(typeof o["VAR?"]=="string"&&o["VAR?"].includes(".")){let[c,p]=o["VAR?"].split(".");if(c in n.enums&&p in n.enums[c])return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:n.enums[c][p]}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:X({key:o["VAR?"],defaultType:"storage"},u)}]}}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}function me(e){return {type:"value",storageType:"label",storageOperationType:"get",label:e}}function Te(e,u){return u||new RegExp(`${"_|_".replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c-\\d+$`).test(e)?"call":"jump"}function le(e,u){if(u){if(typeof u=="string")u.startsWith("^")&&e.push(I(u));else if(typeof u=="object"&&"type"in u)switch(u.type){case "value":case "function":console.warn("Warning: trying to add a value or function operation as text. This is likely a mistake, so it will be ignored.");break;default:e.push(u);}}}function ve(e,u,n,i,o,r={}){let{isNewLine:a=true,isHashtagScript:l=false,isThreads:c=false}=r;return fu(e,u,n,i,o,{isNewLine:a,isHashtagScript:l,isThreads:c})}function fu(e,u,n,i,o,r){if(!u)return;let{isNewLine:a,isHashtagScript:l=false,isThreads:c}=r;if(l){if(Array.isArray(u)&&u.length>0){let p={goNextStep:true},f=[];try{if(u.length===1&&typeof u[0]=="string"&&!u[0].match(Ne)){let C=u[0],A=y.convertTagTolist(C),E=y.convertOperation(A,p);E&&(E.$origin=C,f.push(E));}}catch{}f.length===0&&f.push({type:"operationtoconvert",values:u}),e.push({...p,operations:f});}}else if(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"){if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&!p.labelToOpen&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}typeof u=="string"?e.push(du(I(u),i.characterIds)):e.push({dialogue:u});}else if(typeof u=="string"){if(u==="end")e.push({end:"game_end"});else if(u==="done")e.push({end:"label_end",goNextStep:true});else if(u==="<>")if(e.length>0){let p=e[e.length-1];p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true),e[e.length-1]=p;}else e.push({glueEnabled:true,goNextStep:false});}else if(typeof u=="object"){if("type"in u)switch(u.type){case "value":u.storageOperationType==="set"?(typeof u.value=="string"&&u.value.startsWith("^")&&(u.value=I(u.value)),e.push({goNextStep:true,operations:[u]})):console.warn("Warning: trying to add a value get operation as step. This is likely a mistake, so it will be ignored.");break;case "function":e.push({goNextStep:true,operations:[u]});break;default:if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}e.push({conditionalStep:u});}else if("->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let f=e[e.length-1];f.labelToOpen||(f.goNextStep=true),e[e.length-1]=f;}if(u.params&&u.params.length===0&&delete u.params,u.var)e.push({labelToOpen:{label:X({key:u["->"],defaultType:"storage"},o),type:c?"call":"jump",params:u.params},glueEnabled:p});else {let f=Z(u["->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:Te(f,c),params:u.params},glueEnabled:p});}}else if("->t->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let C=e[e.length-1];C.labelToOpen||(C.goNextStep=true),e[e.length-1]=C;}u.params&&u.params.length===0&&delete u.params;let f=Z(u["->t->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:"call",params:u.params},glueEnabled:p});}}}function du(e,u){let n;if(e.includes(": ")){let i=e.split(": "),o=i[0],r=i.slice(1).join(": ");(u?.has(o)||characters.RegisteredCharacters.has(o))&&(n=o,e=r);}return n?{dialogue:{character:n,text:e}}:{dialogue:e}}function xe(e,u,n,i=true,o=false){return Cu(e,u,n,i,o)}function Cu(e,u,n,i,o=false){u&&(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"?typeof u=="string"?e.push(I(u)):e.push(u):typeof u=="object"&&"type"in u&&e.push(u));}function De(e,u,n,i){if(e.length===0){O.error("Error parsing ink file: Arithmetic statement is not valid",e);return}let o=U(e,u,n,i);if(o.length===1){let r=o[0];return r&&typeof r=="object"&&"type"in r?{type:"value",storageType:"logic",storageOperationType:"get",operation:r}:r}}function K(e,u,n,i="",o,r,a=void 0){let l=[],c="sequential",p=false,f=true;e.forEach(E=>{E==="%"&&(c="loop"),E==="seq"&&(c="random"),E==="MIN"&&(p=true);});let C=e[e.length-1];return Object.keys(C).forEach(E=>{let m=C[E];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let F=[];q(m,i,o,F,u,u,n,ee,a,true,r),F.length===1?l.push(F[0]):l.push({type:"resulttocombine",combine:"cross",secondConditionalItem:F});}else Array.isArray(m)&&m.length===3&&(f=false);}),c==="sequential"?{type:"stepswitch",elements:l,choiceType:c,end:f?"lastItem":void 0,nestedId:a}:p&&c==="random"?{type:"stepswitch",elements:l,choiceType:"sequentialrandom",end:f?"lastItem":void 0,nestedId:a}:{type:"stepswitch",elements:l,choiceType:c}}function q(e,u,n,i=[],o,r,a,l,c=void 0,p=true,f=[]){let C=false,A=[],E=false,m=false,F=false,x=[],T=[];if(n.preDialog[u]&&(p=false,o(i,`^${n.preDialog[u].text}`,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),n.preDialog[u].glue&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),delete n.preDialog[u]),e.includes("visit")){let t=K(e,r,a,u,n,f,c);t&&(!p&&i.length>0&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}));return}let P=e[0];if(P&&typeof P=="object"&&"temp="in P){for(;e[0]&&typeof e[0]=="object"&&"temp="in e[0];)f.push(e[0]["temp="]),e.shift();f=f.reverse();}if(e.forEach((t,h)=>{if(m){if(typeof t=="string"&&t==="/#"){let d=[];q(T,u,n,d,xe,xe,a,l,c,p),o(i,d,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),m=false,T=[];}else T.push(t);return}else if(C)if(Array.isArray(t))A.push(t);else if(t&&typeof t=="object")"CNT?"in t?h>0&&e[h-1]==="ev"?(E=true,x.push(t)):E?x.push(t):(A.push(t),p=false):"VAR="in t||"temp="in t?ie({key:"VAR="in t?t["VAR="]:t["temp="],value:e[h-1],defaultType:"VAR="in t?"storage":"tempstorage"},f,n).forEach(g=>{if(g.value&&typeof g.value=="string"&&g.value==="/str"&&(g.value=e[h-2]),g.value&&typeof g.value=="object"&&"^->"in g.value&&(g.value=g.value["^->"]),A.length>1){let B=De(A,u,f,n);A=[],B&&typeof B=="object"&&"type"in B&&B.type==="value"&&"storageType"in B&&B.storageType==="logic"&&(g.value=B.operation);}(typeof g.key!="string"||!g.key.includes("$r"))&&(o(i,g,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=true);}):"VAR?"in t?A.push(t):"^->"in t?t["^->"].includes("$r")||A.push(t):("f()"in t||"list"in t&&typeof t.list=="object")&&A.push(t);else switch(t){case "/ev":E&&x.push(t),C=false,A.push(t);break;case "out":if(A.length>0){let d=A[A.length-1];if(d&&typeof d=="object"&&"VAR?"in d){A.pop();let g=X({key:d["VAR?"],defaultType:"storage"},f);o(i,g,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F});}else {let g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)g.push(A.pop());g=g.reverse();let B=De(g,u,f,n);A=[],B&&typeof B=="object"&&"type"in B&&B.type==="value"&&"storageType"in B&&B.storageType==="logic"?o(i,{storageOperationType:"get",storageType:"logic",operation:B.operation,type:"value"},u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}):(o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),B=`^${B}`,o(i,B,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}));}p=false;}break;case "pop":{let d=A[A.length-1];if(d&&typeof d=="object"&&"f()"in d){let g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)g.push(A.pop());g=g.reverse();let B=U(g,u,f,n);A=[],B.forEach(b=>{b&&typeof b=="object"&&"type"in b&&b.type==="function"?o(i,b,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}):O.warn("Unhandled case: value is not a function",b);}),p=false;}else A.push(t);return}default:A.push(t);}else if(typeof t=="string")if(t.startsWith("^"))o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="ev")C=true;else if(t===`
23
- `)p=true;else if(t==="done"||t==="end")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="<>")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="nop"&&E){let d=Ge(x,r,a,u,n,f,c);d&&o(i,d,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),E=false,x=[];}else t==="#"?m=true:t==="thread"&&(F=true);else if(Array.isArray(t))if(E)x.push(t);else if(t.length>1&&typeof t[t.length-2]=="object"&&t[t.length-2]&&"c"in t[t.length-2]&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"b"in t[t.length-1]){A.pop();let d=[],g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)d.push(A.pop());x=[...x,...d.reverse()],E=true,g.push(t.pop()),g.push(t.pop()),x=[...x,...t],x.push(g);}else if(t.length>1&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"#n"in t[t.length-1]){let d=t.pop();if(!d){O.error("Error parsing ink file: el is undefined");return}let g=d["#n"];delete d["#n"],t.push(d),o(i,{"->":u?u+"_|_"+g:g},u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),a({[g]:t},u,n);}else q(t,u,n,i,o,r,a,l,c,p,f);else if(t&&typeof t=="object")if("->"in t&&typeof t["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;}else if("->t->"in t&&typeof t["->t->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->t->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;}else if("*"in t&&typeof t["*"]=="string")t["*"].includes("c")&&(A.push(t),p=false);else if("s"in t&&Array.isArray(t.s))A.push(t),p=false;else if("CNT?"in t)A.push(t),p=false;else if("VAR="in t||"temp="in t){let d="VAR="in t?t["VAR="]:t["temp="],g,B=[];if(d!=="$r"){for(A.pop(),A[A.length-1]==="/ev"&&A.pop();A.length>0&&A[A.length-1]!=="/ev";)B.push(A.pop());B=B.reverse(),g=De(B,u,f,n),A=[],ie({key:d,value:g,defaultType:"VAR="in t?"storage":"tempstorage",artmeticValue:true},f,n).forEach(J=>{(J.value!==void 0||J.value!==null)&&o(i,J,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F});}),p=false;}}else a(t,u,n);}),l(A,i,u,n,f),u.includes("_|_")&&i.length===2){let t=i[0],h=i[1];t&&h&&typeof t=="object"&&"dialogue"in t&&typeof h=="object"&&"labelToOpen"in h&&t.dialogue===" "&&h.labelToOpen&&(i.shift(),delete h.glueEnabled,i[0]=h);}}function be(e,u,n,i,o,r){if(u.length===0)return;let a=U(u,i,n,o);if(a.length===1){let l={type:"ifelse",condition:a[0],then:e,else:r};return l.else||delete l.else,l}else if(a.length>1){let l={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:e,else:r};return l.else||delete l.else,l}}function Ge(e,u,n,i,o,r,a=void 0){if(e.length===0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let l=[],c=[];if(e.forEach(C=>{Array.isArray(C)?c.push(C):typeof C=="string"&&C==="du"?o.du?l.push(o.du):o.du=l[l.length-1]:(typeof C!="string"||C!=="/ev")&&l.push(C);}),c.length===0){O.error("Error parsing ink file: Conditional statement is not valid",c);return}let p=Se(c[0],u,n,`${i}${"_|_"}then`,o,r,`${a||""}then`),f;return c.length===2?f=Se(c[1],u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`):c.length>2?(c.shift(),c.push("nop"),c=[{b:c}],f=Se(c,u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`)):f=void 0,o.du=void 0,be(p,l,r,i,o,f)}function Se(e,u,n,i,o,r,a=void 0){let l=[];for(let p of e)typeof p=="object"&&"b"in p&&(p.b=p.b.filter(f=>f!==null&&!(typeof f=="object"&&"->"in f&&new RegExp(/.*\.[0-9]/).test(f["->"]))),q(p.b,i,o,l,u,u,n,ee,a,true,r));return l.length===1?l[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:l}}function Ve(e="",u=""){let n=Array.isArray(e)?e:[e],i=Array.isArray(u)?u:[u];return [...new Set([...n,...i])]}function ee(e,u,n,i,o){if(e.length>0){let r={};Ye(e,r,o,i);for(let[a,l]of Object.entries(r)){let c=n+"_|_"+a,p={text:l.text.length===1?l.text[0]:l.text,label:c,props:{},type:Te(c,false),oneTime:l.onetime};l.text.length===0&&(p.onlyHaveNoChoice=true,p.autoSelect=true),p.oneTime===false&&delete p.oneTime;let f=be(p,l.conditions,o,n,i)||p,C=u[u.length-1];if(typeof C=="object"&&C&&"type"in C&&(C={conditionalStep:C}),u.length>0&&typeof C=="object"&&C&&"choices"in C&&C.choices){let A=C.choices;A&&Array.isArray(A)?A.push(f):O.error("Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",l,A),C.choices=A.sort((E,m)=>{try{let F=E.label.split("."),x=F[F.length-1].replaceAll(".","_|_"),T=m.label.split("."),P=T[T.length-1].replaceAll(".","_|_");if(x.includes("c-")&&P.includes("c-")){let t=x.split("c-")[1],h=Number(t),d=P.split("c-")[1],g=Number(d);return h-g}}catch{}return 0});}else u.push({choices:[f]});l.preDialog&&(i.preDialog[c]={...l.preDialog});}}}function Ye(e,u,n,i,o){let r=[],a="",l="",c=false,p=[];for(let f=0;f<e.length;f++){let C=e[f];if(typeof C=="string")C.startsWith("^")?r.push(I(C)):$e.includes(C)&&p.push(C);else if(Array.isArray(C)&&C.includes("visit")){let A=K(C,le,(E,m,F)=>{},o,i,n);r.push(A);}else if(C&&typeof C=="object")if("*"in C&&typeof C["*"]&&typeof C["*"]=="string")C["*"].includes("c")&&(a=`c${C["*"].split("c")[1]}`,C.flg&16&&(c=true));else if("s"in C&&Array.isArray(C.s)){let A=Qe(C.s),E=C.s.includes("<>");A&&(o&&u[o]?(u[o].preDialog={text:A,glue:E},u[o].text=Ve(A,u[o].text)):(r.push(A),l=A));}else ("CNT?"in C||"VAR?"in C)&&p.push(C);else p.push(C);if(a){u[a]?u[a].text=Ve(r,u[a].text):u[a]={text:r,onetime:c,conditions:p},l&&(u[a].preDialog={text:l,glue:false});let A=e.slice(f+1);Ye(A,u,n,i,a);return}}}function Qe(e){for(let u of e)if(typeof u=="string"){if(u.startsWith("^"))return I(u)}else if(Array.isArray(u)){let n=Qe(u);if(n)return n}}exports.InkMapper=void 0;(o=>{function e(r,a={}){let{labelToRemove:l=[],initialVarsToRemove:c=[],enums:p={},functions:f=[],preDialog:C={},characterIds:A}=a,E={$schema:pixiVnJson.PIXIVNJSON_SCHEMA_URL};if(E.labels=u(r.root,{labelToRemove:l,initialVarsToRemove:c,enums:p,functions:f,preDialog:C,characterIds:A}),E.labels&&re in E.labels){let m=E.labels[re];delete E.labels[re],m.forEach(F=>{F.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...F.operations]:[...F.operations]);});}if(E.labels&&G in E.labels){let m=E.labels[G];delete E.labels[G],m.forEach(F=>{F.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...F.operations]:[...F.operations]);});}return l.forEach(m=>{E.labels&&m in E.labels&&delete E.labels[m];}),c.forEach(m=>{E.initialOperations&&(E.initialOperations=E.initialOperations.filter(F=>!(F.type==="value"&&F.key===m)));}),E}o.inkToJson=e;function u(r,a){try{let l={};return n(r,l,a),l}catch(l){O.error("Error parsing ink file",l);}}function n(r,a,l){for(let c of r)if(c)if(Array.isArray(c))if(c.includes("visit")){let p=K(c,le,(f,C,A)=>{},"",l,[]);p&&(l.externalSwitch=p);}else n(c,a,l);else typeof c=="object"&&(c&&"VAR="in c&&l.externalSwitch&&(a[G]||(a[G]=[]),a[G].push({operations:ie({defaultType:"storage",key:c["VAR="],value:l.externalSwitch},[],l)})),i(c,a,"",l));}function i(r,a,l="",c){if(r!==null){for(let[p,f]of Object.entries(r))if(Array.isArray(f)){let C=[],A={},E=(l?l+"_|_":"")+p;q(f,E,c,C,ve,ve,(m,F,x)=>{i(m,A,F,x);},ee);for(let[m,F]of Object.entries(A))a[m]=F;C.length>0&&(a[E]=C);}}}})(exports.InkMapper||={});
22
+ `),e=e.replaceAll("\\t"," "),e=e.replaceAll(" "," "),e=e.replaceAll(qe,"\\\\"),e}function U(e,u,n,i){let{functions:o}=i;e=e.map(a=>{if(typeof a=="string")switch(a){case "rnd":return "RANDOM";case "?":return "CONTAINS"}return a});let r=[];return e.forEach(a=>{if(typeof a=="string")switch(a){case "&&":case "||":if(r.length>=2){let l={type:"union",unionType:a==="&&"?"and":"or",conditions:[r[r.length-2],r[r.length-1]]};r.pop(),r.pop(),r.push(l);}break;case "!":if(r.length===0)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"union",unionType:"not",condition:r[r.length-1]};r[r.length-1]=l;}break;case "!?":if(r.length>1){let l={type:"union",unionType:"not",condition:{type:"compare",operator:"CONTAINS",leftValue:r[r.length-2],rightValue:r[r.length-1]}};r.pop(),r.pop(),r.push(l);}else O.error("Error parsing ink file: Conditional statement is not valid",e);break;default:if(pixiVnJson.PixiVNJsonComparationOperators.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"compare",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(ze.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {a==="L^"&&(a="INTERSECTION");let l={type:"arithmetic",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(Ue.includes(a)){let l={type:"arithmeticsingle",operator:a,leftValue:r[r.length-1]};r.pop(),r.push(l);}else a.startsWith("^")&&r.push(I(a));}else if(typeof a=="object"&&"CNT?"in a)if(new RegExp(/.*\.[0-9]\..*/).test(a["CNT?"])){let l=a["CNT?"].split("."),c=l.pop(),p=l.pop();if(p===void 0||c===void 0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let f=Number(p),C=l.join(".");if(C.includes("^.")){let E=C.split("."),B=E[E.length-1].replaceAll(".","_|_");E.pop(),C=`${E.join(".")}.${B}`,c.includes("c-")&&(C=C+"_|_"+c);}else C=C.replaceAll(".","_|_");let A=Z(C,u);if(!A)return;r.push({type:"compare",leftValue:me(A),operator:">=",rightValue:{type:"value",value:f}});}else {let l=Z(a["CNT?"],u);if(!l)return;r.push(me(l));}else if(typeof a=="object"&&"VAR?"in a)r.push(X({key:a["VAR?"],defaultType:"storage"},n));else if(typeof a=="object"&&"f()"in a){let l=a["f()"],c=o.find(f=>f.name===l);if(!c){O.error(`Error parsing ink file: Function ${l} is not defined`,e);return}let p=[];for(let f=0;f<c.args;f++)r.length!==0&&p.push(r.pop());r.push({type:"function",functionName:l,args:p.reverse()});}else if(typeof a=="object"&&"^->"in a)a["^->"].includes("$r")||r.push(a["^->"]);else if(typeof a=="object"&&"list"in a){let l=Object.values(a.list).map(c=>c);r.push(l);}else r.push(a);}),r}function Be(e,u,n,i){return U(e,u,n,i)}function X(e,u,n){let{key:i,defaultType:o}=e,r=u.indexOf(i);return r>=0?{type:"value",storageType:"params",storageOperationType:"get",key:r}:{type:"value",storageOperationType:"get",storageType:o,key:i}}function ie(e,u,n){let{key:i,value:o,defaultType:r,artmeticValue:a}=e,l=u.indexOf(i);if(l>=0)return [{type:"value",storageType:"params",storageOperationType:"set",key:l,value:o}];if(a){if(typeof o=="object"&&"list"in o){let c=Object.values(o.list).map(p=>p);return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:c}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}else if(typeof o=="object"){if("list"in o&&typeof o.list=="object"){if("origins"in o&&Array.isArray(o.origins)&&o.origins.length>0)return o.origins.reduce(c=>(c.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(n.enums[i])}),Object.entries(n.enums[i]).forEach(([p,f])=>{c.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${p}`,value:f});}),c),[]);{let c=new Set,p=Object.entries(o.list).reduce((f,[C,A])=>{let[E,B]=C.split(".");return f.push({type:"value",storageOperationType:"set",storageType:r,key:B,value:A}),c.add(E),f},[]);return c.forEach(f=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:f,value:Object.values(n.enums[f])});}),i in n.enums?Object.entries(n.enums[i]).forEach(([f,C])=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${f}`,value:C});}):p.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(o.list)}),p}}else if(typeof o=="object"&&"VAR?"in o){if(typeof o["VAR?"]=="string"&&o["VAR?"].includes(".")){let[c,p]=o["VAR?"].split(".");if(c in n.enums&&p in n.enums[c])return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:n.enums[c][p]}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:X({key:o["VAR?"],defaultType:"storage"},u)}]}}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}function me(e){return {type:"value",storageType:"label",storageOperationType:"get",label:e}}function Te(e,u){return u||new RegExp(`${"_|_".replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c-\\d+$`).test(e)?"call":"jump"}function le(e,u){if(u){if(typeof u=="string")u.startsWith("^")&&e.push(I(u));else if(typeof u=="object"&&"type"in u)switch(u.type){case "value":case "function":console.warn("Warning: trying to add a value or function operation as text. This is likely a mistake, so it will be ignored.");break;default:e.push(u);}}}function ve(e,u,n,i,o,r={}){let{isNewLine:a=true,isHashtagScript:l=false,isThreads:c=false}=r;return fu(e,u,n,i,o,{isNewLine:a,isHashtagScript:l,isThreads:c})}function fu(e,u,n,i,o,r){if(!u)return;let{isNewLine:a,isHashtagScript:l=false,isThreads:c}=r;if(l){if(Array.isArray(u)&&u.length>0){let p={goNextStep:true},f=[];try{if(u.length===1&&typeof u[0]=="string"&&!u[0].match(Ne)){let C=u[0],A=y.convertTagTolist(C),E=y.convertOperation(A,p,{silent:!0});E&&(E.$origin=C,f.push(E));}}catch{}f.length===0&&f.push({type:"operationtoconvert",values:u}),e.push({...p,operations:f});}}else if(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"){if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&!p.labelToOpen&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}typeof u=="string"?e.push(du(I(u),i.characterIds)):e.push({dialogue:u});}else if(typeof u=="string"){if(u==="end")e.push({end:"game_end"});else if(u==="done")e.push({end:"label_end",goNextStep:true});else if(u==="<>")if(e.length>0){let p=e[e.length-1];p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true),e[e.length-1]=p;}else e.push({glueEnabled:true,goNextStep:false});}else if(typeof u=="object"){if("type"in u)switch(u.type){case "value":u.storageOperationType==="set"?(typeof u.value=="string"&&u.value.startsWith("^")&&(u.value=I(u.value)),e.push({goNextStep:true,operations:[u]})):console.warn("Warning: trying to add a value get operation as step. This is likely a mistake, so it will be ignored.");break;case "function":e.push({goNextStep:true,operations:[u]});break;default:if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}e.push({conditionalStep:u});}else if("->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let f=e[e.length-1];f.labelToOpen||(f.goNextStep=true),e[e.length-1]=f;}if(u.params&&u.params.length===0&&delete u.params,u.var)e.push({labelToOpen:{label:X({key:u["->"],defaultType:"storage"},o),type:c?"call":"jump",params:u.params},glueEnabled:p});else {let f=Z(u["->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:Te(f,c),params:u.params},glueEnabled:p});}}else if("->t->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let C=e[e.length-1];C.labelToOpen||(C.goNextStep=true),e[e.length-1]=C;}u.params&&u.params.length===0&&delete u.params;let f=Z(u["->t->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:"call",params:u.params},glueEnabled:p});}}}function du(e,u){let n;if(e.includes(": ")){let i=e.split(": "),o=i[0],r=i.slice(1).join(": ");(u?.has(o)||characters.RegisteredCharacters.has(o))&&(n=o,e=r);}return n?{dialogue:{character:n,text:e}}:{dialogue:e}}function xe(e,u,n,i=true,o=false){return Cu(e,u,n,i,o)}function Cu(e,u,n,i,o=false){u&&(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"?typeof u=="string"?e.push(I(u)):e.push(u):typeof u=="object"&&"type"in u&&e.push(u));}function De(e,u,n,i){if(e.length===0){O.error("Error parsing ink file: Arithmetic statement is not valid",e);return}let o=U(e,u,n,i);if(o.length===1){let r=o[0];return r&&typeof r=="object"&&"type"in r?{type:"value",storageType:"logic",storageOperationType:"get",operation:r}:r}}function K(e,u,n,i="",o,r,a=void 0){let l=[],c="sequential",p=false,f=true;e.forEach(E=>{E==="%"&&(c="loop"),E==="seq"&&(c="random"),E==="MIN"&&(p=true);});let C=e[e.length-1];return Object.keys(C).forEach(E=>{let B=C[E];if(Array.isArray(B)&&B.length>3){B=B.slice(1,B.length-2);let g=[];q(B,i,o,g,u,u,n,ee,a,true,r),g.length===1?l.push(g[0]):l.push({type:"resulttocombine",combine:"cross",secondConditionalItem:g});}else Array.isArray(B)&&B.length===3&&(f=false);}),c==="sequential"?{type:"stepswitch",elements:l,choiceType:c,end:f?"lastItem":void 0,nestedId:a}:p&&c==="random"?{type:"stepswitch",elements:l,choiceType:"sequentialrandom",end:f?"lastItem":void 0,nestedId:a}:{type:"stepswitch",elements:l,choiceType:c}}function q(e,u,n,i=[],o,r,a,l,c=void 0,p=true,f=[]){let C=false,A=[],E=false,B=false,g=false,x=[],T=[];if(n.preDialog[u]&&(p=false,o(i,`^${n.preDialog[u].text}`,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),n.preDialog[u].glue&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),delete n.preDialog[u]),e.includes("visit")){let t=K(e,r,a,u,n,f,c);t&&(!p&&i.length>0&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}));return}let P=e[0];if(P&&typeof P=="object"&&"temp="in P){for(;e[0]&&typeof e[0]=="object"&&"temp="in e[0];)f.push(e[0]["temp="]),e.shift();f=f.reverse();}if(e.forEach((t,h)=>{if(B){if(typeof t=="string"&&t==="/#"){let d=[];q(T,u,n,d,xe,xe,a,l,c,p),o(i,d,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),B=false,T=[];}else T.push(t);return}else if(C)if(Array.isArray(t))A.push(t);else if(t&&typeof t=="object")"CNT?"in t?h>0&&e[h-1]==="ev"?(E=true,x.push(t)):E?x.push(t):(A.push(t),p=false):"VAR="in t||"temp="in t?ie({key:"VAR="in t?t["VAR="]:t["temp="],value:e[h-1],defaultType:"VAR="in t?"storage":"tempstorage"},f,n).forEach(F=>{if(F.value&&typeof F.value=="string"&&F.value==="/str"&&(F.value=e[h-2]),F.value&&typeof F.value=="object"&&"^->"in F.value&&(F.value=F.value["^->"]),A.length>1){let m=De(A,u,f,n);A=[],m&&typeof m=="object"&&"type"in m&&m.type==="value"&&"storageType"in m&&m.storageType==="logic"&&(F.value=m.operation);}(typeof F.key!="string"||!F.key.includes("$r"))&&(o(i,F,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=true);}):"VAR?"in t?A.push(t):"^->"in t?t["^->"].includes("$r")||A.push(t):("f()"in t||"list"in t&&typeof t.list=="object")&&A.push(t);else switch(t){case "/ev":E&&x.push(t),C=false,A.push(t);break;case "out":if(A.length>0){let d=A[A.length-1];if(d&&typeof d=="object"&&"VAR?"in d){A.pop();let F=X({key:d["VAR?"],defaultType:"storage"},f);o(i,F,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g});}else {let F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)F.push(A.pop());F=F.reverse();let m=De(F,u,f,n);A=[],m&&typeof m=="object"&&"type"in m&&m.type==="value"&&"storageType"in m&&m.storageType==="logic"?o(i,{storageOperationType:"get",storageType:"logic",operation:m.operation,type:"value"},u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}):(o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),m=`^${m}`,o(i,m,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}));}p=false;}break;case "pop":{let d=A[A.length-1];if(d&&typeof d=="object"&&"f()"in d){let F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)F.push(A.pop());F=F.reverse();let m=U(F,u,f,n);A=[],m.forEach(b=>{b&&typeof b=="object"&&"type"in b&&b.type==="function"?o(i,b,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}):O.warn("Unhandled case: value is not a function",b);}),p=false;}else A.push(t);return}default:A.push(t);}else if(typeof t=="string")if(t.startsWith("^"))o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="ev")C=true;else if(t===`
23
+ `)p=true;else if(t==="done"||t==="end")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="<>")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="nop"&&E){let d=Ge(x,r,a,u,n,f,c);d&&o(i,d,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),E=false,x=[];}else t==="#"?B=true:t==="thread"&&(g=true);else if(Array.isArray(t))if(E)x.push(t);else if(t.length>1&&typeof t[t.length-2]=="object"&&t[t.length-2]&&"c"in t[t.length-2]&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"b"in t[t.length-1]){A.pop();let d=[],F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)d.push(A.pop());x=[...x,...d.reverse()],E=true,F.push(t.pop()),F.push(t.pop()),x=[...x,...t],x.push(F);}else if(t.length>1&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"#n"in t[t.length-1]){let d=t.pop();if(!d){O.error("Error parsing ink file: el is undefined");return}let F=d["#n"];delete d["#n"],t.push(d),o(i,{"->":u?u+"_|_"+F:F},u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),a({[F]:t},u,n);}else q(t,u,n,i,o,r,a,l,c,p,f);else if(t&&typeof t=="object")if("->"in t&&typeof t["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;}else if("->t->"in t&&typeof t["->t->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->t->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;}else if("*"in t&&typeof t["*"]=="string")t["*"].includes("c")&&(A.push(t),p=false);else if("s"in t&&Array.isArray(t.s))A.push(t),p=false;else if("CNT?"in t)A.push(t),p=false;else if("VAR="in t||"temp="in t){let d="VAR="in t?t["VAR="]:t["temp="],F,m=[];if(d!=="$r"){for(A.pop(),A[A.length-1]==="/ev"&&A.pop();A.length>0&&A[A.length-1]!=="/ev";)m.push(A.pop());m=m.reverse(),F=De(m,u,f,n),A=[],ie({key:d,value:F,defaultType:"VAR="in t?"storage":"tempstorage",artmeticValue:true},f,n).forEach(J=>{(J.value!==void 0||J.value!==null)&&o(i,J,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g});}),p=false;}}else a(t,u,n);}),l(A,i,u,n,f),u.includes("_|_")&&i.length===2){let t=i[0],h=i[1];t&&h&&typeof t=="object"&&"dialogue"in t&&typeof h=="object"&&"labelToOpen"in h&&t.dialogue===" "&&h.labelToOpen&&(i.shift(),delete h.glueEnabled,i[0]=h);}}function be(e,u,n,i,o,r){if(u.length===0)return;let a=U(u,i,n,o);if(a.length===1){let l={type:"ifelse",condition:a[0],then:e,else:r};return l.else||delete l.else,l}else if(a.length>1){let l={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:e,else:r};return l.else||delete l.else,l}}function Ge(e,u,n,i,o,r,a=void 0){if(e.length===0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let l=[],c=[];if(e.forEach(C=>{Array.isArray(C)?c.push(C):typeof C=="string"&&C==="du"?o.du?l.push(o.du):o.du=l[l.length-1]:(typeof C!="string"||C!=="/ev")&&l.push(C);}),c.length===0){O.error("Error parsing ink file: Conditional statement is not valid",c);return}let p=Se(c[0],u,n,`${i}${"_|_"}then`,o,r,`${a||""}then`),f;return c.length===2?f=Se(c[1],u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`):c.length>2?(c.shift(),c.push("nop"),c=[{b:c}],f=Se(c,u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`)):f=void 0,o.du=void 0,be(p,l,r,i,o,f)}function Se(e,u,n,i,o,r,a=void 0){let l=[];for(let p of e)typeof p=="object"&&"b"in p&&(p.b=p.b.filter(f=>f!==null&&!(typeof f=="object"&&"->"in f&&new RegExp(/.*\.[0-9]/).test(f["->"]))),q(p.b,i,o,l,u,u,n,ee,a,true,r));return l.length===1?l[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:l}}function Ve(e="",u=""){let n=Array.isArray(e)?e:[e],i=Array.isArray(u)?u:[u];return [...new Set([...n,...i])]}function ee(e,u,n,i,o){if(e.length>0){let r={};Ye(e,r,o,i);for(let[a,l]of Object.entries(r)){let c=n+"_|_"+a,p={text:l.text.length===1?l.text[0]:l.text,label:c,props:{},type:Te(c,false),oneTime:l.onetime};l.text.length===0&&(p.onlyHaveNoChoice=true,p.autoSelect=true),p.oneTime===false&&delete p.oneTime;let f=be(p,l.conditions,o,n,i)||p,C=u[u.length-1];if(typeof C=="object"&&C&&"type"in C&&(C={conditionalStep:C}),u.length>0&&typeof C=="object"&&C&&"choices"in C&&C.choices){let A=C.choices;A&&Array.isArray(A)?A.push(f):O.error("Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",l,A),C.choices=A.sort((E,B)=>{try{let g=E.label.split("."),x=g[g.length-1].replaceAll(".","_|_"),T=B.label.split("."),P=T[T.length-1].replaceAll(".","_|_");if(x.includes("c-")&&P.includes("c-")){let t=x.split("c-")[1],h=Number(t),d=P.split("c-")[1],F=Number(d);return h-F}}catch{}return 0});}else u.push({choices:[f]});l.preDialog&&(i.preDialog[c]={...l.preDialog});}}}function Ye(e,u,n,i,o){let r=[],a="",l="",c=false,p=[];for(let f=0;f<e.length;f++){let C=e[f];if(typeof C=="string")C.startsWith("^")?r.push(I(C)):$e.includes(C)&&p.push(C);else if(Array.isArray(C)&&C.includes("visit")){let A=K(C,le,(E,B,g)=>{},o,i,n);r.push(A);}else if(C&&typeof C=="object")if("*"in C&&typeof C["*"]&&typeof C["*"]=="string")C["*"].includes("c")&&(a=`c${C["*"].split("c")[1]}`,C.flg&16&&(c=true));else if("s"in C&&Array.isArray(C.s)){let A=Qe(C.s),E=C.s.includes("<>");A&&(o&&u[o]?(u[o].preDialog={text:A,glue:E},u[o].text=Ve(A,u[o].text)):(r.push(A),l=A));}else ("CNT?"in C||"VAR?"in C)&&p.push(C);else p.push(C);if(a){u[a]?u[a].text=Ve(r,u[a].text):u[a]={text:r,onetime:c,conditions:p},l&&(u[a].preDialog={text:l,glue:false});let A=e.slice(f+1);Ye(A,u,n,i,a);return}}}function Qe(e){for(let u of e)if(typeof u=="string"){if(u.startsWith("^"))return I(u)}else if(Array.isArray(u)){let n=Qe(u);if(n)return n}}exports.InkMapper=void 0;(o=>{function e(r,a={}){let{labelToRemove:l=[],initialVarsToRemove:c=[],enums:p={},functions:f=[],preDialog:C={},characterIds:A}=a,E={$schema:pixiVnJson.PIXIVNJSON_SCHEMA_URL};if(E.labels=u(r.root,{labelToRemove:l,initialVarsToRemove:c,enums:p,functions:f,preDialog:C,characterIds:A}),E.labels&&re in E.labels){let B=E.labels[re];delete E.labels[re],B.forEach(g=>{g.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...g.operations]:[...g.operations]);});}if(E.labels&&G in E.labels){let B=E.labels[G];delete E.labels[G],B.forEach(g=>{g.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...g.operations]:[...g.operations]);});}return l.forEach(B=>{E.labels&&B in E.labels&&delete E.labels[B];}),c.forEach(B=>{E.initialOperations&&(E.initialOperations=E.initialOperations.filter(g=>!(g.type==="value"&&g.key===B)));}),E}o.inkToJson=e;function u(r,a){try{let l={};return n(r,l,a),l}catch(l){O.error("Error parsing ink file",l);}}function n(r,a,l){for(let c of r)if(c)if(Array.isArray(c))if(c.includes("visit")){let p=K(c,le,(f,C,A)=>{},"",l,[]);p&&(l.externalSwitch=p);}else n(c,a,l);else typeof c=="object"&&(c&&"VAR="in c&&l.externalSwitch&&(a[G]||(a[G]=[]),a[G].push({operations:ie({defaultType:"storage",key:c["VAR="],value:l.externalSwitch},[],l)})),i(c,a,"",l));}function i(r,a,l="",c){if(r!==null){for(let[p,f]of Object.entries(r))if(Array.isArray(f)){let C=[],A={},E=(l?l+"_|_":"")+p;q(f,E,c,C,ve,ve,(B,g,x)=>{i(B,A,g,x);},ee);for(let[B,g]of Object.entries(A))a[B]=g;C.length>0&&(a[E]=C);}}}})(exports.InkMapper||={});
package/dist/mapper.mjs CHANGED
@@ -5,13 +5,13 @@ import s,{ZodType}from'zod';import {PIXIVNJSON_SCHEMA_URL,PixiVNJsonComparationO
5
5
  `:case "\r":throw R(D());case "\u2028":case "\u2029":ru(V);break;case void 0:throw R(D())}v+=D();},start(){switch(V){case "{":case "[":return w("punctuator",D())}S="value";},beforePropertyName(){switch(V){case "$":case "_":v=D(),S="identifierName";return;case "\\":D(),S="identifierNameStartEscape";return;case "}":return w("punctuator",D());case '"':case "'":ue=D()==='"',S="string";return}if(k.isIdStartChar(V)){v+=D(),S="identifierName";return}throw R(D())},afterPropertyName(){if(V===":")return w("punctuator",D());throw R(D())},beforePropertyValue(){S="value";},afterPropertyValue(){switch(V){case ",":case "}":return w("punctuator",D())}throw R(D())},beforeArrayValue(){if(V==="]")return w("punctuator",D());S="value";},afterArrayValue(){switch(V){case ",":case "]":return w("punctuator",D())}throw R(D())},end(){throw R(D())}};function w(e,u){return {type:e,value:u,line:z,column:_}}function Y(e){for(let u of e){if($()!==u)throw R(D());D();}}function tu(){switch($()){case "b":return D(),"\b";case "f":return D(),"\f";case "n":return D(),`
6
6
  `;case "r":return D(),"\r";case "t":return D()," ";case "v":return D(),"\v";case "0":if(D(),k.isDigit($()))throw R(D());return "\0";case "x":return D(),nu();case "u":return D(),Ae();case `
7
7
  `:case "\u2028":case "\u2029":return D(),"";case "\r":return D(),$()===`
8
- `&&D(),"";case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":throw R(D());case void 0:throw R(D())}return D()}function nu(){let e="",u=$();if(!k.isHexDigit(u)||(e+=D(),u=$(),!k.isHexDigit(u)))throw R(D());return e+=D(),String.fromCodePoint(parseInt(e,16))}function Ae(){let e="",u=4;for(;u-- >0;){let n=$();if(!k.isHexDigit(n))throw R(D());e+=D();}return String.fromCodePoint(parseInt(e,16))}var iu={start(){if(M.type==="eof")throw Q();fe();},beforePropertyName(){switch(M.type){case "identifier":case "string":ge=M.value,L="afterPropertyName";return;case "punctuator":se();return;case "eof":throw Q()}},afterPropertyName(){if(M.type==="eof")throw Q();L="beforePropertyValue";},beforePropertyValue(){if(M.type==="eof")throw Q();fe();},beforeArrayValue(){if(M.type==="eof")throw Q();if(M.type==="punctuator"&&M.value==="]"){se();return}fe();},afterPropertyValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforePropertyName";return;case "}":se();}},afterArrayValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforeArrayValue";return;case "]":se();}},end(){}};function fe(){let e;switch(M.type){case "punctuator":switch(M.value){case "{":e={};break;case "[":e=[];break}break;case "null":case "boolean":case "numeric":case "string":e=M.value;break}if(te===void 0)te=e;else {let u=W[W.length-1];Array.isArray(u)?u.push(e):Object.defineProperty(u,ge,{value:e,writable:true,enumerable:true,configurable:true});}if(e!==null&&typeof e=="object")W.push(e),Array.isArray(e)?L="beforeArrayValue":L="beforePropertyName";else {let u=W[W.length-1];u==null?L="end":Array.isArray(u)?L="afterArrayValue":L="afterPropertyValue";}}function se(){W.pop();let e=W[W.length-1];e==null?L="end":Array.isArray(e)?L="afterArrayValue":L="afterPropertyValue";}function R(e){return ae(e===void 0?`JSON5: invalid end of input at ${z}:${_}`:`JSON5: invalid character '${ke(e)}' at ${z}:${_}`)}function Q(){return ae(`JSON5: invalid end of input at ${z}:${_}`)}function we(){return _-=5,ae(`JSON5: invalid identifier character at ${z}:${_}`)}function ru(e){console.warn(`JSON5: '${ke(e)}' in strings is not valid ECMAScript; consider escaping`);}function ke(e){let u={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(u[e])return u[e];if(e<" "){let n=e.charCodeAt(0).toString(16);return "\\x"+("00"+n).substring(n.length)}return e}function ae(e){let u=new SyntaxError(e);return u.lineNumber=z,u.columnNumber=_,u}var su=function(u,n,i){let o=[],r="",a,l,c="",p;if(n!=null&&typeof n=="object"&&!Array.isArray(n)&&(i=n.space,p=n.quote,n=n.replacer),typeof n=="function")l=n;else if(Array.isArray(n)){a=[];for(let F of n){let x;typeof F=="string"?x=F:(typeof F=="number"||F instanceof String||F instanceof Number)&&(x=String(F)),x!==void 0&&a.indexOf(x)<0&&a.push(x);}}return i instanceof Number?i=Number(i):i instanceof String&&(i=String(i)),typeof i=="number"?i>0&&(i=Math.min(10,Math.floor(i)),c=" ".substr(0,i)):typeof i=="string"&&(c=i.substr(0,10)),f("",{"":u});function f(F,x){let T=x[F];switch(T!=null&&(typeof T.toJSON5=="function"?T=T.toJSON5(F):typeof T.toJSON=="function"&&(T=T.toJSON(F))),l&&(T=l.call(x,F,T)),T instanceof Number?T=Number(T):T instanceof String?T=String(T):T instanceof Boolean&&(T=T.valueOf()),T){case null:return "null";case true:return "true";case false:return "false"}if(typeof T=="string")return C(T);if(typeof T=="number")return String(T);if(typeof T=="object")return Array.isArray(T)?m(T):A(T)}function C(F){let x={"'":.1,'"':.2},T={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"},P="";for(let h=0;h<F.length;h++){let d=F[h];switch(d){case "'":case '"':x[d]++,P+=d;continue;case "\0":if(k.isDigit(F[h+1])){P+="\\x00";continue}}if(T[d]){P+=T[d];continue}if(d<" "){let g=d.charCodeAt(0).toString(16);P+="\\x"+("00"+g).substring(g.length);continue}P+=d;}let t=p||Object.keys(x).reduce((h,d)=>x[h]<x[d]?h:d);return P=P.replace(new RegExp(t,"g"),T[t]),t+P+t}function A(F){if(o.indexOf(F)>=0)throw TypeError("Converting circular structure to JSON5");o.push(F);let x=r;r=r+c;let T=a||Object.keys(F),P=[];for(let h of T){let d=f(h,F);if(d!==void 0){let g=E(h)+":";c!==""&&(g+=" "),g+=d,P.push(g);}}let t;if(P.length===0)t="{}";else {let h;if(c==="")h=P.join(","),t="{"+h+"}";else {let d=`,
8
+ `&&D(),"";case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":throw R(D());case void 0:throw R(D())}return D()}function nu(){let e="",u=$();if(!k.isHexDigit(u)||(e+=D(),u=$(),!k.isHexDigit(u)))throw R(D());return e+=D(),String.fromCodePoint(parseInt(e,16))}function Ae(){let e="",u=4;for(;u-- >0;){let n=$();if(!k.isHexDigit(n))throw R(D());e+=D();}return String.fromCodePoint(parseInt(e,16))}var iu={start(){if(M.type==="eof")throw Q();fe();},beforePropertyName(){switch(M.type){case "identifier":case "string":ge=M.value,L="afterPropertyName";return;case "punctuator":se();return;case "eof":throw Q()}},afterPropertyName(){if(M.type==="eof")throw Q();L="beforePropertyValue";},beforePropertyValue(){if(M.type==="eof")throw Q();fe();},beforeArrayValue(){if(M.type==="eof")throw Q();if(M.type==="punctuator"&&M.value==="]"){se();return}fe();},afterPropertyValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforePropertyName";return;case "}":se();}},afterArrayValue(){if(M.type==="eof")throw Q();switch(M.value){case ",":L="beforeArrayValue";return;case "]":se();}},end(){}};function fe(){let e;switch(M.type){case "punctuator":switch(M.value){case "{":e={};break;case "[":e=[];break}break;case "null":case "boolean":case "numeric":case "string":e=M.value;break}if(te===void 0)te=e;else {let u=W[W.length-1];Array.isArray(u)?u.push(e):Object.defineProperty(u,ge,{value:e,writable:true,enumerable:true,configurable:true});}if(e!==null&&typeof e=="object")W.push(e),Array.isArray(e)?L="beforeArrayValue":L="beforePropertyName";else {let u=W[W.length-1];u==null?L="end":Array.isArray(u)?L="afterArrayValue":L="afterPropertyValue";}}function se(){W.pop();let e=W[W.length-1];e==null?L="end":Array.isArray(e)?L="afterArrayValue":L="afterPropertyValue";}function R(e){return ae(e===void 0?`JSON5: invalid end of input at ${z}:${_}`:`JSON5: invalid character '${ke(e)}' at ${z}:${_}`)}function Q(){return ae(`JSON5: invalid end of input at ${z}:${_}`)}function we(){return _-=5,ae(`JSON5: invalid identifier character at ${z}:${_}`)}function ru(e){console.warn(`JSON5: '${ke(e)}' in strings is not valid ECMAScript; consider escaping`);}function ke(e){let u={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(u[e])return u[e];if(e<" "){let n=e.charCodeAt(0).toString(16);return "\\x"+("00"+n).substring(n.length)}return e}function ae(e){let u=new SyntaxError(e);return u.lineNumber=z,u.columnNumber=_,u}var su=function(u,n,i){let o=[],r="",a,l,c="",p;if(n!=null&&typeof n=="object"&&!Array.isArray(n)&&(i=n.space,p=n.quote,n=n.replacer),typeof n=="function")l=n;else if(Array.isArray(n)){a=[];for(let g of n){let x;typeof g=="string"?x=g:(typeof g=="number"||g instanceof String||g instanceof Number)&&(x=String(g)),x!==void 0&&a.indexOf(x)<0&&a.push(x);}}return i instanceof Number?i=Number(i):i instanceof String&&(i=String(i)),typeof i=="number"?i>0&&(i=Math.min(10,Math.floor(i)),c=" ".substr(0,i)):typeof i=="string"&&(c=i.substr(0,10)),f("",{"":u});function f(g,x){let T=x[g];switch(T!=null&&(typeof T.toJSON5=="function"?T=T.toJSON5(g):typeof T.toJSON=="function"&&(T=T.toJSON(g))),l&&(T=l.call(x,g,T)),T instanceof Number?T=Number(T):T instanceof String?T=String(T):T instanceof Boolean&&(T=T.valueOf()),T){case null:return "null";case true:return "true";case false:return "false"}if(typeof T=="string")return C(T);if(typeof T=="number")return String(T);if(typeof T=="object")return Array.isArray(T)?B(T):A(T)}function C(g){let x={"'":.1,'"':.2},T={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"},P="";for(let h=0;h<g.length;h++){let d=g[h];switch(d){case "'":case '"':x[d]++,P+=d;continue;case "\0":if(k.isDigit(g[h+1])){P+="\\x00";continue}}if(T[d]){P+=T[d];continue}if(d<" "){let F=d.charCodeAt(0).toString(16);P+="\\x"+("00"+F).substring(F.length);continue}P+=d;}let t=p||Object.keys(x).reduce((h,d)=>x[h]<x[d]?h:d);return P=P.replace(new RegExp(t,"g"),T[t]),t+P+t}function A(g){if(o.indexOf(g)>=0)throw TypeError("Converting circular structure to JSON5");o.push(g);let x=r;r=r+c;let T=a||Object.keys(g),P=[];for(let h of T){let d=f(h,g);if(d!==void 0){let F=E(h)+":";c!==""&&(F+=" "),F+=d,P.push(F);}}let t;if(P.length===0)t="{}";else {let h;if(c==="")h=P.join(","),t="{"+h+"}";else {let d=`,
9
9
  `+r;h=P.join(d),t=`{
10
10
  `+r+h+`,
11
- `+x+"}";}}return o.pop(),r=x,t}function E(F){if(F.length===0)return C(F);let x=String.fromCodePoint(F.codePointAt(0));if(!k.isIdStartChar(x))return C(F);for(let T=x.length;T<F.length;T++)if(!k.isIdContinueChar(String.fromCodePoint(F.codePointAt(T))))return C(F);return F}function m(F){if(o.indexOf(F)>=0)throw TypeError("Converting circular structure to JSON5");o.push(F);let x=r;r=r+c;let T=[];for(let t=0;t<F.length;t++){let h=f(String(t),F);T.push(h!==void 0?h:"null");}let P;if(T.length===0)P="[]";else if(c==="")P="["+T.join(",")+"]";else {let t=`,
11
+ `+x+"}";}}return o.pop(),r=x,t}function E(g){if(g.length===0)return C(g);let x=String.fromCodePoint(g.codePointAt(0));if(!k.isIdStartChar(x))return C(g);for(let T=x.length;T<g.length;T++)if(!k.isIdContinueChar(String.fromCodePoint(g.codePointAt(T))))return C(g);return g}function B(g){if(o.indexOf(g)>=0)throw TypeError("Converting circular structure to JSON5");o.push(g);let x=r;r=r+c;let T=[];for(let t=0;t<g.length;t++){let h=f(String(t),g);T.push(h!==void 0?h:"null");}let P;if(T.length===0)P="[]";else if(c==="")P="["+T.join(",")+"]";else {let t=`,
12
12
  `+r,h=T.join(t);P=`[
13
13
  `+r+h+`,
14
- `+x+"]";}return o.pop(),r=x,P}},ou={parse:eu,stringify:su},au=ou,Fe=au;var Me="\xA7SPACE\xA7",Le="\xA7DOUBLE_QUOTES\xA7",_e="\xA7QUOTES\xA7",je="SPECIAL_\xA7QUOTES\xA7",Ie="\xA7CURLY_BRACKETS1\xA7",pu="\xA7INK_VAR\xA7",He="\xA7CURLY_BRACKETS2\xA7",y;(P=>{let e=[],u=[];async function n(t,h){for(let d=0;d<e.length;d++)try{let{validation:g}=e[d].opts;if(g instanceof RegExp){if(!g.test(t.join(" ")))continue}else if(g instanceof ZodType&&!g.safeParse(t).success)continue;let B=await e[d].fn(t,h,C);if(B===!0||typeof B=="string")return B}catch{}return false}function i(t,h={name:"custom-command",validation:/^/}){e.unshift({fn:t,opts:h});}P.add=i;function o(){return [...u.map(t=>t.opts),...e.map(t=>t.opts)]}P.info=o;function r(t,h){u.unshift({fn:t,opts:h});}P.addMapper=r;function a(){e.length=0;}P.clear=a;function l(){u.length=0;}P.clearMappers=l;async function c(t,h,d){try{let g=p(t),B=await n(g,d);return B===!0?void 0:typeof B=="string"?(B.startsWith("#")&&(B=B.substring(1)),await P.run(B,h,d)):f(g,h)}catch(g){throw O.error("Error parsing ink hashtag-command",t),g}}P.run=c;function p(t,h){if(t=t.replaceAll('\\"',Le),t=t.replaceAll("\\'",_e),t=t.replaceAll("\\`",je),t=t.replaceAll("\\{",Ie),t=t.replaceAll("\\}",He),h?.mergeInkVariables){let b;do b=t,t=t.replace(/\{[^{}:]*\}/g,pu);while(t!==b)}t=t.replaceAll("{"," { "),t=t.replaceAll("}"," } "),t=t.replaceAll(Ie,"{"),t=t.replaceAll(He,"}");let d=[],g,B="";for(let b=0;b<t.length;b++){let J=t[b];J==='"'||J==="'"||J==="`"?g===void 0?(d.push(B),B="",g=J,B+=J):g===J?(g=void 0,B+=J,d.push(B),B=""):B+=J:B+=J;}return B!==""&&d.push(B),d.forEach((b,J)=>{J%2===1&&(d[J]=b.replaceAll(" ",Me));}),t=d.join(""),d=t.split(" ").filter(b=>b!==""),d=d.map(b=>b.replaceAll(Me," ").replaceAll(Le,'"').replaceAll(_e,"'").replaceAll(je,"`")),d=F(d),d=d.map(b=>b.startsWith('"')&&b.endsWith('"')||b.startsWith("'")&&b.endsWith("'")||b.startsWith("`")&&b.endsWith("`")?b.slice(1,-1):b),d}P.convertTagTolist=p;function f(t,h){for(let d of u){let{validation:g}=d.opts,B=false;if(g instanceof RegExp?B=g.test(t.join(" ")):g instanceof ZodType&&(B=g.safeParse(t).success),B)return d.fn(t,h)}O.error("The operation is not valid",t);}P.convertOperation=f;function C(t){return A(t)}P.convertListStringToObj=C;function A(t){if(t.length===0)return {};if(t.length%2!==0)throw O.error("The props list must have a pair number of elements",t),new Error("The props list must have a pair number of elements");let h="{";t.forEach((d,g)=>{if(g%2===0)h+=`"${d}": `;else {switch(d){case "null":case "undefined":case "true":case "false":h+=`${d}`;break;default:m(d)?(d=E(d),h+=`"${d}"`):d.startsWith("{")&&d.endsWith("}")?h+=`${d}`:d.startsWith('"')&&d.endsWith('"')?h+=`${d}`:Number.isNaN(parseFloat(d))?h+=`"${d}"`:h+=`${d}`;}g<t.length-1&&(h+=", ");}}),h+="}";try{return Fe.parse(h)}catch(d){throw O.error("Error parsing ink json",h),d}}function E(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`")?t.substring(1,t.length-1):t}function m(t){return !!(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`"))}function F(t){return x(t).tokens}P.mergeJsonBlocks=F;function x(t){let h=[],d=false;for(let g=0;g<t.length;g++){let B=t[g];if(B!=="{"){h.push(B);continue}let b=T(t,g);if(b===-1){h.push(B);continue}let J=x(t.slice(g+1,b)),Pe=["{",...J.tokens,"}"],Oe=Pe.join(" ");if(!J.hasInvalidMatchedBlock)try{Fe.parse(Oe),h.push(Oe),g=b;continue}catch{}d=true,h.push(...Pe),g=b;}return {tokens:h,hasInvalidMatchedBlock:d}}function T(t,h){let d=0;for(let g=h;g<t.length;g++)if(t[g]==="{")d++;else if(t[g]==="}"&&(d--,d===0))return g;return -1}})(y||={});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"call"},u.goNextStep=void 0;},{name:"Call",description:"Calls the label specified by the second token, then returns to the current position.\n\n```ink\n# call label_name\n```",validation:s.tuple([s.literal("call"),s.string()])});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"jump"},u.goNextStep=void 0;},{name:"Jump",description:"Jumps to the label specified by the second token without returning.\n\n```ink\n# jump label_name\n```",validation:s.tuple([s.literal("jump"),s.string()])});y.addMapper((e,u)=>("dialogue"in u&&delete u.dialogue,"goNextStep"in u&&delete u.goNextStep,{type:"dialogue",operationType:"clean"}),{name:"Pause",description:"Clears the current dialogue and waits for user input before advancing.\n\n```ink\n# pause\n```",validation:s.tuple([s.literal("pause")])});y.addMapper((e,u)=>{u.goNextStep=true,u.glueEnabled=false;},{name:"Continue",description:"Forces the story to proceed to the next step automatically.\n\n```ink\n# continue\n```",validation:s.tuple([s.literal("continue")])});y.addMapper(e=>({type:"video",operationType:e[0],alias:e[2]}),{name:"Pause/Resume video",description:"Pauses or resumes a video canvas element identified by its alias.\n\n```ink\n# pause video <alias>\n# resume video <alias>\n```",validation:s.tuple([s.enum(["pause","resume"]),s.literal("video"),s.string()])});y.addMapper(e=>({type:e[1],operationType:e[0],aliases:e.slice(2)}),{name:"Load assets/bundle",description:`Loads (eagerly or lazily) a set of asset or bundle aliases.
14
+ `+x+"]";}return o.pop(),r=x,P}},ou={parse:eu,stringify:su},au=ou,Fe=au;var Me="\xA7SPACE\xA7",Le="\xA7DOUBLE_QUOTES\xA7",_e="\xA7QUOTES\xA7",je="SPECIAL_\xA7QUOTES\xA7",Ie="\xA7CURLY_BRACKETS1\xA7",pu="\xA7INK_VAR\xA7",He="\xA7CURLY_BRACKETS2\xA7",y;(P=>{let e=[],u=[];async function n(t,h){for(let d=0;d<e.length;d++)try{let{validation:F}=e[d].opts;if(F instanceof RegExp){if(!F.test(t.join(" ")))continue}else if(F instanceof ZodType&&!F.safeParse(t).success)continue;let m=await e[d].fn(t,h,C);if(m===!0||typeof m=="string")return m}catch{}return false}function i(t,h={name:"custom-command",validation:/^/}){e.unshift({fn:t,opts:h});}P.add=i;function o(){return [...u.map(t=>t.opts),...e.map(t=>t.opts)]}P.info=o;function r(t,h){u.unshift({fn:t,opts:h});}P.addMapper=r;function a(){e.length=0;}P.clear=a;function l(){u.length=0;}P.clearMappers=l;async function c(t,h,d){try{let F=p(t),m=await n(F,d);return m===!0?void 0:typeof m=="string"?(m.startsWith("#")&&(m=m.substring(1)),await P.run(m,h,d)):f(F,h)}catch(F){throw O.error("Error parsing ink hashtag-command",t),F}}P.run=c;function p(t,h){if(t=t.replaceAll('\\"',Le),t=t.replaceAll("\\'",_e),t=t.replaceAll("\\`",je),t=t.replaceAll("\\{",Ie),t=t.replaceAll("\\}",He),h?.mergeInkVariables){let b;do b=t,t=t.replace(/\{[^{}:]*\}/g,pu);while(t!==b)}t=t.replaceAll("{"," { "),t=t.replaceAll("}"," } "),t=t.replaceAll(Ie,"{"),t=t.replaceAll(He,"}");let d=[],F,m="";for(let b=0;b<t.length;b++){let J=t[b];J==='"'||J==="'"||J==="`"?F===void 0?(d.push(m),m="",F=J,m+=J):F===J?(F=void 0,m+=J,d.push(m),m=""):m+=J:m+=J;}return m!==""&&d.push(m),d.forEach((b,J)=>{J%2===1&&(d[J]=b.replaceAll(" ",Me));}),t=d.join(""),d=t.split(" ").filter(b=>b!==""),d=d.map(b=>b.replaceAll(Me," ").replaceAll(Le,'"').replaceAll(_e,"'").replaceAll(je,"`")),d=g(d),d=d.map(b=>b.startsWith('"')&&b.endsWith('"')||b.startsWith("'")&&b.endsWith("'")||b.startsWith("`")&&b.endsWith("`")?b.slice(1,-1):b),d}P.convertTagTolist=p;function f(t,h,d){for(let F of u){let{validation:m}=F.opts,b=false;if(m instanceof RegExp?b=m.test(t.join(" ")):m instanceof ZodType&&(b=m.safeParse(t).success),b)return F.fn(t,h)}d?.silent||O.error("The operation is not valid",t);}P.convertOperation=f;function C(t){return A(t)}P.convertListStringToObj=C;function A(t){if(t.length===0)return {};if(t.length%2!==0)throw O.error("The props list must have a pair number of elements",t),new Error("The props list must have a pair number of elements");let h="{";t.forEach((d,F)=>{if(F%2===0)h+=`"${d}": `;else {switch(d){case "null":case "undefined":case "true":case "false":h+=`${d}`;break;default:B(d)?(d=E(d),h+=`"${d}"`):d.startsWith("{")&&d.endsWith("}")?h+=`${d}`:d.startsWith('"')&&d.endsWith('"')?h+=`${d}`:Number.isNaN(parseFloat(d))?h+=`"${d}"`:h+=`${d}`;}F<t.length-1&&(h+=", ");}}),h+="}";try{return Fe.parse(h)}catch(d){throw O.error("Error parsing ink json",h),d}}function E(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`")?t.substring(1,t.length-1):t}function B(t){return !!(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")||t.startsWith("`")&&t.endsWith("`"))}function g(t){return x(t).tokens}P.mergeJsonBlocks=g;function x(t){let h=[],d=false;for(let F=0;F<t.length;F++){let m=t[F];if(m!=="{"){h.push(m);continue}let b=T(t,F);if(b===-1){h.push(m);continue}let J=x(t.slice(F+1,b)),Pe=["{",...J.tokens,"}"],Oe=Pe.join(" ");if(!J.hasInvalidMatchedBlock)try{Fe.parse(Oe),h.push(Oe),F=b;continue}catch{}d=true,h.push(...Pe),F=b;}return {tokens:h,hasInvalidMatchedBlock:d}}function T(t,h){let d=0;for(let F=h;F<t.length;F++)if(t[F]==="{")d++;else if(t[F]==="}"&&(d--,d===0))return F;return -1}})(y||={});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"call"},u.goNextStep=void 0;},{name:"Call",description:"Calls the label specified by the second token, then returns to the current position.\n\n```ink\n# call label_name\n```",validation:s.tuple([s.literal("call"),s.string()])});y.addMapper((e,u)=>{u.labelToOpen={label:e[1],type:"jump"},u.goNextStep=void 0;},{name:"Jump",description:"Jumps to the label specified by the second token without returning.\n\n```ink\n# jump label_name\n```",validation:s.tuple([s.literal("jump"),s.string()])});y.addMapper((e,u)=>("dialogue"in u&&delete u.dialogue,"goNextStep"in u&&delete u.goNextStep,{type:"dialogue",operationType:"clean"}),{name:"Pause",description:"Clears the current dialogue and waits for user input before advancing.\n\n```ink\n# pause\n```",validation:s.tuple([s.literal("pause")])});y.addMapper((e,u)=>{u.goNextStep=true,u.glueEnabled=false;},{name:"Continue",description:"Forces the story to proceed to the next step automatically.\n\n```ink\n# continue\n```",validation:s.tuple([s.literal("continue")])});y.addMapper(e=>({type:"video",operationType:e[0],alias:e[2]}),{name:"Pause/Resume video",description:"Pauses or resumes a video canvas element identified by its alias.\n\n```ink\n# pause video <alias>\n# resume video <alias>\n```",validation:s.tuple([s.enum(["pause","resume"]),s.literal("video"),s.string()])});y.addMapper(e=>({type:e[1],operationType:e[0],aliases:e.slice(2)}),{name:"Load assets/bundle",description:`Loads (eagerly or lazily) a set of asset or bundle aliases.
15
15
 
16
16
  \`\`\`ink
17
17
  # load assets <alias...>
@@ -19,5 +19,5 @@ import s,{ZodType}from'zod';import {PIXIVNJSON_SCHEMA_URL,PixiVNJsonComparationO
19
19
  # load bundle <alias...>
20
20
  # lazyload bundle <alias...>
21
21
  \`\`\``,validation:s.tuple([s.enum(["load","lazyload"]),s.enum(["assets","bundle"])]).rest(s.string())});y.addMapper(e=>({type:"all",operationType:e[0]}),{name:"Pause/Resume/Stop all sounds",description:"Pauses, resumes, or stops all active sounds at once.\n\n```ink\n# pause all sounds\n# resume all sounds\n# stop all sounds\n```",validation:s.tuple([s.enum(["pause","resume","stop"]),s.literal("all"),s.enum(["sounds","sound"])])});y.addMapper(e=>({type:"sound",operationType:"pause",alias:e[2]}),{name:"Pause sound",description:"Pauses the sound identified by its alias.\n\n```ink\n# pause sound <alias>\n```",validation:s.tuple([s.literal("pause"),s.literal("sound"),s.string()])});y.addMapper(e=>({type:"channel",operationType:"pause",alias:e[2]}),{name:"Pause channel",description:"Pauses the audio channel identified by its alias.\n\n```ink\n# pause channel <alias>\n```",validation:s.tuple([s.literal("pause"),s.literal("channel"),s.string()])});y.addMapper(e=>({type:"sound",operationType:"resume",alias:e[2]}),{name:"Resume sound",description:"Resumes the sound identified by its alias.\n\n```ink\n# resume sound <alias>\n```",validation:s.tuple([s.literal("resume"),s.literal("sound"),s.string()])});y.addMapper(e=>({type:"channel",operationType:"resume",alias:e[2]}),{name:"Resume channel",description:"Resumes the audio channel identified by its alias.\n\n```ink\n# resume channel <alias>\n```",validation:s.tuple([s.literal("resume"),s.literal("channel"),s.string()])});y.addMapper(e=>({type:"sound",operationType:"stop",alias:e[2]}),{name:"Stop sound",description:"Stops the sound identified by its alias.\n\n```ink\n# stop sound <alias>\n```",validation:s.tuple([s.literal("stop"),s.literal("sound"),s.string()])});y.addMapper(e=>({type:"sound",operationType:"stop",alias:e[2]}),{name:"Remove sound",description:"Removes (stops) the sound identified by its alias.\n\n```ink\n# remove sound <alias>\n```",deprecated:true,validation:s.tuple([s.literal("remove"),s.literal("sound"),s.string()])});y.addMapper(e=>({type:"sound",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit sound",description:"Edits the properties of a sound identified by its alias.\n\n```ink\n# edit sound <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("sound"),s.string()]).rest(s.string()).refine(e=>(e.length-3)%2===0)});y.addMapper(e=>{let u=e[2],n={type:"sound",operationType:"play",alias:u,url:u};return e.length>3&&(n.props=y.convertListStringToObj(e.slice(3))),n},{name:"Play sound",description:"Plays a sound using its alias as the URL, with optional key/value properties.\n\n```ink\n# play sound <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("play"),s.literal("sound"),s.string()]).rest(s.string()).refine(e=>(e.length-3)%2===0)});y.addMapper(e=>{let u=e[2],n=e[3],i={type:"sound",operationType:"play",alias:u,url:n};return e.length>4&&(i.props=y.convertListStringToObj(e.slice(4))),i},{name:"Play sound with source",description:"Plays a sound with an explicit source URL and optional key/value properties.\n \n```ink\n# play sound <alias> <source> [<key> <value> \u2026]\n```\n",validation:s.tuple([s.literal("play"),s.literal("sound"),s.string()]).rest(s.string()).refine(e=>e.length>3&&(e.length-3)%2!==0)});function j(e){let u=[],n=0,i="";for(let o of e)o.startsWith("{")?(n++,i+=o):o.endsWith("}")&&n>0?(n--,i+=o,n===0&&(u.push(i),i="")):n>0?i+=o:u.push(o);return u}function pe(e,u){switch(e){case "dissolve":case "fade":case "movein":case "moveout":case "zoomin":case "zoomout":case "pushin":case "pushout":break;default:return}let n={type:e};if(u.length>0)try{n.props=y.convertListStringToObj(u);}catch{}return n}function We(e,u,n){let i,o;n.length%2===0?(i=u,o=n):(i=n[0],o=n.slice(1));let r={type:e,operationType:"show",alias:u,url:i};if(o.length>0){if(o.includes("with")&&o.length>o.indexOf("with")+1){let a=o[o.indexOf("with")+1],l=o.slice(o.indexOf("with")+2);o=o.slice(0,o.indexOf("with"));let c=pe(a,l);c!==void 0&&(r.transition=c);}o.length>0&&(r.props=y.convertListStringToObj(o));}return r}function lu(e,u){let n,i;u.length%2===0?(n=e,i=u):(n=u[0],i=u.slice(1));let o={type:"text",operationType:"show",alias:e,text:n};if(i.length>0){if(i.includes("with")&&i.length>i.indexOf("with")+1){let r=i[i.indexOf("with")+1],a=i.slice(i.indexOf("with")+2);i=i.slice(0,i.indexOf("with"));let l=pe(r,a);l!==void 0&&(o.transition=l);}i.length>0&&(o.props=y.convertListStringToObj(i));}return o}function ne(e,u,n){let i={type:e,operationType:"remove",alias:u};if(n.includes("with")&&n.length>n.indexOf("with")+1){let o=n[n.indexOf("with")+1],r=n.slice(n.indexOf("with")+2),a=pe(o,r);a!==void 0&&(i.transition=a);}return i}function he(e,u){let n=c=>c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")||c.startsWith("`")&&c.endsWith("`")?c.substring(1,c.length-1):c,i=[],o=u.findIndex(c=>c.startsWith("[")),r=u.findIndex(c=>c.endsWith("]"));if(o===-1||r===-1){O.error("Show imagecontainer must have a list of image ulrs",u);return}if(i=u.slice(o,r+1),i.length<2){O.error("Show imagecontainer must have a list of image ulrs",u);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let a={type:"imagecontainer",operationType:"show",alias:e,urls:i.map(c=>n(c))},l=u.slice(r+1);if(l.length>0){if(l.includes("with")&&l.length>l.indexOf("with")+1){let c=l[l.indexOf("with")+1],p=l.slice(l.indexOf("with")+2);l=l.slice(0,l.indexOf("with"));let f=pe(c,p);f!==void 0&&(a.transition=f);}l.length>0&&(a.props=y.convertListStringToObj(l));}return a}function Ee(e){let u=e.slice(3),n=u.findIndex(a=>a.startsWith("[")),i=u.findIndex(a=>a.endsWith("]"));if(n===-1||i===-1||i<n)return;let o=u.slice(i+1),r=o.indexOf("with");return r===-1?{beforeWith:o,afterWith:[]}:{beforeWith:o.slice(0,r),afterWith:o.slice(r+1)}}y.addMapper(e=>({alias:e[1],type:"shake",props:y.convertListStringToObj(e.slice(2))}),{name:"Shake",description:"Applies shake effect to a canvas alias with optional key/value parameters.\n\n```ink\n# shake <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("shake"),s.string()]).rest(s.string()).refine(e=>(e.length-2)%2===0)});y.addMapper(e=>{let u=e.slice(2),n=u,i=[];if(u.includes("options")){let r=u.indexOf("options");n=u.slice(0,r),i=u.slice(r+1);}return {alias:e[1],type:"animate",keyframes:y.convertListStringToObj(n),options:y.convertListStringToObj(i)}},{name:"Animate",description:"Animates a canvas alias with keyframes and optional options section, both in key/value pairs.\n\n```ink\n# animate <alias> [<key> <value> \u2026] [options <key> <value> \u2026]\n```",validation:s.tuple([s.literal("animate"),s.string()]).rest(s.string()).refine(e=>{let u=e.slice(2),n=u.indexOf("options");if(n===-1)return u.length%2===0;if(u.lastIndexOf("options")!==n)return false;let i=u.slice(0,n),o=u.slice(n+1);return i.length%2===0&&o.length%2===0})});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return We("image",u,n)},{name:"Show image",description:"Shows an image canvas element with optional source URL, key/value properties, and transition effect.\n\n```ink\n# show image <alias> [<source>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("show"),s.literal("image"),s.string()]).rest(s.string())});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer",description:"Shows an image-container canvas element with a list of image URLs and optional key/value properties.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("show"),s.literal("imagecontainer"),s.string()]).rest(s.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length===0&&u.beforeWith.length%2===0})});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer with transition",description:"Shows an image-container canvas element with a list of image URLs, optional properties, and a transition effect.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026] with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout\n```",validation:s.tuple([s.literal("show"),s.literal("imagecontainer"),s.string()]).rest(s.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length===1&&u.beforeWith.length%2===0})});y.addMapper(e=>he(e[2],j(e.slice(3))),{name:"Show imagecontainer with transition and props",description:"Shows an image-container canvas element with a list of image URLs, optional properties, a transition effect, and transition key/value properties.\n\n```ink\n# show imagecontainer <alias> [ <url1> <url2> \u2026 ] [<key> <value> \u2026] with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout <key> <value> \u2026\n```",validation:s.tuple([s.literal("show"),s.literal("imagecontainer"),s.string()]).rest(s.string()).refine(e=>{let u=Ee(e);return u===void 0?false:u.afterWith.length>1&&(u.afterWith.length-1)%2===0&&u.beforeWith.length%2===0})});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return We("video",u,n)},{name:"Show video",description:"Shows a video canvas element with optional source URL, key/value properties, and transition effect.\n\n```ink\n# show video <alias> [<source>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("show"),s.literal("video"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2];return lu(u,e.slice(3))},{name:"Show text",description:"Shows a text canvas element with optional text content, key/value properties, and transition effect.\n\n```ink\n# show text <alias> [<text>] [<key> <value> \u2026] [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("show"),s.literal("text"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("image",u,n)},{name:"Remove image",description:"Removes an image canvas element with an optional transition effect.\n\n```ink\n# remove image <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("remove"),s.literal("image"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("video",u,n)},{name:"Remove video",description:"Removes a video canvas element with an optional transition effect.\n\n```ink\n# remove video <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("remove"),s.literal("video"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("canvaselement",u,n)},{name:"Remove canvas element",description:"Removes a canvas element with an optional transition effect.\n\n```ink\n# remove canvaselement <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("remove"),s.literal("canvaselement"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("text",u,n)},{name:"Remove text",description:"Removes a text canvas element with an optional transition effect.\n\n```ink\n# remove text <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("remove"),s.literal("text"),s.string()]).rest(s.string())});y.addMapper(e=>{let u=e[2],n=j(e.slice(3));return ne("imagecontainer",u,n)},{name:"Remove imagecontainer",description:"Removes an image-container canvas element with an optional transition effect.\n\n```ink\n# remove imagecontainer <alias> [with dissolve|fade|movein|moveout|zoomin|zoomout|pushin|pushout [<key> <value> \u2026]]\n```",validation:s.tuple([s.literal("remove"),s.literal("imagecontainer"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"image",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit image",description:"Edits the properties of an image canvas element identified by its alias.\n\n```ink\n# edit image <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("image"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"imagecontainer",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit imagecontainer",description:"Edits the properties of an image-container canvas element identified by its alias.\n\n```ink\n# edit imagecontainer <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("imagecontainer"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"canvaselement",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit canvas element",description:"Edits the properties of a canvas element identified by its alias.\n\n```ink\n# edit canvaselement <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("canvaselement"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"video",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit video",description:"Edits the properties of a video canvas element identified by its alias.\n\n```ink\n# edit video <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("video"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"text",operationType:"edit",alias:e[2],props:y.convertListStringToObj(e.slice(3))}),{name:"Edit text",description:"Edits the properties of a text canvas element identified by its alias.\n\n```ink\n# edit text <alias> [<key> <value> \u2026]\n```",validation:s.tuple([s.literal("edit"),s.literal("text"),s.string()]).rest(s.string())});y.addMapper(e=>({type:"input",operationType:"request"}),{name:"Request input",description:"Requests player input without any additional constraints.\n\n```ink\n# request input\n```",validation:s.tuple([s.literal("request"),s.literal("input")])});y.addMapper(e=>{let u={type:"input",operationType:"request"};try{let n=y.convertListStringToObj(e.slice(2));"type"in n&&typeof n.type=="string"&&(u.valueType=n.type),"default"in n&&(u.defaultValue=n.default);}catch{}return u},{name:"Request input with params",description:"Requests player input with optional key/value parameters (e.g. type, default).\n\n```ink\n# request input <key> <value> [<key> <value> \u2026]\n# request input type number default 18\n```",validation:s.tuple([s.literal("request"),s.literal("input")]).rest(s.string()).refine(e=>e.length>2&&(e.length-2)%2===0)});var $e=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],ze=["+","-","/","*","%","POW","RANDOM","L^"],Ue=["INT","FLOOR","FLOAT"];function Z(e,u){if(e.endsWith(".s"))return;if(new RegExp(/.*\.[0-9]+\..*$/).test(e)&&(e=e.split(".").filter(o=>!o.match(/^[0-9]+$/)).join("."),!e.startsWith(".")))return e.replaceAll(".","_|_");if(!new RegExp(/^\.\^.*$/).test(e)&&e.includes("g-")){let i=e.split("g-");return ye(u)+"_|_"+"g-"+i[i.length-1]}let n=0;for(;new RegExp(/^\.\^.*$/).test(e);)n++,e=e.substring(2);if(n=n-1,new RegExp(/^\..*$/).test(e)&&u){let i=e.substring(1);return ye(u,n)+"_|_"+i.replaceAll(".","_|_")}return e.replaceAll(".","_|_")||ye(u,n).replaceAll(".","_|_")}function ye(e,u=0){let n=e.split("_|_");for(;n.length>1&&u>0;)n.pop()?.includes("g-")&&u--,u--;return n.join("_|_")}var qe="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function I(e){return e.startsWith("^")&&(e=e.substring(1)),e=e.replaceAll("\\\\",qe),e=e.replaceAll("\\n",`
22
- `),e=e.replaceAll("\\t"," "),e=e.replaceAll(" "," "),e=e.replaceAll(qe,"\\\\"),e}function U(e,u,n,i){let{functions:o}=i;e=e.map(a=>{if(typeof a=="string")switch(a){case "rnd":return "RANDOM";case "?":return "CONTAINS"}return a});let r=[];return e.forEach(a=>{if(typeof a=="string")switch(a){case "&&":case "||":if(r.length>=2){let l={type:"union",unionType:a==="&&"?"and":"or",conditions:[r[r.length-2],r[r.length-1]]};r.pop(),r.pop(),r.push(l);}break;case "!":if(r.length===0)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"union",unionType:"not",condition:r[r.length-1]};r[r.length-1]=l;}break;case "!?":if(r.length>1){let l={type:"union",unionType:"not",condition:{type:"compare",operator:"CONTAINS",leftValue:r[r.length-2],rightValue:r[r.length-1]}};r.pop(),r.pop(),r.push(l);}else O.error("Error parsing ink file: Conditional statement is not valid",e);break;default:if(PixiVNJsonComparationOperators.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"compare",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(ze.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {a==="L^"&&(a="INTERSECTION");let l={type:"arithmetic",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(Ue.includes(a)){let l={type:"arithmeticsingle",operator:a,leftValue:r[r.length-1]};r.pop(),r.push(l);}else a.startsWith("^")&&r.push(I(a));}else if(typeof a=="object"&&"CNT?"in a)if(new RegExp(/.*\.[0-9]\..*/).test(a["CNT?"])){let l=a["CNT?"].split("."),c=l.pop(),p=l.pop();if(p===void 0||c===void 0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let f=Number(p),C=l.join(".");if(C.includes("^.")){let E=C.split("."),m=E[E.length-1].replaceAll(".","_|_");E.pop(),C=`${E.join(".")}.${m}`,c.includes("c-")&&(C=C+"_|_"+c);}else C=C.replaceAll(".","_|_");let A=Z(C,u);if(!A)return;r.push({type:"compare",leftValue:me(A),operator:">=",rightValue:{type:"value",value:f}});}else {let l=Z(a["CNT?"],u);if(!l)return;r.push(me(l));}else if(typeof a=="object"&&"VAR?"in a)r.push(X({key:a["VAR?"],defaultType:"storage"},n));else if(typeof a=="object"&&"f()"in a){let l=a["f()"],c=o.find(f=>f.name===l);if(!c){O.error(`Error parsing ink file: Function ${l} is not defined`,e);return}let p=[];for(let f=0;f<c.args;f++)r.length!==0&&p.push(r.pop());r.push({type:"function",functionName:l,args:p.reverse()});}else if(typeof a=="object"&&"^->"in a)a["^->"].includes("$r")||r.push(a["^->"]);else if(typeof a=="object"&&"list"in a){let l=Object.values(a.list).map(c=>c);r.push(l);}else r.push(a);}),r}function Be(e,u,n,i){return U(e,u,n,i)}function X(e,u,n){let{key:i,defaultType:o}=e,r=u.indexOf(i);return r>=0?{type:"value",storageType:"params",storageOperationType:"get",key:r}:{type:"value",storageOperationType:"get",storageType:o,key:i}}function ie(e,u,n){let{key:i,value:o,defaultType:r,artmeticValue:a}=e,l=u.indexOf(i);if(l>=0)return [{type:"value",storageType:"params",storageOperationType:"set",key:l,value:o}];if(a){if(typeof o=="object"&&"list"in o){let c=Object.values(o.list).map(p=>p);return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:c}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}else if(typeof o=="object"){if("list"in o&&typeof o.list=="object"){if("origins"in o&&Array.isArray(o.origins)&&o.origins.length>0)return o.origins.reduce(c=>(c.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(n.enums[i])}),Object.entries(n.enums[i]).forEach(([p,f])=>{c.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${p}`,value:f});}),c),[]);{let c=new Set,p=Object.entries(o.list).reduce((f,[C,A])=>{let[E,m]=C.split(".");return f.push({type:"value",storageOperationType:"set",storageType:r,key:m,value:A}),c.add(E),f},[]);return c.forEach(f=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:f,value:Object.values(n.enums[f])});}),i in n.enums?Object.entries(n.enums[i]).forEach(([f,C])=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${f}`,value:C});}):p.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(o.list)}),p}}else if(typeof o=="object"&&"VAR?"in o){if(typeof o["VAR?"]=="string"&&o["VAR?"].includes(".")){let[c,p]=o["VAR?"].split(".");if(c in n.enums&&p in n.enums[c])return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:n.enums[c][p]}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:X({key:o["VAR?"],defaultType:"storage"},u)}]}}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}function me(e){return {type:"value",storageType:"label",storageOperationType:"get",label:e}}function Te(e,u){return u||new RegExp(`${"_|_".replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c-\\d+$`).test(e)?"call":"jump"}function le(e,u){if(u){if(typeof u=="string")u.startsWith("^")&&e.push(I(u));else if(typeof u=="object"&&"type"in u)switch(u.type){case "value":case "function":console.warn("Warning: trying to add a value or function operation as text. This is likely a mistake, so it will be ignored.");break;default:e.push(u);}}}function ve(e,u,n,i,o,r={}){let{isNewLine:a=true,isHashtagScript:l=false,isThreads:c=false}=r;return fu(e,u,n,i,o,{isNewLine:a,isHashtagScript:l,isThreads:c})}function fu(e,u,n,i,o,r){if(!u)return;let{isNewLine:a,isHashtagScript:l=false,isThreads:c}=r;if(l){if(Array.isArray(u)&&u.length>0){let p={goNextStep:true},f=[];try{if(u.length===1&&typeof u[0]=="string"&&!u[0].match(Ne)){let C=u[0],A=y.convertTagTolist(C),E=y.convertOperation(A,p);E&&(E.$origin=C,f.push(E));}}catch{}f.length===0&&f.push({type:"operationtoconvert",values:u}),e.push({...p,operations:f});}}else if(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"){if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&!p.labelToOpen&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}typeof u=="string"?e.push(du(I(u),i.characterIds)):e.push({dialogue:u});}else if(typeof u=="string"){if(u==="end")e.push({end:"game_end"});else if(u==="done")e.push({end:"label_end",goNextStep:true});else if(u==="<>")if(e.length>0){let p=e[e.length-1];p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true),e[e.length-1]=p;}else e.push({glueEnabled:true,goNextStep:false});}else if(typeof u=="object"){if("type"in u)switch(u.type){case "value":u.storageOperationType==="set"?(typeof u.value=="string"&&u.value.startsWith("^")&&(u.value=I(u.value)),e.push({goNextStep:true,operations:[u]})):console.warn("Warning: trying to add a value get operation as step. This is likely a mistake, so it will be ignored.");break;case "function":e.push({goNextStep:true,operations:[u]});break;default:if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}e.push({conditionalStep:u});}else if("->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let f=e[e.length-1];f.labelToOpen||(f.goNextStep=true),e[e.length-1]=f;}if(u.params&&u.params.length===0&&delete u.params,u.var)e.push({labelToOpen:{label:X({key:u["->"],defaultType:"storage"},o),type:c?"call":"jump",params:u.params},glueEnabled:p});else {let f=Z(u["->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:Te(f,c),params:u.params},glueEnabled:p});}}else if("->t->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let C=e[e.length-1];C.labelToOpen||(C.goNextStep=true),e[e.length-1]=C;}u.params&&u.params.length===0&&delete u.params;let f=Z(u["->t->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:"call",params:u.params},glueEnabled:p});}}}function du(e,u){let n;if(e.includes(": ")){let i=e.split(": "),o=i[0],r=i.slice(1).join(": ");(u?.has(o)||RegisteredCharacters.has(o))&&(n=o,e=r);}return n?{dialogue:{character:n,text:e}}:{dialogue:e}}function xe(e,u,n,i=true,o=false){return Cu(e,u,n,i,o)}function Cu(e,u,n,i,o=false){u&&(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"?typeof u=="string"?e.push(I(u)):e.push(u):typeof u=="object"&&"type"in u&&e.push(u));}function De(e,u,n,i){if(e.length===0){O.error("Error parsing ink file: Arithmetic statement is not valid",e);return}let o=U(e,u,n,i);if(o.length===1){let r=o[0];return r&&typeof r=="object"&&"type"in r?{type:"value",storageType:"logic",storageOperationType:"get",operation:r}:r}}function K(e,u,n,i="",o,r,a=void 0){let l=[],c="sequential",p=false,f=true;e.forEach(E=>{E==="%"&&(c="loop"),E==="seq"&&(c="random"),E==="MIN"&&(p=true);});let C=e[e.length-1];return Object.keys(C).forEach(E=>{let m=C[E];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let F=[];q(m,i,o,F,u,u,n,ee,a,true,r),F.length===1?l.push(F[0]):l.push({type:"resulttocombine",combine:"cross",secondConditionalItem:F});}else Array.isArray(m)&&m.length===3&&(f=false);}),c==="sequential"?{type:"stepswitch",elements:l,choiceType:c,end:f?"lastItem":void 0,nestedId:a}:p&&c==="random"?{type:"stepswitch",elements:l,choiceType:"sequentialrandom",end:f?"lastItem":void 0,nestedId:a}:{type:"stepswitch",elements:l,choiceType:c}}function q(e,u,n,i=[],o,r,a,l,c=void 0,p=true,f=[]){let C=false,A=[],E=false,m=false,F=false,x=[],T=[];if(n.preDialog[u]&&(p=false,o(i,`^${n.preDialog[u].text}`,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),n.preDialog[u].glue&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),delete n.preDialog[u]),e.includes("visit")){let t=K(e,r,a,u,n,f,c);t&&(!p&&i.length>0&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}));return}let P=e[0];if(P&&typeof P=="object"&&"temp="in P){for(;e[0]&&typeof e[0]=="object"&&"temp="in e[0];)f.push(e[0]["temp="]),e.shift();f=f.reverse();}if(e.forEach((t,h)=>{if(m){if(typeof t=="string"&&t==="/#"){let d=[];q(T,u,n,d,xe,xe,a,l,c,p),o(i,d,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),m=false,T=[];}else T.push(t);return}else if(C)if(Array.isArray(t))A.push(t);else if(t&&typeof t=="object")"CNT?"in t?h>0&&e[h-1]==="ev"?(E=true,x.push(t)):E?x.push(t):(A.push(t),p=false):"VAR="in t||"temp="in t?ie({key:"VAR="in t?t["VAR="]:t["temp="],value:e[h-1],defaultType:"VAR="in t?"storage":"tempstorage"},f,n).forEach(g=>{if(g.value&&typeof g.value=="string"&&g.value==="/str"&&(g.value=e[h-2]),g.value&&typeof g.value=="object"&&"^->"in g.value&&(g.value=g.value["^->"]),A.length>1){let B=De(A,u,f,n);A=[],B&&typeof B=="object"&&"type"in B&&B.type==="value"&&"storageType"in B&&B.storageType==="logic"&&(g.value=B.operation);}(typeof g.key!="string"||!g.key.includes("$r"))&&(o(i,g,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=true);}):"VAR?"in t?A.push(t):"^->"in t?t["^->"].includes("$r")||A.push(t):("f()"in t||"list"in t&&typeof t.list=="object")&&A.push(t);else switch(t){case "/ev":E&&x.push(t),C=false,A.push(t);break;case "out":if(A.length>0){let d=A[A.length-1];if(d&&typeof d=="object"&&"VAR?"in d){A.pop();let g=X({key:d["VAR?"],defaultType:"storage"},f);o(i,g,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F});}else {let g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)g.push(A.pop());g=g.reverse();let B=De(g,u,f,n);A=[],B&&typeof B=="object"&&"type"in B&&B.type==="value"&&"storageType"in B&&B.storageType==="logic"?o(i,{storageOperationType:"get",storageType:"logic",operation:B.operation,type:"value"},u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}):(o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),B=`^${B}`,o(i,B,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}));}p=false;}break;case "pop":{let d=A[A.length-1];if(d&&typeof d=="object"&&"f()"in d){let g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)g.push(A.pop());g=g.reverse();let B=U(g,u,f,n);A=[],B.forEach(b=>{b&&typeof b=="object"&&"type"in b&&b.type==="function"?o(i,b,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}):O.warn("Unhandled case: value is not a function",b);}),p=false;}else A.push(t);return}default:A.push(t);}else if(typeof t=="string")if(t.startsWith("^"))o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="ev")C=true;else if(t===`
23
- `)p=true;else if(t==="done"||t==="end")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="<>")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;else if(t==="nop"&&E){let d=Ge(x,r,a,u,n,f,c);d&&o(i,d,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),E=false,x=[];}else t==="#"?m=true:t==="thread"&&(F=true);else if(Array.isArray(t))if(E)x.push(t);else if(t.length>1&&typeof t[t.length-2]=="object"&&t[t.length-2]&&"c"in t[t.length-2]&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"b"in t[t.length-1]){A.pop();let d=[],g=[];for(;A.length>0&&A[A.length-1]!=="/ev";)d.push(A.pop());x=[...x,...d.reverse()],E=true,g.push(t.pop()),g.push(t.pop()),x=[...x,...t],x.push(g);}else if(t.length>1&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"#n"in t[t.length-1]){let d=t.pop();if(!d){O.error("Error parsing ink file: el is undefined");return}let g=d["#n"];delete d["#n"],t.push(d),o(i,{"->":u?u+"_|_"+g:g},u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),a({[g]:t},u,n);}else q(t,u,n,i,o,r,a,l,c,p,f);else if(t&&typeof t=="object")if("->"in t&&typeof t["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;}else if("->t->"in t&&typeof t["->t->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->t->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F}),p=false;}else if("*"in t&&typeof t["*"]=="string")t["*"].includes("c")&&(A.push(t),p=false);else if("s"in t&&Array.isArray(t.s))A.push(t),p=false;else if("CNT?"in t)A.push(t),p=false;else if("VAR="in t||"temp="in t){let d="VAR="in t?t["VAR="]:t["temp="],g,B=[];if(d!=="$r"){for(A.pop(),A[A.length-1]==="/ev"&&A.pop();A.length>0&&A[A.length-1]!=="/ev";)B.push(A.pop());B=B.reverse(),g=De(B,u,f,n),A=[],ie({key:d,value:g,defaultType:"VAR="in t?"storage":"tempstorage",artmeticValue:true},f,n).forEach(J=>{(J.value!==void 0||J.value!==null)&&o(i,J,u,n,f,{isNewLine:p,isHashtagScript:m,isThreads:F});}),p=false;}}else a(t,u,n);}),l(A,i,u,n,f),u.includes("_|_")&&i.length===2){let t=i[0],h=i[1];t&&h&&typeof t=="object"&&"dialogue"in t&&typeof h=="object"&&"labelToOpen"in h&&t.dialogue===" "&&h.labelToOpen&&(i.shift(),delete h.glueEnabled,i[0]=h);}}function be(e,u,n,i,o,r){if(u.length===0)return;let a=U(u,i,n,o);if(a.length===1){let l={type:"ifelse",condition:a[0],then:e,else:r};return l.else||delete l.else,l}else if(a.length>1){let l={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:e,else:r};return l.else||delete l.else,l}}function Ge(e,u,n,i,o,r,a=void 0){if(e.length===0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let l=[],c=[];if(e.forEach(C=>{Array.isArray(C)?c.push(C):typeof C=="string"&&C==="du"?o.du?l.push(o.du):o.du=l[l.length-1]:(typeof C!="string"||C!=="/ev")&&l.push(C);}),c.length===0){O.error("Error parsing ink file: Conditional statement is not valid",c);return}let p=Se(c[0],u,n,`${i}${"_|_"}then`,o,r,`${a||""}then`),f;return c.length===2?f=Se(c[1],u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`):c.length>2?(c.shift(),c.push("nop"),c=[{b:c}],f=Se(c,u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`)):f=void 0,o.du=void 0,be(p,l,r,i,o,f)}function Se(e,u,n,i,o,r,a=void 0){let l=[];for(let p of e)typeof p=="object"&&"b"in p&&(p.b=p.b.filter(f=>f!==null&&!(typeof f=="object"&&"->"in f&&new RegExp(/.*\.[0-9]/).test(f["->"]))),q(p.b,i,o,l,u,u,n,ee,a,true,r));return l.length===1?l[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:l}}function Ve(e="",u=""){let n=Array.isArray(e)?e:[e],i=Array.isArray(u)?u:[u];return [...new Set([...n,...i])]}function ee(e,u,n,i,o){if(e.length>0){let r={};Ye(e,r,o,i);for(let[a,l]of Object.entries(r)){let c=n+"_|_"+a,p={text:l.text.length===1?l.text[0]:l.text,label:c,props:{},type:Te(c,false),oneTime:l.onetime};l.text.length===0&&(p.onlyHaveNoChoice=true,p.autoSelect=true),p.oneTime===false&&delete p.oneTime;let f=be(p,l.conditions,o,n,i)||p,C=u[u.length-1];if(typeof C=="object"&&C&&"type"in C&&(C={conditionalStep:C}),u.length>0&&typeof C=="object"&&C&&"choices"in C&&C.choices){let A=C.choices;A&&Array.isArray(A)?A.push(f):O.error("Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",l,A),C.choices=A.sort((E,m)=>{try{let F=E.label.split("."),x=F[F.length-1].replaceAll(".","_|_"),T=m.label.split("."),P=T[T.length-1].replaceAll(".","_|_");if(x.includes("c-")&&P.includes("c-")){let t=x.split("c-")[1],h=Number(t),d=P.split("c-")[1],g=Number(d);return h-g}}catch{}return 0});}else u.push({choices:[f]});l.preDialog&&(i.preDialog[c]={...l.preDialog});}}}function Ye(e,u,n,i,o){let r=[],a="",l="",c=false,p=[];for(let f=0;f<e.length;f++){let C=e[f];if(typeof C=="string")C.startsWith("^")?r.push(I(C)):$e.includes(C)&&p.push(C);else if(Array.isArray(C)&&C.includes("visit")){let A=K(C,le,(E,m,F)=>{},o,i,n);r.push(A);}else if(C&&typeof C=="object")if("*"in C&&typeof C["*"]&&typeof C["*"]=="string")C["*"].includes("c")&&(a=`c${C["*"].split("c")[1]}`,C.flg&16&&(c=true));else if("s"in C&&Array.isArray(C.s)){let A=Qe(C.s),E=C.s.includes("<>");A&&(o&&u[o]?(u[o].preDialog={text:A,glue:E},u[o].text=Ve(A,u[o].text)):(r.push(A),l=A));}else ("CNT?"in C||"VAR?"in C)&&p.push(C);else p.push(C);if(a){u[a]?u[a].text=Ve(r,u[a].text):u[a]={text:r,onetime:c,conditions:p},l&&(u[a].preDialog={text:l,glue:false});let A=e.slice(f+1);Ye(A,u,n,i,a);return}}}function Qe(e){for(let u of e)if(typeof u=="string"){if(u.startsWith("^"))return I(u)}else if(Array.isArray(u)){let n=Qe(u);if(n)return n}}var gu;(o=>{function e(r,a={}){let{labelToRemove:l=[],initialVarsToRemove:c=[],enums:p={},functions:f=[],preDialog:C={},characterIds:A}=a,E={$schema:PIXIVNJSON_SCHEMA_URL};if(E.labels=u(r.root,{labelToRemove:l,initialVarsToRemove:c,enums:p,functions:f,preDialog:C,characterIds:A}),E.labels&&re in E.labels){let m=E.labels[re];delete E.labels[re],m.forEach(F=>{F.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...F.operations]:[...F.operations]);});}if(E.labels&&G in E.labels){let m=E.labels[G];delete E.labels[G],m.forEach(F=>{F.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...F.operations]:[...F.operations]);});}return l.forEach(m=>{E.labels&&m in E.labels&&delete E.labels[m];}),c.forEach(m=>{E.initialOperations&&(E.initialOperations=E.initialOperations.filter(F=>!(F.type==="value"&&F.key===m)));}),E}o.inkToJson=e;function u(r,a){try{let l={};return n(r,l,a),l}catch(l){O.error("Error parsing ink file",l);}}function n(r,a,l){for(let c of r)if(c)if(Array.isArray(c))if(c.includes("visit")){let p=K(c,le,(f,C,A)=>{},"",l,[]);p&&(l.externalSwitch=p);}else n(c,a,l);else typeof c=="object"&&(c&&"VAR="in c&&l.externalSwitch&&(a[G]||(a[G]=[]),a[G].push({operations:ie({defaultType:"storage",key:c["VAR="],value:l.externalSwitch},[],l)})),i(c,a,"",l));}function i(r,a,l="",c){if(r!==null){for(let[p,f]of Object.entries(r))if(Array.isArray(f)){let C=[],A={},E=(l?l+"_|_":"")+p;q(f,E,c,C,ve,ve,(m,F,x)=>{i(m,A,F,x);},ee);for(let[m,F]of Object.entries(A))a[m]=F;C.length>0&&(a[E]=C);}}}})(gu||={});export{gu as InkMapper};
22
+ `),e=e.replaceAll("\\t"," "),e=e.replaceAll(" "," "),e=e.replaceAll(qe,"\\\\"),e}function U(e,u,n,i){let{functions:o}=i;e=e.map(a=>{if(typeof a=="string")switch(a){case "rnd":return "RANDOM";case "?":return "CONTAINS"}return a});let r=[];return e.forEach(a=>{if(typeof a=="string")switch(a){case "&&":case "||":if(r.length>=2){let l={type:"union",unionType:a==="&&"?"and":"or",conditions:[r[r.length-2],r[r.length-1]]};r.pop(),r.pop(),r.push(l);}break;case "!":if(r.length===0)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"union",unionType:"not",condition:r[r.length-1]};r[r.length-1]=l;}break;case "!?":if(r.length>1){let l={type:"union",unionType:"not",condition:{type:"compare",operator:"CONTAINS",leftValue:r[r.length-2],rightValue:r[r.length-1]}};r.pop(),r.pop(),r.push(l);}else O.error("Error parsing ink file: Conditional statement is not valid",e);break;default:if(PixiVNJsonComparationOperators.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {let l={type:"compare",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(ze.includes(a))if(r.length<2)O.error("Error parsing ink file: Conditional statement is not valid",e);else {a==="L^"&&(a="INTERSECTION");let l={type:"arithmetic",operator:a,rightValue:r[r.length-1],leftValue:r[r.length-2]};r.pop(),r.pop(),r.push(l);}else if(Ue.includes(a)){let l={type:"arithmeticsingle",operator:a,leftValue:r[r.length-1]};r.pop(),r.push(l);}else a.startsWith("^")&&r.push(I(a));}else if(typeof a=="object"&&"CNT?"in a)if(new RegExp(/.*\.[0-9]\..*/).test(a["CNT?"])){let l=a["CNT?"].split("."),c=l.pop(),p=l.pop();if(p===void 0||c===void 0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let f=Number(p),C=l.join(".");if(C.includes("^.")){let E=C.split("."),B=E[E.length-1].replaceAll(".","_|_");E.pop(),C=`${E.join(".")}.${B}`,c.includes("c-")&&(C=C+"_|_"+c);}else C=C.replaceAll(".","_|_");let A=Z(C,u);if(!A)return;r.push({type:"compare",leftValue:me(A),operator:">=",rightValue:{type:"value",value:f}});}else {let l=Z(a["CNT?"],u);if(!l)return;r.push(me(l));}else if(typeof a=="object"&&"VAR?"in a)r.push(X({key:a["VAR?"],defaultType:"storage"},n));else if(typeof a=="object"&&"f()"in a){let l=a["f()"],c=o.find(f=>f.name===l);if(!c){O.error(`Error parsing ink file: Function ${l} is not defined`,e);return}let p=[];for(let f=0;f<c.args;f++)r.length!==0&&p.push(r.pop());r.push({type:"function",functionName:l,args:p.reverse()});}else if(typeof a=="object"&&"^->"in a)a["^->"].includes("$r")||r.push(a["^->"]);else if(typeof a=="object"&&"list"in a){let l=Object.values(a.list).map(c=>c);r.push(l);}else r.push(a);}),r}function Be(e,u,n,i){return U(e,u,n,i)}function X(e,u,n){let{key:i,defaultType:o}=e,r=u.indexOf(i);return r>=0?{type:"value",storageType:"params",storageOperationType:"get",key:r}:{type:"value",storageOperationType:"get",storageType:o,key:i}}function ie(e,u,n){let{key:i,value:o,defaultType:r,artmeticValue:a}=e,l=u.indexOf(i);if(l>=0)return [{type:"value",storageType:"params",storageOperationType:"set",key:l,value:o}];if(a){if(typeof o=="object"&&"list"in o){let c=Object.values(o.list).map(p=>p);return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:c}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}else if(typeof o=="object"){if("list"in o&&typeof o.list=="object"){if("origins"in o&&Array.isArray(o.origins)&&o.origins.length>0)return o.origins.reduce(c=>(c.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(n.enums[i])}),Object.entries(n.enums[i]).forEach(([p,f])=>{c.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${p}`,value:f});}),c),[]);{let c=new Set,p=Object.entries(o.list).reduce((f,[C,A])=>{let[E,B]=C.split(".");return f.push({type:"value",storageOperationType:"set",storageType:r,key:B,value:A}),c.add(E),f},[]);return c.forEach(f=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:f,value:Object.values(n.enums[f])});}),i in n.enums?Object.entries(n.enums[i]).forEach(([f,C])=>{p.push({type:"value",storageOperationType:"set",storageType:r,key:`${i}.${f}`,value:C});}):p.push({type:"value",storageOperationType:"set",storageType:r,key:i,value:Object.values(o.list)}),p}}else if(typeof o=="object"&&"VAR?"in o){if(typeof o["VAR?"]=="string"&&o["VAR?"].includes(".")){let[c,p]=o["VAR?"].split(".");if(c in n.enums&&p in n.enums[c])return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:n.enums[c][p]}]}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:X({key:o["VAR?"],defaultType:"storage"},u)}]}}return [{type:"value",storageOperationType:"set",storageType:r,key:i,value:o}]}function me(e){return {type:"value",storageType:"label",storageOperationType:"get",label:e}}function Te(e,u){return u||new RegExp(`${"_|_".replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c-\\d+$`).test(e)?"call":"jump"}function le(e,u){if(u){if(typeof u=="string")u.startsWith("^")&&e.push(I(u));else if(typeof u=="object"&&"type"in u)switch(u.type){case "value":case "function":console.warn("Warning: trying to add a value or function operation as text. This is likely a mistake, so it will be ignored.");break;default:e.push(u);}}}function ve(e,u,n,i,o,r={}){let{isNewLine:a=true,isHashtagScript:l=false,isThreads:c=false}=r;return fu(e,u,n,i,o,{isNewLine:a,isHashtagScript:l,isThreads:c})}function fu(e,u,n,i,o,r){if(!u)return;let{isNewLine:a,isHashtagScript:l=false,isThreads:c}=r;if(l){if(Array.isArray(u)&&u.length>0){let p={goNextStep:true},f=[];try{if(u.length===1&&typeof u[0]=="string"&&!u[0].match(Ne)){let C=u[0],A=y.convertTagTolist(C),E=y.convertOperation(A,p,{silent:!0});E&&(E.$origin=C,f.push(E));}}catch{}f.length===0&&f.push({type:"operationtoconvert",values:u}),e.push({...p,operations:f});}}else if(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"){if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&!p.labelToOpen&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}typeof u=="string"?e.push(du(I(u),i.characterIds)):e.push({dialogue:u});}else if(typeof u=="string"){if(u==="end")e.push({end:"game_end"});else if(u==="done")e.push({end:"label_end",goNextStep:true});else if(u==="<>")if(e.length>0){let p=e[e.length-1];p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true),e[e.length-1]=p;}else e.push({glueEnabled:true,goNextStep:false});}else if(typeof u=="object"){if("type"in u)switch(u.type){case "value":u.storageOperationType==="set"?(typeof u.value=="string"&&u.value.startsWith("^")&&(u.value=I(u.value)),e.push({goNextStep:true,operations:[u]})):console.warn("Warning: trying to add a value get operation as step. This is likely a mistake, so it will be ignored.");break;case "function":e.push({goNextStep:true,operations:[u]});break;default:if(!a&&e.length>0){let p=e[e.length-1];!p.glueEnabled&&!p.operations&&(p.glueEnabled=true,p.labelToOpen||(p.goNextStep=true)),e[e.length-1]=p;}e.push({conditionalStep:u});}else if("->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let f=e[e.length-1];f.labelToOpen||(f.goNextStep=true),e[e.length-1]=f;}if(u.params&&u.params.length===0&&delete u.params,u.var)e.push({labelToOpen:{label:X({key:u["->"],defaultType:"storage"},o),type:c?"call":"jump",params:u.params},glueEnabled:p});else {let f=Z(u["->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:Te(f,c),params:u.params},glueEnabled:p});}}else if("->t->"in u){let p=a?void 0:true;if(p&&n.includes("c-")&&e.length>0&&e[e.length-1]?.dialogue===void 0&&(p=void 0),!a&&e.length>0){let C=e[e.length-1];C.labelToOpen||(C.goNextStep=true),e[e.length-1]=C;}u.params&&u.params.length===0&&delete u.params;let f=Z(u["->t->"],n);if(!f)return;e.push({labelToOpen:{label:f,type:"call",params:u.params},glueEnabled:p});}}}function du(e,u){let n;if(e.includes(": ")){let i=e.split(": "),o=i[0],r=i.slice(1).join(": ");(u?.has(o)||RegisteredCharacters.has(o))&&(n=o,e=r);}return n?{dialogue:{character:n,text:e}}:{dialogue:e}}function xe(e,u,n,i=true,o=false){return Cu(e,u,n,i,o)}function Cu(e,u,n,i,o=false){u&&(typeof u=="string"&&u.startsWith("^")||u&&typeof u=="object"&&"type"in u&&u.type==="value"&&u.storageOperationType==="get"?typeof u=="string"?e.push(I(u)):e.push(u):typeof u=="object"&&"type"in u&&e.push(u));}function De(e,u,n,i){if(e.length===0){O.error("Error parsing ink file: Arithmetic statement is not valid",e);return}let o=U(e,u,n,i);if(o.length===1){let r=o[0];return r&&typeof r=="object"&&"type"in r?{type:"value",storageType:"logic",storageOperationType:"get",operation:r}:r}}function K(e,u,n,i="",o,r,a=void 0){let l=[],c="sequential",p=false,f=true;e.forEach(E=>{E==="%"&&(c="loop"),E==="seq"&&(c="random"),E==="MIN"&&(p=true);});let C=e[e.length-1];return Object.keys(C).forEach(E=>{let B=C[E];if(Array.isArray(B)&&B.length>3){B=B.slice(1,B.length-2);let g=[];q(B,i,o,g,u,u,n,ee,a,true,r),g.length===1?l.push(g[0]):l.push({type:"resulttocombine",combine:"cross",secondConditionalItem:g});}else Array.isArray(B)&&B.length===3&&(f=false);}),c==="sequential"?{type:"stepswitch",elements:l,choiceType:c,end:f?"lastItem":void 0,nestedId:a}:p&&c==="random"?{type:"stepswitch",elements:l,choiceType:"sequentialrandom",end:f?"lastItem":void 0,nestedId:a}:{type:"stepswitch",elements:l,choiceType:c}}function q(e,u,n,i=[],o,r,a,l,c=void 0,p=true,f=[]){let C=false,A=[],E=false,B=false,g=false,x=[],T=[];if(n.preDialog[u]&&(p=false,o(i,`^${n.preDialog[u].text}`,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),n.preDialog[u].glue&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),delete n.preDialog[u]),e.includes("visit")){let t=K(e,r,a,u,n,f,c);t&&(!p&&i.length>0&&o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}));return}let P=e[0];if(P&&typeof P=="object"&&"temp="in P){for(;e[0]&&typeof e[0]=="object"&&"temp="in e[0];)f.push(e[0]["temp="]),e.shift();f=f.reverse();}if(e.forEach((t,h)=>{if(B){if(typeof t=="string"&&t==="/#"){let d=[];q(T,u,n,d,xe,xe,a,l,c,p),o(i,d,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),B=false,T=[];}else T.push(t);return}else if(C)if(Array.isArray(t))A.push(t);else if(t&&typeof t=="object")"CNT?"in t?h>0&&e[h-1]==="ev"?(E=true,x.push(t)):E?x.push(t):(A.push(t),p=false):"VAR="in t||"temp="in t?ie({key:"VAR="in t?t["VAR="]:t["temp="],value:e[h-1],defaultType:"VAR="in t?"storage":"tempstorage"},f,n).forEach(F=>{if(F.value&&typeof F.value=="string"&&F.value==="/str"&&(F.value=e[h-2]),F.value&&typeof F.value=="object"&&"^->"in F.value&&(F.value=F.value["^->"]),A.length>1){let m=De(A,u,f,n);A=[],m&&typeof m=="object"&&"type"in m&&m.type==="value"&&"storageType"in m&&m.storageType==="logic"&&(F.value=m.operation);}(typeof F.key!="string"||!F.key.includes("$r"))&&(o(i,F,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=true);}):"VAR?"in t?A.push(t):"^->"in t?t["^->"].includes("$r")||A.push(t):("f()"in t||"list"in t&&typeof t.list=="object")&&A.push(t);else switch(t){case "/ev":E&&x.push(t),C=false,A.push(t);break;case "out":if(A.length>0){let d=A[A.length-1];if(d&&typeof d=="object"&&"VAR?"in d){A.pop();let F=X({key:d["VAR?"],defaultType:"storage"},f);o(i,F,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g});}else {let F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)F.push(A.pop());F=F.reverse();let m=De(F,u,f,n);A=[],m&&typeof m=="object"&&"type"in m&&m.type==="value"&&"storageType"in m&&m.storageType==="logic"?o(i,{storageOperationType:"get",storageType:"logic",operation:m.operation,type:"value"},u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}):(o(i,"<>",u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),m=`^${m}`,o(i,m,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}));}p=false;}break;case "pop":{let d=A[A.length-1];if(d&&typeof d=="object"&&"f()"in d){let F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)F.push(A.pop());F=F.reverse();let m=U(F,u,f,n);A=[],m.forEach(b=>{b&&typeof b=="object"&&"type"in b&&b.type==="function"?o(i,b,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}):O.warn("Unhandled case: value is not a function",b);}),p=false;}else A.push(t);return}default:A.push(t);}else if(typeof t=="string")if(t.startsWith("^"))o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="ev")C=true;else if(t===`
23
+ `)p=true;else if(t==="done"||t==="end")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="<>")o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;else if(t==="nop"&&E){let d=Ge(x,r,a,u,n,f,c);d&&o(i,d,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),E=false,x=[];}else t==="#"?B=true:t==="thread"&&(g=true);else if(Array.isArray(t))if(E)x.push(t);else if(t.length>1&&typeof t[t.length-2]=="object"&&t[t.length-2]&&"c"in t[t.length-2]&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"b"in t[t.length-1]){A.pop();let d=[],F=[];for(;A.length>0&&A[A.length-1]!=="/ev";)d.push(A.pop());x=[...x,...d.reverse()],E=true,F.push(t.pop()),F.push(t.pop()),x=[...x,...t],x.push(F);}else if(t.length>1&&typeof t[t.length-1]=="object"&&t[t.length-1]&&"#n"in t[t.length-1]){let d=t.pop();if(!d){O.error("Error parsing ink file: el is undefined");return}let F=d["#n"];delete d["#n"],t.push(d),o(i,{"->":u?u+"_|_"+F:F},u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),a({[F]:t},u,n);}else q(t,u,n,i,o,r,a,l,c,p,f);else if(t&&typeof t=="object")if("->"in t&&typeof t["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;}else if("->t->"in t&&typeof t["->t->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(t["->t->"])){let d=[];A.length>0&&(d=Be(["ev",...A],u,f,n)),t.params=d,o(i,t,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g}),p=false;}else if("*"in t&&typeof t["*"]=="string")t["*"].includes("c")&&(A.push(t),p=false);else if("s"in t&&Array.isArray(t.s))A.push(t),p=false;else if("CNT?"in t)A.push(t),p=false;else if("VAR="in t||"temp="in t){let d="VAR="in t?t["VAR="]:t["temp="],F,m=[];if(d!=="$r"){for(A.pop(),A[A.length-1]==="/ev"&&A.pop();A.length>0&&A[A.length-1]!=="/ev";)m.push(A.pop());m=m.reverse(),F=De(m,u,f,n),A=[],ie({key:d,value:F,defaultType:"VAR="in t?"storage":"tempstorage",artmeticValue:true},f,n).forEach(J=>{(J.value!==void 0||J.value!==null)&&o(i,J,u,n,f,{isNewLine:p,isHashtagScript:B,isThreads:g});}),p=false;}}else a(t,u,n);}),l(A,i,u,n,f),u.includes("_|_")&&i.length===2){let t=i[0],h=i[1];t&&h&&typeof t=="object"&&"dialogue"in t&&typeof h=="object"&&"labelToOpen"in h&&t.dialogue===" "&&h.labelToOpen&&(i.shift(),delete h.glueEnabled,i[0]=h);}}function be(e,u,n,i,o,r){if(u.length===0)return;let a=U(u,i,n,o);if(a.length===1){let l={type:"ifelse",condition:a[0],then:e,else:r};return l.else||delete l.else,l}else if(a.length>1){let l={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:e,else:r};return l.else||delete l.else,l}}function Ge(e,u,n,i,o,r,a=void 0){if(e.length===0){O.error("Error parsing ink file: Conditional statement is not valid",e);return}let l=[],c=[];if(e.forEach(C=>{Array.isArray(C)?c.push(C):typeof C=="string"&&C==="du"?o.du?l.push(o.du):o.du=l[l.length-1]:(typeof C!="string"||C!=="/ev")&&l.push(C);}),c.length===0){O.error("Error parsing ink file: Conditional statement is not valid",c);return}let p=Se(c[0],u,n,`${i}${"_|_"}then`,o,r,`${a||""}then`),f;return c.length===2?f=Se(c[1],u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`):c.length>2?(c.shift(),c.push("nop"),c=[{b:c}],f=Se(c,u,n,`${i}${"_|_"}else`,o,r,`${a||""}else`)):f=void 0,o.du=void 0,be(p,l,r,i,o,f)}function Se(e,u,n,i,o,r,a=void 0){let l=[];for(let p of e)typeof p=="object"&&"b"in p&&(p.b=p.b.filter(f=>f!==null&&!(typeof f=="object"&&"->"in f&&new RegExp(/.*\.[0-9]/).test(f["->"]))),q(p.b,i,o,l,u,u,n,ee,a,true,r));return l.length===1?l[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:l}}function Ve(e="",u=""){let n=Array.isArray(e)?e:[e],i=Array.isArray(u)?u:[u];return [...new Set([...n,...i])]}function ee(e,u,n,i,o){if(e.length>0){let r={};Ye(e,r,o,i);for(let[a,l]of Object.entries(r)){let c=n+"_|_"+a,p={text:l.text.length===1?l.text[0]:l.text,label:c,props:{},type:Te(c,false),oneTime:l.onetime};l.text.length===0&&(p.onlyHaveNoChoice=true,p.autoSelect=true),p.oneTime===false&&delete p.oneTime;let f=be(p,l.conditions,o,n,i)||p,C=u[u.length-1];if(typeof C=="object"&&C&&"type"in C&&(C={conditionalStep:C}),u.length>0&&typeof C=="object"&&C&&"choices"in C&&C.choices){let A=C.choices;A&&Array.isArray(A)?A.push(f):O.error("Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",l,A),C.choices=A.sort((E,B)=>{try{let g=E.label.split("."),x=g[g.length-1].replaceAll(".","_|_"),T=B.label.split("."),P=T[T.length-1].replaceAll(".","_|_");if(x.includes("c-")&&P.includes("c-")){let t=x.split("c-")[1],h=Number(t),d=P.split("c-")[1],F=Number(d);return h-F}}catch{}return 0});}else u.push({choices:[f]});l.preDialog&&(i.preDialog[c]={...l.preDialog});}}}function Ye(e,u,n,i,o){let r=[],a="",l="",c=false,p=[];for(let f=0;f<e.length;f++){let C=e[f];if(typeof C=="string")C.startsWith("^")?r.push(I(C)):$e.includes(C)&&p.push(C);else if(Array.isArray(C)&&C.includes("visit")){let A=K(C,le,(E,B,g)=>{},o,i,n);r.push(A);}else if(C&&typeof C=="object")if("*"in C&&typeof C["*"]&&typeof C["*"]=="string")C["*"].includes("c")&&(a=`c${C["*"].split("c")[1]}`,C.flg&16&&(c=true));else if("s"in C&&Array.isArray(C.s)){let A=Qe(C.s),E=C.s.includes("<>");A&&(o&&u[o]?(u[o].preDialog={text:A,glue:E},u[o].text=Ve(A,u[o].text)):(r.push(A),l=A));}else ("CNT?"in C||"VAR?"in C)&&p.push(C);else p.push(C);if(a){u[a]?u[a].text=Ve(r,u[a].text):u[a]={text:r,onetime:c,conditions:p},l&&(u[a].preDialog={text:l,glue:false});let A=e.slice(f+1);Ye(A,u,n,i,a);return}}}function Qe(e){for(let u of e)if(typeof u=="string"){if(u.startsWith("^"))return I(u)}else if(Array.isArray(u)){let n=Qe(u);if(n)return n}}var gu;(o=>{function e(r,a={}){let{labelToRemove:l=[],initialVarsToRemove:c=[],enums:p={},functions:f=[],preDialog:C={},characterIds:A}=a,E={$schema:PIXIVNJSON_SCHEMA_URL};if(E.labels=u(r.root,{labelToRemove:l,initialVarsToRemove:c,enums:p,functions:f,preDialog:C,characterIds:A}),E.labels&&re in E.labels){let B=E.labels[re];delete E.labels[re],B.forEach(g=>{g.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...g.operations]:[...g.operations]);});}if(E.labels&&G in E.labels){let B=E.labels[G];delete E.labels[G],B.forEach(g=>{g.operations&&(E.initialOperations=E.initialOperations?[...E.initialOperations,...g.operations]:[...g.operations]);});}return l.forEach(B=>{E.labels&&B in E.labels&&delete E.labels[B];}),c.forEach(B=>{E.initialOperations&&(E.initialOperations=E.initialOperations.filter(g=>!(g.type==="value"&&g.key===B)));}),E}o.inkToJson=e;function u(r,a){try{let l={};return n(r,l,a),l}catch(l){O.error("Error parsing ink file",l);}}function n(r,a,l){for(let c of r)if(c)if(Array.isArray(c))if(c.includes("visit")){let p=K(c,le,(f,C,A)=>{},"",l,[]);p&&(l.externalSwitch=p);}else n(c,a,l);else typeof c=="object"&&(c&&"VAR="in c&&l.externalSwitch&&(a[G]||(a[G]=[]),a[G].push({operations:ie({defaultType:"storage",key:c["VAR="],value:l.externalSwitch},[],l)})),i(c,a,"",l));}function i(r,a,l="",c){if(r!==null){for(let[p,f]of Object.entries(r))if(Array.isArray(f)){let C=[],A={},E=(l?l+"_|_":"")+p;q(f,E,c,C,ve,ve,(B,g,x)=>{i(B,A,g,x);},ee);for(let[B,g]of Object.entries(A))a[B]=g;C.length>0&&(a[E]=C);}}}})(gu||={});export{gu as InkMapper};