@arcgis/core 4.32.0-next.20250102 → 4.32.0-next.20250104

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 (276) hide show
  1. package/Color.js +1 -1
  2. package/PopupTemplate.js +1 -1
  3. package/arcade/functions/date.js +1 -1
  4. package/arcade/functions/featuresetbase.js +1 -1
  5. package/arcade/functions/featuresetstats.js +1 -1
  6. package/arcade/functions/featuresetstring.js +1 -1
  7. package/arcade/functions/geomasync.js +1 -1
  8. package/arcade/functions/geometry.js +1 -1
  9. package/arcade/functions/geomsync.js +1 -1
  10. package/arcade/functions/knowledgegraph.js +1 -1
  11. package/arcade/functions/string.js +1 -1
  12. package/arcade/geometry/extendedUnitData.js +5 -0
  13. package/arcade/geometry/functions.js +5 -0
  14. package/arcade/geometry/operators.js +5 -0
  15. package/arcade/geometry/unitConversion.js +5 -0
  16. package/arcade/geometry/wkt.js +5 -0
  17. package/arcade/languageUtils.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/{e371f4f0eb3c22f222df.js → 005727711cca0614c2ab.js} +2 -2
  20. package/assets/esri/core/workers/chunks/{e371f4f0eb3c22f222df.js.LICENSE.txt → 005727711cca0614c2ab.js.LICENSE.txt} +1 -1
  21. package/assets/esri/core/workers/chunks/{2d908c115ea18e813b95.js → 00c0fbe19c12691cf2c3.js} +1 -1
  22. package/assets/esri/core/workers/chunks/08e28328385066c519c2.js +1 -0
  23. package/assets/esri/core/workers/chunks/{0e735d01296d340b393e.js → 0b95ec12218f3c04df18.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{59bf879b4802a5ba431e.js → 0ee669947c23f469e357.js} +1 -1
  25. package/assets/esri/core/workers/chunks/116103ecec27cce47a2f.js +1 -0
  26. package/assets/esri/core/workers/chunks/11f00218905f0db447ff.js +1 -0
  27. package/assets/esri/core/workers/chunks/14b87f3dd9942e6b19d0.js +1 -0
  28. package/assets/esri/core/workers/chunks/16d7c07e1c11b88dae84.js +1 -0
  29. package/assets/esri/core/workers/chunks/1d04fe800cb98e4d6bc4.js +1 -0
  30. package/assets/esri/core/workers/chunks/{71f6e5742cf0c482066b.js → 1dc6b5b177022b80c473.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{59455e2dd44b4c01cc76.js → 2586741c359057b3f626.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{250a810dd4e1ff293564.js → 318a39b56851e707edad.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{648d7d8fa19a2e772c89.js → 3582836342fa78873fe4.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{b1e4813f0c73fc2a483c.js → 370b230fd2d7703d0698.js} +2 -2
  35. package/assets/esri/core/workers/chunks/{b1e4813f0c73fc2a483c.js.LICENSE.txt → 370b230fd2d7703d0698.js.LICENSE.txt} +1 -1
  36. package/assets/esri/core/workers/chunks/{ebf9caf2dc8af89afec2.js → 42aa697b4718b75b8cb2.js} +2 -2
  37. package/assets/esri/core/workers/chunks/{ebf9caf2dc8af89afec2.js.LICENSE.txt → 42aa697b4718b75b8cb2.js.LICENSE.txt} +1 -1
  38. package/assets/esri/core/workers/chunks/44cc3ea8cec8ddd1e3ab.js +1 -0
  39. package/assets/esri/core/workers/chunks/{801dbea20966806db1c9.js → 53cd990b2c988518de6d.js} +1 -1
  40. package/assets/esri/core/workers/chunks/5a1eb0d1e25ff5574c43.js +1 -0
  41. package/assets/esri/core/workers/chunks/6157c49e7431f5868c77.js +1 -0
  42. package/assets/esri/core/workers/chunks/{eef2d94a73064f9bc085.js → 61d64f163840563017d5.js} +1 -1
  43. package/assets/esri/core/workers/chunks/6ed57d01be6bc054c7cd.js +1 -0
  44. package/assets/esri/core/workers/chunks/7254956381e823219db0.js +1 -0
  45. package/assets/esri/core/workers/chunks/740e6bdb3b76f2ea6d61.js +1 -0
  46. package/assets/esri/core/workers/chunks/756c2f7c8659deab6c96.js.LICENSE.txt +1 -1
  47. package/assets/esri/core/workers/chunks/{56fc353421252f2d0a99.js → 75e8ba7e02647b7216ae.js} +1 -1
  48. package/assets/esri/core/workers/chunks/89d7eec47e5b29935d92.js +1 -0
  49. package/assets/esri/core/workers/chunks/8cd2c9ec1e541836b81c.js +1 -0
  50. package/assets/esri/core/workers/chunks/{0b3e1e903120da297641.js → 932375de79e3d33bc4d7.js} +1 -1
  51. package/assets/esri/core/workers/chunks/{263adfd1c2641ef5c0f5.js → 95f23bd17ce9e07fc8ef.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{7de9c01849c4aa1940e7.js → 986889cea53c4a470347.js} +1 -1
  53. package/assets/esri/core/workers/chunks/{cc6160e8ab3cea4040c2.js → 9e9b2fd958e816b1b5f6.js} +1 -1
  54. package/assets/esri/core/workers/chunks/a57cead317eb2fc9afd8.js +1 -0
  55. package/assets/esri/core/workers/chunks/acec58a7f23b2cc938ee.js +1 -0
  56. package/assets/esri/core/workers/chunks/b0f4254d8a32dd713009.js +1 -0
  57. package/assets/esri/core/workers/chunks/b277b8c2f556918e4f9a.js +1 -0
  58. package/assets/esri/core/workers/chunks/{deffd56e39ce725ce377.js → b30046a40bcfbec8abe4.js} +1 -1
  59. package/assets/esri/core/workers/chunks/{5c11e2e65b97565e5003.js → b7db64b07edb0b37ece1.js} +1 -1
  60. package/assets/esri/core/workers/chunks/bd1fb82e8bac439d05ea.js +1 -0
  61. package/assets/esri/core/workers/chunks/bf0a0ca7fdac98f06a89.js.LICENSE.txt +1 -1
  62. package/assets/esri/core/workers/chunks/c44ce0302dc82fb66ada.js +1 -0
  63. package/assets/esri/core/workers/chunks/c52872a50a5989121388.js +1 -0
  64. package/assets/esri/core/workers/chunks/c8cd6ba5600d8ff8db0b.js +2 -0
  65. package/assets/esri/core/workers/chunks/{a100fb789d72410f8d4f.js.LICENSE.txt → c8cd6ba5600d8ff8db0b.js.LICENSE.txt} +1 -1
  66. package/assets/esri/core/workers/chunks/{57c1370b310768c0790a.js → ca1e186f136abb23ae4b.js} +1 -1
  67. package/assets/esri/core/workers/chunks/{d14e4fc82ad772899336.js → ca4a37bdc0f7fb705146.js} +1 -1
  68. package/assets/esri/core/workers/chunks/cb94fc9b0f613ad50b3f.js +1 -0
  69. package/assets/esri/core/workers/chunks/d20764cc99fcabcb7cbf.js +1 -0
  70. package/assets/esri/core/workers/chunks/df18a72e3625cbe31935.js +1 -0
  71. package/assets/esri/core/workers/chunks/eff8fcb6393cd1193cbc.js +1 -0
  72. package/assets/esri/core/workers/chunks/f19d3c855f6e93544918.js +1 -0
  73. package/assets/esri/core/workers/chunks/f4e3db71d1adae717535.js +2 -0
  74. package/assets/esri/core/workers/chunks/{d82b3e2905cab511ff3a.js.LICENSE.txt → f4e3db71d1adae717535.js.LICENSE.txt} +1 -1
  75. package/assets/esri/core/workers/chunks/{60b40b2319d1651dd150.js → f7e50a8284d12da21355.js} +1 -1
  76. package/assets/esri/core/workers/chunks/f9c0d571f62e611ffe2b.js +1 -0
  77. package/assets/esri/core/workers/chunks/fdfe8e0d942b78f08191.js +1 -0
  78. package/assets/esri/core/workers/chunks/ff21207f46a354786eed.js +1 -0
  79. package/assets/esri/libs/parquet/pkg/arcgis_parquet_bg.wasm +0 -0
  80. package/chunks/Bufferer-BiY2mtjI.js +1 -1
  81. package/chunks/Centroid-DZi-eb9F.js +1 -1
  82. package/chunks/Clipper-a9xfvRaw.js +1 -1
  83. package/chunks/CrackAndCluster-CfzXpEle.js +1 -1
  84. package/chunks/Distance2DCalculator-eS0piaux.js +1 -1
  85. package/chunks/GeodeticDistanceCalculator-bNilDneE.js +1 -1
  86. package/chunks/Geometry.js +1 -1
  87. package/chunks/GeometryCleaner-DVgW95-D.js +1 -1
  88. package/chunks/Intersector-K1VmdfQW.js +1 -1
  89. package/chunks/LineSeries.js +1 -1
  90. package/chunks/OperatorClip.js +1 -1
  91. package/chunks/OperatorCrosses.js +1 -1
  92. package/chunks/OperatorCut.js +1 -1
  93. package/chunks/OperatorDensify.js +1 -1
  94. package/chunks/OperatorDifference.js +1 -1
  95. package/chunks/OperatorGeneralize.js +1 -1
  96. package/chunks/OperatorGeodesicBuffer.js +1 -1
  97. package/chunks/OperatorGeodeticArea.js +1 -1
  98. package/chunks/OperatorGeodeticDensifyByLength.js +1 -1
  99. package/chunks/OperatorGeodeticDistance.js +1 -1
  100. package/chunks/OperatorGeodeticLength.js +1 -1
  101. package/chunks/OperatorIntersection.js +1 -1
  102. package/chunks/OperatorIntersects.js +1 -1
  103. package/chunks/OperatorMultiPartToSinglePart.js +1 -1
  104. package/chunks/OperatorOverlaps.js +1 -1
  105. package/chunks/OperatorProject.js +1 -1
  106. package/chunks/OperatorProximity.js +1 -1
  107. package/chunks/OperatorProximityGeodesic.js +1 -1
  108. package/chunks/OperatorShapePreservingDensify.js +1 -1
  109. package/chunks/OperatorShapePreservingLength.js +1 -1
  110. package/chunks/OperatorSimplify.js +1 -1
  111. package/chunks/OperatorTouches.js +1 -1
  112. package/chunks/OperatorUnion.js +1 -1
  113. package/chunks/OperatorWithin.js +1 -1
  114. package/chunks/QuadraticBezier.js +1 -1
  115. package/chunks/SideCalculator2D-Bf4QCxCR.js +1 -1
  116. package/chunks/Theme.js +1 -1
  117. package/chunks/Tick.js +1 -1
  118. package/chunks/Transformation2D.js +1 -1
  119. package/chunks/arcade.js +1 -1
  120. package/chunks/areaOperator.js +5 -0
  121. package/chunks/array.js +1 -1
  122. package/chunks/bufferOperator.js +5 -0
  123. package/chunks/centroidOperator.js +5 -0
  124. package/chunks/chartUtilsAm5.js +1 -1
  125. package/chunks/clipOperator.js +5 -0
  126. package/chunks/containsOperator.js +5 -0
  127. package/chunks/convexHullOperator.js +5 -0
  128. package/chunks/crossesOperator.js +5 -0
  129. package/chunks/cutOperator.js +5 -0
  130. package/chunks/densifyOperator.js +5 -0
  131. package/chunks/differenceOperator.js +5 -0
  132. package/chunks/disjointOperator.js +5 -0
  133. package/chunks/distanceOperator.js +5 -0
  134. package/chunks/equalsOperator.js +5 -0
  135. package/chunks/generalizeOperator.js +5 -0
  136. package/chunks/geodesicBufferOperator.js +5 -0
  137. package/chunks/geodeticAreaOperator.js +5 -0
  138. package/chunks/geodeticDensifyOperator.js +5 -0
  139. package/chunks/geodeticLengthOperator.js +5 -0
  140. package/chunks/i3s.js +1 -1
  141. package/chunks/intersectionOperator.js +5 -0
  142. package/chunks/intersectsOperator.js +5 -0
  143. package/chunks/languageUtils.js +1 -1
  144. package/chunks/lclayout.js +1 -1
  145. package/chunks/lengthOperator.js +5 -0
  146. package/chunks/lyr3DMain.js +1 -1
  147. package/chunks/lyr3DWorker.js +1 -1
  148. package/chunks/offsetOperator.js +5 -0
  149. package/chunks/overlapsOperator.js +5 -0
  150. package/chunks/pe-wasm.js +1 -1
  151. package/chunks/proximityOperator.js +5 -0
  152. package/chunks/relateOperator.js +5 -0
  153. package/chunks/simplifyOperator.js +5 -0
  154. package/chunks/symmetricDifferenceOperator.js +5 -0
  155. package/chunks/touchesOperator.js +5 -0
  156. package/chunks/unionOperator.js +5 -0
  157. package/chunks/vxlLayer.js +1 -1
  158. package/chunks/withinOperator.js +5 -0
  159. package/copyright.txt +2 -2
  160. package/core/Evented.js +1 -1
  161. package/geometry/operators/areaOperator.js +1 -1
  162. package/geometry/operators/bufferOperator.js +1 -1
  163. package/geometry/operators/centroidOperator.js +1 -1
  164. package/geometry/operators/clipOperator.js +1 -1
  165. package/geometry/operators/containsOperator.js +1 -1
  166. package/geometry/operators/convexHullOperator.js +1 -1
  167. package/geometry/operators/crossesOperator.js +1 -1
  168. package/geometry/operators/cutOperator.js +1 -1
  169. package/geometry/operators/densifyOperator.js +1 -1
  170. package/geometry/operators/differenceOperator.js +1 -1
  171. package/geometry/operators/disjointOperator.js +1 -1
  172. package/geometry/operators/distanceOperator.js +1 -1
  173. package/geometry/operators/equalsOperator.js +1 -1
  174. package/geometry/operators/extendOperator.js +1 -1
  175. package/geometry/operators/generalizeOperator.js +1 -1
  176. package/geometry/operators/geodesicBufferOperator.js +1 -1
  177. package/geometry/operators/geodeticAreaOperator.js +1 -1
  178. package/geometry/operators/geodeticDensifyOperator.js +1 -1
  179. package/geometry/operators/geodeticLengthOperator.js +1 -1
  180. package/geometry/operators/gx/operatorAffineTransform.js +1 -1
  181. package/geometry/operators/gx/operatorAlphaShape.js +1 -1
  182. package/geometry/operators/gx/operatorAutoComplete.js +1 -1
  183. package/geometry/operators/gx/operatorBoundary.js +1 -1
  184. package/geometry/operators/gx/operatorBuffer.js +1 -1
  185. package/geometry/operators/gx/operatorConvexHull.js +1 -1
  186. package/geometry/operators/gx/operatorGraphicBuffer.js +1 -1
  187. package/geometry/operators/gx/operatorIntegrate.js +1 -1
  188. package/geometry/operators/gx/operatorLabelPoint.js +1 -1
  189. package/geometry/operators/gx/operatorLinesToPolygons.js +1 -1
  190. package/geometry/operators/gx/operatorLocateBetween.js +1 -1
  191. package/geometry/operators/gx/operatorMinimumBoundingCircle.js +1 -1
  192. package/geometry/operators/gx/operatorOffset.js +1 -1
  193. package/geometry/operators/gx/operatorPolygonOverlay.js +1 -1
  194. package/geometry/operators/gx/operatorPolygonSlicer.js +1 -1
  195. package/geometry/operators/gx/operatorSinglePartToMultiPart.js +1 -1
  196. package/geometry/operators/gx/operatorSymmetricDifference.js +1 -1
  197. package/geometry/operators/intersectionOperator.js +1 -1
  198. package/geometry/operators/intersectsOperator.js +1 -1
  199. package/geometry/operators/isNearOperator.js +1 -1
  200. package/geometry/operators/json/disjointOperator.js +1 -1
  201. package/geometry/operators/lengthOperator.js +1 -1
  202. package/geometry/operators/offsetOperator.js +1 -1
  203. package/geometry/operators/overlapsOperator.js +1 -1
  204. package/geometry/operators/proximityOperator.js +1 -1
  205. package/geometry/operators/relateOperator.js +1 -1
  206. package/geometry/operators/reshapeOperator.js +1 -1
  207. package/geometry/operators/simplifyOperator.js +1 -1
  208. package/geometry/operators/support/apiConverter.js +1 -1
  209. package/geometry/operators/support/jsonConverter.js +1 -1
  210. package/geometry/operators/symmetricDifferenceOperator.js +1 -1
  211. package/geometry/operators/touchesOperator.js +1 -1
  212. package/geometry/operators/unionOperator.js +1 -1
  213. package/geometry/operators/withinOperator.js +1 -1
  214. package/geometry/support/contains.js +1 -1
  215. package/interfaces.d.ts +56 -0
  216. package/kernel.js +1 -1
  217. package/layers/KMLLayer.js +1 -1
  218. package/layers/WCSLayer.js +1 -1
  219. package/layers/graphics/sources/ParquetSource.js +1 -1
  220. package/layers/support/parquetLayerUtils.js +1 -1
  221. package/layers/support/rasterDatasets/WCSRaster.js +1 -1
  222. package/layers/support/rasterFormats/RasterCodec.js +1 -1
  223. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  224. package/layers/support/wmtsUtils.js +1 -1
  225. package/libs/parquet/parquet.js +1 -1
  226. package/package.json +3 -3
  227. package/smartMapping/renderers/support/utils.js +1 -1
  228. package/smartMapping/symbology/support/Theme.js +1 -1
  229. package/support/revision.js +1 -1
  230. package/views/2d/layers/features/FeatureContainer.js +1 -1
  231. package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
  232. package/views/2d/layers/features/Processor.js +1 -1
  233. package/views/2d/layers/features/sources/FeatureSource.js +1 -1
  234. package/views/2d/layers/features/sources/strategies/ParquetLoadStrategy.js +1 -1
  235. package/views/2d/layers/features/sources/strategies/chunks/SourceChunkStore.js +1 -1
  236. package/views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DView.js +1 -1
  237. package/views/3d/support/DisplayQualityProfile.js +1 -1
  238. package/views/3d/webgl-engine/core/shaderModules/interfaces.js +1 -1
  239. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  240. package/views/SelectionManager.js +1 -1
  241. package/widgets/BatchAttributeForm.js +1 -1
  242. package/widgets/Feature/support/featureUtils.js +1 -1
  243. package/widgets/LayerList/LayerListItem.js +1 -1
  244. package/widgets/LayerList/support/layerListUtils.js +1 -1
  245. package/widgets/Legend/support/heatmapRampUtils.js +1 -1
  246. package/widgets/OrientedImageryViewer/OrientedImageryViewerVisibleElements.js +1 -1
  247. package/widgets/OrientedImageryViewer.js +1 -1
  248. package/widgets/support/widgetUtils.js +1 -1
  249. package/assets/esri/core/workers/chunks/015285436ca965f94e17.js +0 -1
  250. package/assets/esri/core/workers/chunks/048d296efa26ccd79056.js +0 -1
  251. package/assets/esri/core/workers/chunks/0e0b978459d70b15acb5.js +0 -1
  252. package/assets/esri/core/workers/chunks/10fa211987b16fd71a1a.js +0 -1
  253. package/assets/esri/core/workers/chunks/200a5f1864c2c2f7536c.js +0 -1
  254. package/assets/esri/core/workers/chunks/23a697d48f6e45cc033e.js +0 -1
  255. package/assets/esri/core/workers/chunks/29b610ff44708e044cbd.js +0 -1
  256. package/assets/esri/core/workers/chunks/3600125c58d5d04c515a.js +0 -1
  257. package/assets/esri/core/workers/chunks/457d4abc938d14f28e31.js +0 -1
  258. package/assets/esri/core/workers/chunks/4b5dbdcad438cb2dd4bf.js +0 -1
  259. package/assets/esri/core/workers/chunks/69efc716991a407c3d23.js +0 -1
  260. package/assets/esri/core/workers/chunks/6e254e846e284223ef63.js +0 -1
  261. package/assets/esri/core/workers/chunks/785610aa615198fd3815.js +0 -1
  262. package/assets/esri/core/workers/chunks/7bf7aace72f81f5de4e4.js +0 -1
  263. package/assets/esri/core/workers/chunks/7ea3d652536e1d79dfc6.js +0 -1
  264. package/assets/esri/core/workers/chunks/816c9c81352cd0ca8ce8.js +0 -1
  265. package/assets/esri/core/workers/chunks/9291508232b23f030178.js +0 -1
  266. package/assets/esri/core/workers/chunks/9fc49968dea8e2b64f3e.js +0 -1
  267. package/assets/esri/core/workers/chunks/a0b3d70a1b0360084593.js +0 -1
  268. package/assets/esri/core/workers/chunks/a100fb789d72410f8d4f.js +0 -2
  269. package/assets/esri/core/workers/chunks/b4d76d46661aba356ea3.js +0 -1
  270. package/assets/esri/core/workers/chunks/cb3af81e1fe6405c4885.js +0 -1
  271. package/assets/esri/core/workers/chunks/cbf57abb537e86c1dd7f.js +0 -1
  272. package/assets/esri/core/workers/chunks/cebdf2f88c4d2ad8baab.js +0 -1
  273. package/assets/esri/core/workers/chunks/d56d77125798beb7e493.js +0 -1
  274. package/assets/esri/core/workers/chunks/d82b3e2905cab511ff3a.js +0 -2
  275. package/assets/esri/core/workers/chunks/e2f91098793b8742fae6.js +0 -1
  276. package/assets/esri/core/workers/chunks/f25c04cf1a4bc1d2636a.js +0 -1
package/Color.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.32/esri/copyright.txt for details.
4
4
  */
5
- import{hsla2rgba as t,isNamedColor as r,getNamedColor as s}from"./colorUtils.js";import{clamp as e}from"./core/mathUtils.js";import{ensureInteger as i}from"./core/accessorSupport/ensureType.js";function a(t){return e(i(t),0,255)}function n(t,r,s){return t=Number(t),isNaN(t)?s:t<r?r:t>s?s:t}function o(t,r){const s=t.toString(16).padStart(2,"0");return r?s.slice(0,1):s}class h{static blendColors(t,r,s,e=new h){return e.r=Math.round(t.r+(r.r-t.r)*s),e.g=Math.round(t.g+(r.g-t.g)*s),e.b=Math.round(t.b+(r.b-t.b)*s),e.a=t.a+(r.a-t.a)*s,e._sanitize()}static fromRgb(r,s){const e=r.toLowerCase().match(/^(rgba?|hsla?)\(([\s.\-,%0-9]+)\)/);if(e){const r=e[2].split(/\s*,\s*/),i=e[1];if("rgb"===i&&3===r.length||"rgba"===i&&4===r.length){const t=r[0];if("%"===t.charAt(t.length-1)){const t=r.map((t=>2.56*parseFloat(t)));return 4===r.length&&(t[3]=parseFloat(r[3])),h.fromArray(t,s)}return h.fromArray(r.map((t=>parseFloat(t))),s)}if("hsl"===i&&3===r.length||"hsla"===i&&4===r.length)return h.fromArray(t(parseFloat(r[0]),parseFloat(r[1])/100,parseFloat(r[2])/100,parseFloat(r[3])),s)}return null}static fromHex(t,r=new h){if("#"!==t[0]||isNaN(Number(`0x${t.slice(1)}`)))return null;switch(t.length){case 4:case 5:{const s=parseInt(t.slice(1,2),16),e=parseInt(t.slice(2,3),16),i=parseInt(t.slice(3,4),16),a=5===t.length?15:parseInt(t.slice(4),16);return h.fromArray([s+16*s,e+16*e,i+16*i,(a+16*a)/255],r)}case 7:case 9:{const s=parseInt(t.slice(1,3),16),e=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16),a=7===t.length?255:parseInt(t.slice(7),16);return h.fromArray([s,e,i,a/255],r)}default:return null}}static fromArray(t,r=new h){return r._set(Number(t[0]),Number(t[1]),Number(t[2]),Number(t[3])),isNaN(r.a)&&(r.a=1),r._sanitize()}static fromString(t,e){const i=r(t)?s(t):null;return i&&h.fromArray(i,e)||h.fromRgb(t,e)||h.fromHex(t,e)}static fromJSON(t){return null!=t?new h([t[0],t[1],t[2],(t[3]??255)/255]):void 0}static toUnitRGB(t){return null!=t?[t.r/255,t.g/255,t.b/255]:null}static toUnitRGBA(t){return null!=t?[t.r/255,t.g/255,t.b/255,null!=t.a?t.a:1]:null}constructor(t){this.r=255,this.g=255,this.b=255,this.a=1,t&&this.setColor(t)}get isBright(){return.299*this.r+.587*this.g+.114*this.b>=127}setColor(t){return"string"==typeof t?h.fromString(t,this):Array.isArray(t)?h.fromArray(t,this):(this._set(t.r??0,t.g??0,t.b??0,t.a??1),t instanceof h||this._sanitize()),this}toRgb(){return[this.r,this.g,this.b]}toRgba(){return[this.r,this.g,this.b,this.a]}toHex(t){const r=t?.capitalize??!1,s=t?.digits??6,e=3===s||4===s,i=4===s||8===s,a=`#${o(this.r,e)}${o(this.g,e)}${o(this.b,e)}${i?o(Math.round(255*this.a),e):""}`;return r?a.toUpperCase():a}toCss(t=!1){const r=this.r+", "+this.g+", "+this.b;return t?`rgba(${r}, ${this.a})`:`rgb(${r})`}toString(){return this.toCss(!0)}toJSON(){return this.toArray()}toArray(t=h.AlphaMode.ALWAYS){const r=a(this.r),s=a(this.g),e=a(this.b);return t===h.AlphaMode.ALWAYS||1!==this.a?[r,s,e,a(255*this.a)]:[r,s,e]}clone(){return new h(this.toRgba())}hash(){return this.r<<24|this.g<<16|this.b<<8|255*this.a}equals(t){return null!=t&&t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}_sanitize(){return this.r=Math.round(n(this.r,0,255)),this.g=Math.round(n(this.g,0,255)),this.b=Math.round(n(this.b,0,255)),this.a=n(this.a,0,1),this}_set(t,r,s,e){this.r=t,this.g=r,this.b=s,this.a=e}}h.prototype.declaredClass="esri.Color",function(t){var r;(r=t.AlphaMode||(t.AlphaMode={}))[r.ALWAYS=0]="ALWAYS",r[r.UNLESS_OPAQUE=1]="UNLESS_OPAQUE"}(h||(h={}));const l=h;export{l as default};
5
+ import{hsla2rgba as t,isNamedColor as r,getNamedColor as s}from"./colorUtils.js";import{clamp as e}from"./core/mathUtils.js";import{ensureInteger as i}from"./core/accessorSupport/ensureType.js";function a(t){return e(i(t),0,255)}function n(t,r,s){return t=Number(t),isNaN(t)?s:t<r?r:t>s?s:t}function o(t,r){const s=t.toString(16).padStart(2,"0");return r?s.slice(0,1):s}class h{static blendColors(t,r,s,e=new h){return e.r=Math.round(t.r+(r.r-t.r)*s),e.g=Math.round(t.g+(r.g-t.g)*s),e.b=Math.round(t.b+(r.b-t.b)*s),e.a=t.a+(r.a-t.a)*s,e._sanitize()}static fromRgb(r,s){const e=r.toLowerCase().match(/^(rgba?|hsla?)\(([\s.\-,%0-9]+)\)/);if(e){const r=e[2].split(/\s*,\s*/),i=e[1];if("rgb"===i&&3===r.length||"rgba"===i&&4===r.length){const t=r[0];if("%"===t.charAt(t.length-1)){const t=r.map((t=>2.56*parseFloat(t)));return 4===r.length&&(t[3]=parseFloat(r[3])),h.fromArray(t,s)}return h.fromArray(r.map((t=>parseFloat(t))),s)}if("hsl"===i&&3===r.length||"hsla"===i&&4===r.length)return h.fromArray(t(parseFloat(r[0]),parseFloat(r[1])/100,parseFloat(r[2])/100,parseFloat(r[3])),s)}return null}static fromHex(t,r=new h){if("#"!==t[0]||isNaN(Number(`0x${t.slice(1)}`)))return null;switch(t.length){case 4:case 5:{const s=parseInt(t.slice(1,2),16),e=parseInt(t.slice(2,3),16),i=parseInt(t.slice(3,4),16),a=5===t.length?15:parseInt(t.slice(4),16);return h.fromArray([s+16*s,e+16*e,i+16*i,(a+16*a)/255],r)}case 7:case 9:{const s=parseInt(t.slice(1,3),16),e=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16),a=7===t.length?255:parseInt(t.slice(7),16);return h.fromArray([s,e,i,a/255],r)}default:return null}}static fromArray(t,r=new h){return r._set(Number(t[0]),Number(t[1]),Number(t[2]),Number(t[3])),isNaN(r.a)&&(r.a=1),r._sanitize()}static fromString(t,e){const i=r(t)?s(t):null;return i&&h.fromArray(i,e)||h.fromRgb(t,e)||h.fromHex(t,e)}static fromJSON(t){return null!=t?new h([t[0],t[1],t[2],(t[3]??255)/255]):void 0}static toUnitRGB(t){return null!=t?[t.r/255,t.g/255,t.b/255]:null}static toUnitRGBA(t){return null!=t?[t.r/255,t.g/255,t.b/255,null!=t.a?t.a:1]:null}constructor(t){this.r=255,this.g=255,this.b=255,this.a=1,t&&this.setColor(t)}get isBright(){return.299*this.r+.587*this.g+.114*this.b>=127}setColor(t){return"string"==typeof t?h.fromString(t,this):Array.isArray(t)?h.fromArray(t,this):(this._set(t.r??0,t.g??0,t.b??0,t.a??1),t instanceof h||this._sanitize()),this}toRgb(){return[this.r,this.g,this.b]}toRgba(){return[this.r,this.g,this.b,this.a]}toHex(t){const r=t?.capitalize??!1,s=t?.digits??6,e=3===s||4===s,i=4===s||8===s,a=`#${o(this.r,e)}${o(this.g,e)}${o(this.b,e)}${i?o(Math.round(255*this.a),e):""}`;return r?a.toUpperCase():a}toCss(t=!1){const r=this.r+", "+this.g+", "+this.b;return t?`rgba(${r}, ${this.a})`:`rgb(${r})`}toString(){return this.toCss(!0)}toJSON(){return this.toArray()}toArray(t=h.AlphaMode.ALWAYS){const r=a(this.r),s=a(this.g),e=a(this.b);return t===h.AlphaMode.ALWAYS||1!==this.a?[r,s,e,a(255*this.a)]:[r,s,e]}clone(){return new h(this.toRgba())}hash(){return this.r<<24|this.g<<16|this.b<<8|255*this.a}equals(t){return null!=t&&t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}_sanitize(){return this.r=Math.round(n(this.r,0,255)),this.g=Math.round(n(this.g,0,255)),this.b=Math.round(n(this.b,0,255)),this.a=n(this.a,0,1),this}_set(t,r,s,e){this.r=t,this.g=r,this.b=s,this.a=e}}h.prototype.declaredClass="esri.Color",function(t){var r;(r=t.AlphaMode||(t.AlphaMode={}))[r.ALWAYS=0]="ALWAYS",r[r.UNLESS_OPAQUE=1]="UNLESS_OPAQUE"}(h);export{h as default};
package/PopupTemplate.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.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"./chunks/tslib.es6.js";import e from"./core/Clonable.js";import o from"./core/Collection.js";import s from"./core/JSONSupport.js";import{clone as i}from"./core/lang.js";import r from"./core/Logger.js";import{isPromiseLike as n}from"./core/promiseUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as l}from"./core/accessorSupport/decorators/cast.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as d}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureOneOfType as f}from"./core/accessorSupport/ensureType.js";import{collectFields as m,collectArcadeFieldNames as u,extractSubstitutionTemplatesFromString as h}from"./layers/support/fieldUtils.js";import{persistableWebSceneTypes as y,persistableTypes as I}from"./popup/content.js";import F from"./popup/ExpressionInfo.js";import _ from"./popup/FieldInfo.js";import w from"./popup/LayerOptions.js";import x from"./popup/RelatedRecordsInfo.js";import{types as g}from"./popup/content/support/mediaInfoTypes.js";import A from"./support/actions/ActionBase.js";import C from"./support/actions/ActionButton.js";import N from"./support/actions/ActionToggle.js";import j from"./popup/content/MediaContent.js";import S from"./popup/content/TextContent.js";import E from"./popup/content/AttachmentsContent.js";import O from"./popup/content/FieldsContent.js";import R from"./popup/content/ExpressionContent.js";import T from"./popup/content/RelationshipContent.js";import b from"./popup/content/UtilityNetworkAssociationsContent.js";import v from"./popup/content/Content.js";import J from"./popup/content/CustomContent.js";const B="relationships/",L="expression/",M=o.ofType({key:"type",defaultKeyValue:"button",base:A,typeMap:{button:C,toggle:N}}),k={base:v,key:"type",typeMap:{media:j,custom:J,text:S,attachments:E,fields:O,expression:R,relationship:T,utilityNetworkAssociations:b}},P=new Set(["attachments","fields","media","text","expression","relationship"]),W=new Set([...P,"utility-network-associations"]);let U=class extends(e.ClonableMixin(s)){constructor(){super(...arguments),this.actions=null,this.content="",this.expressionInfos=null,this.fieldInfos=null,this.layerOptions=null,this.lastEditInfoEnabled=!0,this.outFields=null,this.overwriteActions=!1,this.returnGeometry=!1,this.title=""}castContent(t){return Array.isArray(t)?t.map((t=>f(k,t))):"string"==typeof t||"function"==typeof t||t instanceof HTMLElement||n(t)?t:(r.getLogger(this).error("content error","unsupported content value",{value:t}),null)}readContent(t,e){const{popupElements:o}=e;return Array.isArray(o)&&o.length>0?this._readPopupInfoElements(e.description,e.mediaInfos,o):this._readPopupInfo(e)}writeWebSceneContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeWebMapContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeFieldInfos(t,e,o,s){const{content:i}=this,r=Array.isArray(i)?i:null;if(t){const o=r?r.filter((t=>"fields"===t.type)):[],i=o.length&&o.every((t=>t.fieldInfos?.length));e.fieldInfos=t.filter(Boolean).map((t=>{const e=t.toJSON(s);return i&&(e.visible=!1),e}))}if(r)for(const n of r)"fields"===n.type&&this._writeFieldsContent(n,e)}writeLayerOptions(t,e,o,s){e[o]=!t||null===t.showNoDataRecords&&null===t.returnTopmostRaster?null:t.toJSON(s)}writeTitle(t,e){e.title=t||""}async collectRequiredFields(t,e){const o=this.expressionInfos||[];await this._collectExpressionInfoFields(t,e,[...o,...this._getContentExpressionInfos(this.content,o)]),m(t,e,[...this.outFields||[],...this._getActionsFields(this.actions),...this._getTitleFields(this.title),...this._getContentFields(this.content)])}async getRequiredFields(t){const e=new Set;return await this.collectRequiredFields(e,t),[...e].sort()}_writePopupTemplateContent(t,e,o){"string"!=typeof t?Array.isArray(t)&&(e.popupElements=t.filter((t=>"web-scene"===o?.origin?P.has(t.type):W.has(t.type))).map((t=>t?.toJSON(o))),e.popupElements.forEach((t=>{"attachments"===t.type?this._writeAttachmentContent(e):"media"===t.type?this._writeMediaContent(t,e):"text"===t.type?this._writeTextContent(t,e):"relationship"===t.type&&this._writeRelationshipContent(t,e)}))):e.description=t}_writeFieldsContent(t,e){if(!Array.isArray(t.fieldInfos)||!t.fieldInfos.length)return;const o=i(t.fieldInfos);Array.isArray(e.fieldInfos)?o.forEach((t=>{const o=e.fieldInfos.find((e=>e.fieldName?.toLowerCase()===t.fieldName?.toLowerCase()));o?o.visible=!0:e.fieldInfos.push(t)})):e.fieldInfos=o}_writeAttachmentContent(t){t.showAttachments||(t.showAttachments=!0)}_writeRelationshipContent(t,e){const o=t.orderByFields?.map((e=>this._toFieldOrderJSON(e,t.relationshipId)))||[],s=[...e.relatedRecordsInfo?.orderByFields||[],...o];e.relatedRecordsInfo={showRelatedRecords:!0,...s?.length&&{orderByFields:s}}}_writeTextContent(t,e){!e.description&&t.text&&(e.description=t.text)}_writeMediaContent(t,e){if(!Array.isArray(t.mediaInfos)||!t.mediaInfos.length)return;const o=i(t.mediaInfos);Array.isArray(e.mediaInfos)?e.mediaInfos=[...e.mediaInfos,...o]:e.mediaInfos=o}_readPopupInfoElements(t,e,o){const s={description:!1,mediaInfos:!1};return o.map((o=>"media"===o.type?(o.mediaInfos||!e||s.mediaInfos||(o.mediaInfos=e,s.mediaInfos=!0),j.fromJSON(o)):"text"===o.type?(o.text||!t||s.description||(o.text=t,s.description=!0),S.fromJSON(o)):"attachments"===o.type?E.fromJSON(o):"fields"===o.type?O.fromJSON(o):"expression"===o.type?R.fromJSON(o):"relationship"===o.type?T.fromJSON(o):"utilityNetworkAssociations"===o.type?b.fromJSON(o):void 0)).filter(Boolean)}_toRelationshipContent(t){const{field:e,order:o}=t;if(!e?.startsWith(B))return null;const s=e.replace(B,"").split("/");if(2!==s.length)return null;const i=parseInt(s[0],10),r=s[1];return"number"==typeof i&&r?T.fromJSON({relationshipId:i,orderByFields:[{field:r,order:o}]}):null}_toFieldOrderJSON(t,e){const{order:o,field:s}=t;return{field:`${B}${e}/${s}`,order:o}}_readPopupInfo({description:t,mediaInfos:e,showAttachments:o,relatedRecordsInfo:s={showRelatedRecords:!1}}){const i=[];t?i.push(new S({text:t})):i.push(new O),Array.isArray(e)&&e.length&&i.push(j.fromJSON({mediaInfos:e})),o&&i.push(E.fromJSON({displayType:"auto"}));const{showRelatedRecords:r,orderByFields:n}=s;return r&&n?.length&&n.forEach((t=>{const e=this._toRelationshipContent(t);e&&i.push(e)})),i.length?i:t}_getContentElementFields(t){const e=t?.type;if("attachments"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)];if("custom"===e)return t.outFields||[];if("fields"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...this._getFieldInfoFields(t.fieldInfos??this.fieldInfos)];if("media"===e){const e=t.mediaInfos||[];return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...e.reduce(((t,e)=>[...t,...this._getMediaInfoFields(e)]),[])]}return"text"===e?this._extractFieldNames(t.text):"relationship"===e||"utility-network-associations"===e?[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)]:[]}_getMediaInfoFields(t){const{caption:e,title:o,value:s}=t,i=s||{},{fields:r,normalizeField:n,tooltipField:p,sourceURL:l,linkURL:a}=i,d=[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(l),...this._extractFieldNames(a),...r??[]];return n&&d.push(n),p&&d.push(p),d}_getContentExpressionInfos(t,e){return Array.isArray(t)?t.reduce(((t,e)=>[...t,..."expression"===e.type&&e.expressionInfo?[e.expressionInfo]:[]]),e):[]}_getContentFields(t){return"string"==typeof t?this._extractFieldNames(t):Array.isArray(t)?t.reduce(((t,e)=>[...t,...this._getContentElementFields(e)]),[]):[]}async _collectExpressionInfoFields(t,e,o){o&&await Promise.all(o.map((o=>u(t,e,o.expression))))}_getFieldInfoFields(t){return t?t.filter((({fieldName:t,visible:e})=>!(void 0!==e&&!e||!t||t.startsWith(B)||t.startsWith(L)))).map((t=>t.fieldName)):[]}_getActionsFields(t){return t?t.toArray().reduce(((t,e)=>[...t,...this._getActionFields(e)]),[]):[]}_getActionFields(t){const{className:e,title:o,type:s}=t,i="button"===s||"toggle"===s?t.image:"";return[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(i)]}_getTitleFields(t){return"string"==typeof t?this._extractFieldNames(t):[]}_extractFieldNames(t){return h(t).filter((t=>!(0===t.indexOf(B)||0===t.indexOf(L))))}};t([p({type:M})],U.prototype,"actions",void 0),t([p()],U.prototype,"content",void 0),t([l("content")],U.prototype,"castContent",null),t([a("content",["description","fieldInfos","popupElements","mediaInfos","showAttachments","relatedRecordsInfo"])],U.prototype,"readContent",null),t([c("web-scene","content",{popupElements:{type:o.ofType(y)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebSceneContent",null),t([c("content",{popupElements:{type:o.ofType(I)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebMapContent",null),t([p({type:[F],json:{write:!0}})],U.prototype,"expressionInfos",void 0),t([p({type:[_]})],U.prototype,"fieldInfos",void 0),t([c("fieldInfos")],U.prototype,"writeFieldInfos",null),t([p({type:w})],U.prototype,"layerOptions",void 0),t([c("layerOptions")],U.prototype,"writeLayerOptions",null),t([p({type:Boolean,json:{read:{source:"showLastEditInfo"},write:{target:"showLastEditInfo"},default:!0}})],U.prototype,"lastEditInfoEnabled",void 0),t([p()],U.prototype,"outFields",void 0),t([p()],U.prototype,"overwriteActions",void 0),t([p()],U.prototype,"returnGeometry",void 0),t([p({json:{type:String}})],U.prototype,"title",void 0),t([c("title")],U.prototype,"writeTitle",null),U=t([d("esri.PopupTemplate")],U);const q=U;export{q as default};
5
+ import{_ as t}from"./chunks/tslib.es6.js";import e from"./core/Clonable.js";import o from"./core/Collection.js";import s from"./core/JSONSupport.js";import{clone as i}from"./core/lang.js";import r from"./core/Logger.js";import{isPromiseLike as n}from"./core/promiseUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as l}from"./core/accessorSupport/decorators/cast.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as d}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureOneOfType as f}from"./core/accessorSupport/ensureType.js";import{collectFields as m,collectArcadeFieldNames as u,extractSubstitutionTemplatesFromString as h}from"./layers/support/fieldUtils.js";import{persistableWebSceneTypes as y,persistableTypes as I}from"./popup/content.js";import F from"./popup/ExpressionInfo.js";import _ from"./popup/FieldInfo.js";import w from"./popup/LayerOptions.js";import x from"./popup/RelatedRecordsInfo.js";import{types as g}from"./popup/content/support/mediaInfoTypes.js";import N from"./support/actions/ActionBase.js";import A from"./support/actions/ActionButton.js";import C from"./support/actions/ActionToggle.js";import j from"./popup/content/MediaContent.js";import S from"./popup/content/TextContent.js";import E from"./popup/content/AttachmentsContent.js";import O from"./popup/content/FieldsContent.js";import R from"./popup/content/ExpressionContent.js";import T from"./popup/content/RelationshipContent.js";import b from"./popup/content/UtilityNetworkAssociationsContent.js";import v from"./popup/content/Content.js";import J from"./popup/content/CustomContent.js";const B="relationships/",L="expression/",M=o.ofType({key:"type",defaultKeyValue:"button",base:N,typeMap:{button:A,toggle:C}}),k={base:v,key:"type",typeMap:{media:j,custom:J,text:S,attachments:E,fields:O,expression:R,relationship:T,utilityNetworkAssociations:b}},P=new Set(["attachments","fields","media","text","expression","relationship"]),W=new Set([...P,"utility-network-associations"]);let U=class extends(e.ClonableMixin(s)){constructor(){super(...arguments),this.actions=null,this.content="",this.expressionInfos=null,this.fieldInfos=null,this.layerOptions=null,this.lastEditInfoEnabled=!0,this.outFields=null,this.overwriteActions=!1,this.returnGeometry=!1,this.title=""}castContent(t){return Array.isArray(t)?t.map((t=>f(k,t))):"string"==typeof t||"function"==typeof t||t instanceof HTMLElement||n(t)?t:(r.getLogger(this).error("content error","unsupported content value",{value:t}),null)}readContent(t,e){const{popupElements:o}=e;return Array.isArray(o)&&o.length>0?this._readPopupInfoElements(e.description,e.mediaInfos,o):this._readPopupInfo(e)}writeWebSceneContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeWebMapContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeFieldInfos(t,e,o,s){const{content:i}=this,r=Array.isArray(i)?i:null;if(t){const o=r?r.filter((t=>"fields"===t.type)):[],i=o.length&&o.every((t=>t.fieldInfos?.length));e.fieldInfos=t.filter(Boolean).map((t=>{const e=t.toJSON(s);return i&&(e.visible=!1),e}))}if(r)for(const n of r)"fields"===n.type&&this._writeFieldsContent(n,e)}writeLayerOptions(t,e,o,s){e[o]=!t||null===t.showNoDataRecords&&null===t.returnTopmostRaster?null:t.toJSON(s)}writeTitle(t,e){e.title=t||""}async collectRequiredFields(t,e){const o=this.expressionInfos||[];await this._collectExpressionInfoFields(t,e,[...o,...this._getContentExpressionInfos(this.content,o)]),m(t,e,[...this.outFields||[],...this._getActionsFields(this.actions),...this._getTitleFields(this.title),...this._getContentFields(this.content)])}async getRequiredFields(t){const e=new Set;return await this.collectRequiredFields(e,t),[...e].sort()}_writePopupTemplateContent(t,e,o){"string"!=typeof t?Array.isArray(t)&&(e.popupElements=t.filter((t=>"web-scene"===o?.origin?P.has(t.type):W.has(t.type))).map((t=>t?.toJSON(o))),e.popupElements.forEach((t=>{"attachments"===t.type?this._writeAttachmentContent(e):"media"===t.type?this._writeMediaContent(t,e):"text"===t.type?this._writeTextContent(t,e):"relationship"===t.type&&this._writeRelationshipContent(t,e)}))):e.description=t}_writeFieldsContent(t,e){if(!Array.isArray(t.fieldInfos)||!t.fieldInfos.length)return;const o=i(t.fieldInfos);Array.isArray(e.fieldInfos)?o.forEach((t=>{const o=e.fieldInfos.find((e=>e.fieldName?.toLowerCase()===t.fieldName?.toLowerCase()));o?o.visible=!0:e.fieldInfos.push(t)})):e.fieldInfos=o}_writeAttachmentContent(t){t.showAttachments||(t.showAttachments=!0)}_writeRelationshipContent(t,e){const o=t.orderByFields?.map((e=>this._toFieldOrderJSON(e,t.relationshipId)))||[],s=[...e.relatedRecordsInfo?.orderByFields||[],...o];e.relatedRecordsInfo={showRelatedRecords:!0,...s?.length&&{orderByFields:s}}}_writeTextContent(t,e){!e.description&&t.text&&(e.description=t.text)}_writeMediaContent(t,e){if(!Array.isArray(t.mediaInfos)||!t.mediaInfos.length)return;const o=i(t.mediaInfos);Array.isArray(e.mediaInfos)?e.mediaInfos=[...e.mediaInfos,...o]:e.mediaInfos=o}_readPopupInfoElements(t,e,o){const s={description:!1,mediaInfos:!1};return o.map((o=>"media"===o.type?(o.mediaInfos||!e||s.mediaInfos||(o.mediaInfos=e,s.mediaInfos=!0),j.fromJSON(o)):"text"===o.type?(o.text||!t||s.description||(o.text=t,s.description=!0),S.fromJSON(o)):"attachments"===o.type?E.fromJSON(o):"fields"===o.type?O.fromJSON(o):"expression"===o.type?R.fromJSON(o):"relationship"===o.type?T.fromJSON(o):"utilityNetworkAssociations"===o.type?b.fromJSON(o):void 0)).filter(Boolean)}_toRelationshipContent(t){const{field:e,order:o}=t;if(!e?.startsWith(B))return null;const s=e.replace(B,"").split("/");if(2!==s.length)return null;const i=parseInt(s[0],10),r=s[1];return!Number.isNaN(i)&&r?T.fromJSON({relationshipId:i,orderByFields:[{field:r,order:o}]}):null}_toFieldOrderJSON(t,e){const{order:o,field:s}=t;return{field:`${B}${e}/${s}`,order:o}}_readPopupInfo({description:t,mediaInfos:e,showAttachments:o,relatedRecordsInfo:s={showRelatedRecords:!1}}){const i=[];t?i.push(new S({text:t})):i.push(new O),Array.isArray(e)&&e.length&&i.push(j.fromJSON({mediaInfos:e})),o&&i.push(E.fromJSON({displayType:"auto"}));const{showRelatedRecords:r,orderByFields:n}=s;return r&&n?.length&&n.forEach((t=>{const e=this._toRelationshipContent(t);e&&i.push(e)})),i.length?i:t}_getContentElementFields(t){const e=t?.type;if("attachments"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)];if("custom"===e)return t.outFields||[];if("fields"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...this._getFieldInfoFields(t.fieldInfos??this.fieldInfos)];if("media"===e){const e=t.mediaInfos||[];return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...e.reduce(((t,e)=>[...t,...this._getMediaInfoFields(e)]),[])]}return"text"===e?this._extractFieldNames(t.text):"relationship"===e||"utility-network-associations"===e?[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)]:[]}_getMediaInfoFields(t){const{caption:e,title:o,value:s}=t,i=s||{},{fields:r,normalizeField:n,tooltipField:p,sourceURL:l,linkURL:a}=i,d=[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(l),...this._extractFieldNames(a),...r??[]];return n&&d.push(n),p&&d.push(p),d}_getContentExpressionInfos(t,e){return Array.isArray(t)?t.reduce(((t,e)=>[...t,..."expression"===e.type&&e.expressionInfo?[e.expressionInfo]:[]]),e):[]}_getContentFields(t){return"string"==typeof t?this._extractFieldNames(t):Array.isArray(t)?t.reduce(((t,e)=>[...t,...this._getContentElementFields(e)]),[]):[]}async _collectExpressionInfoFields(t,e,o){o&&await Promise.all(o.map((o=>u(t,e,o.expression))))}_getFieldInfoFields(t){return t?t.filter((({fieldName:t,visible:e})=>!(void 0!==e&&!e||!t||t.startsWith(B)||t.startsWith(L)))).map((t=>t.fieldName)):[]}_getActionsFields(t){return t?t.toArray().reduce(((t,e)=>[...t,...this._getActionFields(e)]),[]):[]}_getActionFields(t){const{className:e,title:o,type:s}=t,i="button"===s||"toggle"===s?t.image:"";return[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(i)]}_getTitleFields(t){return"string"==typeof t?this._extractFieldNames(t):[]}_extractFieldNames(t){return h(t).filter((t=>!(0===t.indexOf(B)||0===t.indexOf(L))))}};t([p({type:M})],U.prototype,"actions",void 0),t([p()],U.prototype,"content",void 0),t([l("content")],U.prototype,"castContent",null),t([a("content",["description","fieldInfos","popupElements","mediaInfos","showAttachments","relatedRecordsInfo"])],U.prototype,"readContent",null),t([c("web-scene","content",{popupElements:{type:o.ofType(y)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebSceneContent",null),t([c("content",{popupElements:{type:o.ofType(I)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebMapContent",null),t([p({type:[F],json:{write:!0}})],U.prototype,"expressionInfos",void 0),t([p({type:[_]})],U.prototype,"fieldInfos",void 0),t([c("fieldInfos")],U.prototype,"writeFieldInfos",null),t([p({type:w})],U.prototype,"layerOptions",void 0),t([c("layerOptions")],U.prototype,"writeLayerOptions",null),t([p({type:Boolean,json:{read:{source:"showLastEditInfo"},write:{target:"showLastEditInfo"},default:!0}})],U.prototype,"lastEditInfoEnabled",void 0),t([p()],U.prototype,"outFields",void 0),t([p()],U.prototype,"overwriteActions",void 0),t([p()],U.prototype,"returnGeometry",void 0),t([p({json:{type:String}})],U.prototype,"title",void 0),t([c("title")],U.prototype,"writeTitle",null),U=t([d("esri.PopupTemplate")],U);const q=U;export{q 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.32/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as n,createDateTimeZone as e}from"../ArcadeDate.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as t}from"../executionError.js";import{B as o,H as u,d as a,k as s,g as i,j as l,f as c,h as f,E as m,K as d,L as h}from"../../chunks/languageUtils.js";import{DateOnly as y}from"../../core/sql/DateOnly.js";import{TimeOnly as N}from"../../core/sql/TimeOnly.js";import{getLocale as w}from"../../intl/locale.js";import{DateTime as g}from"luxon";import{isString as A}from"../../support/guards.js";function k(n,e,r){return n+(T(r)?P:D)[e]}function T(n){return n%4==0&&(n%100!=0||n%400==0)}const D=[0,31,59,90,120,151,181,212,243,273,304,334],P=[0,31,60,91,121,152,182,213,244,274,305,335];function S(n){return null===n?n:!1===n.isValid?null:n}function Z(n,e){return""===n||"default"===n.toLowerCase().trim()?u(e):"z"===n||"Z"===n?"UTC":n}function p(n,e){return l(n)?n.toArcadeDate():f(n,u(e))}function C(T,D){T.today=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=new Date;return i.setHours(0,0,0,0),n.dateJSAndZoneToArcadeDate(i,u(e))}))},T.time=function(e,c){return D(e,c,((f,m,d)=>{switch(o(d,0,4,e,c),d.length){case 0:{const r=n.nowToArcadeDate(u(e));return new N(r.hour,r.minute,r.second,r.millisecond)}case 1:{if(s(d[0]))return d[0].clone();if(i(d[0]))return new N(d[0].hour,d[0].minute,d[0].second,d[0].millisecond);if(l(d[0]))return new N(0,0,0,0);if(A(d[0]))return N.fromString(d[0]);const n=a(d[0]);return!1===isNaN(n)?N.fromMilliseconds(n):null}case 2:return A(d[0])&&A(d[1])?N.fromString(d[0],d[1]):N.fromParts(a(d[0]),a(d[1]),0,0);case 3:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),0);case 4:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),a(d[3]))}throw new r(e,t.InvalidParameter,c)}))},T.dateonly=function(e,r){return D(e,r,((t,s,f)=>{if(o(f,0,3,e,r),3===f.length)return y.fromParts(a(f[0]),a(f[1])+1,a(f[2]));if(2===f.length){const n=c(f[1]);return""===n?null:"X"===n?y.fromSeconds(a(f[0])):"x"===n?y.fromMilliseconds(a(f[0])):y.fromString(c(f[0]),n)}if(1===f.length){if(A(f[0])){if(""===f[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(f[0]))return y.fromString(f[0]+"-01-01")}if(l(f[0]))return f[0].clone();if(i(f[0]))return y.fromParts(f[0].year,f[0].monthJS+1,f[0].day);const n=a(f[0]);return!1===isNaN(n)?y.fromMilliseconds(n):A(f[0])?y.fromString(f[0]):null}if(0===f.length){const r=n.nowToArcadeDate(u(e));return!1===r.isValid?null:y.fromParts(r.year,r.monthJS+1,r.day)}return null}))},T.changetimezone=function(a,s){return D(a,s,((i,m,d)=>{if(o(d,2,2,a,s),null===d[0])return null;if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneDateOnly,s);if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneTime,s);const h=f(d[0],u(a));if(null===h)throw new r(a,t.InvalidParameter,s);const y=e(Z(c(d[1]),a),!1);if(null===y)return null;const N=n.arcadeDateAndZoneToArcadeDate(h,y);return!1===N.isValid?null:N}))},T.timezone=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,1,2,e,r),s(i[0]))return"Unknown";if(l(i[0]))return"Unknown";const c=f(i[0],u(e));if(null===c)return null;const m=c.timeZone;return"system"===m?n.systemTimeZoneCanonicalName:"utc"===m.toLowerCase()?"UTC":"unknown"===m.toLowerCase()?"Unknown":m}))},T.timezoneoffset=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:60*s.timeZoneOffset*1e3}))},T.now=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=n.nowToArcadeDate(u(e));return!1===i.isValid?null:i}))},T.timestamp=function(e,r){return D(e,r,((t,u,a)=>{o(a,0,0,e,r);const s=n.nowUTCToArcadeDate();return!1===s.isValid?null:s}))},T.toutc=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toUTC()}))},T.tolocal=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toLocal()}))},T.day=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.day}))},T.month=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthJS}))},T.year=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.year}))},T.hour=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].hour;const i=f(a[0],u(n));return null===i?NaN:i.hour}))},T.second=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].second;const i=f(a[0],u(n));return null===i?NaN:i.second}))},T.millisecond=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].millisecond;const i=f(a[0],u(n));return null===i?NaN:i.millisecond}))},T.minute=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].minute;const i=f(a[0],u(n));return null===i?NaN:i.minute}))},T.week=function(n,e){return D(n,e,((s,i,l)=>{o(l,1,2,n,e);const c=p(l[0],u(n));if(null===c)return NaN;const f=a(m(l[1],0));if(f<0||f>6)throw new r(n,t.InvalidParameter,e);const d=c.day,h=c.monthJS,y=c.year,N=c.dayOfWeekJS,w=k(d,h,y)-1,g=Math.floor(w/7);return N-f+(N-f<0?7:0)<w-7*g?g+1:g}))},T.weekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekJS}))},T.isoweekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekISO}))},T.isomonth=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthISO}))},T.isoweek=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.weekISO}))},T.isoyear=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.yearISO}))},T.date=function(r,t){return D(r,t,((i,m,h)=>{if(o(h,0,8,r,t),3===h.length){if(l(h[0])&&s(h[1])&&A(h[2])){const t=e(Z(c(h[2])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,t))}return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),0,0,0,0,u(r)))}if(4===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),0,0,0,u(r)));if(5===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),0,0,u(r)));if(6===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),0,u(r)));if(7===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),u(r)));if(8===h.length){const t=e(Z(c(h[7])??"unknown",r),!1);return null===t?null:S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),t))}if(2===h.length){if(l(h[0])&&A(h[1])){const t=e(Z(c(h[1])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,t))}if(l(h[0])&&s(h[1]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,"unknown"));let t,o=c(h[1]);return""===o?null:(o=d(o,!0),t="X"===o?g.fromSeconds(a(h[0])):"x"===o?g.fromMillis(a(h[0])):g.fromFormat(c(h[0]),o,{locale:w(),numberingSystem:"latn"}),t.isValid?n.dateTimeToArcadeDate(t):null)}if(1===h.length){if(l(h[0]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,"unknown"));if(A(h[0])){if(""===h[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(h[0]))return f(h[0]+"-01-01",u(r))}const e=a(h[0]);if(!1===isNaN(e)){const t=g.fromMillis(e);return t.isValid?n.dateTimeAndZoneToArcadeDate(t,u(r)):null}return f(h[0],u(r))}return 0===h.length?n.nowToArcadeDate(u(r)):null}))},T.datediff=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,2,4,e,r),s(i[0]))return s(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(s(i[1]))return NaN;if(l(i[0]))return l(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(l(i[1]))return NaN;let d=f(i[0],u(e)),h=f(i[1],u(e));if(null===d||null===h)return NaN;let y=m(i[3],"");switch(""!==y&&null!==y?(y=Z(c(y),e),d=n.arcadeDateAndZoneToArcadeDate(d,y),h=n.arcadeDateAndZoneToArcadeDate(h,y)):d.timeZone!==h.timeZone&&(d.isUnknownTimeZone?d=n.arcadeDateAndZoneToArcadeDate(d,h.timeZone):h=(h.isUnknownTimeZone,n.arcadeDateAndZoneToArcadeDate(h,d.timeZone))),c(i[2]).toLowerCase()){case"days":case"day":case"d":return d.diff(h,"days");case"months":case"month":return d.diff(h,"months");case"minutes":case"minute":case"m":return"M"===i[2]?d.diff(h,"months"):d.diff(h,"minutes");case"seconds":case"second":case"s":return d.diff(h,"seconds");case"milliseconds":case"millisecond":case"ms":default:return d.diff(h);case"hours":case"hour":case"h":return d.diff(h,"hours");case"years":case"year":case"y":return d.diff(h,"years")}}))},T.dateadd=function(n,e){return D(n,e,((r,t,i)=>{o(i,2,3,n,e);let m=a(i[1]);if(isNaN(m)||m===1/0||m===-1/0)return s(i[0])||l(i[0])?i[0].clone():f(i[0],u(n));let d="milliseconds";switch(c(i[2]).toLowerCase()){case"days":case"day":case"d":d="days",m=l(i[0])?m:h(m);break;case"months":case"month":d="months",m=l(i[0])?m:h(m);break;case"minutes":case"minute":case"m":d="M"===i[2]?"months":"minutes";break;case"seconds":case"second":case"s":d="seconds";break;case"milliseconds":case"millisecond":case"ms":d="milliseconds";break;case"hours":case"hour":case"h":d="hours";break;case"years":case"year":case"y":d="years"}if(s(i[0]))return i[0].plus(d,m);if(l(i[0]))return i[0].plus(d,m);const y=f(i[0],u(n));return null===y?null:y.plus({[d]:m})}))}}export{C as registerFunctions};
5
+ import{ArcadeDate as n,createDateTimeZone as e}from"../ArcadeDate.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as t}from"../executionError.js";import{B as o,H as u,d as a,k as s,g as i,j as l,f as c,h as f,G as m,K as d,L as h}from"../../chunks/languageUtils.js";import{DateOnly as y}from"../../core/sql/DateOnly.js";import{TimeOnly as N}from"../../core/sql/TimeOnly.js";import{getLocale as w}from"../../intl/locale.js";import{DateTime as g}from"luxon";import{isString as A}from"../../support/guards.js";function k(n,e,r){return n+(T(r)?P:D)[e]}function T(n){return n%4==0&&(n%100!=0||n%400==0)}const D=[0,31,59,90,120,151,181,212,243,273,304,334],P=[0,31,60,91,121,152,182,213,244,274,305,335];function S(n){return null===n?n:!1===n.isValid?null:n}function Z(n,e){return""===n||"default"===n.toLowerCase().trim()?u(e):"z"===n||"Z"===n?"UTC":n}function p(n,e){return l(n)?n.toArcadeDate():f(n,u(e))}function C(T,D){T.today=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=new Date;return i.setHours(0,0,0,0),n.dateJSAndZoneToArcadeDate(i,u(e))}))},T.time=function(e,c){return D(e,c,((f,m,d)=>{switch(o(d,0,4,e,c),d.length){case 0:{const r=n.nowToArcadeDate(u(e));return new N(r.hour,r.minute,r.second,r.millisecond)}case 1:{if(s(d[0]))return d[0].clone();if(i(d[0]))return new N(d[0].hour,d[0].minute,d[0].second,d[0].millisecond);if(l(d[0]))return new N(0,0,0,0);if(A(d[0]))return N.fromString(d[0]);const n=a(d[0]);return!1===isNaN(n)?N.fromMilliseconds(n):null}case 2:return A(d[0])&&A(d[1])?N.fromString(d[0],d[1]):N.fromParts(a(d[0]),a(d[1]),0,0);case 3:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),0);case 4:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),a(d[3]))}throw new r(e,t.InvalidParameter,c)}))},T.dateonly=function(e,r){return D(e,r,((t,s,f)=>{if(o(f,0,3,e,r),3===f.length)return y.fromParts(a(f[0]),a(f[1])+1,a(f[2]));if(2===f.length){const n=c(f[1]);return""===n?null:"X"===n?y.fromSeconds(a(f[0])):"x"===n?y.fromMilliseconds(a(f[0])):y.fromString(c(f[0]),n)}if(1===f.length){if(A(f[0])){if(""===f[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(f[0]))return y.fromString(f[0]+"-01-01")}if(l(f[0]))return f[0].clone();if(i(f[0]))return y.fromParts(f[0].year,f[0].monthJS+1,f[0].day);const n=a(f[0]);return!1===isNaN(n)?y.fromMilliseconds(n):A(f[0])?y.fromString(f[0]):null}if(0===f.length){const r=n.nowToArcadeDate(u(e));return!1===r.isValid?null:y.fromParts(r.year,r.monthJS+1,r.day)}return null}))},T.changetimezone=function(a,s){return D(a,s,((i,m,d)=>{if(o(d,2,2,a,s),null===d[0])return null;if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneDateOnly,s);if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneTime,s);const h=f(d[0],u(a));if(null===h)throw new r(a,t.InvalidParameter,s);const y=e(Z(c(d[1]),a),!1);if(null===y)return null;const N=n.arcadeDateAndZoneToArcadeDate(h,y);return!1===N.isValid?null:N}))},T.timezone=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,1,2,e,r),s(i[0]))return"Unknown";if(l(i[0]))return"Unknown";const c=f(i[0],u(e));if(null===c)return null;const m=c.timeZone;return"system"===m?n.systemTimeZoneCanonicalName:"utc"===m.toLowerCase()?"UTC":"unknown"===m.toLowerCase()?"Unknown":m}))},T.timezoneoffset=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:60*s.timeZoneOffset*1e3}))},T.now=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=n.nowToArcadeDate(u(e));return!1===i.isValid?null:i}))},T.timestamp=function(e,r){return D(e,r,((t,u,a)=>{o(a,0,0,e,r);const s=n.nowUTCToArcadeDate();return!1===s.isValid?null:s}))},T.toutc=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toUTC()}))},T.tolocal=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toLocal()}))},T.day=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.day}))},T.month=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthJS}))},T.year=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.year}))},T.hour=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].hour;const i=f(a[0],u(n));return null===i?NaN:i.hour}))},T.second=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].second;const i=f(a[0],u(n));return null===i?NaN:i.second}))},T.millisecond=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].millisecond;const i=f(a[0],u(n));return null===i?NaN:i.millisecond}))},T.minute=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].minute;const i=f(a[0],u(n));return null===i?NaN:i.minute}))},T.week=function(n,e){return D(n,e,((s,i,l)=>{o(l,1,2,n,e);const c=p(l[0],u(n));if(null===c)return NaN;const f=a(m(l[1],0));if(f<0||f>6)throw new r(n,t.InvalidParameter,e);const d=c.day,h=c.monthJS,y=c.year,N=c.dayOfWeekJS,w=k(d,h,y)-1,g=Math.floor(w/7);return N-f+(N-f<0?7:0)<w-7*g?g+1:g}))},T.weekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekJS}))},T.isoweekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekISO}))},T.isomonth=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthISO}))},T.isoweek=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.weekISO}))},T.isoyear=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.yearISO}))},T.date=function(r,t){return D(r,t,((i,m,h)=>{if(o(h,0,8,r,t),3===h.length){if(l(h[0])&&s(h[1])&&A(h[2])){const t=e(Z(c(h[2])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,t))}return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),0,0,0,0,u(r)))}if(4===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),0,0,0,u(r)));if(5===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),0,0,u(r)));if(6===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),0,u(r)));if(7===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),u(r)));if(8===h.length){const t=e(Z(c(h[7])??"unknown",r),!1);return null===t?null:S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),t))}if(2===h.length){if(l(h[0])&&A(h[1])){const t=e(Z(c(h[1])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,t))}if(l(h[0])&&s(h[1]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,"unknown"));let t,o=c(h[1]);return""===o?null:(o=d(o,!0),t="X"===o?g.fromSeconds(a(h[0])):"x"===o?g.fromMillis(a(h[0])):g.fromFormat(c(h[0]),o,{locale:w(),numberingSystem:"latn"}),t.isValid?n.dateTimeToArcadeDate(t):null)}if(1===h.length){if(l(h[0]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,"unknown"));if(A(h[0])){if(""===h[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(h[0]))return f(h[0]+"-01-01",u(r))}const e=a(h[0]);if(!1===isNaN(e)){const t=g.fromMillis(e);return t.isValid?n.dateTimeAndZoneToArcadeDate(t,u(r)):null}return f(h[0],u(r))}return 0===h.length?n.nowToArcadeDate(u(r)):null}))},T.datediff=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,2,4,e,r),s(i[0]))return s(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(s(i[1]))return NaN;if(l(i[0]))return l(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(l(i[1]))return NaN;let d=f(i[0],u(e)),h=f(i[1],u(e));if(null===d||null===h)return NaN;let y=m(i[3],"");switch(""!==y&&null!==y?(y=Z(c(y),e),d=n.arcadeDateAndZoneToArcadeDate(d,y),h=n.arcadeDateAndZoneToArcadeDate(h,y)):d.timeZone!==h.timeZone&&(d.isUnknownTimeZone?d=n.arcadeDateAndZoneToArcadeDate(d,h.timeZone):h=(h.isUnknownTimeZone,n.arcadeDateAndZoneToArcadeDate(h,d.timeZone))),c(i[2]).toLowerCase()){case"days":case"day":case"d":return d.diff(h,"days");case"months":case"month":return d.diff(h,"months");case"minutes":case"minute":case"m":return"M"===i[2]?d.diff(h,"months"):d.diff(h,"minutes");case"seconds":case"second":case"s":return d.diff(h,"seconds");case"milliseconds":case"millisecond":case"ms":default:return d.diff(h);case"hours":case"hour":case"h":return d.diff(h,"hours");case"years":case"year":case"y":return d.diff(h,"years")}}))},T.dateadd=function(n,e){return D(n,e,((r,t,i)=>{o(i,2,3,n,e);let m=a(i[1]);if(isNaN(m)||m===1/0||m===-1/0)return s(i[0])||l(i[0])?i[0].clone():f(i[0],u(n));let d="milliseconds";switch(c(i[2]).toLowerCase()){case"days":case"day":case"d":d="days",m=l(i[0])?m:h(m);break;case"months":case"month":d="months",m=l(i[0])?m:h(m);break;case"minutes":case"minute":case"m":d="M"===i[2]?"months":"minutes";break;case"seconds":case"second":case"s":d="seconds";break;case"milliseconds":case"millisecond":case"ms":d="milliseconds";break;case"hours":case"hour":case"h":d="hours";break;case"years":case"year":case"y":d="years"}if(s(i[0]))return i[0].plus(d,m);if(l(i[0]))return i[0].plus(d,m);const y=f(i[0],u(n));return null===y?null:y.plus({[d]:m})}))}}export{C as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as a}from"../executionError.js";import r from"../Feature.js";import{convertToFeatureSet as s,constructFeatureSetFromPortalItem as o,constructFeatureSet as l,constructFeatureSetFromRelationship as f,constructFeatureSetFromUrl as d,constructAssociationMetaDataFeatureSetFromUrl as u}from"../featureSetUtils.js";import c from"../ImmutableArray.js";import{B as m,k as p,j as y,p as w,f as h,h as I,H as g,g as F,o as D,E as T,e as x,n as E,m as b,i as A,d as N,Y as L,N as S}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as $,FieldRename as v,AdaptedFeatureSet as P,OriginalField as j}from"../featureset/actions/Adapted.js";import U from"../featureset/actions/AttributeFilter.js";import M from"../featureset/actions/OrderBy.js";import R from"../featureset/actions/Top.js";import k from"../featureset/sources/Empty.js";import O from"../featureset/sources/FeatureLayerMemory.js";import z from"../featureset/support/OrderbyClause.js";import{cloneField as H}from"../featureset/support/shared.js";import{isSingleField as W}from"../featureset/support/sqlUtils.js";import{calculateStat as G}from"./fieldStats.js";import{isPromiseLike as _}from"../../core/promiseUtils.js";import B from"../../core/sql/WhereClause.js";import K from"../../layers/FeatureLayer.js";import q from"../../layers/support/Field.js";import V from"../../portal/Portal.js";import{isString as Q,isArray as J,isInteger as Y}from"../../support/guards.js";function X(e){if(1===e.length){if(J(e[0]))return G("distinct",e[0],-1);if(b(e[0]))return G("distinct",e[0].toArray(),-1)}return G("distinct",e,-1)}function ee(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function te(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ie(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const i=te(e,"wkid");return null!==i&&(t.wkid=i),t}function ae(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ie(n));const i=te(e,"x",null);if(null!==i)return t.x=i,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const a=te(e,"rings",null);if(null!==a)return t.rings=a,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==J(e.layerDefinition.fields)&&!1!==J(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(G){"async"===G.mode&&(G.functions.timezone=function(t,r){return G.standardFunctionAsync(t,r,(async(s,o,l)=>{if(m(l,1,2,t,r),p(l[0]))return"Unknown";if(y(l[0]))return"Unknown";if(w(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new i(t,a.InvalidParameter,r);const e=l[1].field("type");if(!1===Q(e))throw new i(t,a.InvalidParameter,r);switch(h(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&Q(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(h(l[1].field("fieldname"))))}throw new i(t,a.InvalidParameter,r)}const f=I(l[0],g(t));if(null===f)return null;const d=f.timeZone;return"system"===d?e.systemTimeZoneCanonicalName:"utc"===d.toLowerCase()?"UTC":"unknown"===d.toLowerCase()?"Unknown":d}))},G.functions.sqltimestamp=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,1,3,e,t);const o=s[0];if(F(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(h(s[1])).toSQLWithKeyword();throw new i(e,a.InvalidParameter,t)}if(y(o))return o.toSQLWithKeyword();if(w(o)){if(3!==s.length)throw new i(e,a.InvalidParameter,t);await o.load();const n=h(s[1]);if(y(s[2]))return s[2].toSQLWithKeyword();if(!1===F(s[2]))throw new i(e,a.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"sqltimestamp",min:2,max:4}),G.functions.featuresetbyid=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetById(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyid",min:2,max:4}),G.functions.getfeatureset=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,o)=>{if(m(o,1,2,e,t),E(o[0])){let t=T(o[1],"datasource");return null===t&&(t="datasource"),t=h(t).toLowerCase(),s(o[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"getfeatureset",min:1,max:2}),G.functions.featuresetbyportalitem=function(e,n){return G.standardFunctionAsync(e,n,((r,s,l)=>{if(m(l,2,5,e,n),null===l[0])throw new i(e,a.PortalRequired,n);if(l[0]instanceof t){const t=h(l[1]),r=h(l[2]);let s=T(l[3],null);const f=x(T(l[4],!0));if(null===s&&(s=["*"]),!1===J(s))throw new i(e,a.InvalidParameter,n);let d;return d=e.services?.portal?e.services.portal:V.getDefault(),d=C(l[0],d),o(t,r,e.spatialReference??null,s,f,d,e.lrucache,e.interceptor)}if(!1===Q(l[0]))throw new i(e,a.PortalRequired,n);const f=h(l[0]),d=h(l[1]);let u=T(l[2],null);const c=x(T(l[3],!0));if(null===u&&(u=["*"]),!1===J(u))throw new i(e,a.InvalidParameter,n);return o(f,d,e.spatialReference??null,u,c,e.services?.portal??V.getDefault(),e.lrucache,e.interceptor)}))},G.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),G.functions.featuresetbyname=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetByName(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyname",min:2,max:4}),G.functions.featureset=function(e,t){return G.standardFunction(e,t,((r,s,o)=>{m(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(Q(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new i(e,a.InvalidParameter,t);{const n=JSON.parse(o[0].castToText(!0)),r=te(n,"layerdefinition");if(null!==r){l.layerDefinition.geometryType=te(r,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(r,"globalidfield",""),l.layerDefinition.objectIdField=te(r,"objectidfield",""),l.layerDefinition.typeIdField=te(r,"typeidfield",""),l.layerDefinition.hasZ=!0===te(r,"hasz",!1),l.layerDefinition.hasM=!0===te(r,"hasm",!1);const e=te(r,"spatialreference");e&&(l.layerDefinition.spatialReference=ie(e));const t=[];for(const n of te(r,"fields",[])){const e={name:te(n,"name",""),alias:te(n,"alias",""),type:te(n,"type",""),nullable:te(n,"nullable",!0),editable:te(n,"editable",!0),length:te(n,"length",null),domain:ne(te(n,"domain"))};t.push(e)}l.layerDefinition.fields=t;const i=te(n,"featureset");if(i){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(i,"features",[])){const n={},i=te(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];l.featureSet.features.push({attributes:n,geometry:ae(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(n,"hasz",!1),l.layerDefinition.hasM=!0===te(n,"hasm",!1),l.layerDefinition.geometryType=te(n,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(n,"objectidfieldname",""),l.layerDefinition.typeIdField=te(n,"typeidfieldname","");const r=te(n,"spatialreference");r&&(l.layerDefinition.spatialReference=ie(r));const s=[],o=te(n,"fields",null);if(!J(o))throw new i(e,a.InvalidParameter,t);for(const e of o){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};s.push(t)}l.layerDefinition.fields=s;const f={};for(const e of s)f[e.name.toLowerCase()]=e.name;let d=te(n,"features",null);if(J(d))for(const e of d){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ae(te(e,"geometry",null))})}else d=null,l.featureSet.features=d}}}if(!1===se(l))throw new i(e,a.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),O.create(l,e.spatialReference)}))},G.signatures.push({name:"featureset",min:1,max:1}),G.functions.filter=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),J(s[0])||b(s[0])){const n=[];let r,o=s[0];if(o instanceof c&&(o=o.toArray()),!A(s[1]))throw new i(e,a.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);_(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(w(s[0])){const t=await s[0].load(),n=B.create(s[1],{fieldsIndex:t.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC}),i=n.getVariables();if(i.length>0){const t={};for(const n of i)t[n]=G.evaluateIdentifier(e,{name:n});n.parameters=t}return new U({parentfeatureset:s[0],whereclause:n})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filter",min:2,max:2}),G.functions.orderby=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const e=new z(s[1]);return new M({parentfeatureset:s[0],orderbyclause:e})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"orderby",min:2,max:2}),G.functions.top=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0]))return new R({parentfeatureset:s[0],topnum:s[1]});if(J(s[0]))return N(s[1])>=s[0].length?s[0].slice():s[0].slice(0,N(s[1]));if(b(s[0]))return N(s[1])>=s[0].length()?s[0].slice():s[0].slice(0,N(s[1]));throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"top",min:2,max:2}),G.functions.first=function(e,t){return G.standardFunctionAsync(e,t,(async(n,i,a)=>{if(m(a,1,1,e,t),w(a[0])){const t=await a[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,a[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return J(a[0])?0===a[0].length?null:a[0][0]:b(a[0])?0===a[0].length()?null:a[0].get(0):null}))},G.signatures.push({name:"first",min:1,max:1}),G.functions.attachments=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{m(o,1,2,e,t);const f={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(f.minsize=N(o[1].field("minsize"))),o[1].hasField("metadata")&&(f.returnMetadata=x(o[1].field("metadata"))),o[1].hasField("maxsize")&&(f.maxsize=N(o[1].field("maxsize"))),o[1].hasField("types")){const e=L(o[1].field("types"),!1);e.length>0&&(f.types=e)}}else if(null!==o[1])throw new i(e,a.InvalidParameter,t);if(E(o[0])){let t=o[0]._layer;return t instanceof K&&(t=l(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===w(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),f.minsize,f.maxsize,f.types,f.returnMetadata))}if(null===o[0])return[];throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"attachments",min:1,max:2}),G.functions.featuresetbyrelationshipname=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,4,e,t);const o=s[0],u=h(s[1]);let c=T(s[2],null);const p=x(T(s[3],!0));if(null===c&&(c=["*"]),!1===J(c))throw new i(e,a.InvalidParameter,t);if(null===s[0])return null;if(!E(s[0]))throw new i(e,a.InvalidParameter,t);let y=o._layer;if(y instanceof K&&(y=l(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===w(y))return null;y=await y.load();const I=y.relationshipMetaData().filter((e=>e.name===u));if(0===I.length)return null;if(void 0!==I[0].relationshipTableId&&null!==I[0].relationshipTableId&&I[0].relationshipTableId>-1)return f(y,I[0],o.field(y.objectIdField),y.spatialReference,c,p,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+I[0].relatedTableId.toString():g+"/"+I[0].relatedTableId.toString();const F=await d(g,y.spatialReference,c,p,e.lrucache,e.interceptor);await F.load();let D=F.relationshipMetaData();if(D=D.filter((e=>e.id===I[0].id)),!1===o.hasField(I[0].keyField)||null===o.field(I[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[I[0].keyField]);if(e){const t=B.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[I[0].keyField]},F.filter(t)}return new k({parentfeatureset:F})}const b=B.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return b.parameters={id:o.field(I[0].keyField)},F.filter(b)}))},G.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),G.functions.featuresetbyassociation=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,3,e,t);const o=s[0],f=h(T(s[1],"")).toLowerCase(),d=Q(s[2])?h(s[2]):null;if(null===s[0])return null;if(!E(s[0]))throw new i(e,a.InvalidParameter,t);let c=o._layer;if(c instanceof K&&(c=l(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===w(c))return null;await c.load();const p=c.serviceUrl(),y=await u(p,e.spatialReference);let I=null,g=null,F=!1;if(null!==d&&""!==d&&void 0!==d){for(const e of y.terminals)e.terminalName===d&&(g=e.terminalId);null===g&&(F=!0)}const D=y.associations.getFieldsIndex(),x=D.get("TOGLOBALID").name,b=D.get("FROMGLOBALID").name,A=D.get("TOTERMINALID").name,N=D.get("FROMTERMINALID").name,L=D.get("FROMNETWORKSOURCEID").name,C=D.get("TONETWORKSOURCEID").name,U=D.get("ASSOCIATIONTYPE").name,M=D.get("ISCONTENTVISIBLE").name,R=D.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){I=o.field(e.name);break}let k=null,O=new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),B.create("''",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));const W="globalid",G="globalId",_={};for(const e in y.lkp)_[e]=y.lkp[e].sourceId;const V=new $(new q({name:"classname",alias:"classname",type:"string"}),null,_);let J="";switch(f){case"midspan":{J=`((${x}='${I}') OR ( ${b}='${I}')) AND (${U} IN (5))`,V.codefield=B.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=H(P.findField(y.associations.fields,b));e.name=W,e.alias=W,k=new Z(e,B.create(`CASE WHEN (${b}='${I}') THEN ${x} ELSE ${b} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),O=y.unVersion>=4?new j(P.findField(y.associations.fields,D.get("PERCENTALONG").name)):new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{J=`((${x}='${I}') OR ( ${b}='${I}')) AND (${U} IN (4,6))`,V.codefield=B.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=H(P.findField(y.associations.fields,b));e.name=W,e.alias=W,k=new Z(e,B.create(`CASE WHEN (${b}='${I}') THEN ${x} ELSE ${b} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),B.create(`CASE WHEN (${U}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${x}='@T'`,t=`${b}='@T'`;null!==g&&(e+=` AND ${A}=@A`,t+=` AND ${N}=@A`),J="(("+e+") OR ("+t+"))",J=S(J,"@T",I??""),e=S(e,"@T",I??""),null!==g&&(e=S(e,"@A",g.toString()),J=S(J,"@A",g.toString())),V.codefield=B.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const n=H(P.findField(y.associations.fields,b));n.name=W,n.alias=W,k=new Z(n,B.create("CASE WHEN "+e+` THEN ${b} ELSE ${x} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"container":J=`${x}='${I}' AND ${U} = 2`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,b),W,W);break;case"content":J=`(${b}='${I}' AND ${U} = 2)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),W,W);break;case"structure":J=`(${x}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,b),W,G);break;case"attached":J=`(${b}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),W,G);break;default:throw new i(e,a.InvalidParameter,t)}F&&(J="1 <> 1");return new P({parentfeatureset:y.associations,adaptedFields:[new j(P.findField(y.associations.fields,R)),new j(P.findField(y.associations.fields,M)),k,z,V,O],extraFilter:J?B.create(J,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}):null})}))},G.signatures.push({name:"featuresetbyassociation",min:2,max:6}),G.functions.groupby=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{if(m(o,3,3,e,t),!w(o[0]))throw new i(e,a.InvalidParameter,t);const l=await o[0].load(),f=[],d=[];let u=!1,c=[];if(Q(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(J(o[1]))c=o[1];else{if(!b(o[1]))throw new i(e,a.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(Q(m)){const e=B.create(h(m),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),t=!0===W(e)?h(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(u=!0)}else{if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(u=!0),!n)throw new i(e,a.InvalidParameter,t);f.push({name:n,expression:B.create(r||n,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],Q(o[2]))c.push(o[2]);else if(J(o[2]))c=o[2];else if(b(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new i(e,a.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new i(e,a.InvalidParameter,t);d.push({name:n,statistic:r.toLowerCase(),expression:B.create(s,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)ee(t.expression,G,e);for(const t of d)ee(t.expression,G,e);return o[0].groupby(f,d)}))},G.signatures.push({name:"groupby",min:3,max:3}),G.functions.distinct=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{if(w(o[0])){m(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(Q(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(J(o[1]))l=o[1];else{if(!b(o[1]))throw new i(e,a.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(Q(o)){const e=B.create(h(o),{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),t=!0===W(e)?h(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new i(e,a.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new i(e,a.InvalidParameter,t);s.push({name:n,expression:B.create(l||n,{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)ee(t.expression,G,e);return o[0].groupby(s,[])}return X(o)}))},G.functions.getfeaturesetinfo=function(e,t){return G.standardFunctionAsync(e,t,(async(i,a,r)=>{if(m(r,1,1,e,t),!w(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},g(e),!1,!1):null}))},G.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),G.functions.filterbysubtypecode=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const n=await s[0].load(),r=s[1];if(!Y(r))throw new i(e,a.InvalidParameter,t);if(n.subtypeField){const e=B.create(`${n.subtypeField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new i(e,a.FeatureSetDoesNotHaveSubtypes,t);const o=B.create(`${n.typeIdField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:o})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
5
+ import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as a}from"../executionError.js";import r from"../Feature.js";import{convertToFeatureSet as s,constructFeatureSetFromPortalItem as o,constructFeatureSet as l,constructFeatureSetFromRelationship as f,constructFeatureSetFromUrl as d,constructAssociationMetaDataFeatureSetFromUrl as u}from"../featureSetUtils.js";import c from"../ImmutableArray.js";import{B as m,k as p,j as y,p as w,f as h,h as I,H as g,g as F,o as D,G as T,e as x,n as b,m as E,i as A,d as N,Y as L,N as S}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as $,FieldRename as v,AdaptedFeatureSet as P,OriginalField as j}from"../featureset/actions/Adapted.js";import U from"../featureset/actions/AttributeFilter.js";import M from"../featureset/actions/OrderBy.js";import R from"../featureset/actions/Top.js";import k from"../featureset/sources/Empty.js";import O from"../featureset/sources/FeatureLayerMemory.js";import z from"../featureset/support/OrderbyClause.js";import{cloneField as H}from"../featureset/support/shared.js";import{isSingleField as W}from"../featureset/support/sqlUtils.js";import{calculateStat as G}from"./fieldStats.js";import{isPromiseLike as _}from"../../core/promiseUtils.js";import B from"../../core/sql/WhereClause.js";import K from"../../layers/FeatureLayer.js";import q from"../../layers/support/Field.js";import V from"../../portal/Portal.js";import{isString as Q,isArray as J,isInteger as Y}from"../../support/guards.js";function X(e){if(1===e.length){if(J(e[0]))return G("distinct",e[0],-1);if(E(e[0]))return G("distinct",e[0].toArray(),-1)}return G("distinct",e,-1)}function ee(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function te(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ie(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const i=te(e,"wkid");return null!==i&&(t.wkid=i),t}function ae(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ie(n));const i=te(e,"x",null);if(null!==i)return t.x=i,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const a=te(e,"rings",null);if(null!==a)return t.rings=a,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==J(e.layerDefinition.fields)&&!1!==J(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(G){"async"===G.mode&&(G.functions.timezone=function(t,r){return G.standardFunctionAsync(t,r,(async(s,o,l)=>{if(m(l,1,2,t,r),p(l[0]))return"Unknown";if(y(l[0]))return"Unknown";if(w(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new i(t,a.InvalidParameter,r);const e=l[1].field("type");if(!1===Q(e))throw new i(t,a.InvalidParameter,r);switch(h(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&Q(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(h(l[1].field("fieldname"))))}throw new i(t,a.InvalidParameter,r)}const f=I(l[0],g(t));if(null===f)return null;const d=f.timeZone;return"system"===d?e.systemTimeZoneCanonicalName:"utc"===d.toLowerCase()?"UTC":"unknown"===d.toLowerCase()?"Unknown":d}))},G.functions.sqltimestamp=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,1,3,e,t);const o=s[0];if(F(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(h(s[1])).toSQLWithKeyword();throw new i(e,a.InvalidParameter,t)}if(y(o))return o.toSQLWithKeyword();if(w(o)){if(3!==s.length)throw new i(e,a.InvalidParameter,t);await o.load();const n=h(s[1]);if(y(s[2]))return s[2].toSQLWithKeyword();if(!1===F(s[2]))throw new i(e,a.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"sqltimestamp",min:2,max:4}),G.functions.featuresetbyid=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetById(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyid",min:2,max:4}),G.functions.getfeatureset=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,o)=>{if(m(o,1,2,e,t),b(o[0])){let t=T(o[1],"datasource");return null===t&&(t="datasource"),t=h(t).toLowerCase(),s(o[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"getfeatureset",min:1,max:2}),G.functions.featuresetbyportalitem=function(e,n){return G.standardFunctionAsync(e,n,((r,s,l)=>{if(m(l,2,5,e,n),null===l[0])throw new i(e,a.PortalRequired,n);if(l[0]instanceof t){const t=h(l[1]),r=h(l[2]);let s=T(l[3],null);const f=x(T(l[4],!0));if(null===s&&(s=["*"]),!1===J(s))throw new i(e,a.InvalidParameter,n);let d;return d=e.services?.portal?e.services.portal:V.getDefault(),d=C(l[0],d),o(t,r,e.spatialReference??null,s,f,d,e.lrucache,e.interceptor)}if(!1===Q(l[0]))throw new i(e,a.PortalRequired,n);const f=h(l[0]),d=h(l[1]);let u=T(l[2],null);const c=x(T(l[3],!0));if(null===u&&(u=["*"]),!1===J(u))throw new i(e,a.InvalidParameter,n);return o(f,d,e.spatialReference??null,u,c,e.services?.portal??V.getDefault(),e.lrucache,e.interceptor)}))},G.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),G.functions.featuresetbyname=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetByName(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyname",min:2,max:4}),G.functions.featureset=function(e,t){return G.standardFunction(e,t,((r,s,o)=>{m(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(Q(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new i(e,a.InvalidParameter,t);{const n=JSON.parse(o[0].castToText(!0)),r=te(n,"layerdefinition");if(null!==r){l.layerDefinition.geometryType=te(r,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(r,"globalidfield",""),l.layerDefinition.objectIdField=te(r,"objectidfield",""),l.layerDefinition.typeIdField=te(r,"typeidfield",""),l.layerDefinition.hasZ=!0===te(r,"hasz",!1),l.layerDefinition.hasM=!0===te(r,"hasm",!1);const e=te(r,"spatialreference");e&&(l.layerDefinition.spatialReference=ie(e));const t=[];for(const n of te(r,"fields",[])){const e={name:te(n,"name",""),alias:te(n,"alias",""),type:te(n,"type",""),nullable:te(n,"nullable",!0),editable:te(n,"editable",!0),length:te(n,"length",null),domain:ne(te(n,"domain"))};t.push(e)}l.layerDefinition.fields=t;const i=te(n,"featureset");if(i){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(i,"features",[])){const n={},i=te(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];l.featureSet.features.push({attributes:n,geometry:ae(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(n,"hasz",!1),l.layerDefinition.hasM=!0===te(n,"hasm",!1),l.layerDefinition.geometryType=te(n,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(n,"objectidfieldname",""),l.layerDefinition.typeIdField=te(n,"typeidfieldname","");const r=te(n,"spatialreference");r&&(l.layerDefinition.spatialReference=ie(r));const s=[],o=te(n,"fields",null);if(!J(o))throw new i(e,a.InvalidParameter,t);for(const e of o){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};s.push(t)}l.layerDefinition.fields=s;const f={};for(const e of s)f[e.name.toLowerCase()]=e.name;let d=te(n,"features",null);if(J(d))for(const e of d){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ae(te(e,"geometry",null))})}else d=null,l.featureSet.features=d}}}if(!1===se(l))throw new i(e,a.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),O.create(l,e.spatialReference)}))},G.signatures.push({name:"featureset",min:1,max:1}),G.functions.filter=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),J(s[0])||E(s[0])){const n=[];let r,o=s[0];if(o instanceof c&&(o=o.toArray()),!A(s[1]))throw new i(e,a.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);_(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(w(s[0])){const t=await s[0].load(),n=B.create(s[1],{fieldsIndex:t.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC}),i=n.getVariables();if(i.length>0){const t={};for(const n of i)t[n]=G.evaluateIdentifier(e,{name:n});n.parameters=t}return new U({parentfeatureset:s[0],whereclause:n})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filter",min:2,max:2}),G.functions.orderby=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const e=new z(s[1]);return new M({parentfeatureset:s[0],orderbyclause:e})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"orderby",min:2,max:2}),G.functions.top=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0]))return new R({parentfeatureset:s[0],topnum:s[1]});if(J(s[0]))return N(s[1])>=s[0].length?s[0].slice():s[0].slice(0,N(s[1]));if(E(s[0]))return N(s[1])>=s[0].length()?s[0].slice():s[0].slice(0,N(s[1]));throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"top",min:2,max:2}),G.functions.first=function(e,t){return G.standardFunctionAsync(e,t,(async(n,i,a)=>{if(m(a,1,1,e,t),w(a[0])){const t=await a[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,a[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return J(a[0])?0===a[0].length?null:a[0][0]:E(a[0])?0===a[0].length()?null:a[0].get(0):null}))},G.signatures.push({name:"first",min:1,max:1}),G.functions.attachments=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{m(o,1,2,e,t);const f={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(f.minsize=N(o[1].field("minsize"))),o[1].hasField("metadata")&&(f.returnMetadata=x(o[1].field("metadata"))),o[1].hasField("maxsize")&&(f.maxsize=N(o[1].field("maxsize"))),o[1].hasField("types")){const e=L(o[1].field("types"),!1);e.length>0&&(f.types=e)}}else if(null!==o[1])throw new i(e,a.InvalidParameter,t);if(b(o[0])){let t=o[0]._layer;return t instanceof K&&(t=l(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===w(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),f.minsize,f.maxsize,f.types,f.returnMetadata))}if(null===o[0])return[];throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"attachments",min:1,max:2}),G.functions.featuresetbyrelationshipname=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,4,e,t);const o=s[0],u=h(s[1]);let c=T(s[2],null);const p=x(T(s[3],!0));if(null===c&&(c=["*"]),!1===J(c))throw new i(e,a.InvalidParameter,t);if(null===s[0])return null;if(!b(s[0]))throw new i(e,a.InvalidParameter,t);let y=o._layer;if(y instanceof K&&(y=l(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===w(y))return null;y=await y.load();const I=y.relationshipMetaData().filter((e=>e.name===u));if(0===I.length)return null;if(void 0!==I[0].relationshipTableId&&null!==I[0].relationshipTableId&&I[0].relationshipTableId>-1)return f(y,I[0],o.field(y.objectIdField),y.spatialReference,c,p,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+I[0].relatedTableId.toString():g+"/"+I[0].relatedTableId.toString();const F=await d(g,y.spatialReference,c,p,e.lrucache,e.interceptor);await F.load();let D=F.relationshipMetaData();if(D=D.filter((e=>e.id===I[0].id)),!1===o.hasField(I[0].keyField)||null===o.field(I[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[I[0].keyField]);if(e){const t=B.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[I[0].keyField]},F.filter(t)}return new k({parentfeatureset:F})}const E=B.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return E.parameters={id:o.field(I[0].keyField)},F.filter(E)}))},G.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),G.functions.featuresetbyassociation=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,3,e,t);const o=s[0],f=h(T(s[1],"")).toLowerCase(),d=Q(s[2])?h(s[2]):null;if(null===s[0])return null;if(!b(s[0]))throw new i(e,a.InvalidParameter,t);let c=o._layer;if(c instanceof K&&(c=l(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===w(c))return null;await c.load();const p=c.serviceUrl(),y=await u(p,e.spatialReference);let I=null,g=null,F=!1;if(null!==d&&""!==d&&void 0!==d){for(const e of y.terminals)e.terminalName===d&&(g=e.terminalId);null===g&&(F=!0)}const D=y.associations.getFieldsIndex(),x=D.get("TOGLOBALID").name,E=D.get("FROMGLOBALID").name,A=D.get("TOTERMINALID").name,N=D.get("FROMTERMINALID").name,L=D.get("FROMNETWORKSOURCEID").name,C=D.get("TONETWORKSOURCEID").name,U=D.get("ASSOCIATIONTYPE").name,M=D.get("ISCONTENTVISIBLE").name,R=D.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){I=o.field(e.name);break}let k=null,O=new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),B.create("''",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));const W="globalid",G="globalId",_={};for(const e in y.lkp)_[e]=y.lkp[e].sourceId;const V=new $(new q({name:"classname",alias:"classname",type:"string"}),null,_);let J="";switch(f){case"midspan":{J=`((${x}='${I}') OR ( ${E}='${I}')) AND (${U} IN (5))`,V.codefield=B.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=H(P.findField(y.associations.fields,E));e.name=W,e.alias=W,k=new Z(e,B.create(`CASE WHEN (${E}='${I}') THEN ${x} ELSE ${E} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),O=y.unVersion>=4?new j(P.findField(y.associations.fields,D.get("PERCENTALONG").name)):new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{J=`((${x}='${I}') OR ( ${E}='${I}')) AND (${U} IN (4,6))`,V.codefield=B.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=H(P.findField(y.associations.fields,E));e.name=W,e.alias=W,k=new Z(e,B.create(`CASE WHEN (${E}='${I}') THEN ${x} ELSE ${E} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),B.create(`CASE WHEN (${U}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${x}='@T'`,t=`${E}='@T'`;null!==g&&(e+=` AND ${A}=@A`,t+=` AND ${N}=@A`),J="(("+e+") OR ("+t+"))",J=S(J,"@T",I??""),e=S(e,"@T",I??""),null!==g&&(e=S(e,"@A",g.toString()),J=S(J,"@A",g.toString())),V.codefield=B.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const n=H(P.findField(y.associations.fields,E));n.name=W,n.alias=W,k=new Z(n,B.create("CASE WHEN "+e+` THEN ${E} ELSE ${x} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"container":J=`${x}='${I}' AND ${U} = 2`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,E),W,W);break;case"content":J=`(${E}='${I}' AND ${U} = 2)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),W,W);break;case"structure":J=`(${x}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,E),W,G);break;case"attached":J=`(${E}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),W,G);break;default:throw new i(e,a.InvalidParameter,t)}F&&(J="1 <> 1");return new P({parentfeatureset:y.associations,adaptedFields:[new j(P.findField(y.associations.fields,R)),new j(P.findField(y.associations.fields,M)),k,z,V,O],extraFilter:J?B.create(J,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}):null})}))},G.signatures.push({name:"featuresetbyassociation",min:2,max:6}),G.functions.groupby=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{if(m(o,3,3,e,t),!w(o[0]))throw new i(e,a.InvalidParameter,t);const l=await o[0].load(),f=[],d=[];let u=!1,c=[];if(Q(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(J(o[1]))c=o[1];else{if(!E(o[1]))throw new i(e,a.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(Q(m)){const e=B.create(h(m),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),t=!0===W(e)?h(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(u=!0)}else{if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(u=!0),!n)throw new i(e,a.InvalidParameter,t);f.push({name:n,expression:B.create(r||n,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],Q(o[2]))c.push(o[2]);else if(J(o[2]))c=o[2];else if(E(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new i(e,a.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new i(e,a.InvalidParameter,t);d.push({name:n,statistic:r.toLowerCase(),expression:B.create(s,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)ee(t.expression,G,e);for(const t of d)ee(t.expression,G,e);return o[0].groupby(f,d)}))},G.signatures.push({name:"groupby",min:3,max:3}),G.functions.distinct=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{if(w(o[0])){m(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(Q(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(J(o[1]))l=o[1];else{if(!E(o[1]))throw new i(e,a.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(Q(o)){const e=B.create(h(o),{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),t=!0===W(e)?h(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new i(e,a.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new i(e,a.InvalidParameter,t);s.push({name:n,expression:B.create(l||n,{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)ee(t.expression,G,e);return o[0].groupby(s,[])}return X(o)}))},G.functions.getfeaturesetinfo=function(e,t){return G.standardFunctionAsync(e,t,(async(i,a,r)=>{if(m(r,1,1,e,t),!w(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},g(e),!1,!1):null}))},G.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),G.functions.filterbysubtypecode=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const n=await s[0].load(),r=s[1];if(!Y(r))throw new i(e,a.InvalidParameter,t);if(n.subtypeField){const e=B.create(`${n.subtypeField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new i(e,a.FeatureSetDoesNotHaveSubtypes,t);const o=B.create(`${n.typeIdField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:o})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as n}from"../ArcadeDate.js";import{ArcadeExecutionError as t,ExecutionErrorCodes as e}from"../executionError.js";import{B as a,p as r,m as i,E as o,H as s}from"../../chunks/languageUtils.js";import{calculateStat as c}from"./fieldStats.js";import{SqlTimeStampOffset as u}from"../../core/sql/SqlTimestampOffset.js";import f from"../../core/sql/WhereClause.js";import{isArray as d,isString as m}from"../../support/guards.js";async function l(n,t,e,a){if(1===e.length){if(d(e[0]))return c(n,e[0],o(e[1],-1));if(i(e[0]))return c(n,e[0].toArray(),o(e[1],-1))}else if(2===e.length){if(d(e[0]))return c(n,e[0],o(e[1],-1));if(i(e[0]))return c(n,e[0].toArray(),o(e[1],-1));if(r(e[0])){const r=await e[0].load(),i=await p(f.create(e[1],{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),a,t);return g(t,await e[0].calculateStatistic(n,i,o(e[2],1e3),t.abortSignal))}}else if(3===e.length&&r(e[0])){const r=await e[0].load(),i=await p(f.create(e[1],{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),a,t);return g(t,await e[0].calculateStatistic(n,i,o(e[2],1e3),t.abortSignal))}return c(n,e,-1)}function g(t,e){return e instanceof u?n.fromReaderAsTimeStampOffset(e.toStorageFormat()):e instanceof Date?n.dateJSAndZoneToArcadeDate(e,s(t)):e}async function p(n,t,e){const a=n.getVariables();if(a.length>0){const r={};for(const n of a)r[n]=t.evaluateIdentifier(e,{name:n});n.parameters=r}return n}function y(n){"async"===n.mode&&(n.functions.stdev=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("stdev",t,r,n)))},n.functions.variance=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("variance",t,r,n)))},n.functions.average=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("mean",t,r,n)))},n.functions.mean=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("mean",t,r,n)))},n.functions.sum=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("sum",t,r,n)))},n.functions.min=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("min",t,r,n)))},n.functions.max=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("max",t,r,n)))},n.functions.count=function(o,s){return n.standardFunctionAsync(o,s,(async(n,c,u)=>{if(a(u,1,1,o,s),r(u[0]))return u[0].count(n.abortSignal);if(d(u[0])||m(u[0]))return u[0].length;if(i(u[0]))return u[0].length();throw new t(o,e.InvalidParameter,s)}))})}export{y as registerFunctions};
5
+ import{ArcadeDate as n}from"../ArcadeDate.js";import{ArcadeExecutionError as t,ExecutionErrorCodes as e}from"../executionError.js";import{B as a,p as r,m as i,G as o,H as s}from"../../chunks/languageUtils.js";import{calculateStat as c}from"./fieldStats.js";import{SqlTimeStampOffset as u}from"../../core/sql/SqlTimestampOffset.js";import f from"../../core/sql/WhereClause.js";import{isArray as d,isString as m}from"../../support/guards.js";async function l(n,t,e,a){if(1===e.length){if(d(e[0]))return c(n,e[0],o(e[1],-1));if(i(e[0]))return c(n,e[0].toArray(),o(e[1],-1))}else if(2===e.length){if(d(e[0]))return c(n,e[0],o(e[1],-1));if(i(e[0]))return c(n,e[0].toArray(),o(e[1],-1));if(r(e[0])){const r=await e[0].load(),i=await p(f.create(e[1],{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),a,t);return g(t,await e[0].calculateStatistic(n,i,o(e[2],1e3),t.abortSignal))}}else if(3===e.length&&r(e[0])){const r=await e[0].load(),i=await p(f.create(e[1],{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),a,t);return g(t,await e[0].calculateStatistic(n,i,o(e[2],1e3),t.abortSignal))}return c(n,e,-1)}function g(t,e){return e instanceof u?n.fromReaderAsTimeStampOffset(e.toStorageFormat()):e instanceof Date?n.dateJSAndZoneToArcadeDate(e,s(t)):e}async function p(n,t,e){const a=n.getVariables();if(a.length>0){const r={};for(const n of a)r[n]=t.evaluateIdentifier(e,{name:n});n.parameters=r}return n}function y(n){"async"===n.mode&&(n.functions.stdev=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("stdev",t,r,n)))},n.functions.variance=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("variance",t,r,n)))},n.functions.average=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("mean",t,r,n)))},n.functions.mean=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("mean",t,r,n)))},n.functions.sum=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("sum",t,r,n)))},n.functions.min=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("min",t,r,n)))},n.functions.max=function(t,e){return n.standardFunctionAsync(t,e,((e,a,r)=>l("max",t,r,n)))},n.functions.count=function(o,s){return n.standardFunctionAsync(o,s,(async(n,c,u)=>{if(a(u,1,1,o,s),r(u[0]))return u[0].count(n.abortSignal);if(d(u[0])||m(u[0]))return u[0].length;if(i(u[0]))return u[0].length();throw new t(o,e.InvalidParameter,s)}))})}export{y as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{B as t,n as r,Q as o,f as i,p as c,Z as s,P as d,H as u,S as m,_ as f,T as l,$ as y,E as v,t as w,O as p}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as h}from"../featureset/support/shared.js";function T(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:h[a.field.type],codedValues:a.domain.codedValues.map((n=>({name:n.name,code:n.code})))},u(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:h[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},u(e)):null}function b(h){"async"===h.mode&&(h.functions.domain=function(n,d){return h.standardFunctionAsync(n,d,(async(u,m,f)=>{if(t(f,2,3,n,d),r(f[0])){return T(o(f[0],i(f[1]),void 0===f[2]?void 0:f[2]),n)}if(c(f[0])){await f[0]._ensureLoaded();return T(s(i(f[1]),f[0],null,void 0===f[2]?void 0:f[2]),n)}throw new a(n,e.InvalidParameter,d)}))},h.functions.subtypes=function(o,i){return h.standardFunctionAsync(o,i,(async(s,m,f)=>{if(t(f,1,1,o,i),r(f[0])){const a=d(f[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}if(c(f[0])){await f[0]._ensureLoaded();const a=f[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))},h.functions.domainname=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,l)=>{if(t(l,2,4,n,o),r(l[0]))return m(l[0],i(l[1]),l[2],void 0===l[3]?void 0:l[3]);if(c(l[0])){await l[0]._ensureLoaded();const n=s(i(l[1]),l[0],null,void 0===l[3]?void 0:l[3]);return f(n,l[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domainname",min:2,max:4}),h.functions.domaincode=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,m)=>{if(t(m,2,4,n,o),r(m[0]))return l(m[0],i(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(c(m[0])){await m[0]._ensureLoaded();const n=s(i(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return y(n,m[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domaincode",min:2,max:4}),h.functions.text=function(n,r){return h.standardFunctionAsync(n,r,(async(o,i,s)=>{if(t(s,1,2,n,r),c(s[0])){const t=v(s[1],"");if(""===t)return s[0].castToText();if("schema"===t.toLowerCase())return s[0].convertToText("schema",o.abortSignal);if("featureset"===t.toLowerCase())return s[0].convertToText("featureset",o.abortSignal);throw new a(n,e.InvalidParameter,r)}return w(s[0],s[1])}))},h.functions.gdbversion=function(n,o){return h.standardFunctionAsync(n,o,(async(i,s,d)=>{if(t(d,1,1,n,o),r(d[0]))return d[0].gdbVersion();if(c(d[0])){return(await d[0].load()).gdbVersion}throw new a(n,e.InvalidParameter,o)}))},h.functions.schema=function(o,i){return h.standardFunctionAsync(o,i,(async(s,d,m)=>{if(t(m,1,1,o,i),c(m[0]))return await m[0].load(),n.convertObjectToArcadeDictionary(m[0].schema(),u(o));if(r(m[0])){const a=p(m[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))})}export{b as registerFunctions};
5
+ import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{B as t,n as r,Q as o,f as i,p as c,Z as s,P as d,H as u,S as m,_ as f,T as l,$ as y,G as v,t as w,O as p}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as h}from"../featureset/support/shared.js";function T(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:h[a.field.type],codedValues:a.domain.codedValues.map((n=>({name:n.name,code:n.code})))},u(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:h[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},u(e)):null}function b(h){"async"===h.mode&&(h.functions.domain=function(n,d){return h.standardFunctionAsync(n,d,(async(u,m,f)=>{if(t(f,2,3,n,d),r(f[0])){return T(o(f[0],i(f[1]),void 0===f[2]?void 0:f[2]),n)}if(c(f[0])){await f[0]._ensureLoaded();return T(s(i(f[1]),f[0],null,void 0===f[2]?void 0:f[2]),n)}throw new a(n,e.InvalidParameter,d)}))},h.functions.subtypes=function(o,i){return h.standardFunctionAsync(o,i,(async(s,m,f)=>{if(t(f,1,1,o,i),r(f[0])){const a=d(f[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}if(c(f[0])){await f[0]._ensureLoaded();const a=f[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))},h.functions.domainname=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,l)=>{if(t(l,2,4,n,o),r(l[0]))return m(l[0],i(l[1]),l[2],void 0===l[3]?void 0:l[3]);if(c(l[0])){await l[0]._ensureLoaded();const n=s(i(l[1]),l[0],null,void 0===l[3]?void 0:l[3]);return f(n,l[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domainname",min:2,max:4}),h.functions.domaincode=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,m)=>{if(t(m,2,4,n,o),r(m[0]))return l(m[0],i(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(c(m[0])){await m[0]._ensureLoaded();const n=s(i(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return y(n,m[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domaincode",min:2,max:4}),h.functions.text=function(n,r){return h.standardFunctionAsync(n,r,(async(o,i,s)=>{if(t(s,1,2,n,r),c(s[0])){const t=v(s[1],"");if(""===t)return s[0].castToText();if("schema"===t.toLowerCase())return s[0].convertToText("schema",o.abortSignal);if("featureset"===t.toLowerCase())return s[0].convertToText("featureset",o.abortSignal);throw new a(n,e.InvalidParameter,r)}return w(s[0],s[1])}))},h.functions.gdbversion=function(n,o){return h.standardFunctionAsync(n,o,(async(i,s,d)=>{if(t(d,1,1,n,o),r(d[0]))return d[0].gdbVersion();if(c(d[0])){return(await d[0].load()).gdbVersion}throw new a(n,e.InvalidParameter,o)}))},h.functions.schema=function(o,i){return h.standardFunctionAsync(o,i,(async(s,d,m)=>{if(t(m,1,1,o,i),c(m[0]))return await m[0].load(),n.convertObjectToArcadeDictionary(m[0].schema(),u(o));if(r(m[0])){const a=p(m[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))})}export{b as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import n from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as e,ExecutionErrorCodes as r}from"../executionError.js";import{cloneGeometry as i,convertSquareUnitsToCode as a,convertLinearUnitsToCode as o}from"../kernel.js";import{C as l,B as s,g as u,k as c,j as f,f as d,m as w,s as m,p as h,E as p,D as y,F as g,G as v,d as P,e as I,H as A}from"../../chunks/languageUtils.js";import{getPortal as F}from"../portalUtils.js";import{centroidPolyline as j,centroidMultiPoint as R,getMetersPerVerticalUnitForSR as b,segmentLength3d as N}from"./centroid.js";import{measureToCoordinate as O,pointToCoordinate as x,distanceToCoordinate as S}from"./measures.js";import{getMetersPerUnitForSR as D}from"../../core/unitUtils.js";import T from"../../geometry/Extent.js";import k from"../../geometry/Geometry.js";import{disjoint as C,intersects as E,touches as L,crosses as M,within as Z,contains as J,overlaps as U,equals as z,relate as W,intersect as q,union as G,difference as B,symmetricDifference as H,clip as V,cut as K,planarArea as Q,geodesicArea as X,planarLength as Y,geodesicLength as $,distance as _,densify as nn,geodesicDensify as tn,generalize as en,buffer as rn,geodesicBuffer as an,offset as on,rotate as ln,simplify as sn,isSimple as un,convexHull as cn,nearestCoordinate as fn,nearestVertex as dn}from"../../geometry/geometryEngineAsync.js";import wn from"../../geometry/Multipoint.js";import mn from"../../geometry/Point.js";import hn from"../../geometry/Polygon.js";import pn from"../../geometry/Polyline.js";import{fromJSON as yn}from"../../geometry/support/jsonUtils.js";import gn from"../../portal/Portal.js";import{lookupUser as vn}from"../../portal/support/utils.js";import{isArray as Pn,isNumber as In}from"../../support/guards.js";function An(n,t,i){if(s(n,2,2,t,i),n[0]instanceof k&&n[1]instanceof k);else if(n[0]instanceof k&&null===n[1]);else if(n[1]instanceof k&&null===n[0]);else if(null!==n[0]||null!==n[1])throw new e(t,r.InvalidParameter,i)}async function Fn(n,t){if("polygon"!==n.type&&"polyline"!==n.type&&"extent"!==n.type)return 0;let e=1;if(n.spatialReference.vcsWkid||n.spatialReference.latestVcsWkid){e=b(n.spatialReference)/D(n.spatialReference)}let r=0;if("polyline"===n.type)for(const a of n.paths)for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],e);else if("polygon"===n.type)for(const a of n.rings){for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],e);(a[0][0]!==a[a.length-1][0]||a[0][1]!==a[a.length-1][1]||void 0!==a[0][2]&&a[0][2]!==a[a.length-1][2])&&(r+=N(a[0],a[a.length-1],e))}else"extent"===n.type&&(r+=2*N([n.xmin,n.ymin,0],[n.xmax,n.ymin,0],e),r+=2*N([n.xmin,n.ymin,0],[n.xmin,n.ymax,0],e),r*=2,r+=4*Math.abs(p(n.zmax,0)*e-p(n.zmin,0)*e));const i=new pn({hasZ:!1,hasM:!1,spatialReference:n.spatialReference,paths:[[[0,0],[0,r]]]});return Y(i,t)}function jn(b){"async"===b.mode&&(b.functions.disjoint=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null===i[0]||null===i[1]||C(i[0],i[1]))))},b.functions.intersects=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&E(i[0],i[1]))))},b.functions.touches=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&L(i[0],i[1]))))},b.functions.crosses=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&M(i[0],i[1]))))},b.functions.within=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&Z(i[0],i[1]))))},b.functions.contains=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&J(i[0],i[1]))))},b.functions.overlaps=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&U(i[0],i[1]))))},b.functions.equals=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(s(i,2,2,n,t),i[0]===i[1]||(i[0]instanceof k&&i[1]instanceof k?z(i[0],i[1]):(u(i[0])&&u(i[1])||!!(c(i[0])&&c(i[1])||f(i[0])&&f(i[1])))&&i[0].equals(i[1])))))},b.functions.relate=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,3,3,n,t),o[0]instanceof k&&o[1]instanceof k)return W(o[0],o[1],d(o[2]));if(o[0]instanceof k&&null===o[1])return!1;if(o[1]instanceof k&&null===o[0])return!1;if(null===o[0]&&null===o[1])return!1;throw new e(n,r.InvalidParameter,t)}))},b.functions.intersection=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null===i[0]||null===i[1]?null:q(i[0],i[1]))))},b.functions.union=function(n,t){return b.standardFunctionAsync(n,t,((a,o,s)=>{const u=[];if(0===(s=l(s)).length)throw new e(n,r.WrongNumberOfParameters,t);if(1===s.length)if(Pn(s[0])){const i=l(s[0]);for(let a=0;a<i.length;a++)if(null!==i[a]){if(!(i[a]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(i[a])}}else{if(!w(s[0])){if(s[0]instanceof k)return m(i(s[0]),n.spatialReference);if(null===s[0])return null;throw new e(n,r.InvalidParameter,t)}{const i=l(s[0].toArray());for(let a=0;a<i.length;a++)if(null!==i[a]){if(!(i[a]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(i[a])}}}else for(let i=0;i<s.length;i++)if(null!==s[i]){if(!(s[i]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(s[i])}return 0===u.length?null:G(u)}))},b.functions.difference=function(n,t){return b.standardFunctionAsync(n,t,((e,r,a)=>(An(a=l(a),n,t),null===a[0]?null:null===a[1]?i(a[0]):B(a[0],a[1]))))},b.functions.symmetricdifference=function(n,t){return b.standardFunctionAsync(n,t,((e,r,a)=>(An(a=l(a),n,t),null===a[0]&&null===a[1]?null:null===a[0]?i(a[1]):null===a[1]?i(a[0]):H(a[0],a[1]))))},b.functions.clip=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,2,2,n,t),!(o[1]instanceof T)&&null!==o[1])throw new e(n,r.InvalidParameter,t);if(null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return null===o[1]?null:V(o[0],o[1])}))},b.functions.cut=function(n,t){return b.standardFunctionAsync(n,t,((a,o,u)=>{if(u=l(u),s(u,2,2,n,t),!(u[1]instanceof pn)&&null!==u[1])throw new e(n,r.InvalidParameter,t);if(null===u[0])return[];if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return null===u[1]?[i(u[0])]:K(u[0],u[1])}))},b.functions.area=function(n,t){return b.standardFunctionAsync(n,t,(async(i,o,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumArea(a(p(u[1],-1)),!1,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=y(u[0],n.spatialReference);return null===t?0:Q(t,a(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return Q(u[0],a(p(u[1],-1)))}))},b.functions.areageodetic=function(n,t){return b.standardFunctionAsync(n,t,(async(i,o,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumArea(a(p(u[1],-1)),!0,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=y(u[0],n.spatialReference);return null===t?0:X(t,a(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return X(u[0],a(p(u[1],-1)))}))},b.functions.length=function(n,t){return b.standardFunctionAsync(n,t,(async(i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumLength(o(p(u[1],-1)),!1,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:Y(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return Y(u[0],o(p(u[1],-1)))}))},b.functions.length3d=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:!0===t.hasZ?Fn(t,o(p(u[1],-1))):Y(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return!0===u[0].hasZ?Fn(u[0],o(p(u[1],-1))):Y(u[0],o(p(u[1],-1)))}))},b.functions.lengthgeodetic=function(n,t){return b.standardFunctionAsync(n,t,(async(i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumLength(o(p(u[1],-1)),!0,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:$(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return $(u[0],o(p(u[1],-1)))}))},b.functions.distance=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{u=l(u),s(u,2,3,n,t);let c=u[0];(Pn(u[0])||w(u[0]))&&(c=v(u[0],n.spatialReference));let f=u[1];if((Pn(u[1])||w(u[1]))&&(f=v(u[1],n.spatialReference)),!(c instanceof k))throw new e(n,r.InvalidParameter,t);if(!(f instanceof k))throw new e(n,r.InvalidParameter,t);return _(c,f,o(p(u[2],-1)))}))},b.functions.distancegeodetic=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{u=l(u),s(u,2,3,n,t);const c=u[0],f=u[1];if(!(c instanceof mn))throw new e(n,r.InvalidParameter,t);if(!(f instanceof mn))throw new e(n,r.InvalidParameter,t);const d=new pn({paths:[],spatialReference:c.spatialReference});return d.addPath([c,f]),$(d,o(p(u[2],-1)))}))},b.functions.densify=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,3,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);if(c<=0)throw new e(n,r.InvalidParameter,t);return u[0]instanceof hn||u[0]instanceof pn?nn(u[0],c,o(p(u[2],-1))):u[0]instanceof T?nn(hn.fromExtent(u[0]),c,o(p(u[2],-1))):u[0]}))},b.functions.densifygeodetic=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,3,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);if(c<=0)throw new e(n,r.InvalidParameter,t);return u[0]instanceof hn||u[0]instanceof pn?tn(u[0],c,o(p(u[2],-1))):u[0]instanceof T?tn(hn.fromExtent(u[0]),c,o(p(u[2],-1))):u[0]}))},b.functions.generalize=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,4,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);return en(u[0],c,I(p(u[2],!0)),o(p(u[3],-1)))}))},b.functions.buffer=function(n,t){return b.standardFunctionAsync(n,t,((a,u,c)=>{if(c=l(c),s(c,2,3,n,t),null===c[0])return null;if(!(c[0]instanceof k))throw new e(n,r.InvalidParameter,t);const f=P(c[1]);if(isNaN(f))throw new e(n,r.InvalidParameter,t);return 0===f?i(c[0]):rn(c[0],f,o(p(c[2],-1)))}))},b.functions.buffergeodetic=function(n,t){return b.standardFunctionAsync(n,t,((a,u,c)=>{if(c=l(c),s(c,2,3,n,t),null===c[0])return null;if(!(c[0]instanceof k))throw new e(n,r.InvalidParameter,t);const f=P(c[1]);if(isNaN(f))throw new e(n,r.InvalidParameter,t);return 0===f?i(c[0]):an(c[0],f,o(p(c[2],-1)))}))},b.functions.offset=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,6,n,t),null===u[0])return null;if(!(u[0]instanceof hn||u[0]instanceof pn))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);const f=P(p(u[4],10));if(isNaN(f))throw new e(n,r.InvalidParameter,t);const w=P(p(u[5],0));if(isNaN(w))throw new e(n,r.InvalidParameter,t);return on(u[0],c,o(p(u[2],-1)),d(p(u[3],"round")).toLowerCase(),f,w)}))},b.functions.rotate=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,2,3,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);const u=o[0]instanceof T?hn.fromExtent(o[0]):o[0],c=P(o[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);const f=p(o[2],null);if(null===f)return ln(u,c);if(f instanceof mn)return ln(u,c,f);throw new e(n,r.InvalidParameter,t)}))},b.functions.centroid=function(n,t){return b.standardFunctionAsync(n,t,((a,o,u)=>{if(u=l(u),s(u,1,1,n,t),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=v(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,t);return c instanceof mn?m(i(c),n.spatialReference):c instanceof hn?c.centroid:c instanceof pn?j(c):c instanceof wn?R(c):c instanceof T?c.center:null}))},b.functions.measuretocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const f=O(c,u[1]);return f?t.convertObjectToArcadeDictionary(f,A(n),!1,!0):null}))},b.functions.pointtocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);const f=u[1];if(null===f)return null;if(!(f instanceof mn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const d=x(c,f);return d?t.convertObjectToArcadeDictionary(d,A(n),!1,!0):null}))},b.functions.distancetocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const f=S(c,u[1]);return f?t.convertObjectToArcadeDictionary(f,A(n),!1,!0):null}))},b.functions.multiparttosinglepart=function(n,t){return b.standardFunctionAsync(n,t,(async(a,o,u)=>{if(u=l(u),s(u,1,1,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);if(u[0]instanceof mn)return[m(i(u[0]),n.spatialReference)];if(u[0]instanceof T)return[m(i(u[0]),n.spatialReference)];const c=await sn(u[0]);if(c instanceof hn){const n=[],t=[];for(let e=0;e<c.rings.length;e++)if(c.isClockwise(c.rings[e])){const t=yn({rings:[c.rings[e]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(t)}else t.push({ring:c.rings[e],pt:c.getPoint(e,0)});for(let e=0;e<t.length;e++)for(let r=0;r<n.length;r++)if(n[r].contains(t[e].pt)){n[r].addRing(t[e].ring);break}return n}if(c instanceof pn){const n=[];for(let t=0;t<c.paths.length;t++){const e=yn({paths:[c.paths[t]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(e)}return n}if(u[0]instanceof wn){const t=[],e=m(i(u[0]),n.spatialReference);for(let n=0;n<e.points.length;n++)t.push(e.getPoint(n));return t}return null}))},b.functions.issimple=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return!0;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return un(o[0])}))},b.functions.simplify=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return sn(o[0])}))},b.functions.convexhull=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return cn(o[0])}))},b.functions.getuser=function(i,a){return b.standardFunctionAsync(i,a,(async(o,l,u)=>{s(u,0,2,i,a);let c=p(u[1],""),f=!0===c;if(c=!0===c||!1===c?"":d(c),0===u.length||u[0]instanceof n){let n;n=i.services?.portal?i.services.portal:gn.getDefault(),u.length>0&&(n=F(u[0],n));const e=await vn(n,c,f);if(e){const n=JSON.parse(JSON.stringify(e));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,A(i))}return null}let w=null;if(h(u[0])&&(w=u[0]),w){if(f=!1,c)return null;await w.load();const e=await w.getOwningSystemUrl();if(!e){if(!c){const n=await w.getIdentityUser();return n?t.convertObjectToArcadeDictionary({username:n},A(i)):null}return null}let r;r=i.services?.portal?i.services.portal:gn.getDefault(),r=F(new n(e),r);const a=await vn(r,c,f);if(a){const n=JSON.parse(JSON.stringify(a));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,A(i))}return null}throw new e(i,r.InvalidParameter,a)}))},b.functions.nearestcoordinate=function(n,i){return b.standardFunctionAsync(n,i,(async(a,o,u)=>{if(u=l(u),s(u,2,2,n,i),!(u[0]instanceof k||null===u[0]))throw new e(n,r.InvalidParameter,i);if(!(u[1]instanceof mn||null===u[1]))throw new e(n,r.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const c=await fn(u[0],u[1]);return null===c?null:t.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"},A(n),!1,!0)}))},b.functions.nearestvertex=function(n,i){return b.standardFunctionAsync(n,i,(async(a,o,u)=>{if(u=l(u),s(u,2,2,n,i),!(u[0]instanceof k||null===u[0]))throw new e(n,r.InvalidParameter,i);if(!(u[1]instanceof mn||null===u[1]))throw new e(n,r.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const c=await dn(u[0],u[1]);return null===c?null:t.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"},A(n),!1,!0)}))})}export{jn as registerFunctions};
5
+ import n from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as e,ExecutionErrorCodes as r}from"../executionError.js";import{cloneGeometry as i,convertSquareUnitsToCode as a,convertLinearUnitsToCode as o}from"../kernel.js";import{C as l,B as s,g as u,k as c,j as f,f as d,m as w,s as m,p as h,G as p,D as y,E as g,F as v,d as P,e as I,H as A}from"../../chunks/languageUtils.js";import{getPortal as F}from"../portalUtils.js";import{centroidPolyline as j,centroidMultiPoint as R,getMetersPerVerticalUnitForSR as b,segmentLength3d as N}from"./centroid.js";import{measureToCoordinate as O,pointToCoordinate as x,distanceToCoordinate as S}from"./measures.js";import{getMetersPerUnitForSR as D}from"../../core/unitUtils.js";import T from"../../geometry/Extent.js";import k from"../../geometry/Geometry.js";import{disjoint as C,intersects as E,touches as L,crosses as M,within as Z,contains as J,overlaps as U,equals as z,relate as W,intersect as q,union as G,difference as B,symmetricDifference as H,clip as V,cut as K,planarArea as Q,geodesicArea as X,planarLength as Y,geodesicLength as $,distance as _,densify as nn,geodesicDensify as tn,generalize as en,buffer as rn,geodesicBuffer as an,offset as on,rotate as ln,simplify as sn,isSimple as un,convexHull as cn,nearestCoordinate as fn,nearestVertex as dn}from"../../geometry/geometryEngineAsync.js";import wn from"../../geometry/Multipoint.js";import mn from"../../geometry/Point.js";import hn from"../../geometry/Polygon.js";import pn from"../../geometry/Polyline.js";import{fromJSON as yn}from"../../geometry/support/jsonUtils.js";import gn from"../../portal/Portal.js";import{lookupUser as vn}from"../../portal/support/utils.js";import{isArray as Pn,isNumber as In}from"../../support/guards.js";function An(n,t,i){if(s(n,2,2,t,i),n[0]instanceof k&&n[1]instanceof k);else if(n[0]instanceof k&&null===n[1]);else if(n[1]instanceof k&&null===n[0]);else if(null!==n[0]||null!==n[1])throw new e(t,r.InvalidParameter,i)}async function Fn(n,t){if("polygon"!==n.type&&"polyline"!==n.type&&"extent"!==n.type)return 0;let e=1;if(n.spatialReference.vcsWkid||n.spatialReference.latestVcsWkid){e=b(n.spatialReference)/D(n.spatialReference)}let r=0;if("polyline"===n.type)for(const a of n.paths)for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],e);else if("polygon"===n.type)for(const a of n.rings){for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],e);(a[0][0]!==a[a.length-1][0]||a[0][1]!==a[a.length-1][1]||void 0!==a[0][2]&&a[0][2]!==a[a.length-1][2])&&(r+=N(a[0],a[a.length-1],e))}else"extent"===n.type&&(r+=2*N([n.xmin,n.ymin,0],[n.xmax,n.ymin,0],e),r+=2*N([n.xmin,n.ymin,0],[n.xmin,n.ymax,0],e),r*=2,r+=4*Math.abs(p(n.zmax,0)*e-p(n.zmin,0)*e));const i=new pn({hasZ:!1,hasM:!1,spatialReference:n.spatialReference,paths:[[[0,0],[0,r]]]});return Y(i,t)}function jn(b){"async"===b.mode&&(b.functions.disjoint=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null===i[0]||null===i[1]||C(i[0],i[1]))))},b.functions.intersects=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&E(i[0],i[1]))))},b.functions.touches=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&L(i[0],i[1]))))},b.functions.crosses=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&M(i[0],i[1]))))},b.functions.within=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&Z(i[0],i[1]))))},b.functions.contains=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&J(i[0],i[1]))))},b.functions.overlaps=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null!==i[0]&&null!==i[1]&&U(i[0],i[1]))))},b.functions.equals=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(s(i,2,2,n,t),i[0]===i[1]||(i[0]instanceof k&&i[1]instanceof k?z(i[0],i[1]):(u(i[0])&&u(i[1])||!!(c(i[0])&&c(i[1])||f(i[0])&&f(i[1])))&&i[0].equals(i[1])))))},b.functions.relate=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,3,3,n,t),o[0]instanceof k&&o[1]instanceof k)return W(o[0],o[1],d(o[2]));if(o[0]instanceof k&&null===o[1])return!1;if(o[1]instanceof k&&null===o[0])return!1;if(null===o[0]&&null===o[1])return!1;throw new e(n,r.InvalidParameter,t)}))},b.functions.intersection=function(n,t){return b.standardFunctionAsync(n,t,((e,r,i)=>(An(i=l(i),n,t),null===i[0]||null===i[1]?null:q(i[0],i[1]))))},b.functions.union=function(n,t){return b.standardFunctionAsync(n,t,((a,o,s)=>{const u=[];if(0===(s=l(s)).length)throw new e(n,r.WrongNumberOfParameters,t);if(1===s.length)if(Pn(s[0])){const i=l(s[0]);for(let a=0;a<i.length;a++)if(null!==i[a]){if(!(i[a]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(i[a])}}else{if(!w(s[0])){if(s[0]instanceof k)return m(i(s[0]),n.spatialReference);if(null===s[0])return null;throw new e(n,r.InvalidParameter,t)}{const i=l(s[0].toArray());for(let a=0;a<i.length;a++)if(null!==i[a]){if(!(i[a]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(i[a])}}}else for(let i=0;i<s.length;i++)if(null!==s[i]){if(!(s[i]instanceof k))throw new e(n,r.InvalidParameter,t);u.push(s[i])}return 0===u.length?null:G(u)}))},b.functions.difference=function(n,t){return b.standardFunctionAsync(n,t,((e,r,a)=>(An(a=l(a),n,t),null===a[0]?null:null===a[1]?i(a[0]):B(a[0],a[1]))))},b.functions.symmetricdifference=function(n,t){return b.standardFunctionAsync(n,t,((e,r,a)=>(An(a=l(a),n,t),null===a[0]&&null===a[1]?null:null===a[0]?i(a[1]):null===a[1]?i(a[0]):H(a[0],a[1]))))},b.functions.clip=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,2,2,n,t),!(o[1]instanceof T)&&null!==o[1])throw new e(n,r.InvalidParameter,t);if(null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return null===o[1]?null:V(o[0],o[1])}))},b.functions.cut=function(n,t){return b.standardFunctionAsync(n,t,((a,o,u)=>{if(u=l(u),s(u,2,2,n,t),!(u[1]instanceof pn)&&null!==u[1])throw new e(n,r.InvalidParameter,t);if(null===u[0])return[];if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return null===u[1]?[i(u[0])]:K(u[0],u[1])}))},b.functions.area=function(n,t){return b.standardFunctionAsync(n,t,(async(i,o,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumArea(a(p(u[1],-1)),!1,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=y(u[0],n.spatialReference);return null===t?0:Q(t,a(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return Q(u[0],a(p(u[1],-1)))}))},b.functions.areageodetic=function(n,t){return b.standardFunctionAsync(n,t,(async(i,o,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumArea(a(p(u[1],-1)),!0,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=y(u[0],n.spatialReference);return null===t?0:X(t,a(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return X(u[0],a(p(u[1],-1)))}))},b.functions.length=function(n,t){return b.standardFunctionAsync(n,t,(async(i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumLength(o(p(u[1],-1)),!1,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:Y(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return Y(u[0],o(p(u[1],-1)))}))},b.functions.length3d=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:!0===t.hasZ?Fn(t,o(p(u[1],-1))):Y(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return!0===u[0].hasZ?Fn(u[0],o(p(u[1],-1))):Y(u[0],o(p(u[1],-1)))}))},b.functions.lengthgeodetic=function(n,t){return b.standardFunctionAsync(n,t,(async(i,a,u)=>{if(s(u,1,2,n,t),null===(u=l(u))[0])return 0;if(h(u[0])){const i=await u[0].sumLength(o(p(u[1],-1)),!0,n.abortSignal);if(n.abortSignal.aborted)throw new e(n,r.Cancelled,t);return i}if(Pn(u[0])||w(u[0])){const t=g(u[0],n.spatialReference);return null===t?0:$(t,o(p(u[1],-1)))}if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);return $(u[0],o(p(u[1],-1)))}))},b.functions.distance=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{u=l(u),s(u,2,3,n,t);let c=u[0];(Pn(u[0])||w(u[0]))&&(c=v(u[0],n.spatialReference));let f=u[1];if((Pn(u[1])||w(u[1]))&&(f=v(u[1],n.spatialReference)),!(c instanceof k))throw new e(n,r.InvalidParameter,t);if(!(f instanceof k))throw new e(n,r.InvalidParameter,t);return _(c,f,o(p(u[2],-1)))}))},b.functions.distancegeodetic=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{u=l(u),s(u,2,3,n,t);const c=u[0],f=u[1];if(!(c instanceof mn))throw new e(n,r.InvalidParameter,t);if(!(f instanceof mn))throw new e(n,r.InvalidParameter,t);const d=new pn({paths:[],spatialReference:c.spatialReference});return d.addPath([c,f]),$(d,o(p(u[2],-1)))}))},b.functions.densify=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,3,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);if(c<=0)throw new e(n,r.InvalidParameter,t);return u[0]instanceof hn||u[0]instanceof pn?nn(u[0],c,o(p(u[2],-1))):u[0]instanceof T?nn(hn.fromExtent(u[0]),c,o(p(u[2],-1))):u[0]}))},b.functions.densifygeodetic=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,3,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);if(c<=0)throw new e(n,r.InvalidParameter,t);return u[0]instanceof hn||u[0]instanceof pn?tn(u[0],c,o(p(u[2],-1))):u[0]instanceof T?tn(hn.fromExtent(u[0]),c,o(p(u[2],-1))):u[0]}))},b.functions.generalize=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,4,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);return en(u[0],c,I(p(u[2],!0)),o(p(u[3],-1)))}))},b.functions.buffer=function(n,t){return b.standardFunctionAsync(n,t,((a,u,c)=>{if(c=l(c),s(c,2,3,n,t),null===c[0])return null;if(!(c[0]instanceof k))throw new e(n,r.InvalidParameter,t);const f=P(c[1]);if(isNaN(f))throw new e(n,r.InvalidParameter,t);return 0===f?i(c[0]):rn(c[0],f,o(p(c[2],-1)))}))},b.functions.buffergeodetic=function(n,t){return b.standardFunctionAsync(n,t,((a,u,c)=>{if(c=l(c),s(c,2,3,n,t),null===c[0])return null;if(!(c[0]instanceof k))throw new e(n,r.InvalidParameter,t);const f=P(c[1]);if(isNaN(f))throw new e(n,r.InvalidParameter,t);return 0===f?i(c[0]):an(c[0],f,o(p(c[2],-1)))}))},b.functions.offset=function(n,t){return b.standardFunctionAsync(n,t,((i,a,u)=>{if(u=l(u),s(u,2,6,n,t),null===u[0])return null;if(!(u[0]instanceof hn||u[0]instanceof pn))throw new e(n,r.InvalidParameter,t);const c=P(u[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);const f=P(p(u[4],10));if(isNaN(f))throw new e(n,r.InvalidParameter,t);const w=P(p(u[5],0));if(isNaN(w))throw new e(n,r.InvalidParameter,t);return on(u[0],c,o(p(u[2],-1)),d(p(u[3],"round")).toLowerCase(),f,w)}))},b.functions.rotate=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,2,3,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);const u=o[0]instanceof T?hn.fromExtent(o[0]):o[0],c=P(o[1]);if(isNaN(c))throw new e(n,r.InvalidParameter,t);const f=p(o[2],null);if(null===f)return ln(u,c);if(f instanceof mn)return ln(u,c,f);throw new e(n,r.InvalidParameter,t)}))},b.functions.centroid=function(n,t){return b.standardFunctionAsync(n,t,((a,o,u)=>{if(u=l(u),s(u,1,1,n,t),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=v(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,t);return c instanceof mn?m(i(c),n.spatialReference):c instanceof hn?c.centroid:c instanceof pn?j(c):c instanceof wn?R(c):c instanceof T?c.center:null}))},b.functions.measuretocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const f=O(c,u[1]);return f?t.convertObjectToArcadeDictionary(f,A(n),!1,!0):null}))},b.functions.pointtocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);const f=u[1];if(null===f)return null;if(!(f instanceof mn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const d=x(c,f);return d?t.convertObjectToArcadeDictionary(d,A(n),!1,!0):null}))},b.functions.distancetocoordinate=function(n,i){return b.standardFunctionAsync(n,i,((a,o,u)=>{if(u=l(u),s(u,2,2,n,i),null===u[0])return null;let c=u[0];if((Pn(u[0])||w(u[0]))&&(c=g(u[0],n.spatialReference)),null===c)return null;if(!(c instanceof k))throw new e(n,r.InvalidParameter,i);if(!(c instanceof pn))throw new e(n,r.InvalidParameter,i);if(In(!1===u[1]))throw new e(n,r.InvalidParameter,i);const f=S(c,u[1]);return f?t.convertObjectToArcadeDictionary(f,A(n),!1,!0):null}))},b.functions.multiparttosinglepart=function(n,t){return b.standardFunctionAsync(n,t,(async(a,o,u)=>{if(u=l(u),s(u,1,1,n,t),null===u[0])return null;if(!(u[0]instanceof k))throw new e(n,r.InvalidParameter,t);if(u[0]instanceof mn)return[m(i(u[0]),n.spatialReference)];if(u[0]instanceof T)return[m(i(u[0]),n.spatialReference)];const c=await sn(u[0]);if(c instanceof hn){const n=[],t=[];for(let e=0;e<c.rings.length;e++)if(c.isClockwise(c.rings[e])){const t=yn({rings:[c.rings[e]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(t)}else t.push({ring:c.rings[e],pt:c.getPoint(e,0)});for(let e=0;e<t.length;e++)for(let r=0;r<n.length;r++)if(n[r].contains(t[e].pt)){n[r].addRing(t[e].ring);break}return n}if(c instanceof pn){const n=[];for(let t=0;t<c.paths.length;t++){const e=yn({paths:[c.paths[t]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(e)}return n}if(u[0]instanceof wn){const t=[],e=m(i(u[0]),n.spatialReference);for(let n=0;n<e.points.length;n++)t.push(e.getPoint(n));return t}return null}))},b.functions.issimple=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return!0;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return un(o[0])}))},b.functions.simplify=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return sn(o[0])}))},b.functions.convexhull=function(n,t){return b.standardFunctionAsync(n,t,((i,a,o)=>{if(o=l(o),s(o,1,1,n,t),null===o[0])return null;if(!(o[0]instanceof k))throw new e(n,r.InvalidParameter,t);return cn(o[0])}))},b.functions.getuser=function(i,a){return b.standardFunctionAsync(i,a,(async(o,l,u)=>{s(u,0,2,i,a);let c=p(u[1],""),f=!0===c;if(c=!0===c||!1===c?"":d(c),0===u.length||u[0]instanceof n){let n;n=i.services?.portal?i.services.portal:gn.getDefault(),u.length>0&&(n=F(u[0],n));const e=await vn(n,c,f);if(e){const n=JSON.parse(JSON.stringify(e));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,A(i))}return null}let w=null;if(h(u[0])&&(w=u[0]),w){if(f=!1,c)return null;await w.load();const e=await w.getOwningSystemUrl();if(!e){if(!c){const n=await w.getIdentityUser();return n?t.convertObjectToArcadeDictionary({username:n},A(i)):null}return null}let r;r=i.services?.portal?i.services.portal:gn.getDefault(),r=F(new n(e),r);const a=await vn(r,c,f);if(a){const n=JSON.parse(JSON.stringify(a));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,A(i))}return null}throw new e(i,r.InvalidParameter,a)}))},b.functions.nearestcoordinate=function(n,i){return b.standardFunctionAsync(n,i,(async(a,o,u)=>{if(u=l(u),s(u,2,2,n,i),!(u[0]instanceof k||null===u[0]))throw new e(n,r.InvalidParameter,i);if(!(u[1]instanceof mn||null===u[1]))throw new e(n,r.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const c=await fn(u[0],u[1]);return null===c?null:t.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"},A(n),!1,!0)}))},b.functions.nearestvertex=function(n,i){return b.standardFunctionAsync(n,i,(async(a,o,u)=>{if(u=l(u),s(u,2,2,n,i),!(u[0]instanceof k||null===u[0]))throw new e(n,r.InvalidParameter,i);if(!(u[1]instanceof mn||null===u[1]))throw new e(n,r.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const c=await dn(u[0],u[1]);return null===c?null:t.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"},A(n),!1,!0)}))})}export{jn as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a}from"../executionError.js";import i from"../Feature.js";import o from"../ImmutablePointArray.js";import{B as l,m as s,s as f,M as c,C as m,n as u,v as p,f as h,g as w,k as y,j as R,i as g,b as d,H as P,z as v,F as I}from"../../chunks/languageUtils.js";import{angle2D as b,angleBetween2D as F,bearing2D as O,bearingBetween2D as S,pathsSelfIntersecting as j}from"./centroid.js";import N from"../../geometry/Extent.js";import x from"../../geometry/Geometry.js";import J from"../../geometry/Multipoint.js";import D from"../../geometry/Point.js";import G from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{isClockwise as Z}from"../../geometry/support/coordsUtils.js";import{fromJSON as z}from"../../geometry/support/jsonUtils.js";import{isArray as W,isString as A,isNumber as M,isBoolean as q}from"../../support/guards.js";function L(L,U){L.ringisclockwise=function(e,t){return U(e,t,((n,i,f)=>{l(f,1,1,e,t);let c=[];if(null===f[0])return!1;if(W(f[0]))for(const o of f[0]){if(!(o instanceof D))throw new r(e,a.InvalidParameter,t);c.push(o.hasZ?o.hasM?[o.x,o.y,o.z,o.m]:[o.x,o.y,o.z]:[o.x,o.y])}else if(f[0]instanceof o)c=f[0]._elements;else{if(!s(f[0]))throw new r(e,a.InvalidParameter,t);for(const n of f[0].toArray()){if(!(n instanceof D))throw new r(e,a.InvalidParameter,t);c.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(c.length<3)&&Z(c)}))},L.polygon=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof G==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof G)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new G(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.polyline=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof k==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof k)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.point=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof D==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof D)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new D(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.multipoint=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof J==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof J)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new J(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.extent=function(e,t){return U(e,t,((o,s,u)=>{u=m(u),l(u,1,1,e,t);let p=null;if(u[0]instanceof n)p=f(i.parseGeometryFromDictionary(u[0],e.spatialReference),e.spatialReference);else if(u[0]instanceof D){const e={xmin:u[0].x,ymin:u[0].y,xmax:u[0].x,ymax:u[0].y,spatialReference:u[0].spatialReference.toJSON()},t=u[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=z(e)}else if(u[0]instanceof G)p=z(u[0].extent?.toJSON());else if(u[0]instanceof k)p=z(u[0].extent?.toJSON());else if(u[0]instanceof J)p=z(u[0].extent?.toJSON());else if(u[0]instanceof N)p=z(u[0].toJSON());else{const t=JSON.parse(u[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(new N(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.geometry=function(e,t){return U(e,t,((o,s,m)=>{l(m,1,1,e,t);let p=null;if(null===m[0])return null;if(u(m[0]))p=f(m[0].geometry(),e.spatialReference);else if(m[0]instanceof n)p=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(z(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.setgeometry=function(e,t){return U(e,t,((n,i,o)=>{if(l(o,2,2,e,t),!u(o[0]))throw new r(e,a.InvalidParameter,t);if(!0===o[0].immutable)throw new r(e,a.Immutable,t);if(!(o[1]instanceof x||null===o[1]))throw new r(e,a.InvalidParameter,t);return o[0]._geometry=o[1],p}))},L.feature=function(e,t){return U(e,t,((o,l,s)=>{if(0===s.length)throw new r(e,a.WrongNumberOfParameters,t);let c;if(1===s.length)if(A(s[0]))c=i.fromJson(JSON.parse(s[0]),e.timeZone);else if(u(s[0]))c=i.createFromArcadeFeature(s[0]);else if(s[0]instanceof x)c=i.createFromGraphicLikeObject(s[0],null,null,e.timeZone);else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof n&&(t=i.parseGeometryFromDictionary(t,e.spatialReference)),null!==r&&(r=i.parseAttributesFromDictionary(r)),c=i.createFromGraphicLikeObject(t,r,null,e.timeZone)}}else if(2===s.length){let o=null,l=null;if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}if(null!==s[1]){if(!(s[1]instanceof n))throw new r(e,a.InvalidParameter,t);l=i.parseAttributesFromDictionary(s[1])}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}else{let o=null;const l={};if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}for(let n=1;n<s.length;n+=2){const i=h(s[n]),o=s[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||y(o)||R(o)||q(o)))throw new r(e,a.InvalidParameter,t);if(g(o)||!1===d(o))throw new r(e,a.InvalidParameter,t);l[i]=o===p?null:o}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}return c._geometry=f(c.geometry(),e.spatialReference),c.immutable=!1,c}))},L.dictionary=function(e,t){return U(e,t,((i,o,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&A(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof x)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof n)try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(2===l.length&&l[0]instanceof n&&q(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(m){throw new r(e,a.InvalidParameter,t)}if(l.length%2!=0)throw new r(e,a.WrongNumberOfParameters,t);const f={};for(let n=0;n<l.length;n+=2){const i=h(l[n]),o=l[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||q(o)||R(o)||y(o)||W(o)||s(o)))throw new r(e,a.InvalidParameter,t);if(g(o))throw new r(e,a.InvalidParameter,t);f[i]=o===p?null:o}const c=new n(f);return c.immutable=!1,c}))},L.haskey=function(t,i){return U(t,i,((o,s,f)=>{l(f,2,2,t,i);const c=h(f[1]);if(u(f[0]))return f[0].hasField(c);if(f[0]instanceof n)return f[0].hasField(c);if(f[0]instanceof x){const t=e(f[0],c,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,a.InvalidParameter,i)}))},L.hasvalue=function(e,n){return U(e,n,((r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1]))))},L.indexof=function(e,t){return U(e,t,((n,i,o)=>{l(o,2,2,e,t);const f=o[1];if(W(o[0])){for(let e=0;e<o[0].length;e++)if(v(f,o[0][e]))return e;return-1}if(s(o[0])){const e=o[0].length();for(let t=0;t<e;t++)if(v(f,o[0].get(t)))return t;return-1}throw new r(e,a.InvalidParameter,t)}))},L.angle=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?b(o[0],o[1]):F(o[0],o[1],o[2])}))},L.bearing=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?O(o[0],o[1]):S(o[0],o[1],o[2])}))},L.isselfintersecting=function(e,t){return U(e,t,((n,r,a)=>{a=m(a),l(a,1,1,e,t);let i=a[0];if(i instanceof G)return i.isSelfIntersecting;if(i instanceof k)return j(i.paths);if(i instanceof J){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(W(i)||s(i)){const t=I(i,e.spatialReference);return null!==t&&(i=t.paths),j(i)}return!1}))}}export{L as registerFunctions};
5
+ import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a}from"../executionError.js";import i from"../Feature.js";import o from"../ImmutablePointArray.js";import{B as l,m as s,s as f,M as c,C as m,n as u,v as p,f as h,g as w,k as y,j as R,i as g,b as d,H as P,z as v,E as I}from"../../chunks/languageUtils.js";import{angle2D as b,angleBetween2D as F,bearing2D as O,bearingBetween2D as S,pathsSelfIntersecting as j}from"./centroid.js";import N from"../../geometry/Extent.js";import x from"../../geometry/Geometry.js";import J from"../../geometry/Multipoint.js";import D from"../../geometry/Point.js";import G from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{isClockwise as Z}from"../../geometry/support/coordsUtils.js";import{fromJSON as z}from"../../geometry/support/jsonUtils.js";import{isArray as W,isString as A,isNumber as M,isBoolean as q}from"../../support/guards.js";function L(L,U){L.ringisclockwise=function(e,t){return U(e,t,((n,i,f)=>{l(f,1,1,e,t);let c=[];if(null===f[0])return!1;if(W(f[0]))for(const o of f[0]){if(!(o instanceof D))throw new r(e,a.InvalidParameter,t);c.push(o.hasZ?o.hasM?[o.x,o.y,o.z,o.m]:[o.x,o.y,o.z]:[o.x,o.y])}else if(f[0]instanceof o)c=f[0]._elements;else{if(!s(f[0]))throw new r(e,a.InvalidParameter,t);for(const n of f[0].toArray()){if(!(n instanceof D))throw new r(e,a.InvalidParameter,t);c.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(c.length<3)&&Z(c)}))},L.polygon=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof G==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof G)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new G(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.polyline=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof k==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof k)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.point=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof D==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof D)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new D(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.multipoint=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof J==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof J)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new J(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.extent=function(e,t){return U(e,t,((o,s,u)=>{u=m(u),l(u,1,1,e,t);let p=null;if(u[0]instanceof n)p=f(i.parseGeometryFromDictionary(u[0],e.spatialReference),e.spatialReference);else if(u[0]instanceof D){const e={xmin:u[0].x,ymin:u[0].y,xmax:u[0].x,ymax:u[0].y,spatialReference:u[0].spatialReference.toJSON()},t=u[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=z(e)}else if(u[0]instanceof G)p=z(u[0].extent?.toJSON());else if(u[0]instanceof k)p=z(u[0].extent?.toJSON());else if(u[0]instanceof J)p=z(u[0].extent?.toJSON());else if(u[0]instanceof N)p=z(u[0].toJSON());else{const t=JSON.parse(u[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(new N(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.geometry=function(e,t){return U(e,t,((o,s,m)=>{l(m,1,1,e,t);let p=null;if(null===m[0])return null;if(u(m[0]))p=f(m[0].geometry(),e.spatialReference);else if(m[0]instanceof n)p=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(z(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.setgeometry=function(e,t){return U(e,t,((n,i,o)=>{if(l(o,2,2,e,t),!u(o[0]))throw new r(e,a.InvalidParameter,t);if(!0===o[0].immutable)throw new r(e,a.Immutable,t);if(!(o[1]instanceof x||null===o[1]))throw new r(e,a.InvalidParameter,t);return o[0]._geometry=o[1],p}))},L.feature=function(e,t){return U(e,t,((o,l,s)=>{if(0===s.length)throw new r(e,a.WrongNumberOfParameters,t);let c;if(1===s.length)if(A(s[0]))c=i.fromJson(JSON.parse(s[0]),e.timeZone);else if(u(s[0]))c=i.createFromArcadeFeature(s[0]);else if(s[0]instanceof x)c=i.createFromGraphicLikeObject(s[0],null,null,e.timeZone);else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof n&&(t=i.parseGeometryFromDictionary(t,e.spatialReference)),null!==r&&(r=i.parseAttributesFromDictionary(r)),c=i.createFromGraphicLikeObject(t,r,null,e.timeZone)}}else if(2===s.length){let o=null,l=null;if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}if(null!==s[1]){if(!(s[1]instanceof n))throw new r(e,a.InvalidParameter,t);l=i.parseAttributesFromDictionary(s[1])}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}else{let o=null;const l={};if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}for(let n=1;n<s.length;n+=2){const i=h(s[n]),o=s[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||y(o)||R(o)||q(o)))throw new r(e,a.InvalidParameter,t);if(g(o)||!1===d(o))throw new r(e,a.InvalidParameter,t);l[i]=o===p?null:o}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}return c._geometry=f(c.geometry(),e.spatialReference),c.immutable=!1,c}))},L.dictionary=function(e,t){return U(e,t,((i,o,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&A(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof x)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof n)try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(2===l.length&&l[0]instanceof n&&q(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(m){throw new r(e,a.InvalidParameter,t)}if(l.length%2!=0)throw new r(e,a.WrongNumberOfParameters,t);const f={};for(let n=0;n<l.length;n+=2){const i=h(l[n]),o=l[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||q(o)||R(o)||y(o)||W(o)||s(o)))throw new r(e,a.InvalidParameter,t);if(g(o))throw new r(e,a.InvalidParameter,t);f[i]=o===p?null:o}const c=new n(f);return c.immutable=!1,c}))},L.haskey=function(t,i){return U(t,i,((o,s,f)=>{l(f,2,2,t,i);const c=h(f[1]);if(u(f[0]))return f[0].hasField(c);if(f[0]instanceof n)return f[0].hasField(c);if(f[0]instanceof x){const t=e(f[0],c,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,a.InvalidParameter,i)}))},L.hasvalue=function(e,n){return U(e,n,((r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1]))))},L.indexof=function(e,t){return U(e,t,((n,i,o)=>{l(o,2,2,e,t);const f=o[1];if(W(o[0])){for(let e=0;e<o[0].length;e++)if(v(f,o[0][e]))return e;return-1}if(s(o[0])){const e=o[0].length();for(let t=0;t<e;t++)if(v(f,o[0].get(t)))return t;return-1}throw new r(e,a.InvalidParameter,t)}))},L.angle=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?b(o[0],o[1]):F(o[0],o[1],o[2])}))},L.bearing=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?O(o[0],o[1]):S(o[0],o[1],o[2])}))},L.isselfintersecting=function(e,t){return U(e,t,((n,r,a)=>{a=m(a),l(a,1,1,e,t);let i=a[0];if(i instanceof G)return i.isSelfIntersecting;if(i instanceof k)return j(i.paths);if(i instanceof J){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(W(i)||s(i)){const t=I(i,e.spatialReference);return null!==t&&(i=t.paths),j(i)}return!1}))}}export{L as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import n from"../Dictionary.js";import{ArcadeExecutionError as e,ExecutionErrorCodes as t}from"../executionError.js";import{cloneGeometry as r,convertSquareUnitsToCode as i,convertLinearUnitsToCode as a}from"../kernel.js";import{C as l,B as o,g as f,k as u,j as s,f as c,m as d,s as m,D as h,E as w,F as p,G as g,d as v,e as P,H as I}from"../../chunks/languageUtils.js";import{centroidPolyline as y,centroidMultiPoint as R,getMetersPerVerticalUnitForSR as j,segmentLength3d as N}from"./centroid.js";import{measureToCoordinate as x,pointToCoordinate as b,distanceToCoordinate as L}from"./measures.js";import{getMetersPerUnitForSR as A}from"../../core/unitUtils.js";import D from"../../geometry/Extent.js";import O from"../../geometry/Geometry.js";import E from"../../geometry/Multipoint.js";import k from"../../geometry/Point.js";import M from"../../geometry/Polygon.js";import Z from"../../geometry/Polyline.js";import{fromJSON as S}from"../../geometry/support/jsonUtils.js";import{isArray as T,isNumber as z}from"../../support/guards.js";let C=null;function q(n){C=n}function U(n,e){if("polygon"!==n.type&&"polyline"!==n.type&&"extent"!==n.type)return 0;let t=1;if(n.spatialReference.vcsWkid||n.spatialReference.latestVcsWkid){t=j(n.spatialReference)/A(n.spatialReference)}let r=0;if("polyline"===n.type)for(const a of n.paths)for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],t);else if("polygon"===n.type)for(const a of n.rings){for(let n=1;n<a.length;n++)r+=N(a[n],a[n-1],t);(a[0][0]!==a[a.length-1][0]||a[0][1]!==a[a.length-1][1]||void 0!==a[0][2]&&a[0][2]!==a[a.length-1][2])&&(r+=N(a[0],a[a.length-1],t))}else"extent"===n.type&&(r+=2*N([n.xmin,n.ymin,0],[n.xmax,n.ymin,0],t),r+=2*N([n.xmin,n.ymin,0],[n.xmin,n.ymax,0],t),r*=2,r+=4*Math.abs(w(n.zmax,0)*t-w(n.zmin,0)*t));const i=new Z({hasZ:!1,hasM:!1,spatialReference:n.spatialReference,paths:[[[0,0],[0,r]]]});return C.planarLength(i,e)}function W(j,N){function A(n,r,i){if(o(i,2,2,n,r),i[0]instanceof O&&i[1]instanceof O);else if(i[0]instanceof O&&null===i[1]);else if(i[1]instanceof O&&null===i[0]);else if(null!==i[0]||null!==i[1])throw new e(n,t.InvalidParameter,r)}j.disjoint=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null===i[0]||null===i[1]||C.disjoint(i[0],i[1]))))},j.intersects=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.intersects(i[0],i[1]))))},j.touches=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.touches(i[0],i[1]))))},j.crosses=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.crosses(i[0],i[1]))))},j.within=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.within(i[0],i[1]))))},j.contains=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.contains(i[0],i[1]))))},j.overlaps=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null!==i[0]&&null!==i[1]&&C.overlaps(i[0],i[1]))))},j.equals=function(n,e){return N(n,e,((t,r,i)=>(o(i,2,2,n,e),i[0]===i[1]||(i[0]instanceof O&&i[1]instanceof O?C.equals(i[0],i[1]):(f(i[0])&&f(i[1])||u(i[0])&&u(i[1])||!(!s(i[0])||!s(i[1])))&&i[0].equals(i[1])))))},j.relate=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,3,3,n,r),f[0]instanceof O&&f[1]instanceof O)return C.relate(f[0],f[1],c(f[2]));if(f[0]instanceof O&&null===f[1])return!1;if(f[1]instanceof O&&null===f[0])return!1;if(null===f[0]&&null===f[1])return!1;throw new e(n,t.InvalidParameter,r)}))},j.intersection=function(n,e){return N(n,e,((t,r,i)=>(i=l(i),A(n,e,i),null===i[0]||null===i[1]?null:C.intersect(i[0],i[1]))))},j.union=function(n,i){return N(n,i,((a,o,f)=>{const u=[];if(0===(f=l(f)).length)throw new e(n,t.WrongNumberOfParameters,i);if(1===f.length)if(T(f[0])){const r=l(f[0]);for(let a=0;a<r.length;a++)if(null!==r[a]){if(!(r[a]instanceof O))throw new e(n,t.InvalidParameter,i);u.push(r[a])}}else{if(!d(f[0])){if(f[0]instanceof O)return m(r(f[0]),n.spatialReference);if(null===f[0])return null;throw new e(n,t.InvalidParameter,i)}{const r=l(f[0].toArray());for(let a=0;a<r.length;a++)if(null!==r[a]){if(!(r[a]instanceof O))throw new e(n,t.InvalidParameter,i);u.push(r[a])}}}else for(let r=0;r<f.length;r++)if(null!==f[r]){if(!(f[r]instanceof O))throw new e(n,t.InvalidParameter,i);u.push(f[r])}return 0===u.length?null:C.union(u)}))},j.difference=function(n,e){return N(n,e,((t,i,a)=>(a=l(a),A(n,e,a),null===a[0]?null:null===a[1]?r(a[0]):C.difference(a[0],a[1]))))},j.symmetricdifference=function(n,e){return N(n,e,((t,i,a)=>(a=l(a),A(n,e,a),null===a[0]&&null===a[1]?null:null===a[0]?r(a[1]):null===a[1]?r(a[0]):C.symmetricDifference(a[0],a[1]))))},j.clip=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,2,2,n,r),!(f[1]instanceof D)&&null!==f[1])throw new e(n,t.InvalidParameter,r);if(null===f[0])return null;if(!(f[0]instanceof O))throw new e(n,t.InvalidParameter,r);return null===f[1]?null:C.clip(f[0],f[1])}))},j.cut=function(n,i){return N(n,i,((a,f,u)=>{if(u=l(u),o(u,2,2,n,i),!(u[1]instanceof Z)&&null!==u[1])throw new e(n,t.InvalidParameter,i);if(null===u[0])return[];if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,i);return null===u[1]?[r(u[0])]:C.cut(u[0],u[1])}))},j.area=function(n,r){return N(n,r,((a,f,u)=>{if(o(u,1,2,n,r),null===(u=l(u))[0])return 0;if(T(u[0])||d(u[0])){const e=h(u[0],n.spatialReference);return null===e?0:C.planarArea(e,i(w(u[1],-1)))}if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.planarArea(u[0],i(w(u[1],-1)))}))},j.areageodetic=function(n,r){return N(n,r,((a,f,u)=>{if(o(u,1,2,n,r),null===(u=l(u))[0])return 0;if(T(u[0])||d(u[0])){const e=h(u[0],n.spatialReference);return null===e?0:C.geodesicArea(e,i(w(u[1],-1)))}if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.geodesicArea(u[0],i(w(u[1],-1)))}))},j.length=function(n,r){return N(n,r,((i,f,u)=>{if(o(u,1,2,n,r),null===(u=l(u))[0])return 0;if(T(u[0])||d(u[0])){const e=p(u[0],n.spatialReference);return null===e?0:C.planarLength(e,a(w(u[1],-1)))}if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.planarLength(u[0],a(w(u[1],-1)))}))},j.length3d=function(n,r){return N(n,r,((i,f,u)=>{if(o(u,1,2,n,r),null===(u=l(u))[0])return 0;if(T(u[0])||d(u[0])){const e=p(u[0],n.spatialReference);return null===e?0:!0===e.hasZ?U(e,a(w(u[1],-1))):C.planarLength(e,a(w(u[1],-1)))}if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);return!0===u[0].hasZ?U(u[0],a(w(u[1],-1))):C.planarLength(u[0],a(w(u[1],-1)))}))},j.lengthgeodetic=function(n,r){return N(n,r,((i,f,u)=>{if(o(u,1,2,n,r),null===(u=l(u))[0])return 0;if(T(u[0])||d(u[0])){const e=p(u[0],n.spatialReference);return null===e?0:C.geodesicLength(e,a(w(u[1],-1)))}if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.geodesicLength(u[0],a(w(u[1],-1)))}))},j.distance=function(n,r){return N(n,r,((i,f,u)=>{u=l(u),o(u,2,3,n,r);let s=u[0];(T(u[0])||d(u[0]))&&(s=g(u[0],n.spatialReference));let c=u[1];if((T(u[1])||d(u[1]))&&(c=g(u[1],n.spatialReference)),!(s instanceof O))throw new e(n,t.InvalidParameter,r);if(!(c instanceof O))throw new e(n,t.InvalidParameter,r);return C.distance(s,c,a(w(u[2],-1)))}))},j.distancegeodetic=function(n,r){return N(n,r,((i,f,u)=>{u=l(u),o(u,2,3,n,r);const s=u[0],c=u[1];if(!(s instanceof k))throw new e(n,t.InvalidParameter,r);if(!(c instanceof k))throw new e(n,t.InvalidParameter,r);const d=new Z({paths:[],spatialReference:s.spatialReference});return d.addPath([s,c]),C.geodesicLength(d,a(w(u[2],-1)))}))},j.densify=function(n,r){return N(n,r,((i,f,u)=>{if(u=l(u),o(u,2,3,n,r),null===u[0])return null;if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);const s=v(u[1]);if(isNaN(s))throw new e(n,t.InvalidParameter,r);if(s<=0)throw new e(n,t.InvalidParameter,r);return u[0]instanceof M||u[0]instanceof Z?C.densify(u[0],s,a(w(u[2],-1))):u[0]instanceof D?C.densify(M.fromExtent(u[0]),s,a(w(u[2],-1))):u[0]}))},j.densifygeodetic=function(n,r){return N(n,r,((i,f,u)=>{if(u=l(u),o(u,2,3,n,r),null===u[0])return null;if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);const s=v(u[1]);if(isNaN(s))throw new e(n,t.InvalidParameter,r);if(s<=0)throw new e(n,t.InvalidParameter,r);return u[0]instanceof M||u[0]instanceof Z?C.geodesicDensify(u[0],s,a(w(u[2],-1))):u[0]instanceof D?C.geodesicDensify(M.fromExtent(u[0]),s,a(w(u[2],-1))):u[0]}))},j.generalize=function(n,r){return N(n,r,((i,f,u)=>{if(u=l(u),o(u,2,4,n,r),null===u[0])return null;if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,r);const s=v(u[1]);if(isNaN(s))throw new e(n,t.InvalidParameter,r);return C.generalize(u[0],s,P(w(u[2],!0)),a(w(u[3],-1)))}))},j.buffer=function(n,i){return N(n,i,((f,u,s)=>{if(s=l(s),o(s,2,3,n,i),null===s[0])return null;if(!(s[0]instanceof O))throw new e(n,t.InvalidParameter,i);const c=v(s[1]);if(isNaN(c))throw new e(n,t.InvalidParameter,i);return 0===c?r(s[0]):C.buffer(s[0],c,a(w(s[2],-1)))}))},j.buffergeodetic=function(n,i){return N(n,i,((f,u,s)=>{if(s=l(s),o(s,2,3,n,i),null===s[0])return null;if(!(s[0]instanceof O))throw new e(n,t.InvalidParameter,i);const c=v(s[1]);if(isNaN(c))throw new e(n,t.InvalidParameter,i);return 0===c?r(s[0]):C.geodesicBuffer(s[0],c,a(w(s[2],-1)))}))},j.offset=function(n,r){return N(n,r,((i,f,u)=>{if(u=l(u),o(u,2,6,n,r),null===u[0])return null;if(!(u[0]instanceof M||u[0]instanceof Z))throw new e(n,t.InvalidParameter,r);const s=v(u[1]);if(isNaN(s))throw new e(n,t.InvalidParameter,r);const d=v(w(u[4],10));if(isNaN(d))throw new e(n,t.InvalidParameter,r);const m=v(w(u[5],0));if(isNaN(m))throw new e(n,t.InvalidParameter,r);return C.offset(u[0],s,a(w(u[2],-1)),c(w(u[3],"round")).toLowerCase(),d,m)}))},j.rotate=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,2,3,n,r),null===f[0])return null;if(!(f[0]instanceof O))throw new e(n,t.InvalidParameter,r);const u=f[0]instanceof D?M.fromExtent(f[0]):f[0],s=v(f[1]);if(isNaN(s))throw new e(n,t.InvalidParameter,r);const c=w(f[2],null);if(null===c)return C.rotate(u,s);if(c instanceof k)return C.rotate(u,s,c);throw new e(n,t.InvalidParameter,r)}))},j.centroid=function(n,i){return N(n,i,((a,f,u)=>{if(u=l(u),o(u,1,1,n,i),null===u[0])return null;let s=u[0];if((T(u[0])||d(u[0]))&&(s=g(u[0],n.spatialReference)),null===s)return null;if(!(s instanceof O))throw new e(n,t.InvalidParameter,i);return s instanceof k?m(r(s),n.spatialReference):s instanceof M?s.centroid:s instanceof Z?y(s):s instanceof E?R(s):s instanceof D?s.center:null}))},j.measuretocoordinate=function(r,i){return N(r,i,((a,f,u)=>{if(u=l(u),o(u,2,2,r,i),null===u[0])return null;let s=u[0];if((T(u[0])||d(u[0]))&&(s=p(u[0],r.spatialReference)),null===s)return null;if(!(s instanceof O))throw new e(r,t.InvalidParameter,i);if(!(s instanceof Z))throw new e(r,t.InvalidParameter,i);if(z(!1===u[1]))throw new e(r,t.InvalidParameter,i);const c=x(s,u[1]);return c?n.convertObjectToArcadeDictionary(c,I(r),!1,!0):null}))},j.pointtocoordinate=function(r,i){return N(r,i,((a,f,u)=>{if(u=l(u),o(u,2,2,r,i),null===u[0])return null;let s=u[0];if((T(u[0])||d(u[0]))&&(s=p(u[0],r.spatialReference)),null===s)return null;if(!(s instanceof O))throw new e(r,t.InvalidParameter,i);if(!(s instanceof Z))throw new e(r,t.InvalidParameter,i);const c=u[1];if(null===c)return null;if(!(c instanceof k))throw new e(r,t.InvalidParameter,i);if(z(!1===u[1]))throw new e(r,t.InvalidParameter,i);const m=b(s,c);return m?n.convertObjectToArcadeDictionary(m,I(r),!1,!0):null}))},j.distancetocoordinate=function(r,i){return N(r,i,((a,f,u)=>{if(u=l(u),o(u,2,2,r,i),null===u[0])return null;let s=u[0];if((T(u[0])||d(u[0]))&&(s=p(u[0],r.spatialReference)),null===s)return null;if(!(s instanceof O))throw new e(r,t.InvalidParameter,i);if(!(s instanceof Z))throw new e(r,t.InvalidParameter,i);if(z(!1===u[1]))throw new e(r,t.InvalidParameter,i);const c=L(s,u[1]);return c?n.convertObjectToArcadeDictionary(c,I(r),!1,!0):null}))},j.multiparttosinglepart=function(n,i){return N(n,i,((a,f,u)=>{if(u=l(u),o(u,1,1,n,i),null===u[0])return null;if(!(u[0]instanceof O))throw new e(n,t.InvalidParameter,i);if(u[0]instanceof k)return[m(r(u[0]),n.spatialReference)];if(u[0]instanceof D)return[m(r(u[0]),n.spatialReference)];const s=C.simplify(u[0]);if(s instanceof M){const n=[],e=[];for(let t=0;t<s.rings.length;t++)if(s.isClockwise(s.rings[t])){const e=S({rings:[s.rings[t]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});n.push(e)}else e.push({ring:s.rings[t],pt:s.getPoint(t,0)});for(let t=0;t<e.length;t++)for(let r=0;r<n.length;r++)if(n[r].contains(e[t].pt)){n[r].addRing(e[t].ring);break}return n}if(s instanceof Z){const n=[];for(let e=0;e<s.paths.length;e++){const t=S({paths:[s.paths[e]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});n.push(t)}return n}if(u[0]instanceof E){const e=[],t=m(r(u[0]),n.spatialReference);for(let n=0;n<t.points.length;n++)e.push(t.getPoint(n));return e}return null}))},j.issimple=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,1,1,n,r),null===f[0])return!0;if(!(f[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.isSimple(f[0])}))},j.simplify=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,1,1,n,r),null===f[0])return null;if(!(f[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.simplify(f[0])}))},j.convexhull=function(n,r){return N(n,r,((i,a,f)=>{if(f=l(f),o(f,1,1,n,r),null===f[0])return null;if(!(f[0]instanceof O))throw new e(n,t.InvalidParameter,r);return C.convexHull(f[0])}))},j.nearestcoordinate=function(r,i){return N(r,i,((a,f,u)=>{if(u=l(u),o(u,2,2,r,i),!(u[0]instanceof O||null===u[0]))throw new e(r,t.InvalidParameter,i);if(!(u[1]instanceof k||null===u[1]))throw new e(r,t.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const s=C.nearestCoordinate(u[0],u[1]);return null===s||s.isEmpty?null:n.convertObjectToArcadeDictionary({coordinate:s.coordinate,distance:s.distance,sideOfLine:0===s.distance?"straddle":s.isRightSide?"right":"left"},I(r),!1,!0)}))},j.nearestvertex=function(r,i){return N(r,i,((a,f,u)=>{if(u=l(u),o(u,2,2,r,i),!(u[0]instanceof O||null===u[0]))throw new e(r,t.InvalidParameter,i);if(!(u[1]instanceof k||null===u[1]))throw new e(r,t.InvalidParameter,i);if(null===u[0]||null===u[1])return null;const s=C.nearestVertex(u[0],u[1]);return null===s||s.isEmpty?null:n.convertObjectToArcadeDictionary({coordinate:s.coordinate,distance:s.distance,sideOfLine:0===s.distance?"straddle":s.isRightSide?"right":"left"},I(r),!1,!0)}))}}export{W as registerFunctions,q as setGeometryEngine};
5
+ import e from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as t}from"../executionError.js";import{cloneGeometry as r}from"../kernel.js";import{C as i,B as a,g as l,k as o,j as u,f,m as s,s as c,D as m,E as d,F as w,d as h,e as p,G as g,H as v}from"../../chunks/languageUtils.js";import{commonRelationsCheck as P,planarLength3D as x,measureToCoordinateFunc as I,pointToCoordinateFunc as y,distanceToCoordinateFunc as R}from"../geometry/functions.js";import{convertFromSpatialReferenceUnit as j,toAreaUnit as N,convert as b,toLengthUnit as E,convertToSpatialReferenceUnit as D}from"../geometry/unitConversion.js";import L from"../../geometry/Extent.js";import O from"../../geometry/Geometry.js";import k from"../../geometry/Multipoint.js";import M from"../../geometry/Point.js";import S from"../../geometry/Polygon.js";import A from"../../geometry/Polyline.js";import{fromJSON as C}from"../../geometry/support/jsonUtils.js";import{squareMeters as Z,meters as q}from"../geometry/extendedUnitData.js";import{isArray as U}from"../../support/guards.js";let z;async function B(){null==z&&(z=await import("../geometry/operators.js"),await z.loadAll())}function G(B,G){B.disjoint=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null===a[0]||null===a[1]||z.disjoint.execute(a[0],a[1]))))},B.intersects=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.intersects.execute(a[0],a[1]))))},B.touches=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.touches.execute(a[0],a[1]))))},B.crosses=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.crosses.execute(a[0],a[1]))))},B.within=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.within.execute(a[0],a[1]))))},B.contains=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.contains.execute(a[0],a[1]))))},B.overlaps=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null!==a[0]&&null!==a[1]&&z.overlaps.execute(a[0],a[1]))))},B.equals=function(e,n){return G(e,n,((t,r,i)=>(a(i,2,2,e,n),i[0]===i[1]||(i[0]instanceof O&&i[1]instanceof O?z.equals.execute(i[0],i[1]):(l(i[0])&&l(i[1])||o(i[0])&&o(i[1])||!(!u(i[0])||!u(i[1])))&&i[0].equals(i[1])))))},B.relate=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,3,3,e,r),u[0]instanceof O&&u[1]instanceof O)return z.relate.execute(u[0],u[1],f(u[2]));if(u[0]instanceof O&&null===u[1])return!1;if(u[1]instanceof O&&null===u[0])return!1;if(null===u[0]&&null===u[1])return!1;throw new n(e,t.InvalidParameter,r)}))},B.intersection=function(e,n){return G(e,n,((t,r,a)=>(a=i(a),P(a,e,n),null===a[0]||null===a[1]?null:z.intersection.execute(a[0],a[1]))))},B.union=function(e,a){return G(e,a,((l,o,u)=>{const f=[];if(0===(u=i(u)).length)throw new n(e,t.WrongNumberOfParameters,a);if(1===u.length)if(U(u[0])){const r=i(u[0]);for(let i=0;i<r.length;i++)if(null!==r[i]){if(!(r[i]instanceof O))throw new n(e,t.InvalidParameter,a);f.push(r[i])}}else{if(!s(u[0])){if(u[0]instanceof O)return c(r(u[0]),e.spatialReference);if(null===u[0])return null;throw new n(e,t.InvalidParameter,a)}{const r=i(u[0].toArray());for(let i=0;i<r.length;i++)if(null!==r[i]){if(!(r[i]instanceof O))throw new n(e,t.InvalidParameter,a);f.push(r[i])}}}else for(let r=0;r<u.length;r++)if(null!==u[r]){if(!(u[r]instanceof O))throw new n(e,t.InvalidParameter,a);f.push(u[r])}return 0===f.length?null:z.union.executeMany(f)}))},B.difference=function(e,n){return G(e,n,((t,a,l)=>(l=i(l),P(l,e,n),null===l[0]?null:null===l[1]?r(l[0]):z.difference.execute(l[0],l[1]))))},B.symmetricdifference=function(e,n){return G(e,n,((t,a,l)=>(l=i(l),P(l,e,n),null===l[0]&&null===l[1]?null:null===l[0]?r(l[1]):null===l[1]?r(l[0]):z.symmetricDifference.execute(l[0],l[1]))))},B.clip=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,2,e,r),!(u[1]instanceof L)&&null!==u[1])throw new n(e,t.InvalidParameter,r);if(null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);return null===u[1]?null:z.clip.execute(u[0],u[1])}))},B.cut=function(e,l){return G(e,l,((o,u,f)=>{if(f=i(f),a(f,2,2,e,l),!(f[1]instanceof A)&&null!==f[1])throw new n(e,t.InvalidParameter,l);if(null===f[0])return[];if(!(f[0]instanceof O))throw new n(e,t.InvalidParameter,l);return null===f[1]?[r(f[0])]:z.cut.execute(f[0],f[1])}))},B.area=function(e,r){return G(e,r,((l,o,u)=>{a(u,1,2,e,r);let f=(u=i(u))[0];if((U(u[0])||s(u[0]))&&(f=m(u[0],e.spatialReference)),null===f)return 0;if(!(f instanceof O))throw new n(e,t.InvalidParameter,r);return j(f.spatialReference,N(u[1]),z.area.execute(f))}))},B.areageodetic=function(e,r){return G(e,r,((l,o,u)=>{a(u,1,2,e,r);let f=(u=i(u))[0];if((U(u[0])||s(u[0]))&&(f=m(u[0],e.spatialReference)),null===f)return 0;if(!(f instanceof O))throw new n(e,t.InvalidParameter,r);return b(Z,N(u[1]),z.geodeticArea.execute(f))}))},B.length=function(e,r){return G(e,r,((l,o,u)=>{a(u,1,2,e,r);let f=(u=i(u))[0];if((U(u[0])||s(u[0]))&&(f=d(u[0],e.spatialReference)),null===f)return 0;if(!(f instanceof O))throw new n(e,t.InvalidParameter,r);return j(f.spatialReference,E(u[1]),z.length.execute(f))}))},B.length3d=function(e,r){return G(e,r,((l,o,u)=>{a(u,1,2,e,r);let f=(u=i(u))[0];if((U(u[0])||s(u[0]))&&(f=d(u[0],e.spatialReference)),null===f)return 0;if(!(f instanceof O))throw new n(e,t.InvalidParameter,r);return!0===f.hasZ?j(f.spatialReference,E(u[1]),x(f)):j(f.spatialReference,E(u[1]),z.length.execute(f))}))},B.lengthgeodetic=function(e,r){return G(e,r,((l,o,u)=>{a(u,1,2,e,r);let f=(u=i(u))[0];if((U(u[0])||s(u[0]))&&(f=d(u[0],e.spatialReference)),null===f)return 0;if(!(f instanceof O))throw new n(e,t.InvalidParameter,r);return b(q,E(u[1]),z.geodeticLength.execute(f))}))},B.distance=function(e,r){return G(e,r,((l,o,u)=>{u=i(u),a(u,2,3,e,r);let f=u[0];if((U(u[0])||s(u[0]))&&(f=w(u[0],e.spatialReference)),!(f instanceof O))throw new n(e,t.InvalidParameter,r);let c=u[1];if((U(u[1])||s(u[1]))&&(c=w(u[1],e.spatialReference)),!(c instanceof O))throw new n(e,t.InvalidParameter,r);return j(f.spatialReference,E(u[2]),z.distance.execute(f,c))}))},B.distancegeodetic=function(e,r){return G(e,r,((l,o,u)=>{u=i(u),a(u,2,3,e,r);const f=u[0];if(!(f instanceof M))throw new n(e,t.InvalidParameter,r);const s=u[1];if(!(s instanceof M))throw new n(e,t.InvalidParameter,r);const c=new A({paths:[],spatialReference:f.spatialReference});return c.addPath([f,s]),b(q,E(u[2]),z.geodeticLength.execute(c))}))},B.densify=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,3,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);const f=h(u[1]);if(isNaN(f))throw new n(e,t.InvalidParameter,r);if(f<=0)throw new n(e,t.InvalidParameter,r);const s=D(E(u[2]),u[0].spatialReference,f);switch(u[0].type){case"polygon":case"polyline":case"extent":return z.densify.execute(u[0],s);default:return u[0]}}))},B.densifygeodetic=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,3,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);const f=h(u[1]);if(isNaN(f))throw new n(e,t.InvalidParameter,r);if(f<=0)throw new n(e,t.InvalidParameter,r);const s=b(E(u[2]),q,f);switch(u[0].type){case"polygon":case"polyline":case"extent":return z.geodeticDensify.execute(u[0],s);default:return u[0]}}))},B.generalize=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,4,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);const f=h(u[1]);if(isNaN(f))throw new n(e,t.InvalidParameter,r);const s=D(E(u[3]),u[0].spatialReference,f);return z.generalize.execute(u[0],s,{removeDegenerateParts:p(g(u[2],!0))})}))},B.buffer=function(e,l){return G(e,l,((o,u,f)=>{if(f=i(f),a(f,2,3,e,l),null===f[0])return null;if(!(f[0]instanceof O))throw new n(e,t.InvalidParameter,l);const s=h(f[1]);if(isNaN(s))throw new n(e,t.InvalidParameter,l);return 0===s?r(f[0]):z.buffer.execute(f[0],D(E(f[2]),f[0].spatialReference,s))}))},B.buffergeodetic=function(e,l){return G(e,l,((o,u,f)=>{if(f=i(f),a(f,2,3,e,l),null===f[0])return null;if(!(f[0]instanceof O))throw new n(e,t.InvalidParameter,l);const s=h(f[1]);if(isNaN(s))throw new n(e,t.InvalidParameter,l);return 0===s?r(f[0]):z.geodesicBuffer.execute(f[0],b(E(f[2]),q,s))}))},B.offset=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,6,e,r),null===u[0])return null;if(!(u[0]instanceof S||u[0]instanceof A))throw new n(e,t.InvalidParameter,r);const s=h(u[1]);if(isNaN(s))throw new n(e,t.InvalidParameter,r);const c=D(E(u[2]),u[0].spatialReference,s),m=f(u[3]??"round").toLowerCase();let d;switch(m){case"round":case"bevel":case"miter":case"square":d=m;break;default:d="round"}const w=h(g(u[4],10));if(isNaN(w))throw new n(e,t.InvalidParameter,r);const p=h(g(u[5],0));if(isNaN(p))throw new n(e,t.InvalidParameter,r);return z.offset.execute(u[0],c,{joins:d,miterLimit:w,flattenError:p})}))},B.rotate=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,2,3,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);const f=u[0]instanceof L?S.fromExtent(u[0]):u[0],s=h(u[1]);if(isNaN(s))throw new n(e,t.InvalidParameter,r);const c=g(u[2],null);if(null===c){const e="point"===f.type?f:f.extent?.center;return z.rotate(f,s,e?.x,e?.y)}if(c instanceof M)return z.rotate(f,s,c.x,c.y);throw new n(e,t.InvalidParameter,r)}))},B.centroid=function(e,r){return G(e,r,((e,r,l)=>{if(l=i(l),a(l,1,1,e,r),null===l[0])return null;let o=l[0];if((U(l[0])||s(l[0]))&&(o=w(l[0],e.spatialReference)),null===o)return null;if(!(o instanceof O))throw new n(e,t.InvalidParameter,r);return z.centroid.execute(o)}))},B.measuretocoordinate=function(e,n){return G(e,n,I)},B.pointtocoordinate=function(e,n){return G(e,n,y)},B.distancetocoordinate=function(e,n){return G(e,n,R)},B.multiparttosinglepart=function(e,l){return G(e,l,((o,u,f)=>{if(f=i(f),a(f,1,1,e,l),null===f[0])return null;if(!(f[0]instanceof O))throw new n(e,t.InvalidParameter,l);if(f[0]instanceof M)return[c(r(f[0]),e.spatialReference)];if(f[0]instanceof L)return[c(r(f[0]),e.spatialReference)];const s=z.simplify.execute(f[0]);if(s instanceof S){const e=[],n=[];for(let t=0;t<s.rings.length;t++)if(s.isClockwise(s.rings[t])){const n=C({rings:[s.rings[t]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});e.push(n)}else n.push({ring:s.rings[t],pt:s.getPoint(t,0)});for(let t=0;t<n.length;t++)for(let r=0;r<e.length;r++)if(e[r].contains(n[t].pt)){e[r].addRing(n[t].ring);break}return e}if(s instanceof A){const e=[];for(let n=0;n<s.paths.length;n++){const t=C({paths:[s.paths[n]],hasZ:!0===s.hasZ,hasM:!0===s.hasM,spatialReference:s.spatialReference.toJSON()});e.push(t)}return e}if(f[0]instanceof k){const n=[],t=c(r(f[0]),e.spatialReference);for(let e=0;e<t.points.length;e++)n.push(t.getPoint(e));return n}return null}))},B.issimple=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,1,1,e,r),null===u[0])return!0;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);return z.simplify.isSimple(u[0])}))},B.simplify=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,1,1,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);return z.simplify.execute(u[0])}))},B.convexhull=function(e,r){return G(e,r,((l,o,u)=>{if(u=i(u),a(u,1,1,e,r),null===u[0])return null;if(!(u[0]instanceof O))throw new n(e,t.InvalidParameter,r);return z.convexHull.execute(u[0])}))},B.nearestcoordinate=function(r,l){return G(r,l,((o,u,f)=>{if(f=i(f),a(f,2,2,r,l),!(f[0]instanceof O||null===f[0]))throw new n(r,t.InvalidParameter,l);if(!(f[1]instanceof M||null===f[1]))throw new n(r,t.InvalidParameter,l);if(null===f[0]||null===f[1])return null;const s=f[0]instanceof L?S.fromExtent(f[0]):f[0],c=z.proximity.getNearestCoordinate(s,f[1],{calculateLeftRightSide:!0});return null===c||c.isEmpty?null:e.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.rightSide?"right":"left"},v(r),!1,!0)}))},B.nearestvertex=function(r,l){return G(r,l,((o,u,f)=>{if(f=i(f),a(f,2,2,r,l),!(f[0]instanceof O||null===f[0]))throw new n(r,t.InvalidParameter,l);if(!(f[1]instanceof M||null===f[1]))throw new n(r,t.InvalidParameter,l);if(null===f[0]||null===f[1])return null;const s=f[0]instanceof L?S.fromExtent(f[0]):f[0],c=z.proximity.getNearestVertex(s,f[1]);return null===c||c.isEmpty?null:e.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.rightSide?"right":"left"},v(r),!1,!0)}))}}export{B as loadOperators,G as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../config.js";import"../../geometry.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as o}from"../executionError.js";import{B as a,f as i,r as s,E as p,H as l,g as c,j as f,k as u,q as m,l as g}from"../../chunks/languageUtils.js";import{getPortal as d}from"../portalUtils.js";import h from"../../geometry/Geometry.js";import{isLoaded as w,load as y,project as j}from"../../geometry/projection.js";import{webMercatorToGeographic as S,geographicToWebMercator as R}from"../../geometry/support/webMercatorUtils.js";import v from"../../portal/Portal.js";import G from"../../portal/PortalItem.js";import{project as k}from"../../rest/geometryService/project.js";import x from"../../rest/knowledgeGraph/Entity.js";import P from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import b from"../../rest/knowledgeGraph/ObjectValue.js";import I from"../../rest/knowledgeGraph/Path.js";import W from"../../rest/knowledgeGraph/Relationship.js";import D from"../../rest/support/ProjectParameters.js";import T from"../../geometry/SpatialReference.js";import{isString as q,isArray as A,isNumber as N,isDate as U}from"../../support/guards.js";let E=null;async function F(r){const t=e.geometryServiceUrl??"";if(!t){w()||await y();for(const e of r)e.container[e.indexer]=j(e.container[e.indexer],T.WGS84);return}const n=r.map((e=>e.container[e.indexer])),o=new D({geometries:n,outSpatialReference:T.WGS84}),a=await k(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function J(e,r){const t=new G({portal:e,id:r});return await t.load(),null===E&&(E=await import("../../rest/knowledgeGraphService.js")),await E.fetchKnowledgeGraph(t.url)}function M(e,r,t,n,o){if(null===e)return null;if(q(e)||N(e))return e;if(c(e))return e.toJSDate();if(c(e))return e.toJSDate();if(f(e))return e.toStorageFormat();if(u(e))return e.toStorageString();if(m(e)){const a={};for(const i of e.keys())a[i]=M(e.field(i),r,t,n,o),a[i]instanceof h&&o.push({container:a,indexer:i});return a}if(A(e)){const a=e.map((e=>M(e,r,t,n,o)));for(let e=0;e<a.length;e++)a[e]instanceof h&&o.push({container:a,indexer:e});return a}return g(e)?e.spatialReference.isWGS84?e:e.spatialReference.isWebMercator&&r?S(e):e:void 0}function Q(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return R(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n(r,o.WrongSpatialReference,null)}function V(e,r){if(!e)return null;const t={};for(const n in e)t[n]=B(e[n],r);return t}function B(e,r){return null===e?null:A(e)?e.map((e=>B(e,r))):e instanceof x?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:V(e.properties,r)}:e instanceof b?{graphType:"object",properties:V(e.properties,r)}:e instanceof W?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:V(e.properties,r)}:e instanceof I?{graphType:"path",path:e.path?e.path.map((e=>B(e,r))):null}:g(e)?Q(e,r):q(e)||N(e)||U(e)?e:null}function C(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,s){return e.standardFunctionAsync(t,s,((e,p,l)=>{if(a(l,2,2,t,s),null===l[0])throw new n(t,o.PortalRequired,s);if(l[0]instanceof r){const e=i(l[1]);let r;r=t.services?.portal?t.services.portal:v.getDefault();return J(d(l[0],r),e)}if(!1===q(l[0]))throw new n(t,o.InvalidParameter,s);const c=i(l[0]);return J(t.services?.portal??v.getDefault(),c)}))},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,i){return e.standardFunctionAsync(r,i,(async(e,c,f)=>{a(f,2,4,r,i);const u=f[0];if(!s(u))throw new n(r,o.InvalidParameter,i);const m=f[1];if(!q(m))throw new n(r,o.InvalidParameter,i);null===E&&(E=await import("../../rest/knowledgeGraphService.js"));let g=null;const d=p(f[2],null);if(!(d instanceof t||null===d))throw new n(r,o.InvalidParameter,i);if(d){let e=[];g=M(d,!0,!1,r,e),e=e.filter((e=>!e.container[e.indexer].spatialReference.isWGS84)),e.length>0&&await F(e)}const h=new P({openCypherQuery:m,bindParameters:g});(u?.serviceDefinition?.currentVersion??11.3)>11.2&&(h.outputSpatialReference=r.spatialReference);const w=(await E.executeQueryStreaming(u,h)).resultRowsStream.getReader(),y=[];try{for(;;){const{done:e,value:t}=await w.read();if(e)break;if(A(t))for(const n of t)y.push(B(n,r));else{const e=[];for(const n of t)e.push(B(t[n],r));y.push(e)}}}catch(j){throw j}return t.convertJsonToArcade(y,l(r),!1,!0)}))},e.signatures.push({name:"querygraph",min:2,max:4}))}export{C as registerFunctions};
5
+ import e from"../../config.js";import"../../geometry.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as o}from"../executionError.js";import{B as a,f as i,r as s,G as p,H as l,g as c,j as f,k as u,q as m,l as g}from"../../chunks/languageUtils.js";import{getPortal as d}from"../portalUtils.js";import h from"../../geometry/Geometry.js";import{isLoaded as w,load as y,project as j}from"../../geometry/projection.js";import{webMercatorToGeographic as S,geographicToWebMercator as G}from"../../geometry/support/webMercatorUtils.js";import R from"../../portal/Portal.js";import v from"../../portal/PortalItem.js";import{project as k}from"../../rest/geometryService/project.js";import x from"../../rest/knowledgeGraph/Entity.js";import P from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import b from"../../rest/knowledgeGraph/ObjectValue.js";import I from"../../rest/knowledgeGraph/Path.js";import W from"../../rest/knowledgeGraph/Relationship.js";import D from"../../rest/support/ProjectParameters.js";import T from"../../geometry/SpatialReference.js";import{isString as q,isArray as A,isNumber as N,isDate as U}from"../../support/guards.js";let F=null;async function J(r){const t=e.geometryServiceUrl??"";if(!t){w()||await y();for(const e of r)e.container[e.indexer]=j(e.container[e.indexer],T.WGS84);return}const n=r.map((e=>e.container[e.indexer])),o=new D({geometries:n,outSpatialReference:T.WGS84}),a=await k(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function M(e,r){const t=new v({portal:e,id:r});return await t.load(),null===F&&(F=await import("../../rest/knowledgeGraphService.js")),await F.fetchKnowledgeGraph(t.url)}function Q(e,r,t,n,o){if(null===e)return null;if(q(e)||N(e))return e;if(c(e))return e.toJSDate();if(c(e))return e.toJSDate();if(f(e))return e.toStorageFormat();if(u(e))return e.toStorageString();if(m(e)){const a={};for(const i of e.keys())a[i]=Q(e.field(i),r,t,n,o),a[i]instanceof h&&o.push({container:a,indexer:i});return a}if(A(e)){const a=e.map((e=>Q(e,r,t,n,o)));for(let e=0;e<a.length;e++)a[e]instanceof h&&o.push({container:a,indexer:e});return a}return g(e)?e.spatialReference.isWGS84?e:e.spatialReference.isWebMercator&&r?S(e):e:void 0}function E(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return G(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n(r,o.WrongSpatialReference,null)}function V(e,r){if(!e)return null;const t={};for(const n in e)t[n]=B(e[n],r);return t}function B(e,r){return null===e?null:A(e)?e.map((e=>B(e,r))):e instanceof x?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:V(e.properties,r)}:e instanceof b?{graphType:"object",properties:V(e.properties,r)}:e instanceof W?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:V(e.properties,r)}:e instanceof I?{graphType:"path",path:e.path?e.path.map((e=>B(e,r))):null}:g(e)?E(e,r):q(e)||N(e)||U(e)?e:null}function C(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,s){return e.standardFunctionAsync(t,s,((e,p,l)=>{if(a(l,2,2,t,s),null===l[0])throw new n(t,o.PortalRequired,s);if(l[0]instanceof r){const e=i(l[1]);let r;r=t.services?.portal?t.services.portal:R.getDefault();return M(d(l[0],r),e)}if(!1===q(l[0]))throw new n(t,o.InvalidParameter,s);const c=i(l[0]);return M(t.services?.portal??R.getDefault(),c)}))},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,i){return e.standardFunctionAsync(r,i,(async(e,c,f)=>{a(f,2,4,r,i);const u=f[0];if(!s(u))throw new n(r,o.InvalidParameter,i);const m=f[1];if(!q(m))throw new n(r,o.InvalidParameter,i);null===F&&(F=await import("../../rest/knowledgeGraphService.js"));let g=null;const d=p(f[2],null);if(!(d instanceof t||null===d))throw new n(r,o.InvalidParameter,i);if(d){let e=[];g=Q(d,!0,!1,r,e),e=e.filter((e=>!e.container[e.indexer].spatialReference.isWGS84)),e.length>0&&await J(e)}const h=new P({openCypherQuery:m,bindParameters:g});(u?.serviceDefinition?.currentVersion??11.3)>11.2&&(h.outputSpatialReference=r.spatialReference);const w=(await F.executeQueryStreaming(u,h)).resultRowsStream.getReader(),y=[];try{for(;;){const{done:e,value:t}=await w.read();if(e)break;if(A(t))for(const n of t)y.push(B(n,r));else{const e=[];for(const n of t)e.push(B(t[n],r));y.push(e)}}}catch(j){throw j}return t.convertJsonToArcade(y,l(r),!1,!0)}))},e.signatures.push({name:"querygraph",min:2,max:4}))}export{C as registerFunctions};