@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
4 lines • 409 kB
JavaScript
'use strict';var pixiVn=require('@drincs/pixi-vn'),canvas=require('@drincs/pixi-vn/canvas'),narration=require('@drincs/pixi-vn/narration'),sound=require('@drincs/pixi-vn/sound'),storage=require('@drincs/pixi-vn/storage'),characters=require('@drincs/pixi-vn/characters'),g=require('zod');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var Wc=Object.create;var tu=Object.defineProperty;var jc=Object.getOwnPropertyDescriptor;var qc=Object.getOwnPropertyNames;var Mc=Object.getPrototypeOf,Gc=Object.prototype.hasOwnProperty;var Vt=(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 b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var $c=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of qc(e))!Gc.call(i,r)&&r!==t&&tu(i,r,{get:()=>e[r],enumerable:!(n=jc(e,r))||n.enumerable});return i};var sa=(i,e,t)=>(t=i!=null?Wc(Mc(i)):{},$c(tu(t,"default",{value:i,enumerable:true}),i));var Na=b(Vi=>{Object.defineProperty(Vi,"__esModule",{value:true});Vi.CompilerOptions=void 0;var Fa=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;}};Vi.CompilerOptions=Fa;});var Mu=b(ki=>{Object.defineProperty(ki,"__esModule",{value:true});ki.DebugSourceRange=void 0;var Ia=class{constructor(e,t,n){this.length=e,this.debugMetadata=t,this.text=n;}};ki.DebugSourceRange=Ia;});var tn=b(Ri=>{Object.defineProperty(Ri,"__esModule",{value:true});Ri.ErrorType=void 0;var Gu;(function(i){i[i.Author=0]="Author",i[i.Warning=1]="Warning",i[i.Error=2]="Error";})(Gu||(Ri.ErrorType=Gu={}));});var $u=b(Li=>{Object.defineProperty(Li,"__esModule",{value:true});Li.Argument=void 0;var Va=class{constructor(e=null,t=null,n=null){this.identifier=e,this.isByReference=t,this.isDivertTarget=n;}get typeName(){return "Argument"}};Li.Argument=Va;});var U=b(he=>{Object.defineProperty(he,"__esModule",{value:true});he.filterUndef=he.isEquatable=he.nullIfUndefined=he.asINamedContentOrNull=he.asBooleanOrThrows=he.asNumberOrThrows=he.asOrThrows=he.asOrNull=void 0;function Cp(i,e){return i instanceof e?Ju(i):null}he.asOrNull=Cp;function yp(i,e){if(i instanceof e)return Ju(i);throw new Error(`${i} is not of type ${e}`)}he.asOrThrows=yp;function vp(i){if(typeof i=="number")return i;throw new Error(`${i} is not a number`)}he.asNumberOrThrows=vp;function Ep(i){if(typeof i=="boolean")return i;throw new Error(`${i} is not a boolean`)}he.asBooleanOrThrows=Ep;function Sp(i){return i.hasValidName&&i.name?i:null}he.asINamedContentOrNull=Sp;function Dp(i){return typeof i>"u"?null:i}he.nullIfUndefined=Dp;function bp(i){return typeof i=="object"&&typeof i.Equals=="function"}he.isEquatable=bp;function Ju(i,e){return i}function Ap(i){return i!=null}he.filterUndef=Ap;});var Z=b(Bi=>{Object.defineProperty(Bi,"__esModule",{value:true});Bi.ParsedObject=void 0;var Hu=U(),ka=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, Hu.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, Hu.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;}}};Bi.ParsedObject=ka;});var ji=b(Wi=>{Object.defineProperty(Wi,"__esModule",{value:true});Wi.AuthorWarning=void 0;var wp=Z(),Ra=class extends wp.ParsedObject{constructor(e){super(),this.warningMessage=e,this.GenerateRuntimeObject=()=>(this.Warning(this.warningMessage),null);}get typeName(){return "AuthorWarning"}};Wi.AuthorWarning=Ra;});var Ne=b(In=>{Object.defineProperty(In,"__esModule",{value:true});In.Path=void 0;var nn=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}};In.Path=nn;nn.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;})(nn||(In.Path=nn={}));});var Vn=b(qi=>{Object.defineProperty(qi,"__esModule",{value:true});qi.Debug=void 0;var Uu;(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;})(Uu||(qi.Debug=Uu={}));});var ge=b(rn=>{Object.defineProperty(rn,"__esModule",{value:true});rn.throwNullException=rn.NullException=void 0;var Mi=class extends Error{};rn.NullException=Mi;function xp(i){throw new Mi(`${i} is null or undefined`)}rn.throwNullException=xp;});var Ie=b($i=>{Object.defineProperty($i,"__esModule",{value:true});$i.InkObject=void 0;var sn=Ne(),kn=ae(),La=Vn(),an=U(),Gi=ge(),Ba=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 sn.Path;else {let e=[],t=this,n=(0, an.asOrNull)(t.parent,kn.Container);for(;n!==null;){let r=(0, an.asINamedContentOrNull)(t);if(r!=null&&r.hasValidName){if(r.name===null)return (0, Gi.throwNullException)("namedChild.name");e.unshift(new sn.Path.Component(r.name));}else e.unshift(new sn.Path.Component(n.content.indexOf(t)));t=n,n=(0, an.asOrNull)(n.parent,kn.Container);}this._path=new sn.Path(e);}return this._path}ResolvePath(e){if(e===null)return (0, Gi.throwNullException)("path");if(e.isRelative){let t=(0, an.asOrNull)(this,kn.Container);return t===null&&(La.Debug.Assert(this.parent!==null,"Can't resolve relative path because we don't have a parent"),t=(0, an.asOrNull)(this.parent,kn.Container),La.Debug.Assert(t!==null,"Expected parent to be a container"),La.Debug.Assert(e.GetComponent(0).isParent),e=e.tail),t===null?(0, Gi.throwNullException)("nearestContainer"):t.ContentAtPath(e)}else {let t=this.rootContentContainer;return t===null?(0, Gi.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),h=e.GetComponent(l);if(u.Equals(h))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(sn.Path.Component.ToParent());for(let l=r+1;l<e.componentCount;++l)s.push(e.GetComponent(l));return new sn.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, an.asOrNull)(e,kn.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}};$i.InkObject=Ba;});var Wt=b(Ji=>{Object.defineProperty(Ji,"__esModule",{value:true});Ji.StringBuilder=void 0;var Wa=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="";}};Ji.StringBuilder=Wa;});var ke=b(on=>{Object.defineProperty(on,"__esModule",{value:true});on.InkList=on.InkListItem=void 0;var nt=ge(),_p=Wt(),Ve=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)}};on.InkListItem=Ve;var ja=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, nt.throwNullException)("originStory.listDefinitions");let n=t.listDefinitions.TryListGetDefinition(e,null);if(n.exists){if(n.result===null)return (0, nt.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, nt.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 Ve){let n=e;if(n.originName==null){this.AddItem(n.itemName);return}if(this.origins===null)return (0, nt.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, nt.throwNullException)("this.origins");for(let a of this.origins){if(n===null)return (0, nt.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 Ve(r.name,n),s=r.ValueForItem(a);this.Add(a,s);}}}ContainsItemNamed(e){for(let[t]of this)if(Ve.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=Ve.fromSerializedKey(e);if(t.originName===null)return (0, nt.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:Ve.Null,Value:0};for(let[t,n]of this){let r=Ve.fromSerializedKey(t);(e.Key.isNull||n>e.Value)&&(e={Key:r,Value:n});}return e}get minItem(){let e={Key:Ve.Null,Value:0};for(let[t,n]of this){let r=Ve.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=Ve.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=Ve.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=Ve.fromSerializedKey(t);e.push({Key:r,Value:n});}return e.sort((t,n)=>t.Key.originName===null?(0, nt.throwNullException)("x.Key.originName"):n.Key.originName===null?(0, nt.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 _p.StringBuilder;for(let n=0;n<e.length;n++){n>0&&t.Append(", ");let r=e[n].Key;if(r.itemName===null)return (0, nt.throwNullException)("item.itemName");t.Append(r.itemName);}return t.toString()}valueOf(){return NaN}};on.InkList=ja;});var Rn=b(Hi=>{Object.defineProperty(Hi,"__esModule",{value:true});Hi.StoryException=void 0;var qa=class extends Error{constructor(e){super(e),this.useEndLineNumber=false,this.message=e,this.name="StoryException";}};Hi.StoryException=qa;});var ln=b(At=>{Object.defineProperty(At,"__esModule",{value:true});At.tryParseFloat=At.tryParseInt=At.tryGetValueFromMap=void 0;function Tp(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}}At.tryGetValueFromMap=Tp;function Op(i,e=0){let t=parseInt(i);return Number.isNaN(t)?{result:e,exists:false}:{result:t,exists:true}}At.tryParseInt=Op;function Pp(i,e=0){let t=parseFloat(i);return Number.isNaN(t)?{result:e,exists:false}:{result:t,exists:true}}At.tryParseFloat=Pp;});var te=b(ne=>{Object.defineProperty(ne,"__esModule",{value:true});ne.ValueType=ne.ListValue=ne.VariablePointerValue=ne.DivertTargetValue=ne.StringValue=ne.FloatValue=ne.IntValue=ne.BoolValue=ne.Value=ne.AbstractValue=void 0;var zu=Ie(),Ku=Ne(),jt=ke(),Fp=Rn(),Ln=U(),Xu=ln(),Ge=ge(),Ui=class i extends zu.InkObject{static Create(e,t){if(t){if(t===Q.Int&&Number.isInteger(Number(e)))return new rt(Number(e));if(t===Q.Float&&!isNaN(e))return new st(Number(e))}if(typeof e=="boolean")return new un(!!e);if(typeof e=="string")return new Ct(String(e));if(Number.isInteger(Number(e)))return new rt(Number(e));if(isNaN(e)){if(e instanceof Ku.Path)return new zi((0, Ln.asOrThrows)(e,Ku.Path));if(e instanceof jt.InkList)return new Ki((0, Ln.asOrThrows)(e,jt.InkList))}else return new st(Number(e));return null}Copy(){return (0, Ln.asOrThrows)(i.Create(this.valueObject),zu.InkObject)}BadCastException(e){return new Fp.StoryException("Can't cast "+this.valueObject+" from "+this.valueType+" to "+e)}};ne.AbstractValue=Ui;var it=class extends Ui{constructor(e){super(),this.value=e;}get valueObject(){return this.value}toString(){return this.value===null?(0, Ge.throwNullException)("Value.value"):this.value.toString()}};ne.Value=it;var un=class extends it{constructor(e){super(e||false);}get isTruthy(){return !!this.value}get valueType(){return Q.Bool}Cast(e){if(this.value===null)return (0, Ge.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==Q.Int)return new rt(this.value?1:0);if(e==Q.Float)return new st(this.value?1:0);if(e==Q.String)return new Ct(this.value?"true":"false");throw this.BadCastException(e)}toString(){return this.value?"true":"false"}};ne.BoolValue=un;var rt=class extends it{constructor(e){super(e||0);}get isTruthy(){return this.value!=0}get valueType(){return Q.Int}Cast(e){if(this.value===null)return (0, Ge.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==Q.Bool)return new un(this.value!==0);if(e==Q.Float)return new st(this.value);if(e==Q.String)return new Ct(""+this.value);throw this.BadCastException(e)}};ne.IntValue=rt;var st=class extends it{constructor(e){super(e||0);}get isTruthy(){return this.value!=0}get valueType(){return Q.Float}Cast(e){if(this.value===null)return (0, Ge.throwNullException)("Value.value");if(e==this.valueType)return this;if(e==Q.Bool)return new un(this.value!==0);if(e==Q.Int)return new rt(this.value);if(e==Q.String)return new Ct(""+this.value);throw this.BadCastException(e)}};ne.FloatValue=st;var Ct=class extends it{constructor(e){if(super(e||""),this._isNewline=this.value==`
`,this._isInlineWhitespace=true,this.value===null)return (0, Ge.throwNullException)("Value.value");this.value.length>0&&this.value.split("").every(t=>t!=" "&&t!=" "?(this._isInlineWhitespace=false,false):true);}get valueType(){return Q.String}get isTruthy(){return this.value===null?(0, Ge.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==Q.Int){let t=(0, Xu.tryParseInt)(this.value);if(t.exists)return new rt(t.result);throw this.BadCastException(e)}if(e==Q.Float){let t=(0, Xu.tryParseFloat)(this.value);if(t.exists)return new st(t.result);throw this.BadCastException(e)}throw this.BadCastException(e)}};ne.StringValue=Ct;var zi=class extends it{constructor(e=null){super(e);}get valueType(){return Q.DivertTarget}get targetPath(){return this.value===null?(0, Ge.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+")"}};ne.DivertTargetValue=zi;var Ma=class i extends it{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, Ge.throwNullException)("Value.value"):this.value}set variableName(e){this.value=e;}get valueType(){return Q.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)}};ne.VariablePointerValue=Ma;var Ki=class i extends it{get isTruthy(){return this.value===null?(0, Ge.throwNullException)("this.value"):this.value.Count>0}get valueType(){return Q.List}Cast(e){if(this.value===null)return (0, Ge.throwNullException)("Value.value");if(e==Q.Int){let t=this.value.maxItem;return t.Key.isNull?new rt(0):new rt(t.Value)}else if(e==Q.Float){let t=this.value.maxItem;return t.Key.isNull?new st(0):new st(t.Value)}else if(e==Q.String){let t=this.value.maxItem;return t.Key.isNull?new Ct(""):new Ct(t.Key.toString())}if(e==this.valueType)return this;throw this.BadCastException(e)}constructor(e,t){super(null),!e&&!t?this.value=new jt.InkList:e instanceof jt.InkList?this.value=new jt.InkList(e):e instanceof jt.InkListItem&&typeof t=="number"&&(this.value=new jt.InkList({Key:e,Value:t}));}static RetainListOriginsForAssignment(e,t){let n=(0, Ln.asOrNull)(e,i),r=(0, Ln.asOrNull)(t,i);if(r&&r.value===null)return (0, Ge.throwNullException)("newList.value");if(n&&n.value===null)return (0, Ge.throwNullException)("oldList.value");n&&r&&r.value.Count==0&&r.value.SetInitialOriginNames(n.value.originNames);}};ne.ListValue=Ki;var Q;(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";})(Q||(ne.ValueType=Q={}));});var Yu=b(Xi=>{Object.defineProperty(Xi,"__esModule",{value:true});Xi.SearchResult=void 0;var Np=ae(),Ga=class i{constructor(){this.obj=null,this.approximate=false;}get correctObj(){return this.approximate?null:this.obj}get container(){return this.obj instanceof Np.Container?this.obj:null}copy(){let e=new i;return e.obj=this.obj,e.approximate=this.approximate,e}};Xi.SearchResult=Ga;});var ae=b(Wn=>{Object.defineProperty(Wn,"__esModule",{value:true});Wn.Container=void 0;var Ip=te(),Qu=ge(),Vp=Wt(),hn=Ie(),kp=Yu(),Zu=Ne(),eh=Vn(),Rp=ln(),wt=U(),Bn=class i extends hn.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, wt.asOrThrows)(n,hn.InkObject);e.set(t,r);}for(let t of this.content){let n=(0, wt.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, wt.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 Zu.Path.Component(0)),t=t.content[0]);return new Zu.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, wt.asINamedContentOrNull)(e);t!=null&&t.hasValidName&&this.AddToNamedContentOnly(t);}AddToNamedContentOnly(e){eh.Debug.AssertType(e,hn.InkObject,"Can only add Runtime.Objects to a Runtime.Container");let t=(0, wt.asOrThrows)(e,hn.InkObject);if(t.parent=this,e.name===null)return (0, Qu.throwNullException)("namedContentObj.name");this.namedContent.set(e.name,e);}ContentAtPath(e,t=0,n=-1){n==-1&&(n=e.length);let r=new kp.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 h=(0, wt.asOrNull)(u,i);if(o<n-1&&h==null){r.approximate=true;break}s=u,a=h;}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, Qu.throwNullException)("component.name");let t=(0, Rp.tryGetValueFromMap)(this.namedContent,e.name,null);return t.exists?(0, wt.asOrThrows)(t.result,hn.InkObject):null}}BuildStringOfHierarchy(){let e;if(arguments.length==0)return e=new Vp.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 Ip.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, wt.asOrThrows)(o,hn.InkObject))>=0||a.set(s,o);if(a.size>0){r(),e.AppendLine("-- named: --");for(let[,s]of a)eh.Debug.AssertType(s,i,"Can only print out named Containers"),s.BuildStringOfHierarchy(e,t,n),e.AppendLine();}t--,r(),e.Append("]");}};Wn.Container=Bn;(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={}));})(Bn||(Wn.Container=Bn={}));});var Ce=b(qn=>{Object.defineProperty(qn,"__esModule",{value:true});qn.ControlCommand=void 0;var Lp=Ie(),jn=class i extends Lp.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()}};qn.ControlCommand=jn;(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={}));})(jn||(qn.ControlCommand=jn={}));});var $e=b(Yi=>{Object.defineProperty(Yi,"__esModule",{value:true});Yi.Expression=void 0;var th=ae(),$a=Ce(),Bp=Z(),Ja=class extends Bp.ParsedObject{constructor(){super(...arguments),this._prototypeRuntimeConstantExpression=null,this.outputWhenComplete=false,this.GenerateRuntimeObject=()=>{let e=new th.Container;return e.AddContent($a.ControlCommand.EvalStart()),this.GenerateIntoContainer(e),this.outputWhenComplete&&e.AddContent($a.ControlCommand.EvalOutput()),e.AddContent($a.ControlCommand.EvalEnd()),e},this.GenerateConstantIntoContainer=e=>{this._prototypeRuntimeConstantExpression===null&&(this._prototypeRuntimeConstantExpression=new th.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}};Yi.Expression=Ja;});var qt=b(Qi=>{Object.defineProperty(Qi,"__esModule",{value:true});Qi.Void=void 0;var Wp=Ie(),Ha=class extends Wp.InkObject{toString(){return "Void"}};Qi.Void=Ha;});var at=b(er=>{Object.defineProperty(er,"__esModule",{value:true});er.NativeFunctionCall=void 0;var O=te(),Mn=Rn(),jp=qt(),Zi=ke(),qp=Ie(),Je=U(),Re=ge(),W=class i extends qp.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, Re.throwNullException)("NativeFunctionCall._name"):this._name}set name(e){this._name=e,this._isPrototype||(i._nativeFunctions===null?(0, Re.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 jp.Void)throw new Mn.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 O.ListValue&&(t=true);}if(e.length==2&&t)return this.CallBinaryListOperation(e);let n=this.CoerceValuesToSingleType(e),r=n[0].valueType;return r==O.ValueType.Int?this.CallType(n):r==O.ValueType.Float?this.CallType(n):r==O.ValueType.String?this.CallType(n):r==O.ValueType.DivertTarget?this.CallType(n):r==O.ValueType.List?this.CallType(n):null}CallType(e){let t=(0, Je.asOrThrows)(e[0],O.Value),n=t.valueType,r=t,a=e.length;if(a==2||a==1){if(this._operationFuncs===null)return (0, Re.throwNullException)("NativeFunctionCall._operationFuncs");let s=this._operationFuncs.get(n);if(!s){let o=O.ValueType[n];throw new Mn.StoryException("Cannot perform operation "+this.name+" on "+o)}if(a==2){let l=(0, Je.asOrThrows)(e[1],O.Value),u=s;if(r.value===null||l.value===null)return (0, Re.throwNullException)("NativeFunctionCall.Call BinaryOp values");let h=u(r.value,l.value);return O.Value.Create(h)}else {let o=s;if(r.value===null)return (0, Re.throwNullException)("NativeFunctionCall.Call UnaryOp value");let l=o(r.value);return this.name===i.Int?O.Value.Create(l,O.ValueType.Int):this.name===i.Float?O.Value.Create(l,O.ValueType.Float):O.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 O.ListValue&&e[1]instanceof O.IntValue)return this.CallListIncrementOperation(e);let t=(0, Je.asOrThrows)(e[0],O.Value),n=(0, Je.asOrThrows)(e[1],O.Value);if((this.name=="&&"||this.name=="||")&&(t.valueType!=O.ValueType.List||n.valueType!=O.ValueType.List)){if(this._operationFuncs===null)return (0, Re.throwNullException)("NativeFunctionCall._operationFuncs");let r=this._operationFuncs.get(O.ValueType.Int);if(r===null)return (0, Re.throwNullException)("NativeFunctionCall.CallBinaryListOperation op");let a=(0, Je.asBooleanOrThrows)(r(t.isTruthy?1:0,n.isTruthy?1:0));return new O.BoolValue(a)}if(t.valueType==O.ValueType.List&&n.valueType==O.ValueType.List)return this.CallType([t,n]);throw new Mn.StoryException("Can not call use "+this.name+" operation on "+O.ValueType[t.valueType]+" and "+O.ValueType[n.valueType])}CallListIncrementOperation(e){let t=(0, Je.asOrThrows)(e[0],O.ListValue),n=(0, Je.asOrThrows)(e[1],O.IntValue),r=new Zi.InkList;if(t.value===null)return (0, Re.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value");for(let[a,s]of t.value){let o=Zi.InkListItem.fromSerializedKey(a);if(this._operationFuncs===null)return (0, Re.throwNullException)("NativeFunctionCall._operationFuncs");let l=this._operationFuncs.get(O.ValueType.Int);if(n.value===null)return (0, Re.throwNullException)("NativeFunctionCall.CallListIncrementOperation intVal.value");let u=l(s,n.value),h=null;if(t.value.origins===null)return (0, Re.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value.origins");for(let c of t.value.origins)if(c.name==o.originName){h=c;break}if(h!=null){let c=h.TryGetItemWithValue(u,Zi.InkListItem.Null);c.exists&&r.Add(c.result,u);}}return new O.ListValue(r)}CoerceValuesToSingleType(e){let t=O.ValueType.Int,n=null;for(let a of e){let s=(0, Je.asOrThrows)(a,O.Value);s.valueType>t&&(t=s.valueType),s.valueType==O.ValueType.List&&(n=(0, Je.asOrNull)(s,O.ListValue));}let r=[];if(O.ValueType[t]==O.ValueType[O.ValueType.List])for(let a of e){let s=(0, Je.asOrThrows)(a,O.Value);if(s.valueType==O.ValueType.List)r.push(s);else if(s.valueType==O.ValueType.Int){let o=parseInt(s.valueObject);if(n=(0, Je.asOrThrows)(n,O.ListValue),n.value===null)return (0, Re.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType specialCaseList.value");let l=n.value.originOfMaxItem;if(l===null)return (0, Re.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType list");let u=l.TryGetItemWithValue(o,Zi.InkListItem.Null);if(u.exists){let h=new O.ListValue(u.result,o);r.push(h);}else throw new Mn.StoryException("Could not find List item with the value "+o+" in "+l.name)}else {let o=O.ValueType[s.valueType];throw new Mn.StoryException("Cannot mix Lists and "+o+" values in this operation")}}else for(let a of e){let o=(0, Je.asOrThrows)(a,O.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,O.ValueType.DivertTarget,e),this.AddOpToNativeFunc(this.NotEquals,2,O.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, Re.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,O.ValueType.Int,t);}static AddIntUnaryOp(e,t){this.AddOpToNativeFunc(e,1,O.ValueType.Int,t);}static AddFloatBinaryOp(e,t){this.AddOpToNativeFunc(e,2,O.ValueType.Float,t);}static AddFloatUnaryOp(e,t){this.AddOpToNativeFunc(e,1,O.ValueType.Float,t);}static AddStringBinaryOp(e,t){this.AddOpToNativeFunc(e,2,O.ValueType.String,t);}static AddListBinaryOp(e,t){this.AddOpToNativeFunc(e,2,O.ValueType.List,t);}static AddListUnaryOp(e,t){this.AddOpToNativeFunc(e,1,O.ValueType.List,t);}toString(){return 'Native "'+this.name+'"'}};er.NativeFunctionCall=W;W.Add="+";W.Subtract="-";W.Divide="/";W.Multiply="*";W.Mod="%";W.Negate="_";W.Equal="==";W.Greater=">";W.Less="<";W.GreaterThanOrEquals=">=";W.LessThanOrEquals="<=";W.NotEquals="!=";W.Not="!";W.And="&&";W.Or="||";W.Min="MIN";W.Max="MAX";W.Pow="POW";W.Floor="FLOOR";W.Ceiling="CEILING";W.Int="INT";W.Float="FLOAT";W.Has="?";W.Hasnt="!?";W.Intersect="^";W.ListMin="LIST_MIN";W.ListMax="LIST_MAX";W.All="LIST_ALL";W.Count="LIST_COUNT";W.ValueOfList="LIST_VALUE";W.Invert="LIST_INVERT";W._nativeFunctions=null;});var nr=b(tr=>{Object.defineProperty(tr,"__esModule",{value:true});tr.NumberExpression=void 0;var Mp=$e(),Ua=te(),Gp=U(),za=class i extends Mp.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 Ua.IntValue(this.value)):this.isFloat()?n.AddContent(new Ua.FloatValue(this.value)):this.isBool()&&n.AddContent(new Ua.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, Gp.asOrNull)(e,i);return t?t.subtype==this.subtype&&t.value==this.value:false}};tr.NumberExpression=za;});var Ka=b(ir=>{Object.defineProperty(ir,"__esModule",{value:true});ir.UnaryExpression=void 0;var $p=$e(),Jp=at(),cn=nr(),Hp=U(),Gn=class extends $p.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(Jp.NativeFunctionCall.CallWithName(this.nativeNameForOp));},this.toString=()=>this.nativeNameForOp+this.innerExpression,this.innerExpression=this.AddContent(e);}get typeName(){return "UnaryExpression"}};ir.UnaryExpression=Gn;Gn.WithInner=(i,e)=>{let t=(0, Hp.asOrNull)(i,cn.NumberExpression);if(t){if(e==="-"){if(t.isInt())return new cn.NumberExpression(-t.value,"int");if(t.isFloat())return new cn.NumberExpression(-t.value,"float")}else if(e=="!"||e=="not"){if(t.isInt())return new cn.NumberExpression(t.value==0,"bool");if(t.isFloat())return new cn.NumberExpression(t.value==0,"bool");if(t.isBool())return new cn.NumberExpression(!t.value,"bool")}throw new Error("Unexpected operation or number type")}return new Gn(i,e)};});var Ya=b(rr=>{Object.defineProperty(rr,"__esModule",{value:true});rr.BinaryExpression=void 0;var Up=$e(),zp=at(),Kp=Ka(),Xp=U(),Xa=class extends Up.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(zp.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),this.opName=n;}get typeName(){return "BinaryExpression"}ResolveReferences(e){if(super.ResolveReferences(e),this.NativeNameForOp(this.opName)==="?"){let t=(0, Xp.asOrNull)(this.leftExpression,Kp.UnaryExpression);t!==null&&(t.op==="not"||t.op==="!")&&this.Error(`Using 'not' or '!' here negates '${t.innerExpression}' rather than the result of the '?' or 'has' operator. You need to add parentheses around the (A ? B) expression.`);}}};rr.BinaryExpression=Xa;});var Jn=b(sr=>{Object.defineProperty(sr,"__esModule",{value:true});sr.CharacterSet=void 0;var $n=class{constructor(e){this.set=new Set,this.Add=t=>this.set.add(t),this.AddRange=(t,n)=>{for(let r=t.charCodeAt(0);r<=n.charCodeAt(0);++r)this.Add(String.fromCharCode(r));return this},this.AddCharacters=t=>{if(typeof t=="string"||Array.isArray(t))for(let n of t)this.Add(n