@arcgis/core 4.27.0-next.20230419 → 4.27.0-next.20230421

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 (203) hide show
  1. package/WebMap.js +1 -1
  2. package/WebScene.js +1 -1
  3. package/arcade/arcadeAsyncRuntime.js +1 -1
  4. package/arcade/arcadeCompiler.js +1 -1
  5. package/arcade/arcadeRuntime.js +1 -1
  6. package/arcade/executionError.js +1 -1
  7. package/assets/esri/core/workers/RemoteClient.js +1 -1
  8. package/assets/esri/core/workers/chunks/{f64f95623d9296a91f95.js → 059ec6fd9b971de4b4c1.js} +1 -1
  9. package/assets/esri/core/workers/chunks/0d805fd9cd9ff3a636ca.js +1 -0
  10. package/assets/esri/core/workers/chunks/{1fe31a412479815e5e2d.js → 10770939900946feb20d.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{5252f3cc244204edc299.js → 1216e939d363f96b6cc6.js} +1 -1
  12. package/assets/esri/core/workers/chunks/156dad2b7fed6749bae7.js +1 -0
  13. package/assets/esri/core/workers/chunks/15a97d3e42b00ac42984.js +1 -0
  14. package/assets/esri/core/workers/chunks/{d72c0c97cc4e30f1e4f2.js → 18704903814b9d73c708.js} +1 -1
  15. package/assets/esri/core/workers/chunks/1db5e4c8244dbc21590c.js +1 -0
  16. package/assets/esri/core/workers/chunks/2a1a5a1969e80a10dcca.js +1 -0
  17. package/assets/esri/core/workers/chunks/33b735faa582e6f39e9a.js +1 -0
  18. package/assets/esri/core/workers/chunks/34025ac04ca02531923a.js +1 -0
  19. package/assets/esri/core/workers/chunks/3e9f3479fd8558d9e3e3.js +1 -0
  20. package/assets/esri/core/workers/chunks/{d59274ac695dfcff1143.js → 46090b69e9161bc05141.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{f7aa972cb3903847b3bf.js → 47bf38d910e71ac39bb8.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{3978f4f68ada540ee3a3.js → 4f8a09b61267e5e26712.js} +1 -1
  23. package/assets/esri/core/workers/chunks/5183ecab7eddae7b70e8.js +1 -0
  24. package/assets/esri/core/workers/chunks/{a5c33b24b7ee042cb473.js → 51a0d1dabe7415515c77.js} +2 -2
  25. package/assets/esri/core/workers/chunks/541e6efc3b491e507410.js +1 -0
  26. package/assets/esri/core/workers/chunks/588256e65685ff21d2e9.js +1 -0
  27. package/assets/esri/core/workers/chunks/5c64fd3bf057a1a5527f.js +1 -0
  28. package/assets/esri/core/workers/chunks/6047bdaf4855506f8fdb.js +1 -0
  29. package/assets/esri/core/workers/chunks/6adb58f1bffc5d1c03bd.js +1 -0
  30. package/assets/esri/core/workers/chunks/770940417e6ddbdbb9d6.js +1 -0
  31. package/assets/esri/core/workers/chunks/{1c1d8be85297c483a606.js → 77c98121223a144170e3.js} +1 -1
  32. package/assets/esri/core/workers/chunks/80117007d86be4eb3bc3.js +1 -0
  33. package/assets/esri/core/workers/chunks/812cba53143565a825f1.js +1 -0
  34. package/assets/esri/core/workers/chunks/838849b751805615833a.js +1 -0
  35. package/assets/esri/core/workers/chunks/{9ca395f7bc8d397b5240.js → 88197520501fcc20b6e8.js} +1 -1
  36. package/assets/esri/core/workers/chunks/88f9dededcf60fd011ef.js +1 -0
  37. package/assets/esri/core/workers/chunks/88fdd288ef799a7ac48a.js +1 -0
  38. package/assets/esri/core/workers/chunks/8ae7fea9f7fda38dd207.js +1 -0
  39. package/assets/esri/core/workers/chunks/{0d080dd1ca6a71597409.js → 9265d4e9cfab2c7bbce5.js} +1 -1
  40. package/assets/esri/core/workers/chunks/{8d41305509fedb3603ac.js → 94041a9ced04aa281d40.js} +1 -1
  41. package/assets/esri/core/workers/chunks/98540791fcef86069e44.js +1 -0
  42. package/assets/esri/core/workers/chunks/9c1b2f82877ff79969f5.js +1 -0
  43. package/assets/esri/core/workers/chunks/a7b3cd537c9127b5e65e.js +1 -0
  44. package/assets/esri/core/workers/chunks/{3d1c697182237807ab49.js → abea316f2eac0f3086ab.js} +1 -1
  45. package/assets/esri/core/workers/chunks/ad85ade6a2cfb56cf328.js +1 -0
  46. package/assets/esri/core/workers/chunks/b833b4ea2973bb16792e.js +1 -0
  47. package/assets/esri/core/workers/chunks/be4aa835a7abfc809126.js +1 -0
  48. package/assets/esri/core/workers/chunks/c2ec6e904f96173a7b83.js +1 -0
  49. package/assets/esri/core/workers/chunks/{c25aa08b869f2777dc26.js → c4488a8d857c765da30e.js} +1 -1
  50. package/assets/esri/core/workers/chunks/c5c56b6d99db96a6755a.js +2 -0
  51. package/assets/esri/core/workers/chunks/{7f3b0856f594df2b044e.js → c727d38f71e52bee17e1.js} +1 -1
  52. package/assets/esri/core/workers/chunks/cf315d255f0dc8d50f21.js +1 -0
  53. package/assets/esri/core/workers/chunks/cf7676fdc09ad4835680.js +1 -0
  54. package/assets/esri/core/workers/chunks/cfad34c949cbe8a31ef8.js +1 -0
  55. package/assets/esri/core/workers/chunks/{edb4568fe281b5609092.js → d244e50c981146f018d2.js} +1 -1
  56. package/assets/esri/core/workers/chunks/{a2c9cb23f3e35e88da1d.js → d399b1b9cbf0737d1735.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{df7dcd035997881cf2ef.js → d5c8119d6d34628d3126.js} +1 -1
  58. package/assets/esri/core/workers/chunks/d6b6bb8aecc85d2a3f6b.js +1 -0
  59. package/assets/esri/core/workers/chunks/{8dfa32cc8453f85faab0.js → dd1f8bade9c5c3b7929b.js} +1 -1
  60. package/assets/esri/core/workers/chunks/e11e60759821746259c6.js +1 -0
  61. package/assets/esri/core/workers/chunks/{e4b65c5a4575a5c1c49f.js → e356c576f9a7521a49b3.js} +1 -1
  62. package/assets/esri/core/workers/chunks/f02edf71645eb33bf92f.js +1 -0
  63. package/assets/esri/core/workers/chunks/f1a4165c2710ca90e5ea.js +1 -0
  64. package/assets/esri/core/workers/chunks/f57a3ee17869ced3dd33.js +1 -0
  65. package/assets/esri/core/workers/chunks/fc07f6e103d7f69a9909.js +1 -0
  66. package/chunks/WaterSurface.glsl.js +35 -20
  67. package/chunks/index.js +1 -1
  68. package/core/Loadable.js +1 -1
  69. package/core/Promise.js +1 -1
  70. package/core/accessorSupport/ensureType.js +1 -1
  71. package/core/accessorSupport/watch.js +1 -1
  72. package/core/accessorSupport/write.js +1 -1
  73. package/core/promiseUtils.js +1 -1
  74. package/core/watchUtils.js +1 -1
  75. package/core/workers/Connection.js +1 -1
  76. package/core/workers/RemoteClient.js +1 -1
  77. package/core/workers/workerFactory.js +1 -1
  78. package/geometry/support/geodesicUtils.js +1 -1
  79. package/geometry/support/meshUtils/External.js +1 -1
  80. package/geometry/support/meshUtils/Metadata.js +1 -1
  81. package/intl/messages.js +1 -1
  82. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  83. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  84. package/layers/graphics/data/attributeSupport.js +1 -1
  85. package/layers/graphics/sources/FeatureLayerSource.js +1 -1
  86. package/layers/mixins/ArcGISMapService.js +1 -1
  87. package/layers/support/PromiseQueue.js +1 -1
  88. package/layers/support/Sublayer.js +1 -1
  89. package/layers/support/TileKey.js +1 -1
  90. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  91. package/networks/Network.js +1 -1
  92. package/package.json +1 -1
  93. package/portal/schemas/definitions.js +1 -1
  94. package/renderers/support/RasterSymbolizer.js +1 -1
  95. package/renderers/support/rasterRendererChecks.js +5 -0
  96. package/renderers/support/rasterRendererHelper.js +1 -1
  97. package/request.js +1 -1
  98. package/rest/query/operations/query.js +1 -1
  99. package/smartMapping/raster/renderers/uniqueValue.js +1 -1
  100. package/support/featureFlags.js +1 -1
  101. package/support/revision.js +1 -1
  102. package/symbols/support/previewSymbol3D.js +1 -1
  103. package/symbols/support/styleUtils.js +1 -1
  104. package/symbols/support/symbolLayerUtils.js +1 -1
  105. package/symbols/support/utils.js +1 -1
  106. package/symbols/support/webStyleSymbolUtils.js +1 -1
  107. package/views/2d/engine/webgl/TextureManager.js +1 -1
  108. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  109. package/views/2d/layers/features/controllers/FeatureController2D.js +1 -1
  110. package/views/2d/layers/features/sources/DataTileSource.js +1 -1
  111. package/views/2d/layers/features/sources/DataTileSubscription.js +1 -1
  112. package/views/2d/layers/features/sources/DrillDownFeatureSource.js +1 -1
  113. package/views/2d/layers/features/sources/PagedFeatureSource.js +1 -1
  114. package/views/2d/layers/features/support/FeatureSetReaderPBFHeader.js +1 -1
  115. package/views/2d/layers/features/tileRenderers/HeatmapTileRenderer.js +1 -1
  116. package/views/2d/layers/features/tileRenderers/SymbolTileRenderer.js +1 -1
  117. package/views/2d/layers/features/tileRenderers.js +1 -1
  118. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  119. package/views/2d/layers/support/webStyleUtils.js +1 -1
  120. package/views/3d/input/SceneInputManager.js +1 -1
  121. package/views/3d/interactive/manipulatorUtils.js +1 -1
  122. package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
  123. package/views/3d/layers/GraphicsView3D.js +1 -1
  124. package/views/3d/layers/I3SMeshView3D.js +1 -1
  125. package/views/3d/layers/graphics/ElevationQuery.js +1 -1
  126. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  127. package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
  128. package/views/3d/layers/graphics/Graphics3DWaterSymbolLayer.js +1 -1
  129. package/views/3d/layers/graphics/polygonUtils.js +1 -1
  130. package/views/3d/layers/graphics/symbolComplexity.js +1 -1
  131. package/views/3d/layers/graphics/webStyleUtils.js +5 -0
  132. package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
  133. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  134. package/views/3d/layers/i3s/I3SOverrides.js +1 -1
  135. package/views/3d/webgl-engine/materials/WaterMaterial.js +1 -1
  136. package/views/3d/webgl-engine/materials/WaterTechnique.js +1 -1
  137. package/views/3d/webgl-engine/shaders/WaterSurface.glsl.js +1 -1
  138. package/views/LayerViewManager.js +1 -1
  139. package/views/PopupView.js +1 -1
  140. package/views/SceneView.js +1 -1
  141. package/views/ViewAnimation.js +1 -1
  142. package/views/input/BrowserEventSource.js +1 -1
  143. package/views/input/InputManager.js +1 -1
  144. package/views/interactive/coordinateHelper.js +1 -1
  145. package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceSnappingSourceWorker.js +1 -1
  146. package/views/layers/support/MapServiceLayerViewHelper.js +1 -1
  147. package/views/support/QueueProcessor.js +1 -1
  148. package/views/ui/DefaultUI.js +1 -1
  149. package/views/ui/UI.js +1 -1
  150. package/widgets/BasemapGallery/support/PortalBasemapsSource.js +1 -1
  151. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  152. package/widgets/Editor/Upload.js +1 -1
  153. package/widgets/Editor/deprecationUtils.js +1 -1
  154. package/widgets/Editor/modelUploadUtils.js +1 -1
  155. package/widgets/Editor.js +1 -1
  156. package/widgets/Feature/FeatureExpression/FeatureExpressionViewModel.js +1 -1
  157. package/widgets/Feature/FeatureRelationship/FeatureRelationshipViewModel.js +1 -1
  158. package/widgets/Feature/FeatureViewModel.js +1 -1
  159. package/widgets/Feature/support/featureUtils.js +1 -1
  160. package/widgets/FeatureTable/Grid/Grid.js +1 -1
  161. package/widgets/Popup.js +1 -1
  162. package/widgets/support/decorators/accessibleHandler.js +1 -1
  163. package/assets/esri/core/workers/chunks/0948a40569b2408edefb.js +0 -1
  164. package/assets/esri/core/workers/chunks/192e3eeed50768c77c65.js +0 -1
  165. package/assets/esri/core/workers/chunks/1d1b9856f2f44d0c2144.js +0 -1
  166. package/assets/esri/core/workers/chunks/203115cc836e7b364eec.js +0 -1
  167. package/assets/esri/core/workers/chunks/20ad44b1a7adfed4c6c4.js +0 -1
  168. package/assets/esri/core/workers/chunks/27353056c3e4e8d8b8d3.js +0 -1
  169. package/assets/esri/core/workers/chunks/41ae9037c70461d5fdc7.js +0 -1
  170. package/assets/esri/core/workers/chunks/4b6a903d4aeeb4eeb615.js +0 -1
  171. package/assets/esri/core/workers/chunks/4bf9bc8b52d618f395c5.js +0 -1
  172. package/assets/esri/core/workers/chunks/5ec4fedbbcbb0053cf74.js +0 -2
  173. package/assets/esri/core/workers/chunks/60e29d172a2dcf45e8d0.js +0 -1
  174. package/assets/esri/core/workers/chunks/68a15cc7c51645d31572.js +0 -1
  175. package/assets/esri/core/workers/chunks/6b065e581bcf743079cf.js +0 -1
  176. package/assets/esri/core/workers/chunks/6c54579981a7bd483f1a.js +0 -1
  177. package/assets/esri/core/workers/chunks/778ecf61f07dafc51bbc.js +0 -1
  178. package/assets/esri/core/workers/chunks/7da1fd3629362b81b43c.js +0 -1
  179. package/assets/esri/core/workers/chunks/80d335bec34d60b7bbdc.js +0 -1
  180. package/assets/esri/core/workers/chunks/810da30f13151b72a293.js +0 -1
  181. package/assets/esri/core/workers/chunks/81485a5056aed94b3d8d.js +0 -1
  182. package/assets/esri/core/workers/chunks/8374d89e995f0d15c042.js +0 -1
  183. package/assets/esri/core/workers/chunks/8ebda132068f6b962dd9.js +0 -1
  184. package/assets/esri/core/workers/chunks/8f553ae2f1aba4e0371f.js +0 -1
  185. package/assets/esri/core/workers/chunks/8fec9979ae2b0e3a878f.js +0 -1
  186. package/assets/esri/core/workers/chunks/979ea2e3b1b164334634.js +0 -1
  187. package/assets/esri/core/workers/chunks/a0e92dd27c8f6b642dbf.js +0 -1
  188. package/assets/esri/core/workers/chunks/a6240bf258b3886a6661.js +0 -1
  189. package/assets/esri/core/workers/chunks/b059cd03f31ead61abb4.js +0 -1
  190. package/assets/esri/core/workers/chunks/b1a8024bf8cdd0cd3884.js +0 -1
  191. package/assets/esri/core/workers/chunks/b366e0db9b5f27dd53a3.js +0 -1
  192. package/assets/esri/core/workers/chunks/b976d5599672665561ec.js +0 -1
  193. package/assets/esri/core/workers/chunks/c260ac058e63a5c0cf60.js +0 -1
  194. package/assets/esri/core/workers/chunks/c646dc9da08b509e39d6.js +0 -1
  195. package/assets/esri/core/workers/chunks/db5598944b691e43f13e.js +0 -1
  196. package/assets/esri/core/workers/chunks/eb163a2ddeb27c690308.js +0 -1
  197. package/assets/esri/core/workers/chunks/eec12b5666819bf2119d.js +0 -1
  198. package/assets/esri/core/workers/chunks/ef05496c1faf08d247f1.js +0 -1
  199. package/assets/esri/core/workers/chunks/f05634909c9449533193.js +0 -1
  200. package/assets/esri/core/workers/chunks/fcebd70b089dea833c75.js +0 -1
  201. package/views/layers/GraphicsView.js +0 -5
  202. /package/assets/esri/core/workers/chunks/{a5c33b24b7ee042cb473.js.LICENSE.txt → 51a0d1dabe7415515c77.js.LICENSE.txt} +0 -0
  203. /package/assets/esri/core/workers/chunks/{5ec4fedbbcbb0053cf74.js.LICENSE.txt → c5c56b6d99db96a6755a.js.LICENSE.txt} +0 -0
package/WebMap.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.27/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import{isSome as o}from"./core/arrayUtils.js";import a from"./core/Collection.js";import s from"./core/Error.js";import n from"./core/Loadable.js";import{loadAll as l}from"./core/loadAll.js";import p from"./core/Logger.js";import{MultiOriginJSONMixin as m,MultiOriginJSONSupport as u}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as h}from"./core/Promise.js";import{eachAlways as c}from"./core/promiseUtils.js";import{whenOnce as d}from"./core/reactiveUtils.js";import{urlToObject as y,hasSameCanonicalArcGISOnlinePortal as w,isDataProtocol as f,dataComponents as g,addQueryParameter as b}from"./core/urlUtils.js";import{property as _}from"./core/accessorSupport/decorators/property.js";import"./core/accessorSupport/ensureType.js";import"./core/has.js";import{reader as v}from"./core/accessorSupport/decorators/reader.js";import{subclass as A}from"./core/accessorSupport/decorators/subclass.js";import{writer as I}from"./core/accessorSupport/decorators/writer.js";import{updateOrigins as S}from"./core/accessorSupport/originUtils.js";import{readLoadable as j}from"./core/accessorSupport/read.js";import U from"./geometry/SpatialReference.js";import{equals as P}from"./geometry/support/spatialReferenceUtils.js";import{geographicToWebMercator as O,webMercatorToGeographic as L}from"./geometry/support/webMercatorUtils.js";import{isServerOrServicesAGOLUrl as R}from"./layers/support/arcgisLayerUrl.js";import{isFeatureServiceLayer as V,isFeatureCollectionLayer as F}from"./layers/support/layerUtils.js";import T from"./networks/UtilityNetwork.js";import W from"./portal/Portal.js";import k from"./portal/PortalItem.js";import{removeTypeKeyword as N,addTypeKeyword as E,hasTypeKeyword as C,TypeKeyword as M}from"./portal/support/portalItemUtils.js";import{project as x}from"./rest/geometryService/project.js";import B from"./rest/support/ProjectParameters.js";import{hasDeveloperBasemapLayer as J,isDeveloperBasemapLayer as G,findSpatialReference as D}from"./support/basemapUtils.js";import K from"./support/MapFloorInfo.js";import $ from"./webdoc/GeotriggersInfo.js";import z from"./webdoc/RangeInfo.js";import q from"./webdoc/Widgets.js";import{getOptimalThumbnailSize as H}from"./webdoc/support/thumbnailUtils.js";import{getLayerJSON as Q}from"./webdoc/support/writeUtils.js";import X from"./webmap/ApplicationProperties.js";import Y from"./webmap/Bookmark.js";import Z from"./webmap/InitialViewProperties.js";import{Version as ee}from"./webmap/Version.js";import te from"./webmap/background/ColorBackground.js";const re=new ee(2,27),ie="Web Map",oe=a.ofType(Y),ae=a.ofType(T),se=new Map;se.set("image/jpeg","jpeg"),se.set("image/jpg","jpg"),se.set("image/png","png"),se.set("image/gif","gif");const ne="ArcGIS Pro",le=M.JSAPI,pe="CollectorDisabled",me="Collector",ue="Data Editing",he="OfflineDisabled",ce="Offline",de="Workforce Project",ye="Workforce Worker",we="Workforce Dispatcher",fe="Offline Map Areas",ge="FieldMapsDisabled",be=M.DEVELOPER_BASEMAP,_e="UtilityNetwork",ve=["NatGeo_World_Map","Ocean_Basemap","USA_Topo_Maps","World_Imagery","World_Street_Map","World_Terrain_Base","World_Topo_Map","World_Hillshade","Canvas/World_Light_Gray_Base","Canvas/World_Light_Gray_Reference","Canvas/World_Dark_Gray_Base","Canvas/World_Dark_Gray_Reference","Ocean/World_Ocean_Base","Ocean/World_Ocean_Reference","Reference/World_Boundaries_and_Places","Reference/World_Reference_Overlay","Reference/World_Transportation"].map((e=>e.toLowerCase()));let Ae=class extends(m(n.LoadableMixin(h(r)))){constructor(e){super(e),this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1,this._thumbnailFilename=null,this._updateFromPromise=null,this._resourceReferences={portalItem:null,paths:[]},this.applicationProperties=null,this.bookmarks=new oe,this.floorInfo=null,this.geotriggersInfo=null,this.initialViewProperties=new Z,this.portalItem=null,this.presentation=null,this.sourceVersion=null,this.widgets=null,this.utilityNetworks=null,this.authoringApp=this.authoringAppVersion=null,this._isAuthoringAppSetByUser=this._isAuthoringAppVersionSetByUser=!1}destroy(){const e=this.portalItem;this.portalItem=null,e?.destroy()}initialize(){if(this.when().catch((e=>{p.getLogger(this.declaredClass).error("#load()","Failed to load web map",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t)}}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp=le}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}readInitialViewProperties(e,t){const r=new Z;t.background&&(r.background=te.fromJSON(t.background));const o=t.initialState?.viewpoint;if(o){if(o.rotation){ee.parse(t.version||"","webmap").lessThan(2,20)&&t.authoringApp===ne&&(o.rotation*=-1)}r.viewpoint=i.fromJSON(o)}return t.mapRangeInfo&&(r.rangeInfo=z.fromJSON(t.mapRangeInfo)),t.spatialReference&&(r.spatialReference=U.fromJSON(t.spatialReference)),r}writeInitialViewProperties(e,t,r,i){if(!e)return;const o=e.background;o&&o.color&&(t.background=o.write({},i)),e.viewpoint&&(t.initialState={viewpoint:e.viewpoint.write({},i)}),e.rangeInfo&&(t.mapRangeInfo=e.rangeInfo.toJSON(i)),e.spatialReference&&(t.spatialReference=e.spatialReference.write({},i))}writeLayers(e,t,r,i){t[r]=this._writeLayers(e,i,"operational-layers")}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new ee(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${re.major}.${re.minor}`}writeTables(e,t,r,i){const o=this._writeLayers(e,i,"tables");o.length&&(t[r]=o)}get thumbnailUrl(){return this.portalItem&&this.portalItem.thumbnailUrl||null}set thumbnailUrl(e){e?(this._override("thumbnailUrl",e),this._thumbnailFilename=this._generateCustomThumbnailFilename(e)):this._clearThumbnailOverride()}load(e){return this.addResolvingPromise(this._loadFromSource()),Promise.resolve(this)}loadAll(){return l(this,(e=>{e(this.ground,this.basemap,this.layers,this.tables)}))}read(e,t){t={...t,origin:"web-map"};const r=this._getAuthoringPropsState();j(this,e,(t=>super.read(e,t)),t),this._restoreAuthoringPropsFromState(r)}write(e,t){if("loaded"!==this.loadStatus){const e=new s("webmap:not-loaded","Web map must be loaded before it can be serialized");throw p.getLogger(this.declaredClass).error("#toJSON()","Web map must be loaded before it can be serialized",this.loadError||this.loadStatus),e}return this._removeDanglingLayerRefs(),t={...t,origin:"web-map",restrictedWebMapWriting:!0,webmap:this},super.write(e,t)}async save(e){e=e||{},this._validateItem();const t=import("./webdoc/support/saveUtils.js");await this._updateFromPromise,await this.load(),await this._loadLayerContainers(),await this._beforeSave(),await this._validateMap();const r=this.portalItem,i=y(r.itemUrl),o={origin:"web-map",messages:[],writtenProperties:[],url:i,portal:r.portal||W.getDefault(),portalItem:r,verifyItemRelativeUrls:i?{rootPath:i.path,writtenUrls:[]}:null,blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}},a=this.write({},o);return await Promise.all(o.resources.pendingOperations),this._validateJSONForWriting(o,e),await this._updateItemProperties(r),await this._updateItem(r,a,o),await Promise.all([this._updateItemThumbnail(),t.then((({saveResources:e})=>e(this._resourceReferences,o,null)))]),r}async saveAs(e,t){t=t||{};const r=this._getPortalItem(e),i=import("./webdoc/support/saveUtils.js");await this._updateFromPromise,await this.load(),await this._loadLayerContainers(),await this._beforeSave(),await this._validateMap();const o={origin:"web-map",messages:[],writtenProperties:[],url:null,portal:r.portal,portalItem:r,blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}},a=this.write({},o);await Promise.all(o.resources.pendingOperations),this._validateJSONForWriting(o,t),await this._updateItemPropertiesForSaveAs(r);const s=this._getThumbnailState();return await this._createItem(r,a,o,t)&&(this._resourceReferences.portalItem=r),this._restoreThumbnailFromState(s),await Promise.all([this._updateItemThumbnail(),i.then((({saveResources:e})=>e(this._resourceReferences,o,null)))]),r}async updateFrom(e,t){const r=this._updateFromInternal(e,t);this._updateFromPromise=r,await r;r===this._updateFromPromise&&(this._updateFromPromise=null)}getLayerJSONFromResourceInfo(e){const t=this.resourceInfo;return this._collectAllLayersJSON([...t?.baseMap?.baseMapLayers||[],...t?.operationalLayers||[],...this.basemap?.resourceInfo?.data?.baseMapLayers||[]]).find((t=>t.id===e.id))}_collectAllLayersJSON(e){return e.reduce(((e,t)=>(e.push(t),"GroupLayer"===t.layerType&&(e=e.concat(this._collectAllLayersJSON(t.layers||[]))),e)),[])}_writeLayers(e,t,r){t={...t,layerContainerType:r};return e.map((e=>Q(e,"tables"===r?null:this.getLayerJSONFromResourceInfo(e),t))).filter(o).toArray()}_loadFromSource(){return this.resourceInfo?this._loadFromJSON(this.resourceInfo,{origin:"web-map"}):this.portalItem&&this.portalItem.id?this._loadFromItem(this.portalItem):Promise.resolve()}async _loadFromItem(e){if(await e.load().catch((e=>{throw new s("webmap:load-portal-item","Failed to load portal item",{error:e})})),"Web Map"!==e.type)throw new s("webmap:invalid-portal-item",`Invalid portal item type '${e.type}', expected 'Web Map'`,{type:e.type});const t=await e.fetchData();this.resourceInfo=t;const r={origin:"web-map",url:y(e.itemUrl),portal:e.portal||W.getDefault(),portalItem:e,readResourcePaths:[]};return await this._readAndLoadFromJSON(t,r),this._resourceReferences={portalItem:e,paths:r.readResourcePaths??[]},this._computeInitialViewpoint()}_readAndLoadFromJSON(e,t){const r=this._validateJSON(e);return this.read(r,t),this._loadFromJSON(r,t)}_validateJSON(e){const t=ee.parse(e.version||"","webmap");return re.validate(t),e.version=`${t.major}.${t.minor}`,e}_loadFromJSON(e,t){const r={context:{...t,layerContainerType:"operational-layers"}};return this.portalItem&&(r.context.portal=this.portalItem.portal||W.getDefault()),import("./layers/support/layersCreator.js").then((({populateOperationalLayers:t})=>{const i=[],o=e.operationalLayers;o&&o.length&&i.push(t(this.layers,o,r));const a={...r,context:{...r.context,layerContainerType:"tables"},defaultLayerType:"ArcGISFeatureLayer"},s=e.tables;return s&&s.length&&i.push(t(this.tables,s,a)),c(i).then((()=>{}))}))}async _computeInitialViewpoint(){let e=this.initialViewProperties;const t=e?.viewpoint?.targetGeometry;if(t)return;const r=await this._getExtentFromItem();r&&(e=e?e.clone():new Z,e.viewpoint=new i,e.viewpoint.targetGeometry=r,this.initialViewProperties=e)}async _getExtentFromItem(){const e=this.initialViewProperties?.spatialReference,t=this.portalItem?.extent;if(e&&t){if(e.isWGS84)return t.clone();if(e.isWebMercator)return O(t);return(await import("./portal/support/geometryServiceUtils.js")).getGeometryServiceURL(this.portalItem).then((r=>{const i=new B;return i.geometries=[t],i.outSpatialReference=e,x(r,i)})).then((e=>e[0])).catch((e=>(p.getLogger(this.declaredClass).error("Error projecting item's extent:",e),null)))}return null}_removeDanglingLayerRefs(){const e=this.applicationProperties,t=e&&e.viewing&&e.viewing.search,r=e=>this.allLayers.some((t=>t.id===e));t&&t.layers&&(t.layers=t.layers.filter((e=>r(e.id)))),t&&t.tables&&(t.tables=t.tables.filter((e=>this.tables.some((t=>t.id===e.id)))));const i=e&&e.editing&&e.editing.locationTracking;i&&i.info&&!r(i.info.layerId)&&(e.editing=null);const o=this.presentation&&this.presentation.slides;o&&o.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>r(e.id))))}))}async _validateMap(){if(!this.basemap?.baseLayers.length)throw new s("webmap:save","Map does not have a valid basemap with a base layer.");let e=null;if(await d((()=>{const t=D(this.initialViewProperties,this.basemap);return e=t.spatialReference,!t.updating})),!P(e,this.initialViewProperties.spatialReference))throw new s("webmap:save","The spatial reference of the basemap is not compatible with the one from the map.",{expected:this.initialViewProperties.spatialReference,actual:e})}_validateItem(){if(!this.portalItem)throw p.getLogger(this.declaredClass).error("save: requires the portalItem property to be set"),new s("webmap:portal-item-not-set","Portal item to save to has not been set on the WebMap");this._validateItemType(this.portalItem)}_validateItemType(e){if(e.type!==ie)throw new s("webmap:portal-item-wrong-type",`Portal item needs to have type "${ie}"`)}_loadLayerContainers(){const e=[];return this.basemap&&e.push(this.basemap.load()),this.ground&&e.push(this.ground.load()),c(e).then((()=>{}))}async _beforeSave(){const e=[];for(const t of this.allLayers)if("beforeSave"in t&&"function"==typeof t.beforeSave){const r=t.beforeSave();r&&e.push(r)}await c(e)}_loadAllLayers(){const e=this._getAllLayersAndTables().map((e=>e.load()));return c(e).then((()=>{}))}_getAllLayersAndTables(){return this.allLayers.concat(this.allTables)}_validateJSONForWriting(e,t){let r=(e.messages??[]).filter((e=>"error"===e.type)).map((e=>new s(e.name,e.message,e.details)));if(e.blockedRelativeUrls&&(r=r.concat(e.blockedRelativeUrls.map((e=>new s("url:unsupported",`Relative url '${e}' is not supported in Web Map`))))),t.ignoreUnsupported&&(r=r.filter((e=>"layer:unsupported"!==e.name&&"symbol:unsupported"!==e.name&&"symbol-layer:unsupported"!==e.name&&"property:unsupported"!==e.name&&"url:unsupported"!==e.name))),r.length>0)throw new s("webmap:save","Failed to save webmap due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:r})}async _updateItemProperties(e){e.extent=await this._getWGS84Extent(this.initialViewProperties.viewpoint.targetGeometry),await this._updateTypeKeywords(e)}async _updateItemPropertiesForSaveAs(e){N(e,pe),N(e,ge),N(e,M.METADATA),N(e,he),N(e,fe),N(e,we),N(e,de),N(e,ye),await this._updateItemProperties(e)}async _getWGS84Extent(e){const t=e.clone().normalize();let r;if(t.length>1)for(const i of t)r?i.width>r.width&&(r=i):r=i;else r=t[0];return this._projectToWGS84(r)}async _projectToWGS84(e){const t=e.spatialReference;if(t.isWGS84)return e.clone();if(t.isWebMercator)return L(e);const r=await import("./portal/support/geometryServiceUtils.js"),i=await r.getGeometryServiceURL(this.portalItem),o=new B;o.geometries=[e],o.outSpatialReference=U.WGS84;return(await x(i,o))[0]}async _updateTypeKeywords(e){E(e,le),await this._loadAllLayers(),this._evalCollectorKeyword(e),this._evalDataEditingKeyword(e),this._evalOfflineKeyword(e),this._evalDeveloperBasemapKeyword(e),this._evalUtilityNetworkKeyword(e),e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter(((e,t,r)=>r.indexOf(e)===t)))}_evalCollectorKeyword(e){C(e,pe)||C(e,de)||C(e,ye)||C(e,we)||!this._hasEditableFeatureLayer()?N(e,me):E(e,me)}_evalDataEditingKeyword(e){this._hasEditableFeatureLayer()?E(e,ue):N(e,ue)}_evalOfflineKeyword(e){!C(e,he)&&this._isOfflineCapableMap()?E(e,ce):N(e,ce)}_evalDeveloperBasemapKeyword(e){J(this.basemap)?E(e,be):N(e,be)}_evalUtilityNetworkKeyword(e){this.utilityNetworks?.length?E(e,_e):N(e,_e)}_hasEditableFeatureLayer(){return this._getAllLayersAndTables().some((e=>e.loaded&&V(e)&&e.capabilities.operations.supportsEditing&&e.editingEnabled))}_isOfflineCapableMap(){return this._getAllLayersAndTables().filter((e=>"group"!==e.type)).every((e=>e.loaded&&this._isOfflineCapableLayer(e)))}_isFeatureCollectionLike(e){return F(e)||"map-notes"===e.type||"route"===e.type}_isOfflineCapableLayer(e){return V(e)&&e.capabilities.operations.supportsSync||this._isFeatureCollectionLike(e)&&!e.portalItem||("tile"===e.type||"vector-tile"===e.type)&&(e.capabilities.operations.supportsExportTiles||this._isExportableAGOLTileLayer(e)||G(e))&&e.spatialReference.equals(this.initialViewProperties.spatialReference)}_isExportableAGOLTileLayer(e){return"tile"===e.type&&(R(e.url)&&ve.some((t=>e.url?.toLowerCase().includes("/"+t+"/"))))}async _updateItem(e,t,r){await e.update({data:t}),this._syncUpInstanceWithItem(e,t,r)}async _createItem(e,t,r,i){const o=this.portalItem,a={item:o,authenticated:!(!o?.id||!o.portal.user)},n=e.portal;await n.signIn();const{copyAllowed:l,itemReloaded:p}=await this._isCopyAllowed(a,n);if(a.authenticated||(a.authenticated=p),!l)throw new s("webmap:save-as-copy-not-allowed","Owner of this map does not allow others to save a copy");const m=await this._initializeNewItem(e,a,t,i);return this.portalItem=e,this._syncUpInstanceWithItem(e,t,r),m}async _isCopyAllowed(e,t){const{item:r,authenticated:i}=e;return r?.id&&r.typeKeywords?.includes("useOnly")?r.portal.portalHostname!==t.portalHostname?{copyAllowed:!1,itemReloaded:!1}:(i||await r.reload(),{copyAllowed:"admin"===r.itemControl||"update"===r.itemControl,itemReloaded:!0}):{copyAllowed:!0,itemReloaded:!1}}async _initializeNewItem(e,t,r,i){const o=e.portal,{item:a,authenticated:s}=t,{folder:n,copyAllResources:l}=i;let p=!1;if(l&&a?.id&&w(a.portal.url,o.url)&&(s||await a.reload(),a.isOrgItem)){const{total:e}=await a.fetchResources();p=!!e}if(p){const t=await a.copy({copyResources:"all",folder:n});e.id=t.id,e.portal=t.portal;const i=e.toJSON();await e.load(),e.read(i),await e.update({data:r})}else await(o.user?.addItem({item:e,folder:n,data:r}));return p}_syncUpInstanceWithItem(e,t,r){u.prototype.read.call(this,{version:t.version,authoringApp:t.authoringApp,authoringAppVersion:t.authoringAppVersion},{origin:"web-map",ignoreDefaults:!0,url:e.itemUrl&&y(e.itemUrl)}),S(r),this.resourceInfo=t}async _updateItemThumbnail(){this.thumbnailUrl&&this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl,filename:this._thumbnailFilename})),this._clearThumbnailOverride())}_getPortalItem(e){let t=k.from(e);return t.id&&(t=t.clone(),t.id=null),t.type||(t.type=ie),t.portal||(t.portal=W.getDefault()),this._validateItemType(t),t}async _updateFromInternal(e,t){if(t=t||{},await d((()=>e.ready)),this._updateInitialViewProperties(e,t),e.map===this)for(const r of e.allLayerViews)"visible"in r&&"visible"in r.layer&&r._isOverridden("visible")&&(r.layer.visible=r.visible),"featureEffect"in r&&"featureEffect"in r.layer&&r._isOverridden("featureEffect")&&(r.layer.featureEffect=r.featureEffect);await this._updateThumbnailUrl(e,t)}_updateInitialViewProperties(e,t){if(t.backgroundExcluded||(this.initialViewProperties.background=e.background?.clone()),this.initialViewProperties.spatialReference=e.spatialReference?.clone(),t.viewpointExcluded||(this.initialViewProperties.viewpoint=new i({rotation:e.rotation,scale:t.scalePreserved?e.scale:null,targetGeometry:this._getViewExtent(e)})),!t.widgetsExcluded)for(const r of e.persistableViewModels)r.updateWebDocument(this)}_getViewExtent(e){const t=e.center.clone().normalize(),r=e.extent.clone(),i=r.width/2;return r.xmin=t.x-i,r.xmax=t.x+i,r}async _updateThumbnailUrl(e,t){if(t.thumbnailExcluded)return;const r=H(e,t.thumbnailSize),i=await e.takeScreenshot({format:"png",width:r.width,height:r.height});this._setAutoGeneratedThumbnail(i.dataUrl)}_setAutoGeneratedThumbnail(e){this.thumbnailUrl=e,this._thumbnailFilename=null}_clearThumbnailOverride(){this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"),this._thumbnailFilename=null}_generateCustomThumbnailFilename(e){if(f(e)){const t=g(e),r=t&&t.mediaType,i=r&&se.get(r.toLowerCase())||null,o=`thumbnail${Date.now()}`;return i?`${o}.${i}`:o}return null}_getThumbnailState(){let e=this.thumbnailUrl;return e&&(e=this._isOverridden("thumbnailUrl")?e:b(e,"w","8192")),{thumbnailUrl:e,filename:this._thumbnailFilename}}_restoreThumbnailFromState(e){this.thumbnailUrl=e.thumbnailUrl,this._thumbnailFilename=e.filename}_getAuthoringPropsState(){return{authoringApp:this.authoringApp,authoringAppVersion:this.authoringAppVersion,isAuthoringAppSetByUser:this._isAuthoringAppSetByUser,isAuthoringAppVersionSetByUser:this._isAuthoringAppVersionSetByUser}}_restoreAuthoringPropsFromState(e){e.isAuthoringAppSetByUser?this.authoringApp=e.authoringApp:this._isAuthoringAppSetByUser=!1,e.isAuthoringAppVersionSetByUser?this.authoringAppVersion=e.authoringAppVersion:this._isAuthoringAppVersionSetByUser=!1}static fromJSON(e){const t=e;if(!t)throw new s("webmap:empty-resource","Expected a JSON resource but got nothing");return new this({resourceInfo:t})}};Ae.VERSION=re,e([_({type:X,json:{write:!0}})],Ae.prototype,"applicationProperties",void 0),e([_({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],Ae.prototype,"authoringApp",null),e([I("authoringApp")],Ae.prototype,"writeAuthoringApp",null),e([_({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],Ae.prototype,"authoringAppVersion",null),e([I("authoringAppVersion")],Ae.prototype,"writeAuthoringAppVersion",null),e([_({json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],Ae.prototype,"basemap",void 0),e([_({type:oe,json:{write:{overridePolicy:e=>({enabled:!!(e&&e.length>0),ignoreOrigin:!0})}}})],Ae.prototype,"bookmarks",void 0),e([_({type:K,json:{read:{source:"mapFloorInfo"},write:{target:"mapFloorInfo"}}})],Ae.prototype,"floorInfo",void 0),e([_({type:$,json:{write:!0}})],Ae.prototype,"geotriggersInfo",void 0),e([_({type:Z,nonNullable:!0,json:{read:{source:["background","initialState.viewpoint","mapRangeInfo","spatialReference"]},write:{ignoreOrigin:!0,target:{background:{type:te},"initialState.viewpoint":{type:i},mapRangeInfo:{type:z},spatialReference:{type:U}}}}})],Ae.prototype,"initialViewProperties",void 0),e([v("initialViewProperties")],Ae.prototype,"readInitialViewProperties",null),e([I("initialViewProperties")],Ae.prototype,"writeInitialViewProperties",null),e([_({json:{read:!1,write:{target:"operationalLayers",ignoreOrigin:!0}}})],Ae.prototype,"layers",void 0),e([I("layers")],Ae.prototype,"writeLayers",null),e([_({type:k})],Ae.prototype,"portalItem",void 0),e([_({json:{write:!0}})],Ae.prototype,"presentation",void 0),e([_()],Ae.prototype,"resourceInfo",void 0),e([_({readOnly:!0,type:ee,json:{read:{source:"version"},write:{allowNull:!0,ignoreOrigin:!0,target:"version",isRequired:!0}}})],Ae.prototype,"sourceVersion",void 0),e([v("sourceVersion")],Ae.prototype,"readSourceVersion",null),e([I("sourceVersion")],Ae.prototype,"writeSourceVersion",null),e([_({json:{read:!1,write:{ignoreOrigin:!0}}})],Ae.prototype,"tables",void 0),e([I("tables")],Ae.prototype,"writeTables",null),e([_()],Ae.prototype,"thumbnailUrl",null),e([_({type:q,json:{write:!0}})],Ae.prototype,"widgets",void 0),e([_({type:ae,json:{read:!0,write:!0}})],Ae.prototype,"utilityNetworks",void 0),Ae=e([A("esri.WebMap")],Ae);const Ie=Ae;export{Ie as default};
5
+ import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import{isSome as o}from"./core/arrayUtils.js";import a from"./core/Collection.js";import s from"./core/Error.js";import n from"./core/Loadable.js";import{loadAll as l}from"./core/loadAll.js";import p from"./core/Logger.js";import{MultiOriginJSONMixin as m,MultiOriginJSONSupport as u}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as h}from"./core/Promise.js";import{eachAlways as c}from"./core/promiseUtils.js";import{whenOnce as d}from"./core/reactiveUtils.js";import{urlToObject as y,hasSameCanonicalArcGISOnlinePortal as w,isDataProtocol as f,dataComponents as g,addQueryParameter as b}from"./core/urlUtils.js";import{property as _}from"./core/accessorSupport/decorators/property.js";import"./core/accessorSupport/ensureType.js";import"./core/has.js";import{reader as v}from"./core/accessorSupport/decorators/reader.js";import{subclass as A}from"./core/accessorSupport/decorators/subclass.js";import{writer as I}from"./core/accessorSupport/decorators/writer.js";import{updateOrigins as S}from"./core/accessorSupport/originUtils.js";import{readLoadable as j}from"./core/accessorSupport/read.js";import U from"./geometry/SpatialReference.js";import{equals as P}from"./geometry/support/spatialReferenceUtils.js";import{geographicToWebMercator as O,webMercatorToGeographic as L}from"./geometry/support/webMercatorUtils.js";import{isServerOrServicesAGOLUrl as R}from"./layers/support/arcgisLayerUrl.js";import{isFeatureServiceLayer as V,isFeatureCollectionLayer as F}from"./layers/support/layerUtils.js";import T from"./networks/UtilityNetwork.js";import W from"./portal/Portal.js";import k from"./portal/PortalItem.js";import{removeTypeKeyword as N,addTypeKeyword as E,hasTypeKeyword as C,TypeKeyword as M}from"./portal/support/portalItemUtils.js";import{project as x}from"./rest/geometryService/project.js";import B from"./rest/support/ProjectParameters.js";import{hasDeveloperBasemapLayer as J,isDeveloperBasemapLayer as G,findSpatialReference as D}from"./support/basemapUtils.js";import K from"./support/MapFloorInfo.js";import $ from"./webdoc/GeotriggersInfo.js";import z from"./webdoc/RangeInfo.js";import q from"./webdoc/Widgets.js";import{getOptimalThumbnailSize as H}from"./webdoc/support/thumbnailUtils.js";import{getLayerJSON as Q}from"./webdoc/support/writeUtils.js";import X from"./webmap/ApplicationProperties.js";import Y from"./webmap/Bookmark.js";import Z from"./webmap/InitialViewProperties.js";import{Version as ee}from"./webmap/Version.js";import te from"./webmap/background/ColorBackground.js";const re=new ee(2,27),ie="Web Map",oe=a.ofType(Y),ae=a.ofType(T),se=new Map;se.set("image/jpeg","jpeg"),se.set("image/jpg","jpg"),se.set("image/png","png"),se.set("image/gif","gif");const ne="ArcGIS Pro",le=M.JSAPI,pe="CollectorDisabled",me="Collector",ue="Data Editing",he="OfflineDisabled",ce="Offline",de="Workforce Project",ye="Workforce Worker",we="Workforce Dispatcher",fe="Offline Map Areas",ge="FieldMapsDisabled",be=M.DEVELOPER_BASEMAP,_e="UtilityNetwork",ve=["NatGeo_World_Map","Ocean_Basemap","USA_Topo_Maps","World_Imagery","World_Street_Map","World_Terrain_Base","World_Topo_Map","World_Hillshade","Canvas/World_Light_Gray_Base","Canvas/World_Light_Gray_Reference","Canvas/World_Dark_Gray_Base","Canvas/World_Dark_Gray_Reference","Ocean/World_Ocean_Base","Ocean/World_Ocean_Reference","Reference/World_Boundaries_and_Places","Reference/World_Reference_Overlay","Reference/World_Transportation"].map((e=>e.toLowerCase()));let Ae=class extends(m(n.LoadableMixin(h(r)))){constructor(e){super(e),this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1,this._thumbnailFilename=null,this._updateFromPromise=null,this._resourceReferences={portalItem:null,paths:[]},this.applicationProperties=null,this.bookmarks=new oe,this.floorInfo=null,this.geotriggersInfo=null,this.initialViewProperties=new Z,this.portalItem=null,this.presentation=null,this.sourceVersion=null,this.widgets=null,this.utilityNetworks=null,this.authoringApp=this.authoringAppVersion=null,this._isAuthoringAppSetByUser=this._isAuthoringAppVersionSetByUser=!1}destroy(){const e=this.portalItem;this.portalItem=null,e?.destroy()}initialize(){if(this.when().catch((e=>{p.getLogger(this.declaredClass).error("#load()","Failed to load web map",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t)}}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp=le}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}readInitialViewProperties(e,t){const r=new Z;t.background&&(r.background=te.fromJSON(t.background));const o=t.initialState?.viewpoint;if(o){if(o.rotation){ee.parse(t.version||"","webmap").lessThan(2,20)&&t.authoringApp===ne&&(o.rotation*=-1)}r.viewpoint=i.fromJSON(o)}return t.mapRangeInfo&&(r.rangeInfo=z.fromJSON(t.mapRangeInfo)),t.spatialReference&&(r.spatialReference=U.fromJSON(t.spatialReference)),r}writeInitialViewProperties(e,t,r,i){if(!e)return;const o=e.background;o&&o.color&&(t.background=o.write({},i)),e.viewpoint&&(t.initialState={viewpoint:e.viewpoint.write({},i)}),e.rangeInfo&&(t.mapRangeInfo=e.rangeInfo.toJSON(i)),e.spatialReference&&(t.spatialReference=e.spatialReference.write({},i))}writeLayers(e,t,r,i){t[r]=this._writeLayers(e,i,"operational-layers")}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new ee(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${re.major}.${re.minor}`}writeTables(e,t,r,i){const o=this._writeLayers(e,i,"tables");o.length&&(t[r]=o)}get thumbnailUrl(){return this.portalItem&&this.portalItem.thumbnailUrl||null}set thumbnailUrl(e){e?(this._override("thumbnailUrl",e),this._thumbnailFilename=this._generateCustomThumbnailFilename(e)):this._clearThumbnailOverride()}load(e){return this.addResolvingPromise(this._loadFromSource()),Promise.resolve(this)}loadAll(){return l(this,(e=>{e(this.ground,this.basemap,this.layers,this.tables)}))}read(e,t){t={...t,origin:"web-map"};const r=this._getAuthoringPropsState();j(this,e,(t=>super.read(e,t)),t),this._restoreAuthoringPropsFromState(r)}write(e,t){if("loaded"!==this.loadStatus){const e=new s("webmap:not-loaded","Web map must be loaded before it can be serialized");throw p.getLogger(this.declaredClass).error("#toJSON()","Web map must be loaded before it can be serialized",this.loadError||this.loadStatus),e}return this._removeDanglingLayerRefs(),t={...t,origin:"web-map",restrictedWebMapWriting:!0,webmap:this},super.write(e,t)}async save(e){e=e||{},this._validateItem();const t=import("./webdoc/support/saveUtils.js");await this._updateFromPromise,await this.load(),await this._loadLayerContainers(),await this._beforeSave(),await this._validateMap();const r=this.portalItem,i=y(r.itemUrl),o={origin:"web-map",messages:[],writtenProperties:[],url:i,portal:r.portal||W.getDefault(),portalItem:r,verifyItemRelativeUrls:i?{rootPath:i.path,writtenUrls:[]}:null,blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}},a=this.write({},o);return await Promise.all(o.resources.pendingOperations),this._validateJSONForWriting(o,e),await this._updateItemProperties(r),await this._updateItem(r,a,o),await Promise.all([this._updateItemThumbnail(),t.then((({saveResources:e})=>e(this._resourceReferences,o,null)))]),r}async saveAs(e,t){t=t||{};const r=this._getPortalItem(e),i=import("./webdoc/support/saveUtils.js");await this._updateFromPromise,await this.load(),await this._loadLayerContainers(),await this._beforeSave(),await this._validateMap();const o={origin:"web-map",messages:[],writtenProperties:[],url:null,portal:r.portal,portalItem:r,blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}},a=this.write({},o);await Promise.all(o.resources.pendingOperations),this._validateJSONForWriting(o,t),await this._updateItemPropertiesForSaveAs(r);const s=this._getThumbnailState();return await this._createItem(r,a,o,t)&&(this._resourceReferences.portalItem=r),this._restoreThumbnailFromState(s),await Promise.all([this._updateItemThumbnail(),i.then((({saveResources:e})=>e(this._resourceReferences,o,null)))]),r}async updateFrom(e,t){const r=this._updateFromInternal(e,t);this._updateFromPromise=r,await r;r===this._updateFromPromise&&(this._updateFromPromise=null)}getLayerJSONFromResourceInfo(e){const t=this.resourceInfo;return this._collectAllLayersJSON([...t?.baseMap?.baseMapLayers||[],...t?.operationalLayers||[],...this.basemap?.resourceInfo?.data?.baseMapLayers||[]]).find((t=>t.id===e.id))}_collectAllLayersJSON(e){return e.reduce(((e,t)=>(e.push(t),"GroupLayer"===t.layerType&&(e=e.concat(this._collectAllLayersJSON(t.layers||[]))),e)),[])}_writeLayers(e,t,r){t={...t,layerContainerType:r};return e.map((e=>Q(e,"tables"===r?null:this.getLayerJSONFromResourceInfo(e),t))).filter(o).toArray()}_loadFromSource(){return this.resourceInfo?this._loadFromJSON(this.resourceInfo,{origin:"web-map"}):this.portalItem&&this.portalItem.id?this._loadFromItem(this.portalItem):Promise.resolve()}async _loadFromItem(e){if(await e.load().catch((e=>{throw new s("webmap:load-portal-item","Failed to load portal item",{error:e})})),"Web Map"!==e.type)throw new s("webmap:invalid-portal-item",`Invalid portal item type '${e.type}', expected 'Web Map'`,{type:e.type});const t=await e.fetchData();this.resourceInfo=t;const r={origin:"web-map",url:y(e.itemUrl),portal:e.portal||W.getDefault(),portalItem:e,readResourcePaths:[]};return await this._readAndLoadFromJSON(t,r),this._resourceReferences={portalItem:e,paths:r.readResourcePaths??[]},this._computeInitialViewpoint()}_readAndLoadFromJSON(e,t){const r=this._validateJSON(e);return this.read(r,t),this._loadFromJSON(r,t)}_validateJSON(e){const t=ee.parse(e.version||"","webmap");return re.validate(t),e.version=`${t.major}.${t.minor}`,e}_loadFromJSON(e,t){const r={context:{...t,layerContainerType:"operational-layers"}};return this.portalItem&&(r.context.portal=this.portalItem.portal||W.getDefault()),import("./layers/support/layersCreator.js").then((({populateOperationalLayers:t})=>{const i=[],o=e.operationalLayers;o&&o.length&&i.push(t(this.layers,o,r));const a={...r,context:{...r.context,layerContainerType:"tables"},defaultLayerType:"ArcGISFeatureLayer"},s=e.tables;return s&&s.length&&i.push(t(this.tables,s,a)),c(i).then((()=>{}))}))}async _computeInitialViewpoint(){let e=this.initialViewProperties;const t=e?.viewpoint?.targetGeometry;if(t)return;const r=await this._getExtentFromItem();r&&(e=e?e.clone():new Z,e.viewpoint=new i,e.viewpoint.targetGeometry=r,this.initialViewProperties=e)}async _getExtentFromItem(){const e=this.initialViewProperties?.spatialReference,t=this.portalItem?.extent;if(e&&t){if(e.isWGS84)return t.clone();if(e.isWebMercator)return O(t);return(await import("./portal/support/geometryServiceUtils.js")).getGeometryServiceURL(this.portalItem).then((r=>{const i=new B;return i.geometries=[t],i.outSpatialReference=e,x(r,i)})).then((e=>e[0])).catch((e=>(p.getLogger(this.declaredClass).error("Error projecting item's extent:",e),null)))}return null}_removeDanglingLayerRefs(){const e=this.applicationProperties,t=e&&e.viewing&&e.viewing.search,r=e=>this.allLayers.some((t=>t.id===e));t&&t.layers&&(t.layers=t.layers.filter((e=>r(e.id)))),t&&t.tables&&(t.tables=t.tables.filter((e=>this.tables.some((t=>t.id===e.id)))));const i=e&&e.editing&&e.editing.locationTracking;i&&i.info&&!r(i.info.layerId)&&(e.editing=null);const o=this.presentation&&this.presentation.slides;o&&o.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>r(e.id))))}))}async _validateMap(){if(!this.basemap?.baseLayers.length)throw new s("webmap:save","Map does not have a valid basemap with a base layer.");let e=null;if(await d((()=>{const t=D(this.initialViewProperties,this.basemap);return e=t.spatialReference,!t.updating})),!P(e,this.initialViewProperties.spatialReference))throw new s("webmap:save","The spatial reference of the basemap is not compatible with the one from the map.",{expected:this.initialViewProperties.spatialReference,actual:e})}_validateItem(){if(!this.portalItem)throw p.getLogger(this.declaredClass).error("save: requires the portalItem property to be set"),new s("webmap:portal-item-not-set","Portal item to save to has not been set on the WebMap");this._validateItemType(this.portalItem)}_validateItemType(e){if(e.type!==ie)throw new s("webmap:portal-item-wrong-type",`Portal item needs to have type "${ie}"`)}_loadLayerContainers(){const e=[];return this.basemap&&e.push(this.basemap.load()),this.ground&&e.push(this.ground.load()),c(e).then((()=>{}))}async _beforeSave(){const e=[];for(const t of this.allLayers)if("beforeSave"in t&&"function"==typeof t.beforeSave){const r=t.beforeSave();r&&e.push(r)}await c(e)}_loadAllLayers(){const e=this._getAllLayersAndTables().map((e=>e.load()));return c(e).then((()=>{}))}_getAllLayersAndTables(){return this.allLayers.concat(this.allTables)}_validateJSONForWriting(e,t){let r=(e.messages??[]).filter((e=>"error"===e.type)).map((e=>new s(e.name,e.message,e.details)));if(e.blockedRelativeUrls&&(r=r.concat(e.blockedRelativeUrls.map((e=>new s("url:unsupported",`Relative url '${e}' is not supported in Web Map`))))),t.ignoreUnsupported&&(r=r.filter((e=>"layer:unsupported"!==e.name&&"symbol:unsupported"!==e.name&&"symbol-layer:unsupported"!==e.name&&"property:unsupported"!==e.name&&"url:unsupported"!==e.name))),r.length>0)throw new s("webmap:save","Failed to save webmap due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:r})}async _updateItemProperties(e){e.extent=await this._getWGS84Extent(this.initialViewProperties.viewpoint.targetGeometry),await this._updateTypeKeywords(e)}async _updateItemPropertiesForSaveAs(e){N(e,pe),N(e,ge),N(e,M.METADATA),N(e,he),N(e,fe),N(e,we),N(e,de),N(e,ye),await this._updateItemProperties(e)}async _getWGS84Extent(e){const t=e.clone().normalize();let r;if(t.length>1)for(const i of t)r?i.width>r.width&&(r=i):r=i;else r=t[0];return this._projectToWGS84(r)}async _projectToWGS84(e){const t=e.spatialReference;if(t.isWGS84)return e.clone();if(t.isWebMercator)return L(e);const r=await import("./portal/support/geometryServiceUtils.js"),i=await r.getGeometryServiceURL(this.portalItem),o=new B;o.geometries=[e],o.outSpatialReference=U.WGS84;return(await x(i,o))[0]}async _updateTypeKeywords(e){E(e,le),await this._loadAllLayers(),this._evalCollectorKeyword(e),this._evalDataEditingKeyword(e),this._evalOfflineKeyword(e),this._evalDeveloperBasemapKeyword(e),this._evalUtilityNetworkKeyword(e),e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter(((e,t,r)=>r.indexOf(e)===t)))}_evalCollectorKeyword(e){C(e,pe)||C(e,de)||C(e,ye)||C(e,we)||!this._hasEditableFeatureLayer()?N(e,me):E(e,me)}_evalDataEditingKeyword(e){this._hasEditableFeatureLayer()?E(e,ue):N(e,ue)}_evalOfflineKeyword(e){!C(e,he)&&this._isOfflineCapableMap()?E(e,ce):N(e,ce)}_evalDeveloperBasemapKeyword(e){J(this.basemap)?E(e,be):N(e,be)}_evalUtilityNetworkKeyword(e){this.utilityNetworks?.length?E(e,_e):N(e,_e)}_hasEditableFeatureLayer(){return this._getAllLayersAndTables().some((e=>e.loaded&&V(e)&&e.capabilities.operations.supportsEditing&&e.editingEnabled))}_isOfflineCapableMap(){return this._getAllLayersAndTables().filter((e=>"group"!==e.type)).every((e=>e.loaded&&this._isOfflineCapableLayer(e)))}_isFeatureCollectionLike(e){return F(e)||"map-notes"===e.type||"route"===e.type}_isOfflineCapableLayer(e){return V(e)&&e.capabilities.operations.supportsSync||this._isFeatureCollectionLike(e)&&!e.portalItem||("tile"===e.type||"vector-tile"===e.type)&&(e.capabilities.operations.supportsExportTiles||this._isExportableAGOLTileLayer(e)||G(e))&&e.spatialReference.equals(this.initialViewProperties.spatialReference)}_isExportableAGOLTileLayer(e){return"tile"===e.type&&(R(e.url)&&ve.some((t=>e.url?.toLowerCase().includes("/"+t+"/"))))}async _updateItem(e,t,r){await e.update({data:t}),this._syncUpInstanceWithItem(e,t,r)}async _createItem(e,t,r,i){const o=this.portalItem,a={item:o,authenticated:!(!o?.id||!o.portal.user)},n=e.portal;await n.signIn();const{copyAllowed:l,itemReloaded:p}=await this._isCopyAllowed(a,n);if(a.authenticated||(a.authenticated=p),!l)throw new s("webmap:save-as-copy-not-allowed","Owner of this map does not allow others to save a copy");const m=await this._initializeNewItem(e,a,t,i);return this.portalItem=e,this._syncUpInstanceWithItem(e,t,r),m}async _isCopyAllowed(e,t){const{item:r,authenticated:i}=e;return r?.id&&r.typeKeywords?.includes("useOnly")?r.portal.portalHostname!==t.portalHostname?{copyAllowed:!1,itemReloaded:!1}:(i||await r.reload(),{copyAllowed:"admin"===r.itemControl||"update"===r.itemControl,itemReloaded:!0}):{copyAllowed:!0,itemReloaded:!1}}async _initializeNewItem(e,t,r,i){const o=e.portal,{item:a,authenticated:s}=t,{folder:n,copyAllResources:l}=i;let p=!1;if(l&&a?.id&&w(a.portal.url,o.url)&&(s||await a.reload(),a.isOrgItem)){const{total:e}=await a.fetchResources();p=!!e}if(p){const t=await a.copy({copyResources:"all",folder:n});e.id=t.id,e.portal=t.portal;const i=e.toJSON();await e.load(),e.read(i),await e.update({data:r})}else await(o.user?.addItem({item:e,folder:n,data:r}));return p}_syncUpInstanceWithItem(e,t,r){u.prototype.read.call(this,{version:t.version,authoringApp:t.authoringApp,authoringAppVersion:t.authoringAppVersion},{origin:"web-map",ignoreDefaults:!0,url:e.itemUrl?y(e.itemUrl):void 0}),S(r),this.resourceInfo=t}async _updateItemThumbnail(){this.thumbnailUrl&&this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl,filename:this._thumbnailFilename})),this._clearThumbnailOverride())}_getPortalItem(e){let t=k.from(e);return t.id&&(t=t.clone(),t.id=null),t.type||(t.type=ie),t.portal||(t.portal=W.getDefault()),this._validateItemType(t),t}async _updateFromInternal(e,t){if(t=t||{},await d((()=>e.ready)),this._updateInitialViewProperties(e,t),e.map===this)for(const r of e.allLayerViews)"visible"in r&&"visible"in r.layer&&r._isOverridden("visible")&&(r.layer.visible=r.visible),"featureEffect"in r&&"featureEffect"in r.layer&&r._isOverridden("featureEffect")&&(r.layer.featureEffect=r.featureEffect);await this._updateThumbnailUrl(e,t)}_updateInitialViewProperties(e,t){if(t.backgroundExcluded||(this.initialViewProperties.background=e.background?.clone()),this.initialViewProperties.spatialReference=e.spatialReference?.clone(),t.viewpointExcluded||(this.initialViewProperties.viewpoint=new i({rotation:e.rotation,scale:t.scalePreserved?e.scale:null,targetGeometry:this._getViewExtent(e)})),!t.widgetsExcluded)for(const r of e.persistableViewModels)r.updateWebDocument(this)}_getViewExtent(e){const t=e.center.clone().normalize(),r=e.extent.clone(),i=r.width/2;return r.xmin=t.x-i,r.xmax=t.x+i,r}async _updateThumbnailUrl(e,t){if(t.thumbnailExcluded)return;const r=H(e,t.thumbnailSize),i=await e.takeScreenshot({format:"png",width:r.width,height:r.height});this._setAutoGeneratedThumbnail(i.dataUrl)}_setAutoGeneratedThumbnail(e){this.thumbnailUrl=e,this._thumbnailFilename=null}_clearThumbnailOverride(){this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"),this._thumbnailFilename=null}_generateCustomThumbnailFilename(e){if(f(e)){const t=g(e),r=t&&t.mediaType,i=r&&se.get(r.toLowerCase())||null,o=`thumbnail${Date.now()}`;return i?`${o}.${i}`:o}return null}_getThumbnailState(){let e=this.thumbnailUrl;return e&&(e=this._isOverridden("thumbnailUrl")?e:b(e,"w","8192")),{thumbnailUrl:e,filename:this._thumbnailFilename}}_restoreThumbnailFromState(e){this.thumbnailUrl=e.thumbnailUrl,this._thumbnailFilename=e.filename}_getAuthoringPropsState(){return{authoringApp:this.authoringApp,authoringAppVersion:this.authoringAppVersion,isAuthoringAppSetByUser:this._isAuthoringAppSetByUser,isAuthoringAppVersionSetByUser:this._isAuthoringAppVersionSetByUser}}_restoreAuthoringPropsFromState(e){e.isAuthoringAppSetByUser?this.authoringApp=e.authoringApp:this._isAuthoringAppSetByUser=!1,e.isAuthoringAppVersionSetByUser?this.authoringAppVersion=e.authoringAppVersion:this._isAuthoringAppVersionSetByUser=!1}static fromJSON(e){const t=e;if(!t)throw new s("webmap:empty-resource","Expected a JSON resource but got nothing");return new this({resourceInfo:t})}};Ae.VERSION=re,e([_({type:X,json:{write:!0}})],Ae.prototype,"applicationProperties",void 0),e([_({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],Ae.prototype,"authoringApp",null),e([I("authoringApp")],Ae.prototype,"writeAuthoringApp",null),e([_({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],Ae.prototype,"authoringAppVersion",null),e([I("authoringAppVersion")],Ae.prototype,"writeAuthoringAppVersion",null),e([_({json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],Ae.prototype,"basemap",void 0),e([_({type:oe,json:{write:{overridePolicy:e=>({enabled:!!(e&&e.length>0),ignoreOrigin:!0})}}})],Ae.prototype,"bookmarks",void 0),e([_({type:K,json:{read:{source:"mapFloorInfo"},write:{target:"mapFloorInfo"}}})],Ae.prototype,"floorInfo",void 0),e([_({type:$,json:{write:!0}})],Ae.prototype,"geotriggersInfo",void 0),e([_({type:Z,nonNullable:!0,json:{read:{source:["background","initialState.viewpoint","mapRangeInfo","spatialReference"]},write:{ignoreOrigin:!0,target:{background:{type:te},"initialState.viewpoint":{type:i},mapRangeInfo:{type:z},spatialReference:{type:U}}}}})],Ae.prototype,"initialViewProperties",void 0),e([v("initialViewProperties")],Ae.prototype,"readInitialViewProperties",null),e([I("initialViewProperties")],Ae.prototype,"writeInitialViewProperties",null),e([_({json:{read:!1,write:{target:"operationalLayers",ignoreOrigin:!0}}})],Ae.prototype,"layers",void 0),e([I("layers")],Ae.prototype,"writeLayers",null),e([_({type:k})],Ae.prototype,"portalItem",void 0),e([_({json:{write:!0}})],Ae.prototype,"presentation",void 0),e([_()],Ae.prototype,"resourceInfo",void 0),e([_({readOnly:!0,type:ee,json:{read:{source:"version"},write:{allowNull:!0,ignoreOrigin:!0,target:"version",isRequired:!0}}})],Ae.prototype,"sourceVersion",void 0),e([v("sourceVersion")],Ae.prototype,"readSourceVersion",null),e([I("sourceVersion")],Ae.prototype,"writeSourceVersion",null),e([_({json:{read:!1,write:{ignoreOrigin:!0}}})],Ae.prototype,"tables",void 0),e([I("tables")],Ae.prototype,"writeTables",null),e([_()],Ae.prototype,"thumbnailUrl",null),e([_({type:q,json:{write:!0}})],Ae.prototype,"widgets",void 0),e([_({type:ae,json:{read:!0,write:!0}})],Ae.prototype,"utilityNetworks",void 0),Ae=e([A("esri.WebMap")],Ae);const Ie=Ae;export{Ie as default};
package/WebScene.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.27/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import o from"./core/Collection.js";import s from"./core/Error.js";import{clone as a}from"./core/lang.js";import n from"./core/Loadable.js";import{loadAll as l}from"./core/loadAll.js";import p from"./core/Logger.js";import{destroyMaybe as c}from"./core/maybe.js";import{MultiOriginJSONMixin as d,MultiOriginJSONSupport as h}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as u}from"./core/Promise.js";import{debounce as m,eachAlways as y}from"./core/promiseUtils.js";import{urlToObject as w,addQueryParameter as g}from"./core/urlUtils.js";import{property as f}from"./core/accessorSupport/decorators/property.js";import"./core/accessorSupport/ensureType.js";import{reader as v}from"./core/accessorSupport/decorators/reader.js";import{subclass as b}from"./core/accessorSupport/decorators/subclass.js";import{writer as S}from"./core/accessorSupport/decorators/writer.js";import{updateOrigins as A}from"./core/accessorSupport/originUtils.js";import{readLoadable as _}from"./core/accessorSupport/read.js";import I from"./geometry/Extent.js";import j from"./geometry/HeightModelInfo.js";import{canProjectWithoutEngine as L}from"./geometry/projection.js";import R from"./geometry/SpatialReference.js";import{validateWebSceneError as P}from"./geometry/support/heightModelInfoUtils.js";import{fromJSON as V}from"./geometry/support/jsonUtils.js";import{isEarth as M}from"./geometry/support/spatialReferenceUtils.js";import U from"./portal/Portal.js";import O from"./portal/PortalItem.js";import E from"./support/MapFloorInfo.js";import{createSchemaValidationError as C,createCopyError as N}from"./support/webSceneUtils.js";import{ViewingMode as T}from"./views/ViewingMode.js";import{isSpatialReferenceSupported as G}from"./views/support/spatialReferenceSupport.js";import{saveResources as F}from"./webdoc/support/saveUtils.js";import{getOptimalThumbnailSize as $}from"./webdoc/support/thumbnailUtils.js";import W from"./webscene/ApplicationProperties.js";import J from"./webscene/Environment.js";import x from"./webscene/InitialViewProperties.js";import k from"./webscene/Presentation.js";import B from"./webscene/TransportationNetwork.js";import{Version as q}from"./webscene/Version.js";import{getLoader as K}from"./webscene/support/schemaValidatorLoader.js";const D=new q(1,31),H=()=>{const e=8,t=[],r=D.major;for(let i=e;i<=D.minor;i++)t.push(`${r}.${i}`);return t},z="Web Scene",Q="ViewingMode-Local";let X=class extends(n.LoadableMixin(u(d(r)))){constructor(e){super(e),this._layersIdGCTimeoutId=void 0,this._updateFromPromise=null,this.applicationProperties=null,this.clippingArea=null,this.clippingEnabled=!1,this.floorInfo=null,this.heightModelInfo=void 0,this.sourceVersion=null,this.transportationNetworks=null,this.presentation=new k,this.initialViewProperties=new x,this.portalItem=null,this.resourceInfo=null,this._debouncedSaveOperations=m((async(e,t,r)=>{switch(e){case Y.SAVE:return this._saveImpl(t);case Y.SAVE_AS:return this._saveAsImpl(r,t)}})),this._resourceReferences={portalItem:null,paths:[]},this.authoringApp=null,this.authoringAppVersion=null,this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1}initialize(){if(this.when().catch((e=>{p.getLogger(this.declaredClass).error("#load()","Failed to load web scene",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t),this.addResolvingPromise(this._validateSpatialReference()),this.addResolvingPromise(this._validateHeightModelInfo())}this.addHandles(this.allLayers.on("change",(()=>this._scheduleLayersIdGC())))}destroy(){this._unscheduleLayersIdGC(),this.presentation&&this.presentation.destroy(),this.portalItem=c(this.portalItem),this.basemap?.destroy()}writeClippingArea(e,t){t.clippingArea||(t.clippingArea={}),t.clippingArea.geometry=e.toJSON()}readClippingEnabled(e,t){return!!t.clippingArea&&!!t.clippingArea.clip}writeClippingEnabled(e,t){this.clippingArea&&(t.clippingArea||(t.clippingArea={}),t.clippingArea.clip=e)}writeLayers(e,t,r,i){const o={...i,layerContainerType:"operational-layers"},s=e.map((e=>this.verifyWriteLayer(e,i)?e.write({},o):null)).filter((e=>!!e));t[r]=s.toArray()}verifyWriteLayer(e,t){return"write"in e||(t&&t.messages&&t.messages.push(new s("layer:unsupported",`Layers (${e.title}, ${e.id}) of type '${e.declaredClass}' cannot be persisted in web scenes`,{layer:e})),!1)}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new q(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${D.major}.${D.minor}`}get thumbnailUrl(){return this.portalItem?.thumbnailUrl??null}set thumbnailUrl(e){e?this._override("thumbnailUrl",e):(this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"))}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp="ArcGIS API for JavaScript"}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}writeGround(e,t,r,i){t[r]=e?e.write({},i):{transparency:0,layers:[]}}readInitialViewProperties(e,t){const r={};return t.initialState&&t.initialState.environment&&(r.environment=J.fromJSON(t.initialState.environment)),t.spatialReference?r.spatialReference=R.fromJSON(t.spatialReference):r.spatialReference=R.WebMercator,r.viewingMode=t.viewingMode||"global",t.initialState&&t.initialState.viewpoint&&(r.viewpoint=i.fromJSON(t.initialState.viewpoint)),new x(r)}get spatialReference(){return this.initialViewProperties?.spatialReference??R.WebMercator}get viewingMode(){return this.initialViewProperties?.viewingMode??"global"}load(e){const t=this.ground;return this.addResolvingPromise(this._loadFromSource().then((()=>{t&&t!==this.ground&&t.destroy()}))),Promise.resolve(this)}loadAll(){return l(this,(e=>{const t=this.presentation&&this.presentation.slides;e(this.ground,this.basemap,this.layers,t&&t.map((e=>e.basemap)))}))}read(e,t){t={...t,origin:"web-scene"};const r=this._isAuthoringAppVersionSetByUser,i=this._isAuthoringAppSetByUser;if(_(this,e,(t=>super.read(e,t)),t),i||(this._isAuthoringAppSetByUser=!1),r||(this._isAuthoringAppVersionSetByUser=!1),e.baseMap&&Array.isArray(e.baseMap.elevationLayers)&&this.sourceVersion?.supportsVisibleElevationLayersInSlides){const t=e.baseMap.elevationLayers.map((e=>({id:e.id}))),r=this.presentation.slides,i=(e,t)=>e.visibleLayers.some((e=>e.id===t)),o=t.filter((e=>!r.some((t=>i(t,e.id)))));r.forEach((e=>{e.visibleLayers.addMany(o)}))}}_writeBasemapElevationLayers(e){const t=e.ground&&e.ground.layers;!e.baseMap&&t&&t.length&&(e.baseMap={title:"Basemap",baseMapLayers:[]}),e.baseMap&&(e.baseMap.elevationLayers=a(t))}write(e,t){if("loaded"!==this.loadStatus){const e=new s("webscene:not-loaded","Web scene must be loaded before it can be serialized");throw p.getLogger(this.declaredClass).error("#toJSON()","Web scene must be loaded before it can be serialized",this.loadError||this.loadStatus),e}this._runLayersIdGC();const r=!t?.messages;t={messages:[],...t,origin:"web-scene"};const i=super.write(e,t);if(r){const e=t.messages?.filter((e=>"web-document-write:property-required"===e.name))??[];if(e.length){const t=new s("web-document:property-required","One or more properties that are required in the webscene JSON are missing, see details for the specific errors",{errors:e});throw p.getLogger(this.declaredClass).error("#toJSON()","One or more properties that are required in the webscene JSON are missing",e),t}}return this._writeBasemapElevationLayers(i),i}async save(e){return this._debouncedSaveOperations(Y.SAVE,e)}async _saveImpl(e){if(!this.portalItem)throw p.getLogger(this.declaredClass).error("save(): requires the .portalItem property to be set"),await Promise.resolve(),new s("webscene:portal-item-not-set","Portal item to save to has not been set on the WebScene");if(this.portalItem?.type!==z)throw await Promise.resolve(),new s("webscene:portal-item-wrong-type",`Portal item needs to have type "${z}"`);const t=this._updateFromPromise;await this._ensureLoadBeforeSave();const r=this._enableVerifyItemRelativeUrls({origin:"web-scene",url:this.portalItem.itemUrl?w(this.portalItem.itemUrl):null,messages:[],portal:this.portalItem.portal??U.getDefault(),portalItem:this.portalItem,writtenProperties:[],blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}}),i=this.write({},r);return await Promise.all(r.resources.pendingOperations),await this._verifySave(i,r,e),this._updateTypeKeywords(this.portalItem),await this.portalItem.update({data:i}),await F(this._resourceReferences,r,null),A(r),t&&await t,await this._saveThumbnail(),this.portalItem}async saveAs(e,t){return this._debouncedSaveOperations(Y.SAVE_AS,t,e)}async _saveAsImpl(e,t){let r=O.from(e);r||(p.getLogger(this.declaredClass).error("saveAs(portalItem): requires a portal item parameter"),await Promise.reject(new s("webscene:portal-item-required","saveAs requires a portal item to save to"))),r.id&&(r=r.clone(),r.id=null);const i=r.portal||U.getDefault();await this._ensureLoadBeforeSave(),r.type=z,r.portal=i;const o=this._enableVerifyItemRelativeUrls({origin:"web-scene",url:null,messages:[],portal:i,portalItem:r,writtenProperties:[],blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}}),a=this.write({},o);await Promise.all(o.resources.pendingOperations),await this._verifySaveAs(a,o,t);const n=this.thumbnailUrl,l=!this._isOverridden("thumbnailUrl");return this._updateTypeKeywords(r),await i.signIn(),await(i.user?.addItem({item:r,folder:t&&t.folder,data:a})),await F(this._resourceReferences,o,null),this.portalItem=r,h.prototype.read.call(this,{version:a.version,authoringApp:a.authoringApp,authoringAppVersion:a.authoringAppVersion},{name:"web-scene",ignoreDefaults:!0,url:r.itemUrl&&w(r.itemUrl)}),A(o),n&&(this.thumbnailUrl=l?g(n,"w","8192"):n),o.portalItem=r,await this._saveThumbnail(),r}async _saveThumbnail(){this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl})),this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"))}_verifySave(e,t,r,i=!1){if(!M(this.spatialReference))return Promise.reject(new s("webscene:unsupported-spatial-reference","Webscenes using spatial reference systems from Mars or Moon can not be saved currently."));let o,a=t.messages?.filter((e=>"error"===e.type)).map((e=>new s(e.name,e.message,e.details)))??[];t.blockedRelativeUrls&&(a=a.concat(t.blockedRelativeUrls.map((e=>new s("url:unsupported",`Relative url '${e}' is not supported in Web Scene`))))),r&&r.ignoreUnsupported&&(a=a.filter((e=>"layer:unsupported"!==e.name&&"symbol:unsupported"!==e.name&&"symbol-layer:unsupported"!==e.name&&"property:unsupported"!==e.name&&"url:unsupported"!==e.name&&"scenemodification:unsupported"!==e.name))),r?.requiredPropertyChecksDisabled&&(a=a.filter((e=>"web-document-write:property-required"!==e.name)));const n=!!r?.strictSchemaValidationEnabled,l=K();return o=n&&l?l().then((t=>{const r=t.validate(e);if(r.length>0){const e=`webscene did not validate:\n${r.join("\n")}`;p.getLogger(this.declaredClass).error(`${i?"saveAs":"save"}(): ${e}`)}return r.map((e=>new s("webscene:schema-validation",e)))})).then((e=>{if(e.length>0)throw C(e.concat(a));return a})):Promise.resolve(a),o.then((e=>{if(e.length>0)throw new s("webscene:save","Failed to save webscene due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:e})}))}_verifySaveAs(e,t,r){return this.canNotSaveAs(t)?Promise.reject(N()):this._verifySave(e,t,r,!0)}verifySaveAs(e){const t=this._enableVerifyItemRelativeUrls({origin:"web-scene",messages:[]}),r=this.write({},t);return this._verifySaveAs(r,t,e)}canNotSaveAs(e){return e||(e=this._enableVerifyItemRelativeUrls({origin:"web-scene",messages:[]}),this.write({},e)),(e.verifyItemRelativeUrls?.writtenUrls?.length??0)>0}async updateFrom(e,t={}){const r=this._updateFrom(e,t);this._updateFromPromise=r,await r;this._updateFromPromise===r&&(this._updateFromPromise=null)}async _updateFrom(e,t={}){if(await e.whenReady(),!t.environmentExcluded&&e.environment&&(this.initialViewProperties.environment=J.prototype.clone.apply(e.environment)),!t.viewpointExcluded&&e.viewpoint&&(this.initialViewProperties.viewpoint=e.viewpoint.clone()),this.initialViewProperties.spatialReference=e.spatialReference.clone(),this.initialViewProperties.viewingMode=e.viewingMode,null!=e.clippingArea?e.clippingArea!==this.clippingArea&&(this.clippingArea=e.clippingArea.clone(),this.clippingEnabled=!0):this.clippingEnabled=!1,e.heightModelInfo&&(this.heightModelInfo=e.heightModelInfo.clone()),e.map===this)for(const r of e.allLayerViews){const e="visible";e in r&&e in r.layer&&r._isOverridden(e)&&(r.layer[e]=r[e])}(!1===t.thumbnailExcluded||null==t.thumbnailExcluded&&!t.viewpointExcluded)&&await this._updateFromThumbnail(e,t.thumbnailSize??void 0)}async _updateFromThumbnail(e,t){const r=$(e,t),i=await e.takeScreenshot({format:"jpg",width:r.width,height:r.height,disableDecorations:!0});this.thumbnailUrl=i.dataUrl}_loadFromSource(){return this.resourceInfo?this._loadFromJSON(this.resourceInfo,{origin:"web-scene"}):this.portalItem&&this.portalItem.id?this._loadFromItem(this.portalItem):this._loadObjectsWithLayers()}_readAndLoadFromJSON(e,t){const r=this._validateJSON(e);return this.read(r,t),this._loadFromJSON(r,t)}_extractOperationalLayers(e){const t=[];if(!this.sourceVersion?.supportsGround&&e.baseMap&&Array.isArray(e.baseMap.elevationLayers))for(const o of e.baseMap.elevationLayers)t.push(o);const r=[],i=e=>(e.layers&&(e.layers=e.layers.filter(i)),"ArcGISTiledElevationServiceLayer"!==e.layerType||(this.sourceVersion?.supportsGround||r.push(e),!1));return{operationalLayers:e.operationalLayers?e.operationalLayers.filter(i):[],operationalElevationLayers:r,basemapElevationLayers:t}}_loadFromJSON(e,t){const r=new o;return this._validateSpatialReference().then((()=>this._validateHeightModelInfo())).then((()=>import("./layers/support/layersCreator.js"))).then((({populateOperationalLayers:i})=>{const{operationalLayers:o,operationalElevationLayers:s,basemapElevationLayers:a}=this._extractOperationalLayers(e),n=[],l={context:{...t,layerContainerType:"operational-layers"}};if(this.portalItem&&(l.context.portal=this.portalItem.portal||U.getDefault()),a.length>0){const e={...l,context:{...l.context,layerContainerType:"ground"}};e.defaultLayerType="ArcGISTiledElevationServiceLayer",n.push(i(this.ground.layers,a,e))}if(s.length>0){const e={...l,context:{...l.context,layerContainerType:"ground"}};e.defaultLayerType="ArcGISTiledElevationServiceLayer",n.push(i(r,s,e))}return o&&o.length>0&&n.push(i(this.layers,o,l)),y(n).then((()=>{}))})).then((()=>this._loadObjectsWithLayers())).then((()=>{this.ground.layers.addMany(r)}))}async _ensureLoadBeforeSave(){await this.load(),await this._loadObjectsWithLayers();const e=[];for(const t of this.allLayers.items)if("beforeSave"in t&&"function"==typeof t.beforeSave){const r=t.beforeSave();r&&e.push(r)}await y(e)}async _loadObjectsWithLayers(){const e=[];this.ground&&e.push(this.ground.load()),this.basemap&&e.push(this.basemap.load()),this.presentation.slides.forEach((t=>{t.basemap&&e.push(t.basemap.load())})),await y(e)}async _loadFromItem(e){if(await e.load().catch((e=>{throw new s("webscene:load-portal-item","Failed to load portal item",{error:e})})),"Web Scene"!==e.type)throw new s("webscene:invalid-portal-item","Invalid portal item type '${type}', expected 'Web Scene'",{type:e.type});const t=await e.fetchData();this.resourceInfo=t;const r={origin:"web-scene",url:w(e.itemUrl),portal:e.portal||U.getDefault(),portalItem:e,readResourcePaths:[]};await this._readAndLoadFromJSON(t,r),this._resourceReferences={portalItem:e,paths:r.readResourcePaths??[]}}_validateSpatialReference(){const e=this.initialViewProperties,t=this._sceneSpatialReference;let r;if("local"!==e.viewingMode){if(!G(t,T.Global))return Promise.reject(new s("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in global mode, only Web Mercator, WGS84 GCS or CGCS2000 are supported",{spatialReference:t,viewingMode:e.viewingMode}));r=e=>!e||L(e,t)}else{if(!G(t,T.Local))return Promise.reject(new s("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in local mode, only projected coordinate systems are supported",{spatialReference:t,viewingMode:e.viewingMode}));r=e=>!e||e.equals(t)}const i=e=>e?.camera?.position.spatialReference??e?.targetGeometry?.spatialReference,o=e.viewpoint,a=i(o);if(a&&!r(a))return Promise.reject(new s("webscene:incompatible-camera-spatial-reference","Camera spatial reference (${cameraSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",{cameraSpatialReference:a,sceneSpatialReference:t,viewingMode:e.viewingMode}));const n=this.presentation.slides.find((e=>!r(i(e.viewpoint))));if(n){const r=i(n.viewpoint);return Promise.reject(new s("webscene:incompatible-slide-spatial-reference","Slide spatial reference (${slideSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",{slideSpatialReference:r,sceneSpatialReference:t,viewingMode:e.viewingMode}))}return Promise.resolve()}_validateHeightModelInfo(){const e=this._sceneSpatialReference,t=P(this.heightModelInfo,e);return t?Promise.reject(t):Promise.resolve()}_validateJSON(e){const t=q.parse(e.version||"","webscene");return D.validate(t),e.version=`${t.major}.${t.minor}`,1===t.major&&t.minor<=2&&(e.spatialReference=R.WebMercator.toJSON()),e}_updateTypeKeywords(e){"local"===this.initialViewProperties.viewingMode?e.typeKeywords?e.typeKeywords.includes(Q)||e.typeKeywords.push(Q):e.typeKeywords=[Q]:"global"===this.initialViewProperties.viewingMode&&e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter((e=>e!==Q))),e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter(((e,t,r)=>r.indexOf(e)===t)))}get _sceneSpatialReference(){return this.initialViewProperties.spatialReference||R.WebMercator}get _verifyItemRelativeRootPath(){return this.portalItem?.itemUrl?w(this.portalItem.itemUrl).path:null}_enableVerifyItemRelativeUrls(e){const t=this._verifyItemRelativeRootPath;return t&&(e.verifyItemRelativeUrls={rootPath:t,writtenUrls:[]}),e}_unscheduleLayersIdGC(){this._layersIdGCTimeoutId&&(clearTimeout(this._layersIdGCTimeoutId),this._layersIdGCTimeoutId=0)}_scheduleLayersIdGC(){this._unscheduleLayersIdGC(),this._layersIdGCTimeoutId=setTimeout((()=>{this._layersIdGCTimeoutId=0,this._runLayersIdGC()}),3e3)}_runLayersIdGC(){this._unscheduleLayersIdGC();const e=this.applicationProperties&&this.applicationProperties.viewing&&this.applicationProperties.viewing.search,t=e=>this.allLayers.some((t=>t.id===e));e&&e.layers&&(e.layers=e.layers.filter((e=>t(e.id))));const r=this.presentation&&this.presentation.slides;r&&r.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>t(e.id))))}))}static fromJSON(e){if(!e)throw new s("webscene:empty-resource","Expected a JSON resource but got nothing");return new this({resourceInfo:e})}};var Y;X.version=`${D.major}.${D.minor}`,e([f({type:W,json:{write:!0}})],X.prototype,"applicationProperties",void 0),e([f({json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],X.prototype,"basemap",void 0),e([f({type:I,json:{read:{source:"clippingArea.geometry",reader:V},write:{target:"clippingArea.geometry"}}})],X.prototype,"clippingArea",void 0),e([S("clippingArea")],X.prototype,"writeClippingArea",null),e([f({type:Boolean,json:{write:{target:"clippingArea.clip"}}})],X.prototype,"clippingEnabled",void 0),e([v("clippingEnabled",["clippingArea"])],X.prototype,"readClippingEnabled",null),e([S("clippingEnabled")],X.prototype,"writeClippingEnabled",null),e([f({type:E,json:{read:{source:"mapFloorInfo"},write:{target:"mapFloorInfo"}}})],X.prototype,"floorInfo",void 0),e([f({type:j,json:{write:!0}})],X.prototype,"heightModelInfo",void 0),e([f({json:{write:{target:"operationalLayers",ignoreOrigin:!0}}})],X.prototype,"layers",void 0),e([S("layers")],X.prototype,"writeLayers",null),e([f({readOnly:!0,type:q,json:{type:H(),write:{ignoreOrigin:!0,target:"version",isRequired:!0,overridePolicy:()=>({enabled:!0,allowNull:!0,ignoreOrigin:!0})}}})],X.prototype,"sourceVersion",void 0),e([v("sourceVersion",["version"])],X.prototype,"readSourceVersion",null),e([S("sourceVersion")],X.prototype,"writeSourceVersion",null),e([f({json:{read:!1,write:!1}})],X.prototype,"tables",void 0),e([f()],X.prototype,"thumbnailUrl",null),e([f({type:String,json:{write:{writerEnsuresNonNull:!0,ignoreOrigin:!0}}})],X.prototype,"authoringApp",null),e([S("authoringApp")],X.prototype,"writeAuthoringApp",null),e([f({type:String,json:{write:{writerEnsuresNonNull:!0,ignoreOrigin:!0}}})],X.prototype,"authoringAppVersion",null),e([S("authoringAppVersion")],X.prototype,"writeAuthoringAppVersion",null),e([f({json:{write:{isRequired:!0,allowNull:!0,ignoreOrigin:!0,enabled:!0}}})],X.prototype,"ground",void 0),e([S("ground")],X.prototype,"writeGround",null),e([f({type:o.ofType(B),json:{write:!0}})],X.prototype,"transportationNetworks",void 0),e([f({type:k,nonNullable:!0,json:{write:{ignoreOrigin:!0,writer:(e,t,r,i)=>{if(e.slides&&e.slides.length>0){const r={...i,isPresentation:!0};t.presentation=e.write({},r)}}}}})],X.prototype,"presentation",void 0),e([f({type:x,nonNullable:!0,json:{write:{target:"initialState",isRequired:!0,ignoreOrigin:!0},default:()=>new x({viewingMode:"global",spatialReference:R.WebMercator})}})],X.prototype,"initialViewProperties",void 0),e([v("initialViewProperties",["initialState.environment","spatialReference","viewingMode","initialState.viewpoint"])],X.prototype,"readInitialViewProperties",null),e([f({type:R,json:{read:!1,write:{isRequired:!0,ignoreOrigin:!0}}})],X.prototype,"spatialReference",null),e([f({type:["local","global"],json:{read:!1,write:{isRequired:!0,ignoreOrigin:!0}}})],X.prototype,"viewingMode",null),e([f({type:O})],X.prototype,"portalItem",void 0),e([f()],X.prototype,"resourceInfo",void 0),X=e([b("esri.WebScene")],X),function(e){e[e.SAVE=0]="SAVE",e[e.SAVE_AS=1]="SAVE_AS"}(Y||(Y={}));const Z=X;export{Z as default};
5
+ import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import o from"./core/Collection.js";import s from"./core/Error.js";import{clone as a}from"./core/lang.js";import n from"./core/Loadable.js";import{loadAll as l}from"./core/loadAll.js";import p from"./core/Logger.js";import{destroyMaybe as c}from"./core/maybe.js";import{MultiOriginJSONMixin as d,MultiOriginJSONSupport as h}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as u}from"./core/Promise.js";import{debounce as m,eachAlways as y}from"./core/promiseUtils.js";import{urlToObject as w,addQueryParameter as g}from"./core/urlUtils.js";import{property as f}from"./core/accessorSupport/decorators/property.js";import"./core/accessorSupport/ensureType.js";import{reader as v}from"./core/accessorSupport/decorators/reader.js";import{subclass as b}from"./core/accessorSupport/decorators/subclass.js";import{writer as S}from"./core/accessorSupport/decorators/writer.js";import{updateOrigins as A}from"./core/accessorSupport/originUtils.js";import{readLoadable as _}from"./core/accessorSupport/read.js";import I from"./geometry/Extent.js";import j from"./geometry/HeightModelInfo.js";import{canProjectWithoutEngine as L}from"./geometry/projection.js";import R from"./geometry/SpatialReference.js";import{validateWebSceneError as P}from"./geometry/support/heightModelInfoUtils.js";import{fromJSON as V}from"./geometry/support/jsonUtils.js";import{isEarth as M}from"./geometry/support/spatialReferenceUtils.js";import U from"./portal/Portal.js";import O from"./portal/PortalItem.js";import E from"./support/MapFloorInfo.js";import{createSchemaValidationError as C,createCopyError as N}from"./support/webSceneUtils.js";import{ViewingMode as T}from"./views/ViewingMode.js";import{isSpatialReferenceSupported as G}from"./views/support/spatialReferenceSupport.js";import{saveResources as F}from"./webdoc/support/saveUtils.js";import{getOptimalThumbnailSize as $}from"./webdoc/support/thumbnailUtils.js";import W from"./webscene/ApplicationProperties.js";import J from"./webscene/Environment.js";import x from"./webscene/InitialViewProperties.js";import k from"./webscene/Presentation.js";import B from"./webscene/TransportationNetwork.js";import{Version as q}from"./webscene/Version.js";import{getLoader as K}from"./webscene/support/schemaValidatorLoader.js";const D=new q(1,31),H=()=>{const e=8,t=[],r=D.major;for(let i=e;i<=D.minor;i++)t.push(`${r}.${i}`);return t},z="Web Scene",Q="ViewingMode-Local";let X=class extends(n.LoadableMixin(u(d(r)))){constructor(e){super(e),this._layersIdGCTimeoutId=void 0,this._updateFromPromise=null,this.applicationProperties=null,this.clippingArea=null,this.clippingEnabled=!1,this.floorInfo=null,this.heightModelInfo=void 0,this.sourceVersion=null,this.transportationNetworks=null,this.presentation=new k,this.initialViewProperties=new x,this.portalItem=null,this.resourceInfo=null,this._debouncedSaveOperations=m((async(e,t,r)=>{switch(e){case Y.SAVE:return this._saveImpl(t);case Y.SAVE_AS:return this._saveAsImpl(r,t)}})),this._resourceReferences={portalItem:null,paths:[]},this.authoringApp=null,this.authoringAppVersion=null,this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1}initialize(){if(this.when().catch((e=>{p.getLogger(this.declaredClass).error("#load()","Failed to load web scene",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t),this.addResolvingPromise(this._validateSpatialReference()),this.addResolvingPromise(this._validateHeightModelInfo())}this.addHandles(this.allLayers.on("change",(()=>this._scheduleLayersIdGC())))}destroy(){this._unscheduleLayersIdGC(),this.presentation&&this.presentation.destroy(),this.portalItem=c(this.portalItem),this.basemap?.destroy()}writeClippingArea(e,t){t.clippingArea||(t.clippingArea={}),t.clippingArea.geometry=e.toJSON()}readClippingEnabled(e,t){return!!t.clippingArea&&!!t.clippingArea.clip}writeClippingEnabled(e,t){this.clippingArea&&(t.clippingArea||(t.clippingArea={}),t.clippingArea.clip=e)}writeLayers(e,t,r,i){const o={...i,layerContainerType:"operational-layers"},s=e.map((e=>this.verifyWriteLayer(e,i)?e.write({},o):null)).filter((e=>!!e));t[r]=s.toArray()}verifyWriteLayer(e,t){return"write"in e||(t&&t.messages&&t.messages.push(new s("layer:unsupported",`Layers (${e.title}, ${e.id}) of type '${e.declaredClass}' cannot be persisted in web scenes`,{layer:e})),!1)}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new q(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${D.major}.${D.minor}`}get thumbnailUrl(){return this.portalItem?.thumbnailUrl??null}set thumbnailUrl(e){e?this._override("thumbnailUrl",e):(this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"))}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp="ArcGIS API for JavaScript"}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}writeGround(e,t,r,i){t[r]=e?e.write({},i):{transparency:0,layers:[]}}readInitialViewProperties(e,t){const r={};return t.initialState&&t.initialState.environment&&(r.environment=J.fromJSON(t.initialState.environment)),t.spatialReference?r.spatialReference=R.fromJSON(t.spatialReference):r.spatialReference=R.WebMercator,r.viewingMode=t.viewingMode||"global",t.initialState&&t.initialState.viewpoint&&(r.viewpoint=i.fromJSON(t.initialState.viewpoint)),new x(r)}get spatialReference(){return this.initialViewProperties?.spatialReference??R.WebMercator}get viewingMode(){return this.initialViewProperties?.viewingMode??"global"}load(e){const t=this.ground;return this.addResolvingPromise(this._loadFromSource().then((()=>{t&&t!==this.ground&&t.destroy()}))),Promise.resolve(this)}loadAll(){return l(this,(e=>{const t=this.presentation&&this.presentation.slides;e(this.ground,this.basemap,this.layers,t&&t.map((e=>e.basemap)))}))}read(e,t){t={...t,origin:"web-scene"};const r=this._isAuthoringAppVersionSetByUser,i=this._isAuthoringAppSetByUser;if(_(this,e,(t=>super.read(e,t)),t),i||(this._isAuthoringAppSetByUser=!1),r||(this._isAuthoringAppVersionSetByUser=!1),e.baseMap&&Array.isArray(e.baseMap.elevationLayers)&&this.sourceVersion?.supportsVisibleElevationLayersInSlides){const t=e.baseMap.elevationLayers.map((e=>({id:e.id}))),r=this.presentation.slides,i=(e,t)=>e.visibleLayers.some((e=>e.id===t)),o=t.filter((e=>!r.some((t=>i(t,e.id)))));r.forEach((e=>{e.visibleLayers.addMany(o)}))}}_writeBasemapElevationLayers(e){const t=e.ground&&e.ground.layers;!e.baseMap&&t&&t.length&&(e.baseMap={title:"Basemap",baseMapLayers:[]}),e.baseMap&&(e.baseMap.elevationLayers=a(t))}write(e,t){if("loaded"!==this.loadStatus){const e=new s("webscene:not-loaded","Web scene must be loaded before it can be serialized");throw p.getLogger(this.declaredClass).error("#toJSON()","Web scene must be loaded before it can be serialized",this.loadError||this.loadStatus),e}this._runLayersIdGC();const r=!t?.messages;t={messages:[],...t,origin:"web-scene"};const i=super.write(e,t);if(r){const e=t.messages?.filter((e=>"web-document-write:property-required"===e.name))??[];if(e.length){const t=new s("web-document:property-required","One or more properties that are required in the webscene JSON are missing, see details for the specific errors",{errors:e});throw p.getLogger(this.declaredClass).error("#toJSON()","One or more properties that are required in the webscene JSON are missing",e),t}}return this._writeBasemapElevationLayers(i),i}async save(e){return this._debouncedSaveOperations(Y.SAVE,e)}async _saveImpl(e){if(!this.portalItem)throw p.getLogger(this.declaredClass).error("save(): requires the .portalItem property to be set"),await Promise.resolve(),new s("webscene:portal-item-not-set","Portal item to save to has not been set on the WebScene");if(this.portalItem?.type!==z)throw await Promise.resolve(),new s("webscene:portal-item-wrong-type",`Portal item needs to have type "${z}"`);const t=this._updateFromPromise;await this._ensureLoadBeforeSave();const r=this._enableVerifyItemRelativeUrls({origin:"web-scene",url:this.portalItem.itemUrl?w(this.portalItem.itemUrl):null,messages:[],portal:this.portalItem.portal??U.getDefault(),portalItem:this.portalItem,writtenProperties:[],blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}}),i=this.write({},r);return await Promise.all(r.resources.pendingOperations),await this._verifySave(i,r,e),this._updateTypeKeywords(this.portalItem),await this.portalItem.update({data:i}),await F(this._resourceReferences,r,null),A(r),t&&await t,await this._saveThumbnail(),this.portalItem}async saveAs(e,t){return this._debouncedSaveOperations(Y.SAVE_AS,t,e)}async _saveAsImpl(e,t){let r=O.from(e);r||(p.getLogger(this.declaredClass).error("saveAs(portalItem): requires a portal item parameter"),await Promise.reject(new s("webscene:portal-item-required","saveAs requires a portal item to save to"))),r.id&&(r=r.clone(),r.id=null);const i=r.portal||U.getDefault();await this._ensureLoadBeforeSave(),r.type=z,r.portal=i;const o=this._enableVerifyItemRelativeUrls({origin:"web-scene",url:null,messages:[],portal:i,portalItem:r,writtenProperties:[],blockedRelativeUrls:[],resources:{toAdd:[],toUpdate:[],toKeep:[],pendingOperations:[]}}),a=this.write({},o);await Promise.all(o.resources.pendingOperations),await this._verifySaveAs(a,o,t);const n=this.thumbnailUrl,l=!this._isOverridden("thumbnailUrl");return this._updateTypeKeywords(r),await i.signIn(),await(i.user?.addItem({item:r,folder:t&&t.folder,data:a})),await F(this._resourceReferences,o,null),this.portalItem=r,h.prototype.read.call(this,{version:a.version,authoringApp:a.authoringApp,authoringAppVersion:a.authoringAppVersion},{name:"web-scene",ignoreDefaults:!0,url:r.itemUrl?w(r.itemUrl):void 0}),A(o),n&&(this.thumbnailUrl=l?g(n,"w","8192"):n),o.portalItem=r,await this._saveThumbnail(),r}async _saveThumbnail(){this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl})),this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"))}_verifySave(e,t,r,i=!1){if(!M(this.spatialReference))return Promise.reject(new s("webscene:unsupported-spatial-reference","Webscenes using spatial reference systems from Mars or Moon can not be saved currently."));let o,a=t.messages?.filter((e=>"error"===e.type)).map((e=>new s(e.name,e.message,e.details)))??[];t.blockedRelativeUrls&&(a=a.concat(t.blockedRelativeUrls.map((e=>new s("url:unsupported",`Relative url '${e}' is not supported in Web Scene`))))),r&&r.ignoreUnsupported&&(a=a.filter((e=>"layer:unsupported"!==e.name&&"symbol:unsupported"!==e.name&&"symbol-layer:unsupported"!==e.name&&"property:unsupported"!==e.name&&"url:unsupported"!==e.name&&"scenemodification:unsupported"!==e.name))),r?.requiredPropertyChecksDisabled&&(a=a.filter((e=>"web-document-write:property-required"!==e.name)));const n=!!r?.strictSchemaValidationEnabled,l=K();return o=n&&l?l().then((t=>{const r=t.validate(e);if(r.length>0){const e=`webscene did not validate:\n${r.join("\n")}`;p.getLogger(this.declaredClass).error(`${i?"saveAs":"save"}(): ${e}`)}return r.map((e=>new s("webscene:schema-validation",e)))})).then((e=>{if(e.length>0)throw C(e.concat(a));return a})):Promise.resolve(a),o.then((e=>{if(e.length>0)throw new s("webscene:save","Failed to save webscene due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:e})}))}_verifySaveAs(e,t,r){return this.canNotSaveAs(t)?Promise.reject(N()):this._verifySave(e,t,r,!0)}verifySaveAs(e){const t=this._enableVerifyItemRelativeUrls({origin:"web-scene",messages:[]}),r=this.write({},t);return this._verifySaveAs(r,t,e)}canNotSaveAs(e){return e||(e=this._enableVerifyItemRelativeUrls({origin:"web-scene",messages:[]}),this.write({},e)),(e.verifyItemRelativeUrls?.writtenUrls?.length??0)>0}async updateFrom(e,t={}){const r=this._updateFrom(e,t);this._updateFromPromise=r,await r;this._updateFromPromise===r&&(this._updateFromPromise=null)}async _updateFrom(e,t={}){if(await e.whenReady(),!t.environmentExcluded&&e.environment&&(this.initialViewProperties.environment=J.prototype.clone.apply(e.environment)),!t.viewpointExcluded&&e.viewpoint&&(this.initialViewProperties.viewpoint=e.viewpoint.clone()),this.initialViewProperties.spatialReference=e.spatialReference.clone(),this.initialViewProperties.viewingMode=e.viewingMode,null!=e.clippingArea?e.clippingArea!==this.clippingArea&&(this.clippingArea=e.clippingArea.clone(),this.clippingEnabled=!0):this.clippingEnabled=!1,e.heightModelInfo&&(this.heightModelInfo=e.heightModelInfo.clone()),e.map===this)for(const r of e.allLayerViews){const e="visible";e in r&&e in r.layer&&r._isOverridden(e)&&(r.layer[e]=r[e])}(!1===t.thumbnailExcluded||null==t.thumbnailExcluded&&!t.viewpointExcluded)&&await this._updateFromThumbnail(e,t.thumbnailSize??void 0)}async _updateFromThumbnail(e,t){const r=$(e,t),i=await e.takeScreenshot({format:"jpg",width:r.width,height:r.height,disableDecorations:!0});this.thumbnailUrl=i.dataUrl}_loadFromSource(){return this.resourceInfo?this._loadFromJSON(this.resourceInfo,{origin:"web-scene"}):this.portalItem&&this.portalItem.id?this._loadFromItem(this.portalItem):this._loadObjectsWithLayers()}_readAndLoadFromJSON(e,t){const r=this._validateJSON(e);return this.read(r,t),this._loadFromJSON(r,t)}_extractOperationalLayers(e){const t=[];if(!this.sourceVersion?.supportsGround&&e.baseMap&&Array.isArray(e.baseMap.elevationLayers))for(const o of e.baseMap.elevationLayers)t.push(o);const r=[],i=e=>(e.layers&&(e.layers=e.layers.filter(i)),"ArcGISTiledElevationServiceLayer"!==e.layerType||(this.sourceVersion?.supportsGround||r.push(e),!1));return{operationalLayers:e.operationalLayers?e.operationalLayers.filter(i):[],operationalElevationLayers:r,basemapElevationLayers:t}}_loadFromJSON(e,t){const r=new o;return this._validateSpatialReference().then((()=>this._validateHeightModelInfo())).then((()=>import("./layers/support/layersCreator.js"))).then((({populateOperationalLayers:i})=>{const{operationalLayers:o,operationalElevationLayers:s,basemapElevationLayers:a}=this._extractOperationalLayers(e),n=[],l={context:{...t,layerContainerType:"operational-layers"}};if(this.portalItem&&(l.context.portal=this.portalItem.portal||U.getDefault()),a.length>0){const e={...l,context:{...l.context,layerContainerType:"ground"}};e.defaultLayerType="ArcGISTiledElevationServiceLayer",n.push(i(this.ground.layers,a,e))}if(s.length>0){const e={...l,context:{...l.context,layerContainerType:"ground"}};e.defaultLayerType="ArcGISTiledElevationServiceLayer",n.push(i(r,s,e))}return o&&o.length>0&&n.push(i(this.layers,o,l)),y(n).then((()=>{}))})).then((()=>this._loadObjectsWithLayers())).then((()=>{this.ground.layers.addMany(r)}))}async _ensureLoadBeforeSave(){await this.load(),await this._loadObjectsWithLayers();const e=[];for(const t of this.allLayers.items)if("beforeSave"in t&&"function"==typeof t.beforeSave){const r=t.beforeSave();r&&e.push(r)}await y(e)}async _loadObjectsWithLayers(){const e=[];this.ground&&e.push(this.ground.load()),this.basemap&&e.push(this.basemap.load()),this.presentation.slides.forEach((t=>{t.basemap&&e.push(t.basemap.load())})),await y(e)}async _loadFromItem(e){if(await e.load().catch((e=>{throw new s("webscene:load-portal-item","Failed to load portal item",{error:e})})),"Web Scene"!==e.type)throw new s("webscene:invalid-portal-item","Invalid portal item type '${type}', expected 'Web Scene'",{type:e.type});const t=await e.fetchData();this.resourceInfo=t;const r={origin:"web-scene",url:w(e.itemUrl),portal:e.portal||U.getDefault(),portalItem:e,readResourcePaths:[]};await this._readAndLoadFromJSON(t,r),this._resourceReferences={portalItem:e,paths:r.readResourcePaths??[]}}_validateSpatialReference(){const e=this.initialViewProperties,t=this._sceneSpatialReference;let r;if("local"!==e.viewingMode){if(!G(t,T.Global))return Promise.reject(new s("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in global mode, only Web Mercator, WGS84 GCS or CGCS2000 are supported",{spatialReference:t,viewingMode:e.viewingMode}));r=e=>!e||L(e,t)}else{if(!G(t,T.Local))return Promise.reject(new s("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in local mode, only projected coordinate systems are supported",{spatialReference:t,viewingMode:e.viewingMode}));r=e=>!e||e.equals(t)}const i=e=>e?.camera?.position.spatialReference??e?.targetGeometry?.spatialReference,o=e.viewpoint,a=i(o);if(a&&!r(a))return Promise.reject(new s("webscene:incompatible-camera-spatial-reference","Camera spatial reference (${cameraSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",{cameraSpatialReference:a,sceneSpatialReference:t,viewingMode:e.viewingMode}));const n=this.presentation.slides.find((e=>!r(i(e.viewpoint))));if(n){const r=i(n.viewpoint);return Promise.reject(new s("webscene:incompatible-slide-spatial-reference","Slide spatial reference (${slideSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",{slideSpatialReference:r,sceneSpatialReference:t,viewingMode:e.viewingMode}))}return Promise.resolve()}_validateHeightModelInfo(){const e=this._sceneSpatialReference,t=P(this.heightModelInfo,e);return t?Promise.reject(t):Promise.resolve()}_validateJSON(e){const t=q.parse(e.version||"","webscene");return D.validate(t),e.version=`${t.major}.${t.minor}`,1===t.major&&t.minor<=2&&(e.spatialReference=R.WebMercator.toJSON()),e}_updateTypeKeywords(e){"local"===this.initialViewProperties.viewingMode?e.typeKeywords?e.typeKeywords.includes(Q)||e.typeKeywords.push(Q):e.typeKeywords=[Q]:"global"===this.initialViewProperties.viewingMode&&e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter((e=>e!==Q))),e.typeKeywords&&(e.typeKeywords=e.typeKeywords.filter(((e,t,r)=>r.indexOf(e)===t)))}get _sceneSpatialReference(){return this.initialViewProperties.spatialReference||R.WebMercator}get _verifyItemRelativeRootPath(){return this.portalItem?.itemUrl?w(this.portalItem.itemUrl).path:null}_enableVerifyItemRelativeUrls(e){const t=this._verifyItemRelativeRootPath;return t&&(e.verifyItemRelativeUrls={rootPath:t,writtenUrls:[]}),e}_unscheduleLayersIdGC(){this._layersIdGCTimeoutId&&(clearTimeout(this._layersIdGCTimeoutId),this._layersIdGCTimeoutId=0)}_scheduleLayersIdGC(){this._unscheduleLayersIdGC(),this._layersIdGCTimeoutId=setTimeout((()=>{this._layersIdGCTimeoutId=0,this._runLayersIdGC()}),3e3)}_runLayersIdGC(){this._unscheduleLayersIdGC();const e=this.applicationProperties&&this.applicationProperties.viewing&&this.applicationProperties.viewing.search,t=e=>this.allLayers.some((t=>t.id===e));e&&e.layers&&(e.layers=e.layers.filter((e=>t(e.id))));const r=this.presentation&&this.presentation.slides;r&&r.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>t(e.id))))}))}static fromJSON(e){if(!e)throw new s("webscene:empty-resource","Expected a JSON resource but got nothing");return new this({resourceInfo:e})}};var Y;X.version=`${D.major}.${D.minor}`,e([f({type:W,json:{write:!0}})],X.prototype,"applicationProperties",void 0),e([f({json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],X.prototype,"basemap",void 0),e([f({type:I,json:{read:{source:"clippingArea.geometry",reader:V},write:{target:"clippingArea.geometry"}}})],X.prototype,"clippingArea",void 0),e([S("clippingArea")],X.prototype,"writeClippingArea",null),e([f({type:Boolean,json:{write:{target:"clippingArea.clip"}}})],X.prototype,"clippingEnabled",void 0),e([v("clippingEnabled",["clippingArea"])],X.prototype,"readClippingEnabled",null),e([S("clippingEnabled")],X.prototype,"writeClippingEnabled",null),e([f({type:E,json:{read:{source:"mapFloorInfo"},write:{target:"mapFloorInfo"}}})],X.prototype,"floorInfo",void 0),e([f({type:j,json:{write:!0}})],X.prototype,"heightModelInfo",void 0),e([f({json:{write:{target:"operationalLayers",ignoreOrigin:!0}}})],X.prototype,"layers",void 0),e([S("layers")],X.prototype,"writeLayers",null),e([f({readOnly:!0,type:q,json:{type:H(),write:{ignoreOrigin:!0,target:"version",isRequired:!0,overridePolicy:()=>({enabled:!0,allowNull:!0,ignoreOrigin:!0})}}})],X.prototype,"sourceVersion",void 0),e([v("sourceVersion",["version"])],X.prototype,"readSourceVersion",null),e([S("sourceVersion")],X.prototype,"writeSourceVersion",null),e([f({json:{read:!1,write:!1}})],X.prototype,"tables",void 0),e([f()],X.prototype,"thumbnailUrl",null),e([f({type:String,json:{write:{writerEnsuresNonNull:!0,ignoreOrigin:!0}}})],X.prototype,"authoringApp",null),e([S("authoringApp")],X.prototype,"writeAuthoringApp",null),e([f({type:String,json:{write:{writerEnsuresNonNull:!0,ignoreOrigin:!0}}})],X.prototype,"authoringAppVersion",null),e([S("authoringAppVersion")],X.prototype,"writeAuthoringAppVersion",null),e([f({json:{write:{isRequired:!0,allowNull:!0,ignoreOrigin:!0,enabled:!0}}})],X.prototype,"ground",void 0),e([S("ground")],X.prototype,"writeGround",null),e([f({type:o.ofType(B),json:{write:!0}})],X.prototype,"transportationNetworks",void 0),e([f({type:k,nonNullable:!0,json:{write:{ignoreOrigin:!0,writer:(e,t,r,i)=>{if(e.slides&&e.slides.length>0){const r={...i,isPresentation:!0};t.presentation=e.write({},r)}}}}})],X.prototype,"presentation",void 0),e([f({type:x,nonNullable:!0,json:{write:{target:"initialState",isRequired:!0,ignoreOrigin:!0},default:()=>new x({viewingMode:"global",spatialReference:R.WebMercator})}})],X.prototype,"initialViewProperties",void 0),e([v("initialViewProperties",["initialState.environment","spatialReference","viewingMode","initialState.viewpoint"])],X.prototype,"readInitialViewProperties",null),e([f({type:R,json:{read:!1,write:{isRequired:!0,ignoreOrigin:!0}}})],X.prototype,"spatialReference",null),e([f({type:["local","global"],json:{read:!1,write:{isRequired:!0,ignoreOrigin:!0}}})],X.prototype,"viewingMode",null),e([f({type:O})],X.prototype,"portalItem",void 0),e([f()],X.prototype,"resourceInfo",void 0),X=e([b("esri.WebScene")],X),function(e){e[e.SAVE=0]="SAVE",e[e.SAVE_AS=1]="SAVE_AS"}(Y||(Y={}));const Z=X;export{Z as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.27/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 c,wrapModuleScopedResponse as u}from"./FunctionWrapper.js";import{y as f,a as p,s as w,p as d,v as h,o as m,i as g,c as y,R as v,m as b,x as S,w as x,T as I,b as R,g as F,I as C,j as A,r as M,u as j,q as L}from"../chunks/languageUtils.js";import{addFunctionDeclaration as k}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as O}from"./functions/date.js";import{registerFunctions as E}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 T from"../geometry/Geometry.js";import U from"../geometry/SpatialReference.js";function q(e){return e&&"function"==typeof e.then}const W=100;async function V(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await J(e,t.arguments[r]));return n}async function _(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await V(e,t))}class Y 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,timeReference:this.context.timeReference??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 Pe(this.definition,n,t,null)}}call(e,t){return H(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,timeReference:e.timeReference??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 Pe(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,timeReference:e.timeReference??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!g(t)||t instanceof c?t:u(t,e,r))),u(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 J(this.executingContext,t.node),t.valueset=!0),g(t.value)&&!(t.value instanceof c)){const e=new c;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(g(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=Ge({},e.customfunctions,e.timeReference),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??Te,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await J(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed){const r=n(e,null,t.arguments);return q(r),r}const r=n(e,t,await V(e,t));return q(r),r}async function J(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,J(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 Z(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return m;case"EmptyStatement":return h;case"ContinueStatement":return d;case"TemplateElement":return await Le(e,t);case"TemplateLiteral":return await Ne(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 Re(e,t);case"BinaryExpression":return await Ce(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Fe(e,t);case"ObjectExpression":return await Q(e,t);case"Property":return await X(e,t);default:throw new r(e,o.Unrecognised,t)}}catch(i){throw a(e,t,i)}}async function Q(e,t){const a=[];for(let n=0;n<t.properties.length;n++)a[n]=await J(e,t.properties[n]);const i={},l=new Map;for(let n=0;n<a.length;n++){const s=a[n];if(g(s.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===y(s.key))throw new r(e,o.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===h?i[c]=null:i[c]=s.value}const s=new n(i);return s.immutable=!1,s}async function X(e,t){const n=await J(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await J(e,t.key),value:n}}async function Z(e,t){const n={testResult:!0,lastAction:h};if(n.testResult=await J(e,t.test),!1===n.testResult)return h;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await J(e,t.body),n.lastAction!==m)&&!(n.lastAction instanceof v);)if(n.testResult=await J(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof v?n.lastAction:h}async function $(e,t,n){const r=await J(e,t.body);return n.lastAction=r,n.lastAction===m||n.lastAction instanceof v?(n.testResult=!1,n):null!==t.update?(await J(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const a=await J(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 $(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>W?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof v?r(n.lastAction):r(h)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?J(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:h},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:h},(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(h);o.value="k"===i?n[a]:a,J(e,t.body).then((u=>{try{u instanceof v?l(u):u===m?l(h):++c>W?(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(h);r.value="k"===a?n.get(o):o,J(e,t.body).then((c=>{c instanceof v?i(c):c===m?i(h):++s>W?(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(h);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(h);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,l,s){try{e.next().then((c=>{try{if(null===c)a(h);else{const u=i.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeReference);u._underlyingGraphic=c,o.value=u;J(t,n.body).then((i=>{try{i===m?a(h):i instanceof v?a(i):++s>W?(s=0,setTimeout((()=>{se(e,t,n,r,o,a,l,s)}),0)):se(e,t,n,r,o,a,l,s)}catch(c){l(c)}}),(e=>{l(e)}))}}catch(u){l(u)}}),(e=>{l(e)}))}catch(c){l(c)}}async function ce(e,t){return new Promise(((a,i)=>{J(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?J(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 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 i(new r(e,o.InvalidIdentifier,t));b(l)||y(l)?ae(e,t,l,{reject:i,resolve:a},c):S(l)?ie(e,t,l,{reject:i,resolve:a},c):l instanceof n||x(l)?le(e,t,l,{reject:i,resolve:a},c):I(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{a(e)}),(e=>{i(e)}),0):ae(e,t,[],{reject:i,resolve:a},c)}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 J(e,a.object);let s=null;i.t=l,!0===a.computed?s=await J(e,a.property):"Identifier"===a.property.type&&(s=a.property.name);const c=i.t;let u;if(b(c)){if(!R(s))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new r(e,o.OutOfBounds,t);u=F(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof n){if(!1===y(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=F(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===y(s))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new r(e,o.ModuleExportNotFound,t);u=F(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!x(c))throw S(c)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===y(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=F(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-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=F(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=F(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 fe(e,t,n,a,i){switch(t){case"=":return e===h?null:e;case"/=":return F(n)/F(e);case"*=":return F(n)*F(e);case"-=":return F(n)-F(e);case"+=":return y(n)||y(e)?A(n)+A(e):F(n)+F(e);case"%=":return F(n)%F(e);default:throw new r(i,o.UnsupportedOperator,a)}}async function pe(e,t){const a=t.left;if("MemberExpression"===a.type){const i=await J(e,a.object);let l=null;if(!0===a.computed)l=await J(e,a.property);else{if("Identifier"!==a.property.type)throw new r(e,o.InvalidIdentifier,t);l=a.property.name}const s=await J(e,t.right);if(b(i)){if(!R(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]=fe(s,t.operator,i[l],t,e)}else i[l]=fe(s,t.operator,i[l],t,e)}else if(i instanceof n){if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}else if(i instanceof z){if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasGlobal(l))throw new r(e,o.ModuleExportNotFound,t);i.setGlobal(l,fe(s,t.operator,await i.global(l),t,e))}else{if(!x(i))throw S(i)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}return h}const i=a.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[i]){const n=await J(e,t.right);return e.localScope[i]={value:fe(n,t.operator,e.localScope[i].value,t,e),valueset:!0,node:t.right},h}if(void 0!==e.globalScope[i]){const n=await J(e,t.right);return e.globalScope[i]={value:fe(n,t.operator,e.globalScope[i].value,t,e),valueset:!0,node:t.right},h}throw new r(e,o.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return J(e,t.expression);if("CallExpression"===t.expression.type){const n=await J(e,t.expression);return n===h?h:new C(n)}const n=await J(e,t.expression);return n===h?h:new C(n)}async function de(e,t){const n=await J(e,t.test);if(!0===n)return J(e,t.consequent);if(!1===n)return null!==t.alternate?J(e,t.alternate):h;throw new r(e,o.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return h;const r=await J(e,t.body[n]);return r instanceof v||r===m||r===d||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new v(h);const n=await J(e,t.argument);return new v(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new Y(t,e)},h}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},h}async function be(e,t){if(await J(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 h}async function Se(e,t,n){return n>=t.declarations.length?h:(await J(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),h)}async function xe(e,t){let n=null;if(n=null===t.init?null:await J(e,t.init),null!==e.localScope){if(n===h&&(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}),h}if("Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return n===h&&(n=null),e.globalScope[a]={value:n,valueset:!0,node:t.init},h}async function Ie(e,t){const a=await J(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||x(a))return a.field(t.property.name);if(a instanceof T)return P(a,t.property.name,e,t);if(a instanceof z){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 J(e,t.property);if(a instanceof n||x(a)){if(y(i))return a.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof z){if(y(i))return a.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof T){if(y(i))return P(a,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(b(a)){if(R(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(S(a)){if(R(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(y(a)){if(R(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 Re(e,t){const n=await J(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*F(n);if("+"===t.operator)return 1*F(n);if("~"===t.operator)return~F(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*F(n);if("+"===t.operator)return 1*F(n);if("~"===t.operator)return~F(n);throw new r(e,o.UnsupportedUnaryOperator,t)}async function Fe(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await J(e,t.elements[r]));for(let a=0;a<n.length;a++){if(g(n[a]))throw new r(e,o.NoFunctionInArray,t);n[a]===h&&(n[a]=null)}return n}async function Ce(e,t){const n=[];n[0]=await J(e,t.left),n[1]=await J(e,t.right);const a=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(F(a),F(i),t.operator);case"==":return w(a,i);case"!=":return!w(a,i);case"<":case">":case"<=":case">=":return M(a,i,t.operator);case"+":return y(a)||y(i)?A(a)+A(i):F(a)+F(i);case"-":return F(a)-F(i);case"*":return F(a)*F(i);case"/":return F(a)/F(i);case"%":return F(a)%F(i);default:throw new r(e,o.UnsupportedOperator,t)}}async function Ae(e,t){const n=await J(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 J(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(a=await J(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);default:throw new r(e,o.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=J(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=J(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 je(e,t){if("MemberExpression"===t.callee.type){const n=await J(e,t.callee.object);if(!(n instanceof z))throw new r(e,o.FuncionNotFound,t);const a=!1===t.callee.computed?t.callee.property.name:await J(e,t.callee.property);if(!n.hasGlobal(a))throw new r(e,o.FuncionNotFound,t);const i=await n.global(a);if(!g(i))throw new r(e,o.CallNonFunction,t);return i.call(e,t)}if("Identifier"!==t.callee.type)throw new r(e,o.FuncionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(g(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(g(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FuncionNotFound,t)}async function Le(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(g(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}async function Ne(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await J(e,t.expressions[a]);n[a]=A(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 Oe={};async function Ee(e,t,n,r){const o=await J(e,t.arguments[n]);if(w(o,r))return J(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?J(e,t.arguments[n]):2===a?null:3===a?J(e,t.arguments[n+2]):Ee(e,t,n+2,r)}async function Be(e,t,n,a){if(!0===a)return J(e,t.arguments[n+1]);if(3===t.arguments.length-n)return J(e,t.arguments[n+2]);const i=await J(e,t.arguments[n+2]);if(!1===p(i))throw new r(e,o.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,i)}async function Pe(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 J(t,i);if(l instanceof v)return l.value;if(l===m)throw new r(t,o.UnexpectedToken,a);if(l===d)throw new r(t,o.UnexpectedToken,a);return l instanceof C?l.value:l}O(Oe,_),G(Oe,_),K(Oe,_),B(Oe,_),D(Oe,_),E({functions:Oe,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:_,standardFunctionAsync:H}),Oe.iif=async function(e,t){f(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await J(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t);return J(e,n?t.arguments[1]:t.arguments[2])},Oe.decode=async function(e,t){if(t.arguments.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===t.arguments.length)return J(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);return Ee(e,t,1,await J(e,t.arguments[0]))},Oe.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 J(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:L,parseArguments:V,standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Me};for(const Ve in Oe)Oe[Ve]={value:new l(Oe[Ve]),valueset:!0,node:null};const De=function(){};function Ge(e,t,r){const o=new De;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 Te(e){console.log(e)}De.prototype=Oe,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ue=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Oe[n]={value:new l(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Oe[n];for(let n=0;n<t.signatures.length;n++)k(t.signatures[n],"async")}async function We(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=Ge(n.vars,n.customfunctions,n.timeReference),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??Te,timeReference:n.timeReference??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await J(s,e);if(c instanceof v&&(c=c.value),c instanceof C&&(c=c.value),c===h&&(c=null),c===m)throw new r(s,o.IllegalResult,null);if(c===d)throw new r(s,o.IllegalResult,null);if(g(c))throw new r(s,o.IllegalResult,null);return c}qe([N]);export{We as executeScript,qe as extend,Ue as functionHelper};
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 c,wrapModuleScopedResponse as u}from"./FunctionWrapper.js";import{y as f,a as p,s as w,p as d,v as h,o as m,i as g,c as y,R as v,m as b,x as S,w as x,T as I,b as R,g as F,I as C,j as A,r as M,u as j,q as L}from"../chunks/languageUtils.js";import{addFunctionDeclaration as k}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as O}from"./functions/date.js";import{registerFunctions as E}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 T from"../geometry/Geometry.js";import U from"../geometry/SpatialReference.js";function q(e){return e&&"function"==typeof e.then}const W=100;async function V(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await J(e,t.arguments[r]));return n}async function _(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await V(e,t))}class Y 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,timeReference:this.context.timeReference??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 Pe(this.definition,n,t,null)}}call(e,t){return H(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,timeReference:e.timeReference??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 Pe(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,timeReference:e.timeReference??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!g(t)||t instanceof c?t:u(t,e,r))),u(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 J(this.executingContext,t.node),t.valueset=!0),g(t.value)&&!(t.value instanceof c)){const e=new c;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(g(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=Ge({},e.customfunctions,e.timeReference),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??Te,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await J(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed){const r=n(e,null,t.arguments);return q(r),r}const r=n(e,t,await V(e,t));return q(r),r}async function J(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,J(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 Z(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return m;case"EmptyStatement":return h;case"ContinueStatement":return d;case"TemplateElement":return await Le(e,t);case"TemplateLiteral":return await Ne(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 Re(e,t);case"BinaryExpression":return await Ce(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Fe(e,t);case"ObjectExpression":return await Q(e,t);case"Property":return await X(e,t);default:throw new r(e,o.Unrecognised,t)}}catch(i){throw a(e,t,i)}}async function Q(e,t){const a=[];for(let n=0;n<t.properties.length;n++)a[n]=await J(e,t.properties[n]);const i={},l=new Map;for(let n=0;n<a.length;n++){const s=a[n];if(g(s.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===y(s.key))throw new r(e,o.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===h?i[c]=null:i[c]=s.value}const s=new n(i);return s.immutable=!1,s}async function X(e,t){const n=await J(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await J(e,t.key),value:n}}async function Z(e,t){const n={testResult:!0,lastAction:h};if(n.testResult=await J(e,t.test),!1===n.testResult)return h;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await J(e,t.body),n.lastAction!==m)&&!(n.lastAction instanceof v);)if(n.testResult=await J(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof v?n.lastAction:h}async function $(e,t,n){const r=await J(e,t.body);return n.lastAction=r,n.lastAction===m||n.lastAction instanceof v?(n.testResult=!1,n):null!==t.update?(await J(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const a=await J(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 $(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>W?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof v?r(n.lastAction):r(h)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?J(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:h},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:h},(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(h);o.value="k"===i?n[a]:a,J(e,t.body).then((u=>{try{u instanceof v?l(u):u===m?l(h):++c>W?(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(h);r.value="k"===a?n.get(o):o,J(e,t.body).then((c=>{c instanceof v?i(c):c===m?i(h):++s>W?(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(h);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(h);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,l,s){try{e.next().then((c=>{try{if(null===c)a(h);else{const u=i.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeReference);u._underlyingGraphic=c,o.value=u;J(t,n.body).then((i=>{try{i===m?a(h):i instanceof v?a(i):++s>W?(s=0,setTimeout((()=>{se(e,t,n,r,o,a,l,s)}),0)):se(e,t,n,r,o,a,l,s)}catch(c){l(c)}}),(e=>{l(e)}))}}catch(u){l(u)}}),(e=>{l(e)}))}catch(c){l(c)}}async function ce(e,t){return new Promise(((a,i)=>{J(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?J(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 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 i(new r(e,o.InvalidIdentifier,t));b(l)||y(l)?ae(e,t,l,{reject:i,resolve:a},c):S(l)?ie(e,t,l,{reject:i,resolve:a},c):l instanceof n||x(l)?le(e,t,l,{reject:i,resolve:a},c):I(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{a(e)}),(e=>{i(e)}),0):ae(e,t,[],{reject:i,resolve:a},c)}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 J(e,a.object);let s=null;i.t=l,!0===a.computed?s=await J(e,a.property):"Identifier"===a.property.type&&(s=a.property.name);const c=i.t;let u;if(b(c)){if(!R(s))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new r(e,o.OutOfBounds,t);u=F(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof n){if(!1===y(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=F(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===y(s))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new r(e,o.ModuleExportNotFound,t);u=F(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!x(c))throw S(c)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===y(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=F(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-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=F(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=F(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 fe(e,t,n,a,i){switch(t){case"=":return e===h?null:e;case"/=":return F(n)/F(e);case"*=":return F(n)*F(e);case"-=":return F(n)-F(e);case"+=":return y(n)||y(e)?A(n)+A(e):F(n)+F(e);case"%=":return F(n)%F(e);default:throw new r(i,o.UnsupportedOperator,a)}}async function pe(e,t){const a=t.left;if("MemberExpression"===a.type){const i=await J(e,a.object);let l=null;if(!0===a.computed)l=await J(e,a.property);else{if("Identifier"!==a.property.type)throw new r(e,o.InvalidIdentifier,t);l=a.property.name}const s=await J(e,t.right);if(b(i)){if(!R(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]=fe(s,t.operator,i[l],t,e)}else i[l]=fe(s,t.operator,i[l],t,e)}else if(i instanceof n){if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}else if(i instanceof z){if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasGlobal(l))throw new r(e,o.ModuleExportNotFound,t);i.setGlobal(l,fe(s,t.operator,await i.global(l),t,e))}else{if(!x(i))throw S(i)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===y(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}return h}const i=a.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[i]){const n=await J(e,t.right);return e.localScope[i]={value:fe(n,t.operator,e.localScope[i].value,t,e),valueset:!0,node:t.right},h}if(void 0!==e.globalScope[i]){const n=await J(e,t.right);return e.globalScope[i]={value:fe(n,t.operator,e.globalScope[i].value,t,e),valueset:!0,node:t.right},h}throw new r(e,o.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return J(e,t.expression);if("CallExpression"===t.expression.type){const n=await J(e,t.expression);return n===h?h:new C(n)}const n=await J(e,t.expression);return n===h?h:new C(n)}async function de(e,t){const n=await J(e,t.test);if(!0===n)return J(e,t.consequent);if(!1===n)return null!==t.alternate?J(e,t.alternate):h;throw new r(e,o.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return h;const r=await J(e,t.body[n]);return r instanceof v||r===m||r===d||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new v(h);const n=await J(e,t.argument);return new v(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new Y(t,e)},h}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},h}async function be(e,t){if(await J(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 h}async function Se(e,t,n){return n>=t.declarations.length?h:(await J(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),h)}async function xe(e,t){let n=null;if(n=null===t.init?null:await J(e,t.init),null!==e.localScope){if(n===h&&(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}),h}if("Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return n===h&&(n=null),e.globalScope[a]={value:n,valueset:!0,node:t.init},h}async function Ie(e,t){const a=await J(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||x(a))return a.field(t.property.name);if(a instanceof T)return P(a,t.property.name,e,t);if(a instanceof z){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 J(e,t.property);if(a instanceof n||x(a)){if(y(i))return a.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof z){if(y(i))return a.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof T){if(y(i))return P(a,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(b(a)){if(R(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(S(a)){if(R(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(y(a)){if(R(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 Re(e,t){const n=await J(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*F(n);if("+"===t.operator)return 1*F(n);if("~"===t.operator)return~F(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*F(n);if("+"===t.operator)return 1*F(n);if("~"===t.operator)return~F(n);throw new r(e,o.UnsupportedUnaryOperator,t)}async function Fe(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await J(e,t.elements[r]));for(let a=0;a<n.length;a++){if(g(n[a]))throw new r(e,o.NoFunctionInArray,t);n[a]===h&&(n[a]=null)}return n}async function Ce(e,t){const n=[];n[0]=await J(e,t.left),n[1]=await J(e,t.right);const a=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(F(a),F(i),t.operator);case"==":return w(a,i);case"!=":return!w(a,i);case"<":case">":case"<=":case">=":return M(a,i,t.operator);case"+":return y(a)||y(i)?A(a)+A(i):F(a)+F(i);case"-":return F(a)-F(i);case"*":return F(a)*F(i);case"/":return F(a)/F(i);case"%":return F(a)%F(i);default:throw new r(e,o.UnsupportedOperator,t)}}async function Ae(e,t){const n=await J(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 J(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(a=await J(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);default:throw new r(e,o.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=J(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=J(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 je(e,t){if("MemberExpression"===t.callee.type){const n=await J(e,t.callee.object);if(!(n instanceof z))throw new r(e,o.FunctionNotFound,t);const a=!1===t.callee.computed?t.callee.property.name:await J(e,t.callee.property);if(!n.hasGlobal(a))throw new r(e,o.FunctionNotFound,t);const i=await n.global(a);if(!g(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(g(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(g(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FunctionNotFound,t)}async function Le(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(g(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}async function Ne(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await J(e,t.expressions[a]);n[a]=A(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 Oe={};async function Ee(e,t,n,r){const o=await J(e,t.arguments[n]);if(w(o,r))return J(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?J(e,t.arguments[n]):2===a?null:3===a?J(e,t.arguments[n+2]):Ee(e,t,n+2,r)}async function Be(e,t,n,a){if(!0===a)return J(e,t.arguments[n+1]);if(3===t.arguments.length-n)return J(e,t.arguments[n+2]);const i=await J(e,t.arguments[n+2]);if(!1===p(i))throw new r(e,o.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,i)}async function Pe(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 J(t,i);if(l instanceof v)return l.value;if(l===m)throw new r(t,o.UnexpectedToken,a);if(l===d)throw new r(t,o.UnexpectedToken,a);return l instanceof C?l.value:l}O(Oe,_),G(Oe,_),K(Oe,_),B(Oe,_),D(Oe,_),E({functions:Oe,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:_,standardFunctionAsync:H}),Oe.iif=async function(e,t){f(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await J(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t);return J(e,n?t.arguments[1]:t.arguments[2])},Oe.decode=async function(e,t){if(t.arguments.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===t.arguments.length)return J(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);return Ee(e,t,1,await J(e,t.arguments[0]))},Oe.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 J(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:L,parseArguments:V,standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Me};for(const Ve in Oe)Oe[Ve]={value:new l(Oe[Ve]),valueset:!0,node:null};const De=function(){};function Ge(e,t,r){const o=new De;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 Te(e){console.log(e)}De.prototype=Oe,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ue=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Oe[n]={value:new l(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Oe[n];for(let n=0;n<t.signatures.length;n++)k(t.signatures[n],"async")}async function We(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=Ge(n.vars,n.customfunctions,n.timeReference),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??Te,timeReference:n.timeReference??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await J(s,e);if(c instanceof v&&(c=c.value),c instanceof C&&(c=c.value),c===h&&(c=null),c===m)throw new r(s,o.IllegalResult,null);if(c===d)throw new r(s,o.IllegalResult,null);if(g(c))throw new r(s,o.IllegalResult,null);return c}qe([N]);export{We as executeScript,qe as extend,Ue 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.27/esri/copyright.txt for details.
4
4
  */
5
- import e from"./Dictionary.js";import n from"./Feature.js";import{i as t,n as o,R as l,I as r,v as a,o as s,p as i,q as c,j as u,c as p,a as m,g,r as d,s as f,u as h,m as y,b,w,x as S}from"../chunks/languageUtils.js";import{addFunctionDeclaration as v}from"./treeAnalysis.js";import{A as x}from"../chunks/array.js";import{registerFunctions as M}from"./functions/date.js";import{registerFunctions as F,geometryMember as C}from"./functions/geometry.js";import{registerFunctions as I}from"./functions/geomsync.js";import{registerFunctions as A}from"./functions/maths.js";import{registerFunctions as _}from"./functions/stats.js";import{registerFunctions as O}from"./functions/string.js";import{isPromiseLike as k}from"../core/promiseUtils.js";import E from"../geometry/Geometry.js";import R from"../geometry/SpatialReference.js";import{ArcadeModuleLoader as G}from"./ArcadeModuleLoader.js";import{ArcadeModule as B}from"./ArcadeModule.js";import{NativeFunction as $,ArcadeFunction as j,ScopeMarshalledFunction as N,wrapModuleScopedResponse as L}from"./FunctionWrapper.js";import{ArcadeExecutionError as U,ExecutionErrorCodes as D,ArcadeCompilationError as P,ArcadeUncompilableError as K}from"./executionError.js";class T extends j{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new U(e,D.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,o,l){return l(e,n,((n,r,a)=>{a=a.map((n=>!t(n)||n instanceof N?n:L(n,e,l)));const s=this.call(o,{arguments:a});return k(s)?s.then((e=>L(e,o,l))):s}))}}function q(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(V(e,n.arguments[o]));return t}function W(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 ue(e,n);case"VariableDeclaration":return ce(e,n);case"BlockStatement":case"Program":return oe(e,n);case"FunctionDeclaration":return ie(e,n);case"ImportDeclaration":return re(e,n);case"ExportNamedDeclaration":return ae(e,n);case"ReturnStatement":return le(e,n);case"IfStatement":return te(e,n);case"ExpressionStatement":return ee(e,n);case"AssignmentExpression":return Z(e,n);case"UpdateExpression":return Q(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"TemplateLiteral":return de(e,n);case"TemplateElement":return JSON.stringify(n.value?n.value.cooked:"");case"ForStatement":return H(e,n);case"ForInStatement":return Y(e,n);case"WhileStatement":return X(e,n);case"Identifier":return ye(e,n);case"MemberExpression":return pe(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return be(e,n);case"UnaryExpression":return me(e,n);case"BinaryExpression":return fe(e,n);case"LogicalExpression":return he(e,n);case"ArrayExpression":return ge(e,n);case"ObjectExpression":return J(e,n);case"Property":return z(e,n);case"Array":throw new P(e,D.NeverReach,n);default:throw new P(e,D.Unrecognised,n)}}catch(t){throw t}}function J(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];se(l.key.name);o>0&&(t+=","),t+="lang.strCheck("+("Identifier"===l.key.type?"'"+l.key.name+"'":V(e,l.key))+",'ObjectExpression'),lang.aCheck("+V(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function z(e,n){throw new P(e,D.NeverReach,n)}function Y(e,n){const t=Fe(e),o=Fe(e),l=Fe(e);let r="var "+t+" = "+V(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(r+=V(e,n.left));let a="VariableDeclaration"===n.left.type?n.left.declarations[0].id.name:n.left.name;a=a.toLowerCase(),se(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:Me(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+=V(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+=V(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+=V(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+=V(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n"),r+="else { lastStatement = lc.voidOperation; } \n",r}function H(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&(t+=V(e,n.init)+"; ");const o=Fe(e),l=Fe(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('"+D.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 Q(e,n){let t=null,o="";if("MemberExpression"===n.argument.type)return t=V(e,n.argument.object),!0===n.argument.computed?o=V(e,n.argument.property):(o="'"+n.argument.property.name+"'",se(n.argument.property.name)),"lang.memberupdate("+t+","+o+",'"+n.operator+"',"+n.prefix+")";if(t=n.argument.name.toLowerCase(),se(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:Me(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"lang.update(gscope, lang.chkAssig('"+o.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new U(e,D.InvalidIdentifier,n)}function X(e,n){let t="lastStatement = lc.voidOperation; \n";const o=Fe(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('${D.BooleanConditionRequired}');\n }\n ${V(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function Z(e,n){const t=V(e,n.right);let o=null,l="";if("MemberExpression"===n.left.type)return o=V(e,n.left.object),!0===n.left.computed?l=V(e,n.left.property):(l="'"+n.left.property.name+"'",se(n.left.property.name)),"lang.assignmember("+o+","+l+",'"+n.operator+"',"+t+")";if(o=n.left.name.toLowerCase(),se(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:Me(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 U(e,D.InvalidIdentifier,n)}function ee(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+V(e,n.expression)+"; \n ":(n.expression.type,"lastStatement = "+V(e,n.expression)+"; ")}function ne(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 te(e,n){if("AssignmentExpression"===n.test.type||"UpdateExpression"===n.test.type)throw new P(e,D.BooleanConditionRequired,n);return`if (lang.mustBoolean(${V(e,n.test)}, runtimeCtx) === true) {\n ${ne(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+te(e,n.alternate):` else {\n ${ne(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function oe(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 le(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+V(e,n.argument)}function re(e,n){const t=n.specifiers[0].local.name.toLowerCase();se(t);const o=e.libraryResolver?.loadLibrary(t),l=Me(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=De(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeReference:e.timeReference??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=Me(e),e.globalScope._SymbolsMap[t]=a,e.mangleMap[t]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+r}function ae(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 se(e){if("iif"===e)throw new K;if("decode"===e)throw new K;if("when"===e)throw new K}function ie(e,n){const t=n.id.name.toLowerCase();se(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=Me(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();se(t);const o=Me(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+=oe(r,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=oe(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 ce(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 ue(e,n){let t=null===n.init?null:V(e,n.init);t===a&&(t=null);const o=n.id.name.toLowerCase();if(se(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=Me(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=Me(e);return e.globalScope._SymbolsMap[o]=l,e.mangleMap[o]=l,"gscope['"+l+"']="+t+"; "}function pe(e,n){try{let t;return!0===n.computed?t=V(e,n.property):(t="'"+n.property.name+"'",se(n.property.name)),"lang.member("+V(e,n.object)+","+t+")"}catch(t){throw t}}function me(e,n){try{return"lang.unary("+V(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function ge(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 de(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("+V(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function fe(e,n){try{return"lang.binary("+V(e,n.left)+","+V(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function he(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new P(e,D.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new P(e,D.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+V(e,n.left)+") "+n.operator+" lang.logicalCheck("+V(e,n.right)+"))";throw new P(null,D.LogicExpressionOrAnd,null)}catch(t){throw t}}function ye(e,n){try{const t=n.name.toLowerCase();if(se(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:Me(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new P(e,D.InvalidIdentifier,n)}catch(t){throw t}}function be(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+"'",se(n.callee.property.name));let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=V(e,n.arguments[l]);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 P(e,D.FuncionNotFound,n);const t=n.callee.name.toLowerCase();if("iif"===t)return we(e,n);if("when"===t)return Se(e,n);if("decode"===t)return ve(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:Me(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+=V(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new P(e,D.FuncionNotFound,n)}catch(t){throw t}}function we(e,n){try{if(3!==n.arguments.length)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(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 Se(e,n){try{if(n.arguments.length<3)throw new P(e,D.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${V(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${V(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 ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function ve(e,n){try{if(n.arguments.length<2)throw new P(e,D.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${V(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(e),o=Fe(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${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 ${l}\n return ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const xe={};function Me(e){return e.symbols.symbolCounter++,"_T"+e.symbols.symbolCounter.toString()}function Fe(e){return e.symbols.symbolCounter++,"_Tvar"+e.symbols.symbolCounter.toString()}M(xe,W),O(xe,W),A(xe,W),F(xe,W),_(xe,W),xe.iif=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}},xe.decode=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}},xe.when=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}};const Ce={};for(const Pe in xe)Ce[Pe]=new $(xe[Pe]);I(xe,W);for(const Pe in xe)xe[Pe]=new $(xe[Pe]);const Ie=function(){};Ie.prototype=xe;const Ae=function(){};function _e(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 Oe(t,o,l,r){const a=l?new Ae:new Ie;t||(t={}),o||(o={});const s=new e({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});s.immutable=!1,a._SymbolsMap={textformatting:1,infinity:1,pi:1},a.textformatting=s,a.infinity=Number.POSITIVE_INFINITY,a.pi=Math.PI;for(const e in o)a[e]=o[e],a._SymbolsMap[e]=1;for(const e in t)a._SymbolsMap[e]=1,t[e]&&"esri.Graphic"===t[e].declaredClass?a[e]=n.createFromGraphic(t[e],r??null):a[e]=t[e];return a}Ae.prototype=Ce;const ke={fixSpatialReference:c,parseArguments:q,standardFunction:W};function Ee(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:W,standardFunctionAsync:W,evaluateIdentifier:Ge};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)xe[e]=new $(t.functions[e]),Ie.prototype[e]=xe[e];for(let e=0;e<t.signatures.length;e++)v(t.signatures[e],"sync")}else{for(const e in t.functions)Ce[e]=new $(t.functions[e]),Ae.prototype[e]=Ce[e];for(let e=0;e<t.signatures.length;e++)v(t.signatures[e],"async")}}function Re(e,n){return e(n)}function Ge(e,n){const t=n.name;if("_SymbolsMap"===t)throw new U(e,D.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}Ee([x],"sync"),Ee([x],"async");let Be=0;const $e={error(e){throw new U(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&&e.value.then?e.value.then(r,a):(Be++,Be%100==0?setTimeout((()=>{Be=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 U(null,D.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 U(n,D.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new U(n,D.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>u(e),aCheck(e,n){if(t(e)){if("ArrayExpression"===n)throw new U(null,D.NoFunctionInArray,null);if("ObjectExpression"===n)throw new U(null,D.NoFunctionInDictionary,null);throw new U(null,D.NoFunctionInTemplateLiteral,null)}return e===a?null:e},Dictionary:e,Feature:n,UserDefinedCompiledFunction:T,dictionary(n){const o={},l=new Map;for(let e=0;e<n.length;e+=2){if(t(n[e+1]))throw new U(null,D.NoFunctionInDictionary,null);if(!1===p(n[e]))throw new U(null,D.KeyMustBeString,null);let r=n[e].toString();const s=r.toLowerCase();l.has(s)?r=l.get(s):l.set(s,r),n[e+1]===a?o[r]=null:o[r]=n[e+1]}const r=new e(o);return r.immutable=!1,r},strCheck(e){if(!1===p(e))throw new U(null,D.KeyMustBeString,null);return e},unary(e,n){if(m(e)){if("!"===n)return!e;if("-"===n)return-1*g(e);if("+"===n)return 1*g(e);if("~"===n)return~g(e);throw new U(null,D.UnsupportedUnaryOperator,null)}if("-"===n)return-1*g(e);if("+"===n)return 1*g(e);if("~"===n)return~g(e);throw new U(null,D.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===m(e))throw new U(null,D.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(m(e)&&m(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new U(null,D.LogicExpressionOrAnd,null)}throw new U(null,D.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return h(g(e),g(n),t);case"==":case"=":return f(e,n);case"!=":return!f(e,n);case"<":case">":case"<=":case">=":return d(e,n,t);case"+":return p(e)||p(n)?u(e)+u(n):g(e)+g(n);case"-":return g(e)-g(n);case"*":return g(e)*g(n);case"/":return g(e)/g(n);case"%":return g(e)%g(n);default:throw new U(null,D.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===a?null:e;case"/=":return g(t)/g(e);case"*=":return g(t)*g(e);case"-=":return g(t)-g(e);case"+=":return p(t)||p(e)?u(t)+u(e):g(t)+g(e);case"%=":return g(t)%g(e);default:throw new U(null,D.UnsupportedOperator,null)}},update(e,n,t,o){const l=g(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,t,o)=>null===e?null:n.createFromGraphicLikeObject(e.geometry,e.attributes,t,o.timeReference),memberupdate(n,t,o,l){let r;if(y(n)){if(!b(t))throw new U(null,D.ArrayAccessorMustBeNumber,null);if(t<0&&(t=n.length+t),t<0||t>=n.length)throw new U(null,D.OutOfBounds,null);r=g(n[t]),n[t]="++"===o?r+1:r-1}else if(n instanceof e){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0!==n.hasField(t))throw new U(null,D.FieldNotFound,null,{key:t});r=g(n.field(t)),n.setField(t,"++"===o?r+1:r-1)}else if(w(n)){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0!==n.hasField(t))throw new U(null,D.FieldNotFound,null);r=g(n.field(t)),n.setField(t,"++"===o?r+1:r-1)}else{if(S(n))throw new U(null,D.Immutable,null);if(!(n instanceof Ue))throw new U(null,D.InvalidIdentifier,null);if(!1===p(t))throw new U(null,D.ModuleAccessorMustBeString,null);if(!0!==n.hasGlobal(t))throw new U(null,D.ModuleExportNotFound,null);r=g(n.global(t)),n.setGlobal(t,"++"===o?r+1:r-1)}return!1===l?r:"++"===o?r+1:r-1},assignmember(n,t,o,l){if(y(n)){if(!b(t))throw new U(null,D.ArrayAccessorMustBeNumber,null);if(t<0&&(t=n.length+t),t<0||t>n.length)throw new U(null,D.OutOfBounds,null);if(t===n.length){if("="!==o)throw new U(null,D.OutOfBounds,null);n[t]=this.assign(l,o,n[t])}else n[t]=this.assign(l,o,n[t])}else if(n instanceof e){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0===n.hasField(t))n.setField(t,this.assign(l,o,n.field(t)));else{if("="!==o)throw new U(null,D.FieldNotFound,null);n.setField(t,this.assign(l,o,null))}}else if(w(n)){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0===n.hasField(t))n.setField(t,this.assign(l,o,n.field(t)));else{if("="!==o)throw new U(null,D.FieldNotFound,null);n.setField(t,this.assign(l,o,null))}}else{if(S(n))throw new U(null,D.Immutable,null);if(!(n instanceof Ue))throw new U(null,D.InvalidIdentifier,null);if(!1===p(t))throw new U(null,D.ModuleAccessorMustBeString,null);if(!n.hasGlobal(t))throw new U(null,D.ModuleExportNotFound,null);n.setGlobal(t,this.assign(l,o,n.global(t)))}},member(n,t){if(null===n)throw new U(null,D.MemberOfNull,null);if(n instanceof e||w(n)){if(p(t))return n.field(t);throw new U(null,D.InvalidMemberAccessKey,null)}if(n instanceof E){if(p(t))return C(n,t,null,null);throw new U(null,D.InvalidMemberAccessKey,null)}if(y(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length+t),t>=n.length||t<0)throw new U(null,D.OutOfBounds,null);return n[t]}throw new U(null,D.InvalidMemberAccessKey,null)}if(p(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length+t),t>=n.length||t<0)throw new U(null,D.OutOfBounds,null);return n[t]}throw new U(null,D.InvalidMemberAccessKey,null)}if(S(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length()+t),t>=n.length()||t<0)throw new U(null,D.OutOfBounds,null);return n.get(t)}throw new U(null,D.InvalidMemberAccessKey,null)}if(n instanceof Ue){if(p(t))return n.global(t);throw new U(null,D.InvalidMemberAccessKey,null)}throw new U(null,D.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,timeReference:n.timeReference??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,o,l){if(!(e instanceof Ue))throw new U(null,D.FuncionNotFound,null);const r=e.global(o);if(!1===t(r))throw new U(null,D.CallNonFunction,null);return r.call(l,{preparsed:!0,arguments:n})}};function je(e){console.log(e)}function Ne(e,n,c=!1){null===n&&(n={vars:{},customfunctions:{}});let u=null;e.usesModules&&(u=new G(null,e.loadedModules));const p={isAsync:c,globalScope:_e(n.vars,c?Ce:xe,n.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:n.customfunctions,libraryResolver:u,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:je,lrucache:n.lrucache,timeReference:n.timeReference??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let m=V(p,e);""===m&&(m="lc.voidOperation; "),p.undeclaredGlobalsInFunctions.size>0&&p.undeclaredGlobalsInFunctions.forEach((e=>{throw new P(n,D.InvalidIdentifier,e.node)}));let g="";g=c?"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"+m+"\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 "+m+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const d=p.moduleFactory,f=p.moduleFactoryMap,h=p.exports,y={};for(const t in h)y[t]=void 0!==p.mangleMap[t]?p.mangleMap[t]:t;const b={lc:o,lang:$e,mangles:p.mangleMap,postProcess(e){if(e instanceof l&&(e=e.value),e instanceof r&&(e=e.value),e===a&&(e=null),e===s)throw new U(null,D.IllegalResult,null);if(e===i)throw new U(null,D.IllegalResult,null);if(t(e))throw new U(null,D.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=R.WebMercator);const o=Oe(e.vars,e.customfunctions,n,e.timeReference);return{localStack:[],isAsync:n,moduleFactory:d,moduleFactoryMap:f,mangleMap:this.mangles,moduleSingletons:{},exports:h,gdefs:{},exportmangle:y,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??je,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",g).bind(b)}async function Le(){return Ee([await import("./functions/geomasync.js")],"async"),!0}class Ue extends B{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 o=this.moduleContext.globalScope,l=e.toLowerCase();if(t(n))throw new U(null,D.AssignModuleFunction,null);o[this.moduleContext.exportmangle[l]]=n}global(e){const n=this.moduleContext.globalScope;e=e.toLowerCase();const o=n[this.moduleContext.exportmangle[e]];if(void 0===o)throw new U(null,D.InvalidIdentifier,null);if(t(o)&&!(o instanceof N)){const t=new N;return t.fn=o,t.parameterEvaluator=W,t.context=this.moduleContext,n[this.moduleContext.exportmangle[e]]=t,t}return o}}function De(e,n,t=!1){const l={isAsync:t,moduleFactory:n.moduleFactory,moduleFactoryMap:{},libraryResolver:new G(null,e.loadedModules),globalScope:_e(n.vars,t?Ce:xe,n.customfunctions),customfunctions:n.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:je,lrucache:n.lrucache,timeReference:n.timeReference??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let r=V(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=t?"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 o in c)u[o]=void 0!==l.mangleMap[o]?l.mangleMap[o]:o;const p={lc:o,lang:$e,mangles:l.mangleMap,prepareModule:e=>new Ue(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new R({wkid:102100}));const o=Oe(e.vars,e.customfunctions,n,e.timeReference);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??je,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(p)}export{T as UserDefinedCompiledFunction,Ne as compileScript,Le as enableAsyncSupport,Re as executeScript,Ee as extend,ke as functionHelper};
5
+ import e from"./Dictionary.js";import n from"./Feature.js";import{i as t,n as o,R as l,I as r,v as a,o as s,p as i,q as c,j as u,c as p,a as m,g,r as d,s as f,u as h,m as y,b,w,x as S}from"../chunks/languageUtils.js";import{addFunctionDeclaration as v}from"./treeAnalysis.js";import{A as x}from"../chunks/array.js";import{registerFunctions as M}from"./functions/date.js";import{registerFunctions as F,geometryMember as C}from"./functions/geometry.js";import{registerFunctions as I}from"./functions/geomsync.js";import{registerFunctions as A}from"./functions/maths.js";import{registerFunctions as _}from"./functions/stats.js";import{registerFunctions as O}from"./functions/string.js";import{isPromiseLike as k}from"../core/promiseUtils.js";import E from"../geometry/Geometry.js";import R from"../geometry/SpatialReference.js";import{ArcadeModuleLoader as G}from"./ArcadeModuleLoader.js";import{ArcadeModule as B}from"./ArcadeModule.js";import{NativeFunction as $,ArcadeFunction as j,ScopeMarshalledFunction as N,wrapModuleScopedResponse as L}from"./FunctionWrapper.js";import{ArcadeExecutionError as U,ExecutionErrorCodes as D,ArcadeCompilationError as P,ArcadeUncompilableError as K}from"./executionError.js";class T extends j{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new U(e,D.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,o,l){return l(e,n,((n,r,a)=>{a=a.map((n=>!t(n)||n instanceof N?n:L(n,e,l)));const s=this.call(o,{arguments:a});return k(s)?s.then((e=>L(e,o,l))):s}))}}function q(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(V(e,n.arguments[o]));return t}function W(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 ue(e,n);case"VariableDeclaration":return ce(e,n);case"BlockStatement":case"Program":return oe(e,n);case"FunctionDeclaration":return ie(e,n);case"ImportDeclaration":return re(e,n);case"ExportNamedDeclaration":return ae(e,n);case"ReturnStatement":return le(e,n);case"IfStatement":return te(e,n);case"ExpressionStatement":return ee(e,n);case"AssignmentExpression":return Z(e,n);case"UpdateExpression":return Q(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"TemplateLiteral":return de(e,n);case"TemplateElement":return JSON.stringify(n.value?n.value.cooked:"");case"ForStatement":return H(e,n);case"ForInStatement":return Y(e,n);case"WhileStatement":return X(e,n);case"Identifier":return ye(e,n);case"MemberExpression":return pe(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return be(e,n);case"UnaryExpression":return me(e,n);case"BinaryExpression":return fe(e,n);case"LogicalExpression":return he(e,n);case"ArrayExpression":return ge(e,n);case"ObjectExpression":return J(e,n);case"Property":return z(e,n);case"Array":throw new P(e,D.NeverReach,n);default:throw new P(e,D.Unrecognised,n)}}catch(t){throw t}}function J(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];se(l.key.name);o>0&&(t+=","),t+="lang.strCheck("+("Identifier"===l.key.type?"'"+l.key.name+"'":V(e,l.key))+",'ObjectExpression'),lang.aCheck("+V(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function z(e,n){throw new P(e,D.NeverReach,n)}function Y(e,n){const t=Fe(e),o=Fe(e),l=Fe(e);let r="var "+t+" = "+V(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(r+=V(e,n.left));let a="VariableDeclaration"===n.left.type?n.left.declarations[0].id.name:n.left.name;a=a.toLowerCase(),se(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:Me(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+=V(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+=V(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+=V(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+=V(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n"),r+="else { lastStatement = lc.voidOperation; } \n",r}function H(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&(t+=V(e,n.init)+"; ");const o=Fe(e),l=Fe(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('"+D.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 Q(e,n){let t=null,o="";if("MemberExpression"===n.argument.type)return t=V(e,n.argument.object),!0===n.argument.computed?o=V(e,n.argument.property):(o="'"+n.argument.property.name+"'",se(n.argument.property.name)),"lang.memberupdate("+t+","+o+",'"+n.operator+"',"+n.prefix+")";if(t=n.argument.name.toLowerCase(),se(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:Me(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"lang.update(gscope, lang.chkAssig('"+o.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new U(e,D.InvalidIdentifier,n)}function X(e,n){let t="lastStatement = lc.voidOperation; \n";const o=Fe(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('${D.BooleanConditionRequired}');\n }\n ${V(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function Z(e,n){const t=V(e,n.right);let o=null,l="";if("MemberExpression"===n.left.type)return o=V(e,n.left.object),!0===n.left.computed?l=V(e,n.left.property):(l="'"+n.left.property.name+"'",se(n.left.property.name)),"lang.assignmember("+o+","+l+",'"+n.operator+"',"+t+")";if(o=n.left.name.toLowerCase(),se(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:Me(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 U(e,D.InvalidIdentifier,n)}function ee(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+V(e,n.expression)+"; \n ":(n.expression.type,"lastStatement = "+V(e,n.expression)+"; ")}function ne(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 te(e,n){if("AssignmentExpression"===n.test.type||"UpdateExpression"===n.test.type)throw new P(e,D.BooleanConditionRequired,n);return`if (lang.mustBoolean(${V(e,n.test)}, runtimeCtx) === true) {\n ${ne(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+te(e,n.alternate):` else {\n ${ne(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function oe(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 le(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+V(e,n.argument)}function re(e,n){const t=n.specifiers[0].local.name.toLowerCase();se(t);const o=e.libraryResolver?.loadLibrary(t),l=Me(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=De(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeReference:e.timeReference??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=Me(e),e.globalScope._SymbolsMap[t]=a,e.mangleMap[t]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+r}function ae(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 se(e){if("iif"===e)throw new K;if("decode"===e)throw new K;if("when"===e)throw new K}function ie(e,n){const t=n.id.name.toLowerCase();se(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=Me(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();se(t);const o=Me(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+=oe(r,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=oe(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 ce(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 ue(e,n){let t=null===n.init?null:V(e,n.init);t===a&&(t=null);const o=n.id.name.toLowerCase();if(se(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=Me(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=Me(e);return e.globalScope._SymbolsMap[o]=l,e.mangleMap[o]=l,"gscope['"+l+"']="+t+"; "}function pe(e,n){try{let t;return!0===n.computed?t=V(e,n.property):(t="'"+n.property.name+"'",se(n.property.name)),"lang.member("+V(e,n.object)+","+t+")"}catch(t){throw t}}function me(e,n){try{return"lang.unary("+V(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function ge(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 de(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("+V(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function fe(e,n){try{return"lang.binary("+V(e,n.left)+","+V(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function he(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new P(e,D.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new P(e,D.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+V(e,n.left)+") "+n.operator+" lang.logicalCheck("+V(e,n.right)+"))";throw new P(null,D.LogicExpressionOrAnd,null)}catch(t){throw t}}function ye(e,n){try{const t=n.name.toLowerCase();if(se(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:Me(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new P(e,D.InvalidIdentifier,n)}catch(t){throw t}}function be(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+"'",se(n.callee.property.name));let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=V(e,n.arguments[l]);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 P(e,D.FunctionNotFound,n);const t=n.callee.name.toLowerCase();if("iif"===t)return we(e,n);if("when"===t)return Se(e,n);if("decode"===t)return ve(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:Me(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+=V(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new P(e,D.FunctionNotFound,n)}catch(t){throw t}}function we(e,n){try{if(3!==n.arguments.length)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(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 Se(e,n){try{if(n.arguments.length<3)throw new P(e,D.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${V(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${V(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 ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function ve(e,n){try{if(n.arguments.length<2)throw new P(e,D.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${V(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new P(e,D.WrongNumberOfParameters,n);const t=Fe(e),o=Fe(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${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 ${l}\n return ${V(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const xe={};function Me(e){return e.symbols.symbolCounter++,"_T"+e.symbols.symbolCounter.toString()}function Fe(e){return e.symbols.symbolCounter++,"_Tvar"+e.symbols.symbolCounter.toString()}M(xe,W),O(xe,W),A(xe,W),F(xe,W),_(xe,W),xe.iif=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}},xe.decode=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}},xe.when=function(e,n){try{return W(e,n,((t,o,l)=>{throw new U(e,D.Unrecognised,n)}))}catch(t){throw t}};const Ce={};for(const Pe in xe)Ce[Pe]=new $(xe[Pe]);I(xe,W);for(const Pe in xe)xe[Pe]=new $(xe[Pe]);const Ie=function(){};Ie.prototype=xe;const Ae=function(){};function _e(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 Oe(t,o,l,r){const a=l?new Ae:new Ie;t||(t={}),o||(o={});const s=new e({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});s.immutable=!1,a._SymbolsMap={textformatting:1,infinity:1,pi:1},a.textformatting=s,a.infinity=Number.POSITIVE_INFINITY,a.pi=Math.PI;for(const e in o)a[e]=o[e],a._SymbolsMap[e]=1;for(const e in t)a._SymbolsMap[e]=1,t[e]&&"esri.Graphic"===t[e].declaredClass?a[e]=n.createFromGraphic(t[e],r??null):a[e]=t[e];return a}Ae.prototype=Ce;const ke={fixSpatialReference:c,parseArguments:q,standardFunction:W};function Ee(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:W,standardFunctionAsync:W,evaluateIdentifier:Ge};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)xe[e]=new $(t.functions[e]),Ie.prototype[e]=xe[e];for(let e=0;e<t.signatures.length;e++)v(t.signatures[e],"sync")}else{for(const e in t.functions)Ce[e]=new $(t.functions[e]),Ae.prototype[e]=Ce[e];for(let e=0;e<t.signatures.length;e++)v(t.signatures[e],"async")}}function Re(e,n){return e(n)}function Ge(e,n){const t=n.name;if("_SymbolsMap"===t)throw new U(e,D.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}Ee([x],"sync"),Ee([x],"async");let Be=0;const $e={error(e){throw new U(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&&e.value.then?e.value.then(r,a):(Be++,Be%100==0?setTimeout((()=>{Be=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 U(null,D.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 U(n,D.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new U(n,D.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>u(e),aCheck(e,n){if(t(e)){if("ArrayExpression"===n)throw new U(null,D.NoFunctionInArray,null);if("ObjectExpression"===n)throw new U(null,D.NoFunctionInDictionary,null);throw new U(null,D.NoFunctionInTemplateLiteral,null)}return e===a?null:e},Dictionary:e,Feature:n,UserDefinedCompiledFunction:T,dictionary(n){const o={},l=new Map;for(let e=0;e<n.length;e+=2){if(t(n[e+1]))throw new U(null,D.NoFunctionInDictionary,null);if(!1===p(n[e]))throw new U(null,D.KeyMustBeString,null);let r=n[e].toString();const s=r.toLowerCase();l.has(s)?r=l.get(s):l.set(s,r),n[e+1]===a?o[r]=null:o[r]=n[e+1]}const r=new e(o);return r.immutable=!1,r},strCheck(e){if(!1===p(e))throw new U(null,D.KeyMustBeString,null);return e},unary(e,n){if(m(e)){if("!"===n)return!e;if("-"===n)return-1*g(e);if("+"===n)return 1*g(e);if("~"===n)return~g(e);throw new U(null,D.UnsupportedUnaryOperator,null)}if("-"===n)return-1*g(e);if("+"===n)return 1*g(e);if("~"===n)return~g(e);throw new U(null,D.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===m(e))throw new U(null,D.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(m(e)&&m(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new U(null,D.LogicExpressionOrAnd,null)}throw new U(null,D.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return h(g(e),g(n),t);case"==":case"=":return f(e,n);case"!=":return!f(e,n);case"<":case">":case"<=":case">=":return d(e,n,t);case"+":return p(e)||p(n)?u(e)+u(n):g(e)+g(n);case"-":return g(e)-g(n);case"*":return g(e)*g(n);case"/":return g(e)/g(n);case"%":return g(e)%g(n);default:throw new U(null,D.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===a?null:e;case"/=":return g(t)/g(e);case"*=":return g(t)*g(e);case"-=":return g(t)-g(e);case"+=":return p(t)||p(e)?u(t)+u(e):g(t)+g(e);case"%=":return g(t)%g(e);default:throw new U(null,D.UnsupportedOperator,null)}},update(e,n,t,o){const l=g(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,t,o)=>null===e?null:n.createFromGraphicLikeObject(e.geometry,e.attributes,t,o.timeReference),memberupdate(n,t,o,l){let r;if(y(n)){if(!b(t))throw new U(null,D.ArrayAccessorMustBeNumber,null);if(t<0&&(t=n.length+t),t<0||t>=n.length)throw new U(null,D.OutOfBounds,null);r=g(n[t]),n[t]="++"===o?r+1:r-1}else if(n instanceof e){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0!==n.hasField(t))throw new U(null,D.FieldNotFound,null,{key:t});r=g(n.field(t)),n.setField(t,"++"===o?r+1:r-1)}else if(w(n)){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0!==n.hasField(t))throw new U(null,D.FieldNotFound,null);r=g(n.field(t)),n.setField(t,"++"===o?r+1:r-1)}else{if(S(n))throw new U(null,D.Immutable,null);if(!(n instanceof Ue))throw new U(null,D.InvalidIdentifier,null);if(!1===p(t))throw new U(null,D.ModuleAccessorMustBeString,null);if(!0!==n.hasGlobal(t))throw new U(null,D.ModuleExportNotFound,null);r=g(n.global(t)),n.setGlobal(t,"++"===o?r+1:r-1)}return!1===l?r:"++"===o?r+1:r-1},assignmember(n,t,o,l){if(y(n)){if(!b(t))throw new U(null,D.ArrayAccessorMustBeNumber,null);if(t<0&&(t=n.length+t),t<0||t>n.length)throw new U(null,D.OutOfBounds,null);if(t===n.length){if("="!==o)throw new U(null,D.OutOfBounds,null);n[t]=this.assign(l,o,n[t])}else n[t]=this.assign(l,o,n[t])}else if(n instanceof e){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0===n.hasField(t))n.setField(t,this.assign(l,o,n.field(t)));else{if("="!==o)throw new U(null,D.FieldNotFound,null);n.setField(t,this.assign(l,o,null))}}else if(w(n)){if(!1===p(t))throw new U(null,D.KeyAccessorMustBeString,null);if(!0===n.hasField(t))n.setField(t,this.assign(l,o,n.field(t)));else{if("="!==o)throw new U(null,D.FieldNotFound,null);n.setField(t,this.assign(l,o,null))}}else{if(S(n))throw new U(null,D.Immutable,null);if(!(n instanceof Ue))throw new U(null,D.InvalidIdentifier,null);if(!1===p(t))throw new U(null,D.ModuleAccessorMustBeString,null);if(!n.hasGlobal(t))throw new U(null,D.ModuleExportNotFound,null);n.setGlobal(t,this.assign(l,o,n.global(t)))}},member(n,t){if(null===n)throw new U(null,D.MemberOfNull,null);if(n instanceof e||w(n)){if(p(t))return n.field(t);throw new U(null,D.InvalidMemberAccessKey,null)}if(n instanceof E){if(p(t))return C(n,t,null,null);throw new U(null,D.InvalidMemberAccessKey,null)}if(y(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length+t),t>=n.length||t<0)throw new U(null,D.OutOfBounds,null);return n[t]}throw new U(null,D.InvalidMemberAccessKey,null)}if(p(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length+t),t>=n.length||t<0)throw new U(null,D.OutOfBounds,null);return n[t]}throw new U(null,D.InvalidMemberAccessKey,null)}if(S(n)){if(b(t)&&isFinite(t)&&Math.floor(t)===t){if(t<0&&(t=n.length()+t),t>=n.length()||t<0)throw new U(null,D.OutOfBounds,null);return n.get(t)}throw new U(null,D.InvalidMemberAccessKey,null)}if(n instanceof Ue){if(p(t))return n.global(t);throw new U(null,D.InvalidMemberAccessKey,null)}throw new U(null,D.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,timeReference:n.timeReference??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,o,l){if(!(e instanceof Ue))throw new U(null,D.FunctionNotFound,null);const r=e.global(o);if(!1===t(r))throw new U(null,D.CallNonFunction,null);return r.call(l,{preparsed:!0,arguments:n})}};function je(e){console.log(e)}function Ne(e,n,c=!1){null===n&&(n={vars:{},customfunctions:{}});let u=null;e.usesModules&&(u=new G(null,e.loadedModules));const p={isAsync:c,globalScope:_e(n.vars,c?Ce:xe,n.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:n.customfunctions,libraryResolver:u,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:je,lrucache:n.lrucache,timeReference:n.timeReference??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let m=V(p,e);""===m&&(m="lc.voidOperation; "),p.undeclaredGlobalsInFunctions.size>0&&p.undeclaredGlobalsInFunctions.forEach((e=>{throw new P(n,D.InvalidIdentifier,e.node)}));let g="";g=c?"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"+m+"\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 "+m+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const d=p.moduleFactory,f=p.moduleFactoryMap,h=p.exports,y={};for(const t in h)y[t]=void 0!==p.mangleMap[t]?p.mangleMap[t]:t;const b={lc:o,lang:$e,mangles:p.mangleMap,postProcess(e){if(e instanceof l&&(e=e.value),e instanceof r&&(e=e.value),e===a&&(e=null),e===s)throw new U(null,D.IllegalResult,null);if(e===i)throw new U(null,D.IllegalResult,null);if(t(e))throw new U(null,D.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=R.WebMercator);const o=Oe(e.vars,e.customfunctions,n,e.timeReference);return{localStack:[],isAsync:n,moduleFactory:d,moduleFactoryMap:f,mangleMap:this.mangles,moduleSingletons:{},exports:h,gdefs:{},exportmangle:y,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??je,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",g).bind(b)}async function Le(){return Ee([await import("./functions/geomasync.js")],"async"),!0}class Ue extends B{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 o=this.moduleContext.globalScope,l=e.toLowerCase();if(t(n))throw new U(null,D.AssignModuleFunction,null);o[this.moduleContext.exportmangle[l]]=n}global(e){const n=this.moduleContext.globalScope;e=e.toLowerCase();const o=n[this.moduleContext.exportmangle[e]];if(void 0===o)throw new U(null,D.InvalidIdentifier,null);if(t(o)&&!(o instanceof N)){const t=new N;return t.fn=o,t.parameterEvaluator=W,t.context=this.moduleContext,n[this.moduleContext.exportmangle[e]]=t,t}return o}}function De(e,n,t=!1){const l={isAsync:t,moduleFactory:n.moduleFactory,moduleFactoryMap:{},libraryResolver:new G(null,e.loadedModules),globalScope:_e(n.vars,t?Ce:xe,n.customfunctions),customfunctions:n.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:je,lrucache:n.lrucache,timeReference:n.timeReference??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let r=V(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=t?"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 o in c)u[o]=void 0!==l.mangleMap[o]?l.mangleMap[o]:o;const p={lc:o,lang:$e,mangles:l.mangleMap,prepareModule:e=>new Ue(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new R({wkid:102100}));const o=Oe(e.vars,e.customfunctions,n,e.timeReference);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??je,lrucache:e.lrucache,timeReference:e.timeReference??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(p)}export{T as UserDefinedCompiledFunction,Ne as compileScript,Le as enableAsyncSupport,Re as executeScript,Ee as extend,ke as functionHelper};