@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
4 lines • 336 kB
JavaScript
'use strict';var d=require('zod');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var d__default=/*#__PURE__*/_interopDefault(d);var Zl=Object.create;var Mo=Object.defineProperty;var th=Object.getOwnPropertyDescriptor;var eh=Object.getOwnPropertyNames;var nh=Object.getPrototypeOf,ih=Object.prototype.hasOwnProperty;var C=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var rh=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of eh(t))!ih.call(s,i)&&i!==e&&Mo(s,i,{get:()=>t[i],enumerable:!(n=th(t,i))||n.enumerable});return s};var Go=(s,t,e)=>(e=s!=null?Zl(nh(s)):{},rh(Mo(e,"default",{value:s,enumerable:true}),s));var Ds=C(qn=>{Object.defineProperty(qn,"__esModule",{value:true});qn.CompilerOptions=void 0;var vs=class{constructor(t=null,e=[],n=false,i=null,a=null){this.sourceFilename=t,this.pluginNames=e,this.countAllVisits=n,this.errorHandler=i,this.fileHandler=a;}};qn.CompilerOptions=vs;});var eu=C(jn=>{Object.defineProperty(jn,"__esModule",{value:true});jn.DebugSourceRange=void 0;var Es=class{constructor(t,e,n){this.length=t,this.debugMetadata=e,this.text=n;}};jn.DebugSourceRange=Es;});var Je=C(Mn=>{Object.defineProperty(Mn,"__esModule",{value:true});Mn.ErrorType=void 0;var nu;(function(s){s[s.Author=0]="Author",s[s.Warning=1]="Warning",s[s.Error=2]="Error";})(nu||(Mn.ErrorType=nu={}));});var iu=C(Gn=>{Object.defineProperty(Gn,"__esModule",{value:true});Gn.Argument=void 0;var Ss=class{constructor(t=null,e=null,n=null){this.identifier=t,this.isByReference=e,this.isDivertTarget=n;}get typeName(){return "Argument"}};Gn.Argument=Ss;});var q=C(tt=>{Object.defineProperty(tt,"__esModule",{value:true});tt.filterUndef=tt.isEquatable=tt.nullIfUndefined=tt.asINamedContentOrNull=tt.asBooleanOrThrows=tt.asNumberOrThrows=tt.asOrThrows=tt.asOrNull=void 0;function Dh(s,t){return s instanceof t?ru(s):null}tt.asOrNull=Dh;function Eh(s,t){if(s instanceof t)return ru(s);throw new Error(`${s} is not of type ${t}`)}tt.asOrThrows=Eh;function Sh(s){if(typeof s=="number")return s;throw new Error(`${s} is not a number`)}tt.asNumberOrThrows=Sh;function yh(s){if(typeof s=="boolean")return s;throw new Error(`${s} is not a boolean`)}tt.asBooleanOrThrows=yh;function bh(s){return s.hasValidName&&s.name?s:null}tt.asINamedContentOrNull=bh;function Ah(s){return typeof s>"u"?null:s}tt.nullIfUndefined=Ah;function _h(s){return typeof s=="object"&&typeof s.Equals=="function"}tt.isEquatable=_h;function ru(s,t){return s}function Fh(s){return s!=null}tt.filterUndef=Fh;});var H=C($n=>{Object.defineProperty($n,"__esModule",{value:true});$n.ParsedObject=void 0;var su=q(),ys=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=t=>{this.content===null&&(this.content=[]);let e=Array.isArray(t)?t:[t];for(let n of e)n.hasOwnProperty("parent")&&(n.parent=this),this.content.push(n);if(!Array.isArray(t))return t},this.InsertContent=(t,e)=>(this.content===null&&(this.content=[]),e.parent=this,this.content.splice(t,0,e),e),this.Find=t=>(e=null)=>{let n=(0, su.asOrNull)(this,t);if(n!==null&&(e===null||e(n)===true))return n;if(this.content===null)return null;for(let i of this.content){let a=i.Find&&i.Find(t)(e);if(a)return a}return null},this.FindAll=t=>(e,n)=>{let i=Array.isArray(n)?n:[],a=(0, su.asOrNull)(this,t);if(a!==null&&(!e||e(a)===true)&&i.push(a),this.content===null)return [];for(let r of this.content)r.FindAll&&r.FindAll(t)(e,i);return i},this.Warning=(t,e=null)=>{this.Error(t,e,true);};}get debugMetadata(){return this._debugMetadata===null&&this.parent?this.parent.debugMetadata:this._debugMetadata}set debugMetadata(t){this._debugMetadata=t;}get hasOwnDebugMetadata(){return !!this.debugMetadata}get typeName(){return "ParsedObject"}get story(){let t=this;for(;t.parent;)t=t.parent;return t}get runtimeObject(){return this._runtimeObject||(this._runtimeObject=this.GenerateRuntimeObject(),this._runtimeObject&&(this._runtimeObject.debugMetadata=this.debugMetadata)),this._runtimeObject}set runtimeObject(t){this._runtimeObject=t;}get runtimePath(){if(!this.runtimeObject.path)throw new Error;return this.runtimeObject.path}get containerForCounting(){return this.runtimeObject}get ancestry(){let t=[],e=this.parent;for(;e;)t.push(e),e=e.parent;return t=t.reverse(),t}ResolveReferences(t){if(this.content!==null)for(let e of this.content)e.ResolveReferences(t);}Error(t,e=null,n=false){if(e===null&&(e=this),!(e._alreadyHadError&&!n||e._alreadyHadWarning&&n)){if(this.parent)this.parent.Error(t,e,n);else throw new Error(`No parent object to send error to: ${t}`);n?e._alreadyHadWarning=true:e._alreadyHadError=true;}}};$n.ParsedObject=ys;});var Un=C(Hn=>{Object.defineProperty(Hn,"__esModule",{value:true});Hn.AuthorWarning=void 0;var wh=H(),bs=class extends wh.ParsedObject{constructor(t){super(),this.warningMessage=t,this.GenerateRuntimeObject=()=>(this.Warning(this.warningMessage),null);}get typeName(){return "AuthorWarning"}};Hn.AuthorWarning=bs;});var ft=C(ze=>{Object.defineProperty(ze,"__esModule",{value:true});ze.Path=void 0;var Se=class s{constructor(){if(this._components=[],this._componentsString=null,this._isRelative=false,typeof arguments[0]=="string"){let t=arguments[0];this.componentsString=t;}else if(arguments[0]instanceof s.Component&&arguments[1]instanceof s){let t=arguments[0],e=arguments[1];this._components.push(t),this._components=this._components.concat(e._components);}else if(arguments[0]instanceof Array){let t=arguments[0],e=!!arguments[1];this._components=this._components.concat(t),this._isRelative=e;}}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 t=this._components.slice(1,this._components.length);return new s(t)}else return s.self}get length(){return this._components.length}get lastComponent(){let t=this._components.length-1;return t>=0?this._components[t]:null}get containsNamedComponent(){for(let t=0,e=this._components.length;t<e;t++)if(!this._components[t].isIndex)return true;return false}static get self(){let t=new s;return t._isRelative=true,t}GetComponent(t){return this._components[t]}PathByAppendingPath(t){let e=new s,n=0;for(let i=0;i<t._components.length&&t._components[i].isParent;++i)n++;for(let i=0;i<this._components.length-n;++i)e._components.push(this._components[i]);for(let i=n;i<t._components.length;++i)e._components.push(t._components[i]);return e}get componentsString(){return this._componentsString==null&&(this._componentsString=this._components.join("."),this.isRelative&&(this._componentsString="."+this._componentsString)),this._componentsString}set componentsString(t){if(this._components.length=0,this._componentsString=t,this._componentsString==null||this._componentsString=="")return;this._componentsString[0]=="."&&(this._isRelative=true,this._componentsString=this._componentsString.substring(1));let e=this._componentsString.split(".");for(let n of e)/^(\-|\+)?([0-9]+|Infinity)$/.test(n)?this._components.push(new s.Component(parseInt(n))):this._components.push(new s.Component(n));}toString(){return this.componentsString}Equals(t){if(t==null||t._components.length!=this._components.length||t.isRelative!=this.isRelative)return false;for(let e=0,n=t._components.length;e<n;e++)if(!t._components[e].Equals(this._components[e]))return false;return true}PathByAppendingComponent(t){let e=new s;return e._components.push(...this._components),e._components.push(t),e}};ze.Path=Se;Se.parentId="^";(function(s){class t{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==s.parentId}static ToParent(){return new t(s.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}}s.Component=t;})(Se||(ze.Path=Se={}));});var Xe=C(Kn=>{Object.defineProperty(Kn,"__esModule",{value:true});Kn.Debug=void 0;var au;(function(s){function t(n,i,a){e(n instanceof i,a);}s.AssertType=t;function e(n,i){if(!n)throw typeof i<"u"&&console.warn(i),console.trace&&console.trace(),new Error("")}s.Assert=e;})(au||(Kn.Debug=au={}));});var st=C(ye=>{Object.defineProperty(ye,"__esModule",{value:true});ye.throwNullException=ye.NullException=void 0;var Jn=class extends Error{};ye.NullException=Jn;function xh(s){throw new Jn(`${s} is null or undefined`)}ye.throwNullException=xh;});var pt=C(Xn=>{Object.defineProperty(Xn,"__esModule",{value:true});Xn.InkObject=void 0;var be=ft(),Ye=z(),As=Xe(),Ae=q(),zn=st(),_s=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(t){this._debugMetadata=t;}get ownDebugMetadata(){return this._debugMetadata}DebugLineNumberOfPath(t){if(t===null)return null;let e=this.rootContentContainer;if(e){let n=e.ContentAtPath(t).obj;if(n){let i=n.debugMetadata;if(i!==null)return i.startLineNumber}}return null}get path(){if(this._path==null)if(this.parent==null)this._path=new be.Path;else {let t=[],e=this,n=(0, Ae.asOrNull)(e.parent,Ye.Container);for(;n!==null;){let i=(0, Ae.asINamedContentOrNull)(e);if(i!=null&&i.hasValidName){if(i.name===null)return (0, zn.throwNullException)("namedChild.name");t.unshift(new be.Path.Component(i.name));}else t.unshift(new be.Path.Component(n.content.indexOf(e)));e=n,n=(0, Ae.asOrNull)(n.parent,Ye.Container);}this._path=new be.Path(t);}return this._path}ResolvePath(t){if(t===null)return (0, zn.throwNullException)("path");if(t.isRelative){let e=(0, Ae.asOrNull)(this,Ye.Container);return e===null&&(As.Debug.Assert(this.parent!==null,"Can't resolve relative path because we don't have a parent"),e=(0, Ae.asOrNull)(this.parent,Ye.Container),As.Debug.Assert(e!==null,"Expected parent to be a container"),As.Debug.Assert(t.GetComponent(0).isParent),t=t.tail),e===null?(0, zn.throwNullException)("nearestContainer"):e.ContentAtPath(t)}else {let e=this.rootContentContainer;return e===null?(0, zn.throwNullException)("contentContainer"):e.ContentAtPath(t)}}ConvertPathToRelative(t){let e=this.path,n=Math.min(t.length,e.length),i=-1;for(let u=0;u<n;++u){let l=e.GetComponent(u),h=t.GetComponent(u);if(l.Equals(h))i=u;else break}if(i==-1)return t;let a=e.componentCount-1-i,r=[];for(let u=0;u<a;++u)r.push(be.Path.Component.ToParent());for(let u=i+1;u<t.componentCount;++u)r.push(t.GetComponent(u));return new be.Path(r,true)}CompactPathString(t){let e=null,n=null;return t.isRelative?(n=t.componentsString,e=this.path.PathByAppendingPath(t).componentsString):(n=this.ConvertPathToRelative(t).componentsString,e=t.componentsString),n.length<e.length?n:e}get rootContentContainer(){let t=this;for(;t.parent;)t=t.parent;return (0, Ae.asOrNull)(t,Ye.Container)}Copy(){throw Error("Not Implemented: Doesn't support copying")}SetChild(t,e,n){t[e]&&(t[e]=null),t[e]=n,t[e]&&(t[e].parent=this);}Equals(t){return t===this}};Xn.InkObject=_s;});var le=C(Yn=>{Object.defineProperty(Yn,"__esModule",{value:true});Yn.StringBuilder=void 0;var Fs=class{constructor(t){t=typeof t<"u"?t.toString():"",this.string=t;}get Length(){return this.string.length}Append(t){t!==null&&(this.string+=t);}AppendLine(t){typeof t<"u"&&this.Append(t),this.string+=`
`;}AppendFormat(t,...e){this.string+=t.replace(/{(\d+)}/g,(n,i)=>typeof e[i]<"u"?e[i]:n);}toString(){return this.string}Clear(){this.string="";}};Yn.StringBuilder=Fs;});var gt=C(_e=>{Object.defineProperty(_e,"__esModule",{value:true});_e.InkList=_e.InkListItem=void 0;var Nt=st(),Oh=le(),mt=class s{constructor(){if(this.originName=null,this.itemName=null,typeof arguments[1]<"u"){let t=arguments[0],e=arguments[1];this.originName=t,this.itemName=e;}else if(arguments[0]){let e=arguments[0].toString().split(".");this.originName=e[0],this.itemName=e[1];}}static get Null(){return new s(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(t){if(t instanceof s){let e=t;return e.itemName==this.itemName&&e.originName==this.originName}return false}copy(){return new s(this.originName,this.itemName)}serialized(){return JSON.stringify({originName:this.originName,itemName:this.itemName})}static fromSerializedKey(t){let e=JSON.parse(t);if(!s.isLikeInkListItem(e))return s.Null;let n=e;return new s(n.originName,n.itemName)}static isLikeInkListItem(t){return !(typeof t!="object"||!t.hasOwnProperty("originName")||!t.hasOwnProperty("itemName")||typeof t.originName!="string"&&typeof t.originName!==null||typeof t.itemName!="string"&&typeof t.itemName!==null)}};_e.InkListItem=mt;var ws=class s extends Map{constructor(){if(super(arguments[0]instanceof s?arguments[0]:[]),this.origins=null,this._originNames=[],arguments[0]instanceof s){let t=arguments[0],e=t.originNames;e!==null&&(this._originNames=e.slice()),t.origins!==null&&(this.origins=t.origins.slice());}else if(typeof arguments[0]=="string"){let t=arguments[0],e=arguments[1];if(this.SetInitialOriginName(t),e.listDefinitions===null)return (0, Nt.throwNullException)("originStory.listDefinitions");let n=e.listDefinitions.TryListGetDefinition(t,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: "+t)}else if(typeof arguments[0]=="object"&&arguments[0].hasOwnProperty("Key")&&arguments[0].hasOwnProperty("Value")){let t=arguments[0];this.Add(t.Key,t.Value);}}static FromString(t,e){var n;if(t==null||t=="")return new s;let i=(n=e.listDefinitions)===null||n===void 0?void 0:n.FindSingleItemListWithName(t);if(i)return i.value===null?(0, Nt.throwNullException)("listValue.value"):new s(i.value);throw new Error("Could not find the InkListItem from the string '"+t+"' to create an InkList because it doesn't exist in the original list definition in ink.")}AddItem(t,e=null){if(t instanceof mt){let n=t;if(n.originName==null){this.AddItem(n.itemName);return}if(this.origins===null)return (0, Nt.throwNullException)("this.origins");for(let i of this.origins)if(i.name==n.originName){let a=i.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(t!==null){let n=t,i=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(i!=null)throw new Error("Could not add the item "+n+" to this list because it could come from either "+a.name+" or "+i.name);i=a;}}if(i==null){if(e==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=s.FromString(n,e).orderedItems[0];this.Add(a.Key,a.Value);}}else {let a=new mt(i.name,n),r=i.ValueForItem(a);this.Add(a,r);}}}ContainsItemNamed(t){for(let[e]of this)if(mt.fromSerializedKey(e).itemName==t)return true;return false}ContainsKey(t){return this.has(t.serialized())}Add(t,e){let n=t.serialized();if(this.has(n))throw new Error(`The Map already contains an entry for ${t}`);this.set(n,e);}Remove(t){return this.delete(t.serialized())}get Count(){return this.size}get originOfMaxItem(){if(this.origins==null)return null;let t=this.maxItem.Key.originName,e=null;return this.origins.every(n=>n.name==t?(e=n,false):true),e}get originNames(){if(this.Count>0){this._originNames==null&&this.Count>0?this._originNames=[]:(this._originNames||(this._originNames=[]),this._originNames.length=0);for(let[t]of this){let e=mt.fromSerializedKey(t);if(e.originName===null)return (0, Nt.throwNullException)("item.originName");this._originNames.push(e.originName);}}return this._originNames}SetInitialOriginName(t){this._originNames=[t];}SetInitialOriginNames(t){t==null?this._originNames=null:this._originNames=t.slice();}get maxItem(){let t={Key:mt.Null,Value:0};for(let[e,n]of this){let i=mt.fromSerializedKey(e);(t.Key.isNull||n>t.Value)&&(t={Key:i,Value:n});}return t}get minItem(){let t={Key:mt.Null,Value:0};for(let[e,n]of this){let i=mt.fromSerializedKey(e);(t.Key.isNull||n<t.Value)&&(t={Key:i,Value:n});}return t}get inverse(){let t=new s;if(this.origins!=null)for(let e of this.origins)for(let[n,i]of e.items){let a=mt.fromSerializedKey(n);this.ContainsKey(a)||t.Add(a,i);}return t}get all(){let t=new s;if(this.origins!=null)for(let e of this.origins)for(let[n,i]of e.items){let a=mt.fromSerializedKey(n);t.set(a.serialized(),i);}return t}Union(t){let e=new s(this);for(let[n,i]of t)e.set(n,i);return e}Intersect(t){let e=new s;for(let[n,i]of this)t.has(n)&&e.set(n,i);return e}HasIntersection(t){for(let[e]of this)if(t.has(e))return true;return false}Without(t){let e=new s(this);for(let[n]of t)e.delete(n);return e}Contains(t){if(typeof t=="string")return this.ContainsItemNamed(t);let e=t;if(e.size==0||this.size==0)return false;for(let[n]of e)if(!this.has(n))return false;return true}GreaterThan(t){return this.Count==0?false:t.Count==0?true:this.minItem.Value>t.maxItem.Value}GreaterThanOrEquals(t){return this.Count==0?false:t.Count==0?true:this.minItem.Value>=t.minItem.Value&&this.maxItem.Value>=t.maxItem.Value}LessThan(t){return t.Count==0?false:this.Count==0?true:this.maxItem.Value<t.minItem.Value}LessThanOrEquals(t){return t.Count==0?false:this.Count==0?true:this.maxItem.Value<=t.maxItem.Value&&this.minItem.Value<=t.minItem.Value}MaxAsList(){return this.Count>0?new s(this.maxItem):new s}MinAsList(){return this.Count>0?new s(this.minItem):new s}ListWithSubRange(t,e){if(this.Count==0)return new s;let n=this.orderedItems,i=0,a=Number.MAX_SAFE_INTEGER;Number.isInteger(t)?i=t:t instanceof s&&t.Count>0&&(i=t.minItem.Value),Number.isInteger(e)?a=e:e instanceof s&&e.Count>0&&(a=e.maxItem.Value);let r=new s;r.SetInitialOriginNames(this.originNames);for(let o of n)o.Value>=i&&o.Value<=a&&r.Add(o.Key,o.Value);return r}Equals(t){if(!(t instanceof s)||t.Count!=this.Count)return false;for(let[e]of this)if(!t.has(e))return false;return true}get orderedItems(){let t=new Array;for(let[e,n]of this){let i=mt.fromSerializedKey(e);t.push({Key:i,Value:n});}return t.sort((e,n)=>e.Key.originName===null?(0, Nt.throwNullException)("x.Key.originName"):n.Key.originName===null?(0, Nt.throwNullException)("y.Key.originName"):e.Value==n.Value?e.Key.originName.localeCompare(n.Key.originName):e.Value<n.Value?-1:e.Value>n.Value?1:0),t}get singleItem(){for(let t of this.orderedItems)return t.Key;return null}toString(){let t=this.orderedItems,e=new Oh.StringBuilder;for(let n=0;n<t.length;n++){n>0&&e.Append(", ");let i=t[n].Key;if(i.itemName===null)return (0, Nt.throwNullException)("item.itemName");e.Append(i.itemName);}return e.toString()}valueOf(){return NaN}};_e.InkList=ws;});var Qe=C(Qn=>{Object.defineProperty(Qn,"__esModule",{value:true});Qn.StoryException=void 0;var xs=class extends Error{constructor(t){super(t),this.useEndLineNumber=false,this.message=t,this.name="StoryException";}};Qn.StoryException=xs;});var Fe=C(Yt=>{Object.defineProperty(Yt,"__esModule",{value:true});Yt.tryParseFloat=Yt.tryParseInt=Yt.tryGetValueFromMap=void 0;function Ph(s,t,e){if(s===null)return {result:e,exists:false};let n=s.get(t);return typeof n>"u"?{result:e,exists:false}:{result:n,exists:true}}Yt.tryGetValueFromMap=Ph;function Th(s,t=0){let e=parseInt(s);return Number.isNaN(e)?{result:t,exists:false}:{result:e,exists:true}}Yt.tryParseInt=Th;function Nh(s,t=0){let e=parseFloat(s);return Number.isNaN(e)?{result:t,exists:false}:{result:e,exists:true}}Yt.tryParseFloat=Nh;});var U=C(K=>{Object.defineProperty(K,"__esModule",{value:true});K.ValueType=K.ListValue=K.VariablePointerValue=K.DivertTargetValue=K.StringValue=K.FloatValue=K.IntValue=K.BoolValue=K.Value=K.AbstractValue=void 0;var ou=pt(),uu=ft(),he=gt(),Ih=Qe(),Ze=q(),lu=Fe(),St=st(),Zn=class s extends ou.InkObject{static Create(t,e){if(e){if(e===$.Int&&Number.isInteger(Number(t)))return new kt(Number(t));if(e===$.Float&&!isNaN(t))return new Rt(Number(t))}if(typeof t=="boolean")return new we(!!t);if(typeof t=="string")return new Ut(String(t));if(Number.isInteger(Number(t)))return new kt(Number(t));if(isNaN(t)){if(t instanceof uu.Path)return new ti((0, Ze.asOrThrows)(t,uu.Path));if(t instanceof he.InkList)return new ei((0, Ze.asOrThrows)(t,he.InkList))}else return new Rt(Number(t));return null}Copy(){return (0, Ze.asOrThrows)(s.Create(this.valueObject),ou.InkObject)}BadCastException(t){return new Ih.StoryException("Can't cast "+this.valueObject+" from "+this.valueType+" to "+t)}};K.AbstractValue=Zn;var It=class extends Zn{constructor(t){super(),this.value=t;}get valueObject(){return this.value}toString(){return this.value===null?(0, St.throwNullException)("Value.value"):this.value.toString()}};K.Value=It;var we=class extends It{constructor(t){super(t||false);}get isTruthy(){return !!this.value}get valueType(){return $.Bool}Cast(t){if(this.value===null)return (0, St.throwNullException)("Value.value");if(t==this.valueType)return this;if(t==$.Int)return new kt(this.value?1:0);if(t==$.Float)return new Rt(this.value?1:0);if(t==$.String)return new Ut(this.value?"true":"false");throw this.BadCastException(t)}toString(){return this.value?"true":"false"}};K.BoolValue=we;var kt=class extends It{constructor(t){super(t||0);}get isTruthy(){return this.value!=0}get valueType(){return $.Int}Cast(t){if(this.value===null)return (0, St.throwNullException)("Value.value");if(t==this.valueType)return this;if(t==$.Bool)return new we(this.value!==0);if(t==$.Float)return new Rt(this.value);if(t==$.String)return new Ut(""+this.value);throw this.BadCastException(t)}};K.IntValue=kt;var Rt=class extends It{constructor(t){super(t||0);}get isTruthy(){return this.value!=0}get valueType(){return $.Float}Cast(t){if(this.value===null)return (0, St.throwNullException)("Value.value");if(t==this.valueType)return this;if(t==$.Bool)return new we(this.value!==0);if(t==$.Int)return new kt(this.value);if(t==$.String)return new Ut(""+this.value);throw this.BadCastException(t)}};K.FloatValue=Rt;var Ut=class extends It{constructor(t){if(super(t||""),this._isNewline=this.value==`
`,this._isInlineWhitespace=true,this.value===null)return (0, St.throwNullException)("Value.value");this.value.length>0&&this.value.split("").every(e=>e!=" "&&e!=" "?(this._isInlineWhitespace=false,false):true);}get valueType(){return $.String}get isTruthy(){return this.value===null?(0, St.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(t){if(t==this.valueType)return this;if(t==$.Int){let e=(0, lu.tryParseInt)(this.value);if(e.exists)return new kt(e.result);throw this.BadCastException(t)}if(t==$.Float){let e=(0, lu.tryParseFloat)(this.value);if(e.exists)return new Rt(e.result);throw this.BadCastException(t)}throw this.BadCastException(t)}};K.StringValue=Ut;var ti=class extends It{constructor(t=null){super(t);}get valueType(){return $.DivertTarget}get targetPath(){return this.value===null?(0, St.throwNullException)("Value.value"):this.value}set targetPath(t){this.value=t;}get isTruthy(){throw new Error("Shouldn't be checking the truthiness of a divert target")}Cast(t){if(t==this.valueType)return this;throw this.BadCastException(t)}toString(){return "DivertTargetValue("+this.targetPath+")"}};K.DivertTargetValue=ti;var Os=class s extends It{constructor(t,e=-1){super(t),this._contextIndex=e;}get contextIndex(){return this._contextIndex}set contextIndex(t){this._contextIndex=t;}get variableName(){return this.value===null?(0, St.throwNullException)("Value.value"):this.value}set variableName(t){this.value=t;}get valueType(){return $.VariablePointer}get isTruthy(){throw new Error("Shouldn't be checking the truthiness of a variable pointer")}Cast(t){if(t==this.valueType)return this;throw this.BadCastException(t)}toString(){return "VariablePointerValue("+this.variableName+")"}Copy(){return new s(this.variableName,this.contextIndex)}};K.VariablePointerValue=Os;var ei=class s extends It{get isTruthy(){return this.value===null?(0, St.throwNullException)("this.value"):this.value.Count>0}get valueType(){return $.List}Cast(t){if(this.value===null)return (0, St.throwNullException)("Value.value");if(t==$.Int){let e=this.value.maxItem;return e.Key.isNull?new kt(0):new kt(e.Value)}else if(t==$.Float){let e=this.value.maxItem;return e.Key.isNull?new Rt(0):new Rt(e.Value)}else if(t==$.String){let e=this.value.maxItem;return e.Key.isNull?new Ut(""):new Ut(e.Key.toString())}if(t==this.valueType)return this;throw this.BadCastException(t)}constructor(t,e){super(null),!t&&!e?this.value=new he.InkList:t instanceof he.InkList?this.value=new he.InkList(t):t instanceof he.InkListItem&&typeof e=="number"&&(this.value=new he.InkList({Key:t,Value:e}));}static RetainListOriginsForAssignment(t,e){let n=(0, Ze.asOrNull)(t,s),i=(0, Ze.asOrNull)(e,s);if(i&&i.value===null)return (0, St.throwNullException)("newList.value");if(n&&n.value===null)return (0, St.throwNullException)("oldList.value");n&&i&&i.value.Count==0&&i.value.SetInitialOriginNames(n.value.originNames);}};K.ListValue=ei;var $;(function(s){s[s.Bool=-1]="Bool",s[s.Int=0]="Int",s[s.Float=1]="Float",s[s.List=2]="List",s[s.String=3]="String",s[s.DivertTarget=4]="DivertTarget",s[s.VariablePointer=5]="VariablePointer";})($||(K.ValueType=$={}));});var hu=C(ni=>{Object.defineProperty(ni,"__esModule",{value:true});ni.SearchResult=void 0;var kh=z(),Ps=class s{constructor(){this.obj=null,this.approximate=false;}get correctObj(){return this.approximate?null:this.obj}get container(){return this.obj instanceof kh.Container?this.obj:null}copy(){let t=new s;return t.obj=this.obj,t.approximate=this.approximate,t}};ni.SearchResult=Ps;});var z=C(en=>{Object.defineProperty(en,"__esModule",{value:true});en.Container=void 0;var Rh=U(),cu=st(),Vh=le(),xe=pt(),Bh=hu(),du=ft(),fu=Xe(),Wh=Fe(),Qt=q(),tn=class s extends xe.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(t){this.AddContent(t);}get namedOnlyContent(){let t=new Map;for(let[e,n]of this.namedContent){let i=(0, Qt.asOrThrows)(n,xe.InkObject);t.set(e,i);}for(let e of this.content){let n=(0, Qt.asINamedContentOrNull)(e);n!=null&&n.hasValidName&&t.delete(n.name);}return t.size==0&&(t=null),t}set namedOnlyContent(t){let e=this.namedOnlyContent;if(e!=null)for(let[n]of e)this.namedContent.delete(n);if(t!=null)for(let[,n]of t){let i=(0, Qt.asINamedContentOrNull)(n);i!=null&&this.AddToNamedContentOnly(i);}}get countFlags(){let t=0;return this.visitsShouldBeCounted&&(t|=s.CountFlags.Visits),this.turnIndexShouldBeCounted&&(t|=s.CountFlags.Turns),this.countingAtStartOnly&&(t|=s.CountFlags.CountStartOnly),t==s.CountFlags.CountStartOnly&&(t=0),t}set countFlags(t){let e=t;(e&s.CountFlags.Visits)>0&&(this.visitsShouldBeCounted=true),(e&s.CountFlags.Turns)>0&&(this.turnIndexShouldBeCounted=true),(e&s.CountFlags.CountStartOnly)>0&&(this.countingAtStartOnly=true);}get pathToFirstLeafContent(){return this._pathToFirstLeafContent==null&&(this._pathToFirstLeafContent=this.path.PathByAppendingPath(this.internalPathToFirstLeafContent)),this._pathToFirstLeafContent}get internalPathToFirstLeafContent(){let t=[],e=this;for(;e instanceof s;)e.content.length>0&&(t.push(new du.Path.Component(0)),e=e.content[0]);return new du.Path(t)}AddContent(t){if(t instanceof Array){let e=t;for(let n of e)this.AddContent(n);}else {let e=t;if(this._content.push(e),e.parent)throw new Error("content is already in "+e.parent);e.parent=this,this.TryAddNamedContent(e);}}TryAddNamedContent(t){let e=(0, Qt.asINamedContentOrNull)(t);e!=null&&e.hasValidName&&this.AddToNamedContentOnly(e);}AddToNamedContentOnly(t){fu.Debug.AssertType(t,xe.InkObject,"Can only add Runtime.Objects to a Runtime.Container");let e=(0, Qt.asOrThrows)(t,xe.InkObject);if(e.parent=this,t.name===null)return (0, cu.throwNullException)("namedContentObj.name");this.namedContent.set(t.name,t);}ContentAtPath(t,e=0,n=-1){n==-1&&(n=t.length);let i=new Bh.SearchResult;i.approximate=false;let a=this,r=this;for(let o=e;o<n;++o){let u=t.GetComponent(o);if(a==null){i.approximate=true;break}let l=a.ContentWithPathComponent(u);if(l==null){i.approximate=true;break}let h=(0, Qt.asOrNull)(l,s);if(o<n-1&&h==null){i.approximate=true;break}r=l,a=h;}return i.obj=r,i}InsertContent(t,e){if(this.content.splice(e,0,t),t.parent)throw new Error("content is already in "+t.parent);t.parent=this,this.TryAddNamedContent(t);}AddContentsOfContainer(t){this.content.push(...t.content);for(let e of t.content)e.parent=this,this.TryAddNamedContent(e);}ContentWithPathComponent(t){if(t.isIndex)return t.index>=0&&t.index<this.content.length?this.content[t.index]:null;if(t.isParent)return this.parent;{if(t.name===null)return (0, cu.throwNullException)("component.name");let e=(0, Wh.tryGetValueFromMap)(this.namedContent,t.name,null);return e.exists?(0, Qt.asOrThrows)(e.result,xe.InkObject):null}}BuildStringOfHierarchy(){let t;if(arguments.length==0)return t=new Vh.StringBuilder,this.BuildStringOfHierarchy(t,0,null),t.toString();t=arguments[0];let e=arguments[1],n=arguments[2];function i(){for(let o=0;o<4*e;++o)t.Append(" ");}i(),t.Append("["),this.hasValidName&&t.AppendFormat(" ({0})",this.name),this==n&&t.Append(" <---"),t.AppendLine(),e++;for(let r=0;r<this.content.length;++r){let o=this.content[r];o instanceof s?o.BuildStringOfHierarchy(t,e,n):(i(),o instanceof Rh.StringValue?(t.Append('"'),t.Append(o.toString().replace(`
`,"\\n")),t.Append('"')):t.Append(o.toString())),r!=this.content.length-1&&t.Append(","),!(o instanceof s)&&o==n&&t.Append(" <---"),t.AppendLine();}let a=new Map;for(let[r,o]of this.namedContent)this.content.indexOf((0, Qt.asOrThrows)(o,xe.InkObject))>=0||a.set(r,o);if(a.size>0){i(),t.AppendLine("-- named: --");for(let[,r]of a)fu.Debug.AssertType(r,s,"Can only print out named Containers"),r.BuildStringOfHierarchy(t,e,n),t.AppendLine();}e--,i(),t.Append("]");}};en.Container=tn;(function(s){(function(e){e[e.Start=0]="Start",e[e.Visits=1]="Visits",e[e.Turns=2]="Turns",e[e.CountStartOnly=4]="CountStartOnly";})(s.CountFlags||(s.CountFlags={}));})(tn||(en.Container=tn={}));});var at=C(rn=>{Object.defineProperty(rn,"__esModule",{value:true});rn.ControlCommand=void 0;var Lh=pt(),nn=class s extends Lh.InkObject{get commandType(){return this._commandType}constructor(t=s.CommandType.NotSet){super(),this._commandType=t;}Copy(){return new s(this.commandType)}static EvalStart(){return new s(s.CommandType.EvalStart)}static EvalOutput(){return new s(s.CommandType.EvalOutput)}static EvalEnd(){return new s(s.CommandType.EvalEnd)}static Duplicate(){return new s(s.CommandType.Duplicate)}static PopEvaluatedValue(){return new s(s.CommandType.PopEvaluatedValue)}static PopFunction(){return new s(s.CommandType.PopFunction)}static PopTunnel(){return new s(s.CommandType.PopTunnel)}static BeginString(){return new s(s.CommandType.BeginString)}static EndString(){return new s(s.CommandType.EndString)}static NoOp(){return new s(s.CommandType.NoOp)}static ChoiceCount(){return new s(s.CommandType.ChoiceCount)}static Turns(){return new s(s.CommandType.Turns)}static TurnsSince(){return new s(s.CommandType.TurnsSince)}static ReadCount(){return new s(s.CommandType.ReadCount)}static Random(){return new s(s.CommandType.Random)}static SeedRandom(){return new s(s.CommandType.SeedRandom)}static VisitIndex(){return new s(s.CommandType.VisitIndex)}static SequenceShuffleIndex(){return new s(s.CommandType.SequenceShuffleIndex)}static StartThread(){return new s(s.CommandType.StartThread)}static Done(){return new s(s.CommandType.Done)}static End(){return new s(s.CommandType.End)}static ListFromInt(){return new s(s.CommandType.ListFromInt)}static ListRange(){return new s(s.CommandType.ListRange)}static ListRandom(){return new s(s.CommandType.ListRandom)}static BeginTag(){return new s(s.CommandType.BeginTag)}static EndTag(){return new s(s.CommandType.EndTag)}toString(){return "ControlCommand "+this.commandType.toString()}};rn.ControlCommand=nn;(function(s){(function(e){e[e.NotSet=-1]="NotSet",e[e.EvalStart=0]="EvalStart",e[e.EvalOutput=1]="EvalOutput",e[e.EvalEnd=2]="EvalEnd",e[e.Duplicate=3]="Duplicate",e[e.PopEvaluatedValue=4]="PopEvaluatedValue",e[e.PopFunction=5]="PopFunction",e[e.PopTunnel=6]="PopTunnel",e[e.BeginString=7]="BeginString",e[e.EndString=8]="EndString",e[e.NoOp=9]="NoOp",e[e.ChoiceCount=10]="ChoiceCount",e[e.Turns=11]="Turns",e[e.TurnsSince=12]="TurnsSince",e[e.ReadCount=13]="ReadCount",e[e.Random=14]="Random",e[e.SeedRandom=15]="SeedRandom",e[e.VisitIndex=16]="VisitIndex",e[e.SequenceShuffleIndex=17]="SequenceShuffleIndex",e[e.StartThread=18]="StartThread",e[e.Done=19]="Done",e[e.End=20]="End",e[e.ListFromInt=21]="ListFromInt",e[e.ListRange=22]="ListRange",e[e.ListRandom=23]="ListRandom",e[e.BeginTag=24]="BeginTag",e[e.EndTag=25]="EndTag",e[e.TOTAL_VALUES=26]="TOTAL_VALUES";})(s.CommandType||(s.CommandType={}));})(nn||(rn.ControlCommand=nn={}));});var yt=C(ii=>{Object.defineProperty(ii,"__esModule",{value:true});ii.Expression=void 0;var pu=z(),Ts=at(),qh=H(),Ns=class extends qh.ParsedObject{constructor(){super(...arguments),this._prototypeRuntimeConstantExpression=null,this.outputWhenComplete=false,this.GenerateRuntimeObject=()=>{let t=new pu.Container;return t.AddContent(Ts.ControlCommand.EvalStart()),this.GenerateIntoContainer(t),this.outputWhenComplete&&t.AddContent(Ts.ControlCommand.EvalOutput()),t.AddContent(Ts.ControlCommand.EvalEnd()),t},this.GenerateConstantIntoContainer=t=>{this._prototypeRuntimeConstantExpression===null&&(this._prototypeRuntimeConstantExpression=new pu.Container,this.GenerateIntoContainer(this._prototypeRuntimeConstantExpression));for(let e of this._prototypeRuntimeConstantExpression.content){let n=e.Copy();n&&t.AddContent(n);}},this.toString=()=>"No string value in JavaScript.";}get typeName(){return "Expression"}Equals(t){return false}};ii.Expression=Ns;});var ce=C(ri=>{Object.defineProperty(ri,"__esModule",{value:true});ri.Void=void 0;var jh=pt(),Is=class extends jh.InkObject{toString(){return "Void"}};ri.Void=Is;});var Vt=C(ai=>{Object.defineProperty(ai,"__esModule",{value:true});ai.NativeFunctionCall=void 0;var _=U(),sn=Qe(),Mh=ce(),si=gt(),Gh=pt(),bt=q(),Ct=st(),R=class s extends Gh.InkObject{static CallWithName(t){return new s(t)}static CallExistsWithName(t){return this.GenerateNativeFunctionsIfNecessary(),this._nativeFunctions.get(t)}get name(){return this._name===null?(0, Ct.throwNullException)("NativeFunctionCall._name"):this._name}set name(t){this._name=t,this._isPrototype||(s._nativeFunctions===null?(0, Ct.throwNullException)("NativeFunctionCall._nativeFunctions"):this._prototype=s._nativeFunctions.get(this._name)||null);}get numberOfParameters(){return this._prototype?this._prototype.numberOfParameters:this._numberOfParameters}set numberOfParameters(t){this._numberOfParameters=t;}Call(t){if(this._prototype)return this._prototype.Call(t);if(this.numberOfParameters!=t.length)throw new Error("Unexpected number of parameters");let e=false;for(let a of t){if(a instanceof Mh.Void)throw new sn.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 _.ListValue&&(e=true);}if(t.length==2&&e)return this.CallBinaryListOperation(t);let n=this.CoerceValuesToSingleType(t),i=n[0].valueType;return i==_.ValueType.Int?this.CallType(n):i==_.ValueType.Float?this.CallType(n):i==_.ValueType.String?this.CallType(n):i==_.ValueType.DivertTarget?this.CallType(n):i==_.ValueType.List?this.CallType(n):null}CallType(t){let e=(0, bt.asOrThrows)(t[0],_.Value),n=e.valueType,i=e,a=t.length;if(a==2||a==1){if(this._operationFuncs===null)return (0, Ct.throwNullException)("NativeFunctionCall._operationFuncs");let r=this._operationFuncs.get(n);if(!r){let o=_.ValueType[n];throw new sn.StoryException("Cannot perform operation "+this.name+" on "+o)}if(a==2){let u=(0, bt.asOrThrows)(t[1],_.Value),l=r;if(i.value===null||u.value===null)return (0, Ct.throwNullException)("NativeFunctionCall.Call BinaryOp values");let h=l(i.value,u.value);return _.Value.Create(h)}else {let o=r;if(i.value===null)return (0, Ct.throwNullException)("NativeFunctionCall.Call UnaryOp value");let u=o(i.value);return this.name===s.Int?_.Value.Create(u,_.ValueType.Int):this.name===s.Float?_.Value.Create(u,_.ValueType.Float):_.Value.Create(u,e.valueType)}}else throw new Error("Unexpected number of parameters to NativeFunctionCall: "+t.length)}CallBinaryListOperation(t){if((this.name=="+"||this.name=="-")&&t[0]instanceof _.ListValue&&t[1]instanceof _.IntValue)return this.CallListIncrementOperation(t);let e=(0, bt.asOrThrows)(t[0],_.Value),n=(0, bt.asOrThrows)(t[1],_.Value);if((this.name=="&&"||this.name=="||")&&(e.valueType!=_.ValueType.List||n.valueType!=_.ValueType.List)){if(this._operationFuncs===null)return (0, Ct.throwNullException)("NativeFunctionCall._operationFuncs");let i=this._operationFuncs.get(_.ValueType.Int);if(i===null)return (0, Ct.throwNullException)("NativeFunctionCall.CallBinaryListOperation op");let a=(0, bt.asBooleanOrThrows)(i(e.isTruthy?1:0,n.isTruthy?1:0));return new _.BoolValue(a)}if(e.valueType==_.ValueType.List&&n.valueType==_.ValueType.List)return this.CallType([e,n]);throw new sn.StoryException("Can not call use "+this.name+" operation on "+_.ValueType[e.valueType]+" and "+_.ValueType[n.valueType])}CallListIncrementOperation(t){let e=(0, bt.asOrThrows)(t[0],_.ListValue),n=(0, bt.asOrThrows)(t[1],_.IntValue),i=new si.InkList;if(e.value===null)return (0, Ct.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value");for(let[a,r]of e.value){let o=si.InkListItem.fromSerializedKey(a);if(this._operationFuncs===null)return (0, Ct.throwNullException)("NativeFunctionCall._operationFuncs");let u=this._operationFuncs.get(_.ValueType.Int);if(n.value===null)return (0, Ct.throwNullException)("NativeFunctionCall.CallListIncrementOperation intVal.value");let l=u(r,n.value),h=null;if(e.value.origins===null)return (0, Ct.throwNullException)("NativeFunctionCall.CallListIncrementOperation listVal.value.origins");for(let c of e.value.origins)if(c.name==o.originName){h=c;break}if(h!=null){let c=h.TryGetItemWithValue(l,si.InkListItem.Null);c.exists&&i.Add(c.result,l);}}return new _.ListValue(i)}CoerceValuesToSingleType(t){let e=_.ValueType.Int,n=null;for(let a of t){let r=(0, bt.asOrThrows)(a,_.Value);r.valueType>e&&(e=r.valueType),r.valueType==_.ValueType.List&&(n=(0, bt.asOrNull)(r,_.ListValue));}let i=[];if(_.ValueType[e]==_.ValueType[_.ValueType.List])for(let a of t){let r=(0, bt.asOrThrows)(a,_.Value);if(r.valueType==_.ValueType.List)i.push(r);else if(r.valueType==_.ValueType.Int){let o=parseInt(r.valueObject);if(n=(0, bt.asOrThrows)(n,_.ListValue),n.value===null)return (0, Ct.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType specialCaseList.value");let u=n.value.originOfMaxItem;if(u===null)return (0, Ct.throwNullException)("NativeFunctionCall.CoerceValuesToSingleType list");let l=u.TryGetItemWithValue(o,si.InkListItem.Null);if(l.exists){let h=new _.ListValue(l.result,o);i.push(h);}else throw new sn.StoryException("Could not find List item with the value "+o+" in "+u.name)}else {let o=_.ValueType[r.valueType];throw new sn.StoryException("Cannot mix Lists and "+o+" values in this operation")}}else for(let a of t){let o=(0, bt.asOrThrows)(a,_.Value).Cast(e);i.push(o);}return i}constructor(){if(super(),this._name=null,this._numberOfParameters=0,this._prototype=null,this._isPrototype=false,this._operationFuncs=null,arguments.length===0)s.GenerateNativeFunctionsIfNecessary();else if(arguments.length===1){let t=arguments[0];s.GenerateNativeFunctionsIfNecessary(),this.name=t;}else if(arguments.length===2){let t=arguments[0],e=arguments[1];this._isPrototype=true,this.name=t,this.numberOfParameters=e;}}static Identity(t){return t}static GenerateNativeFunctionsIfNecessary(){if(this._nativeFunctions==null){this._nativeFunctions=new Map,this.AddIntBinaryOp(this.Add,(n,i)=>n+i),this.AddIntBinaryOp(this.Subtract,(n,i)=>n-i),this.AddIntBinaryOp(this.Multiply,(n,i)=>n*i),this.AddIntBinaryOp(this.Divide,(n,i)=>Math.floor(n/i)),this.AddIntBinaryOp(this.Mod,(n,i)=>n%i),this.AddIntUnaryOp(this.Negate,n=>-n),this.AddIntBinaryOp(this.Equal,(n,i)=>n==i),this.AddIntBinaryOp(this.Greater,(n,i)=>n>i),this.AddIntBinaryOp(this.Less,(n,i)=>n<i),this.AddIntBinaryOp(this.GreaterThanOrEquals,(n,i)=>n>=i),this.AddIntBinaryOp(this.LessThanOrEquals,(n,i)=>n<=i),this.AddIntBinaryOp(this.NotEquals,(n,i)=>n!=i),this.AddIntUnaryOp(this.Not,n=>n==0),this.AddIntBinaryOp(this.And,(n,i)=>n!=0&&i!=0),this.AddIntBinaryOp(this.Or,(n,i)=>n!=0||i!=0),this.AddIntBinaryOp(this.Max,(n,i)=>Math.max(n,i)),this.AddIntBinaryOp(this.Min,(n,i)=>Math.min(n,i)),this.AddIntBinaryOp(this.Pow,(n,i)=>Math.pow(n,i)),this.AddIntUnaryOp(this.Floor,s.Identity),this.AddIntUnaryOp(this.Ceiling,s.Identity),this.AddIntUnaryOp(this.Int,s.Identity),this.AddIntUnaryOp(this.Float,n=>n),this.AddFloatBinaryOp(this.Add,(n,i)=>n+i),this.AddFloatBinaryOp(this.Subtract,(n,i)=>n-i),this.AddFloatBinaryOp(this.Multiply,(n,i)=>n*i),this.AddFloatBinaryOp(this.Divide,(n,i)=>n/i),this.AddFloatBinaryOp(this.Mod,(n,i)=>n%i),this.AddFloatUnaryOp(this.Negate,n=>-n),this.AddFloatBinaryOp(this.Equal,(n,i)=>n==i),this.AddFloatBinaryOp(this.Greater,(n,i)=>n>i),this.AddFloatBinaryOp(this.Less,(n,i)=>n<i),this.AddFloatBinaryOp(this.GreaterThanOrEquals,(n,i)=>n>=i),this.AddFloatBinaryOp(this.LessThanOrEquals,(n,i)=>n<=i),this.AddFloatBinaryOp(this.NotEquals,(n,i)=>n!=i),this.AddFloatUnaryOp(this.Not,n=>n==0),this.AddFloatBinaryOp(this.And,(n,i)=>n!=0&&i!=0),this.AddFloatBinaryOp(this.Or,(n,i)=>n!=0||i!=0),this.AddFloatBinaryOp(this.Max,(n,i)=>Math.max(n,i)),this.AddFloatBinaryOp(this.Min,(n,i)=>Math.min(n,i)),this.AddFloatBinaryOp(this.Pow,(n,i)=>Math.pow(n,i)),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,s.Identity),this.AddStringBinaryOp(this.Add,(n,i)=>n+i),this.AddStringBinaryOp(this.Equal,(n,i)=>n===i),this.AddStringBinaryOp(this.NotEquals,(n,i)=>n!==i),this.AddStringBinaryOp(this.Has,(n,i)=>n.includes(i)),this.AddStringBinaryOp(this.Hasnt,(n,i)=>!n.includes(i)),this.AddListBinaryOp(this.Add,(n,i)=>n.Union(i)),this.AddListBinaryOp(this.Subtract,(n,i)=>n.Without(i)),this.AddListBinaryOp(this.Has,(n,i)=>n.Contains(i)),this.AddListBinaryOp(this.Hasnt,(n,i)=>!n.Contains(i)),this.AddListBinaryOp(this.Intersect,(n,i)=>n.Intersect(i)),this.AddListBinaryOp(this.Equal,(n,i)=>n.Equals(i)),this.AddListBinaryOp(this.Greater,(n,i)=>n.GreaterThan(i)),this.AddListBinaryOp(this.Less,(n,i)=>n.LessThan(i)),this.AddListBinaryOp(this.GreaterThanOrEquals,(n,i)=>n.GreaterThanOrEquals(i)),this.AddListBinaryOp(this.LessThanOrEquals,(n,i)=>n.LessThanOrEquals(i)),this.AddListBinaryOp(this.NotEquals,(n,i)=>!n.Equals(i)),this.AddListBinaryOp(this.And,(n,i)=>n.Count>0&&i.Count>0),this.AddListBinaryOp(this.Or,(n,i)=>n.Count>0||i.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 t=(n,i)=>n.Equals(i),e=(n,i)=>!n.Equals(i);this.AddOpToNativeFunc(this.Equal,2,_.ValueType.DivertTarget,t),this.AddOpToNativeFunc(this.NotEquals,2,_.ValueType.DivertTarget,e);}}AddOpFuncForType(t,e){this._operationFuncs==null&&(this._operationFuncs=new Map),this._operationFuncs.set(t,e);}static AddOpToNativeFunc(t,e,n,i){if(this._nativeFunctions===null)return (0, Ct.throwNullException)("NativeFunctionCall._nativeFunctions");let a=this._nativeFunctions.get(t);a||(a=new s(t,e),this._nativeFunctions.set(t,a)),a.AddOpFuncForType(n,i);}static AddIntBinaryOp(t,e){this.AddOpToNativeFunc(t,2,_.ValueType.Int,e);}static AddIntUnaryOp(t,e){this.AddOpToNativeFunc(t,1,_.ValueType.Int,e);}static AddFloatBinaryOp(t,e){this.AddOpToNativeFunc(t,2,_.ValueType.Float,e);}static AddFloatUnaryOp(t,e){this.AddOpToNativeFunc(t,1,_.ValueType.Float,e);}static AddStringBinaryOp(t,e){this.AddOpToNativeFunc(t,2,_.ValueType.String,e);}static AddListBinaryOp(t,e){this.AddOpToNativeFunc(t,2,_.ValueType.List,e);}static AddListUnaryOp(t,e){this.AddOpToNativeFunc(t,1,_.ValueType.List,e);}toString(){return 'Native "'+this.name+'"'}};ai.NativeFunctionCall=R;R.Add="+";R.Subtract="-";R.Divide="/";R.Multiply="*";R.Mod="%";R.Negate="_";R.Equal="==";R.Greater=">";R.Less="<";R.GreaterThanOrEquals=">=";R.LessThanOrEquals="<=";R.NotEquals="!=";R.Not="!";R.And="&&";R.Or="||";R.Min="MIN";R.Max="MAX";R.Pow="POW";R.Floor="FLOOR";R.Ceiling="CEILING";R.Int="INT";R.Float="FLOAT";R.Has="?";R.Hasnt="!?";R.Intersect="^";R.ListMin="LIST_MIN";R.ListMax="LIST_MAX";R.All="LIST_ALL";R.Count="LIST_COUNT";R.ValueOfList="LIST_VALUE";R.Invert="LIST_INVERT";R._nativeFunctions=null;});var ui=C(oi=>{Object.defineProperty(oi,"__esModule",{value:true});oi.NumberExpression=void 0;var $h=yt(),ks=U(),Hh=q(),Rs=class s extends $h.Expression{constructor(t,e){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 ks.IntValue(this.value)):this.isFloat()?n.AddContent(new ks.FloatValue(this.value)):this.isBool()&&n.AddContent(new ks.BoolValue(this.value));},this.toString=()=>String(this.value),typeof t=="number"&&!Number.isNaN(t)||typeof t=="boolean")this.value=t,this.subtype=e;else throw new Error("Unexpected object type in NumberExpression.")}get typeName(){return "Number"}Equals(t){let e=(0, Hh.asOrNull)(t,s);return e?e.subtype==this.subtype&&e.value==this.value:false}};oi.NumberExpression=Rs;});var Vs=C(li=>{Object.defineProperty(li,"__esModule",{value:true});li.UnaryExpression=void 0;var Uh=yt(),Kh=Vt(),Oe=ui(),Jh=q(),an=class extends Uh.Expression{get nativeNameForOp(){return this.op==="-"?"_":this.op==="not"?"!":this.op}constructor(t,e){super(),this.op=e,this.GenerateIntoContainer=n=>{this.innerExpression.GenerateIntoContainer(n),n.AddContent(Kh.NativeFunctionCall.CallWithName(this.nativeNameForOp));},this.toString=()=>this.nativeNameForOp+this.innerExpression,this.innerExpression=this.AddContent(t);}get typeName(){return "UnaryExpression"}};li.UnaryExpression=an;an.WithInner=(s,t)=>{let e=(0, Jh.asOrNull)(s,Oe.NumberExpression);if(e){if(t==="-"){if(e.isInt())return new Oe.NumberExpression(-e.value,"int");if(e.isFloat())return new Oe.NumberExpression(-e.value,"float")}else if(t=="!"||t=="not"){if(e.isInt())return new Oe.NumberExpression(e.value==0,"bool");if(e.isFloat())return new Oe.NumberExpression(e.value==0,"bool");if(e.isBool())return new Oe.NumberExpression(!e.value,"bool")}throw new Error("Unexpected operation or number type")}return new an(s,t)};});var Ws=C(hi=>{Object.defineProperty(hi,"__esModule",{value:true});hi.BinaryExpression=void 0;var zh=yt(),Xh=Vt(),Yh=Vs(),Qh=q(),Bs=class extends zh.Expression{constructor(t,e,n){super(),this.opName=n,this.GenerateIntoContainer=i=>{this.leftExpression.GenerateIntoContainer(i),this.rightExpression.GenerateIntoContainer(i),this.opName=this.NativeNameForOp(this.opName),i.AddContent(Xh.NativeFunctionCall.CallWithName(this.opName));},this.NativeNameForOp=i=>i==="and"?"&&":i==="or"?"||":i==="mod"?"%":i==="has"?"?":i==="hasnt"?"!?":i,this.toString=()=>`(${this.leftExpression} ${this.opName} ${this.rightExpression})`,this.leftExpression=this.AddContent(t),this.rightExpression=this.AddContent(e),this.opName=n;}get typeName(){return "BinaryExpression"}ResolveReferences(t){if(super.ResolveReferences(t),this.NativeNameForOp(this.opName)==="?"){let e=(0, Qh.asOrNull)(this.leftExpression,Yh.UnaryExpression);e!==null&&(e.op==="not"||e.op==="!")&&this.Error(`Using 'not' or '!' here negates '${e.innerExpression}' rather than the result of the '?' or 'has' operator. You need to add parentheses around the (A ? B) expression.`);}}};hi.BinaryExpression=Bs;});var un=C(ci=>{Object.defineProperty(ci,"__esModule",{value:true});ci.CharacterSet=void 0;var on=class{constructor(t){this.set=new Set,this.Add=e=>this.set.add(e),this.AddRange=(e,n)=>{for(let i=e.charCodeAt(0);i<=n.charCodeAt(0);++i)this.Add(String.fromCharCode(i));return this},this.AddCharacters=e=>{if(typeof e=="string"||Array.isArray(e))for(let n of e)this.Add(n);else for(let n of e.set)this.Add(n);return this},t&&this.AddCharacters(t);}};ci.CharacterSet=on;on.FromRange=(s,t)=>new on().AddRange(s,t);});var gu=C(di=>{Object.defineProperty(di,"__esModule",{value:true});di.CharacterRange=void 0;var mu=un(),ln=class{constructor(t,e,n=[]){if(this._start=t,this._end=e,this._correspondingCharSet=new mu.CharacterSet,this._excludes=new Set,this.ToCharacterSet=()=>{if(this._correspondingCharSet.set.size===0)for(let i=this.start.charCodeAt(0),a;i<=this.end.charCodeAt(0);i+=1)a=String.fromCharCod