@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
4 lines • 445 kB
JavaScript
'use strict';var S=require('zod'),pixiVn=require('@drincs/pixi-vn');require('@drincs/pixi-vn/canvas');var narration=require('@drincs/pixi-vn/narration');require('@drincs/pixi-vn/sound');var storage=require('@drincs/pixi-vn/storage'),characters=require('@drincs/pixi-vn/characters'),Wt=require('fs/promises'),Y=require('path'),Dv=require('fs'),url=require('url'),module$1=require('module');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var S__default=/*#__PURE__*/_interopDefault(S);var Wt__default=/*#__PURE__*/_interopDefault(Wt);var Y__default=/*#__PURE__*/_interopDefault(Y);var Dv__namespace=/*#__PURE__*/_interopNamespace(Dv);var Ed=Object.create;var ja=Object.defineProperty;var bd=Object.getOwnPropertyDescriptor;var Ad=Object.getOwnPropertyNames;var Dd=Object.getPrototypeOf,xd=Object.prototype.hasOwnProperty;var _d=(i,e,t)=>e in i?ja(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var an=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var O=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var wd=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ad(e))!xd.call(i,r)&&r!==t&&ja(i,r,{get:()=>e[r],enumerable:!(n=bd(e,r))||n.enumerable});return i};var _n=(i,e,t)=>(t=i!=null?Ed(Dd(i)):{},wd(ja(t,"default",{value:i,enumerable:true}),i));var Se=(i,e,t)=>_d(i,typeof e!="symbol"?e+"":e,t);var ho=O(dr=>{Object.defineProperty(dr,"__esModule",{value:true});dr.CompilerOptions=void 0;var co=class{constructor(e=null,t=[],n=false,r=null,a=null){this.sourceFilename=e,this.pluginNames=t,this.countAllVisits=n,this.errorHandler=r,this.fileHandler=a;}};dr.CompilerOptions=co;});var Ec=O(fr=>{Object.defineProperty(fr,"__esModule",{value:true});fr.DebugSourceRange=void 0;var po=class{constructor(e,t,n){this.length=e,this.debugMetadata=t,this.text=n;}};fr.DebugSourceRange=po;});var hn=O(gr=>{Object.defineProperty(gr,"__esModule",{value:true});gr.ErrorType=void 0;var bc;(function(i){i[i.Author=0]="Author",i[i.Warning=1]="Warning",i[i.Error=2]="Error";})(bc||(gr.ErrorType=bc={}));});var Ac=O(mr=>{Object.defineProperty(mr,"__esModule",{value:true});mr.Argument=void 0;var fo=class{constructor(e=null,t=null,n=null){this.identifier=e,this.isByReference=t,this.isDivertTarget=n;}get typeName(){return "Argument"}};mr.Argument=fo;});var re=O(_e=>{Object.defineProperty(_e,"__esModule",{value:true});_e.filterUndef=_e.isEquatable=_e.nullIfUndefined=_e.asINamedContentOrNull=_e.asBooleanOrThrows=_e.asNumberOrThrows=_e.asOrThrows=_e.asOrNull=void 0;function Df(i,e){return i instanceof e?Dc(i):null}_e.asOrNull=Df;function xf(i,e){if(i instanceof e)return Dc(i);throw new Error(`${i} is not of type ${e}`)}_e.asOrThrows=xf;function _f(i){if(typeof i=="number")return i;throw new Error(`${i} is not a number`)}_e.asNumberOrThrows=_f;function wf(i){if(typeof i=="boolean")return i;throw new Error(`${i} is not a boolean`)}_e.asBooleanOrThrows=wf;function Tf(i){return i.hasValidName&&i.name?i:null}_e.asINamedContentOrNull=Tf;function Of(i){return typeof i>"u"?null:i}_e.nullIfUndefined=Of;function Pf(i){return typeof i=="object"&&typeof i.Equals=="function"}_e.isEquatable=Pf;function Dc(i,e){return i}function Ff(i){return i!=null}_e.filterUndef=Ff;});var fe=O(Cr=>{Object.defineProperty(Cr,"__esModule",{value:true});Cr.ParsedObject=void 0;var xc=re(),go=class{constructor(){this._alreadyHadError=false,this._alreadyHadWarning=false,this._debugMetadata=null,this._runtimeObject=null,this.content=[],this.parent=null,this.GetType=()=>this.typeName,this.AddContent=e=>{this.content===null&&(this.content=[]);let t=Array.isArray(e)?e:[e];for(let n of t)n.hasOwnProperty("parent")&&(n.parent=this),this.content.push(n);if(!Array.isArray(e))return e},this.InsertContent=(e,t)=>(this.content===null&&(this.content=[]),t.parent=this,this.content.splice(e,0,t),t),this.Find=e=>(t=null)=>{let n=(0, xc.asOrNull)(this,e);if(n!==null&&(t===null||t(n)===true))return n;if(this.content===null)return null;for(let r of this.content){let a=r.Find&&r.Find(e)(t);if(a)return a}return null},this.FindAll=e=>(t,n)=>{let r=Array.isArray(n)?n:[],a=(0, xc.asOrNull)(this,e);if(a!==null&&(!t||t(a)===true)&&r.push(a),this.content===null)return [];for(let s of this.content)s.FindAll&&s.FindAll(e)(t,r);return r},this.Warning=(e,t=null)=>{this.Error(e,t,true);};}get debugMetadata(){return this._debugMetadata===null&&this.parent?this.parent.debugMetadata:this._debugMetadata}set debugMetadata(e){this._debugMetadata=e;}get hasOwnDebugMetadata(){return !!this.debugMetadata}get typeName(){return "ParsedObject"}get story(){let e=this;for(;e.parent;)e=e.parent;return e}get runtimeObject(){return this._runtimeObject||(this._runtimeObject=this.GenerateRuntimeObject(),this._runtimeObject&&(this._runtimeObject.debugMetadata=this.debugMetadata)),this._runtimeObject}set runtimeObject(e){this._runtimeObject=e;}get runtimePath(){if(!this.runtimeObject.path)throw new Error;return this.runtimeObject.path}get containerForCounting(){return this.runtimeObject}get ancestry(){let e=[],t=this.parent;for(;t;)e.push(t),t=t.parent;return e=e.reverse(),e}ResolveReferences(e){if(this.content!==null)for(let t of this.content)t.ResolveReferences(e);}Error(e,t=null,n=false){if(t===null&&(t=this),!(t._alreadyHadError&&!n||t._alreadyHadWarning&&n)){if(this.parent)this.parent.Error(e,t,n);else throw new Error(`No parent object to send error to: ${e}`);n?t._alreadyHadWarning=true:t._alreadyHadError=true;}}};Cr.ParsedObject=go;});var vr=O(yr=>{Object.defineProperty(yr,"__esModule",{value:true});yr.AuthorWarning=void 0;var Nf=fe(),mo=class extends Nf.ParsedObject{constructor(e){super(),this.warningMessage=e,this.GenerateRuntimeObject=()=>(this.Warning(this.warningMessage),null);}get typeName(){return "AuthorWarning"}};yr.AuthorWarning=mo;});var ze=O(ci=>{Object.defineProperty(ci,"__esModule",{value:true});ci.Path=void 0;var Fn=class i{constructor(){if(this._components=[],this._componentsString=null,this._isRelative=false,typeof arguments[0]=="string"){let e=arguments[0];this.componentsString=e;}else if(arguments[0]instanceof i.Component&&arguments[1]instanceof i){let e=arguments[0],t=arguments[1];this._components.push(e),this._components=this._components.concat(t._components);}else if(arguments[0]instanceof Array){let e=arguments[0],t=!!arguments[1];this._components=this._components.concat(e),this._isRelative=t;}}get isRelative(){return this._isRelative}get componentCount(){return this._components.length}get head(){return this._components.length>0?this._components[0]:null}get tail(){if(this._components.length>=2){let e=this._components.slice(1,this._components.length);return new i(e)}else return i.self}get length(){return this._components.length}get lastComponent(){let e=this._components.length-1;return e>=0?this._components[e]:null}get containsNamedComponent(){for(let e=0,t=this._components.length;e<t;e++)if(!this._components[e].isIndex)return true;return false}static get self(){let e=new i;return e._isRelative=true,e}GetComponent(e){return this._components[e]}PathByAppendingPath(e){let t=new i,n=0;for(let r=0;r<e._components.length&&e._components[r].isParent;++r)n++;for(let r=0;r<this._components.length-n;++r)t._components.push(this._components[r]);for(let r=n;r<e._components.length;++r)t._components.push(e._components[r]);return t}get componentsString(){return this._componentsString==null&&(this._componentsString=this._components.join("."),this.isRelative&&(this._componentsString="."+this._componentsString)),this._componentsString}set componentsString(e){if(this._components.length=0,this._componentsString=e,this._componentsString==null||this._componentsString=="")return;this._componentsString[0]=="."&&(this._isRelative=true,this._componentsString=this._componentsString.substring(1));let t=this._componentsString.split(".");for(let n of t)/^(\-|\+)?([0-9]+|Infinity)$/.test(n)?this._components.push(new i.Component(parseInt(n))):this._components.push(new i.Component(n));}toString(){return this.componentsString}Equals(e){if(e==null||e._components.length!=this._components.length||e.isRelative!=this.isRelative)return false;for(let t=0,n=e._components.length;t<n;t++)if(!e._components[t].Equals(this._components[t]))return false;return true}PathByAppendingComponent(e){let t=new i;return t._components.push(...this._components),t._components.push(e),t}};ci.Path=Fn;Fn.parentId="^";(function(i){class e{constructor(n){this.index=-1,this.name=null,typeof n=="string"?this.name=n:this.index=n;}get isIndex(){return this.index>=0}get isParent(){return this.name==i.parentId}static ToParent(){return new e(i.parentId)}toString(){return this.isIndex?this.index.toString():this.name}Equals(n){return n!=null&&n.isIndex==this.isIndex?this.isIndex?this.index==n.index:this.name==n.name:false}}i.Component=e;})(Fn||(ci.Path=Fn={}));});var hi=O(Sr=>{Object.defineProperty(Sr,"__esModule",{value:true});Sr.Debug=void 0;var _c;(function(i){function e(n,r,a){t(n instanceof r,a);}i.AssertType=e;function t(n,r){if(!n)throw typeof r<"u"&&console.warn(r),console.trace&&console.trace(),new Error("")}i.Assert=t;})(_c||(Sr.Debug=_c={}));});var Ne=O(Nn=>{Object.defineProperty(Nn,"__esModule",{value:true});Nn.throwNullException=Nn.NullException=void 0;var Er=class extends Error{};Nn.NullException=Er;function If(i){throw new Er(`${i} is null or undefined`)}Nn.throwNullException=If;});var Ke=O(Ar=>{Object.defineProperty(Ar,"__esModule",{value:true});Ar.InkObject=void 0;var In=ze(),pi=Ee(),Co=hi(),Vn=re(),br=Ne(),yo=class{constructor(){this.parent=null,this._debugMetadata=null,this._path=null;}get debugMetadata(){return this._debugMetadata===null&&this.parent?this.parent.debugMetadata:this._debugMetadata}set debugMetadata(e){this._debugMetadata=e;}get ownDebugMetadata(){return this._debugMetadata}DebugLineNumberOfPath(e){if(e===null)return null;let t=this.rootContentContainer;if(t){let n=t.ContentAtPath(e).obj;if(n){let r=n.debugMetadata;if(r!==null)return r.startLineNumber}}return null}get path(){if(this._path==null)if(this.parent==null)this._path=new In.Path;else {let e=[],t=this,n=(0, Vn.asOrNull)(t.parent,pi.Container);for(;n!==null;){let r=(0, Vn.asINamedContentOrNull)(t);if(r!=null&&r.hasValidName){if(r.name===null)return (0, br.throwNullException)("namedChild.name");e.unshift(new In.Path.Component(r.name));}else e.unshift(new In.Path.Component(n.content.indexOf(t)));t=n,n=(0, Vn.asOrNull)(n.parent,pi.Container);}this._path=new In.Path(e);}return this._path}ResolvePath(e){if(e===null)return (0, br.throwNullException)("path");if(e.isRelative){let t=(0, Vn.asOrNull)(this,pi.Container);return t===null&&(Co.Debug.Assert(this.parent!==null,"Can't resolve relative path because we don't have a parent"),t=(0, Vn.asOrNull)(this.parent,pi.Container),Co.Debug.Assert(t!==null,"Expected parent to be a container"),Co.Debug.Assert(e.GetComponent(0).isParent),e=e.tail),t===null?(0, br.throwNullException)("nearestContainer"):t.ContentAtPath(e)}else {let t=this.rootContentContainer;return t===null?(0, br.throwNullException)("contentContainer"):t.ContentAtPath(e)}}ConvertPathToRelative(e){let t=this.path,n=Math.min(e.length,t.length),r=-1;for(let l=0;l<n;++l){let u=t.GetComponent(l),c=e.GetComponent(l);if(u.Equals(c))r=l;else break}if(r==-1)return e;let a=t.componentCount-1-r,s=[];for(let l=0;l<a;++l)s.push(In.Path.Component.ToParent());for(let l=r+1;l<e.componentCount;++l)s.push(e.GetComponent(l));return new In.Path(s,true)}CompactPathString(e){let t=null,n=null;return e.isRelative?(n=e.componentsString,t=this.path.PathByAppendingPath(e).componentsString):(n=this.ConvertPathToRelative(e).componentsString,t=e.componentsString),n.length<t.length?n:t}get rootContentContainer(){let e=this;for(;e.parent;)e=e.parent;return (0, Vn.asOrNull)(e,pi.Container)}Copy(){throw Error("Not Implemented: Doesn't support copying")}SetChild(e,t,n){e[t]&&(e[t]=null),e[t]=n,e[t]&&(e[t].parent=this);}Equals(e){return e===this}};Ar.InkObject=yo;});var pn=O(Dr=>{Object.defineProperty(Dr,"__esModule",{value:true});Dr.StringBuilder=void 0;var vo=class{constructor(e){e=typeof e<"u"?e.toString():"",this.string=e;}get Length(){return this.string.length}Append(e){e!==null&&(this.string+=e);}AppendLine(e){typeof e<"u"&&this.Append(e),this.string+=`
`;}AppendFormat(e,...t){this.string+=e.replace(/{(\d+)}/g,(n,r)=>typeof t[r]<"u"?t[r]:n);}toString(){return this.string}Clear(){this.string="";}};Dr.StringBuilder=vo;});var Ye=O(Rn=>{Object.defineProperty(Rn,"__esModule",{value:true});Rn.InkList=Rn.InkListItem=void 0;var Et=Ne(),Vf=pn(),Xe=class i{constructor(){if(this.originName=null,this.itemName=null,typeof arguments[1]<"u"){let e=arguments[0],t=arguments[1];this.originName=e,this.itemName=t;}else if(arguments[0]){let t=arguments[0].toString().split(".");this.originName=t[0],this.itemName=t[1];}}static get Null(){return new i(null,null)}get isNull(){return this.originName==null&&this.itemName==null}get fullName(){return (this.originName!==null?this.originName:"?")+"."+this.itemName}toString(){return this.fullName}Equals(e){if(e instanceof i){let t=e;return t.itemName==this.itemName&&t.originName==this.originName}return false}copy(){return new i(this.originName,this.itemName)}serialized(){return JSON.stringify({originName:this.originName,itemName:this.itemName})}static fromSerializedKey(e){let t=JSON.parse(e);if(!i.isLikeInkListItem(t))return i.Null;let n=t;return new i(n.originName,n.itemName)}static isLikeInkListItem(e){return !(typeof e!="object"||!e.hasOwnProperty("originName")||!e.hasOwnProperty("itemName")||typeof e.originName!="string"&&typeof e.originName!==null||typeof e.itemName!="string"&&typeof e.itemName!==null)}};Rn.InkListItem=Xe;var So=class i extends Map{constructor(){if(super(arguments[0]instanceof i?arguments[0]:[]),this.origins=null,this._originNames=[],arguments[0]instanceof i){let e=arguments[0],t=e.originNames;t!==null&&(this._originNames=t.slice()),e.origins!==null&&(this.origins=e.origins.slice());}else if(typeof arguments[0]=="string"){let e=arguments[0],t=arguments[1];if(this.SetInitialOriginName(e),t.listDefinitions===null)return (0, Et.throwNullException)("originStory.listDefinitions");let n=t.listDefinitions.TryListGetDefinition(e,null);if(n.exists){if(n.result===null)return (0, Et.throwNullException)("def.result");this.origins=[n.result];}else throw new Error("InkList origin could not be found in story when constructing new list: "+e)}else if(typeof arguments[0]=="object"&&arguments[0].hasOwnProperty("Key")&&arguments[0].hasOwnProperty("Value")){let e=arguments[0];this.Add(e.Key,e.Value);}}static FromString(e,t){var n;if(e==null||e=="")return new i;let r=(n=t.listDefinitions)===null||n===void 0?void 0:n.FindSingleItemListWithName(e);if(r)return r.value===null?(0, Et.throwNullException)("listValue.value"):new i(r.value);throw new Error("Could not find the InkListItem from the string '"+e+"' to create an InkList because it doesn't exist in the original list definition in ink.")}AddItem(e,t=null){if(e instanceof Xe){let n=e;if(n.originName==null){this.AddItem(n.itemName);return}if(this.origins===null)return (0, Et.throwNullException)("this.origins");for(let r of this.origins)if(r.name==n.originName){let a=r.TryGetValueForItem(n,0);if(a.exists){this.Add(n,a.result);return}else throw new Error("Could not add the item "+n+" to this list because it doesn't exist in the original list definition in ink.")}throw new Error("Failed to add item to list because the item was from a new list definition that wasn't previously known to this list. Only items from previously known lists can be used, so that the int value can be found.")}else if(e!==null){let n=e,r=null;if(this.origins===null)return (0, Et.throwNullException)("this.origins");for(let a of this.origins){if(n===null)return (0, Et.throwNullException)("itemName");if(a.ContainsItemWithName(n)){if(r!=null)throw new Error("Could not add the item "+n+" to this list because it could come from either "+a.name+" or "+r.name);r=a;}}if(r==null){if(t==null)throw new Error("Could not add the item "+n+" to this list because it isn't known to any list definitions previously associated with this list.");{let a=i.FromString(n,t).orderedItems[0];this.Add(a.Key,a.Value);}}else {let a=new Xe(r.name,n),s=r.ValueForItem(a);this.Add(a,s);}}}ContainsItemNamed(e){for(let[t]of this)if(Xe.fromSerializedKey(t).itemName==e)return true;return false}ContainsKey(e){return this.has(e.serialized())}Add(e,t){let n=e.serialized();if(this.has(n))throw new Error(`The Map already contains an entry for ${e}`);this.set(n,t);}Remove(e){return this.delete(e.serialized())}get Count(){return this.size}get originOfMaxItem(){if(this.origins==null)return null;let e=this.maxItem.Key.originName,t=null;return this.origins.every(n=>n.name==e?(t=n,false):true),t}get originNames(){if(this.Count>0){this._originNames==null&&this.Count>0?this._originNames=[]:(this._originNames||(this._originNames=[]),this._originNames.length=0);for(let[e]of this){let t=Xe.fromSerializedKey(e);if(t.originName===null)return (0, Et.throwNullException)("item.originName");this._originNames.push(t.originName);}}return this._originNames}SetInitialOriginName(e){this._originNames=[e];}SetInitialOriginNames(e){e==null?this._originNames=null:this._originNames=e.slice();}get maxItem(){let e={Key:Xe.Null,Value:0};for(let[t,n]of this){let r=Xe.fromSerializedKey(t);(e.Key.isNull||n>e.Value)&&(e={Key:r,Value:n});}return e}get minItem(){let e={Key:Xe.Null,Value:0};for(let[t,n]of this){let r=Xe.fromSerializedKey(t);(e.Key.isNull||n<e.Value)&&(e={Key:r,Value:n});}return e}get inverse(){let e=new i;if(this.origins!=null)for(let t of this.origins)for(let[n,r]of t.items){let a=Xe.fromSerializedKey(n);this.ContainsKey(a)||e.Add(a,r);}return e}get all(){let e=new i;if(this.origins!=null)for(let t of this.origins)for(let[n,r]of t.items){let a=Xe.fromSerializedKey(n);e.set(a.serialized(),r);}return e}Union(e){let t=new i(this);for(let[n,r]of e)t.set(n,r);return t}Intersect(e){let t=new i;for(let[n,r]of this)e.has(n)&&t.set(n,r);return t}HasIntersection(e){for(let[t]of this)if(e.has(t))return true;return false}Without(e){let t=new i(this);for(let[n]of e)t.delete(n);return t}Contains(e){if(typeof e=="string")return this.ContainsItemNamed(e);let t=e;if(t.size==0||this.size==0)return false;for(let[n]of t)if(!this.has(n))return false;return true}GreaterThan(e){return this.Count==0?false:e.Count==0?true:this.minItem.Value>e.maxItem.Value}GreaterThanOrEquals(e){return this.Count==0?false:e.Count==0?true:this.minItem.Value>=e.minItem.Value&&this.maxItem.Value>=e.maxItem.Value}LessThan(e){return e.Count==0?false:this.Count==0?true:this.maxItem.Value<e.minItem.Value}LessThanOrEquals(e){return e.Count==0?false:this.Count==0?true:this.maxItem.Value<=e.maxItem.Value&&this.minItem.Value<=e.minItem.Value}MaxAsList(){return this.Count>0?new i(this.maxItem):new i}MinAsList(){return this.Count>0?new i(this.minItem):new i}ListWithSubRange(e,t){if(this.Count==0)return new i;let n=this.orderedItems,r=0,a=Number.MAX_SAFE_INTEGER;Number.isInteger(e)?r=e:e instanceof i&&e.Count>0&&(r=e.minItem.Value),Number.isInteger(t)?a=t:t instanceof i&&t.Count>0&&(a=t.maxItem.Value);let s=new i;s.SetInitialOriginNames(this.originNames);for(let o of n)o.Value>=r&&o.Value<=a&&s.Add(o.Key,o.Value);return s}Equals(e){if(!(e instanceof i)||e.Count!=this.Count)return false;for(let[t]of this)if(!e.has(t))return false;return true}get orderedItems(){let e=new Array;for(let[t,n]of this){let r=Xe.fromSerializedKey(t);e.push({Key:r,Value:n});}return e.sort((t,n)=>t.Key.originName===null?(0, Et.throwNullException)("x.Key.originName"):n.Key.originName===null?(0, Et.throwNullException)("y.Key.originName"):t.Value==n.Value?t.Key.originName.localeCompare(n.Key.originName):t.Value<n.Value?-1:t.Value>n.Value?1:0),e}get singleItem(){for(let e of this.orderedItems)return e.Key;return null}toString(){let e=this.orderedItems,t=new Vf.StringBuilder;for(let n=0;n<e.length;n++){n>0&&t.Append(", ");let r=e[n].Key;if(r.itemName===null)return (0, Et.throwNullException)("item.itemName");t.Append(r.itemName);}return t.toString()}valueOf(){return NaN}};Rn.InkList=So;});var di=O(xr=>{Object.defineProperty(xr,"__esModule",{value:true});xr.StoryException=void 0;var Eo=class extends Error{constructor(e){super(e),this.useEndLineNumber=false,this.message=e,this.name="StoryException";}};xr.StoryException=Eo;});var kn=O(Ut=>{Object.defineProperty(Ut,"__esModule",{value:true});Ut.tryParseFloat=Ut.tryParseInt=Ut.tryGetValueFromMap=void 0;function Rf(i,e,t){if(i===null)return {result:t,exists:false};let n=i.get(e);return typeof n>"u"?{result:t,exists:false}:{result:n,exists:true}}Ut.tryGetValueFromMap=Rf;function kf(i,e=0){let t=parseInt(i);return Number.isNaN(t)?{result:e,exists:false}:{result:t,exists:true}}Ut.tryParseInt=kf;function Lf(i,e=0){let t=parseFloat(i);return Number.isNaN(t)?{result:e,exists:false}:{result:t,exists:true}}Ut.tryParseFloat=Lf;});var me=O(Ce=>{Object.defineProperty(Ce,"__esModule",{value:true});Ce.ValueType=Ce.ListValue=Ce.VariablePointerValue=Ce.DivertTargetValue=Ce.StringValue=Ce.FloatValue=Ce.IntValue=Ce.BoolValue=Ce.Value=Ce.AbstractValue=void 0;var wc=Ke(),Tc=ze(),dn=Ye(),Bf=di(),fi=re(),Oc=kn(),ot=Ne(),_r=class i extends wc.InkObject{static Create(e,t){if(t){if(t===he.Int&&Number.isInteger(Number(e)))return new At(Number(e));if(t===he.Float&&!isNaN(e))return new Dt(Number(e))}if(typeof e=="boolean")return new Ln(!!e);if(typeof e=="string")return new Rt(String(e));if(Number.isInteger(Number(e)))return new At(Number(e));if(isNaN(e)){if(e instanceof Tc.Path)return new wr((0, fi.asOrThrows)(e,Tc.Path));if(e instanceof dn.InkList)return new Tr((0, fi.asOrThrows)(e,dn.InkList))}else return new Dt(Number(e));return null}Copy(){return (0, fi.asOrThrows)(i.Create(this.valueObject),wc.InkObject)}BadCastException(e){return new Bf.StoryException("Can't cast "+this.valueObject+" from "+this.valueType+" to "+e)}};Ce.AbstractValue=_r;var bt=class extends _r{constructor(e){super(),this.value=e;}get valueObject(){return this.value}toString(){return this.value===null?(0, ot.throwNullException)("Value.value"):this.value.toString()}};Ce.Value=bt;var Ln=class extends bt{constructor(e){super(e||false);}get isTruthy(){return !!this.value}get valueType(){return he.Bool}Cast(e){if(this.value===null)return (0, ot.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==he.Int)return new At(this.value?1:0);if(e==he.Float)return new Dt(this.value?1:0);if(e==he.String)return new Rt(this.value?"true":"false");throw this.BadCastException(e)}toString(){return this.value?"true":"false"}};Ce.BoolValue=Ln;var At=class extends bt{constructor(e){super(e||0);}get isTruthy(){return this.value!=0}get valueType(){return he.Int}Cast(e){if(this.value===null)return (0, ot.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==he.Bool)return new Ln(this.value!==0);if(e==he.Float)return new Dt(this.value);if(e==he.String)return new Rt(""+this.value);throw this.BadCastException(e)}};Ce.IntValue=At;var Dt=class extends bt{constructor(e){super(e||0);}get isTruthy(){return this.value!=0}get valueType(){return he.Float}Cast(e){if(this.value===null)return (0, ot.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==he.Bool)return new Ln(this.value!==0);if(e==he.Int)return new At(this.value);if(e==he.String)return new Rt(""+this.value);throw this.BadCastException(e)}};Ce.FloatValue=Dt;var Rt=class extends bt{constructor(e){if(super(e||""),this._isNewline=this.value==`
`,this._isInlineWhitespace=true,this.value===null)return (0, ot.throwNullException)("Value.value");this.value.length>0&&this.value.split("").every(t=>t!=" "&&t!=" "?(this._isInlineWhitespace=false,false):true);}get valueType(){return he.String}get isTruthy(){return this.value===null?(0, ot.throwNullException)("Value.value"):this.value.length>0}get isNewline(){return this._isNewline}get isInlineWhitespace(){return this._isInlineWhitespace}get isNonWhitespace(){return !this.isNewline&&!this.isInlineWhitespace}Cast(e){if(e==this.valueType)return this;if(e==he.Int){let t=(0, Oc.tryParseInt)(this.value);if(t.exists)return new At(t.result);throw this.BadCastException(e)}if(e==he.Float){let t=(0, Oc.tryParseFloat)(this.value);if(t.exists)return new Dt(t.result);throw this.BadCastException(e)}throw this.BadCastException(e)}};Ce.StringValue=Rt;var wr=class extends bt{constructor(e=null){super(e);}get valueType(){return he.DivertTarget}get targetPath(){return this.value===null?(0, ot.throwNullException)("Value.value"):this.value}set targetPath(e){this.value=e;}get isTruthy(){throw new Error("Shouldn't be checking the truthiness of a divert target")}Cast(e){if(e==this.valueType)return this;throw this.BadCastException(e)}toString(){return "DivertTargetValue("+this.targetPath+")"}};Ce.DivertTargetValue=wr;var bo=class i extends bt{constructor(e,t=-1){super(e),this._contextIndex=t;}get contextIndex(){return this._contextIndex}set contextIndex(e){this._contextIndex=e;}get variableName(){return this.value===null?(0, ot.throwNullException)("Value.value"):this.value}set variableName(e){this.value=e;}get valueType(){return he.VariablePointer}get isTruthy(){throw new Error("Shouldn't be checking the truthiness of a variable pointer")}Cast(e){if(e==this.valueType)return this;throw this.BadCastException(e)}toString(){return "VariablePointerValue("+this.variableName+")"}Copy(){return new i(this.variableName,this.contextIndex)}};Ce.VariablePointerValue=bo;var Tr=class i extends bt{get isTruthy(){return this.value===null?(0, ot.throwNullException)("this.value"):this.value.Count>0}get valueType(){return he.List}Cast(e){if(this.value===null)return (0, ot.throwNullException)("Value.value");if(e==he.Int){let t=this.value.maxItem;return t.Key.isNull?new At(0):new At(t.Value)}else if(e==he.Float){let t=this.value.maxItem;return t.Key.isNull?new Dt(0):new Dt(t.Value)}else if(e==he.String){let t=this.value.maxItem;return t.Key.isNull?new Rt(""):new Rt(t.Key.toString())}if(e==this.valueType)return this;throw this.BadCastException(e)}constructor(e,t){super(null),!e&&!t?this.value=new dn.InkList:e instanceof dn.InkList?this.value=new dn.InkList(e):e instanceof dn.InkListItem&&typeof t=="number"&&(this.value=new dn.InkList({Key:e,Value:t}));}static RetainListOriginsForAssignment(e,t){let n=(0, fi.asOrNull)(e,i),r=(0, fi.asOrNull)(t,i);if(r&&r.value===null)return (0, ot.throwNullException)("newList.value");if(n&&n.value===null)return (0, ot.throwNullException)("oldList.value");n&&r&&r.value.Count==0&&r.value.SetInitialOriginNames(n.value.originNames);}};Ce.ListValue=Tr;var he;(function(i){i[i.Bool=-1]="Bool",i[i.Int=0]="Int",i[i.Float=1]="Float",i[i.List=2]="List",i[i.String=3]="String",i[i.DivertTarget=4]="DivertTarget",i[i.VariablePointer=5]="VariablePointer";})(he||(Ce.ValueType=he={}));});var Pc=O(Or=>{Object.defineProperty(Or,"__esModule",{value:true});Or.SearchResult=void 0;var Wf=Ee(),Ao=class i{constructor(){this.obj=null,this.approximate=false;}get correctObj(){return this.approximate?null:this.obj}get container(){return this.obj instanceof Wf.Container?this.obj:null}copy(){let e=new i;return e.obj=this.obj,e.approximate=this.approximate,e}};Or.SearchResult=Ao;});var Ee=O(mi=>{Object.defineProperty(mi,"__esModule",{value:true});mi.Container=void 0;var jf=me(),Fc=Ne(),qf=pn(),Bn=Ke(),Mf=Pc(),Nc=ze(),Ic=hi(),$f=kn(),zt=re(),gi=class i extends Bn.InkObject{constructor(){super(...arguments),this.name=null,this._content=[],this.namedContent=new Map,this.visitsShouldBeCounted=false,this.turnIndexShouldBeCounted=false,this.countingAtStartOnly=false,this._pathToFirstLeafContent=null;}get hasValidName(){return this.name!=null&&this.name.length>0}get content(){return this._content}set content(e){this.AddContent(e);}get namedOnlyContent(){let e=new Map;for(let[t,n]of this.namedContent){let r=(0, zt.asOrThrows)(n,Bn.InkObject);e.set(t,r);}for(let t of this.content){let n=(0, zt.asINamedContentOrNull)(t);n!=null&&n.hasValidName&&e.delete(n.name);}return e.size==0&&(e=null),e}set namedOnlyContent(e){let t=this.namedOnlyContent;if(t!=null)for(let[n]of t)this.namedContent.delete(n);if(e!=null)for(let[,n]of e){let r=(0, zt.asINamedContentOrNull)(n);r!=null&&this.AddToNamedContentOnly(r);}}get countFlags(){let e=0;return this.visitsShouldBeCounted&&(e|=i.CountFlags.Visits),this.turnIndexShouldBeCounted&&(e|=i.CountFlags.Turns),this.countingAtStartOnly&&(e|=i.CountFlags.CountStartOnly),e==i.CountFlags.CountStartOnly&&(e=0),e}set countFlags(e){let t=e;(t&i.CountFlags.Visits)>0&&(this.visitsShouldBeCounted=true),(t&i.CountFlags.Turns)>0&&(this.turnIndexShouldBeCounted=true),(t&i.CountFlags.CountStartOnly)>0&&(this.countingAtStartOnly=true);}get pathToFirstLeafContent(){return this._pathToFirstLeafContent==null&&(this._pathToFirstLeafContent=this.path.PathByAppendingPath(this.internalPathToFirstLeafContent)),this._pathToFirstLeafContent}get internalPathToFirstLeafContent(){let e=[],t=this;for(;t instanceof i;)t.content.length>0&&(e.push(new Nc.Path.Component(0)),t=t.content[0]);return new Nc.Path(e)}AddContent(e){if(e instanceof Array){let t=e;for(let n of t)this.AddContent(n);}else {let t=e;if(this._content.push(t),t.parent)throw new Error("content is already in "+t.parent);t.parent=this,this.TryAddNamedContent(t);}}TryAddNamedContent(e){let t=(0, zt.asINamedContentOrNull)(e);t!=null&&t.hasValidName&&this.AddToNamedContentOnly(t);}AddToNamedContentOnly(e){Ic.Debug.AssertType(e,Bn.InkObject,"Can only add Runtime.Objects to a Runtime.Container");let t=(0, zt.asOrThrows)(e,Bn.InkObject);if(t.parent=this,e.name===null)return (0, Fc.throwNullException)("namedContentObj.name");this.namedContent.set(e.name,e);}ContentAtPath(e,t=0,n=-1){n==-1&&(n=e.length);let r=new Mf.SearchResult;r.approximate=false;let a=this,s=this;for(let o=t;o<n;++o){let l=e.GetComponent(o);if(a==null){r.approximate=true;break}let u=a.ContentWithPathComponent(l);if(u==null){r.approximate=true;break}let c=(0, zt.asOrNull)(u,i);if(o<n-1&&c==null){r.approximate=true;break}s=u,a=c;}return r.obj=s,r}InsertContent(e,t){if(this.content.splice(t,0,e),e.parent)throw new Error("content is already in "+e.parent);e.parent=this,this.TryAddNamedContent(e);}AddContentsOfContainer(e){this.content.push(...e.content);for(let t of e.content)t.parent=this,this.TryAddNamedContent(t);}ContentWithPathComponent(e){if(e.isIndex)return e.index>=0&&e.index<this.content.length?this.content[e.index]:null;if(e.isParent)return this.parent;{if(e.name===null)return (0, Fc.throwNullException)("component.name");let t=(0, $f.tryGetValueFromMap)(this.namedContent,e.name,null);return t.exists?(0, zt.asOrThrows)(t.result,Bn.InkObject):null}}BuildStringOfHierarchy(){let e;if(arguments.length==0)return e=new qf.StringBuilder,this.BuildStringOfHierarchy(e,0,null),e.toString();e=arguments[0];let t=arguments[1],n=arguments[2];function r(){for(let o=0;o<4*t;++o)e.Append(" ");}r(),e.Append("["),this.hasValidName&&e.AppendFormat(" ({0})",this.name),this==n&&e.Append(" <---"),e.AppendLine(),t++;for(let s=0;s<this.content.length;++s){let o=this.content[s];o instanceof i?o.BuildStringOfHierarchy(e,t,n):(r(),o instanceof jf.StringValue?(e.Append('"'),e.Append(o.toString().replace(`
`,"\\n")),e.Append('"')):e.Append(o.toString())),s!=this.content.length-1&&e.Append(","),!(o instanceof i)&&o==n&&e.Append(" <---"),e.AppendLine();}let a=new Map;for(let[s,o]of this.namedContent)this.content.indexOf((0, zt.asOrThrows)(o,Bn.InkObject))>=0||a.set(s,o);if(a.size>0){r(),e.AppendLine("-- named: --");for(let[,s]of a)Ic.Debug.AssertType(s,i,"Can only print out named Containers"),s.BuildStringOfHierarchy(e,t,n),e.AppendLine();}t--,r(),e.Append("]");}};mi.Container=gi;(function(i){(function(t){t[t.Start=0]="Start",t[t.Visits=1]="Visits",t[t.Turns=2]="Turns",t[t.CountStartOnly=4]="CountStartOnly";})(i.CountFlags||(i.CountFlags={}));})(gi||(mi.Container=gi={}));});var Ie=O(yi=>{Object.defineProperty(yi,"__esModule",{value:true});yi.ControlCommand=void 0;var Gf=Ke(),Ci=class i extends Gf.InkObject{get commandType(){return this._commandType}constructor(e=i.CommandType.NotSet){super(),this._commandType=e;}Copy(){return new i(this.commandType)}static EvalStart(){return new i(i.CommandType.EvalStart)}static EvalOutput(){return new i(i.CommandType.EvalOutput)}static EvalEnd(){return new i(i.CommandType.EvalEnd)}static Duplicate(){return new i(i.CommandType.Duplicate)}static PopEvaluatedValue(){return new i(i.CommandType.PopEvaluatedValue)}static PopFunction(){return new i(i.CommandType.PopFunction)}static PopTunnel(){return new i(i.CommandType.PopTunnel)}static BeginString(){return new i(i.CommandType.BeginString)}static EndString(){return new i(i.CommandType.EndString)}static NoOp(){return new i(i.CommandType.NoOp)}static ChoiceCount(){return new i(i.CommandType.ChoiceCount)}static Turns(){return new i(i.CommandType.Turns)}static TurnsSince(){return new i(i.CommandType.TurnsSince)}static ReadCount(){return new i(i.CommandType.ReadCount)}static Random(){return new i(i.CommandType.Random)}static SeedRandom(){return new i(i.CommandType.SeedRandom)}static VisitIndex(){return new i(i.CommandType.VisitIndex)}static SequenceShuffleIndex(){return new i(i.CommandType.SequenceShuffleIndex)}static StartThread(){return new i(i.CommandType.StartThread)}static Done(){return new i(i.CommandType.Done)}static End(){return new i(i.CommandType.End)}static ListFromInt(){return new i(i.CommandType.ListFromInt)}static ListRange(){return new i(i.CommandType.ListRange)}static ListRandom(){return new i(i.CommandType.ListRandom)}static BeginTag(){return new i(i.CommandType.BeginTag)}static EndTag(){return new i(i.CommandType.EndTag)}toString(){return "ControlCommand "+this.commandType.toString()}};yi.ControlCommand=Ci;(function(i){(function(t){t[t.NotSet=-1]="NotSet",t[t.EvalStart=0]="EvalStart",t[t.EvalOutput=1]="EvalOutput",t[t.EvalEnd=2]="EvalEnd",t[t.Duplicate=3]="Duplicate",t[t.PopEvaluatedValue=4]="PopEvaluatedValue",t[t.PopFunction=5]="PopFunction",t[t.PopTunnel=6]="PopTunnel",t[t.BeginString=7]="BeginString",t[t.EndString=8]="EndString",t[t.NoOp=9]="NoOp",t[t.ChoiceCount=10]="ChoiceCount",t[t.Turns=11]="Turns",t[t.TurnsSince=12]="TurnsSince",t[t.ReadCount=13]="ReadCount",t[t.Random=14]="Random",t[t.SeedRandom=15]="SeedRandom",t[t.VisitIndex=16]="VisitIndex",t[t.SequenceShuffleIndex=17]="SequenceShuffleIndex",t[t.StartThread=18]="StartThread",t[t.Done=19]="Done",t[t.End=20]="End",t[t.ListFromInt=21]="ListFromInt",t[t.ListRange=22]="ListRange",t[t.ListRandom=23]="ListRandom",t[t.BeginTag=24]="BeginTag",t[t.EndTag=25]="EndTag",t[t.TOTAL_VALUES=26]="TOTAL_VALUES";})(i.CommandType||(i.CommandType={}));})(Ci||(yi.ControlCommand=Ci={}));});var lt=O(Pr=>{Object.defineProperty(Pr,"__esModule",{value:true});Pr.Expression=void 0;var Vc=Ee(),Do=Ie(),Hf=fe(),xo=class extends Hf.ParsedObject{constructor(){super(...arguments),this._prototypeRuntimeConstantExpression=null,this.outputWhenComplete=false,this.GenerateRuntimeObject=()=>{let e=new Vc.Container;return e.AddContent(Do.ControlCommand.EvalStart()),this.GenerateIntoContainer(e),this.outputWhenComplete&&e.AddContent(Do.ControlCommand.EvalOutput()),e.AddContent(Do.ControlCommand.EvalEnd()),e},this.GenerateConstantIntoContainer=e=>{this._prototypeRuntimeConstantExpression===null&&(this._prototypeRuntimeConstantExpression=new Vc.Container,this.GenerateIntoContainer(this._prototypeRuntimeConstantExpression));for(let t of this._prototypeRuntimeConstantExpression.content){let n=t.Copy();n&&e.AddContent(n);}},this.toString=()=>"No string value in JavaScript.";}get typeName(){return "Expression"}Equals(e){return false}};Pr.Expression=xo;});var fn=O(Fr=>{Object.defineProperty(Fr,"__esModule",{value:true});Fr.Void=void 0;var Jf=Ke(),_o=class extends Jf.InkObject{toString(){return "Void"}};Fr.Void=_o;});var xt=O(Ir=>{Object.defineProperty(Ir,"__esModule",{value:true});Ir.NativeFunctionCall=void 0;var R=me(),vi=di(),Uf=fn(),Nr=Ye(),zf=Ke(),ut=re(),Qe=Ne(),J=class i extends zf.InkObject{static CallWithName(e){return new i(e)}static CallExistsWithName(e){return this.GenerateNativeFunctionsIfNecessary(),this._nativeFunctions.get(e)}get name(){return this._name===null?(0, Qe.throwNullException)("NativeFunctionCall._name"):this._name}set name(e){this._name=e,this._isPrototype||(i._nativeFunctions===null?(0, Qe.throwNullException)("NativeFunctionCall._nativeFunctions"):this._prototype=i._nativeFunctions.get(this._name)||null);}get numberOfParameters(){return this._prototype?this._prototype.numberOfParameters:this._numberOfParameters}set numberOfParameters(e){this._numberOfParameters=e;}Call(e){if(this._prototype)return this._prototype.Call(e);if(this.numberOfParameters!=e.length)throw new Error("Unexpected number of parameters");let t=false;for(let a of e){if(a instanceof Uf.Void)throw new vi.StoryException("Attempting to perform "+this.name+' on a void value. Did you forget to "return" a value from a function you called here?');a instanceof R.ListValue&&(t=true);}if(e.length==2&&t)return this.CallBinaryListOperation(e);let n=this.CoerceValuesToSingleType(e),r=n[0].valueType;return r==R.ValueType.Int?this.CallType(n):r==R.ValueType.Float?this.CallType(n):r==R.ValueType.String?this.CallType(n):r==R.ValueType.DivertTarget?this.CallType(n):r==R.ValueType.List?this.CallType(n):null}CallType(e){let t=(0, ut.asOrThrows)(e[0],R.Value),n=t.valueType,r=t,a=e.length;if(a==2||a==1){if(this._operationFuncs===null)return (0, Qe.throwNullException)("NativeFunctionCall._operationFuncs");let s=this._operationFuncs.get(n);if(!s){let o=R.ValueType[n];throw new vi.StoryException("Cannot perform operation "+this.name+" on "+o)}if(a==2){let l=(0, ut.asOrThrows)(e[1],R.Value),u=s;if(r.value===null||l.value===null)return (0, Qe.throwNullException)("NativeFunctionCall.Call BinaryOp values");let c=u(r.value,l.value);return R.Value.Create(c)}else {let o=s;if(r.value===null)return (0, Qe.throwNullException)("NativeFunctionCall.Call UnaryOp value");let l=o(r.value);return this.name===i.Int?R.Value.Create(l,R.ValueType.Int):this.name===i.Float?R.Value.Create(l,R.ValueType.Float):R.Value.Create(l,t.valueType)}}else throw new Error("Unexpected number of parameters to NativeFunctionCall: "+e.length)}CallBinaryListOperation(e){if((this.name=="+"||this.name=="-")&&e[0]instanceof R.ListValue&&e[1]instanceof R.IntValue)return this.CallListIncrementOperation(e);let t=(0, ut.asOrThrows)(e[0],R.Value),n=(0, ut.asOrThrows)(e[1],R.Value);if((this.name=="&&"||this.name=="||")&&(t.valueType!=R.ValueType.List||n.valueType!=R.ValueType.List)){if(this._operationFuncs===null)return (0, Qe.throwNullException)("NativeFunctionCall._operationFuncs");let r=this._operationFuncs.get(R.ValueType.Int);if(r===null)return (0, Qe.throwNullException)("NativeFunctionCall.CallBinaryListOperation op");let a=(0, ut.asBooleanOrThrows)(r(t.isTruthy?1:0,n.isTruthy?1:0));return new R.BoolValue(a)}if(t.valueType==R.ValueType.List&&n.valueType==R.ValueType.List)return this.CallType([t,n]);throw new vi.StoryException("Can not call use "+this.name+" operation on "+R.ValueType[t.valueType]+" and "+R.ValueType[n.valueType])}CallListIncrementOperation(e){let t=(0, ut.asOrThrows)(e[0],R.ListValue),n=(0, ut.asOrThrows)(e[1],R.IntValue),r=new Nr.InkList;if(t.value===null)return (0, Qe.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value");for(let[a,s]of t.value){let o=Nr.InkListItem.fromSerializedKey(a);if(this._operationFuncs===null)return (0, Qe.throwNullException)("NativeFunctionCall._operationFuncs");let l=this._operationFuncs.get(R.ValueType.Int);if(n.value===null)return (0, Qe.throwNullException)("NativeFunctionCall.CallListIncrementOperation intVal.value");let u=l(s,n.value),c=null;if(t.value.origins===null)return (0, Qe.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value.origins");for(let h of t.value.origins)if(h.name==o.originName){c=h;break}if(c!=null){let h=c.TryGetItemWithValue(u,Nr.InkListItem.Null);h.exists&&r.Add(h.result,u);}}return new R.ListValue(r)}CoerceValuesToSingleType(e){let t=R.ValueType.Int,n=null;for(let a of e){let s=(0, ut.asOrThrows)(a,R.Value);s.valueType>t&&(t=s.valueType),s.valueType==R.ValueType.List&&(n=(0, ut.asOrNull)(s,R.ListValue));}let r=[];if(R.ValueType[t]==R.ValueType[R.ValueType.List])for(let a of e){let s=(0, ut.asOrThrows)(a,R.Value);if(s.valueType==R.ValueType.List)r.push(s);else if(s.valueType==R.ValueType.Int){let o=parseInt(s.valueObject);if(n=(0, ut.asOrThrows)(n,R.ListValue),n.value===null)return (0, Qe.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType specialCaseList.value");let l=n.value.originOfMaxItem;if(l===null)return (0, Qe.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType list");let u=l.TryGetItemWithValue(o,Nr.InkListItem.Null);if(u.exists){let c=new R.ListValue(u.result,o);r.push(c);}else throw new vi.StoryException("Could not find List item with the value "+o+" in "+l.name)}else {let o=R.ValueType[s.valueType];throw new vi.StoryException("Cannot mix Lists and "+o+" values in this operation")}}else for(let a of e){let o=(0, ut.asOrThrows)(a,R.Value).Cast(t);r.push(o);}return r}constructor(){if(super(),this._name=null,this._numberOfParameters=0,this._prototype=null,this._isPrototype=false,this._operationFuncs=null,arguments.length===0)i.GenerateNativeFunctionsIfNecessary();else if(arguments.length===1){let e=arguments[0];i.GenerateNativeFunctionsIfNecessary(),this.name=e;}else if(arguments.length===2){let e=arguments[0],t=arguments[1];this._isPrototype=true,this.name=e,this.numberOfParameters=t;}}static Identity(e){return e}static GenerateNativeFunctionsIfNecessary(){if(this._nativeFunctions==null){this._nativeFunctions=new Map,this.AddIntBinaryOp(this.Add,(n,r)=>n+r),this.AddIntBinaryOp(this.Subtract,(n,r)=>n-r),this.AddIntBinaryOp(this.Multiply,(n,r)=>n*r),this.AddIntBinaryOp(this.Divide,(n,r)=>Math.floor(n/r)),this.AddIntBinaryOp(this.Mod,(n,r)=>n%r),this.AddIntUnaryOp(this.Negate,n=>-n),this.AddIntBinaryOp(this.Equal,(n,r)=>n==r),this.AddIntBinaryOp(this.Greater,(n,r)=>n>r),this.AddIntBinaryOp(this.Less,(n,r)=>n<r),this.AddIntBinaryOp(this.GreaterThanOrEquals,(n,r)=>n>=r),this.AddIntBinaryOp(this.LessThanOrEquals,(n,r)=>n<=r),this.AddIntBinaryOp(this.NotEquals,(n,r)=>n!=r),this.AddIntUnaryOp(this.Not,n=>n==0),this.AddIntBinaryOp(this.And,(n,r)=>n!=0&&r!=0),this.AddIntBinaryOp(this.Or,(n,r)=>n!=0||r!=0),this.AddIntBinaryOp(this.Max,(n,r)=>Math.max(n,r)),this.AddIntBinaryOp(this.Min,(n,r)=>Math.min(n,r)),this.AddIntBinaryOp(this.Pow,(n,r)=>Math.pow(n,r)),this.AddIntUnaryOp(this.Floor,i.Identity),this.AddIntUnaryOp(this.Ceiling,i.Identity),this.AddIntUnaryOp(this.Int,i.Identity),this.AddIntUnaryOp(this.Float,n=>n),this.AddFloatBinaryOp(this.Add,(n,r)=>n+r),this.AddFloatBinaryOp(this.Subtract,(n,r)=>n-r),this.AddFloatBinaryOp(this.Multiply,(n,r)=>n*r),this.AddFloatBinaryOp(this.Divide,(n,r)=>n/r),this.AddFloatBinaryOp(this.Mod,(n,r)=>n%r),this.AddFloatUnaryOp(this.Negate,n=>-n),this.AddFloatBinaryOp(this.Equal,(n,r)=>n==r),this.AddFloatBinaryOp(this.Greater,(n,r)=>n>r),this.AddFloatBinaryOp(this.Less,(n,r)=>n<r),this.AddFloatBinaryOp(this.GreaterThanOrEquals,(n,r)=>n>=r),this.AddFloatBinaryOp(this.LessThanOrEquals,(n,r)=>n<=r),this.AddFloatBinaryOp(this.NotEquals,(n,r)=>n!=r),this.AddFloatUnaryOp(this.Not,n=>n==0),this.AddFloatBinaryOp(this.And,(n,r)=>n!=0&&r!=0),this.AddFloatBinaryOp(this.Or,(n,r)=>n!=0||r!=0),this.AddFloatBinaryOp(this.Max,(n,r)=>Math.max(n,r)),this.AddFloatBinaryOp(this.Min,(n,r)=>Math.min(n,r)),this.AddFloatBinaryOp(this.Pow,(n,r)=>Math.pow(n,r)),this.AddFloatUnaryOp(this.Floor,n=>Math.floor(n)),this.AddFloatUnaryOp(this.Ceiling,n=>Math.ceil(n)),this.AddFloatUnaryOp(this.Int,n=>Math.floor(n)),this.AddFloatUnaryOp(this.Float,i.Identity),this.AddStringBinaryOp(this.Add,(n,r)=>n+r),this.AddStringBinaryOp(this.Equal,(n,r)=>n===r),this.AddStringBinaryOp(this.NotEquals,(n,r)=>n!==r),this.AddStringBinaryOp(this.Has,(n,r)=>n.includes(r)),this.AddStringBinaryOp(this.Hasnt,(n,r)=>!n.includes(r)),this.AddListBinaryOp(this.Add,(n,r)=>n.Union(r)),this.AddListBinaryOp(this.Subtract,(n,r)=>n.Without(r)),this.AddListBinaryOp(this.Has,(n,r)=>n.Contains(r)),this.AddListBinaryOp(this.Hasnt,(n,r)=>!n.Contains(r)),this.AddListBinaryOp(this.Intersect,(n,r)=>n.Intersect(r)),this.AddListBinaryOp(this.Equal,(n,r)=>n.Equals(r)),this.AddListBinaryOp(this.Greater,(n,r)=>n.GreaterThan(r)),this.AddListBinaryOp(this.Less,(n,r)=>n.LessThan(r)),this.AddListBinaryOp(this.GreaterThanOrEquals,(n,r)=>n.GreaterThanOrEquals(r)),this.AddListBinaryOp(this.LessThanOrEquals,(n,r)=>n.LessThanOrEquals(r)),this.AddListBinaryOp(this.NotEquals,(n,r)=>!n.Equals(r)),this.AddListBinaryOp(this.And,(n,r)=>n.Count>0&&r.Count>0),this.AddListBinaryOp(this.Or,(n,r)=>n.Count>0||r.Count>0),this.AddListUnaryOp(this.Not,n=>n.Count==0?1:0),this.AddListUnaryOp(this.Invert,n=>n.inverse),this.AddListUnaryOp(this.All,n=>n.all),this.AddListUnaryOp(this.ListMin,n=>n.MinAsList()),this.AddListUnaryOp(this.ListMax,n=>n.MaxAsList()),this.AddListUnaryOp(this.Count,n=>n.Count),this.AddListUnaryOp(this.ValueOfList,n=>n.maxItem.Value);let e=(n,r)=>n.Equals(r),t=(n,r)=>!n.Equals(r);this.AddOpToNativeFunc(this.Equal,2,R.ValueType.DivertTarget,e),this.AddOpToNativeFunc(this.NotEquals,2,R.ValueType.DivertTarget,t);}}AddOpFuncForType(e,t){this._operationFuncs==null&&(this._operationFuncs=new Map),this._operationFuncs.set(e,t);}static AddOpToNativeFunc(e,t,n,r){if(this._nativeFunctions===null)return (0, Qe.throwNullException)("NativeFunctionCall._nativeFunctions");let a=this._nativeFunctions.get(e);a||(a=new i(e,t),this._nativeFunctions.set(e,a)),a.AddOpFuncForType(n,r);}static AddIntBinaryOp(e,t){this.AddOpToNativeFunc(e,2,R.ValueType.Int,t);}static AddIntUnaryOp(e,t){this.AddOpToNativeFunc(e,1,R.ValueType.Int,t);}static AddFloatBinaryOp(e,t){this.AddOpToNativeFunc(e,2,R.ValueType.Float,t);}static AddFloatUnaryOp(e,t){this.AddOpToNativeFunc(e,1,R.ValueType.Float,t);}static AddStringBinaryOp(e,t){this.AddOpToNativeFunc(e,2,R.ValueType.String,t);}static AddListBinaryOp(e,t){this.AddOpToNativeFunc(e,2,R.ValueType.List,t);}static AddListUnaryOp(e,t){this.AddOpToNativeFunc(e,1,R.ValueType.List,t);}toString(){return 'Native "'+this.name+'"'}};Ir.NativeFunctionCall=J;J.Add="+";J.Subtract="-";J.Divide="/";J.Multiply="*";J.Mod="%";J.Negate="_";J.Equal="==";J.Greater=">";J.Less="<";J.GreaterThanOrEquals=">=";J.LessThanOrEquals="<=";J.NotEquals="!=";J.Not="!";J.And="&&";J.Or="||";J.Min="MIN";J.Max="MAX";J.Pow="POW";J.Floor="FLOOR";J.Ceiling="CEILING";J.Int="INT";J.Float="FLOAT";J.Has="?";J.Hasnt="!?";J.Intersect="^";J.ListMin="LIST_MIN";J.ListMax="LIST_MAX";J.All="LIST_ALL";J.Count="LIST_COUNT";J.ValueOfList="LIST_VALUE";J.Invert="LIST_INVERT";J._nativeFunctions=null;});var Rr=O(Vr=>{Object.defineProperty(Vr,"__esModule",{value:true});Vr.NumberExpression=void 0;var Kf=lt(),wo=me(),Xf=re(),To=class i extends Kf.Expression{constructor(e,t){if(super(),this.isInt=()=>this.subtype=="int",this.isFloat=()=>this.subtype=="float",this.isBool=()=>this.subtype=="bool",this.GenerateIntoContainer=n=>{this.isInt()?n.AddContent(new wo.IntValue(this.value)):this.isFloat()?n.AddContent(new wo.FloatValue(this.value)):this.isBool()&&n.AddContent(new wo.BoolValue(this.value));},this.toString=()=>String(this.value),typeof e=="number"&&!Number.isNaN(e)||typeof e=="boolean")this.value=e,this.subtype=t;else throw new Error("Unexpected object type in NumberExpression.")}get typeName(){return "Number"}Equals(e){let t=(0, Xf.asOrNull)(e,i);return t?t.subtype==this.subtype&&t.value==this.value:false}};Vr.NumberExpression=To;});var Oo=O(kr=>{Object.defineProperty(kr,"__esModule",{value:true});kr.UnaryExpression=void 0;var Yf=lt(),Qf=xt(),Wn=Rr(),Zf=re(),Si=class extends Yf.Expression{get nativeNameForOp(){return this.op==="-"?"_":this.op==="not"?"!":this.op}constructor(e,t){super(),this.op=t,this.GenerateIntoContainer=n=>{this.innerExpression.GenerateIntoContainer(n),n.AddContent(Qf.NativeFunctionCall.CallWithName(this.nativeNameForOp));},this.toString=()=>this.nativeNameForOp+this.innerExpression,this.innerExpression=this.AddContent(e);}get typeName(){return "UnaryExpression"}};kr.UnaryExpression=Si;Si.WithInner=(i,e)=>{let t=(0, Zf.asOrNull)(i,Wn.NumberExpression);if(t){if(e==="-"){if(t.isInt())return new Wn.NumberExpression(-t.value,"int");if(t.isFloat())return new Wn.NumberExpression(-t.value,"float")}else if(e=="!"||e=="not"){if(t.isInt())return new Wn.NumberExpression(t.value==0,"bool");if(t.isFloat())return new Wn.NumberExpression(t.value==0,"bool");if(t.isBool())return new Wn.NumberExpression(!t.value,"bool")}throw new Error("Unexpected operation or number type")}return new Si(i,e)};});var Fo=O(Lr=>{Object.defineProperty(Lr,"__esModule",{value:true});Lr.BinaryExpression=void 0;var eg=lt(),tg=xt(),ng=Oo(),ig=re(),Po=class extends eg.Expression{constructor(e,t,n){super(),this.opName=n,this.GenerateIntoContainer=r=>{this.leftExpression.GenerateIntoContainer(r),this.rightExpression.GenerateIntoContainer(r),this.opName=this.NativeNameForOp(this.opName),r.AddContent(tg.NativeFunctionCall.CallWithName(this.opName));},this.NativeNameForOp=r=>r==="and"?"&&":r==="or"?"||":r==="mod"?"%":r==="has"?"?":r==="hasnt"?"!?":r,this.toString=()=>`(${this.leftExpression} ${this.opName} ${this.rightExpression})`,this.leftExpression=this.AddContent(e),this.rightExpression=this.AddContent(t),