// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ./ArcadeModule ./ArcadeModuleLoader ./containerUtils ./Dictionary ./executionError ./Feature ./FunctionWrapper ../chunks/languageUtils ./treeAnalysis ../chunks/array ./functions/date ./functions/geometry ./functions/geomsync ./functions/maths ./functions/stats ./functions/string ../geometry/Geometry ../geometry/SpatialReference".split(" "),function(H,K,P,L,w,d,ea,t,e,fa,ha,ia,ja,ka,la,ma,na,Q,R){function S(a,b){const c=[];for(let f=0;fl&&(l=c.length+l);if(0>l||l>c.length)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds,b);if(l===c.length&&"\x3d"!==b.operator)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds,b);c[l]=v(g,b.operator,c[l],b,a)}else throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.ArrayAccessorMustBeNumber,b);else if(c instanceof w){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.KeyAccessorMustBeString,b);if(!0===c.hasField(l))c.setField(l,v(g,b.operator,c.field(l),b,a));else{if("\x3d"!==b.operator)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FieldNotFound,b,{key:l});c.setField(l,v(g,b.operator,null,b,a))}}else if(e.isFeature(c)){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.KeyAccessorMustBeString, b);if(!0===c.hasField(l))c.setField(l,v(g,b.operator,c.field(l),b,a));else{if("\x3d"!==b.operator)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FieldNotFound,b,{key:l});c.setField(l,v(g,b.operator,null,b,a))}}else{if(e.isImmutableArray(c))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.Immutable,b);if(c instanceof A){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.ModuleAccessorMustBeString,b);if(!0===c.hasGlobal(l))c.setGlobal(l,v(g,b.operator,c.global(l), b,a));else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.ModuleExportNotFound,b);}else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidIdentifier,b);}var E=e.voidOperation}else{c=b.left.name.toLowerCase();var B=k(a,b.right);if(null!=a.localScope&&void 0!==a.localScope[c])a.localScope[c]={value:v(B,b.operator,a.localScope[c].value,b,a),valueset:!0,node:b.right},E=e.voidOperation;else if(void 0!==a.globalScope[c])a.globalScope[c]={value:v(B,b.operator,a.globalScope[c].value, b,a),valueset:!0,node:b.right},E=e.voidOperation;else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidIdentifier,b);}return E;case "UpdateExpression":{let g;c=null;l="";if("MemberExpression"===b.argument.type){c=k(a,b.argument.object);!0===b.argument.computed?l=k(a,b.argument.property):"Identifier"===b.argument.property.type&&(l=b.argument.property.name);if(e.isArray(c))if(e.isNumber(l)){0>l&&(l=c.length+l);if(0>l||l>=c.length)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds, b);g=e.toNumber(c[l]);c[l]="++"===b.operator?g+1:g-1}else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.ArrayAccessorMustBeNumber,b);else if(c instanceof w){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.KeyAccessorMustBeString,b);if(!0===c.hasField(l))g=e.toNumber(c.field(l)),c.setField(l,"++"===b.operator?g+1:g-1);else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FieldNotFound,b);}else if(e.isFeature(c)){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.KeyAccessorMustBeString,b);if(!0===c.hasField(l))g=e.toNumber(c.field(l)),c.setField(l,"++"===b.operator?g+1:g-1);else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FieldNotFound,b);}else{if(e.isImmutableArray(c))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.Immutable,b);if(c instanceof A){if(!1===e.isString(l))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.ModuleAccessorMustBeString,b);if(!0===c.hasGlobal(l))g=e.toNumber(c.global(l)),c.setGlobal(l, "++"===b.operator?g+1:g-1);else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.ModuleExportNotFound,b);}else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidParameter,b);}var x=!1===b.prefix?g:"++"===b.operator?g+1:g-1}else{c="Identifier"===b.argument.type?b.argument.name.toLowerCase():"";if(!c)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidIdentifier,b);if(null!=a.localScope&&void 0!==a.localScope[c])g=e.toNumber(a.localScope[c].value),a.localScope[c]={value:"++"=== b.operator?g+1:g-1,valueset:!0,node:b},x=!1===b.prefix?g:"++"===b.operator?g+1:g-1;else if(void 0!==a.globalScope[c])g=e.toNumber(a.globalScope[c].value),a.globalScope[c]={value:"++"===b.operator?g+1:g-1,valueset:!0,node:b},x=!1===b.prefix?g:"++"===b.operator?g+1:g-1;else throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidIdentifier,b);}}return x;case "BreakStatement":return e.breakResult;case "ContinueStatement":return e.continueResult;case "TemplateElement":return b.value?b.value.cooked: "";case "TemplateLiteral":B="";x=0;for(const g of b.quasis)if(B+=g.value?g.value.cooked:"",!1===g.tail){if(b.expressions[x]){var J=e;l=J.toString;var q=k(a,b.expressions[x]),C=a;E=b;if(e.isFunctionParameter(q))throw new d.ArcadeExecutionError(C,d.ExecutionErrorCodes.NoFunctionInTemplateLiteral,E);c=l.call(J,q)}else c="";B+=c;x++}return B;case "ForStatement":null!==b.init&&k(a,b.init);C={testResult:!0,lastAction:e.voidOperation};do b:{c=a;l=b;q=C;if(null!==l.test){q.testResult=k(c,l.test);if(!1=== q.testResult)break b;if(!0!==q.testResult)throw new d.ArcadeExecutionError(c,d.ExecutionErrorCodes.BooleanConditionRequired,l);}q.lastAction=k(c,l.body);q.lastAction===e.breakResult?q.testResult=!1:q.lastAction instanceof e.returnResult?q.testResult=!1:null!==l.update&&k(c,l.update)}while(!0===C.testResult);J=C.lastAction instanceof e.returnResult?C.lastAction:e.voidOperation;return J;case "ForInStatement":return qa(a,b);case "WhileStatement":c=!0;var F=e.voidOperation;c=k(a,b.test);if(!1===c)var W= e.voidOperation;else{if(!0!==c)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.BooleanConditionRequired,b);for(;!0===c;){F=k(a,b.body);if(F===e.breakResult)break;if(F instanceof e.returnResult)break;c=k(a,b.test);if(!0!==c&&!1!==c)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.BooleanConditionRequired,b);}W=F instanceof e.returnResult?F:e.voidOperation}return W;case "Identifier":return X(a,b);case "MemberExpression":return ra(a,b);case "Literal":return b.value;case "CallExpression":a:try{if("MemberExpression"=== b.callee.type){const g=k(a,b.callee.object);if(!(g instanceof A))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FunctionNotFound,b);const y=!1===b.callee.computed?b.callee.property.name:k(a,b.callee.property);if(!g.hasGlobal(y))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FunctionNotFound,b);const D=g.global(y);if(!e.isFunctionParameter(D))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.CallNonFunction,b);var M=D.call(a,b)}else{if("Identifier"!==b.callee.type)throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.FunctionNotFound,b);if(null!=a.localScope&&void 0!==a.localScope[b.callee.name.toLowerCase()]){const g=a.localScope[b.callee.name.toLowerCase()];if(e.isFunctionParameter(g.value)){M=g.value.call(a,b);break a}throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.CallNonFunction,b);}if(void 0!==a.globalScope[b.callee.name.toLowerCase()]){const g=a.globalScope[b.callee.name.toLowerCase()];if(e.isFunctionParameter(g.value)){M=g.value.call(a,b);break a}throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.CallNonFunction,b);}throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.FunctionNotFound,b);}}catch(g){throw g;}return M;case "UnaryExpression":return sa(a,b);case "BinaryExpression":return ta(a,b);case "LogicalExpression":return ua(a,b);case "ArrayExpression":try{c=[];for(l=0;lf&&(f=c.length+f);if(f>=c.length||0>f)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds,b);return c[f]}throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.InvalidMemberAccessKey,b);}if(e.isString(c)){if(e.isNumber(f)&&isFinite(f)&&Math.floor(f)===f){0>f&&(f=c.length+f);if(f>=c.length||0>f)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds,b);return c[f]}throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidMemberAccessKey,b);}if(e.isImmutableArray(c)&&e.isNumber(f)&&isFinite(f)&&Math.floor(f)===f){0>f&&(f=c.length()+f);if(f>=c.length()||0>f)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.OutOfBounds, b);return c.get(f)}throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.InvalidMemberAccessKey,b);}catch(c){throw c;}}function sa(a,b){try{const c=k(a,b.argument);if(e.isBoolean(c)){if("!"===b.operator)return!c;if("-"===b.operator)return-1*e.toNumber(c);if("+"===b.operator)return 1*e.toNumber(c);if("~"===b.operator)return~e.toNumber(c);throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.UnsupportedUnaryOperator,b);}if("~"===b.operator)return~e.toNumber(c);if("-"===b.operator)return-1*e.toNumber(c); if("+"===b.operator)return 1*e.toNumber(c);throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.UnsupportedUnaryOperator,b);}catch(c){throw c;}}function ta(a,b){try{const c=[k(a,b.left),k(a,b.right)],f=c[0],h=c[1];switch(b.operator){case "|":case "\x3c\x3c":case "\x3e\x3e":case "\x3e\x3e\x3e":case "^":case "\x26":return e.binaryOperator(e.toNumber(f),e.toNumber(h),b.operator);case "\x3d\x3d":return e.equalityTest(f,h);case "!\x3d":return!e.equalityTest(f,h);case "\x3c":return e.greaterThanLessThan(f, h,b.operator);case "\x3e":return e.greaterThanLessThan(f,h,b.operator);case "\x3c\x3d":return e.greaterThanLessThan(f,h,b.operator);case "\x3e\x3d":return e.greaterThanLessThan(f,h,b.operator);case "+":return e.isString(f)||e.isString(h)?e.toString(f)+e.toString(h):e.toNumber(f)+e.toNumber(h);case "-":return e.toNumber(f)-e.toNumber(h);case "*":return e.toNumber(f)*e.toNumber(h);case "/":return e.toNumber(f)/e.toNumber(h);case "%":return e.toNumber(f)%e.toNumber(h);default:throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.UnsupportedOperator,b);}}catch(c){throw c;}}function ua(a,b){try{const c=k(a,b.left);if(e.isBoolean(c))switch(b.operator){case "||":if(!0===c)return c;const f=k(a,b.right);if(e.isBoolean(f))return f;throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.LogicExpressionOrAnd,b);case "\x26\x26":if(!1===c)return c;const h=k(a,b.right);if(e.isBoolean(h))return h;throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.LogicExpressionOrAnd,b);default:throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.LogicExpressionOrAnd,b);}throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.LogicalExpressionOnlyBoolean,b);}catch(c){throw c;}}function X(a,b){let c;try{const f=b.name.toLowerCase();if(null!=a.localScope&&void 0!==a.localScope[f]){c=a.localScope[f];if(!0===c.valueset)return c.value;c.value=k(a,c.node);c.valueset=!0;return c.value}if(void 0!==a.globalScope[f]){c=a.globalScope[f];if(!0===c.valueset)return c.value;c.value=k(a,c.node);c.valueset=!0;return c.value}throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.InvalidIdentifier,b);}catch(f){throw f;}}function Z(a,b,c,f){try{const h=b.arguments,m=k(a,h[c]);if(e.equalityTest(m,f))return k(a,h[c+1]);const p=h.length-c;return 1===p?k(a,h[c]):2===p?null:3===p?k(a,h[c+2]):Z(a,b,c+2,f)}catch(h){throw h;}}function aa(a,b,c,f){try{const h=b.arguments;if(!0===f)return k(a,h[c+1]);if(3===h.length-c)return k(a,h[c+2]);const m=k(a,h[c+2]);if(!1===e.isBoolean(m))throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.BooleanConditionRequired,h[c+ 2]);return aa(a,b,c+2,m)}catch(h){throw h;}}function O(a,b,c,f){try{const h=a.body;if(c.length!==a.params.length)throw new d.ArcadeExecutionError(b,d.ExecutionErrorCodes.WrongNumberOfParameters,f);if(null!=b.localScope)for(let p=0;p{const c={spatialReference:this.context.spatialReference,console:this.context.console,services:this.context.services,timeZone:this.context.timeZone??null,lrucache:this.context.lrucache,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:a.depthCounter.depth+1},globalScope:this.context.globalScope}; if(64{c={spatialReference:a.spatialReference,services:a.services,globalScope:a.globalScope,depthCounter:{depth:a.depthCounter.depth+1},libraryResolver:a.libraryResolver,exports:a.exports,timeZone:a.timeZone??null,console:a.console,lrucache:a.lrucache,interceptor:a.interceptor,localScope:{}};if(64{h={spatialReference:a.spatialReference,globalScope:c.globalScope,services:a.services,depthCounter:{depth:a.depthCounter.depth+1},libraryResolver:a.libraryResolver,exports:a.exports,console:a.console,timeZone:a.timeZone??null,lrucache:a.lrucache,interceptor:a.interceptor,localScope:{}};p=p.map(u=>!e.isFunctionParameter(u)||u instanceof t.ScopeMarshalledFunction?u:t.wrapModuleScopedResponse(u, a,f));return t.wrapModuleScopedResponse(O(this.definition,h,p,b),c,f)})}}class A extends K.ArcadeModule{constructor(a){super(a)}global(a){a=this.executingContext.globalScope[a.toLowerCase()];a.valueset||(a.value=k(this.executingContext,a.node),a.valueset=!0);if(e.isFunctionParameter(a.value)&&!(a.value instanceof t.ScopeMarshalledFunction)){const b=new t.ScopeMarshalledFunction;b.fn=a.value;b.parameterEvaluator=r;b.context=this.executingContext;a.value=b}return a.value}setGlobal(a,b){if(e.isFunctionParameter(b))throw new d.ArcadeExecutionError(null, d.ExecutionErrorCodes.AssignModuleFunction,null);this.executingContext.globalScope[a.toLowerCase()]={value:b,valueset:!0,node:null}}hasGlobal(a){void 0===this.executingContext.exports[a]&&(a=a.toLowerCase());return void 0!==this.executingContext.exports[a]?!0:!1}loadModule(a){let b=a.spatialReference;if(null===b||void 0===b)b=new R({wkid:102100});this.moduleScope=ba({},a.customfunctions,a.timeZone);this.executingContext={spatialReference:b,globalScope:this.moduleScope,localScope:null,libraryResolver:new P.ArcadeModuleLoader(a.libraryResolver._moduleSingletons, this.source.syntax.loadedModules),exports:{},services:a.services,console:a.console??ca,timeZone:a.timeZone??null,lrucache:a.lrucache,interceptor:a.interceptor,depthCounter:{depth:1}};k(this.executingContext,this.source.syntax)}}const n={};ia.registerFunctions(n,r);na.registerFunctions(n,r);la.registerFunctions(n,r);ja.registerFunctions(n,r);ma.registerFunctions(n,r);ka.registerFunctions(n,r);n.iif=function(a,b){try{const c=b.arguments;e.pcCheck(null===c?[]:c,3,3,a,b);const f=k(a,c[0]);if(!1===e.isBoolean(f))throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.BooleanConditionRequired,b);return!0===f?k(a,c[1]):k(a,c[2])}catch(c){throw c;}};n.defaultvalue=function(a,b){try{const c=b.arguments;e.pcCheck(null===c?[]:c,2,3,a,b);const f=k(a,c[0]);if(3===c.length){const h=k(a,c[1]),m=L.getNestedOptionalValue(f,h);return null!=m&&""!==m?m:k(a,c[2])}return null===f||""===f||void 0===f?k(a,c[1]):f}catch(c){throw c;}};n.decode=function(a,b){try{const c=b.arguments;if(2>c.length)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.WrongNumberOfParameters, b);if(2===c.length)return k(a,c[1]);if(0===(c.length-1)%2)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.WrongNumberOfParameters,b);const f=k(a,c[0]);return Z(a,b,1,f)}catch(c){throw c;}};n.when=function(a,b){try{const c=b.arguments;if(3>c.length)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.WrongNumberOfParameters,b);if(0===c.length%2)throw new d.ArcadeExecutionError(a,d.ExecutionErrorCodes.WrongNumberOfParameters,b);const f=k(a,c[0]);if(!1===e.isBoolean(f))throw new d.ArcadeExecutionError(a, d.ExecutionErrorCodes.BooleanConditionRequired,c[0]);return aa(a,b,0,f)}catch(c){throw c;}};for(const a in n)n[a]={value:new t.NativeFunction(n[a]),valueset:!0,node:null};const G=function(){};G.prototype=n;G.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null};G.prototype.pi={value:Math.PI,valueset:!0,node:null};K={fixSpatialReference:e.fixSpatialReference,parseArguments:S,standardFunction:r};da([ha.ArrayFunctions]);H.executeScript=function(a,b){let c=b.spatialReference;if(null=== c||void 0===c)c=new R({wkid:102100});let f=null;a.usesModules&&(f=new P.ArcadeModuleLoader(new Map,a.loadedModules));const h=ba(b.vars,b.customfunctions,b.timeZone);b={spatialReference:c,globalScope:h,localScope:null,services:b.services??null,exports:{},libraryResolver:f,console:b.console??ca,timeZone:b.timeZone??null,lrucache:b.lrucache,interceptor:b.interceptor,depthCounter:{depth:1}};a=k(b,a);a instanceof e.returnResult&&(a=a.value);a instanceof e.implicitResult&&(a=a.value);a===e.voidOperation&& (a=null);if(a===e.breakResult)throw new d.ArcadeExecutionError(b,d.ExecutionErrorCodes.IllegalResult,null);if(a===e.continueResult)throw new d.ArcadeExecutionError(b,d.ExecutionErrorCodes.IllegalResult,null);if(e.isFunctionParameter(a))throw new d.ArcadeExecutionError(b,d.ExecutionErrorCodes.IllegalResult,null);return a};H.extend=da;H.functionHelper=K;Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});