@arcgis/core 4.31.0-next.20240523 → 4.31.0-next.20240524

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/arcade/arcadeAsyncRuntime.js +1 -1
  2. package/arcade/arcadeCompiler.js +1 -1
  3. package/arcade/arcadeRuntime.js +1 -1
  4. package/arcade/containerUtils.js +5 -0
  5. package/arcade/functions/geometry.js +1 -1
  6. package/arcade.js +1 -1
  7. package/assets/esri/core/workers/RemoteClient.js +1 -1
  8. package/assets/esri/core/workers/chunks/3e11cc999936cd97f8ea.js +1 -0
  9. package/assets/esri/core/workers/chunks/621178ba416f92cb7d22.js +1 -0
  10. package/assets/esri/core/workers/chunks/{f56ab3e1f914cfe1ea71.js → 8992b2cf52f7f80a3ffd.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{16608dc112d4af1f7f97.js → a37b95cd0dce2e47e161.js} +1 -1
  12. package/assets/esri/core/workers/chunks/b2562f5d0d5a44dc004e.js +1 -0
  13. package/assets/esri/core/workers/chunks/c80568ff68be908b3c30.js +1 -0
  14. package/assets/esri/core/workers/chunks/ccad364912ff1d85a9dc.js +1 -0
  15. package/assets/esri/core/workers/chunks/ce130ddf9eeafbd39a47.js +1 -0
  16. package/assets/esri/core/workers/chunks/{7c764bbd5dd650512cd8.js → ce5a9206eb3b4e43d3f1.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{7b93aa6615cfa9b14978.js → f12251c286a24e90ba8a.js} +1 -1
  18. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ar.json +1 -1
  19. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_bg.json +1 -1
  20. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_bs.json +1 -1
  21. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ca.json +1 -1
  22. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_cs.json +1 -1
  23. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_da.json +1 -1
  24. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_de.json +1 -1
  25. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_el.json +1 -1
  26. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_es.json +1 -1
  27. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_et.json +1 -1
  28. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_fi.json +1 -1
  29. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_fr.json +1 -1
  30. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_he.json +1 -1
  31. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_hr.json +1 -1
  32. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_hu.json +1 -1
  33. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_id.json +1 -1
  34. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_it.json +1 -1
  35. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ja.json +1 -1
  36. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ko.json +1 -1
  37. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_lt.json +1 -1
  38. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_lv.json +1 -1
  39. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_nb.json +1 -1
  40. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_nl.json +1 -1
  41. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_pl.json +1 -1
  42. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_pt-BR.json +1 -1
  43. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_pt-PT.json +1 -1
  44. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ro.json +1 -1
  45. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_ru.json +1 -1
  46. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_sk.json +1 -1
  47. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_sl.json +1 -1
  48. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_sr.json +1 -1
  49. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_sv.json +1 -1
  50. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_th.json +1 -1
  51. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_tr.json +1 -1
  52. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_uk.json +1 -1
  53. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_vi.json +1 -1
  54. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_zh-CN.json +1 -1
  55. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_zh-HK.json +1 -1
  56. package/assets/esri/widgets/FeatureTable/t9n/FeatureTable_zh-TW.json +1 -1
  57. package/chunks/Theme.js +1 -1
  58. package/chunks/chartUtilsAm5.js +1 -1
  59. package/geometry/GeometryCursor.js +1 -1
  60. package/interfaces.d.ts +27 -41
  61. package/layers/BuildingSceneLayer.js +1 -1
  62. package/layers/buildingSublayers/BuildingComponentSublayer.js +1 -1
  63. package/layers/support/arcadeUtils.js +1 -1
  64. package/package.json +1 -1
  65. package/portal/schemas/buildingSceneLayerItem.js +1 -1
  66. package/portal/schemas/definitions.js +1 -1
  67. package/support/revision.js +1 -1
  68. package/views/2d/engine/webgl/cpuMapped/FreeList.js +1 -1
  69. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/utils.js +1 -1
  70. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  71. package/views/2d/layers/features/FeatureContainer.js +1 -1
  72. package/views/2d/layers/features/RenderState.js +1 -1
  73. package/views/2d/layers/support/FeatureCommandQueue.js +1 -1
  74. package/views/2d/pointToPoint/Camera.js +1 -1
  75. package/views/3d/analysis/Viewshed/FieldOfViewManipulation.js +1 -1
  76. package/views/3d/analysis/Viewshed/ScaleOrientManipulation.js +1 -1
  77. package/views/3d/analysis/Viewshed/ViewshedComputedData.js +1 -1
  78. package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
  79. package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
  80. package/views/3d/analysis/Viewshed/ViewshedVisualization.js +1 -1
  81. package/views/3d/analysis/Viewshed/viewshedToolUtils.js +1 -1
  82. package/views/3d/animation/pointToPoint/Camera.js +1 -1
  83. package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
  84. package/views/3d/terrain/PatchRenderData.js +1 -1
  85. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  86. package/views/3d/webgl-engine/lib/ViewshedShadowMap.js +1 -1
  87. package/views/animation/pointToPoint/Animation.js +1 -1
  88. package/views/animation/pointToPoint/Camera.js +5 -0
  89. package/views/animation/pointToPoint/Definition.js +1 -1
  90. package/views/animation/pointToPoint/InterpolateComponents.js +5 -0
  91. package/views/animation/pointToPoint/Path.js +1 -1
  92. package/views/animation/pointToPoint/Segment.js +1 -1
  93. package/views/animation/pointToPoint/apex/Path.js +1 -1
  94. package/views/draw/support/Reshape.js +1 -1
  95. package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
  96. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  97. package/widgets/FeatureTable/FieldColumn.js +1 -1
  98. package/widgets/FeatureTable/Grid/GroupColumn.js +1 -1
  99. package/widgets/FeatureTable.js +1 -1
  100. package/widgets/VersionManagement/VersionManagementViewModel.js +1 -1
  101. package/assets/esri/core/workers/chunks/3f86042d9c0cc2d9acba.js +0 -1
  102. package/assets/esri/core/workers/chunks/95fb6643bd54d354f266.js +0 -1
  103. package/assets/esri/core/workers/chunks/b52295fa9cf2f3244b65.js +0 -1
  104. package/assets/esri/core/workers/chunks/b61e458ef5021adba1cb.js +0 -1
  105. package/assets/esri/core/workers/chunks/cccf37e2af3f8c5b2869.js +0 -1
  106. package/assets/esri/core/workers/chunks/eaff59400a0dcd535e02.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import n from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as o,ensureArcadeExecutionError as a}from"./executionError.js";import i from"./Feature.js";import{NativeFunction as l,ArcadeFunction as s,ScopeMarshalledFunction as u,wrapModuleScopedResponse as c}from"./FunctionWrapper.js";import{H as f,a as p,q as w,o as d,r as h,c as m,b as g,F as y,D as v,B as b,C as S,i as x,z as F,u as I,g as C,A,j as R,E as M,G as j,x as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as L}from"./treeAnalysis.js";import{A as E}from"../chunks/array.js";import{registerFunctions as N}from"./functions/date.js";import{registerFunctions as O}from"./functions/geomasync.js";import{registerFunctions as B,geometryMember as P}from"./functions/geometry.js";import{registerFunctions as K}from"./functions/maths.js";import{registerFunctions as D}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import Z from"../geometry/Geometry.js";import U from"../geometry/SpatialReference.js";const q=100;async function T(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await H(e,t.arguments[r]));return n}async function W(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await T(e,t))}class V extends s{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,null);return Be(this.definition,n,t,null)}}call(e,t){return z(e,t,((n,a,i)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,t);return Be(this.definition,l,i,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!x(t)||t instanceof u?t:c(t,e,r))),c(await Be(this.definition,l,i,t),n,r)}))}}class _ extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await H(this.executingContext,t.node),t.valueset=!0),x(t.value)&&!(t.value instanceof u)){const e=new u;e.fn=t.value,e.parameterEvaluator=z,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(x(t))throw new r(null,o.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new U({wkid:102100})),this.moduleScope=De({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ge,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await H(this.executingContext,this.source.syntax)}}async function z(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await T(e,t))}async function H(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,H(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await Se(e,t);case"ImportDeclaration":return await ye(e,t);case"ExportNamedDeclaration":return await ve(e,t);case"VariableDeclaration":return await be(e,t,0);case"BlockStatement":case"Program":return await de(e,t);case"FunctionDeclaration":return await ge(e,t);case"ReturnStatement":return await me(e,t);case"IfStatement":return await we(e,t);case"ExpressionStatement":return await pe(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await fe(e,t);case"ForStatement":return await te(e,t);case"WhileStatement":return await Q(e,t);case"ForInStatement":return await se(e,t);case"BreakStatement":return S;case"EmptyStatement":return b;case"ContinueStatement":return v;case"TemplateElement":return await je(e,t);case"TemplateLiteral":return await Le(e,t);case"Identifier":return await Re(e,t);case"MemberExpression":return await xe(e,t);case"Literal":return t.value;case"CallExpression":return await Me(e,t);case"UnaryExpression":return await Fe(e,t);case"BinaryExpression":return await Ce(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Ie(e,t);case"ObjectExpression":return await Y(e,t);case"Property":return await J(e,t);default:throw new r(e,o.Unrecognized,t)}}catch(i){throw a(e,t,i)}}async function Y(e,t){const a=[];for(let n=0;n<t.properties.length;n++)a[n]=await H(e,t.properties[n]);const i={},l=new Map;for(let n=0;n<a.length;n++){const s=a[n];if(x(s.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===m(s.key))throw new r(e,o.KeyMustBeString,t);let u=s.key.toString();const c=u.toLowerCase();l.has(c)?u=l.get(c):l.set(c,u),s.value===b?i[u]=null:i[u]=s.value}const s=new n(i);return s.immutable=!1,s}async function J(e,t){const n=await H(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await H(e,t.key),value:n}}async function Q(e,t){const n={testResult:!0,lastAction:b};if(n.testResult=await H(e,t.test),!1===n.testResult)return b;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await H(e,t.body),n.lastAction!==S)&&!(n.lastAction instanceof F);)if(n.testResult=await H(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof F?n.lastAction:b}async function X(e,t,n){const r=await H(e,t.body);return n.lastAction=r,n.lastAction===S||n.lastAction instanceof F?(n.testResult=!1,n):null!==t.update?(await H(e,t.update),n):n}async function $(e,t,n){if(null!==t.test){const a=await H(e,t.test);if(!0===e.abortSignal?.aborted)throw new r(e,o.Cancelled,t);if(n.testResult=a,!1===n.testResult)return n;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return X(e,t,n)}return X(e,t,n)}function ee(e,t,n,r,o,a){try{$(e,t,n).then((()=>{try{!0===n.testResult?++a>q?(a=0,setTimeout((()=>{ee(e,t,n,r,o,a)}),0)):ee(e,t,n,r,o,a):n.lastAction instanceof F?r(n.lastAction):r(b)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function te(e,t){try{return null!==t.init?H(e,t.init).then((()=>new Promise(((n,r)=>{ee(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{ee(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function ne(e,t,n,r,o,a,i,l,s,u){try{if(r<=a)return void l(b);o.value="k"===i?n[a]:a,H(e,t.body).then((c=>{try{c instanceof F?l(c):c===S?l(b):++u>q?(u=0,setTimeout((()=>{ne(e,t,n,r,o,a+1,i,l,s,u)}),0)):ne(e,t,n,r,o,a+1,i,l,s,u)}catch(f){s(f)}}),(e=>{s(e)}))}catch(c){s(c)}}function re(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(b);r.value="k"===a?n.get(o):o,H(e,t.body).then((u=>{u instanceof F?i(u):u===S?i(b):++s>q?(s=0,setTimeout((()=>{re(e,t,n,r,o+1,a,i,l,s)}),0)):re(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(u){l(u)}}function oe(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);ne(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);re(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o){try{oe(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function le(e,t,n,r,o,a,l,s){try{e.next().then((u=>{try{if(null===u)a(b);else{const c=i.createFromGraphicLikeObject(u.geometry,u.attributes,r,t.timeZone);c._underlyingGraphic=u,o.value=c;H(t,n.body).then((i=>{try{i===S?a(b):i instanceof F?a(i):++s>q?(s=0,setTimeout((()=>{le(e,t,n,r,o,a,l,s)}),0)):le(e,t,n,r,o,a,l,s)}catch(u){l(u)}}),(e=>{l(e)}))}}catch(c){l(c)}}),(e=>{l(e)}))}catch(u){l(u)}}async function se(e,t){return new Promise(((a,i)=>{H(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?H(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new r(e,o.InvalidIdentifier,t);s=s.toLowerCase();let u=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(u=e.localScope[s]),null===u&&void 0!==e.globalScope[s]&&(u=e.globalScope[s]),null===u)return void i(new r(e,o.InvalidIdentifier,t));d(l)||m(l)?oe(e,t,l,{reject:i,resolve:a},u):w(l)?ae(e,t,l,{reject:i,resolve:a},u):l instanceof n||h(l)?ie(e,t,l,{reject:i,resolve:a},u):I(l)?le(l.iterator(e.abortSignal),e,t,l,u,(e=>{a(e)}),(e=>{i(e)}),0):oe(e,t,[],{reject:i,resolve:a},u)}catch(s){i(s)}}),i)}catch(s){i(s)}}),i)}))}async function ue(e,t){const a=t.argument;if("MemberExpression"===a.type){const i={t:null},l=await H(e,a.object);let s=null;i.t=l,!0===a.computed?s=await H(e,a.property):"Identifier"===a.property.type&&(s=a.property.name);const u=i.t;let c;if(d(u)){if(!g(s))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(s<0&&(s=u.length+s),s<0||s>=u.length)throw new r(e,o.OutOfBounds,t);c=C(u[s]),u[s]="++"===t.operator?c+1:c-1}else if(u instanceof n){if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==u.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});c=C(u.field(s)),u.setField(s,"++"===t.operator?c+1:c-1)}else if(u instanceof _){if(!1===m(s))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==u.hasGlobal(s))throw new r(e,o.ModuleExportNotFound,t);c=C(await u.global(s)),u.setGlobal(s,"++"===t.operator?c+1:c-1)}else{if(!h(u))throw w(u)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==u.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});c=C(u.field(s)),u.setField(s,"++"===t.operator?c+1:c-1)}return!1===t.prefix?c:"++"===t.operator?c+1:c-1}const i="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!i)throw new r(e,o.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[i])return l=C(e.localScope[i].value),e.localScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[i])return l=C(e.globalScope[i].value),e.globalScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new r(e,o.InvalidIdentifier,t)}function ce(e,t,n,a,i){switch(t){case"=":return e===b?null:e;case"/=":return C(n)/C(e);case"*=":return C(n)*C(e);case"-=":return C(n)-C(e);case"+=":return m(n)||m(e)?R(n)+R(e):C(n)+C(e);case"%=":return C(n)%C(e);default:throw new r(i,o.UnsupportedOperator,a)}}async function fe(e,t){const a=t.left;if("MemberExpression"===a.type){const i=await H(e,a.object);let l=null;if(!0===a.computed)l=await H(e,a.property);else{if("Identifier"!==a.property.type)throw new r(e,o.InvalidIdentifier,t);l=a.property.name}const s=await H(e,t.right);if(d(i)){if(!g(l))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(l<0&&(l=i.length+l),l<0||l>i.length)throw new r(e,o.OutOfBounds,t);if(l===i.length){if("="!==t.operator)throw new r(e,o.OutOfBounds,t);i[l]=ce(s,t.operator,i[l],t,e)}else i[l]=ce(s,t.operator,i[l],t,e)}else if(i instanceof n){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,ce(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,ce(s,t.operator,null,t,e))}}else if(i instanceof _){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasGlobal(l))throw new r(e,o.ModuleExportNotFound,t);i.setGlobal(l,ce(s,t.operator,await i.global(l),t,e))}else{if(!h(i))throw w(i)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,ce(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,ce(s,t.operator,null,t,e))}}return b}const i=a.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[i]){const n=await H(e,t.right);return e.localScope[i]={value:ce(n,t.operator,e.localScope[i].value,t,e),valueset:!0,node:t.right},b}if(void 0!==e.globalScope[i]){const n=await H(e,t.right);return e.globalScope[i]={value:ce(n,t.operator,e.globalScope[i].value,t,e),valueset:!0,node:t.right},b}throw new r(e,o.InvalidIdentifier,t)}async function pe(e,t){if("AssignmentExpression"===t.expression.type)return H(e,t.expression);if("CallExpression"===t.expression.type){const n=await H(e,t.expression);return n===b?b:new A(n)}const n=await H(e,t.expression);return n===b?b:new A(n)}async function we(e,t){const n=await H(e,t.test);if(!0===n)return H(e,t.consequent);if(!1===n)return null!==t.alternate?H(e,t.alternate):b;throw new r(e,o.BooleanConditionRequired,t)}async function de(e,t){return he(e,t,0)}async function he(e,t,n){if(n>=t.body.length)return b;const r=await H(e,t.body[n]);return r instanceof F||r===S||r===v||n===t.body.length-1?r:he(e,t,n+1)}async function me(e,t){if(null===t.argument)return new F(b);const n=await H(e,t.argument);return new F(n)}async function ge(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new V(t,e)},b}async function ye(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new _(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},b}async function ve(e,t){if(await H(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return b}async function be(e,t,n){return n>=t.declarations.length?b:(await H(e,t.declarations[n]),n===t.declarations.length-1||await be(e,t,n+1),b)}async function Se(e,t){let n=null;if(n=null===t.init?null:await H(e,t.init),null!==e.localScope){if(n===b&&(n=null),"Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[a]={value:n,valueset:!0,node:t.init}),b}if("Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return n===b&&(n=null),e.globalScope[a]={value:n,valueset:!0,node:t.init},b}async function xe(e,t){const a=await H(e,t.object);if(null===a)throw new r(e,o.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(a instanceof n||h(a))return a.field(t.property.name);if(a instanceof Z)return P(a,t.property.name,e,t);if(a instanceof _){if(!a.hasGlobal(t.property.name))throw new r(e,o.InvalidIdentifier,t);return a.global(t.property.name)}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}let i=await H(e,t.property);if(a instanceof n||h(a)){if(m(i))return a.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof _){if(m(i))return a.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof Z){if(m(i))return P(a,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(d(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}if(w(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length()+i),i>=a.length()||i<0)throw new r(e,o.OutOfBounds,t);return a.get(i)}throw new r(e,o.InvalidMemberAccessKey,t)}if(m(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}async function Fe(e,t){const n=await H(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}async function Ie(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await H(e,t.elements[r]));for(let a=0;a<n.length;a++){if(x(n[a]))throw new r(e,o.NoFunctionInArray,t);n[a]===b&&(n[a]=null)}return n}async function Ce(e,t){const n=[];n[0]=await H(e,t.left),n[1]=await H(e,t.right);const a=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(C(a),C(i),t.operator);case"==":return y(a,i);case"!=":return!y(a,i);case"<":case">":case"<=":case">=":return M(a,i,t.operator);case"+":return m(a)||m(i)?R(a)+R(i):C(a)+C(i);case"-":return C(a)-C(i);case"*":return C(a)*C(i);case"/":return C(a)/C(i);case"%":return C(a)%C(i);default:throw new r(e,o.UnsupportedOperator,t)}}async function Ae(e,t){const n=await H(e,t.left);let a=null;if(!p(n))throw new r(e,o.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(a=await H(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(a=await H(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);default:throw new r(e,o.LogicExpressionOrAnd,t)}}async function Re(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=H(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=H(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new r(e,o.InvalidIdentifier,t)}async function Me(e,t){if("MemberExpression"===t.callee.type){const n=await H(e,t.callee.object);if(!(n instanceof _))throw new r(e,o.FunctionNotFound,t);const a=!1===t.callee.computed?t.callee.property.name:await H(e,t.callee.property);if(!n.hasGlobal(a))throw new r(e,o.FunctionNotFound,t);const i=await n.global(a);if(!x(i))throw new r(e,o.CallNonFunction,t);return i.call(e,t)}if("Identifier"!==t.callee.type)throw new r(e,o.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FunctionNotFound,t)}async function je(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(x(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}async function Le(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await H(e,t.expressions[a]);n[a]=R(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?ke(n[o],e,t):"",o++}return r}const Ee={};async function Ne(e,t,n,r){const o=await H(e,t.arguments[n]);if(y(o,r))return H(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?H(e,t.arguments[n]):2===a?null:3===a?H(e,t.arguments[n+2]):Ne(e,t,n+2,r)}async function Oe(e,t,n,a){if(!0===a)return H(e,t.arguments[n+1]);if(3===t.arguments.length-n)return H(e,t.arguments[n+2]);const i=await H(e,t.arguments[n+2]);if(!1===p(i))throw new r(e,o.ModuleExportNotFound,t.arguments[n+2]);return Oe(e,t,n+2,i)}async function Be(e,t,n,a){const i=e.body;if(n.length!==e.params.length)throw new r(t,o.WrongNumberOfParameters,null);for(let r=0;r<n.length;r++){const o=e.params[r];"Identifier"===o.type&&null!=t.localScope&&(t.localScope[o.name.toLowerCase()]={d:null,value:n[r],valueset:!0,node:null})}const l=await H(t,i);if(l instanceof F)return l.value;if(l===S)throw new r(t,o.UnexpectedToken,a);if(l===v)throw new r(t,o.UnexpectedToken,a);return l instanceof A?l.value:l}N(Ee,W),G(Ee,W),K(Ee,W),B(Ee,W),D(Ee,W),O({functions:Ee,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:W,standardFunctionAsync:z}),Ee.iif=async function(e,t){f(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await H(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t);return H(e,n?t.arguments[1]:t.arguments[2])},Ee.defaultvalue=async function(e,t){f(null===t.arguments?[]:t.arguments,2,3,e,t);const a=await H(e,t.arguments[0]);if(3===t.arguments.length){const i=await H(e,t.arguments[1]);let l=[];if(w(i))l=i.toArray();else{if(!d(i))throw new r(e,o.InvalidParameter,t);l=i}let s=a;if(null===s)return H(e,t.arguments[2]);for(const r of l)if(h(s)){if(!1===m(r))return H(e,t.arguments[2]);if(!s.hasField(r))return H(e,t.arguments[2]);s=s.field(r)}else if(s instanceof n){if(!1===m(r))return H(e,t.arguments[2]);if(!s.hasField(r))return H(e,t.arguments[2]);s=s.field(r)}else if(s instanceof Z){if(!1===m(r))return H(e,t.arguments[2]);if(s=P(s,r,null,null,2),null===s)return H(e,t.arguments[2]);if("notfound"===s?.keystate)return H(e,t.arguments[2])}else if(d(s)){if(!1===g(r))return H(e,t.arguments[2]);if(s=s[r],null==s)return H(e,t.arguments[2])}else{if(!w(s))return H(e,t.arguments[2]);if(!1===g(r))return H(e,t.arguments[2]);if(s=s.get(r),null==s)return H(e,t.arguments[2])}return s}return null==a||""===a?H(e,t.arguments[1]):a},Ee.decode=async function(e,t){if(t.arguments.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===t.arguments.length)return H(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);return Ne(e,t,1,await H(e,t.arguments[0]))},Ee.when=async function(e,t){if(t.arguments.length<3)throw new r(e,o.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new r(e,o.WrongNumberOfParameters,t);const n=await H(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t.arguments[0]);return Oe(e,t,0,n)};const Pe={fixSpatialReference:k,parseArguments:T,standardFunction:W,standardFunctionAsync:z,evaluateIdentifier:Re};for(const Te in Ee)Ee[Te]={value:new l(Ee[Te]),valueset:!0,node:null};const Ke=function(){};function De(e,t,r){const o=new Ke;null==e&&(e={}),null==t&&(t={});const a=new n({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const n in t)o[n]={value:new l(t[n]),native:!0,valueset:!0,node:null};for(const n in e)e[n]&&"esri.Graphic"===e[n].declaredClass?o[n]={value:i.createFromGraphic(e[n],r),valueset:!0,node:null}:o[n]={value:e[n],valueset:!0,node:null};return o}function Ge(e){console.log(e)}Ke.prototype=Ee,Ke.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ke.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ze=Pe;function Ue(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:W,standardFunctionAsync:z,evaluateIdentifier:Re};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ee[n]={value:new l(t.functions[n]),valueset:!0,node:null},Ke.prototype[n]=Ee[n];for(let n=0;n<t.signatures.length;n++)L(t.signatures[n],"async")}async function qe(e,n){let a=n.spatialReference;null==a&&(a=new U({wkid:102100}));let i=null;e.usesModules&&(i=new t(new Map,e.loadedModules));const l=De(n.vars,n.customfunctions,n.timeZone),s={spatialReference:a,services:n.services,exports:{},libraryResolver:i,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ge,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let u=await H(s,e);if(u instanceof F&&(u=u.value),u instanceof A&&(u=u.value),u===b&&(u=null),u===S)throw new r(s,o.IllegalResult,null);if(u===v)throw new r(s,o.IllegalResult,null);if(x(u))throw new r(s,o.IllegalResult,null);return u}Ue([E]);export{qe as executeScript,Ue as extend,Ze as functionHelper};
5
+ import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as r}from"./containerUtils.js";import o from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i,ensureArcadeExecutionError as l}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{H as w,a as d,F as h,D as m,B as g,C as y,i as v,c as b,z as S,o as x,q as I,r as F,u as C,b as R,g as A,A as M,j,E as L,G as k,x as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as O}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as P}from"./functions/geomasync.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import Z from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";const T=100;async function W(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await Y(e,t.arguments[r]));return n}async function V(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}class _ extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,null);return Pe(this.definition,n,t,null)}}call(e,t){return H(e,t,((n,r,o)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,t);return Pe(this.definition,l,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!v(t)||t instanceof f?t:p(t,e,r))),p(await Pe(this.definition,l,i,t),n,r)}))}}class z extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await Y(this.executingContext,t.node),t.valueset=!0),v(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(v(t))throw new a(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new q({wkid:102100})),this.moduleScope=Ge({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ue,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await Y(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}async function Y(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,Y(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await xe(e,t);case"ImportDeclaration":return await ve(e,t);case"ExportNamedDeclaration":return await be(e,t);case"VariableDeclaration":return await Se(e,t,0);case"BlockStatement":case"Program":return await he(e,t);case"FunctionDeclaration":return await ye(e,t);case"ReturnStatement":return await ge(e,t);case"IfStatement":return await de(e,t);case"ExpressionStatement":return await we(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await pe(e,t);case"ForStatement":return await ne(e,t);case"WhileStatement":return await X(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return y;case"EmptyStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return await Le(e,t);case"TemplateLiteral":return await Ee(e,t);case"Identifier":return await Me(e,t);case"MemberExpression":return await Ie(e,t);case"Literal":return t.value;case"CallExpression":return await je(e,t);case"UnaryExpression":return await Fe(e,t);case"BinaryExpression":return await Re(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Ce(e,t);case"ObjectExpression":return await J(e,t);case"Property":return await Q(e,t);default:throw new a(e,i.Unrecognized,t)}}catch(r){throw l(e,t,r)}}async function J(e,t){const n=[];for(let o=0;o<t.properties.length;o++)n[o]=await Y(e,t.properties[o]);const r={},l=new Map;for(let o=0;o<n.length;o++){const s=n[o];if(v(s.value))throw new a(e,i.NoFunctionInDictionary,t);if(!1===b(s.key))throw new a(e,i.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===g?r[c]=null:r[c]=s.value}const s=new o(r);return s.immutable=!1,s}async function Q(e,t){const n=await Y(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await Y(e,t.key),value:n}}async function X(e,t){const n={testResult:!0,lastAction:g};if(n.testResult=await Y(e,t.test),!1===n.testResult)return g;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await Y(e,t.body),n.lastAction!==y)&&!(n.lastAction instanceof S);)if(n.testResult=await Y(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:g}async function $(e,t,n){const r=await Y(e,t.body);return n.lastAction=r,n.lastAction===y||n.lastAction instanceof S?(n.testResult=!1,n):null!==t.update?(await Y(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const r=await Y(e,t.test);if(!0===e.abortSignal?.aborted)throw new a(e,i.Cancelled,t);if(n.testResult=r,!1===n.testResult)return n;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return $(e,t,n)}return $(e,t,n)}function te(e,t,n,r,o,a){try{ee(e,t,n).then((()=>{try{!0===n.testResult?++a>T?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof S?r(n.lastAction):r(g)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?Y(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function re(e,t,n,r,o,a,i,l,s,c){try{if(r<=a)return void l(g);o.value="k"===i?n[a]:a,Y(e,t.body).then((u=>{try{u instanceof S?l(u):u===y?l(g):++c>T?(c=0,setTimeout((()=>{re(e,t,n,r,o,a+1,i,l,s,c)}),0)):re(e,t,n,r,o,a+1,i,l,s,c)}catch(f){s(f)}}),(e=>{s(e)}))}catch(u){s(u)}}function oe(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(g);r.value="k"===a?n.get(o):o,Y(e,t.body).then((c=>{c instanceof S?i(c):c===y?i(g):++s>T?(s=0,setTimeout((()=>{oe(e,t,n,r,o+1,a,i,l,s)}),0)):oe(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(c){l(c)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);re(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);oe(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function le(e,t,n,r,o){try{ae(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function se(e,t,n,r,o,a,i,l){try{e.next().then((c=>{try{if(null===c)a(g);else{const u=s.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeZone);u._underlyingGraphic=c,o.value=u;Y(t,n.body).then((s=>{try{s===y?a(g):s instanceof S?a(s):++l>T?(l=0,setTimeout((()=>{se(e,t,n,r,o,a,i,l)}),0)):se(e,t,n,r,o,a,i,l)}catch(c){i(c)}}),(e=>{i(e)}))}}catch(u){i(u)}}),(e=>{i(e)}))}catch(c){i(c)}}async function ce(e,t){return new Promise(((n,r)=>{Y(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?Y(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new a(e,i.InvalidIdentifier,t);s=s.toLowerCase();let c=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(c=e.localScope[s]),null===c&&void 0!==e.globalScope[s]&&(c=e.globalScope[s]),null===c)return void r(new a(e,i.InvalidIdentifier,t));x(l)||b(l)?ae(e,t,l,{reject:r,resolve:n},c):I(l)?ie(e,t,l,{reject:r,resolve:n},c):l instanceof o||F(l)?le(e,t,l,{reject:r,resolve:n},c):C(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{n(e)}),(e=>{r(e)}),0):ae(e,t,[],{reject:r,resolve:n},c)}catch(s){r(s)}}),r)}catch(s){r(s)}}),r)}))}async function ue(e,t){const n=t.argument;if("MemberExpression"===n.type){const r={t:null},l=await Y(e,n.object);let s=null;r.t=l,!0===n.computed?s=await Y(e,n.property):"Identifier"===n.property.type&&(s=n.property.name);const c=r.t;let u;if(x(c)){if(!R(s))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new a(e,i.OutOfBounds,t);u=A(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof o){if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===b(s))throw new a(e,i.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new a(e,i.ModuleExportNotFound,t);u=A(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!F(c))throw I(c)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-1}const r="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!r)throw new a(e,i.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[r])return l=A(e.localScope[r].value),e.localScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[r])return l=A(e.globalScope[r].value),e.globalScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new a(e,i.InvalidIdentifier,t)}function fe(e,t,n,r,o){switch(t){case"=":return e===g?null:e;case"/=":return A(n)/A(e);case"*=":return A(n)*A(e);case"-=":return A(n)-A(e);case"+=":return b(n)||b(e)?j(n)+j(e):A(n)+A(e);case"%=":return A(n)%A(e);default:throw new a(o,i.UnsupportedOperator,r)}}async function pe(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await Y(e,n.object);let l=null;if(!0===n.computed)l=await Y(e,n.property);else{if("Identifier"!==n.property.type)throw new a(e,i.InvalidIdentifier,t);l=n.property.name}const s=await Y(e,t.right);if(x(r)){if(!R(l))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(l<0&&(l=r.length+l),l<0||l>r.length)throw new a(e,i.OutOfBounds,t);if(l===r.length){if("="!==t.operator)throw new a(e,i.OutOfBounds,t);r[l]=fe(s,t.operator,r[l],t,e)}else r[l]=fe(s,t.operator,r[l],t,e)}else if(r instanceof o){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}else if(r instanceof z){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==r.hasGlobal(l))throw new a(e,i.ModuleExportNotFound,t);r.setGlobal(l,fe(s,t.operator,await r.global(l),t,e))}else{if(!F(r))throw I(r)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}return g}const r=n.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[r]){const n=await Y(e,t.right);return e.localScope[r]={value:fe(n,t.operator,e.localScope[r].value,t,e),valueset:!0,node:t.right},g}if(void 0!==e.globalScope[r]){const n=await Y(e,t.right);return e.globalScope[r]={value:fe(n,t.operator,e.globalScope[r].value,t,e),valueset:!0,node:t.right},g}throw new a(e,i.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return Y(e,t.expression);if("CallExpression"===t.expression.type){const n=await Y(e,t.expression);return n===g?g:new M(n)}const n=await Y(e,t.expression);return n===g?g:new M(n)}async function de(e,t){const n=await Y(e,t.test);if(!0===n)return Y(e,t.consequent);if(!1===n)return null!==t.alternate?Y(e,t.alternate):g;throw new a(e,i.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return g;const r=await Y(e,t.body[n]);return r instanceof S||r===y||r===m||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new S(g);const n=await Y(e,t.argument);return new S(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new _(t,e)},g}async function ve(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new z(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},g}async function be(e,t){if(await Y(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return g}async function Se(e,t,n){return n>=t.declarations.length?g:(await Y(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),g)}async function xe(e,t){let n=null;if(n=null===t.init?null:await Y(e,t.init),null!==e.localScope){if(n===g&&(n=null),"Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[r]={value:n,valueset:!0,node:t.init}),g}if("Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return n===g&&(n=null),e.globalScope[r]={value:n,valueset:!0,node:t.init},g}async function Ie(e,t){const n=await Y(e,t.object);if(null===n)throw new a(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof o||F(n))return n.field(t.property.name);if(n instanceof Z)return r(n,t.property.name,e,t);if(n instanceof z){if(!n.hasGlobal(t.property.name))throw new a(e,i.InvalidIdentifier,t);return n.global(t.property.name)}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}let l=await Y(e,t.property);if(n instanceof o||F(n)){if(b(l))return n.field(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof z){if(b(l))return n.global(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof Z){if(b(l))return r(n,l,e,t);throw new a(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length()+l),l>=n.length()||l<0)throw new a(e,i.OutOfBounds,t);return n.get(l)}throw new a(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}async function Fe(e,t){const n=await Y(e,t.argument);if(d(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}async function Ce(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await Y(e,t.elements[r]));for(let r=0;r<n.length;r++){if(v(n[r]))throw new a(e,i.NoFunctionInArray,t);n[r]===g&&(n[r]=null)}return n}async function Re(e,t){const n=[];n[0]=await Y(e,t.left),n[1]=await Y(e,t.right);const r=n[0],o=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(A(r),A(o),t.operator);case"==":return h(r,o);case"!=":return!h(r,o);case"<":case">":case"<=":case">=":return L(r,o,t.operator);case"+":return b(r)||b(o)?j(r)+j(o):A(r)+A(o);case"-":return A(r)-A(o);case"*":return A(r)*A(o);case"/":return A(r)/A(o);case"%":return A(r)%A(o);default:throw new a(e,i.UnsupportedOperator,t)}}async function Ae(e,t){const n=await Y(e,t.left);let r=null;if(!d(n))throw new a(e,i.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);default:throw new a(e,i.LogicExpressionOrAnd,t)}}async function Me(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new a(e,i.InvalidIdentifier,t)}async function je(e,t){if("MemberExpression"===t.callee.type){const n=await Y(e,t.callee.object);if(!(n instanceof z))throw new a(e,i.FunctionNotFound,t);const r=!1===t.callee.computed?t.callee.property.name:await Y(e,t.callee.property);if(!n.hasGlobal(r))throw new a(e,i.FunctionNotFound,t);const o=await n.global(r);if(!v(o))throw new a(e,i.CallNonFunction,t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new a(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}throw new a(e,i.FunctionNotFound,t)}async function Le(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(v(e))throw new a(t,i.NoFunctionInTemplateLiteral,n);return e}async function Ee(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await Y(e,t.expressions[a]);n[a]=j(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?ke(n[o],e,t):"",o++}return r}const Ne={};async function Oe(e,t,n,r){const o=await Y(e,t.arguments[n]);if(h(o,r))return Y(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?Y(e,t.arguments[n]):2===a?null:3===a?Y(e,t.arguments[n+2]):Oe(e,t,n+2,r)}async function Be(e,t,n,r){if(!0===r)return Y(e,t.arguments[n+1]);if(3===t.arguments.length-n)return Y(e,t.arguments[n+2]);const o=await Y(e,t.arguments[n+2]);if(!1===d(o))throw new a(e,i.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,o)}async function Pe(e,t,n,r){const o=e.body;if(n.length!==e.params.length)throw new a(t,i.WrongNumberOfParameters,null);for(let a=0;a<n.length;a++){const r=e.params[a];"Identifier"===r.type&&null!=t.localScope&&(t.localScope[r.name.toLowerCase()]={d:null,value:n[a],valueset:!0,node:null})}const l=await Y(t,o);if(l instanceof S)return l.value;if(l===y)throw new a(t,i.UnexpectedToken,r);if(l===m)throw new a(t,i.UnexpectedToken,r);return l instanceof M?l.value:l}B(Ne,V),U(Ne,V),D(Ne,V),K(Ne,V),G(Ne,V),P({functions:Ne,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:V,standardFunctionAsync:H}),Ne.iif=async function(e,t){w(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t);return Y(e,n?t.arguments[1]:t.arguments[2])},Ne.defaultvalue=async function(e,t){w(null===t.arguments?[]:t.arguments,2,3,e,t);const r=await Y(e,t.arguments[0]);if(3===t.arguments.length){const o=await Y(e,t.arguments[1]),a=n(r,o);return null!=a&&""!==a?a:Y(e,t.arguments[2])}return null==r||""===r?Y(e,t.arguments[1]):r},Ne.decode=async function(e,t){if(t.arguments.length<2)throw new a(e,i.WrongNumberOfParameters,t);if(2===t.arguments.length)return Y(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new a(e,i.WrongNumberOfParameters,t);return Oe(e,t,1,await Y(e,t.arguments[0]))},Ne.when=async function(e,t){if(t.arguments.length<3)throw new a(e,i.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new a(e,i.WrongNumberOfParameters,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:E,parseArguments:W,standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(const We in Ne)Ne[We]={value:new c(Ne[We]),valueset:!0,node:null};const De=function(){};function Ge(e,t,n){const r=new De;null==e&&(e={}),null==t&&(t={});const a=new o({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r.textformatting={value:a,valueset:!0,node:null};for(const o in t)r[o]={value:new c(t[o]),native:!0,valueset:!0,node:null};for(const o in e)e[o]&&"esri.Graphic"===e[o].declaredClass?r[o]={value:s.createFromGraphic(e[o],n),valueset:!0,node:null}:r[o]={value:e[o],valueset:!0,node:null};return r}function Ue(e){console.log(e)}De.prototype=Ne,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ze=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ne[n]={value:new c(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Ne[n];for(let n=0;n<t.signatures.length;n++)N(t.signatures[n],"async")}async function Te(e,n){let r=n.spatialReference;null==r&&(r=new q({wkid:102100}));let o=null;e.usesModules&&(o=new t(new Map,e.loadedModules));const l=Ge(n.vars,n.customfunctions,n.timeZone),s={spatialReference:r,services:n.services,exports:{},libraryResolver:o,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ue,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await Y(s,e);if(c instanceof S&&(c=c.value),c instanceof M&&(c=c.value),c===g&&(c=null),c===y)throw new a(s,i.IllegalResult,null);if(c===m)throw new a(s,i.IllegalResult,null);if(v(c))throw new a(s,i.IllegalResult,null);return c}qe([O]);export{Te as executeScript,qe as extend,Ze as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import t from"./Dictionary.js";import{ArcadeExecutionError as o,ExecutionErrorCodes as r,ArcadeCompilationError as l,ArcadeUncompilableError as a}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as i,ArcadeFunction as u,ScopeMarshalledFunction as c,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{i as m,x as g,y as f,z as d,A as h,B as y,C as b,D as w,b as S,o as v,q as x,r as F,c as M,v as $,p as C,j as A,a as I,g as _,E as O,F as k,G as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as G}from"./treeAnalysis.js";import{A as B}from"../chunks/array.js";import{registerFunctions as N}from"./functions/date.js";import{registerFunctions as j,geometryMember as L}from"./functions/geometry.js";import{registerFunctions as R}from"./functions/geomsync.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as U}from"./functions/stats.js";import{registerFunctions as P}from"./functions/string.js";import{isPromiseLike as Z}from"../core/promiseUtils.js";import K from"../geometry/Geometry.js";import T from"../geometry/SpatialReference.js";class q extends u{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new o(e,r.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,r,l)=>{l=l.map((n=>!m(n)||n instanceof c?n:p(n,e,o)));const a=this.call(t,{arguments:l});return Z(a)?a.then((e=>p(e,t,o))):a}))}}function W(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(V(e,n.arguments[o]));return t}function z(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function V(e,n){try{switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclarator":return me(e,n);case"VariableDeclaration":return pe(e,n);case"BlockStatement":case"Program":return le(e,n);case"FunctionDeclaration":return ce(e,n);case"ImportDeclaration":return se(e,n);case"ExportNamedDeclaration":return ie(e,n);case"ReturnStatement":return ae(e,n);case"IfStatement":return re(e,n);case"ExpressionStatement":return te(e,n);case"AssignmentExpression":return ne(e,n);case"UpdateExpression":return X(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"TemplateLiteral":return he(e,n);case"TemplateElement":return JSON.stringify(n.value?n.value.cooked:"");case"ForStatement":return Q(e,n);case"ForInStatement":return H(e,n);case"WhileStatement":return ee(e,n);case"Identifier":return we(e,n);case"MemberExpression":return ge(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Se(e,n);case"UnaryExpression":return fe(e,n);case"BinaryExpression":return ye(e,n);case"LogicalExpression":return be(e,n);case"ArrayExpression":return de(e,n);case"ObjectExpression":return J(e,n);case"Property":return Y(e,n);case"Array":throw new l(e,r.NeverReach,n);default:throw new l(e,r.Unrecognized,n)}}catch(t){throw t}}function J(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const r=n.properties[o];ue(r.key.name);o>0&&(t+=","),t+="lang.strCheck("+("Identifier"===r.key.type?"'"+r.key.name+"'":V(e,r.key))+",'ObjectExpression'),lang.aCheck("+V(e,r.value)+", 'ObjectExpression')"}return t+="])",t}function Y(e,n){throw new l(e,r.NeverReach,n)}function H(e,n){const t=Ae(e),o=Ae(e),r=Ae(e);let l="var "+t+" = "+V(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(l+=V(e,n.left));let a="VariableDeclaration"===n.left.type?n.left.declarations[0].id.name:n.left.name;a=a.toLowerCase(),ue(a);let s="";null!==e.localScope&&(void 0!==e.localScope[a]?s="lscope['"+a+"']":void 0!==e.localScope._SymbolsMap[a]&&(s="lscope['"+e.localScope._SymbolsMap[a]+"']"));let i="";if(""===s)if(void 0!==e.globalScope[a])s="gscope['"+a+"']";else if(void 0!==e.globalScope._SymbolsMap[a])s="gscope['"+e.globalScope._SymbolsMap[a]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(a))s="gscope['"+e.undeclaredGlobalsInFunctions.get(a).manglename+"']",i=e.undeclaredGlobalsInFunctions.get(a).manglename;else{const t={manglename:Ce(e),node:n.left};e.undeclaredGlobalsInFunctions.set(a,t),s="gscope['"+t.manglename+"']",i=t.manglename}return i&&(l+="lang.chkAssig('"+i+"',runtimeCtx); \n"),l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {",l+="var "+o+"="+t+".length; \n",l+="for(var "+r+"=0; "+r+"<"+o+"; "+r+"++) {\n",l+=s+"="+r+";\n",l+=V(e,n.body),l+="\n}\n",l+=" lastStatement = lc.voidOperation; \n",l+=" \n}\n",l+="else if (lc.isImmutableArray("+t+")) {",l+="var "+o+"="+t+".length(); \n",l+="for(var "+r+"=0; "+r+"<"+o+"; "+r+"++) {\n",l+=s+"="+r+";\n",l+=V(e,n.body),l+="\n}\n",l+=" lastStatement = lc.voidOperation; \n",l+=" \n}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || ( "+t+" instanceof lang.Feature)) {",l+="var "+o+"="+t+".keys(); \n",l+="for(var "+r+"=0; "+r+"<"+o+".length; "+r+"++) {\n",l+=s+"="+o+"["+r+"];\n",l+=V(e,n.body),l+="\n}\n",l+=" lastStatement = lc.voidOperation; \n",l+=" \n}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {",l+="var "+o+"="+t+".iterator(runtimeCtx.abortSignal); \n",l+="for(var "+r+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx); "+r+"!=null; "+r+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx)) {\n",l+=s+"="+r+";\n",l+=V(e,n.body),l+="\n}\n",l+=" lastStatement = lc.voidOperation; \n",l+=" \n}\n"),l+="else { lastStatement = lc.voidOperation; } \n",l}function Q(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&(t+=V(e,n.init)+"; ");const o=Ae(e),l=Ae(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+V(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+V(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+r.BooleanConditionRequired+"'); }\n"),t+=V(e,n.body),null!==n.update&&(t+="\n "+V(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function X(e,n){let t=null,l="";if("MemberExpression"===n.argument.type)return t=V(e,n.argument.object),!0===n.argument.computed?l=V(e,n.argument.property):(l="'"+n.argument.property.name+"'",ue(n.argument.property.name)),"lang.memberupdate("+t+","+l+",'"+n.operator+"',"+n.prefix+")";if(t=n.argument.name.toLowerCase(),ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lang.update(lscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.localScope._SymbolsMap[t])return"lang.update(lscope, '"+e.localScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")"}if(void 0!==e.globalScope[t])return"lang.update(gscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.globalScope._SymbolsMap[t])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")";const o={manglename:Ce(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"lang.update(gscope, lang.chkAssig('"+o.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new o(e,r.InvalidIdentifier,n)}function ee(e,n){let t="lastStatement = lc.voidOperation; \n";const o=Ae(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${V(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${r.BooleanConditionRequired}');\n }\n ${V(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ne(e,n){const t=V(e,n.right);let l=null,a="";if("MemberExpression"===n.left.type)return l=V(e,n.left.object),!0===n.left.computed?a=V(e,n.left.property):(a="'"+n.left.property.name+"'",ue(n.left.property.name)),"lang.assignmember("+l+","+a+",'"+n.operator+"',"+t+")";if(l=n.left.name.toLowerCase(),ue(l),null!==e.localScope){if(void 0!==e.localScope[l])return"lscope['"+l+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+l+"'])";if(void 0!==e.localScope._SymbolsMap[l])return"lscope['"+e.localScope._SymbolsMap[l]+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+e.localScope._SymbolsMap[l]+"'])"}if(void 0!==e.globalScope[l])return"gscope['"+l+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+l+"'])";if(void 0!==e.globalScope._SymbolsMap[l])return"gscope['"+e.globalScope._SymbolsMap[l]+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+e.globalScope._SymbolsMap[l]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(l))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(l).manglename+"'])";const o={manglename:Ce(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(l,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+o.manglename+"'])"}throw new o(e,r.InvalidIdentifier,n)}function te(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+V(e,n.expression)+"; \n ":(n.expression.type,"lastStatement = "+V(e,n.expression)+"; ")}function oe(e,n){return"BlockStatement"===n.type?V(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?V(e,n)+"; ":"UpdateExpression"===n.type?"lastStatement = "+V(e,n)+"; ":"ExpressionStatement"===n.type?V(e,n):"ObjectExpression"===n.type?"lastStatement = "+V(e,n)+"; ":V(e,n)+"; "}function re(e,n){if("AssignmentExpression"===n.test.type||"UpdateExpression"===n.test.type)throw new l(e,r.BooleanConditionRequired,n);return`if (lang.mustBoolean(${V(e,n.test)}, runtimeCtx) === true) {\n ${oe(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+re(e,n.alternate):` else {\n ${oe(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function le(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=V(e,n.body[o])+"; \n":"UpdateExpression"===n.body[o].type||"ObjectExpression"===n.body[o].type?t+="lastStatement = "+V(e,n.body[o])+"; \n":t+=V(e,n.body[o])+" \n");return t}function ae(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+V(e,n.argument)}function se(e,n){const t=n.specifiers[0].local.name.toLowerCase();ue(t);const o=e.libraryResolver?.loadLibrary(t),r=Ce(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=Ke(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeZone:e.timeZone??null,libraryResolver:e.libraryResolver,customfunctions:e.customfunctions,vars:{}},e.isAsync)),e.moduleFactoryMap[r]=o.uri;let l="";if(l=e.isAsync?"(yield lang.loadModule('"+r+"', runtimeCtx) ); ":"lang.loadModule('"+r+"', runtimeCtx); ",void 0!==e.globalScope[t])return"gscope['"+t+"']="+l;if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']="+l;let a="";return e.undeclaredGlobalsInFunctions.has(t)?(a=e.undeclaredGlobalsInFunctions.get(t).manglename,e.undeclaredGlobalsInFunctions.delete(t)):a=Ce(e),e.globalScope._SymbolsMap[t]=a,e.mangleMap[t]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+l}function ie(e,n){const t=V(e,n.declaration);if("FunctionDeclaration"===n.declaration.type)e.exports[n.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===n.declaration.type)for(const o of n.declaration.declarations)e.exports[o.id.name.toLowerCase()]="variable";return t}function ue(e){if("iif"===e)throw new a;if("decode"===e)throw new a;if("when"===e)throw new a;if("defaultvalue"===e)throw new a}function ce(e,n){const t=n.id.name.toLowerCase();ue(t);let o="",r=!1;void 0!==e.globalScope[t]?o=t:void 0!==e.globalScope._SymbolsMap[t]?o=e.globalScope._SymbolsMap[t]:e.undeclaredGlobalsInFunctions.has(t)?(o=e.undeclaredGlobalsInFunctions.get(t).manglename,e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o,e.undeclaredGlobalsInFunctions.delete(t),r=!0):(o=Ce(e),e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o);const l={isAsync:e.isAsync,console:e.console,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,customfunctions:e.customfunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let a="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let s=0;s<n.params.length;s++){const t=n.params[s].name.toLowerCase();ue(t);const o=Ce(e);l.localScope._SymbolsMap[t]=o,l.mangleMap[t]=o,a+="lscope['"+o+"']=arguments["+s.toString()+"];\n"}return!0===e.isAsync?(a+="return lang.__awaiter(this, void 0, void 0, function* () {\n",a+=le(l,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=le(l,n.body)+"\n return lastStatement; }, runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"),r?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+a:"gscope['"+o+"']="+a}function pe(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(V(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function me(e,n){let t=null===n.init?null:V(e,n.init);t===y&&(t=null);const o=n.id.name.toLowerCase();if(ue(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+t+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+t+"; ";{const n=Ce(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+t+"; "}}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+t+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+t+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+t+"; "}const r=Ce(e);return e.globalScope._SymbolsMap[o]=r,e.mangleMap[o]=r,"gscope['"+r+"']="+t+"; "}function ge(e,n){try{let t;return!0===n.computed?t=V(e,n.property):(t="'"+n.property.name+"'",ue(n.property.name)),"lang.member("+V(e,n.object)+","+t+")"}catch(t){throw t}}function fe(e,n){try{return"lang.unary("+V(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function de(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(V(e,n.elements[o])):t.push("lang.aCheck("+V(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function he(e,n){try{const t=[];let o=0;for(const r of n.quasis)t.push(r.value?JSON.stringify(r.value.cooked):JSON.stringify("")),!1===r.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+V(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function ye(e,n){try{return"lang.binary("+V(e,n.left)+","+V(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function be(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new l(e,r.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new l(e,r.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+V(e,n.left)+") "+n.operator+" lang.logicalCheck("+V(e,n.right)+"))";throw new l(null,r.LogicExpressionOrAnd,null)}catch(t){throw t}}function we(e,n){try{const t=n.name.toLowerCase();if(ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lscope['"+t+"']";if(void 0!==e.localScope._SymbolsMap[t])return"lscope['"+e.localScope._SymbolsMap[t]+"']"}if(void 0!==e.globalScope[t])return"gscope['"+t+"']";if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";const o={manglename:Ce(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new l(e,r.InvalidIdentifier,n)}catch(t){throw t}}function Se(e,n){try{if("MemberExpression"===n.callee.type){let t;!0===n.callee.computed?t=V(e,n.callee.property):(t="'"+n.callee.property.name+"'",ue(n.callee.property.name));let o="[";for(let r=0;r<n.arguments.length;r++)r>0&&(o+=", "),o+=V(e,n.arguments[r]);return o+="]",e.isAsync?"(yield lang.callModuleFunction("+V(e,n.callee.object)+","+o+","+t+",runtimeCtx))":"lang.callModuleFunction("+V(e,n.callee.object)+","+o+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new l(e,r.FunctionNotFound,n);const t=n.callee.name.toLowerCase();if("iif"===t)return ve(e,n);if("when"===t)return Fe(e,n);if("defaultvalue"===t)return xe(e,n);if("decode"===t)return Me(e,n);let o="";if(null!==e.localScope&&(void 0!==e.localScope[t]?o="lscope['"+t+"']":void 0!==e.localScope._SymbolsMap[t]&&(o="lscope['"+e.localScope._SymbolsMap[t]+"']")),""===o)if(void 0!==e.globalScope[t])o="gscope['"+t+"']";else if(void 0!==e.globalScope._SymbolsMap[t])o="gscope['"+e.globalScope._SymbolsMap[t]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(t))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";else{const r={manglename:Ce(e),node:n.argument};e.undeclaredGlobalsInFunctions.set(t,r),o="gscope[lang.chkAssig('"+r.manglename+"',runtimeCtx)]"}if(""!==o){let t="[";for(let o=0;o<n.arguments.length;o++)o>0&&(t+=", "),t+=V(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new l(e,r.FunctionNotFound,n)}catch(t){throw t}}function ve(e,n){try{if(3!==n.arguments.length)throw new l(e,r.WrongNumberOfParameters,n);const t=Ae(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${V(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${V(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${V(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function xe(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new l(e,r.WrongNumberOfParameters,n);const t=Ae(e),o=Ae(e),a=Ae(e),s=Ae(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${V(e,n.arguments[0])};\n var ${o} = ${V(e,n.arguments[1])};\n var ${a} = [];\n if (lang.isImmutableArray(${o})) {\n ${a} = ${o}.toArray();\n } else if (lang.isArray(${o})) {\n ${a} = ${o};\n } else {\n lang.error('${r.InvalidParameter}');\n }\n if (${t} === null) {\n return ${V(e,n.arguments[2])};\n }\n for (var ${s} of ${a}) {\n if (lang.isFeature(${t})) {\n if (lang.isString(${s}) === false) {\n return ${V(e,n.arguments[2])};\n }\n if (!${t}.hasField(${s})) {\n return ${V(e,n.arguments[2])};\n }\n ${t} = ${t}.field(${s});\n } else if (lang.isDictionary(${t})) {\n if (lang.isString(${s}) === false) {\n return ${V(e,n.arguments[2])};\n }\n if (!${t}.hasField(${s})) {\n return ${V(e,n.arguments[2])};\n }\n ${t} = ${t}.field(${s});\n } else if (lang.isGeometry(${t})) {\n if (lang.isString(${s}) === false) {\n return ${V(e,n.arguments[2])};\n }\n ${t} = lang.geometryMember(${t}, ${s}, null, null, 2);\n if (${t} === null) {\n return ${V(e,n.arguments[2])};\n }\n if (${t} && ${t}.keystate === "notfound") {\n return ${V(e,n.arguments[2])};\n }\n } else if (lang.isArray(${t})) {\n if (lang.isNumber(${s}) === false) {\n return ${V(e,n.arguments[2])};\n }\n ${t} = ${t}[${s}];\n if (${t} === null || ${t} === undefined) {\n return ${V(e,n.arguments[2])};\n }\n } else if (lang.isImmutableArray(${t})) {\n if (lang.isNumber(${s}) === false) {\n return ${V(e,n.arguments[2])};\n }\n ${t} = ${t}.get(${s});\n if (${t} === null || ${t} === undefined) {\n return ${V(e,n.arguments[2])};\n }\n } else {\n return ${V(e,n.arguments[2])};\n }\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`:`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${V(e,n.arguments[0])};\n if (${t} === null) {\n return ${V(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${V(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${V(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Fe(e,n){try{if(n.arguments.length<3)throw new l(e,r.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new l(e,r.WrongNumberOfParameters,n);const t=Ae(e);let o="var ";for(let r=0;r<n.arguments.length-1;r+=2)o+=`${t} = lang.mustBoolean(${V(e,n.arguments[r])}, runtimeCtx);\n if (${t} === true ) {\n return ${V(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Me(e,n){try{if(n.arguments.length<2)throw new l(e,r.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${V(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new l(e,r.WrongNumberOfParameters,n);const t=Ae(e),o=Ae(e);let a="var ";for(let r=1;r<n.arguments.length-1;r+=2)a+=`${o} = ${V(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${V(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${V(e,n.arguments[0])};\n ${a}\n return ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const $e={};function Ce(e){return e.symbols.symbolCounter++,"_T"+e.symbols.symbolCounter.toString()}function Ae(e){return e.symbols.symbolCounter++,"_Tvar"+e.symbols.symbolCounter.toString()}N($e,z),P($e,z),D($e,z),j($e,z),U($e,z),$e.iif=function(e,n){try{return z(e,n,((t,l,a)=>{throw new o(e,r.Unrecognized,n)}))}catch(t){throw t}},$e.decode=function(e,n){try{return z(e,n,((t,l,a)=>{throw new o(e,r.Unrecognized,n)}))}catch(t){throw t}},$e.when=function(e,n){try{return z(e,n,((t,l,a)=>{throw new o(e,r.Unrecognized,n)}))}catch(t){throw t}},$e.defaultvalue=function(e,n){try{return z(e,n,((t,l,a)=>{throw new o(e,r.Unrecognized,n)}))}catch(t){throw t}};const Ie={};for(const Te in $e)Ie[Te]=new i($e[Te]);R($e,z);for(const Te in $e)$e[Te]=new i($e[Te]);const _e=function(){};_e.prototype=$e;const Oe=function(){};function ke(e,n,t){const o={};e||(e={}),t||(t={}),o._SymbolsMap={},o.textformatting=1,o.infinity=1,o.pi=1;for(const r in n)o[r]=1;for(const r in t)o[r]=1;for(const r in e)o[r]=1;return o}function Ee(e,n,o,r){const l=o?new Oe:new _e;e||(e={}),n||(n={});const a=new t({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,l._SymbolsMap={textformatting:1,infinity:1,pi:1},l.textformatting=a,l.infinity=Number.POSITIVE_INFINITY,l.pi=Math.PI;for(const t in n)l[t]=n[t],l._SymbolsMap[t]=1;for(const t in e)l._SymbolsMap[t]=1,e[t]&&"esri.Graphic"===e[t].declaredClass?l[t]=s.createFromGraphic(e[t],r??null):l[t]=e[t];return l}Oe.prototype=Ie;const Ge={fixSpatialReference:g,parseArguments:W,standardFunction:z};function Be(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:z,standardFunctionAsync:z,evaluateIdentifier:je};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)$e[e]=new i(t.functions[e]),_e.prototype[e]=$e[e];for(let e=0;e<t.signatures.length;e++)G(t.signatures[e],"sync")}else{for(const e in t.functions)Ie[e]=new i(t.functions[e]),Oe.prototype[e]=Ie[e];for(let e=0;e<t.signatures.length;e++)G(t.signatures[e],"async")}}function Ne(e,n){return e(n)}function je(e,n){const t=n.name;if("_SymbolsMap"===t)throw new o(e,r.InvalidIdentifier,null);if(e.localStack.length>0){if("_t"!==t.substr(0,2).toLowerCase()&&void 0!==e.localStack[e.localStack.length-1][t])return e.localStack[e.localStack.length-1][t];const n=e.mangleMap[t];if(void 0!==n&&void 0!==e.localStack[e.localStack.length-1][n])return e.localStack[e.localStack.length-1][n]}if("_t"!==t.substr(0,2).toLowerCase()&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const l=e.mangleMap[t];return void 0!==l?e.globalScope[l]:void 0}Be([B],"sync"),Be([B],"async");let Le=0;const Re={isNumber:e=>S(e),isArray:e=>v(e),isImmutableArray:e=>x(e),isFeature:e=>F(e),isString:e=>M(e),isDictionary:e=>$(e),isGeometry:e=>C(e),geometryMember:(e,n,t,o,r=1)=>L(e,n,t,o,r),error(e){throw new o(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,r)=>{function l(e){try{s(o.next(e))}catch(n){r(n)}}function a(e){try{s(o.throw(e))}catch(n){r(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(l,a):(Le++,Le%100==0?setTimeout((()=>{Le=0,l(e.value)}),0):l(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push([]),n.depthCounter.depth>64)throw new o(null,r.MaximumCallDepth,null);const t=e.apply(this,arguments);return Z(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new o(n,r.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new o(n,r.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>A(e),aCheck(e,n){if(m(e)){if("ArrayExpression"===n)throw new o(null,r.NoFunctionInArray,null);if("ObjectExpression"===n)throw new o(null,r.NoFunctionInDictionary,null);throw new o(null,r.NoFunctionInTemplateLiteral,null)}return e===y?null:e},Dictionary:t,Feature:s,UserDefinedCompiledFunction:q,dictionary(e){const n={},l=new Map;for(let t=0;t<e.length;t+=2){if(m(e[t+1]))throw new o(null,r.NoFunctionInDictionary,null);if(!1===M(e[t]))throw new o(null,r.KeyMustBeString,null);let a=e[t].toString();const s=a.toLowerCase();l.has(s)?a=l.get(s):l.set(s,a),e[t+1]===y?n[a]=null:n[a]=e[t+1]}const a=new t(n);return a.immutable=!1,a},strCheck(e){if(!1===M(e))throw new o(null,r.KeyMustBeString,null);return e},unary(e,n){if(I(e)){if("!"===n)return!e;if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new o(null,r.UnsupportedUnaryOperator,null)}if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new o(null,r.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===I(e))throw new o(null,r.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(I(e)&&I(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new o(null,r.LogicExpressionOrAnd,null)}throw new o(null,r.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return E(_(e),_(n),t);case"==":case"=":return k(e,n);case"!=":return!k(e,n);case"<":case">":case"<=":case">=":return O(e,n,t);case"+":return M(e)||M(n)?A(e)+A(n):_(e)+_(n);case"-":return _(e)-_(n);case"*":return _(e)*_(n);case"/":return _(e)/_(n);case"%":return _(e)%_(n);default:throw new o(null,r.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===y?null:e;case"/=":return _(t)/_(e);case"*=":return _(t)*_(e);case"-=":return _(t)-_(e);case"+=":return M(t)||M(e)?A(t)+A(e):_(t)+_(e);case"%=":return _(t)%_(e);default:throw new o(null,r.UnsupportedOperator,null)}},update(e,n,t,o){const r=_(e[n]);return e[n]="++"===t?r+1:r-1,!1===o?r:"++"===t?r+1:r-1},graphicToFeature:(e,n,t)=>null===e?null:s.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,l,a){let s;if(v(e)){if(!S(n))throw new o(null,r.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new o(null,r.OutOfBounds,null);s=_(e[n]),e[n]="++"===l?s+1:s-1}else if(e instanceof t){if(!1===M(n))throw new o(null,r.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new o(null,r.FieldNotFound,null,{key:n});s=_(e.field(n)),e.setField(n,"++"===l?s+1:s-1)}else if(F(e)){if(!1===M(n))throw new o(null,r.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new o(null,r.FieldNotFound,null);s=_(e.field(n)),e.setField(n,"++"===l?s+1:s-1)}else{if(x(e))throw new o(null,r.Immutable,null);if(!(e instanceof Ze))throw new o(null,r.InvalidIdentifier,null);if(!1===M(n))throw new o(null,r.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new o(null,r.ModuleExportNotFound,null);s=_(e.global(n)),e.setGlobal(n,"++"===l?s+1:s-1)}return!1===a?s:"++"===l?s+1:s-1},assignmember(e,n,l,a){if(v(e)){if(!S(n))throw new o(null,r.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new o(null,r.OutOfBounds,null);if(n===e.length){if("="!==l)throw new o(null,r.OutOfBounds,null);e[n]=this.assign(a,l,e[n])}else e[n]=this.assign(a,l,e[n])}else if(e instanceof t){if(!1===M(n))throw new o(null,r.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(a,l,e.field(n)));else{if("="!==l)throw new o(null,r.FieldNotFound,null);e.setField(n,this.assign(a,l,null))}}else if(F(e)){if(!1===M(n))throw new o(null,r.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(a,l,e.field(n)));else{if("="!==l)throw new o(null,r.FieldNotFound,null);e.setField(n,this.assign(a,l,null))}}else{if(x(e))throw new o(null,r.Immutable,null);if(!(e instanceof Ze))throw new o(null,r.InvalidIdentifier,null);if(!1===M(n))throw new o(null,r.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new o(null,r.ModuleExportNotFound,null);e.setGlobal(n,this.assign(a,l,e.global(n)))}},member(e,n){if(null===e)throw new o(null,r.MemberOfNull,null);if(e instanceof t||F(e)){if(M(n))return e.field(n);throw new o(null,r.InvalidMemberAccessKey,null)}if(e instanceof K){if(M(n))return L(e,n,null,null);throw new o(null,r.InvalidMemberAccessKey,null)}if(v(e)){if(S(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new o(null,r.OutOfBounds,null);return e[n]}throw new o(null,r.InvalidMemberAccessKey,null)}if(M(e)){if(S(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new o(null,r.OutOfBounds,null);return e[n]}throw new o(null,r.InvalidMemberAccessKey,null)}if(x(e)){if(S(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new o(null,r.OutOfBounds,null);return e.get(n)}throw new o(null,r.InvalidMemberAccessKey,null)}if(e instanceof Ze){if(M(n))return e.global(n);throw new o(null,r.InvalidMemberAccessKey,null)}throw new o(null,r.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,l){if(!(e instanceof Ze))throw new o(null,r.FunctionNotFound,null);const a=e.global(t);if(!1===m(a))throw new o(null,r.CallNonFunction,null);return a.call(l,{preparsed:!0,arguments:n})}};function De(e){console.log(e)}function Ue(e,t,a=!1){null===t&&(t={vars:{},customfunctions:{}});let s=null;e.usesModules&&(s=new n(null,e.loadedModules));const i={isAsync:a,globalScope:ke(t.vars,a?Ie:$e,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:t.customfunctions,libraryResolver:s,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let u=V(i,e);""===u&&(u="lc.voidOperation; "),i.undeclaredGlobalsInFunctions.size>0&&i.undeclaredGlobalsInFunctions.forEach((e=>{throw new l(t,r.InvalidIdentifier,e.node)}));let c="";c=a?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+u+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+u+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=i.moduleFactory,g=i.moduleFactoryMap,S=i.exports,v={};for(const n in S)v[n]=void 0!==i.mangleMap[n]?i.mangleMap[n]:n;const x={lc:f,lang:Re,mangles:i.mangleMap,postProcess(e){if(e instanceof d&&(e=e.value),e instanceof h&&(e=e.value),e===y&&(e=null),e===b)throw new o(null,r.IllegalResult,null);if(e===w)throw new o(null,r.IllegalResult,null);if(m(e))throw new o(null,r.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=T.WebMercator);const o=Ee(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:g,mangleMap:this.mangles,moduleSingletons:{},exports:S,gdefs:{},exportmangle:v,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",c).bind(x)}async function Pe(){return Be([await import("./functions/geomasync.js")],"async"),!0}class Ze extends e{constructor(e){super(null),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,l=e.toLowerCase();if(m(n))throw new o(null,r.AssignModuleFunction,null);t[this.moduleContext.exportmangle[l]]=n}global(e){const n=this.moduleContext.globalScope;e=e.toLowerCase();const t=n[this.moduleContext.exportmangle[e]];if(void 0===t)throw new o(null,r.InvalidIdentifier,null);if(m(t)&&!(t instanceof c)){const o=new c;return o.fn=t,o.parameterEvaluator=z,o.context=this.moduleContext,n[this.moduleContext.exportmangle[e]]=o,o}return t}}function Ke(e,t,o=!1){const r={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new n(null,e.loadedModules),globalScope:ke(t.vars,o?Ie:$e,t.customfunctions),customfunctions:t.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let l=V(r,e);""===l&&(l="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+l+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+l+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=r.moduleFactory,i=r.moduleFactoryMap,u=r.exports,c={};for(const n in u)c[n]=void 0!==r.mangleMap[n]?r.mangleMap[n]:n;const p={lc:f,lang:Re,mangles:r.mangleMap,prepareModule:e=>new Ze(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new T({wkid:102100}));const o=Ee(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:u,exportmangle:c,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(p)}export{q as UserDefinedCompiledFunction,Ue as compileScript,Pe as enableAsyncSupport,Ne as executeScript,Be as extend,Ge as functionHelper};
5
+ import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{geometryMember as t,getNestedOptionalValue as o}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a,ArcadeCompilationError as s,ArcadeUncompilableError as i}from"./executionError.js";import c from"./Feature.js";import{NativeFunction as u,ArcadeFunction as p,ScopeMarshalledFunction as m,wrapModuleScopedResponse as g}from"./FunctionWrapper.js";import{i as d,x as f,y as h,z as y,A as b,B as w,C as S,D as v,b as x,o as M,q as F,r as C,c as I,v as A,p as _,j as O,a as $,g as k,E,F as G,G as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as j}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as R}from"./functions/geometry.js";import{registerFunctions as U}from"./functions/geomsync.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as P}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{isPromiseLike as K}from"../core/promiseUtils.js";import T from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";class W extends p{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new r(e,a.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,l,r)=>{r=r.map((n=>!d(n)||n instanceof m?n:g(n,e,o)));const a=this.call(t,{arguments:r});return K(a)?a.then((e=>g(e,t,o))):a}))}}function V(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(J(e,n.arguments[o]));return t}function z(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function J(e,n){try{switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclarator":return ge(e,n);case"VariableDeclaration":return me(e,n);case"BlockStatement":case"Program":return ae(e,n);case"FunctionDeclaration":return pe(e,n);case"ImportDeclaration":return ie(e,n);case"ExportNamedDeclaration":return ce(e,n);case"ReturnStatement":return se(e,n);case"IfStatement":return re(e,n);case"ExpressionStatement":return oe(e,n);case"AssignmentExpression":return te(e,n);case"UpdateExpression":return ee(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"TemplateLiteral":return ye(e,n);case"TemplateElement":return JSON.stringify(n.value?n.value.cooked:"");case"ForStatement":return X(e,n);case"ForInStatement":return Q(e,n);case"WhileStatement":return ne(e,n);case"Identifier":return Se(e,n);case"MemberExpression":return de(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return ve(e,n);case"UnaryExpression":return fe(e,n);case"BinaryExpression":return be(e,n);case"LogicalExpression":return we(e,n);case"ArrayExpression":return he(e,n);case"ObjectExpression":return Y(e,n);case"Property":return H(e,n);case"Array":throw new s(e,a.NeverReach,n);default:throw new s(e,a.Unrecognized,n)}}catch(t){throw t}}function Y(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];ue(l.key.name);o>0&&(t+=","),t+="lang.strCheck("+("Identifier"===l.key.type?"'"+l.key.name+"'":J(e,l.key))+",'ObjectExpression'),lang.aCheck("+J(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function H(e,n){throw new s(e,a.NeverReach,n)}function Q(e,n){const t=_e(e),o=_e(e),l=_e(e);let r="var "+t+" = "+J(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(r+=J(e,n.left));let a="VariableDeclaration"===n.left.type?n.left.declarations[0].id.name:n.left.name;a=a.toLowerCase(),ue(a);let s="";null!==e.localScope&&(void 0!==e.localScope[a]?s="lscope['"+a+"']":void 0!==e.localScope._SymbolsMap[a]&&(s="lscope['"+e.localScope._SymbolsMap[a]+"']"));let i="";if(""===s)if(void 0!==e.globalScope[a])s="gscope['"+a+"']";else if(void 0!==e.globalScope._SymbolsMap[a])s="gscope['"+e.globalScope._SymbolsMap[a]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(a))s="gscope['"+e.undeclaredGlobalsInFunctions.get(a).manglename+"']",i=e.undeclaredGlobalsInFunctions.get(a).manglename;else{const t={manglename:Ae(e),node:n.left};e.undeclaredGlobalsInFunctions.set(a,t),s="gscope['"+t.manglename+"']",i=t.manglename}return i&&(r+="lang.chkAssig('"+i+"',runtimeCtx); \n"),r+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",r+="else if (lc.isArray("+t+") || lc.isString("+t+")) {",r+="var "+o+"="+t+".length; \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (lc.isImmutableArray("+t+")) {",r+="var "+o+"="+t+".length(); \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (( "+t+" instanceof lang.Dictionary) || ( "+t+" instanceof lang.Feature)) {",r+="var "+o+"="+t+".keys(); \n",r+="for(var "+l+"=0; "+l+"<"+o+".length; "+l+"++) {\n",r+=s+"="+o+"["+l+"];\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",e.isAsync&&(r+="else if (lc.isFeatureSet("+t+")) {",r+="var "+o+"="+t+".iterator(runtimeCtx.abortSignal); \n",r+="for(var "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx); "+l+"!=null; "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx)) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n"),r+="else { lastStatement = lc.voidOperation; } \n",r}function X(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&(t+=J(e,n.init)+"; ");const o=_e(e),l=_e(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+J(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+J(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+a.BooleanConditionRequired+"'); }\n"),t+=J(e,n.body),null!==n.update&&(t+="\n "+J(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function ee(e,n){let t=null,o="";if("MemberExpression"===n.argument.type)return t=J(e,n.argument.object),!0===n.argument.computed?o=J(e,n.argument.property):(o="'"+n.argument.property.name+"'",ue(n.argument.property.name)),"lang.memberupdate("+t+","+o+",'"+n.operator+"',"+n.prefix+")";if(t=n.argument.name.toLowerCase(),ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lang.update(lscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.localScope._SymbolsMap[t])return"lang.update(lscope, '"+e.localScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")"}if(void 0!==e.globalScope[t])return"lang.update(gscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.globalScope._SymbolsMap[t])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")";const o={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"lang.update(gscope, lang.chkAssig('"+o.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new r(e,a.InvalidIdentifier,n)}function ne(e,n){let t="lastStatement = lc.voidOperation; \n";const o=_e(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${J(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${a.BooleanConditionRequired}');\n }\n ${J(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function te(e,n){const t=J(e,n.right);let o=null,l="";if("MemberExpression"===n.left.type)return o=J(e,n.left.object),!0===n.left.computed?l=J(e,n.left.property):(l="'"+n.left.property.name+"'",ue(n.left.property.name)),"lang.assignmember("+o+","+l+",'"+n.operator+"',"+t+")";if(o=n.left.name.toLowerCase(),ue(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+o+"'])";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+e.localScope._SymbolsMap[o]+"'])"}if(void 0!==e.globalScope[o])return"gscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+o+"'])";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+e.globalScope._SymbolsMap[o]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(o).manglename+"'])";const l={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(o,l),"gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+l.manglename+"'])"}throw new r(e,a.InvalidIdentifier,n)}function oe(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+J(e,n.expression)+"; \n ":(n.expression.type,"lastStatement = "+J(e,n.expression)+"; ")}function le(e,n){return"BlockStatement"===n.type?J(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?J(e,n)+"; ":"UpdateExpression"===n.type?"lastStatement = "+J(e,n)+"; ":"ExpressionStatement"===n.type?J(e,n):"ObjectExpression"===n.type?"lastStatement = "+J(e,n)+"; ":J(e,n)+"; "}function re(e,n){if("AssignmentExpression"===n.test.type||"UpdateExpression"===n.test.type)throw new s(e,a.BooleanConditionRequired,n);return`if (lang.mustBoolean(${J(e,n.test)}, runtimeCtx) === true) {\n ${le(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+re(e,n.alternate):` else {\n ${le(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ae(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=J(e,n.body[o])+"; \n":"UpdateExpression"===n.body[o].type||"ObjectExpression"===n.body[o].type?t+="lastStatement = "+J(e,n.body[o])+"; \n":t+=J(e,n.body[o])+" \n");return t}function se(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+J(e,n.argument)}function ie(e,n){const t=n.specifiers[0].local.name.toLowerCase();ue(t);const o=e.libraryResolver?.loadLibrary(t),l=Ae(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=Te(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeZone:e.timeZone??null,libraryResolver:e.libraryResolver,customfunctions:e.customfunctions,vars:{}},e.isAsync)),e.moduleFactoryMap[l]=o.uri;let r="";if(r=e.isAsync?"(yield lang.loadModule('"+l+"', runtimeCtx) ); ":"lang.loadModule('"+l+"', runtimeCtx); ",void 0!==e.globalScope[t])return"gscope['"+t+"']="+r;if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']="+r;let a="";return e.undeclaredGlobalsInFunctions.has(t)?(a=e.undeclaredGlobalsInFunctions.get(t).manglename,e.undeclaredGlobalsInFunctions.delete(t)):a=Ae(e),e.globalScope._SymbolsMap[t]=a,e.mangleMap[t]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+r}function ce(e,n){const t=J(e,n.declaration);if("FunctionDeclaration"===n.declaration.type)e.exports[n.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===n.declaration.type)for(const o of n.declaration.declarations)e.exports[o.id.name.toLowerCase()]="variable";return t}function ue(e){if("iif"===e)throw new i;if("decode"===e)throw new i;if("when"===e)throw new i;if("defaultvalue"===e)throw new i}function pe(e,n){const t=n.id.name.toLowerCase();ue(t);let o="",l=!1;void 0!==e.globalScope[t]?o=t:void 0!==e.globalScope._SymbolsMap[t]?o=e.globalScope._SymbolsMap[t]:e.undeclaredGlobalsInFunctions.has(t)?(o=e.undeclaredGlobalsInFunctions.get(t).manglename,e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o,e.undeclaredGlobalsInFunctions.delete(t),l=!0):(o=Ae(e),e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o);const r={isAsync:e.isAsync,console:e.console,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,customfunctions:e.customfunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let a="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let s=0;s<n.params.length;s++){const t=n.params[s].name.toLowerCase();ue(t);const o=Ae(e);r.localScope._SymbolsMap[t]=o,r.mangleMap[t]=o,a+="lscope['"+o+"']=arguments["+s.toString()+"];\n"}return!0===e.isAsync?(a+="return lang.__awaiter(this, void 0, void 0, function* () {\n",a+=ae(r,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=ae(r,n.body)+"\n return lastStatement; }, runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"),l?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+a:"gscope['"+o+"']="+a}function me(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(J(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function ge(e,n){let t=null===n.init?null:J(e,n.init);t===w&&(t=null);const o=n.id.name.toLowerCase();if(ue(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+t+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+t+"; ";{const n=Ae(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+t+"; "}}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+t+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+t+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+t+"; "}const l=Ae(e);return e.globalScope._SymbolsMap[o]=l,e.mangleMap[o]=l,"gscope['"+l+"']="+t+"; "}function de(e,n){try{let t;return!0===n.computed?t=J(e,n.property):(t="'"+n.property.name+"'",ue(n.property.name)),"lang.member("+J(e,n.object)+","+t+")"}catch(t){throw t}}function fe(e,n){try{return"lang.unary("+J(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function he(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(J(e,n.elements[o])):t.push("lang.aCheck("+J(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function ye(e,n){try{const t=[];let o=0;for(const l of n.quasis)t.push(l.value?JSON.stringify(l.value.cooked):JSON.stringify("")),!1===l.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+J(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function be(e,n){try{return"lang.binary("+J(e,n.left)+","+J(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function we(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+J(e,n.left)+") "+n.operator+" lang.logicalCheck("+J(e,n.right)+"))";throw new s(null,a.LogicExpressionOrAnd,null)}catch(t){throw t}}function Se(e,n){try{const t=n.name.toLowerCase();if(ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lscope['"+t+"']";if(void 0!==e.localScope._SymbolsMap[t])return"lscope['"+e.localScope._SymbolsMap[t]+"']"}if(void 0!==e.globalScope[t])return"gscope['"+t+"']";if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";const o={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new s(e,a.InvalidIdentifier,n)}catch(t){throw t}}function ve(e,n){try{if("MemberExpression"===n.callee.type){let t;!0===n.callee.computed?t=J(e,n.callee.property):(t="'"+n.callee.property.name+"'",ue(n.callee.property.name));let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=J(e,n.arguments[l]);return o+="]",e.isAsync?"(yield lang.callModuleFunction("+J(e,n.callee.object)+","+o+","+t+",runtimeCtx))":"lang.callModuleFunction("+J(e,n.callee.object)+","+o+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new s(e,a.FunctionNotFound,n);const t=n.callee.name.toLowerCase();if("iif"===t)return xe(e,n);if("when"===t)return Fe(e,n);if("defaultvalue"===t)return Me(e,n);if("decode"===t)return Ce(e,n);let o="";if(null!==e.localScope&&(void 0!==e.localScope[t]?o="lscope['"+t+"']":void 0!==e.localScope._SymbolsMap[t]&&(o="lscope['"+e.localScope._SymbolsMap[t]+"']")),""===o)if(void 0!==e.globalScope[t])o="gscope['"+t+"']";else if(void 0!==e.globalScope._SymbolsMap[t])o="gscope['"+e.globalScope._SymbolsMap[t]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(t))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";else{const l={manglename:Ae(e),node:n.argument};e.undeclaredGlobalsInFunctions.set(t,l),o="gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]"}if(""!==o){let t="[";for(let o=0;o<n.arguments.length;o++)o>0&&(t+=", "),t+=J(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new s(e,a.FunctionNotFound,n)}catch(t){throw t}}function xe(e,n){try{if(3!==n.arguments.length)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${J(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${J(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Me(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e),o=_e(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n var ${o} = ${J(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${o});\n return ${t} != null && ${t} !== "" ? ${t} : ${J(e,n.arguments[2])};\n ${e.isAsync?"})}()))":"}()"}`:`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n if (${t} === null) {\n return ${J(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${J(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${J(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Fe(e,n){try{if(n.arguments.length<3)throw new s(e,a.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${J(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${J(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${J(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ce(e,n){try{if(n.arguments.length<2)throw new s(e,a.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${J(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e),o=_e(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${o} = ${J(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${J(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n ${l}\n return ${J(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const Ie={};function Ae(e){return e.symbols.symbolCounter++,"_T"+e.symbols.symbolCounter.toString()}function _e(e){return e.symbols.symbolCounter++,"_Tvar"+e.symbols.symbolCounter.toString()}L(Ie,z),Z(Ie,z),D(Ie,z),R(Ie,z),P(Ie,z),Ie.iif=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.decode=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.when=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.defaultvalue=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}};const Oe={};for(const qe in Ie)Oe[qe]=new u(Ie[qe]);U(Ie,z);for(const qe in Ie)Ie[qe]=new u(Ie[qe]);const $e=function(){};$e.prototype=Ie;const ke=function(){};function Ee(e,n,t){const o={};e||(e={}),t||(t={}),o._SymbolsMap={},o.textformatting=1,o.infinity=1,o.pi=1;for(const l in n)o[l]=1;for(const l in t)o[l]=1;for(const l in e)o[l]=1;return o}function Ge(e,n,t,o){const r=t?new ke:new $e;e||(e={}),n||(n={});const a=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r._SymbolsMap={textformatting:1,infinity:1,pi:1},r.textformatting=a,r.infinity=Number.POSITIVE_INFINITY,r.pi=Math.PI;for(const l in n)r[l]=n[l],r._SymbolsMap[l]=1;for(const l in e)r._SymbolsMap[l]=1,e[l]&&"esri.Graphic"===e[l].declaredClass?r[l]=c.createFromGraphic(e[l],o??null):r[l]=e[l];return r}ke.prototype=Oe;const Be={fixSpatialReference:f,parseArguments:V,standardFunction:z};function je(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:z,standardFunctionAsync:z,evaluateIdentifier:Le};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)Ie[e]=new u(t.functions[e]),$e.prototype[e]=Ie[e];for(let e=0;e<t.signatures.length;e++)j(t.signatures[e],"sync")}else{for(const e in t.functions)Oe[e]=new u(t.functions[e]),ke.prototype[e]=Oe[e];for(let e=0;e<t.signatures.length;e++)j(t.signatures[e],"async")}}function Ne(e,n){return e(n)}function Le(e,n){const t=n.name;if("_SymbolsMap"===t)throw new r(e,a.InvalidIdentifier,null);if(e.localStack.length>0){if("_t"!==t.substr(0,2).toLowerCase()&&void 0!==e.localStack[e.localStack.length-1][t])return e.localStack[e.localStack.length-1][t];const n=e.mangleMap[t];if(void 0!==n&&void 0!==e.localStack[e.localStack.length-1][n])return e.localStack[e.localStack.length-1][n]}if("_t"!==t.substr(0,2).toLowerCase()&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const o=e.mangleMap[t];return void 0!==o?e.globalScope[o]:void 0}je([N],"sync"),je([N],"async");let Re=0;const Ue={isNumber:e=>x(e),isArray:e=>M(e),isImmutableArray:e=>F(e),isFeature:e=>C(e),isString:e=>I(e),isDictionary:e=>A(e),isGeometry:e=>_(e),geometryMember:(e,n,o,l,r=1)=>t(e,n,o,l,r),error(e){throw new r(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,l)=>{function r(e){try{s(o.next(e))}catch(n){l(n)}}function a(e){try{s(o.throw(e))}catch(n){l(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(r,a):(Re++,Re%100==0?setTimeout((()=>{Re=0,r(e.value)}),0):r(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push([]),n.depthCounter.depth>64)throw new r(null,a.MaximumCallDepth,null);const t=e.apply(this,arguments);return K(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new r(n,a.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new r(n,a.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>O(e),aCheck(e,n){if(d(e)){if("ArrayExpression"===n)throw new r(null,a.NoFunctionInArray,null);if("ObjectExpression"===n)throw new r(null,a.NoFunctionInDictionary,null);throw new r(null,a.NoFunctionInTemplateLiteral,null)}return e===w?null:e},Dictionary:l,Feature:c,UserDefinedCompiledFunction:W,dictionary(e){const n={},t=new Map;for(let l=0;l<e.length;l+=2){if(d(e[l+1]))throw new r(null,a.NoFunctionInDictionary,null);if(!1===I(e[l]))throw new r(null,a.KeyMustBeString,null);let o=e[l].toString();const s=o.toLowerCase();t.has(s)?o=t.get(s):t.set(s,o),e[l+1]===w?n[o]=null:n[o]=e[l+1]}const o=new l(n);return o.immutable=!1,o},strCheck(e){if(!1===I(e))throw new r(null,a.KeyMustBeString,null);return e},unary(e,n){if($(e)){if("!"===n)return!e;if("-"===n)return-1*k(e);if("+"===n)return 1*k(e);if("~"===n)return~k(e);throw new r(null,a.UnsupportedUnaryOperator,null)}if("-"===n)return-1*k(e);if("+"===n)return 1*k(e);if("~"===n)return~k(e);throw new r(null,a.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===$(e))throw new r(null,a.LogicExpressionOrAnd,null);return e},logical(e,n,t){if($(e)&&$(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new r(null,a.LogicExpressionOrAnd,null)}throw new r(null,a.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return B(k(e),k(n),t);case"==":case"=":return G(e,n);case"!=":return!G(e,n);case"<":case">":case"<=":case">=":return E(e,n,t);case"+":return I(e)||I(n)?O(e)+O(n):k(e)+k(n);case"-":return k(e)-k(n);case"*":return k(e)*k(n);case"/":return k(e)/k(n);case"%":return k(e)%k(n);default:throw new r(null,a.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===w?null:e;case"/=":return k(t)/k(e);case"*=":return k(t)*k(e);case"-=":return k(t)-k(e);case"+=":return I(t)||I(e)?O(t)+O(e):k(t)+k(e);case"%=":return k(t)%k(e);default:throw new r(null,a.UnsupportedOperator,null)}},update(e,n,t,o){const l=k(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,n,t)=>null===e?null:c.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,o){let s;if(M(e)){if(!x(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new r(null,a.OutOfBounds,null);s=k(e[n]),e[n]="++"===t?s+1:s-1}else if(e instanceof l){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null,{key:n});s=k(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else if(C(e)){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null);s=k(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else{if(F(e))throw new r(null,a.Immutable,null);if(!(e instanceof Ke))throw new r(null,a.InvalidIdentifier,null);if(!1===I(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);s=k(e.global(n)),e.setGlobal(n,"++"===t?s+1:s-1)}return!1===o?s:"++"===t?s+1:s-1},assignmember(e,n,t,o){if(M(e)){if(!x(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new r(null,a.OutOfBounds,null);if(n===e.length){if("="!==t)throw new r(null,a.OutOfBounds,null);e[n]=this.assign(o,t,e[n])}else e[n]=this.assign(o,t,e[n])}else if(e instanceof l){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else if(C(e)){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else{if(F(e))throw new r(null,a.Immutable,null);if(!(e instanceof Ke))throw new r(null,a.InvalidIdentifier,null);if(!1===I(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);e.setGlobal(n,this.assign(o,t,e.global(n)))}},member(e,n){if(null===e)throw new r(null,a.MemberOfNull,null);if(e instanceof l||C(e)){if(I(n))return e.field(n);throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof T){if(I(n))return t(e,n,null,null);throw new r(null,a.InvalidMemberAccessKey,null)}if(M(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(I(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(F(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new r(null,a.OutOfBounds,null);return e.get(n)}throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof Ke){if(I(n))return e.global(n);throw new r(null,a.InvalidMemberAccessKey,null)}throw new r(null,a.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,o){if(!(e instanceof Ke))throw new r(null,a.FunctionNotFound,null);const l=e.global(t);if(!1===d(l))throw new r(null,a.CallNonFunction,null);return l.call(o,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>o(e,n)};function De(e){console.log(e)}function Pe(e,t,o=!1){null===t&&(t={vars:{},customfunctions:{}});let l=null;e.usesModules&&(l=new n(null,e.loadedModules));const i={isAsync:o,globalScope:Ee(t.vars,o?Oe:Ie,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:t.customfunctions,libraryResolver:l,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let c=J(i,e);""===c&&(c="lc.voidOperation; "),i.undeclaredGlobalsInFunctions.size>0&&i.undeclaredGlobalsInFunctions.forEach((e=>{throw new s(t,a.InvalidIdentifier,e.node)}));let u="";u=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+c+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+c+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=i.moduleFactory,m=i.moduleFactoryMap,g=i.exports,f={};for(const n in g)f[n]=void 0!==i.mangleMap[n]?i.mangleMap[n]:n;const x={lc:h,lang:Ue,mangles:i.mangleMap,postProcess(e){if(e instanceof y&&(e=e.value),e instanceof b&&(e=e.value),e===w&&(e=null),e===S)throw new r(null,a.IllegalResult,null);if(e===v)throw new r(null,a.IllegalResult,null);if(d(e))throw new r(null,a.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=q.WebMercator);const o=Ge(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:m,mangleMap:this.mangles,moduleSingletons:{},exports:g,gdefs:{},exportmangle:f,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",u).bind(x)}async function Ze(){return je([await import("./functions/geomasync.js")],"async"),!0}class Ke extends e{constructor(e){super(null),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,o=e.toLowerCase();if(d(n))throw new r(null,a.AssignModuleFunction,null);t[this.moduleContext.exportmangle[o]]=n}global(e){const n=this.moduleContext.globalScope;e=e.toLowerCase();const t=n[this.moduleContext.exportmangle[e]];if(void 0===t)throw new r(null,a.InvalidIdentifier,null);if(d(t)&&!(t instanceof m)){const o=new m;return o.fn=t,o.parameterEvaluator=z,o.context=this.moduleContext,n[this.moduleContext.exportmangle[e]]=o,o}return t}}function Te(e,t,o=!1){const l={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new n(null,e.loadedModules),globalScope:Ee(t.vars,o?Oe:Ie,t.customfunctions),customfunctions:t.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let r=J(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+r+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+r+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=l.moduleFactory,i=l.moduleFactoryMap,c=l.exports,u={};for(const n in c)u[n]=void 0!==l.mangleMap[n]?l.mangleMap[n]:n;const p={lc:h,lang:Ue,mangles:l.mangleMap,prepareModule:e=>new Ke(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new q({wkid:102100}));const o=Ge(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:c,exportmangle:u,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(p)}export{W as UserDefinedCompiledFunction,Pe as compileScript,Ze as enableAsyncSupport,Ne as executeScript,je as extend,Be as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import n from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as o,ensureArcadeExecutionError as l}from"./executionError.js";import i from"./Feature.js";import{NativeFunction as a,ArcadeFunction as s,ScopeMarshalledFunction as c,wrapModuleScopedResponse as u}from"./FunctionWrapper.js";import{H as f,a as p,q as d,o as h,r as w,c as m,b as g,F as v,D as y,C as b,B as x,i as S,z as F,g as I,A as C,j as R,E as A,G as M,x as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as L}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as O}from"./functions/date.js";import{registerFunctions as B,geometryMember as k}from"./functions/geometry.js";import{registerFunctions as j}from"./functions/geomsync.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import q from"../geometry/Geometry.js";import G from"../geometry/SpatialReference.js";class Z extends s{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={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:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,null);return Fe(this.definition,n,t,null)}}call(e,t){return W(e,t,((n,l,i)=>{const a={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,t);return Fe(this.definition,a,i,t)}))}marshalledCall(e,t,n,r){return r(e,t,((o,l,i)=>{const a={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!S(t)||t instanceof c?t:u(t,e,r))),u(Fe(this.definition,a,i,t),n,r)}))}}class P extends e{constructor(e){super(e)}global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=V(this.executingContext,t.node),t.valueset=!0),S(t.value)&&!(t.value instanceof c)){const e=new c;e.fn=t.value,e.parameterEvaluator=W,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(S(t))throw new r(null,o.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}loadModule(e){let n=e.spatialReference;null==n&&(n=new G({wkid:102100})),this.moduleScope=Ce({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,globalScope:this.moduleScope,localScope:null,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??Ae,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},V(this.executingContext,this.source.syntax)}}function T(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(V(e,t.arguments[r]));return n}function W(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,T(e,t))}catch(r){throw r}}function V(e,t){try{switch(t?.type){case"EmptyStatement":return x;case"VariableDeclarator":return ce(e,t);case"VariableDeclaration":return se(e,t);case"ImportDeclaration":return ie(e,t);case"ExportNamedDeclaration":return ae(e,t);case"BlockStatement":case"Program":return re(e,t);case"FunctionDeclaration":return le(e,t);case"ReturnStatement":return oe(e,t);case"IfStatement":return ne(e,t);case"ExpressionStatement":return te(e,t);case"AssignmentExpression":return ee(e,t);case"UpdateExpression":return X(e,t);case"BreakStatement":return b;case"ContinueStatement":return y;case"TemplateElement":return we(e,t);case"TemplateLiteral":return ge(e,t);case"ForStatement":return Y(e,t);case"ForInStatement":return H(e,t);case"WhileStatement":return J(e,t);case"Identifier":return ve(e,t);case"MemberExpression":return ue(e,t);case"Literal":return t.value;case"CallExpression":return ye(e,t);case"UnaryExpression":return fe(e,t);case"BinaryExpression":return de(e,t);case"LogicalExpression":return he(e,t);case"ArrayExpression":return pe(e,t);case"ObjectExpression":return _(e,t);case"Property":return z(e,t);default:throw new r(e,o.Unrecognized,t)}}catch(n){throw l(e,t,n)}}function _(e,t){const l={},i=new Map;for(let n=0;n<t.properties.length;n++){const a=V(e,t.properties[n]);if(S(a.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===m(a.key))throw new r(e,o.KeyMustBeString,t);let s=a.key.toString();const c=s.toLowerCase();i.has(c)?s=i.get(c):i.set(c,s),a.value===x?l[s]=null:l[s]=a.value}const a=new n(l);return a.immutable=!1,a}function z(e,t){return{key:"Identifier"===t.key.type?t.key.name:V(e,t.key),value:V(e,t.value)}}function H(e,t){const l=V(e,t.right);"VariableDeclaration"===t.left.type&&V(e,t.left);let i=null,a="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===t.left.type&&(a=t.left.name);if(!a)throw new r(e,o.InvalidIdentifier,t);if(a=a.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[a]&&(i=e.localScope[a]),null===i&&void 0!==e.globalScope[a]&&(i=e.globalScope[a]),null===i)throw new r(e,o.InvalidIdentifier,t);if(h(l)||m(l)){const n=l.length;for(let r=0;r<n;r++){i.value=r;const n=V(e,t.body);if(n===b)break;if(n instanceof F)return n}return x}if(d(l)){for(let n=0;n<l.length();n++){i.value=n;const r=V(e,t.body);if(r===b)break;if(r instanceof F)return r}return x}if(!(l instanceof n||w(l)))return x;{const n=l.keys();for(let r=0;r<n.length;r++){i.value=n[r];const o=V(e,t.body);if(o===b)break;if(o instanceof F)return o}}}function Y(e,t){null!==t.init&&V(e,t.init);const n={testResult:!0,lastAction:x};do{Q(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof F?n.lastAction:x}function J(e,t){const n={testResult:!0,lastAction:x};if(n.testResult=V(e,t.test),!1===n.testResult)return x;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=V(e,t.body),n.lastAction!==b)&&!(n.lastAction instanceof F);)if(n.testResult=V(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof F?n.lastAction:x}function Q(e,t,n){if(null!==t.test){if(n.testResult=V(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t)}n.lastAction=V(e,t.body),n.lastAction!==b?n.lastAction instanceof F?n.testResult=!1:null!==t.update&&V(e,t.update):n.testResult=!1}function X(e,t){let l,i=null,a="";if("MemberExpression"===t.argument.type){if(i=V(e,t.argument.object),!0===t.argument.computed?a=V(e,t.argument.property):"Identifier"===t.argument.property.type&&(a=t.argument.property.name),h(i)){if(!g(a))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(a<0&&(a=i.length+a),a<0||a>=i.length)throw new r(e,o.OutOfBounds,t);l=I(i[a]),i[a]="++"===t.operator?l+1:l-1}else if(i instanceof n){if(!1===m(a))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasField(a))throw new r(e,o.FieldNotFound,t);l=I(i.field(a)),i.setField(a,"++"===t.operator?l+1:l-1)}else if(w(i)){if(!1===m(a))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasField(a))throw new r(e,o.FieldNotFound,t);l=I(i.field(a)),i.setField(a,"++"===t.operator?l+1:l-1)}else{if(d(i))throw new r(e,o.Immutable,t);if(!(i instanceof P))throw new r(e,o.InvalidParameter,t);if(!1===m(a))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==i.hasGlobal(a))throw new r(e,o.ModuleExportNotFound,t);l=I(i.global(a)),i.setGlobal(a,"++"===t.operator?l+1:l-1)}return!1===t.prefix?l:"++"===t.operator?l+1:l-1}if(i="Identifier"===t.argument.type?t.argument.name.toLowerCase():"",!i)throw new r(e,o.InvalidIdentifier,t);if(null!=e.localScope&&void 0!==e.localScope[i])return l=I(e.localScope[i].value),e.localScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[i])return l=I(e.globalScope[i].value),e.globalScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new r(e,o.InvalidIdentifier,t)}function $(e,t,n,l,i){switch(t){case"=":return e===x?null:e;case"/=":return I(n)/I(e);case"*=":return I(n)*I(e);case"-=":return I(n)-I(e);case"+=":return m(n)||m(e)?R(n)+R(e):I(n)+I(e);case"%=":return I(n)%I(e);default:throw new r(i,o.UnsupportedOperator,l)}}function ee(e,t){let l=null,i="";if("MemberExpression"===t.left.type){if(l=V(e,t.left.object),!0===t.left.computed)i=V(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new r(e,o.InvalidIdentifier,t);i=t.left.property.name}const a=V(e,t.right);if(h(l)){if(!g(i))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(i<0&&(i=l.length+i),i<0||i>l.length)throw new r(e,o.OutOfBounds,t);if(i===l.length){if("="!==t.operator)throw new r(e,o.OutOfBounds,t);l[i]=$(a,t.operator,l[i],t,e)}else l[i]=$(a,t.operator,l[i],t,e)}else if(l instanceof n){if(!1===m(i))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===l.hasField(i))l.setField(i,$(a,t.operator,l.field(i),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:i});l.setField(i,$(a,t.operator,null,t,e))}}else if(w(l)){if(!1===m(i))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===l.hasField(i))l.setField(i,$(a,t.operator,l.field(i),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:i});l.setField(i,$(a,t.operator,null,t,e))}}else{if(d(l))throw new r(e,o.Immutable,t);if(!(l instanceof P))throw new r(e,o.InvalidIdentifier,t);if(!1===m(i))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==l.hasGlobal(i))throw new r(e,o.ModuleExportNotFound,t);l.setGlobal(i,$(a,t.operator,l.global(i),t,e))}return x}l=t.left.name.toLowerCase();const a=V(e,t.right);if(null!=e.localScope&&void 0!==e.localScope[l])return e.localScope[l]={value:$(a,t.operator,e.localScope[l].value,t,e),valueset:!0,node:t.right},x;if(void 0!==e.globalScope[l])return e.globalScope[l]={value:$(a,t.operator,e.globalScope[l].value,t,e),valueset:!0,node:t.right},x;throw new r(e,o.InvalidIdentifier,t)}function te(e,t){if("AssignmentExpression"===t.expression.type||"UpdateExpression"===t.expression.type)return V(e,t.expression);if("CallExpression"===t.expression.type){const n=V(e,t.expression);return n===x?x:new C(n)}{const n=V(e,t.expression);return n===x?x:new C(n)}}function ne(e,t){const n=V(e,t.test);if(!0===n)return V(e,t.consequent);if(!1===n)return null!==t.alternate?V(e,t.alternate):x;throw new r(e,o.BooleanConditionRequired,t)}function re(e,t){let n=x;for(let r=0;r<t.body.length;r++)if(n=V(e,t.body[r]),n instanceof F||n===b||n===y)return n;return n}function oe(e,t){if(null===t.argument)return new F(x);const n=V(e,t.argument);return new F(n)}function le(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new Z(t,e)},x}function ie(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new P(r),o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},x}function ae(e,t){if(V(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return x}function se(e,t){for(let n=0;n<t.declarations.length;n++)V(e,t.declarations[n]);return x}function ce(e,t){let n=null===t.init?null:V(e,t.init);if(n===x&&(n=null),"Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const l=t.id.name.toLowerCase();return null!=e.localScope?e.localScope[l]={value:n,valueset:!0,node:t.init}:e.globalScope[l]={value:n,valueset:!0,node:t.init},x}function ue(e,t){try{const l=V(e,t.object);if(null===l)throw new r(e,o.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(l instanceof n||w(l))return l.field(t.property.name);if(l instanceof q)return k(l,t.property.name,e,t);if(l instanceof P){if(!l.hasGlobal(t.property.name))throw new r(e,o.InvalidIdentifier,t);return l.global(t.property.name)}}throw new r(e,o.InvalidMemberAccessKey,t)}{let i=V(e,t.property);if(l instanceof n||w(l)){if(m(i))return l.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(l instanceof P){if(m(i))return l.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(l instanceof q){if(m(i))return k(l,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(h(l)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=l.length+i),i>=l.length||i<0)throw new r(e,o.OutOfBounds,t);return l[i]}throw new r(e,o.InvalidMemberAccessKey,t)}if(m(l)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=l.length+i),i>=l.length||i<0)throw new r(e,o.OutOfBounds,t);return l[i]}throw new r(e,o.InvalidMemberAccessKey,t)}if(d(l)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=l.length()+i),i>=l.length()||i<0)throw new r(e,o.OutOfBounds,t);return l.get(i)}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}}catch(l){throw l}}function fe(e,t){try{const n=V(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*I(n);if("+"===t.operator)return 1*I(n);if("~"===t.operator)return~I(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~I(n);if("-"===t.operator)return-1*I(n);if("+"===t.operator)return 1*I(n);throw new r(e,o.UnsupportedUnaryOperator,t)}catch(n){throw n}}function pe(e,t){try{const n=[];for(let l=0;l<t.elements.length;l++){const i=V(e,t.elements[l]);if(S(i))throw new r(e,o.NoFunctionInArray,t);i===x?n.push(null):n.push(i)}return n}catch(n){throw n}}function de(e,t){try{const n=[V(e,t.left),V(e,t.right)],l=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return M(I(l),I(i),t.operator);case"==":return v(l,i);case"!=":return!v(l,i);case"<":case">":case"<=":case">=":return A(l,i,t.operator);case"+":return m(l)||m(i)?R(l)+R(i):I(l)+I(i);case"-":return I(l)-I(i);case"*":return I(l)*I(i);case"/":return I(l)/I(i);case"%":return I(l)%I(i);default:throw new r(e,o.UnsupportedOperator,t)}}catch(n){throw n}}function he(e,t){try{const n=V(e,t.left);if(p(n))switch(t.operator){case"||":if(!0===n)return n;{const n=V(e,t.right);if(p(n))return n;throw new r(e,o.LogicExpressionOrAnd,t)}case"&&":if(!1===n)return n;{const n=V(e,t.right);if(p(n))return n;throw new r(e,o.LogicExpressionOrAnd,t)}default:throw new r(e,o.LogicExpressionOrAnd,t)}throw new r(e,o.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function we(e,t){return t.value?t.value.cooked:""}function me(e,t,n){if(S(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}function ge(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?R(me(V(e,t.expressions[r]),e,t)):"",r++}return n}function ve(e,t){let n;try{const l=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[l])return n=e.localScope[l],!0===n.valueset||(n.value=V(e,n.node),n.valueset=!0),n.value;if(void 0!==e.globalScope[l])return n=e.globalScope[l],!0===n.valueset||(n.value=V(e,n.node),n.valueset=!0),n.value;throw new r(e,o.InvalidIdentifier,t)}catch(l){throw l}}function ye(e,t){try{if("MemberExpression"===t.callee.type){const n=V(e,t.callee.object);if(!(n instanceof P))throw new r(e,o.FunctionNotFound,t);const l=!1===t.callee.computed?t.callee.property.name:V(e,t.callee.property);if(!n.hasGlobal(l))throw new r(e,o.FunctionNotFound,t);const i=n.global(l);if(!S(i))throw new r(e,o.CallNonFunction,t);return i.call(e,t)}if("Identifier"!==t.callee.type)throw new r(e,o.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(S(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(S(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FunctionNotFound,t)}catch(n){throw n}}const be={};function xe(e,t,n,r){try{const o=t.arguments,l=V(e,o[n]);if(v(l,r))return V(e,o[n+1]);{const l=o.length-n;return 1===l?V(e,o[n]):2===l?null:3===l?V(e,o[n+2]):xe(e,t,n+2,r)}}catch(o){throw o}}function Se(e,t,n,l){try{const i=t.arguments;if(!0===l)return V(e,i[n+1]);if(3===i.length-n)return V(e,i[n+2]);{const l=V(e,i[n+2]);if(!1===p(l))throw new r(e,o.BooleanConditionRequired,i[n+2]);return Se(e,t,n+2,l)}}catch(i){throw i}}function Fe(e,t,n,l){try{const i=e.body;if(n.length!==e.params.length)throw new r(t,o.WrongNumberOfParameters,l);if(null!=t.localScope)for(let r=0;r<n.length;r++)t.localScope[e.params[r].name.toLowerCase()]={value:n[r],valueset:!0,node:null};const a=V(t,i);if(a instanceof F)return a.value;if(a===b)throw new r(t,o.UnexpectedToken,l);if(a===y)throw new r(t,o.UnexpectedToken,l);return a instanceof C?a.value:a}catch(i){throw i}}O(be,W),U(be,W),D(be,W),B(be,W),K(be,W),j(be,W),be.iif=function(e,t){try{const n=t.arguments;f(null===n?[]:n,3,3,e,t);const l=V(e,n[0]);if(!1===p(l))throw new r(e,o.BooleanConditionRequired,t);return V(e,!0===l?n[1]:n[2])}catch(n){throw n}},be.defaultvalue=function(e,t){try{const l=t.arguments;f(null===l?[]:l,2,3,e,t);const i=V(e,l[0]);if(3===l.length){const a=V(e,l[1]);let s=[];if(d(a))s=a.toArray();else{if(!h(a))throw new r(e,o.InvalidParameter,t);s=a}let c=i;if(null===c)return V(e,l[2]);for(const t of s)if(w(c)){if(!1===m(t))return V(e,l[2]);if(!c.hasField(t))return V(e,l[2]);c=c.field(t)}else if(c instanceof n){if(!1===m(t))return V(e,l[2]);if(!c.hasField(t))return V(e,l[2]);c=c.field(t)}else if(c instanceof q){if(!1===m(t))return V(e,l[2]);if(c=k(c,t,null,null,2),null===c)return V(e,l[2]);if("notfound"===c?.keystate)return V(e,l[2])}else if(h(c)){if(!1===g(t))return V(e,l[2]);if(c=c[t],null==c)return V(e,l[2])}else{if(!d(c))return V(e,l[2]);if(!1===g(t))return V(e,l[2]);if(c=c.get(t),null==c)return V(e,l[2])}return c}return null===i||""===i||void 0===i?V(e,l[1]):i}catch(l){throw l}},be.decode=function(e,t){try{const n=t.arguments;if(n.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===n.length)return V(e,n[1]);{if((n.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);const l=V(e,n[0]);return xe(e,t,1,l)}}catch(n){throw n}},be.when=function(e,t){try{const n=t.arguments;if(n.length<3)throw new r(e,o.WrongNumberOfParameters,t);if(n.length%2==0)throw new r(e,o.WrongNumberOfParameters,t);const l=V(e,n[0]);if(!1===p(l))throw new r(e,o.BooleanConditionRequired,n[0]);return Se(e,t,0,l)}catch(n){throw n}};for(const Le in be)be[Le]={value:new a(be[Le]),valueset:!0,node:null};const Ie=function(){};function Ce(e,t,r){const o=new Ie;e||(e={}),t||(t={});const l=new n({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});l.immutable=!1,o.textformatting={value:l,valueset:!0,node:null};for(const n in t)o[n]={value:new a(t[n]),native:!0,valueset:!0,node:null};for(const n in e)e[n]&&"esri.Graphic"===e[n].declaredClass?o[n]={value:i.createFromGraphic(e[n],r),valueset:!0,node:null}:o[n]={value:e[n],valueset:!0,node:null};return o}Ie.prototype=be,Ie.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ie.prototype.pi={value:Math.PI,valueset:!0,node:null};const Re={fixSpatialReference:E,parseArguments:T,standardFunction:W};function Ae(e){console.log(e)}function Me(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:W,evaluateIdentifier:ve};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)be[n]={value:new a(t.functions[n]),valueset:!0,node:null},Ie.prototype[n]=be[n];for(let n=0;n<t.signatures.length;n++)L(t.signatures[n],"sync")}function Ee(e,n){let l=n.spatialReference;null==l&&(l=new G({wkid:102100}));let i=null;e.usesModules&&(i=new t(new Map,e.loadedModules));const a={spatialReference:l,globalScope:Ce(n.vars,n.customfunctions,n.timeZone),localScope:null,services:n.services??null,exports:{},libraryResolver:i,console:n.console??Ae,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,depthCounter:{depth:1}};let s=V(a,e);if(s instanceof F&&(s=s.value),s instanceof C&&(s=s.value),s===x&&(s=null),s===b)throw new r(a,o.IllegalResult,null);if(s===y)throw new r(a,o.IllegalResult,null);if(S(s))throw new r(a,o.IllegalResult,null);return s}Me([N]);export{Ee as executeScript,Me as extend,Re as functionHelper};
5
+ import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as o}from"./containerUtils.js";import r from"./Dictionary.js";import{ArcadeExecutionError as l,ExecutionErrorCodes as i,ensureArcadeExecutionError as a}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{H as d,a as h,F as w,D as m,C as g,B as v,i as y,c as b,o as x,z as S,q as I,r as F,b as C,g as R,A,j as M,E,G as L,x as N}from"../chunks/languageUtils.js";import{addFunctionDeclaration as O}from"./treeAnalysis.js";import{A as B}from"../chunks/array.js";import{registerFunctions as j}from"./functions/date.js";import{registerFunctions as k}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/geomsync.js";import{registerFunctions as U}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as q}from"./functions/string.js";import G from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";class P extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={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:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,null);return Fe(this.definition,n,t,null)}}call(e,t){return V(e,t,((n,o,r)=>{const a={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,t);return Fe(this.definition,a,r,t)}))}marshalledCall(e,t,n,o){return o(e,t,((r,l,i)=>{const a={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!y(t)||t instanceof f?t:p(t,e,o))),p(Fe(this.definition,a,i,t),n,o)}))}}class T extends e{constructor(e){super(e)}global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=_(this.executingContext,t.node),t.valueset=!0),y(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=V,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(y(t))throw new l(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}loadModule(e){let n=e.spatialReference;null==n&&(n=new Z({wkid:102100})),this.moduleScope=Re({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,globalScope:this.moduleScope,localScope:null,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??Me,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},_(this.executingContext,this.source.syntax)}}function W(e,t){const n=[];for(let o=0;o<t.arguments.length;o++)n.push(_(e,t.arguments[o]));return n}function V(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,W(e,t))}catch(o){throw o}}function _(e,t){try{switch(t?.type){case"EmptyStatement":return v;case"VariableDeclarator":return ue(e,t);case"VariableDeclaration":return ce(e,t);case"ImportDeclaration":return ae(e,t);case"ExportNamedDeclaration":return se(e,t);case"BlockStatement":case"Program":return re(e,t);case"FunctionDeclaration":return ie(e,t);case"ReturnStatement":return le(e,t);case"IfStatement":return oe(e,t);case"ExpressionStatement":return ne(e,t);case"AssignmentExpression":return te(e,t);case"UpdateExpression":return $(e,t);case"BreakStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return me(e,t);case"TemplateLiteral":return ve(e,t);case"ForStatement":return J(e,t);case"ForInStatement":return Y(e,t);case"WhileStatement":return Q(e,t);case"Identifier":return ye(e,t);case"MemberExpression":return fe(e,t);case"Literal":return t.value;case"CallExpression":return be(e,t);case"UnaryExpression":return pe(e,t);case"BinaryExpression":return he(e,t);case"LogicalExpression":return we(e,t);case"ArrayExpression":return de(e,t);case"ObjectExpression":return z(e,t);case"Property":return H(e,t);default:throw new l(e,i.Unrecognized,t)}}catch(n){throw a(e,t,n)}}function z(e,t){const n={},o=new Map;for(let r=0;r<t.properties.length;r++){const a=_(e,t.properties[r]);if(y(a.value))throw new l(e,i.NoFunctionInDictionary,t);if(!1===b(a.key))throw new l(e,i.KeyMustBeString,t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===v?n[s]=null:n[s]=a.value}const a=new r(n);return a.immutable=!1,a}function H(e,t){return{key:"Identifier"===t.key.type?t.key.name:_(e,t.key),value:_(e,t.value)}}function Y(e,t){const n=_(e,t.right);"VariableDeclaration"===t.left.type&&_(e,t.left);let o=null,a="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===t.left.type&&(a=t.left.name);if(!a)throw new l(e,i.InvalidIdentifier,t);if(a=a.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new l(e,i.InvalidIdentifier,t);if(x(n)||b(n)){const r=n.length;for(let n=0;n<r;n++){o.value=n;const r=_(e,t.body);if(r===g)break;if(r instanceof S)return r}return v}if(I(n)){for(let r=0;r<n.length();r++){o.value=r;const n=_(e,t.body);if(n===g)break;if(n instanceof S)return n}return v}if(!(n instanceof r||F(n)))return v;{const r=n.keys();for(let n=0;n<r.length;n++){o.value=r[n];const l=_(e,t.body);if(l===g)break;if(l instanceof S)return l}}}function J(e,t){null!==t.init&&_(e,t.init);const n={testResult:!0,lastAction:v};do{X(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof S?n.lastAction:v}function Q(e,t){const n={testResult:!0,lastAction:v};if(n.testResult=_(e,t.test),!1===n.testResult)return v;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=_(e,t.body),n.lastAction!==g)&&!(n.lastAction instanceof S);)if(n.testResult=_(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:v}function X(e,t,n){if(null!==t.test){if(n.testResult=_(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t)}n.lastAction=_(e,t.body),n.lastAction!==g?n.lastAction instanceof S?n.testResult=!1:null!==t.update&&_(e,t.update):n.testResult=!1}function $(e,t){let n,o=null,a="";if("MemberExpression"===t.argument.type){if(o=_(e,t.argument.object),!0===t.argument.computed?a=_(e,t.argument.property):"Identifier"===t.argument.property.type&&(a=t.argument.property.name),x(o)){if(!C(a))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new l(e,i.OutOfBounds,t);n=R(o[a]),o[a]="++"===t.operator?n+1:n-1}else if(o instanceof r){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else if(F(o)){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else{if(I(o))throw new l(e,i.Immutable,t);if(!(o instanceof T))throw new l(e,i.InvalidParameter,t);if(!1===b(a))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==o.hasGlobal(a))throw new l(e,i.ModuleExportNotFound,t);n=R(o.global(a)),o.setGlobal(a,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}if(o="Identifier"===t.argument.type?t.argument.name.toLowerCase():"",!o)throw new l(e,i.InvalidIdentifier,t);if(null!=e.localScope&&void 0!==e.localScope[o])return n=R(e.localScope[o].value),e.localScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=R(e.globalScope[o].value),e.globalScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;throw new l(e,i.InvalidIdentifier,t)}function ee(e,t,n,o,r){switch(t){case"=":return e===v?null:e;case"/=":return R(n)/R(e);case"*=":return R(n)*R(e);case"-=":return R(n)-R(e);case"+=":return b(n)||b(e)?M(n)+M(e):R(n)+R(e);case"%=":return R(n)%R(e);default:throw new l(r,i.UnsupportedOperator,o)}}function te(e,t){let n=null,o="";if("MemberExpression"===t.left.type){if(n=_(e,t.left.object),!0===t.left.computed)o=_(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new l(e,i.InvalidIdentifier,t);o=t.left.property.name}const a=_(e,t.right);if(x(n)){if(!C(o))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(o<0&&(o=n.length+o),o<0||o>n.length)throw new l(e,i.OutOfBounds,t);if(o===n.length){if("="!==t.operator)throw new l(e,i.OutOfBounds,t);n[o]=ee(a,t.operator,n[o],t,e)}else n[o]=ee(a,t.operator,n[o],t,e)}else if(n instanceof r){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else if(F(n)){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else{if(I(n))throw new l(e,i.Immutable,t);if(!(n instanceof T))throw new l(e,i.InvalidIdentifier,t);if(!1===b(o))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==n.hasGlobal(o))throw new l(e,i.ModuleExportNotFound,t);n.setGlobal(o,ee(a,t.operator,n.global(o),t,e))}return v}n=t.left.name.toLowerCase();const a=_(e,t.right);if(null!=e.localScope&&void 0!==e.localScope[n])return e.localScope[n]={value:ee(a,t.operator,e.localScope[n].value,t,e),valueset:!0,node:t.right},v;if(void 0!==e.globalScope[n])return e.globalScope[n]={value:ee(a,t.operator,e.globalScope[n].value,t,e),valueset:!0,node:t.right},v;throw new l(e,i.InvalidIdentifier,t)}function ne(e,t){if("AssignmentExpression"===t.expression.type||"UpdateExpression"===t.expression.type)return _(e,t.expression);if("CallExpression"===t.expression.type){const n=_(e,t.expression);return n===v?v:new A(n)}{const n=_(e,t.expression);return n===v?v:new A(n)}}function oe(e,t){const n=_(e,t.test);if(!0===n)return _(e,t.consequent);if(!1===n)return null!==t.alternate?_(e,t.alternate):v;throw new l(e,i.BooleanConditionRequired,t)}function re(e,t){let n=v;for(let o=0;o<t.body.length;o++)if(n=_(e,t.body[o]),n instanceof S||n===g||n===m)return n;return n}function le(e,t){if(null===t.argument)return new S(v);const n=_(e,t.argument);return new S(n)}function ie(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new P(t,e)},v}function ae(e,t){const n=t.specifiers[0].local.name.toLowerCase(),o=e.libraryResolver.loadLibrary(n);let r=null;return e.libraryResolver._moduleSingletons?.has(o.uri)?r=e.libraryResolver._moduleSingletons.get(o.uri):(r=new T(o),r.loadModule(e),e.libraryResolver._moduleSingletons?.set(o.uri,r)),e.globalScope[n]={value:r,valueset:!0,node:t},v}function se(e,t){if(_(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return v}function ce(e,t){for(let n=0;n<t.declarations.length;n++)_(e,t.declarations[n]);return v}function ue(e,t){let n=null===t.init?null:_(e,t.init);if(n===v&&(n=null),"Identifier"!==t.id.type)throw new l(e,i.InvalidIdentifier,t);const o=t.id.name.toLowerCase();return null!=e.localScope?e.localScope[o]={value:n,valueset:!0,node:t.init}:e.globalScope[o]={value:n,valueset:!0,node:t.init},v}function fe(e,t){try{const n=_(e,t.object);if(null===n)throw new l(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof r||F(n))return n.field(t.property.name);if(n instanceof G)return o(n,t.property.name,e,t);if(n instanceof T){if(!n.hasGlobal(t.property.name))throw new l(e,i.InvalidIdentifier,t);return n.global(t.property.name)}}throw new l(e,i.InvalidMemberAccessKey,t)}{let a=_(e,t.property);if(n instanceof r||F(n)){if(b(a))return n.field(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof T){if(b(a))return n.global(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof G){if(b(a))return o(n,a,e,t);throw new l(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length()+a),a>=n.length()||a<0)throw new l(e,i.OutOfBounds,t);return n.get(a)}throw new l(e,i.InvalidMemberAccessKey,t)}throw new l(e,i.InvalidMemberAccessKey,t)}}catch(n){throw n}}function pe(e,t){try{const n=_(e,t.argument);if(h(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);if("~"===t.operator)return~R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~R(n);if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}catch(n){throw n}}function de(e,t){try{const n=[];for(let o=0;o<t.elements.length;o++){const r=_(e,t.elements[o]);if(y(r))throw new l(e,i.NoFunctionInArray,t);r===v?n.push(null):n.push(r)}return n}catch(n){throw n}}function he(e,t){try{const n=[_(e,t.left),_(e,t.right)],o=n[0],r=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return L(R(o),R(r),t.operator);case"==":return w(o,r);case"!=":return!w(o,r);case"<":case">":case"<=":case">=":return E(o,r,t.operator);case"+":return b(o)||b(r)?M(o)+M(r):R(o)+R(r);case"-":return R(o)-R(r);case"*":return R(o)*R(r);case"/":return R(o)/R(r);case"%":return R(o)%R(r);default:throw new l(e,i.UnsupportedOperator,t)}}catch(n){throw n}}function we(e,t){try{const n=_(e,t.left);if(h(n))switch(t.operator){case"||":if(!0===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}case"&&":if(!1===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}default:throw new l(e,i.LogicExpressionOrAnd,t)}throw new l(e,i.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function me(e,t){return t.value?t.value.cooked:""}function ge(e,t,n){if(y(e))throw new l(t,i.NoFunctionInTemplateLiteral,n);return e}function ve(e,t){let n="",o=0;for(const r of t.quasis)if(n+=r.value?r.value.cooked:"",!1===r.tail){n+=t.expressions[o]?M(ge(_(e,t.expressions[o]),e,t)):"",o++}return n}function ye(e,t){let n;try{const o=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[o])return n=e.localScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;if(void 0!==e.globalScope[o])return n=e.globalScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;throw new l(e,i.InvalidIdentifier,t)}catch(o){throw o}}function be(e,t){try{if("MemberExpression"===t.callee.type){const n=_(e,t.callee.object);if(!(n instanceof T))throw new l(e,i.FunctionNotFound,t);const o=!1===t.callee.computed?t.callee.property.name:_(e,t.callee.property);if(!n.hasGlobal(o))throw new l(e,i.FunctionNotFound,t);const r=n.global(o);if(!y(r))throw new l(e,i.CallNonFunction,t);return r.call(e,t)}if("Identifier"!==t.callee.type)throw new l(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}throw new l(e,i.FunctionNotFound,t)}catch(n){throw n}}const xe={};function Se(e,t,n,o){try{const r=t.arguments,l=_(e,r[n]);if(w(l,o))return _(e,r[n+1]);{const l=r.length-n;return 1===l?_(e,r[n]):2===l?null:3===l?_(e,r[n+2]):Se(e,t,n+2,o)}}catch(r){throw r}}function Ie(e,t,n,o){try{const r=t.arguments;if(!0===o)return _(e,r[n+1]);if(3===r.length-n)return _(e,r[n+2]);{const o=_(e,r[n+2]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,r[n+2]);return Ie(e,t,n+2,o)}}catch(r){throw r}}function Fe(e,t,n,o){try{const r=e.body;if(n.length!==e.params.length)throw new l(t,i.WrongNumberOfParameters,o);if(null!=t.localScope)for(let o=0;o<n.length;o++)t.localScope[e.params[o].name.toLowerCase()]={value:n[o],valueset:!0,node:null};const a=_(t,r);if(a instanceof S)return a.value;if(a===g)throw new l(t,i.UnexpectedToken,o);if(a===m)throw new l(t,i.UnexpectedToken,o);return a instanceof A?a.value:a}catch(r){throw r}}j(xe,V),q(xe,V),U(xe,V),k(xe,V),K(xe,V),D(xe,V),xe.iif=function(e,t){try{const n=t.arguments;d(null===n?[]:n,3,3,e,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,t);return _(e,!0===o?n[1]:n[2])}catch(n){throw n}},xe.defaultvalue=function(e,t){try{const o=t.arguments;d(null===o?[]:o,2,3,e,t);const r=_(e,o[0]);if(3===o.length){const t=_(e,o[1]),l=n(r,t);return null!=l&&""!==l?l:_(e,o[2])}return null===r||""===r||void 0===r?_(e,o[1]):r}catch(o){throw o}},xe.decode=function(e,t){try{const n=t.arguments;if(n.length<2)throw new l(e,i.WrongNumberOfParameters,t);if(2===n.length)return _(e,n[1]);{if((n.length-1)%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);return Se(e,t,1,o)}}catch(n){throw n}},xe.when=function(e,t){try{const n=t.arguments;if(n.length<3)throw new l(e,i.WrongNumberOfParameters,t);if(n.length%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,n[0]);return Ie(e,t,0,o)}catch(n){throw n}};for(const Ne in xe)xe[Ne]={value:new c(xe[Ne]),valueset:!0,node:null};const Ce=function(){};function Re(e,t,n){const o=new Ce;e||(e={}),t||(t={});const l=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});l.immutable=!1,o.textformatting={value:l,valueset:!0,node:null};for(const r in t)o[r]={value:new c(t[r]),native:!0,valueset:!0,node:null};for(const r in e)e[r]&&"esri.Graphic"===e[r].declaredClass?o[r]={value:s.createFromGraphic(e[r],n),valueset:!0,node:null}:o[r]={value:e[r],valueset:!0,node:null};return o}Ce.prototype=xe,Ce.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ce.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ae={fixSpatialReference:N,parseArguments:W,standardFunction:V};function Me(e){console.log(e)}function Ee(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:V,evaluateIdentifier:ye};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)xe[n]={value:new c(t.functions[n]),valueset:!0,node:null},Ce.prototype[n]=xe[n];for(let n=0;n<t.signatures.length;n++)O(t.signatures[n],"sync")}function Le(e,n){let o=n.spatialReference;null==o&&(o=new Z({wkid:102100}));let r=null;e.usesModules&&(r=new t(new Map,e.loadedModules));const a={spatialReference:o,globalScope:Re(n.vars,n.customfunctions,n.timeZone),localScope:null,services:n.services??null,exports:{},libraryResolver:r,console:n.console??Me,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,depthCounter:{depth:1}};let s=_(a,e);if(s instanceof S&&(s=s.value),s instanceof A&&(s=s.value),s===v&&(s=null),s===g)throw new l(a,i.IllegalResult,null);if(s===m)throw new l(a,i.IllegalResult,null);if(y(s))throw new l(a,i.IllegalResult,null);return s}Ee([B]);export{Le as executeScript,Ee as extend,Ae as functionHelper};
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
+ */
5
+ import e from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as r}from"./executionError.js";import t from"./ImmutablePathArray.js";import n from"./ImmutablePointArray.js";import{o as s,q as c,r as i,c as l,v as u,p as o,b as f}from"../chunks/languageUtils.js";let h=0;function d(s,c,i,l,u=1){let o;switch(c=c.toLowerCase()){case"hasz":{const e=s.hasZ;return void 0!==e&&e}case"hasm":{const e=s.hasM;return void 0!==e&&e}case"spatialreference":{let a=s.spatialReference._arcadeCacheId;if(void 0===a){let e=!0;Object.freeze&&Object.isFrozen(s.spatialReference)&&(e=!1),e&&(h++,s.spatialReference._arcadeCacheId=h,a=h)}const r=new e({wkt:s.spatialReference.wkt,wkid:s.spatialReference.wkid});return void 0!==a&&(r._arcadeCacheId="SPREF"+a.toString()),r}}switch(s.type){case"extent":switch(c){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const e=s[c];return void 0!==e?e:null}case"type":return"Extent"}break;case"polygon":switch(c){case"rings":o=s.cache._arcadeCacheId,void 0===o&&(h++,o=h,s.cache._arcadeCacheId=o);return new t(s.rings,s.spatialReference,!0===s.hasZ,!0===s.hasM,o);case"type":return"Polygon"}break;case"point":switch(c){case"x":case"y":case"z":case"m":return s[c]??null;case"type":return"Point"}break;case"polyline":switch(c){case"paths":o=s.cache._arcadeCacheId,void 0===o&&(h++,o=h,s.cache._arcadeCacheId=o);return new t(s.paths,s.spatialReference,!0===s.hasZ,!0===s.hasM,o);case"type":return"Polyline"}break;case"multipoint":switch(c){case"points":o=s.cache._arcadeCacheId,void 0===o&&(h++,o=h,s.cache._arcadeCacheId=o);return new n(s.points,s.spatialReference,!0===s.hasZ,!0===s.hasM,o,1);case"type":return"Multipoint"}}if(1===u)throw new a(i,r.InvalidIdentifier,l);return 2===u?{keystate:"notfound"}:null}function p(e,a){let r,t=e;if(null==t)return null;if(s(a))r=a;else if(c(a))r=a.toArray();else{if(null==a)return null;r=[a]}for(const n of r){if(i(t)){if(!1===l(n))return null;if(!t.hasField(n))return null;t=t.field(n)}else if(u(t)){if(!1===l(n))return null;if(!t.hasField(n))return null;t=t.field(n)}else if(o(t)){if(!1===l(n))return null;t=d(t,n,null,null,0)}else if(s(t)){if(!1===f(n))return null;t=n>=0?t[n]:t[t.length+n]}else{if(!c(t))return null;if(!1===f(n))return null;t=n>=0?t.get(n):t.get(t.length()+n)}if(null==t)return null}return t}export{d as geometryMember,p as getNestedOptionalValue};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"../Dictionary.js";import{ArcadeExecutionError as t,ExecutionErrorCodes as n}from"../executionError.js";import r from"../Feature.js";import a from"../ImmutablePathArray.js";import i from"../ImmutablePointArray.js";import{H as s,o as l,q as o,x as f,S as c,I as u,r as m,B as p,c as h,j as w,k as d,b as y,n as R,m as g,a as I,i as v,f as P,N as b,F,L as x}from"../../chunks/languageUtils.js";import{angle2D as O,angleBetween2D as S,bearing2D as j,bearingBetween2D as N,pathsSelfIntersecting as k}from"./centroid.js";import J from"../../geometry/Extent.js";import z from"../../geometry/Geometry.js";import D from"../../geometry/Multipoint.js";import G from"../../geometry/Point.js";import Z from"../../geometry/Polygon.js";import _ from"../../geometry/Polyline.js";import{isClockwise as C}from"../../geometry/support/coordsUtils.js";import{fromJSON as M}from"../../geometry/support/jsonUtils.js";function A(a,A){a.ringisclockwise=function(e,r){return A(e,r,((a,f,c)=>{s(c,1,1,e,r);let u=[];if(null===c[0])return!1;if(l(c[0]))for(const i of c[0]){if(!(i instanceof G))throw new t(e,n.InvalidParameter,r);u.push(i.hasZ?i.hasM?[i.x,i.y,i.z,i.m]:[i.x,i.y,i.z]:[i.x,i.y])}else if(c[0]instanceof i)u=c[0]._elements;else{if(!o(c[0]))throw new t(e,n.InvalidParameter,r);for(const a of c[0].toArray()){if(!(a instanceof G))throw new t(e,n.InvalidParameter,r);u.push(a.hasZ?a.hasM?[a.x,a.y,a.z,a.m]:[a.x,a.y,a.z]:[a.x,a.y])}}return!(u.length<3)&&C(u)}))},a.polygon=function(a,i){return A(a,i,((l,o,u)=>{let m;if(s(u,1,1,a,i),u[0]instanceof e){const e=f(r.parseGeometryFromDictionary(u[0],a.spatialReference),a.spatialReference);if(e instanceof Z==!1)throw new t(a,n.InvalidParameter,i);m=e}else if(u[0]instanceof Z)m=M(u[0].toJSON());else{const e=JSON.parse(u[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),m=f(new Z(e),a.spatialReference)}if(null!==m&&!1===m.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(m)}))},a.polyline=function(a,i){return A(a,i,((l,o,u)=>{let m;if(s(u,1,1,a,i),u[0]instanceof e){const e=f(r.parseGeometryFromDictionary(u[0],a.spatialReference),a.spatialReference);if(e instanceof _==!1)throw new t(a,n.InvalidParameter,i);m=e}else if(u[0]instanceof _)m=M(u[0].toJSON());else{const e=JSON.parse(u[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),m=f(new _(e),a.spatialReference)}if(null!==m&&!1===m.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(m)}))},a.point=function(a,i){return A(a,i,((l,o,u)=>{let m;if(s(u,1,1,a,i),u[0]instanceof e){const e=f(r.parseGeometryFromDictionary(u[0],a.spatialReference),a.spatialReference);if(e instanceof G==!1)throw new t(a,n.InvalidParameter,i);m=e}else if(u[0]instanceof G)m=M(u[0].toJSON());else{const e=JSON.parse(u[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),m=f(new G(e),a.spatialReference)}if(null!==m&&!1===m.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(m)}))},a.multipoint=function(a,i){return A(a,i,((l,o,u)=>{let m;if(s(u,1,1,a,i),u[0]instanceof e){const e=f(r.parseGeometryFromDictionary(u[0],a.spatialReference),a.spatialReference);if(e instanceof D==!1)throw new t(a,n.InvalidParameter,i);m=e}else if(u[0]instanceof D)m=M(u[0].toJSON());else{const e=JSON.parse(u[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),m=f(new D(e),a.spatialReference)}if(null!==m&&!1===m.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(m)}))},a.extent=function(a,i){return A(a,i,((l,o,m)=>{m=u(m),s(m,1,1,a,i);let p=null;if(m[0]instanceof e)p=f(r.parseGeometryFromDictionary(m[0],a.spatialReference),a.spatialReference);else if(m[0]instanceof G){const e={xmin:m[0].x,ymin:m[0].y,xmax:m[0].x,ymax:m[0].y,spatialReference:m[0].spatialReference.toJSON()},t=m[0];t.hasZ?(e.zmin=t.z,e.zmax=t.z):t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=M(e)}else if(m[0]instanceof Z)p=M(m[0].extent?.toJSON());else if(m[0]instanceof _)p=M(m[0].extent?.toJSON());else if(m[0]instanceof D)p=M(m[0].extent?.toJSON());else if(m[0]instanceof J)p=M(m[0].toJSON());else{const e=JSON.parse(m[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),p=f(new J(e),a.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(p)}))},a.geometry=function(a,i){return A(a,i,((l,o,u)=>{s(u,1,1,a,i);let p=null;if(null===u[0])return null;if(m(u[0]))p=f(u[0].geometry(),a.spatialReference);else if(u[0]instanceof e)p=f(r.parseGeometryFromDictionary(u[0],a.spatialReference),a.spatialReference);else{const e=JSON.parse(u[0]);e&&!e.spatialReference&&(e.spatialReference=a.spatialReference),p=f(M(e),a.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(a.spatialReference))throw new t(a,n.WrongSpatialReference,i);return c(p)}))},a.setgeometry=function(e,r){return A(e,r,((a,i,l)=>{if(s(l,2,2,e,r),!m(l[0]))throw new t(e,n.InvalidParameter,r);if(!0===l[0].immutable)throw new t(e,n.Immutable,r);if(!(l[1]instanceof z||null===l[1]))throw new t(e,n.InvalidParameter,r);return l[0]._geometry=l[1],p}))},a.feature=function(a,i){return A(a,i,((s,l,o)=>{if(0===o.length)throw new t(a,n.WrongNumberOfParameters,i);let c;if(1===o.length)if(h(o[0]))c=r.fromJson(JSON.parse(o[0]),a.timeZone);else if(m(o[0]))c=r.createFromArcadeFeature(o[0]);else if(o[0]instanceof z)c=r.createFromGraphicLikeObject(o[0],null,null,a.timeZone);else{if(!(o[0]instanceof e))throw new t(a,n.InvalidParameter,i);{let t=o[0].hasField("geometry")?o[0].field("geometry"):null,n=o[0].hasField("attributes")?o[0].field("attributes"):null;null!==t&&t instanceof e&&(t=r.parseGeometryFromDictionary(t,a.spatialReference)),null!==n&&(n=r.parseAttributesFromDictionary(n)),c=r.createFromGraphicLikeObject(t,n,null,a.timeZone)}}else if(2===o.length){let s=null,l=null;if(null!==o[0])if(o[0]instanceof z)s=o[0];else{if(!(s instanceof e))throw new t(a,n.InvalidParameter,i);s=r.parseGeometryFromDictionary(o[0],a.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof e))throw new t(a,n.InvalidParameter,i);l=r.parseAttributesFromDictionary(o[1])}c=r.createFromGraphicLikeObject(s,l,null,a.timeZone)}else{let s=null;const l={};if(null!==o[0])if(o[0]instanceof z)s=o[0];else{if(!(s instanceof e))throw new t(a,n.InvalidParameter,i);s=r.parseGeometryFromDictionary(o[0],a.spatialReference)}for(let e=1;e<o.length;e+=2){const r=w(o[e]),s=o[e+1];if(!(null==s||h(s)||isNaN(s)||d(s)||y(s)||R(s)||g(s)||I(s)))throw new t(a,n.InvalidParameter,i);if(v(s)||!1===P(s))throw new t(a,n.InvalidParameter,i);l[r]=s===p?null:s}c=r.createFromGraphicLikeObject(s,l,null,a.timeZone)}return c._geometry=f(c.geometry(),a.spatialReference),c.immutable=!1,c}))},a.dictionary=function(r,a){return A(r,a,((i,s,f)=>{if(0===f.length||1===f.length&&null===f[0]){const t=new e;return t.immutable=!1,t}if(1===f.length&&h(f[0]))try{const t=JSON.parse(f[0]),n=e.convertObjectToArcadeDictionary(t,b(r),!1);return n.immutable=!1,n}catch(P){throw new t(r,n.InvalidParameter,a)}if(1===f.length&&f[0]instanceof z)try{const t=f[0].toJSON();t.hasZ=!0===f[0].hasZ,t.hasM=!0===f[0].hasM;const n=e.convertObjectToArcadeDictionary(t,b(r),!1);return n.immutable=!1,n}catch(P){throw new t(r,n.InvalidParameter,a)}if(1===f.length&&m(f[0]))try{const t=new e;t.immutable=!1,t.setField("geometry",f[0].geometry());const n=new e;n.immutable=!1,t.setField("attributes",n);for(const e of f[0].keys())n.setField(e,f[0].field(e));return t}catch(P){throw new t(r,n.InvalidParameter,a)}if(1===f.length&&f[0]instanceof e)try{const t=new e;t.immutable=!1;for(const e of f[0].keys())t.setField(e,f[0].field(e));return t}catch(P){throw new t(r,n.InvalidParameter,a)}if(2===f.length&&f[0]instanceof e&&I(f[1]))try{if(!(!0===f[1])){const t=new e;t.immutable=!1;for(const e of f[0].keys())t.setField(e,f[0].field(e));return t}return f[0].deepClone()}catch(P){throw new t(r,n.InvalidParameter,a)}if(f.length%2!=0)throw new t(r,n.WrongNumberOfParameters,a);const c={};for(let e=0;e<f.length;e+=2){const i=w(f[e]),s=f[e+1];if(!(null==s||h(s)||isNaN(s)||d(s)||y(s)||I(s)||g(s)||R(s)||l(s)||o(s)))throw new t(r,n.InvalidParameter,a);if(v(s))throw new t(r,n.InvalidParameter,a);c[i]=s===p?null:s}const u=new e(c);return u.immutable=!1,u}))},a.haskey=function(r,a){return A(r,a,((i,l,o)=>{s(o,2,2,r,a);const f=w(o[1]);if(m(o[0]))return o[0].hasField(f);if(o[0]instanceof e)return o[0].hasField(f);if(o[0]instanceof z){const e=q(o[0],f,null,null,2);return!e||"notfound"!==e.keystate}throw new t(r,n.InvalidParameter,a)}))},a.hasvalue=function(r,a){return A(r,a,((i,f,c)=>{if(s(c,2,2,r,a),l(c[1])||o(c[1])){const i=c[1];let s=[];if(o(i))s=i.toArray();else{if(!l(i))throw new t(r,n.InvalidParameter,a);s=i}let f=c[0];if(null===f)return!1;for(const t of s)if(m(f)){if(!1===h(t))return!1;if(!f.hasField(t))return!1;if(f=f.field(t),null===f)return!1}else if(f instanceof e){if(!1===h(t))return!1;if(!f.hasField(t))return!1;if(f=f.field(t),null===f)return!1}else if(f instanceof z){if(!1===h(t))return!1;if(f=q(f,t,null,null,0),null===f)return!1}else if(l(f)){if(!1===y(t))return!1;if(f=f[t],null==f)return!1}else{if(!o(f))return!1;if(!1===y(t))return!1;if(f=f.get(t),null==f)return!1}return!0}if(null===c[0]||null===c[1])return!1;const u=w(c[1]);if(m(c[0]))return!!c[0].hasField(u)&&null!==c[0].field(u);if(c[0]instanceof e)return!!c[0].hasField(u)&&null!==c[0].field(u);if(c[0]instanceof z){return null!==q(c[0],u,null,null,0)}return!1}))},a.indexof=function(e,r){return A(e,r,((a,i,f)=>{s(f,2,2,e,r);const c=f[1];if(l(f[0])){for(let e=0;e<f[0].length;e++)if(F(c,f[0][e]))return e;return-1}if(o(f[0])){const e=f[0].length();for(let t=0;t<e;t++)if(F(c,f[0].get(t)))return t;return-1}throw new t(e,n.InvalidParameter,r)}))},a.angle=function(e,r){return A(e,r,((a,i,l)=>{if(l=u(l),s(l,2,3,e,r),!(l[0]instanceof G))throw new t(e,n.InvalidParameter,r);if(!(l[1]instanceof G))throw new t(e,n.InvalidParameter,r);if(l.length>2&&!(l[2]instanceof G))throw new t(e,n.InvalidParameter,r);return 2===l.length?O(l[0],l[1]):S(l[0],l[1],l[2])}))},a.bearing=function(e,r){return A(e,r,((a,i,l)=>{if(l=u(l),s(l,2,3,e,r),!(l[0]instanceof G))throw new t(e,n.InvalidParameter,r);if(!(l[1]instanceof G))throw new t(e,n.InvalidParameter,r);if(l.length>2&&!(l[2]instanceof G))throw new t(e,n.InvalidParameter,r);return 2===l.length?j(l[0],l[1]):N(l[0],l[1],l[2])}))},a.isselfintersecting=function(e,t){return A(e,t,((n,r,a)=>{a=u(a),s(a,1,1,e,t);let i=a[0];if(i instanceof Z)return i.isSelfIntersecting;if(i instanceof _)return k(i.paths);if(i instanceof D){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(l(i)||o(i)){const t=x(i,e.spatialReference);return null!==t&&(i=t.paths),k(i)}return!1}))}}let W=0;function q(r,s,l,o,f=1){let c;switch(s=s.toLowerCase()){case"hasz":{const e=r.hasZ;return void 0!==e&&e}case"hasm":{const e=r.hasM;return void 0!==e&&e}case"spatialreference":{let t=r.spatialReference._arcadeCacheId;if(void 0===t){let e=!0;Object.freeze&&Object.isFrozen(r.spatialReference)&&(e=!1),e&&(W++,r.spatialReference._arcadeCacheId=W,t=W)}const n=new e({wkt:r.spatialReference.wkt,wkid:r.spatialReference.wkid});return void 0!==t&&(n._arcadeCacheId="SPREF"+t.toString()),n}}switch(r.type){case"extent":switch(s){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const e=r[s];return void 0!==e?e:null}case"type":return"Extent"}break;case"polygon":switch(s){case"rings":c=r.cache._arcadeCacheId,void 0===c&&(W++,c=W,r.cache._arcadeCacheId=c);return new a(r.rings,r.spatialReference,!0===r.hasZ,!0===r.hasM,c);case"type":return"Polygon"}break;case"point":switch(s){case"x":case"y":case"z":case"m":return r[s]??null;case"type":return"Point"}break;case"polyline":switch(s){case"paths":c=r.cache._arcadeCacheId,void 0===c&&(W++,c=W,r.cache._arcadeCacheId=c);return new a(r.paths,r.spatialReference,!0===r.hasZ,!0===r.hasM,c);case"type":return"Polyline"}break;case"multipoint":switch(s){case"points":c=r.cache._arcadeCacheId,void 0===c&&(W++,c=W,r.cache._arcadeCacheId=c);return new i(r.points,r.spatialReference,!0===r.hasZ,!0===r.hasM,c,1);case"type":return"Multipoint"}}if(1===f)throw new t(l,n.InvalidIdentifier,o);return 2===f?{keystate:"notfound"}:null}export{q as geometryMember,A as registerFunctions};
5
+ import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a}from"../executionError.js";import i from"../Feature.js";import o from"../ImmutablePointArray.js";import{H as l,o as s,q as f,x as c,S as m,I as u,r as p,B as h,c as w,j as y,k as R,b as g,n as d,m as P,a as I,i as v,f as b,N as F,F as O,L as S}from"../../chunks/languageUtils.js";import{angle2D as N,angleBetween2D as j,bearing2D as x,bearingBetween2D as J,pathsSelfIntersecting as D}from"./centroid.js";import G from"../../geometry/Extent.js";import k from"../../geometry/Geometry.js";import Z from"../../geometry/Multipoint.js";import z from"../../geometry/Point.js";import W from"../../geometry/Polygon.js";import q from"../../geometry/Polyline.js";import{isClockwise as A}from"../../geometry/support/coordsUtils.js";import{fromJSON as M}from"../../geometry/support/jsonUtils.js";function L(L,U){L.ringisclockwise=function(e,t){return U(e,t,((n,i,c)=>{l(c,1,1,e,t);let m=[];if(null===c[0])return!1;if(s(c[0]))for(const o of c[0]){if(!(o instanceof z))throw new r(e,a.InvalidParameter,t);m.push(o.hasZ?o.hasM?[o.x,o.y,o.z,o.m]:[o.x,o.y,o.z]:[o.x,o.y])}else if(c[0]instanceof o)m=c[0]._elements;else{if(!f(c[0]))throw new r(e,a.InvalidParameter,t);for(const n of c[0].toArray()){if(!(n instanceof z))throw new r(e,a.InvalidParameter,t);m.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(m.length<3)&&A(m)}))},L.polygon=function(e,t){return U(e,t,((o,s,f)=>{let u;if(l(f,1,1,e,t),f[0]instanceof n){const n=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);if(n instanceof W==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(f[0]instanceof W)u=M(f[0].toJSON());else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=c(new W(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(u)}))},L.polyline=function(e,t){return U(e,t,((o,s,f)=>{let u;if(l(f,1,1,e,t),f[0]instanceof n){const n=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);if(n instanceof q==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(f[0]instanceof q)u=M(f[0].toJSON());else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=c(new q(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(u)}))},L.point=function(e,t){return U(e,t,((o,s,f)=>{let u;if(l(f,1,1,e,t),f[0]instanceof n){const n=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);if(n instanceof z==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(f[0]instanceof z)u=M(f[0].toJSON());else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=c(new z(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(u)}))},L.multipoint=function(e,t){return U(e,t,((o,s,f)=>{let u;if(l(f,1,1,e,t),f[0]instanceof n){const n=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);if(n instanceof Z==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(f[0]instanceof Z)u=M(f[0].toJSON());else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=c(new Z(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(u)}))},L.extent=function(e,t){return U(e,t,((o,s,f)=>{f=u(f),l(f,1,1,e,t);let p=null;if(f[0]instanceof n)p=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);else if(f[0]instanceof z){const e={xmin:f[0].x,ymin:f[0].y,xmax:f[0].x,ymax:f[0].y,spatialReference:f[0].spatialReference.toJSON()},t=f[0];t.hasZ?(e.zmin=t.z,e.zmax=t.z):t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=M(e)}else if(f[0]instanceof W)p=M(f[0].extent?.toJSON());else if(f[0]instanceof q)p=M(f[0].extent?.toJSON());else if(f[0]instanceof Z)p=M(f[0].extent?.toJSON());else if(f[0]instanceof G)p=M(f[0].toJSON());else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=c(new G(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(p)}))},L.geometry=function(e,t){return U(e,t,((o,s,f)=>{l(f,1,1,e,t);let u=null;if(null===f[0])return null;if(p(f[0]))u=c(f[0].geometry(),e.spatialReference);else if(f[0]instanceof n)u=c(i.parseGeometryFromDictionary(f[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(f[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=c(M(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return m(u)}))},L.setgeometry=function(e,t){return U(e,t,((n,i,o)=>{if(l(o,2,2,e,t),!p(o[0]))throw new r(e,a.InvalidParameter,t);if(!0===o[0].immutable)throw new r(e,a.Immutable,t);if(!(o[1]instanceof k||null===o[1]))throw new r(e,a.InvalidParameter,t);return o[0]._geometry=o[1],h}))},L.feature=function(e,t){return U(e,t,((o,l,s)=>{if(0===s.length)throw new r(e,a.WrongNumberOfParameters,t);let f;if(1===s.length)if(w(s[0]))f=i.fromJson(JSON.parse(s[0]),e.timeZone);else if(p(s[0]))f=i.createFromArcadeFeature(s[0]);else if(s[0]instanceof k)f=i.createFromGraphicLikeObject(s[0],null,null,e.timeZone);else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof n&&(t=i.parseGeometryFromDictionary(t,e.spatialReference)),null!==r&&(r=i.parseAttributesFromDictionary(r)),f=i.createFromGraphicLikeObject(t,r,null,e.timeZone)}}else if(2===s.length){let o=null,l=null;if(null!==s[0])if(s[0]instanceof k)o=s[0];else{if(!(o instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}if(null!==s[1]){if(!(s[1]instanceof n))throw new r(e,a.InvalidParameter,t);l=i.parseAttributesFromDictionary(s[1])}f=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}else{let o=null;const l={};if(null!==s[0])if(s[0]instanceof k)o=s[0];else{if(!(o instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}for(let n=1;n<s.length;n+=2){const i=y(s[n]),o=s[n+1];if(!(null==o||w(o)||isNaN(o)||R(o)||g(o)||d(o)||P(o)||I(o)))throw new r(e,a.InvalidParameter,t);if(v(o)||!1===b(o))throw new r(e,a.InvalidParameter,t);l[i]=o===h?null:o}f=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}return f._geometry=c(f.geometry(),e.spatialReference),f.immutable=!1,f}))},L.dictionary=function(e,t){return U(e,t,((i,o,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&w(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,F(e),!1);return r.immutable=!1,r}catch(u){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof k)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,F(e),!1);return r.immutable=!1,r}catch(u){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&p(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(u){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof n)try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(u){throw new r(e,a.InvalidParameter,t)}if(2===l.length&&l[0]instanceof n&&I(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(u){throw new r(e,a.InvalidParameter,t)}if(l.length%2!=0)throw new r(e,a.WrongNumberOfParameters,t);const c={};for(let n=0;n<l.length;n+=2){const i=y(l[n]),o=l[n+1];if(!(null==o||w(o)||isNaN(o)||R(o)||g(o)||I(o)||P(o)||d(o)||s(o)||f(o)))throw new r(e,a.InvalidParameter,t);if(v(o))throw new r(e,a.InvalidParameter,t);c[i]=o===h?null:o}const m=new n(c);return m.immutable=!1,m}))},L.haskey=function(t,i){return U(t,i,((o,s,f)=>{l(f,2,2,t,i);const c=y(f[1]);if(p(f[0]))return f[0].hasField(c);if(f[0]instanceof n)return f[0].hasField(c);if(f[0]instanceof k){const t=e(f[0],c,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,a.InvalidParameter,i)}))},L.hasvalue=function(e,n){return U(e,n,((r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1]))))},L.indexof=function(e,t){return U(e,t,((n,i,o)=>{l(o,2,2,e,t);const c=o[1];if(s(o[0])){for(let e=0;e<o[0].length;e++)if(O(c,o[0][e]))return e;return-1}if(f(o[0])){const e=o[0].length();for(let t=0;t<e;t++)if(O(c,o[0].get(t)))return t;return-1}throw new r(e,a.InvalidParameter,t)}))},L.angle=function(e,t){return U(e,t,((n,i,o)=>{if(o=u(o),l(o,2,3,e,t),!(o[0]instanceof z))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof z))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof z))throw new r(e,a.InvalidParameter,t);return 2===o.length?N(o[0],o[1]):j(o[0],o[1],o[2])}))},L.bearing=function(e,t){return U(e,t,((n,i,o)=>{if(o=u(o),l(o,2,3,e,t),!(o[0]instanceof z))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof z))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof z))throw new r(e,a.InvalidParameter,t);return 2===o.length?x(o[0],o[1]):J(o[0],o[1],o[2])}))},L.isselfintersecting=function(e,t){return U(e,t,((n,r,a)=>{a=u(a),l(a,1,1,e,t);let i=a[0];if(i instanceof W)return i.isSelfIntersecting;if(i instanceof q)return D(i.paths);if(i instanceof Z){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(s(i)||f(i)){const t=S(i,e.spatialReference);return null!==t&&(i=t.paths),D(i)}return!1}))}}export{L as registerFunctions};
package/arcade.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"./Graphic.js";import{ArcadeDate as t}from"./arcade/ArcadeDate.js";import r from"./arcade/ImmutableArray.js";import a from"./core/Error.js";import{clone as n}from"./core/lang.js";import{DateOnly as o}from"./core/sql/DateOnly.js";import{TimeOnly as s}from"./core/sql/TimeOnly.js";import c from"./layers/FeatureLayer.js";import i from"./portal/Portal.js";import l from"./rest/support/FeatureSet.js";import{loadArcade as u}from"./support/arcadeOnDemand.js";let p=null;function f(e,t,a,n={}){const o=t.elementType,s="value",c="array"===o.type?[{name:s,type:o.type,elementType:o.elementType}]:"dictionary"===o.type?[{name:s,type:o.type,properties:o.properties}]:[{name:s,type:o.type}];return new r(e.map((e=>{const t={};return b(t,c,{[s]:e},a,n),t[s]})))}function m(e,t,r={}){const a=e instanceof l?new c({source:e.features,geometryType:e.geometryType,fields:e.fields,spatialReference:e.spatialReference}):e;return t.constructFeatureSet(a,r.spatialReference,null,!0,r.lruCache,r.interceptor)}function y(e,t,r={}){const{spatialReference:a,interceptor:n,lruCache:o}=r;return"string"==typeof e?t.createFeatureSetCollectionFromService(e,a,o,n):t.createFeatureSetCollectionFromMap(e,a,o,n)}function d(e,t,r,a={}){const n={};return b(n,t.properties,e,r,a),new p.Dictionary(n)}function b(e,r,a,n,c={}){const i={};for(const t of Object.keys(a))i[t.toLowerCase()]=a[t];for(const l of r){const r=l.name.toLowerCase();if(c.variablesPreProcessed)e[r]=i[r];else switch(l.type){case"array":{const t=i[r];e[r]=null==t?null:f(t,l,n,c);break}case"feature":{const t=i[r];e[r]=null==t?null:p.Feature.createFromGraphic(t,c?.timeZone);break}case"featureSet":{const t=i[r];e[r]=null==t?null:n?m(t,n,c):null;break}case"featureSetCollection":{const t=i[r];e[r]=null==t?null:n?y(t,n,c):null;break}case"dictionary":{const t=i[r];e[r]=null==t?null:d(t,l,n,c);break}case"date":{const a=i[r];e[r]=a?a instanceof t?a:c?.timeZone?t.dateJSAndZoneToArcadeDate(a,c?.timeZone):t.dateJSToArcadeDate(a):null;break}case"dateOnly":{const t=i[r];e[r]=t?t instanceof o?t:o.fromReader(t):null;break}case"time":{const t=i[r];e[r]=t?t instanceof s?t:s.fromReader(t):null;break}case"knowledgeGraph":case"geometry":case"boolean":case"text":case"number":e[r]=i[r]}}}function S(e,t){for(const r of e)t.push(r),"dictionary"===r.type&&S(r.properties,t);return t}function v(e,t,r,a,n){const{spatialReference:o,interceptor:s,lruCache:c,console:l,abortSignal:u,timeZone:p,services:f={portal:i.getDefault()}}=r,m={vars:{},spatialReference:o,interceptor:s,timeZone:p,lrucache:c,useAsync:n,services:f,console:l,abortSignal:u};return t?(b(m.vars,e.variables,t,a,r),m):m}function g(t,r){switch(r.getArcadeType(t)){case"number":case"text":case"boolean":case"point":case"polygon":case"polyline":case"multipoint":case"extent":return t;case"date":return t.toJSDate();case"time":case"dateOnly":return t.toString();case"feature":{const r=(t.type,t),a="geometry"in r?r.geometry():null,n="readAttributes"in r?r.readAttributes():r.attributes;return new e({geometry:a,attributes:n})}case"dictionary":{const e=t,a=e.attributes,n={};for(const t of Object.keys(a))n[t]=g(e.field(t),r);return n}case"array":return("toArray"in t?t.toArray():t).map((e=>g(e,r)))}return t}const w={variables:[{name:"$feature",type:"feature"},{name:"$layer",type:"featureSet"},{name:"$datastore",type:"featureSetCollection"},{name:"$map",type:"featureSetCollection"},{name:"$userInput",type:"geometry"},{name:"$graph",type:"knowledgeGraph"}]},$={variables:[{name:"$feature",type:"feature"},{name:"$aggregatedFeatures",type:"featureSet"}]},h=new Map([["form-constraint",{variables:[{name:"$feature",type:"feature"}]}],["feature-z",{variables:[{name:"$feature",type:"feature"}]}],["field-calculation",{variables:[{name:"$feature",type:"feature"},{name:"$datastore",type:"featureSetCollection"}]}],["form-calculation",{variables:[{name:"$feature",type:"feature"},{name:"$originalFeature",type:"feature"},{name:"$layer",type:"featureSet"},{name:"$featureSet",type:"featureSet"},{name:"$datastore",type:"featureSetCollection"},{name:"$map",type:"featureSetCollection"},{name:"$editContext",type:"dictionary",properties:[{name:"editType",type:"text"}]}]}],["labeling",{variables:[{name:"$feature",type:"feature"}]}],["popup",w],["popup-element",w],["feature-reduction-popup",$],["feature-reduction-popup-element",$],["visualization",{variables:[{name:"$feature",type:"feature"},{name:"$view",type:"dictionary",properties:[{name:"scale",type:"number"}]}]}]]);function C(e){const t=h.get(e);if(!t){const t=Array.from(h.keys()).map((e=>`'${e}'`)).join(", ");throw new a("createArcadeProfile:invalid-profile-name",`Invalid profile name '${e}'. You must specify one of the following values: ${t}`)}return n(t)}async function A(e,t,r={}){p||(p=await u());const{arcade:n,arcadeUtils:o}=p,{loadScriptDependencies:s,referencesMember:c,scriptIsAsync:i}=n,l=S(t.variables,[]),f=l.filter((e=>"featureSet"===e.type||"featureSetCollection"===e.type)).map((e=>e.name.toLowerCase())),m=n.parseScript(e,f);if(!m)throw new a("arcade:invalid-script","Unable to create SyntaxTree");const y=o.extractFieldNames(m),d=n.scriptTouchesGeometry(m),b=l.map((e=>e.name.toLowerCase())).filter((e=>c(m,e))),w=i(m,f);await s(m,w,f);const $={vars:{},spatialReference:null,useAsync:w};for(const a of b)$.vars[a]="any";const{lruCache:h}=r,C=n.compileScript(m,$),A=n.featureSetUtils(),{services:j}=r;return{execute:(e,r={})=>{if(w)throw new a("arcade:invalid-execution-mode","Cannot execute the script in synchronous mode");const n=C(v(t,e,{lruCache:h,...r},A,w));return r.rawOutput?n:g(n,o)},executeAsync:async(e,r={})=>{const a=await C(v(t,e,{lruCache:h,services:j,...r},A,w));return r.rawOutput?a:g(a,o)},isAsync:w,variablesUsed:b,fieldsUsed:y,geometryUsed:d,syntaxTree:m}}export{A as createArcadeExecutor,C as createArcadeProfile};
5
+ import e from"./Graphic.js";import{ArcadeDate as t}from"./arcade/ArcadeDate.js";import r from"./arcade/ImmutableArray.js";import a from"./core/Error.js";import{clone as n}from"./core/lang.js";import{DateOnly as o}from"./core/sql/DateOnly.js";import{TimeOnly as s}from"./core/sql/TimeOnly.js";import c from"./layers/FeatureLayer.js";import i from"./portal/Portal.js";import l from"./rest/support/FeatureSet.js";import{loadArcade as u}from"./support/arcadeOnDemand.js";let p=null;function f(e,t,a,n={}){const o=t.elementType,s="value",c="array"===o.type?[{name:s,type:o.type,elementType:o.elementType}]:"dictionary"===o.type?[{name:s,type:o.type,properties:o.properties}]:[{name:s,type:o.type}];return new r(e.map((e=>{const t={};return b(t,c,{[s]:e},a,n),t[s]})))}function m(e,t,r={}){const a=e instanceof l?new c({source:e.features,geometryType:e.geometryType,fields:e.fields,spatialReference:e.spatialReference}):e;return t.constructFeatureSet(a,r.spatialReference,null,!0,r.lruCache,r.interceptor)}function y(e,t,r={}){const{spatialReference:a,interceptor:n,lruCache:o}=r;return"string"==typeof e?t.createFeatureSetCollectionFromService(e,a,o,n):t.createFeatureSetCollectionFromMap(e,a,o,n)}function d(e,t,r,a={}){const n={};return b(n,t.properties,e,r,a),new p.Dictionary(n)}function b(e,r,a,n,c={}){const i={};for(const t of Object.keys(a))i[t.toLowerCase()]=a[t];for(const l of r){const r=l.name.toLowerCase();if(c.variablesPreProcessed)e[r]=i[r];else switch(l.type){case"array":{const t=i[r];e[r]=null==t?null:f(t,l,n,c);break}case"feature":{const t=i[r];e[r]=null==t?null:p.Feature.createFromGraphic(t,c?.timeZone);break}case"featureSet":{const t=i[r];e[r]=null==t?null:n?m(t,n,c):null;break}case"featureSetCollection":{const t=i[r];e[r]=null==t?null:n?y(t,n,c):null;break}case"dictionary":{const t=i[r];e[r]=null==t?null:d(t,l,n,c);break}case"date":{const a=i[r];e[r]=a?a instanceof t?a:c?.timeZone?t.dateJSAndZoneToArcadeDate(a,c?.timeZone):t.dateJSToArcadeDate(a):null;break}case"dateOnly":{const t=i[r];e[r]=t?t instanceof o?t:o.fromReader(t):null;break}case"time":{const t=i[r];e[r]=t?t instanceof s?t:s.fromReader(t):null;break}case"knowledgeGraph":case"geometry":case"boolean":case"text":case"number":e[r]=i[r]}}}function v(e,t){for(const r of e)t.push(r),"dictionary"===r.type&&v(r.properties,t);return t}function S(e,t,r,a,n){const{spatialReference:o,interceptor:s,lruCache:c,console:l,abortSignal:u,timeZone:p,services:f={portal:i.getDefault()}}=r,m={vars:{},spatialReference:o,interceptor:s,timeZone:p,lrucache:c,useAsync:n,services:f,console:l,abortSignal:u};return t?(b(m.vars,e.variables,t,a,r),m):m}function g(t,r){switch(r.getArcadeType(t)){case"number":case"text":case"boolean":case"point":case"polygon":case"polyline":case"multipoint":case"extent":return t;case"date":return t.toJSDate();case"time":case"dateOnly":return t.toString();case"feature":{const r=(t.type,t),a="geometry"in r?r.geometry():null,n="readAttributes"in r?r.readAttributes():r.attributes;return new e({geometry:a,attributes:n})}case"dictionary":{const e=t,a=e.attributes,n={};for(const t of Object.keys(a))n[t]=g(e.field(t),r);return n}case"array":return("toArray"in t?t.toArray():t).map((e=>g(e,r)))}return t}const w={variables:[{name:"$feature",type:"feature"},{name:"$layer",type:"featureSet"},{name:"$datastore",type:"featureSetCollection"},{name:"$map",type:"featureSetCollection"},{name:"$userInput",type:"geometry"},{name:"$graph",type:"knowledgeGraph"}]},$={variables:[{name:"$feature",type:"feature"},{name:"$aggregatedFeatures",type:"featureSet"}]},h=new Map([["aggregate-field",{variables:[{name:"$feature",type:"feature"}]}],["form-constraint",{variables:[{name:"$feature",type:"feature"}]}],["feature-z",{variables:[{name:"$feature",type:"feature"}]}],["field-calculation",{variables:[{name:"$feature",type:"feature"},{name:"$datastore",type:"featureSetCollection"}]}],["form-calculation",{variables:[{name:"$feature",type:"feature"},{name:"$originalFeature",type:"feature"},{name:"$layer",type:"featureSet"},{name:"$featureSet",type:"featureSet"},{name:"$datastore",type:"featureSetCollection"},{name:"$map",type:"featureSetCollection"},{name:"$editContext",type:"dictionary",properties:[{name:"editType",type:"text"}]}]}],["labeling",{variables:[{name:"$feature",type:"feature"}]}],["popup",w],["popup-element",w],["feature-reduction-popup",$],["feature-reduction-popup-element",$],["visualization",{variables:[{name:"$feature",type:"feature"},{name:"$view",type:"dictionary",properties:[{name:"scale",type:"number"}]}]}]]);function C(e){const t=h.get(e);if(!t){const t=Array.from(h.keys()).map((e=>`'${e}'`)).join(", ");throw new a("createArcadeProfile:invalid-profile-name",`Invalid profile name '${e}'. You must specify one of the following values: ${t}`)}return n(t)}async function A(e,t,r={}){p||(p=await u());const{arcade:n,arcadeUtils:o}=p,{loadScriptDependencies:s,referencesMember:c,scriptIsAsync:i}=n,l=v(t.variables,[]),f=l.filter((e=>"featureSet"===e.type||"featureSetCollection"===e.type)).map((e=>e.name.toLowerCase())),m=n.parseScript(e,f);if(!m)throw new a("arcade:invalid-script","Unable to create SyntaxTree");const y=o.extractFieldNames(m),d=n.scriptTouchesGeometry(m),b=l.map((e=>e.name.toLowerCase())).filter((e=>c(m,e))),w=i(m,f);await s(m,w,f);const $={vars:{},spatialReference:null,useAsync:w};for(const a of b)$.vars[a]="any";const{lruCache:h}=r,C=n.compileScript(m,$),A=n.featureSetUtils(),{services:j}=r;return{execute:(e,r={})=>{if(w)throw new a("arcade:invalid-execution-mode","Cannot execute the script in synchronous mode");const n=C(S(t,e,{lruCache:h,...r},A,w));return r.rawOutput?n:g(n,o)},executeAsync:async(e,r={})=>{const a=await C(S(t,e,{lruCache:h,services:j,...r},A,w));return r.rawOutput?a:g(a,o)},isAsync:w,variablesUsed:b,fieldsUsed:y,geometryUsed:d,syntaxTree:m}}export{A as createArcadeExecutor,C as createArcadeProfile};