// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("require 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 ../core/promiseUtils ../geometry/Geometry ../geometry/SpatialReference".split(" "),function(ka,G,la,Y,O,H,e,P,C,f,Z,aa,Q,ma,na,oa,pa,qa,ba,ra,ca){function x(a,b,c){try{return c(a,null,b.arguments)}catch(d){throw d; }}function h(a,b){try{switch(b.type){case "EmptyStatement":return"lc.voidOperation";case "VariableDeclarator":return sa(a,b);case "VariableDeclaration":var c=[];for(var d=0;db.arguments.length)throw new e.ArcadeCompilationError(a,e.ExecutionErrorCodes.WrongNumberOfParameters,b);if(0===b.arguments.length%2)throw new e.ArcadeCompilationError(a,e.ExecutionErrorCodes.WrongNumberOfParameters,b);const m=z(a);g="var ";for(var p=0;pb.arguments.length||3b.arguments.length)throw new e.ArcadeCompilationError(a,e.ExecutionErrorCodes.WrongNumberOfParameters,b);if(2===b.arguments.length)g=`(${h(a,b.arguments[1])})`;else{if(0===(b.arguments.length-1)%2)throw new e.ArcadeCompilationError(a,e.ExecutionErrorCodes.WrongNumberOfParameters,b);p=z(a);var r=z(a);d="var ";for(c=1;c{if(b.length!==this.paramCount)throw new e.ArcadeExecutionError(a,e.ExecutionErrorCodes.WrongNumberOfParameters, null);return this.fn(...b)}}call(a,b){return this.fn(...b.arguments)}marshalledCall(a,b,c,d){return d(a,b,(g,t,p)=>{p=p.map(n=>!f.isFunctionParameter(n)||n instanceof C.ScopeMarshalledFunction?n:C.wrapModuleScopedResponse(n,a,d));g=this.call(c,{arguments:p});return ba.isPromiseLike(g)?g.then(n=>C.wrapModuleScopedResponse(n,c,d)):g})}}const u={};Q.registerFunctions(u,x);qa.registerFunctions(u,x);oa.registerFunctions(u,x);ma.registerFunctions(u,x);pa.registerFunctions(u,x);u.iif=function(a,b){try{return x(a, b,(c,d,g)=>{throw new e.ArcadeExecutionError(a,e.ExecutionErrorCodes.Unrecognized,b);})}catch(c){throw c;}};u.decode=function(a,b){try{return x(a,b,(c,d,g)=>{throw new e.ArcadeExecutionError(a,e.ExecutionErrorCodes.Unrecognized,b);})}catch(c){throw c;}};u.when=function(a,b){try{return x(a,b,(c,d,g)=>{throw new e.ArcadeExecutionError(a,e.ExecutionErrorCodes.Unrecognized,b);})}catch(c){throw c;}};u.defaultvalue=function(a,b){try{return x(a,b,(c,d,g)=>{throw new e.ArcadeExecutionError(a,e.ExecutionErrorCodes.Unrecognized, b);})}catch(c){throw c;}};const I={};for(const a in u)I[a]=new C.NativeFunction(u[a]);na.registerFunctions(u,x);for(const a in u)u[a]=new C.NativeFunction(u[a]);const W=function(){};W.prototype=u;const V=function(){};V.prototype=I;Q={fixSpatialReference:f.fixSpatialReference,parseArguments:function(a,b){const c=[];for(let d=0;d{function p(k){try{r(d.next(k))}catch(m){t(m)}}function n(k){try{r(d["throw"](k))}catch(m){t(m)}}function r(k){k.done? g(k.value):k.value?.then?k.value.then(p,n):(X++,0===X%100?setTimeout(()=>{X=0;p(k.value)},0):p(k.value))}r((d=d.apply(a,b||[])).next())})},functionDepthchecker(a,b){return function(){b.depthCounter.depth++;b.localStack.push([]);if(64{b.depthCounter.depth--;--b.localStack.length;return d});b.depthCounter.depth--;--b.localStack.length; return c}},chkAssig(a,b){if(void 0===b.gdefs[a])throw new e.ArcadeExecutionError(b,e.ExecutionErrorCodes.InvalidIdentifier,null);return a},mustBoolean(a,b){if(!0===a||!1===a)return a;throw new e.ArcadeExecutionError(b,e.ExecutionErrorCodes.BooleanConditionRequired,null);},setAssig(a,b){b.gdefs[a]=1;return a},castString(a){return f.toString(a)},aCheck(a,b){if(f.isFunctionParameter(a)){if("ArrayExpression"===b)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.NoFunctionInArray,null);if("ObjectExpression"=== b)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.NoFunctionInDictionary,null);throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.NoFunctionInTemplateLiteral,null);}return a===f.voidOperation?null:a},Dictionary:H,Feature:P,UserDefinedCompiledFunction:ja,dictionary(a){const b={},c=new Map;for(let d=0;db&&(b=a.length+b);if(0>b||b>=a.length)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds,null);g=f.toNumber(a[b]);a[b]="++"===c?g+1:g-1}else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ArrayAccessorMustBeNumber,null);else if(a instanceof H){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.KeyAccessorMustBeString,null);if(!0===a.hasField(b))g=f.toNumber(a.field(b)), a.setField(b,"++"===c?g+1:g-1);else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.FieldNotFound,null,{key:b});}else if(f.isFeature(a)){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.KeyAccessorMustBeString,null);if(!0===a.hasField(b))g=f.toNumber(a.field(b)),a.setField(b,"++"===c?g+1:g-1);else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.FieldNotFound,null);}else{if(f.isImmutableArray(a))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.Immutable, null);if(a instanceof K){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ModuleAccessorMustBeString,null);if(!0===a.hasGlobal(b))g=f.toNumber(a.global(b)),a.setGlobal(b,"++"===c?g+1:g-1);else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ModuleExportNotFound,null);}else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidIdentifier,null);}return!1===d?g:"++"===c?g+1:g-1},assignmember(a,b,c,d){if(f.isArray(a))if(f.isNumber(b)){0>b&&(b= a.length+b);if(0>b||b>a.length)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds,null);if(b===a.length&&"\x3d"!==c)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds,null);a[b]=this.assign(d,c,a[b])}else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ArrayAccessorMustBeNumber,null);else if(a instanceof H){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.KeyAccessorMustBeString,null);if(!0===a.hasField(b))a.setField(b, this.assign(d,c,a.field(b)));else{if("\x3d"!==c)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.FieldNotFound,null);a.setField(b,this.assign(d,c,null))}}else if(f.isFeature(a)){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.KeyAccessorMustBeString,null);if(!0===a.hasField(b))a.setField(b,this.assign(d,c,a.field(b)));else{if("\x3d"!==c)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.FieldNotFound,null);a.setField(b,this.assign(d,c,null))}}else{if(f.isImmutableArray(a))throw new e.ArcadeExecutionError(null, e.ExecutionErrorCodes.Immutable,null);if(a instanceof K){if(!1===f.isString(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ModuleAccessorMustBeString,null);if(a.hasGlobal(b))a.setGlobal(b,this.assign(d,c,a.global(b)));else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.ModuleExportNotFound,null);}else throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidIdentifier,null);}},member(a,b){if(null===a)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.MemberOfNull, null);if(a instanceof H||f.isFeature(a)){if(f.isString(b))return a.field(b);throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);}if(a instanceof ra){if(f.isString(b))return O.geometryMember(a,b,null,null);throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);}if(f.isArray(a)){if(f.isNumber(b)&&isFinite(b)&&Math.floor(b)===b){0>b&&(b=a.length+b);if(b>=a.length||0>b)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds, null);return a[b]}throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);}if(f.isString(a)){if(f.isNumber(b)&&isFinite(b)&&Math.floor(b)===b){0>b&&(b=a.length+b);if(b>=a.length||0>b)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds,null);return a[b]}throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);}if(f.isImmutableArray(a)){if(f.isNumber(b)&&isFinite(b)&&Math.floor(b)===b){0>b&&(b=a.length()+b);if(b>=a.length()|| 0>b)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.OutOfBounds,null);return a.get(b)}throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);}if(a instanceof K&&f.isString(b))return a.global(b);throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidMemberAccessKey,null);},callfunc(a,b,c){return a.call(c,{arguments:b,preparsed:!0})},loadModule(a,b){a=b.moduleFactoryMap[a];if(b.moduleSingletons[a])return b.moduleSingletons[a];const c=b.moduleFactory[a]({vars:{}, moduleSingletons:b.moduleSingletons,depthCounter:b.depthCounter,console:b.console,abortSignal:b.abortSignal,isAsync:b.isAsync,services:b.services,lrucache:b.lrucache,timeZone:b.timeZone??null,interceptor:b.interceptor},b.spatialReference);return b.moduleSingletons[a]=c},callModuleFunction(a,b,c,d){if(!(a instanceof K))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.FunctionNotFound,null);a=a.global(c);if(!1===f.isFunctionParameter(a))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.CallNonFunction, null);return a.call(d,{preparsed:!0,arguments:b})},getNestedOptionalValue(a,b){return O.getNestedOptionalValue(a,b)}};class K extends la.ArcadeModule{constructor(a){super(null);this.moduleContext=a}hasGlobal(a){void 0===this.moduleContext.exports[a]&&(a=a.toLowerCase());return void 0!==this.moduleContext.exports[a]?!0:!1}setGlobal(a,b){const c=this.moduleContext.globalScope;a=a.toLowerCase();if(f.isFunctionParameter(b))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.AssignModuleFunction, null);c[this.moduleContext.exportmangle[a]]=b}global(a){const b=this.moduleContext.globalScope;a=a.toLowerCase();const c=b[this.moduleContext.exportmangle[a]];if(void 0===c)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.InvalidIdentifier,null);if(f.isFunctionParameter(c)&&!(c instanceof C.ScopeMarshalledFunction)){const d=new C.ScopeMarshalledFunction;d.fn=c;d.parameterEvaluator=x;d.context=this.moduleContext;return b[this.moduleContext.exportmangle[a]]=d}return c}}G.UserDefinedCompiledFunction= ja;G.compileScript=function(a,b,c=!1){null===b&&(b={vars:{},customfunctions:{}});var d=null;a.usesModules&&(d=new Y.ArcadeModuleLoader(null,a.loadedModules));d={isAsync:c,globalScope:fa(b.vars,c?I:u,b.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:b.customfunctions,libraryResolver:d,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:N,lrucache:b.lrucache,timeZone:b.timeZone??null,interceptor:b.interceptor,services:b.services, symbols:{symbolCounter:0}};a=h(d,a);""===a&&(a="lc.voidOperation; ");0{throw new e.ArcadeCompilationError(b,e.ExecutionErrorCodes.InvalidIdentifier,k.node);});const g=d.moduleFactory,t=d.moduleFactoryMap,p=d.exports,n={};for(var r in p)n[r]=void 0!==d.mangleMap[r]?d.mangleMap[r]:r;r={lc:f.lc,lang:ia,mangles:d.mangleMap,postProcess(k){k instanceof f.returnResult&&(k=k.value);k instanceof f.implicitResult&&(k=k.value);k=== f.voidOperation&&(k=null);if(k===f.breakResult)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.IllegalResult,null);if(k===f.continueResult)throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.IllegalResult,null);if(f.isFunctionParameter(k))throw new e.ArcadeExecutionError(null,e.ExecutionErrorCodes.IllegalResult,null);return k},prepare(k,m){let B=k.spatialReference;if(null===B||void 0===B)B=ca.WebMercator;const U=ha(k.vars,k.customfunctions,m,k.timeZone);return{localStack:[],isAsync:m, moduleFactory:g,moduleFactoryMap:t,mangleMap:this.mangles,moduleSingletons:{},exports:p,gdefs:{},exportmangle:n,spatialReference:B,globalScope:U,abortSignal:void 0===k.abortSignal||null===k.abortSignal?{aborted:!1}:k.abortSignal,localScope:null,services:k.services,console:k.console??N,lrucache:k.lrucache,timeZone:k.timeZone??null,interceptor:k.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return(new Function("context","spatialReference",c?"var runtimeCtx\x3dthis.prepare(context, true);\n var lc \x3d this.lc; var lang \x3d this.lang; var gscope\x3druntimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement\x3dlc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+ a+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx\x3dthis.prepare(context, false);\n var lc \x3d this.lc; var lang \x3d this.lang; var gscope\x3druntimeCtx.globalScope; \n function mainBody() {\n var lastStatement\x3dlc.voidOperation;\n "+a+"\n return lastStatement; } \n return this.postProcess(mainBody()); ")).bind(r)};G.enableAsyncSupport=async function(){const a=await new Promise((b,c)=>ka(["./functions/geomasync"],b,c));M([a],"async");return!0}; G.executeScript=function(a,b){return a(b)};G.extend=M;G.functionHelper=Q;Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});