@arcgis/core 6.0.0-next.22 → 6.0.0-next.23

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 (217) hide show
  1. package/PopupTemplate.js +1 -1
  2. package/analysis/LineOfSightAnalysis.d.ts +1 -1
  3. package/analysis/LineOfSightAnalysisObserver.d.ts +5 -4
  4. package/analysis/LineOfSightAnalysisTarget.d.ts +4 -4
  5. package/analysis/Viewshed.d.ts +4 -4
  6. package/arcgisGlobal.d.ts +0 -5
  7. package/assets/esri/core/workers/RemoteClient.js +1 -1
  8. package/assets/esri/core/workers/chunks/{3c277a0f099d67090d07.js → 02335385b1476fe322eb.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{4911ce62421a6c3320b0.js → 13c64087be3b2985a21b.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{8e19629899a5becf8e19.js → 150e7a7bd5df25693da7.js} +1 -1
  11. package/assets/esri/core/workers/chunks/2c0cb214fedb29487eef.js +1 -0
  12. package/assets/esri/core/workers/chunks/{2e096537a3a5555a4a93.js → 4cb751dc8d00bdaeb04c.js} +1 -1
  13. package/assets/esri/core/workers/chunks/517106048980a3cbe072.js +1 -0
  14. package/assets/esri/core/workers/chunks/{d08ff41e2a9bcd58b64a.js → 636cd05abfbdff19029e.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{84940d8e14caf5a27e04.js → 64b360625c68cb863a08.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{814751e705c05099f864.js → 7c75a8ee266c36baa902.js} +1 -1
  17. package/assets/esri/core/workers/chunks/947674b2ca8be65b9bcc.js +1 -0
  18. package/assets/esri/core/workers/chunks/{baed828b7846c0863289.js → 96c4ea9cfa3930f1c3fb.js} +21 -17
  19. package/assets/esri/core/workers/chunks/{8a485130781b49dbf608.js → 9d40786c5ceface786ba.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{a35c69a4751d28c39907.js → 9e7c4eda135c4911b268.js} +1 -1
  21. package/assets/esri/core/workers/chunks/ad96132bc89671e595f3.js +1 -0
  22. package/assets/esri/themes/base/_core.scss +0 -2
  23. package/assets/esri/themes/dark/main.css +1 -1
  24. package/assets/esri/themes/light/main.css +1 -1
  25. package/assets/esri/themes/light/view.css +1 -1
  26. package/chunks/Component.glsl.js +9 -12
  27. package/chunks/DefaultMaterial.glsl.js +4 -5
  28. package/chunks/Path.glsl.js +2 -4
  29. package/chunks/RealisticTree.glsl.js +3 -3
  30. package/chunks/SSAO.glsl.js +1 -2
  31. package/config.js +1 -1
  32. package/geometry/support/clipRay.js +1 -1
  33. package/geometry/support/plane.js +1 -1
  34. package/interfaces.d.ts +0 -55
  35. package/kernel.js +1 -1
  36. package/layers/ElevationLayer.d.ts +6 -2
  37. package/layers/GeoJSONLayer.d.ts +2 -107
  38. package/layers/IntegratedMeshLayer.js +1 -1
  39. package/layers/SceneLayer.d.ts +40 -16
  40. package/layers/ViewshedLayer.d.ts +10 -4
  41. package/layers/WMSLayer.d.ts +2 -69
  42. package/layers/mixins/TemporalLayer.d.ts +70 -48
  43. package/layers/mixins/TiledImagery.d.ts +0 -11
  44. package/package.json +2 -2
  45. package/popup/content.d.ts +38 -1
  46. package/popup/content.js +1 -1
  47. package/smartMapping/popup/support/clusterUtils.js +1 -1
  48. package/smartMapping/popup/support/utils.js +2 -2
  49. package/smartMapping/renderers/size.js +1 -1
  50. package/smartMapping/renderers/support/regenerateUtils.js +1 -1
  51. package/support/timeUtils.d.ts +11 -0
  52. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  53. package/views/2d/layers/features/Processor.js +1 -1
  54. package/views/2d/layers/features/aggregation/GeohashSpatialIndex.js +1 -1
  55. package/views/2d/layers/features/aggregation/GridSpatialIndex.js +1 -1
  56. package/views/2d/layers/features/layerAdapters/CatalogFootprintLayerAdapter.js +1 -1
  57. package/views/2d/layers/features/layerAdapters/FeatureLayerAdapter.js +1 -1
  58. package/views/2d/layers/features/layerAdapters/InMemoryLayerAdapter.js +1 -1
  59. package/views/2d/layers/features/layerAdapters/KnowledgeGraphSublayerAdapter.js +1 -1
  60. package/views/2d/layers/features/layerAdapters/OGCFeatureLayerAdapter.js +1 -1
  61. package/views/2d/layers/features/layerAdapters/OrientedImageryLayerAdapter.js +1 -1
  62. package/views/2d/layers/features/layerAdapters/ParquetLayerAdapter.js +1 -1
  63. package/views/2d/layers/features/layerAdapters/StreamLayerAdapter.js +1 -1
  64. package/views/2d/layers/features/processor/AggregateStrategy.js +1 -1
  65. package/views/2d/layers/features/processor/FeatureUpdateStrategy.js +1 -1
  66. package/views/2d/layers/features/processor/bins/BinAdapter.js +1 -1
  67. package/views/2d/layers/features/processor/bins/BinLevelState.js +1 -1
  68. package/views/2d/layers/features/processor/clusters/ClusterAdapter.js +1 -1
  69. package/views/2d/layers/features/processor/clusters/ClusterLevelState.js +1 -1
  70. package/views/2d/layers/features/processor/tracks/TrackAdapter.js +1 -1
  71. package/views/2d/layers/features/processor/tracks/TrackLevelState.js +1 -1
  72. package/views/2d/layers/features/schema/processor/SimpleProcessorSchema.js +1 -1
  73. package/views/2d/layers/features/sources/strategies/chunks/ASourceChunk.js +1 -1
  74. package/views/2d/layers/features/sources/strategies/chunks/ByReferenceTileSourceChunk.js +1 -1
  75. package/views/2d/layers/features/sources/strategies/chunks/FeatureSnapshotSourceChunk.js +1 -1
  76. package/views/2d/layers/features/sources/strategies/chunks/Overrides.js +1 -1
  77. package/views/2d/layers/features/sources/strategies/chunks/ParquetSnapshotSourceChunk.js +1 -1
  78. package/views/2d/layers/features/sources/strategies/chunks/SourceChunkStore.js +1 -1
  79. package/views/2d/layers/features/sources/strategies/chunks/StreamSourceChunk.js +1 -1
  80. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  81. package/views/2d/layers/features/support/FeatureFilterEvaluator.js +1 -1
  82. package/views/2d/layers/features/support/FeatureSetReader.js +1 -1
  83. package/views/2d/layers/features/support/GraphicsReader.js +1 -1
  84. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  85. package/views/3d/environment/SunLighting.d.ts +0 -1
  86. package/views/3d/environment/SunLighting.js +1 -1
  87. package/views/3d/environment/VirtualLighting.d.ts +0 -1
  88. package/views/3d/environment/VirtualLighting.js +1 -1
  89. package/views/3d/input/handlers/ground/GroundDoubleClickMove.js +1 -1
  90. package/views/3d/interactive/placementTools/GroundNavigationPlacementTool3D.js +1 -1
  91. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  92. package/views/3d/state/utils/groundNavigationUtils.js +1 -1
  93. package/views/3d/webgl-engine/collections/Component/Material/Component.glsl.js +1 -1
  94. package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +1 -2
  95. package/views/3d/webgl-engine/core/shaderLibrary/shading/ScreenSpaceRayMarching.glsl.js +1 -2
  96. package/views/3d/webgl-engine/effects/glow/applyEmissiveGlow.glsl.js +9 -4
  97. package/views/3d/webgl-engine/effects/snowcover/applySnow.glsl.js +18 -0
  98. package/views/3d/webgl-engine/lib/Intersector.js +1 -1
  99. package/views/3d/webgl-engine/materials/Path.glsl.js +1 -1
  100. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  101. package/views/3d/webgl-engine/materials/internal/worldSizedRibbonLineIntersectionUtils.js +2 -0
  102. package/views/3d/webgl-engine/shaders/DefaultMaterial.glsl.js +1 -1
  103. package/views/3d/webgl-engine/shaders/RealisticTree.glsl.js +1 -1
  104. package/views/layers/LineOfSightLayerView.d.ts +2 -2
  105. package/views/layers/ViewshedLayerView.d.ts +2 -1
  106. package/widgets/Feature/FeatureExpression/FeatureExpressionViewModel.js +1 -1
  107. package/widgets/FloorFilter/FloorFilterViewModel.js +1 -1
  108. package/widgets/Locate.d.ts +1 -1
  109. package/widgets/Search/SearchViewModel.js +1 -1
  110. package/widgets/Search/support/layerSearchUtils.js +1 -1
  111. package/widgets/Sketch/SketchViewModel.js +1 -1
  112. package/widgets/Sketch/support/PluginManager.js +1 -1
  113. package/widgets/UtilityNetworkTrace/UtilityNetworkTraceFeature.js +1 -1
  114. package/widgets/support/GeolocationPositioning.d.ts +1 -2
  115. package/assets/esri/core/workers/chunks/42045cf46497828cd3c0.js +0 -1
  116. package/assets/esri/core/workers/chunks/576248e9ae2654569420.js +0 -1
  117. package/assets/esri/core/workers/chunks/6059853ef3b6cddbe869.js +0 -1
  118. package/assets/esri/core/workers/chunks/a679207c3458cc0b1fec.js +0 -1
  119. package/assets/esri/themes/base/widgets/_DirectionalPad.scss +0 -85
  120. package/assets/esri/widgets/DirectionalPad/t9n/messages.ar.json +0 -1
  121. package/assets/esri/widgets/DirectionalPad/t9n/messages.bg.json +0 -1
  122. package/assets/esri/widgets/DirectionalPad/t9n/messages.bs.json +0 -1
  123. package/assets/esri/widgets/DirectionalPad/t9n/messages.ca.json +0 -1
  124. package/assets/esri/widgets/DirectionalPad/t9n/messages.cs.json +0 -1
  125. package/assets/esri/widgets/DirectionalPad/t9n/messages.da.json +0 -1
  126. package/assets/esri/widgets/DirectionalPad/t9n/messages.de.json +0 -1
  127. package/assets/esri/widgets/DirectionalPad/t9n/messages.el.json +0 -1
  128. package/assets/esri/widgets/DirectionalPad/t9n/messages.en.json +0 -1
  129. package/assets/esri/widgets/DirectionalPad/t9n/messages.es.json +0 -1
  130. package/assets/esri/widgets/DirectionalPad/t9n/messages.et.json +0 -1
  131. package/assets/esri/widgets/DirectionalPad/t9n/messages.fi.json +0 -1
  132. package/assets/esri/widgets/DirectionalPad/t9n/messages.fr.json +0 -1
  133. package/assets/esri/widgets/DirectionalPad/t9n/messages.he.json +0 -1
  134. package/assets/esri/widgets/DirectionalPad/t9n/messages.hr.json +0 -1
  135. package/assets/esri/widgets/DirectionalPad/t9n/messages.hu.json +0 -1
  136. package/assets/esri/widgets/DirectionalPad/t9n/messages.id.json +0 -1
  137. package/assets/esri/widgets/DirectionalPad/t9n/messages.it.json +0 -1
  138. package/assets/esri/widgets/DirectionalPad/t9n/messages.ja.json +0 -1
  139. package/assets/esri/widgets/DirectionalPad/t9n/messages.ko.json +0 -1
  140. package/assets/esri/widgets/DirectionalPad/t9n/messages.lt.json +0 -1
  141. package/assets/esri/widgets/DirectionalPad/t9n/messages.lv.json +0 -1
  142. package/assets/esri/widgets/DirectionalPad/t9n/messages.nl.json +0 -1
  143. package/assets/esri/widgets/DirectionalPad/t9n/messages.no.json +0 -1
  144. package/assets/esri/widgets/DirectionalPad/t9n/messages.pl.json +0 -1
  145. package/assets/esri/widgets/DirectionalPad/t9n/messages.pt-BR.json +0 -1
  146. package/assets/esri/widgets/DirectionalPad/t9n/messages.pt-PT.json +0 -1
  147. package/assets/esri/widgets/DirectionalPad/t9n/messages.ro.json +0 -1
  148. package/assets/esri/widgets/DirectionalPad/t9n/messages.ru.json +0 -1
  149. package/assets/esri/widgets/DirectionalPad/t9n/messages.sk.json +0 -1
  150. package/assets/esri/widgets/DirectionalPad/t9n/messages.sl.json +0 -1
  151. package/assets/esri/widgets/DirectionalPad/t9n/messages.sr.json +0 -1
  152. package/assets/esri/widgets/DirectionalPad/t9n/messages.sv.json +0 -1
  153. package/assets/esri/widgets/DirectionalPad/t9n/messages.th.json +0 -1
  154. package/assets/esri/widgets/DirectionalPad/t9n/messages.tr.json +0 -1
  155. package/assets/esri/widgets/DirectionalPad/t9n/messages.uk.json +0 -1
  156. package/assets/esri/widgets/DirectionalPad/t9n/messages.vi.json +0 -1
  157. package/assets/esri/widgets/DirectionalPad/t9n/messages.zh-CN.json +0 -1
  158. package/assets/esri/widgets/DirectionalPad/t9n/messages.zh-HK.json +0 -1
  159. package/assets/esri/widgets/DirectionalPad/t9n/messages.zh-TW.json +0 -1
  160. package/assets/esri/widgets/Track/t9n/messages.ar.json +0 -1
  161. package/assets/esri/widgets/Track/t9n/messages.bg.json +0 -1
  162. package/assets/esri/widgets/Track/t9n/messages.bs.json +0 -1
  163. package/assets/esri/widgets/Track/t9n/messages.ca.json +0 -1
  164. package/assets/esri/widgets/Track/t9n/messages.cs.json +0 -1
  165. package/assets/esri/widgets/Track/t9n/messages.da.json +0 -1
  166. package/assets/esri/widgets/Track/t9n/messages.de.json +0 -1
  167. package/assets/esri/widgets/Track/t9n/messages.el.json +0 -1
  168. package/assets/esri/widgets/Track/t9n/messages.en.json +0 -1
  169. package/assets/esri/widgets/Track/t9n/messages.es.json +0 -1
  170. package/assets/esri/widgets/Track/t9n/messages.et.json +0 -1
  171. package/assets/esri/widgets/Track/t9n/messages.fi.json +0 -1
  172. package/assets/esri/widgets/Track/t9n/messages.fr.json +0 -1
  173. package/assets/esri/widgets/Track/t9n/messages.he.json +0 -1
  174. package/assets/esri/widgets/Track/t9n/messages.hr.json +0 -1
  175. package/assets/esri/widgets/Track/t9n/messages.hu.json +0 -1
  176. package/assets/esri/widgets/Track/t9n/messages.id.json +0 -1
  177. package/assets/esri/widgets/Track/t9n/messages.it.json +0 -1
  178. package/assets/esri/widgets/Track/t9n/messages.ja.json +0 -1
  179. package/assets/esri/widgets/Track/t9n/messages.ko.json +0 -1
  180. package/assets/esri/widgets/Track/t9n/messages.lt.json +0 -1
  181. package/assets/esri/widgets/Track/t9n/messages.lv.json +0 -1
  182. package/assets/esri/widgets/Track/t9n/messages.nl.json +0 -1
  183. package/assets/esri/widgets/Track/t9n/messages.no.json +0 -1
  184. package/assets/esri/widgets/Track/t9n/messages.pl.json +0 -1
  185. package/assets/esri/widgets/Track/t9n/messages.pt-BR.json +0 -1
  186. package/assets/esri/widgets/Track/t9n/messages.pt-PT.json +0 -1
  187. package/assets/esri/widgets/Track/t9n/messages.ro.json +0 -1
  188. package/assets/esri/widgets/Track/t9n/messages.ru.json +0 -1
  189. package/assets/esri/widgets/Track/t9n/messages.sk.json +0 -1
  190. package/assets/esri/widgets/Track/t9n/messages.sl.json +0 -1
  191. package/assets/esri/widgets/Track/t9n/messages.sr.json +0 -1
  192. package/assets/esri/widgets/Track/t9n/messages.sv.json +0 -1
  193. package/assets/esri/widgets/Track/t9n/messages.th.json +0 -1
  194. package/assets/esri/widgets/Track/t9n/messages.tr.json +0 -1
  195. package/assets/esri/widgets/Track/t9n/messages.uk.json +0 -1
  196. package/assets/esri/widgets/Track/t9n/messages.vi.json +0 -1
  197. package/assets/esri/widgets/Track/t9n/messages.zh-CN.json +0 -1
  198. package/assets/esri/widgets/Track/t9n/messages.zh-HK.json +0 -1
  199. package/assets/esri/widgets/Track/t9n/messages.zh-TW.json +0 -1
  200. package/views/2d/layers/features/FeatureSpatialIndex.js +0 -2
  201. package/views/2d/layers/features/support/FeatureSetReaderIndirect.js +0 -2
  202. package/views/3d/webgl-engine/effects/snowcover/SnowCover.glsl.js +0 -12
  203. package/widgets/DirectionalPad/DirectionalPadViewModel.d.ts +0 -85
  204. package/widgets/DirectionalPad/DirectionalPadViewModel.js +0 -2
  205. package/widgets/DirectionalPad/VisibleElements.d.ts +0 -40
  206. package/widgets/DirectionalPad/VisibleElements.js +0 -2
  207. package/widgets/DirectionalPad/constants.js +0 -2
  208. package/widgets/DirectionalPad/css.js +0 -2
  209. package/widgets/DirectionalPad/types.d.ts +0 -27
  210. package/widgets/DirectionalPad/utils.js +0 -2
  211. package/widgets/DirectionalPad.d.ts +0 -156
  212. package/widgets/DirectionalPad.js +0 -2
  213. package/widgets/Track/TrackViewModel.d.ts +0 -131
  214. package/widgets/Track/TrackViewModel.js +0 -2
  215. package/widgets/Track/types.d.ts +0 -6
  216. package/widgets/Track.d.ts +0 -278
  217. package/widgets/Track.js +0 -2
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{createTask as n}from"../../core/asyncUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import a from"../../core/Logger.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{watch as s,initial as c,syncAndInitial as l}from"../../core/reactiveUtils.js";import{Milliseconds as u}from"../../core/time.js";import{isBlobProtocol as d}from"../../core/urlUtils.js";import{property as f,subclass as p}from"../../core/accessorSupport/decorators.js";import m from"../../geometry/Polygon.js";import h from"../../webdoc/Widgets.js";import g from"../../webdoc/widgets/FloorFilter.js";import{isWebMap as _}from"../../webmap/utils.js";import{GoTo as v}from"../support/GoTo.js";function y(e){return e.declaredClass===`esri.WebScene`}let b=class extends v(t){constructor(e){super(e),this.filterMenuOpen=!1,this.filterMenuType=`site`,this.filterMode=`base-floors`,this.levelsExpanded=!0,this.searchTerm=null,this.view=null,this._updateFloorFilterTask=null,this._viewHeightBreakpoint=null,this._viewWidthBreakpoint=null}initialize(){this.addHandles([s(()=>this.view?.map,e=>{this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=n(async t=>{await this._updateFloorFilterFromMap(e),o(t),this._setInitialViewState(e)}),this._watchMapLayers(e)},c),s(()=>this.view,(e,t)=>{this._unregisterWidget(t),this._registerWidget(e),this._watchSearchResults(e)},l),s(()=>this.mediaLayer,e=>{this._watchLayerVisibility(e)},l),s(()=>this.view?.widthBreakpoint??null,e=>{this._viewWidthBreakpoint=e}),s(()=>this.view?.heightBreakpoint??null,e=>{this._viewHeightBreakpoint=e}),s(()=>this.facility,()=>void this.getOverlays()),s(()=>this.level,e=>this._updateMediaLayer(e))])}destroy(){if(this._unregisterWidget(this.view),this.mediaLayer&&this.view?.map.remove(this.mediaLayer),this.overlaysByLevel){for(let e of this.overlaysByLevel.values()){let t=e.image.image;d(t)&&URL.revokeObjectURL(t)}this.overlaysByFacility?.clear(),this.overlaysByLevel.clear()}this.view=null,this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null)}set enabled(e){this._callOverride(`enabled`,e)}set facility(e){if(e&&this._isOverridden(`facility`)){let t=this.getFacility(e);this.hasMultipleSites&&(this.site=t?.siteId||null)}this._callOverride(`facility`,e)}set filterFeatures(e){this._callOverride(`filterFeatures`,e)}set filterLayers(e){this._callOverride(`filterLayers`,e)}get floorVisibilityMode(){return this.view&&y(this.view?.map)?this.view.map.widgets?.floorFilter?.floorVisibilityMode??`belowSelected`:`belowSelected`}get hasFacilities(){return this.filterLayers?.facilityLayer!=null&&this.filterFeatures?.facilities?.facilitiesInfo?.length>0}get hasLevels(){return this.filterLayers?.levelLayer!=null&&this.filterFeatures?.levels?.levelsInfo?.length>0}get hasMultipleSites(){return this.filterLayers?.siteLayer!=null&&this.filterFeatures?.sites?.sitesInfo?.length>1}get isNormalMode(){let e=!0,t=this._viewWidthBreakpoint;return(this._viewHeightBreakpoint===`xsmall`||t===`xsmall`)&&(e=!1),e}set level(e){if(!e){this._callOverride(`level`,e),this.facility=null,this.site=null,this.setFloors(null);return}let t=null,n=null,r=e?.split(`--`);r?.length>1&&r[0]===`all`?(n=r[1],t={id:e,facilityId:n,shortName:null,longName:null,levelNumber:null,verticalOrder:null}):(t=this.getLevel(e),n=t?.facilityId??null),this.level===e&&!this.isNormalMode&&!this.levelsExpanded?this.getFacilityLevels(n)?.length>1&&(this.levelsExpanded=!0):(t&&this.hasFacilities&&this.hasLevels?(this.facility=n,this.hasMultipleSites&&(this.site=this.getFacility(n)?.siteId||null),this.setFloors(t)):this._isOverridden(`level`)&&(this.facility=null,this.site=null,this.hasMultipleSites&&(this.filterMenuType=`site`),this.setFloors(null)),this._callOverride(`level`,e))}set longNames(e){this._callOverride(`longNames`,e)}set minimized(e){this._callOverride(`minimized`,e)}set pinnedLevels(e){this._callOverride(`pinnedLevels`,e)}get selectedVerticalOrder(){return _(this.view?.map)?this.view.map.resourceInfo?.widgets?.floorFilter?.selectedVerticalOrder??null:null}set site(e){this._callOverride(`site`,e)}get state(){return this.view&&this.filterFeatures&&this.hasFacilities&&this.hasLevels?`ready`:this.view&&!this.filterFeatures?`loading`:`disabled`}get useVerticalOrder(){return this.view?.map==null?!1:_(this.view?.map)||y(this.view.map)?this.view.map.widgets?.floorFilter?.useVerticalOrder??!1:!1}filterFacilities(e){let t=e;return this.searchTerm&&(this.searchTerm=this.searchTerm.trim(),t=e.filter(e=>{let{name:t}=e;return t.toLowerCase().includes(this.searchTerm?.toLowerCase())})),this.site&&(t=t.filter(e=>e.siteId===this.site)),t.sort((e,t)=>{let n=e.name,r=t.name;return n.localeCompare(r,void 0,{sensitivity:`base`})})}filterSites(e){let t=e;return this.searchTerm&&(this.searchTerm=this.searchTerm.trim(),t=e.filter(e=>{let{name:t}=e;return t.toLowerCase().includes(this.searchTerm?.toLowerCase())})),t.sort((e,t)=>{let n=e.name,r=t.name;return n.localeCompare(r,void 0,{sensitivity:`base`})})}getBaseLevel(e){let t=this.filterFeatures?.levels?.levelsInfo,n=null;if(e){let{id:r}=e;if(t&&t.length>0&&(t.forEach(e=>{e.verticalOrder===0&&e.facilityId===r&&(n=e)}),!n)){let e=null;t.forEach(t=>{t.facilityId===r&&(e?(t.verticalOrder??0)>=0?e.verticalOrder!=null&&(e.verticalOrder<0||(t.verticalOrder??0)<e.verticalOrder)&&(e=t):e.verticalOrder!=null&&t.verticalOrder!=null&&e.verticalOrder<0&&t.verticalOrder>e.verticalOrder&&(e=t):e=t)}),e&&(n=e)}}return n}getFacility(e){return this.filterFeatures?.facilities?.facilitiesInfo?.find(t=>t.id===e)??null}getFacilityLevels(e){return!e||!this.filterFeatures?.levels?.levelsInfo?[]:this.filterFeatures.levels.levelsInfo.filter(t=>t.facilityId===e).sort((e,t)=>{let n=e.verticalOrder??0,r=t.verticalOrder??0;return n>r?-1:n===r?0:1})}getLevel(e){return this.filterFeatures?.levels?.levelsInfo?.find(t=>t.id===e)??null}async getOverlays(e=!1){let{facility:t,level:n,mediaLayer:i,overlaysByFacility:a,overlaysByLevel:o,view:s}=this;if(_(s?.map)&&i){if((i?.source).elements.removeAll(),t?.length&&(!a?.has(t)||e)){a?.set(t,new r);let e=s.map.floorInfo?.levelLayer?.layerId,n=s.map.findLayerById(e??``);if(!n||s.type!==`2d`)return;let i=await this._getAttachments(n,t),{default:c}=await import(`../../request.js`),l=Object.keys(i).map(async e=>{let r=i[e],s=r.find(e=>e.contentType===`application/json`);if(!s?.url)return;let l=new URL(s.url);n.gdbVersion?.length&&l.searchParams.set(`gdbVersion`,n.gdbVersion);let{data:u}=await c(l.toString(),{responseType:`json`}),d=r.find(e=>e.name===u.name),f=d?.url??``;if(f?.length>0){let e=new URL(f);e.searchParams.delete(`token`),n.gdbVersion?.length&&e.searchParams.set(`gdbVersion`,n.gdbVersion);let{default:r}=await import(`../../layers/support/ControlPointsGeoreference.js`),i=r.fromJSON(u.georeference),c=await this.toImageElement(e.toString(),i,u.opacity,u.clipImage,u.geometry);await c.load();let l={...u,attachments:[s,d],facilityId:t,image:c,source:JSON.stringify(u),url:e.toString()};o?.set(l.levelId,l),a?.get(t)?.push(l)}});await Promise.all(l)}this._updateMediaLayer(n)}}getSite(e){return this.filterFeatures?.sites?.sitesInfo?.find(t=>t.id===e)??null}async goTo(e){let{view:t}=this;if(!t||!e)return;let{geometry:n}=e;if(n?.extent){let e=e=>{this.callGoTo({target:e,options:{duration:u(1e3),easing:`quad-in-out-coast`}})};if(n.hasZ&&n.spatialReference?.vcsWkid!==t.spatialReference?.vcsWkid){let{projectIsLoaded:r,projectLoad:i,projectExecute:a}=await import(`../../geometry/operators/projectOperator.js`);r()||await i();let o=a(n.extent,t.spatialReference.clone(),{zConversionDisabled:!0});o&&e(o)}else e(n.extent)}}setFloors(e){let{view:t}=this;t&&(t?.map?.allLayers?.forEach(e=>{e.type===`feature`&&this._computeViewAllModeFloors(e)}),t.floors=new r(this._computeFloors(e)))}async toImageElement(e,t,n,r,i){let{default:o}=await import(`../../layers/support/ImageElement.js`),{facility:s}=this,c=()=>new o({image:e,georeference:t,opacity:n});if(r)try{let r=i?m.fromJSON(i):this.getFacility(s)?.geometry;if(r==null)return c();let{pixelRings:a,width:l,height:u}=await this._polygonToImagePixels(t,r),d=await this._imagePolygonToBlob(e,a,l,u);return new o({image:URL.createObjectURL(d),georeference:t,opacity:n})}catch(e){return a.getLogger(this).warn(`Unable to clip image; using full image instead: ${e.message}`,e),c()}return c()}updateWebDocument(e){if(_(e)||y(e)){let t={enabled:this.enabled,longNames:this.longNames,minimized:this.minimized,pinnedLevels:this.pinnedLevels,site:this.site??null,facility:this.facility??null,level:this.level??null,useVerticalOrder:this.useVerticalOrder,selectedVerticalOrder:this.selectedVerticalOrder};y(e)&&(t.floorVisibilityMode=this.floorVisibilityMode);let n=new g(t);e.widgets??=new h,e.widgets.floorFilter=n}}_computeFloors(e){if(this.filterMode===`single-floor`)this._computeSingleFloor(e);else if(this.filterMode===`base-floors`)return this.view?.type===`3d`?this._computeBaseFloors3D(e):this._computeBaseFloors(e);return this._computeEmptyFloors()}_computeSingleFloor(e){if(!e)return this._computeEmptyFloors();let t=[];return e?.id===`all`?this.getFacilityLevels(e.facilityId).forEach(e=>{e.id&&t.push(e.id)}):e&&t.push(e.id),t}_computeBaseFloors(e){let t=this.filterFeatures?.levels?.levelsInfo;if(!t?.length)return this._computeEmptyFloors();let n=[];e?.id===`all`?this.getFacilityLevels(e.facilityId).forEach(e=>{e.id&&n.push(e.id)}):e&&n.push(e.id);let r=e?.facilityId,i=e?.verticalOrder,a=(e,t)=>{e===0&&n.push(t)};return t.forEach(e=>{let{id:t,facilityId:o,verticalOrder:s}=e;!r&&!n.includes(t)?a(s,t):o!==r&&!n.includes(t)&&(this.useVerticalOrder?s===i&&n.push(t):a(s,t))}),n}_computeBaseFloors3D(e){let t=this.filterFeatures?.levels?.levelsInfo;if(!t?.length)return this._computeEmptyFloors();let n=[],r=e?.id.split(`--`)??[],i=r?.length>1&&r[0]===`all`;i?this.getFacilityLevels(e?.facilityId).forEach(e=>{e.id&&n.push(e.id)}):e&&n.push(e.id);let a=e?.facilityId,o=e?.verticalOrder;return t.forEach(e=>{let{id:t,facilityId:r,verticalOrder:s}=e;if(!a&&!n.includes(t))n.push(t);else if(!n.includes(t)){let{floorVisibilityMode:e,useVerticalOrder:c}=this,l=s<=o;r===a?e===`belowSelected`&&l&&n.push(t):(i||!c||e===`selectedOnly`&&s===o||e===`belowSelected`&&l)&&n.push(t)}}),n}_computeEmptyFloors(){return[]}async _setFilterLayers(){let{view:e}=this;if(e&&!this._isOverridden(`filterLayers`)){if(!_(e.map)&&!y(e.map))throw new i(`floorfilter:unsupported-map`,`Map must be a webmap or webscene`);{let t=e.map,n=t?.allLayers;if(n?.items?.length>0){let e={siteLayer:null,facilityLayer:null,levelLayer:null},r=t.floorInfo?.siteLayer?.layerId,i=t.floorInfo?.facilityLayer?.layerId,a=t.floorInfo?.levelLayer?.layerId,o=t.floorInfo?.siteLayer?.sublayerId||t.floorInfo?.facilityLayer?.sublayerId||t.floorInfo?.levelLayer?.sublayerId;if(!i||!a)return;let s=n.items.filter(e=>e.type===`feature`||e.type===`scene`),c=n.items.filter(e=>e.type===`map-image`);if(c?.length>0&&o){await Promise.all(c.map(e=>e.load()));let n=t.floorInfo?.siteLayer?.sublayerId,o=t.floorInfo?.facilityLayer?.sublayerId,s=t.floorInfo?.levelLayer?.sublayerId;c.forEach(t=>{let c=t.id,l=t?.allSublayers,u=l?.items;(c===r||c===i||c===a)&&u?.length>0&&l.items.forEach(t=>{let i=t.id;c===r&&i===n?e.siteLayer=t:i===o?e.facilityLayer=t:i===s&&(e.levelLayer=t)})})}s?.length>0&&s.forEach(t=>{let n=t.id;n===r?e.siteLayer=t:n===i?e.facilityLayer=t:n===a&&(e.levelLayer=t)}),this.filterLayers=e}}}}async _getAttachments(e,t){let{view:n}=this;if(_(n?.map)){let{facilityIdField:r}=n.map.floorInfo?.levelLayer??{};if(e&&n.type===`2d`&&t?.length>0&&e.capabilities.data.supportsAttachment)return e.queryAttachments({returnMetadata:!0,where:`${r} = '${t}'`})}return{}}async _getFilterFeatures(){if(this._isOverridden(`filterFeatures`))return this.filterFeatures;let[e,t,n]=await Promise.all([this._getSites(),this._getFacilities(),this._getLevels()]);return{sites:e,facilities:t,levels:n}}async _getSites(){let e={sitesInfo:[]},{filterLayers:t,view:n}=this,r=n?.map,{siteLayer:i}=t;if(!i||!r?.floorInfo?.siteLayer)return e;let a=i.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0,`type`in i&&i.type===`scene`&&(a.multipatchOption=`xyFootprint`);let{siteIdField:o,nameField:s}=r.floorInfo.siteLayer,c=await i.queryFeatures(a);if(c?.features?.length>0){let t=c.features,n=i?.fieldsIndex.get(o)?.name||o,r=i?.fieldsIndex.get(s)?.name||s;n!=null&&r!=null&&t.forEach(t=>{let i=t.attributes,a=t.geometry,o=i[n],s=i[r];o&&s&&e.sitesInfo.push({id:o,name:s,geometry:a})})}return e}async _getFacilities(){let{filterLayers:e,view:t}=this,n=t?.map,{facilityLayer:r}=e,i={facilitiesInfo:[]};if(!r||!n?.floorInfo?.facilityLayer)return i;let a=r.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0,`type`in r&&r.type===`scene`&&(a.multipatchOption=`xyFootprint`);let{facilityIdField:o,siteIdField:s,nameField:c}=n.floorInfo.facilityLayer,l=await r.queryFeatures(a);if(l?.features?.length>0){let e=l.features,t=r?.fieldsIndex.get(o)?.name||o,n=r?.fieldsIndex.get(s)?.name||s,a=r?.fieldsIndex.get(c)?.name||c;t&&n&&a&&e.forEach(e=>{let r=e.attributes,o=e.geometry,s=r[t],c=r[n],l=r[a];s&&l&&i.facilitiesInfo.push({id:s,siteId:c,name:l,geometry:o})})}return i}async _getLevels(){let{filterLayers:e,view:t}=this,n=t?.map,{levelLayer:r}=e,i={levelsInfo:[]};if(!r||!n?.floorInfo?.levelLayer)return i;let a=r.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0;let{levelIdField:o,facilityIdField:s,longNameField:c,shortNameField:l,levelNumberField:u,verticalOrderField:d}=n.floorInfo.levelLayer,f=await r.queryFeatures(a);if(f?.features?.length>0){let e=f.features,t=r?.fieldsIndex.get(o)?.name||o,n=r?.fieldsIndex.get(s)?.name||s,a=r?.fieldsIndex.get(c)?.name||c,p=r?.fieldsIndex.get(l)?.name||l,m=r?.fieldsIndex.get(u)?.name||u,h=r?.fieldsIndex.get(d)?.name||d;t&&n&&a&&p&&m&&h&&e.forEach(e=>{let r=e.attributes,o=r[t],s=r[n],c=r[a],l=r[p],u=r[m],d=r[h];o&&s&&c&&l&&typeof u==`number`&&typeof d==`number`&&i.levelsInfo.push({id:o,facilityId:s,longName:c,shortName:l,levelNumber:u,verticalOrder:d})})}return i}async _imagePolygonToBlob(e,t,n,r){let{getImageData:a}=await import(`../../core/imageUtils.js`),o=await a(e),s=new OffscreenCanvas(n,r),c=s.getContext(`2d`);if(!c)throw new i(`floorfilter:floor-plan-overlay`,`Unable to obtain a rendering context from the canvas.`);let l=new Path2D;for(let e of t)if(!(e.length<3)){l.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)l.lineTo(e[t].x,e[t].y);l.closePath()}return c.save(),c.clip(l,`evenodd`),c.drawImage(o,0,0,n,r),c.restore(),await s.convertToBlob({type:`image/png`})}async _polygonToImagePixels(e,t){if(e?.type!==`control-points`)throw new i(`floorfilter:floor-plan-overlay`,"Expected a `ControlPointsGeoreference`.");let{default:n}=await import(`../../geometry/Point.js`);return{pixelRings:t.rings.map(r=>r.map(([r,a])=>{let o=new n({x:r,y:a,spatialReference:t.spatialReference}),s=e.toSource(o);if(!s)throw new i(`floorfilter:floor-plan-overlay`,`toSource() returned null; check spatial references and projectOperator.`);return{x:s.x,y:s.y}})),width:e.width,height:e.height}}_registerWidget(e){e?.registerComponent(this)}_unregisterWidget(e){e?.unregisterComponent(this)}_watchLayerVisibility(e){if(this.filterLayers?.levelLayer?.type===`feature`&&e){let t=this.filterLayers?.levelLayer;this.addHandles(s(()=>t.visible,t=>{e.visible=t},l))}}_watchMapLayers(e){this.removeHandles(`layers-handle`),e&&this.addHandles(e.allLayers.on(`after-remove`,t=>{if(t.item){let r=e.floorInfo,i=r?.siteLayer?.layerId??``,a=r?.facilityLayer?.layerId??``,s=r?.levelLayer?.layerId??``;(t.item.id===a||t.item.id===s||t.item.id===i)&&(this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=n(async t=>{o(t),this.level=null,this.filterMenuOpen=!1,this._clearOverride(`filterLayers`),this._clearOverride(`filterFeatures`),this._setInitialViewState(e)}))}}),`layers-handle`)}_watchSearchResults(e){e?.on(`select-result-floor`,e=>{let t=this.getLevel(e);t&&this.level!==e&&(this.level=e,this.setFloors(t))})}async _setInitialViewState(e){if(this.view)try{await this.view.when(),await this._setFilterLayers();let t=await this._getFilterFeatures();if(!t)return;if(this.filterFeatures=t,!this.hasFacilities||!this.hasLevels){a.getLogger(this).error(`Facilities and Levels are required for the Floor Filter widget`);return}if(this.hasMultipleSites||(this.filterMenuType=`facility`),this.facility&&this.level){this.filterMenuType=`facility`;let e=this.getFacility(this.facility),t=this.getLevel(this.level);this.site||=e?.siteId||void 0,this.setFloors(t)}else if(this.facility&&!this.level){this.filterMenuType=`facility`;let e=this.getFacility(this.facility),t=this.getBaseLevel(e);this.site||=e?.siteId||void 0,this.level=t?.id||void 0,this.setFloors(t)}else if(!this.facility&&this.level){this.filterMenuType=`facility`;let e=this.getLevel(this.level),t=this.getFacility(e?.facilityId);this.facility=t?.id||void 0,this.site||=t?.siteId||void 0,this.setFloors(e)}else if(this.site&&!this.facility&&!this.level)this.filterMenuType=`site`,this.setFloors(null);else{if(!e||!_(e)){this.setFloors(null);return}let t=e?.widgets?.floorFilter;if(!t){this.setFloors(null);return}t.site&&!this.site&&(this.site=t.site,this.filterMenuType=`facility`),this.setFloors(null)}if(this.filterLayers?.levelLayer?.type===`feature`&&this.filterLayers.levelLayer.capabilities.data.supportsAttachment&&this.mediaLayer==null){let{levelLayer:e}=this.filterLayers,{default:t}=await import(`../../layers/MediaLayer.js`);this.mediaLayer=new t({blendMode:`normal`,listMode:`hide`,maxScale:e.maxScale,minScale:e.minScale,spatialReference:this.view.spatialReference.clone(),title:`floor-filter-media-layer`,visible:e.visible}),this.overlaysByFacility=new Map,this.overlaysByLevel=new Map,this.view.map.add(this.mediaLayer),this.getOverlays(!0)}}catch(e){a.getLogger(this).error(`Couldn't retrieve sites, facilities, and levels`,e)}}_callOverride(e,t){this._override(e,t)}async _updateFloorFilterFromMap(e){if(!e||!_(e))return;await this.view?.when();let t=e?.widgets?.floorFilter;t&&(this._isOverridden(`enabled`)||(this.enabled=t.enabled),this._isOverridden(`longNames`)||(this.longNames=t.longNames),this._isOverridden(`minimized`)||(this.minimized=t.minimized),this._isOverridden(`pinnedLevels`)||(this.pinnedLevels=t.pinnedLevels),this._isOverridden(`site`)||(this.site=t.site),this._isOverridden(`facility`)||(this.facility=t.facility),this._isOverridden(`level`)||(this.level=t.level))}_updateMediaLayer(e){let{mediaLayer:t,overlaysByLevel:n}=this;if(t&&n&&e?.length){let r=t.source;r.elements.removeAll(),n.get(e)?.visible===!0&&r.elements.push(n.get(e)?.image)}}_computeViewAllModeFloors(e){let{filterFeatures:t}=this;if(e.floorInfo?.viewAllMode&&this.hasLevels&&this.hasFacilities&&this.filterMode===`base-floors`){let{level:n,facility:i}=this,a=[];t.levels.levelsInfo.forEach(e=>{let{id:t,facilityId:r}=e;i&&r===i?n&&t===n&&a.push(t):a.push(t)}),e.floorInfo.viewAllLevelIds=new r(a)}}};e([f({value:!1})],b.prototype,`enabled`,null),e([f({value:void 0})],b.prototype,`facility`,null),e([f({value:null})],b.prototype,`filterFeatures`,null),e([f({value:null})],b.prototype,`filterLayers`,null),e([f()],b.prototype,`filterMenuOpen`,void 0),e([f()],b.prototype,`filterMenuType`,void 0),e([f()],b.prototype,`filterMode`,void 0),e([f({readOnly:!0,value:`belowSelected`})],b.prototype,`floorVisibilityMode`,null),e([f()],b.prototype,`hasFacilities`,null),e([f()],b.prototype,`hasLevels`,null),e([f()],b.prototype,`hasMultipleSites`,null),e([f({readOnly:!0})],b.prototype,`isNormalMode`,null),e([f({value:void 0})],b.prototype,`level`,null),e([f({value:!1})],b.prototype,`longNames`,null),e([f()],b.prototype,`levelsExpanded`,void 0),e([f()],b.prototype,`mediaLayer`,void 0),e([f({value:!1})],b.prototype,`minimized`,null),e([f()],b.prototype,`overlaysByFacility`,void 0),e([f()],b.prototype,`overlaysByLevel`,void 0),e([f({value:!1})],b.prototype,`pinnedLevels`,null),e([f()],b.prototype,`searchTerm`,void 0),e([f({readOnly:!0})],b.prototype,`selectedVerticalOrder`,null),e([f({value:void 0})],b.prototype,`site`,null),e([f({readOnly:!0})],b.prototype,`state`,null),e([f({readOnly:!0,value:!1})],b.prototype,`useVerticalOrder`,null),e([f()],b.prototype,`view`,void 0),e([f()],b.prototype,`_viewHeightBreakpoint`,void 0),e([f()],b.prototype,`_viewWidthBreakpoint`,void 0),e([f()],b.prototype,`updateWebDocument`,null),b=e([p(`esri.widgets.FloorFilter.FloorFilterViewModel`)],b);const x=b;export{x as default};
2
+ import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{createTask as n}from"../../core/asyncUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import a from"../../core/Logger.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{watch as s,initial as c,syncAndInitial as l}from"../../core/reactiveUtils.js";import{Milliseconds as u}from"../../core/time.js";import{isBlobProtocol as d}from"../../core/urlUtils.js";import{property as f,subclass as p}from"../../core/accessorSupport/decorators.js";import m from"../../geometry/Polygon.js";import h from"../../webdoc/Widgets.js";import g from"../../webdoc/widgets/FloorFilter.js";import{isWebMap as _}from"../../webmap/utils.js";import{GoTo as v}from"../support/GoTo.js";function y(e){return e.declaredClass===`esri.WebScene`}let b=class extends v(t){constructor(e){super(e),this.filterMenuOpen=!1,this.filterMenuType=`site`,this.filterMode=`base-floors`,this.levelsExpanded=!0,this.searchTerm=null,this.view=null,this._updateFloorFilterTask=null,this._viewHeightBreakpoint=null,this._viewWidthBreakpoint=null}initialize(){this.addHandles([s(()=>this.view?.map,e=>{this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=n(async t=>{await this._updateFloorFilterFromMap(e),o(t),this._setInitialViewState(e)}),this._watchMapLayers(e)},c),s(()=>this.view,(e,t)=>{this._unregisterWidget(t),this._registerWidget(e),this._watchSearchResults(e)},l),s(()=>this.mediaLayer,e=>{this._watchLayerVisibility(e)},l),s(()=>this.view?.widthBreakpoint??null,e=>{this._viewWidthBreakpoint=e}),s(()=>this.view?.heightBreakpoint??null,e=>{this._viewHeightBreakpoint=e}),s(()=>this.facility,()=>void this.getOverlays()),s(()=>this.level,e=>this._updateMediaLayer(e))])}destroy(){if(this._unregisterWidget(this.view),this.mediaLayer&&this.view?.map.remove(this.mediaLayer),this.overlaysByLevel){for(let e of this.overlaysByLevel.values()){let t=e.image.image;d(t)&&URL.revokeObjectURL(t)}this.overlaysByFacility?.clear(),this.overlaysByLevel.clear()}this.view=null,this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null)}set enabled(e){this._callOverride(`enabled`,e)}set facility(e){if(e&&this._isOverridden(`facility`)){let t=this.getFacility(e);this.hasMultipleSites&&(this.site=t?.siteId||null)}this._callOverride(`facility`,e)}set filterFeatures(e){this._callOverride(`filterFeatures`,e)}set filterLayers(e){this._callOverride(`filterLayers`,e)}get floorVisibilityMode(){return this.view&&y(this.view?.map)?this.view.map.widgets?.floorFilter?.floorVisibilityMode??`belowSelected`:`belowSelected`}get hasFacilities(){return this.filterLayers?.facilityLayer!=null&&this.filterFeatures?.facilities?.facilitiesInfo?.length>0}get hasLevels(){return this.filterLayers?.levelLayer!=null&&this.filterFeatures?.levels?.levelsInfo?.length>0}get hasMultipleSites(){return this.filterLayers?.siteLayer!=null&&this.filterFeatures?.sites?.sitesInfo?.length>1}get isNormalMode(){let e=!0,t=this._viewWidthBreakpoint;return(this._viewHeightBreakpoint===`xsmall`||t===`xsmall`)&&(e=!1),e}set level(e){if(!e){this._callOverride(`level`,e),this.facility=null,this.site=null,this.setFloors(null);return}let t=null,n=null,r=e?.split(`--`);r?.length>1&&r[0]===`all`?(n=r[1],t={id:e,facilityId:n,shortName:null,longName:null,levelNumber:null,verticalOrder:null}):(t=this.getLevel(e),n=t?.facilityId??null),this.level===e&&!this.isNormalMode&&!this.levelsExpanded?this.getFacilityLevels(n)?.length>1&&(this.levelsExpanded=!0):(t&&this.hasFacilities&&this.hasLevels?(this.facility=n,this.hasMultipleSites&&(this.site=this.getFacility(n)?.siteId||null),this.setFloors(t)):this._isOverridden(`level`)&&(this.facility=null,this.site=null,this.hasMultipleSites&&(this.filterMenuType=`site`),this.setFloors(null)),this._callOverride(`level`,e))}set longNames(e){this._callOverride(`longNames`,e)}set minimized(e){this._callOverride(`minimized`,e)}set pinnedLevels(e){this._callOverride(`pinnedLevels`,e)}get selectedVerticalOrder(){return _(this.view?.map)?this.view.map.resourceInfo?.widgets?.floorFilter?.selectedVerticalOrder??null:null}set site(e){this._callOverride(`site`,e)}get state(){return this.view&&this.filterFeatures&&this.hasFacilities&&this.hasLevels?`ready`:this.view&&!this.filterFeatures?`loading`:`disabled`}get useVerticalOrder(){return this.view?.map==null?!1:_(this.view?.map)||y(this.view.map)?this.view.map.widgets?.floorFilter?.useVerticalOrder??!1:!1}filterFacilities(e){let t=e;return this.searchTerm&&(this.searchTerm=this.searchTerm.trim(),t=e.filter(e=>{let{name:t}=e;return t.toLowerCase().includes(this.searchTerm?.toLowerCase())})),this.site&&(t=t.filter(e=>e.siteId===this.site)),t.sort((e,t)=>{let n=e.name,r=t.name;return n.localeCompare(r,void 0,{sensitivity:`base`})})}filterSites(e){let t=e;return this.searchTerm&&(this.searchTerm=this.searchTerm.trim(),t=e.filter(e=>{let{name:t}=e;return t.toLowerCase().includes(this.searchTerm?.toLowerCase())})),t.sort((e,t)=>{let n=e.name,r=t.name;return n.localeCompare(r,void 0,{sensitivity:`base`})})}getBaseLevel(e){let t=this.filterFeatures?.levels?.levelsInfo,n=null;if(e){let{id:r}=e;if(t&&t.length>0&&(t.forEach(e=>{e.verticalOrder===0&&e.facilityId===r&&(n=e)}),!n)){let e=null;t.forEach(t=>{t.facilityId===r&&(e?(t.verticalOrder??0)>=0?e.verticalOrder!=null&&(e.verticalOrder<0||(t.verticalOrder??0)<e.verticalOrder)&&(e=t):e.verticalOrder!=null&&t.verticalOrder!=null&&e.verticalOrder<0&&t.verticalOrder>e.verticalOrder&&(e=t):e=t)}),e&&(n=e)}}return n}getFacility(e){return this.filterFeatures?.facilities?.facilitiesInfo?.find(t=>t.id===e)??null}getFacilityLevels(e){return!e||!this.filterFeatures?.levels?.levelsInfo?[]:this.filterFeatures.levels.levelsInfo.filter(t=>t.facilityId===e).sort((e,t)=>{let n=e.verticalOrder??0,r=t.verticalOrder??0;return n>r?-1:n===r?0:1})}getLevel(e){return this.filterFeatures?.levels?.levelsInfo?.find(t=>t.id===e)??null}async getOverlays(e=!1){let{facility:t,level:n,mediaLayer:i,overlaysByFacility:a,overlaysByLevel:o,view:s}=this;if(_(s?.map)&&i){if((i?.source).elements.removeAll(),t?.length&&(!a?.has(t)||e)){a?.set(t,new r);let e=s.map.floorInfo?.levelLayer?.layerId,n=s.map.findLayerById(e??``);if(!n||s.type!==`2d`)return;let i=await this._getAttachments(n,t),{default:c}=await import(`../../request.js`),l=Object.keys(i).map(async e=>{let r=i[e],s=r.find(e=>e.contentType===`application/json`);if(!s?.url)return;let l=new URL(s.url);n.gdbVersion?.length&&l.searchParams.set(`gdbVersion`,n.gdbVersion);let{data:u}=await c(l.toString(),{responseType:`json`}),d=r.find(e=>e.name===u.name),f=d?.url??``;if(f?.length>0){let e=new URL(f);e.searchParams.delete(`token`),n.gdbVersion?.length&&e.searchParams.set(`gdbVersion`,n.gdbVersion);let{default:r}=await import(`../../layers/support/ControlPointsGeoreference.js`),i=r.fromJSON(u.georeference),c=await this.toImageElement(e.toString(),i,u.opacity,u.clipImage,u.geometry);await c.load();let l={...u,attachments:[s,d],facilityId:t,image:c,source:JSON.stringify(u),url:e.toString()};o?.set(l.levelId,l),a?.get(t)?.push(l)}});await Promise.all(l)}this._updateMediaLayer(n)}}getSite(e){return this.filterFeatures?.sites?.sitesInfo?.find(t=>t.id===e)??null}async goTo(e){let{view:t}=this;if(!t||!e)return;let{geometry:n}=e;if(n?.extent){let e=e=>{this.callGoTo({target:e,options:{duration:u(1e3),easing:`quad-in-out-coast`}})};if(n.hasZ&&n.spatialReference?.vcsWkid!==t.spatialReference?.vcsWkid){let{projectIsLoaded:r,projectLoad:i,projectExecute:a}=await import(`../../geometry/operators/projectOperator.js`);r()||await i();let o=a(n.extent,t.spatialReference.clone(),{zConversionDisabled:!0});o&&e(o)}else e(n.extent)}}setFloors(e){let{view:t}=this;t&&(t?.map?.allLayers?.forEach(e=>{e.type===`feature`&&this._computeViewAllModeFloors(e)}),t.floors=new r(this._computeFloors(e)))}async toImageElement(e,t,n,r,i){let{default:o}=await import(`../../layers/support/ImageElement.js`),{facility:s}=this,c=()=>new o({image:e,georeference:t,opacity:n});if(r)try{let r=i?m.fromJSON(i):this.getFacility(s)?.geometry;if(r==null)return c();let{pixelRings:a,width:l,height:u}=await this._polygonToImagePixels(t,r),d=await this._imagePolygonToBlob(e,a,l,u);return new o({image:URL.createObjectURL(d),georeference:t,opacity:n})}catch(e){return a.getLogger(this).warn(`Unable to clip image; using full image instead: ${e.message}`,e),c()}return c()}updateWebDocument(e){if(_(e)||y(e)){let t={enabled:this.enabled,longNames:this.longNames,minimized:this.minimized,pinnedLevels:this.pinnedLevels,site:this.site??null,facility:this.facility??null,level:this.level??null,useVerticalOrder:this.useVerticalOrder,selectedVerticalOrder:this.selectedVerticalOrder};y(e)&&(t.floorVisibilityMode=this.floorVisibilityMode);let n=new g(t);e.widgets??=new h,e.widgets.floorFilter=n}}_computeFloors(e){if(this.filterMode===`single-floor`)this._computeSingleFloor(e);else if(this.filterMode===`base-floors`)return this.view?.type===`3d`?this._computeBaseFloors3D(e):this._computeBaseFloors(e);return this._computeEmptyFloors()}_computeSingleFloor(e){if(!e)return this._computeEmptyFloors();let t=[];return e?.id===`all`?this.getFacilityLevels(e.facilityId).forEach(e=>{e.id&&t.push(e.id)}):e&&t.push(e.id),t}_computeBaseFloors(e){let t=this.filterFeatures?.levels?.levelsInfo;if(!t?.length)return this._computeEmptyFloors();let n=[];e?.id===`all`?this.getFacilityLevels(e.facilityId).forEach(e=>{e.id&&n.push(e.id)}):e&&n.push(e.id);let r=e?.facilityId,i=e?.verticalOrder,a=(e,t)=>{e===0&&n.push(t)};return t.forEach(e=>{let{id:t,facilityId:o,verticalOrder:s}=e;!r&&!n.includes(t)?a(s,t):o!==r&&!n.includes(t)&&(this.useVerticalOrder?s===i&&n.push(t):a(s,t))}),n}_computeBaseFloors3D(e){let t=this.filterFeatures?.levels?.levelsInfo;if(!t?.length)return this._computeEmptyFloors();let n=[],r=e?.id.split(`--`)??[],i=r?.length>1&&r[0]===`all`;i?this.getFacilityLevels(e?.facilityId).forEach(e=>{e.id&&n.push(e.id)}):e&&n.push(e.id);let a=e?.facilityId,o=e?.verticalOrder;return t.forEach(e=>{let{id:t,facilityId:r,verticalOrder:s}=e;if(!a&&!n.includes(t))n.push(t);else if(!n.includes(t)){let{floorVisibilityMode:e,useVerticalOrder:c}=this,l=s<=o;r===a?e===`belowSelected`&&l&&n.push(t):(i||!c||e===`selectedOnly`&&s===o||e===`belowSelected`&&l)&&n.push(t)}}),n}_computeEmptyFloors(){return[]}async _setFilterLayers(){let{view:e}=this;if(e&&!this._isOverridden(`filterLayers`)){if(!_(e.map)&&!y(e.map))throw new i(`floorfilter:unsupported-map`,`Map must be a webmap or webscene`);{let t=e.map,n=t?.allLayers;if(n?.items?.length>0){let e={siteLayer:null,facilityLayer:null,levelLayer:null},r=t.floorInfo?.siteLayer?.layerId,i=t.floorInfo?.facilityLayer?.layerId,a=t.floorInfo?.levelLayer?.layerId,o=t.floorInfo?.siteLayer?.sublayerId||t.floorInfo?.facilityLayer?.sublayerId||t.floorInfo?.levelLayer?.sublayerId;if(!i||!a)return;let s=n.items.filter(e=>e.type===`feature`||e.type===`scene`),c=n.items.filter(e=>e.type===`map-image`);if(c?.length>0&&o){await Promise.all(c.map(e=>e.load()));let n=t.floorInfo?.siteLayer?.sublayerId,o=t.floorInfo?.facilityLayer?.sublayerId,s=t.floorInfo?.levelLayer?.sublayerId;c.forEach(t=>{let c=t.id,l=t?.allSublayers,u=l?.items;(c===r||c===i||c===a)&&u?.length>0&&l.items.forEach(t=>{let i=t.id;c===r&&i===n?e.siteLayer=t:i===o?e.facilityLayer=t:i===s&&(e.levelLayer=t)})})}s?.length>0&&s.forEach(t=>{let n=t.id;n===r?e.siteLayer=t:n===i?e.facilityLayer=t:n===a&&(e.levelLayer=t)}),this.filterLayers=e}}}}async _getAttachments(e,t){let{view:n}=this;if(_(n?.map)){let{facilityIdField:r}=n.map.floorInfo?.levelLayer??{};if(e&&n.type===`2d`&&t?.length>0&&e.capabilities.data.supportsAttachment)return e.queryAttachments({returnMetadata:!0,where:`${r} = '${t}'`})}return{}}async _getFilterFeatures(){if(this._isOverridden(`filterFeatures`))return this.filterFeatures;let[e,t,n]=await Promise.all([this._getSites(),this._getFacilities(),this._getLevels()]);return{sites:e,facilities:t,levels:n}}async _getSites(){let e={sitesInfo:[]},{filterLayers:t,view:n}=this,r=n?.map,{siteLayer:i}=t;if(!i||!r?.floorInfo?.siteLayer)return e;let a=i.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0,`type`in i&&i.type===`scene`&&(a.multipatchOption=`xyFootprint`);let{siteIdField:o,nameField:s}=r.floorInfo.siteLayer,c=await x(i,a);if(c.features.length>0){let t=c.features,n=i?.fieldsIndex.get(o)?.name||o,r=i?.fieldsIndex.get(s)?.name||s;n!=null&&r!=null&&t.forEach(t=>{let i=t.attributes,a=t.geometry,o=i[n],s=i[r];o&&s&&e.sitesInfo.push({id:o,name:s,geometry:a})})}return e}async _getFacilities(){let{filterLayers:e,view:t}=this,n=t?.map,{facilityLayer:r}=e,i={facilitiesInfo:[]};if(!r||!n?.floorInfo?.facilityLayer)return i;let a=r.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0,`type`in r&&r.type===`scene`&&(a.multipatchOption=`xyFootprint`);let{facilityIdField:o,siteIdField:s,nameField:c}=n.floorInfo.facilityLayer,l=await x(r,a);if(l.features.length>0){let e=l.features,t=r?.fieldsIndex.get(o)?.name||o,n=r?.fieldsIndex.get(s)?.name||s,a=r?.fieldsIndex.get(c)?.name||c;t&&n&&a&&e.forEach(e=>{let r=e.attributes,o=e.geometry,s=r[t],c=r[n],l=r[a];s&&l&&i.facilitiesInfo.push({id:s,siteId:c,name:l,geometry:o})})}return i}async _getLevels(){let{filterLayers:e,view:t}=this,n=t?.map,{levelLayer:r}=e,i={levelsInfo:[]};if(!r||!n?.floorInfo?.levelLayer)return i;let a=r.createQuery();a.returnGeometry=!0,a.outFields=[`*`],a.returnZ=!0;let{levelIdField:o,facilityIdField:s,longNameField:c,shortNameField:l,levelNumberField:u,verticalOrderField:d}=n.floorInfo.levelLayer,f=await x(r,a);if(f.features.length>0){let e=f.features,t=r?.fieldsIndex.get(o)?.name||o,n=r?.fieldsIndex.get(s)?.name||s,a=r?.fieldsIndex.get(c)?.name||c,p=r?.fieldsIndex.get(l)?.name||l,m=r?.fieldsIndex.get(u)?.name||u,h=r?.fieldsIndex.get(d)?.name||d;t&&n&&a&&p&&m&&h&&e.forEach(e=>{let r=e.attributes,o=r[t],s=r[n],c=r[a],l=r[p],u=r[m],d=r[h];o&&s&&c&&l&&typeof u==`number`&&typeof d==`number`&&i.levelsInfo.push({id:o,facilityId:s,longName:c,shortName:l,levelNumber:u,verticalOrder:d})})}return i}async _imagePolygonToBlob(e,t,n,r){let{getImageData:a}=await import(`../../core/imageUtils.js`),o=await a(e),s=new OffscreenCanvas(n,r),c=s.getContext(`2d`);if(!c)throw new i(`floorfilter:floor-plan-overlay`,`Unable to obtain a rendering context from the canvas.`);let l=new Path2D;for(let e of t)if(!(e.length<3)){l.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)l.lineTo(e[t].x,e[t].y);l.closePath()}return c.save(),c.clip(l,`evenodd`),c.drawImage(o,0,0,n,r),c.restore(),await s.convertToBlob({type:`image/png`})}async _polygonToImagePixels(e,t){if(e?.type!==`control-points`)throw new i(`floorfilter:floor-plan-overlay`,"Expected a `ControlPointsGeoreference`.");let{default:n}=await import(`../../geometry/Point.js`);return{pixelRings:t.rings.map(r=>r.map(([r,a])=>{let o=new n({x:r,y:a,spatialReference:t.spatialReference}),s=e.toSource(o);if(!s)throw new i(`floorfilter:floor-plan-overlay`,`toSource() returned null; check spatial references and projectOperator.`);return{x:s.x,y:s.y}})),width:e.width,height:e.height}}_registerWidget(e){e?.registerComponent(this)}_unregisterWidget(e){e?.unregisterComponent(this)}_watchLayerVisibility(e){if(this.filterLayers?.levelLayer?.type===`feature`&&e){let t=this.filterLayers?.levelLayer;this.addHandles(s(()=>t.visible,t=>{e.visible=t},l))}}_watchMapLayers(e){this.removeHandles(`layers-handle`),e&&this.addHandles(e.allLayers.on(`after-remove`,t=>{if(t.item){let r=e.floorInfo,i=r?.siteLayer?.layerId??``,a=r?.facilityLayer?.layerId??``,s=r?.levelLayer?.layerId??``;(t.item.id===a||t.item.id===s||t.item.id===i)&&(this._updateFloorFilterTask!=null&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=n(async t=>{o(t),this.level=null,this.filterMenuOpen=!1,this._clearOverride(`filterLayers`),this._clearOverride(`filterFeatures`),this._setInitialViewState(e)}))}}),`layers-handle`)}_watchSearchResults(e){e?.on(`select-result-floor`,e=>{let t=this.getLevel(e);t&&this.level!==e&&(this.level=e,this.setFloors(t))})}async _setInitialViewState(e){if(this.view)try{await this.view.when(),await this._setFilterLayers();let t=await this._getFilterFeatures();if(!t)return;if(this.filterFeatures=t,!this.hasFacilities||!this.hasLevels){a.getLogger(this).error(`Facilities and Levels are required for the Floor Filter widget`);return}if(this.hasMultipleSites||(this.filterMenuType=`facility`),this.facility&&this.level){this.filterMenuType=`facility`;let e=this.getFacility(this.facility),t=this.getLevel(this.level);this.site||=e?.siteId||void 0,this.setFloors(t)}else if(this.facility&&!this.level){this.filterMenuType=`facility`;let e=this.getFacility(this.facility),t=this.getBaseLevel(e);this.site||=e?.siteId||void 0,this.level=t?.id||void 0,this.setFloors(t)}else if(!this.facility&&this.level){this.filterMenuType=`facility`;let e=this.getLevel(this.level),t=this.getFacility(e?.facilityId);this.facility=t?.id||void 0,this.site||=t?.siteId||void 0,this.setFloors(e)}else if(this.site&&!this.facility&&!this.level)this.filterMenuType=`site`,this.setFloors(null);else{if(!e||!_(e)){this.setFloors(null);return}let t=e?.widgets?.floorFilter;if(!t){this.setFloors(null);return}t.site&&!this.site&&(this.site=t.site,this.filterMenuType=`facility`),this.setFloors(null)}if(this.filterLayers?.levelLayer?.type===`feature`&&this.filterLayers.levelLayer.capabilities.data.supportsAttachment&&this.mediaLayer==null){let{levelLayer:e}=this.filterLayers,{default:t}=await import(`../../layers/MediaLayer.js`);this.mediaLayer=new t({blendMode:`normal`,listMode:`hide`,maxScale:e.maxScale,minScale:e.minScale,spatialReference:this.view.spatialReference.clone(),title:`floor-filter-media-layer`,visible:e.visible}),this.mediaLayer.persistenceEnabled=!1,this.overlaysByFacility=new Map,this.overlaysByLevel=new Map;let n=e.parent?.type===`group`,r=e.parent,i=(n?r.layers:this.view.map.layers).indexOf(e);n?i>-1?r.add(this.mediaLayer,i+1):r.add(this.mediaLayer):i>-1?this.view.map.add(this.mediaLayer,i+1):this.view.map.add(this.mediaLayer),this.getOverlays(!0)}}catch(e){a.getLogger(this).error(`Couldn't retrieve sites, facilities, and levels`,e)}}_callOverride(e,t){this._override(e,t)}async _updateFloorFilterFromMap(e){if(!e||!_(e))return;await this.view?.when();let t=e?.widgets?.floorFilter;t&&(this._isOverridden(`enabled`)||(this.enabled=t.enabled),this._isOverridden(`longNames`)||(this.longNames=t.longNames),this._isOverridden(`minimized`)||(this.minimized=t.minimized),this._isOverridden(`pinnedLevels`)||(this.pinnedLevels=t.pinnedLevels),this._isOverridden(`site`)||(this.site=t.site),this._isOverridden(`facility`)||(this.facility=t.facility),this._isOverridden(`level`)||(this.level=t.level))}_updateMediaLayer(e){let{mediaLayer:t,overlaysByLevel:n}=this;if(t&&n&&e?.length){let r=t.source;r.elements.removeAll(),n.get(e)?.visible===!0&&r.elements.push(n.get(e)?.image)}}_computeViewAllModeFloors(e){let{filterFeatures:t}=this;if(e.floorInfo?.viewAllMode&&this.hasLevels&&this.hasFacilities&&this.filterMode===`base-floors`){let{level:n,facility:i}=this,a=[];t.levels.levelsInfo.forEach(e=>{let{id:t,facilityId:r}=e;i&&r===i?n&&t===n&&a.push(t):a.push(t)}),e.floorInfo.viewAllLevelIds=new r(a)}}};e([f({value:!1})],b.prototype,`enabled`,null),e([f({value:void 0})],b.prototype,`facility`,null),e([f({value:null})],b.prototype,`filterFeatures`,null),e([f({value:null})],b.prototype,`filterLayers`,null),e([f()],b.prototype,`filterMenuOpen`,void 0),e([f()],b.prototype,`filterMenuType`,void 0),e([f()],b.prototype,`filterMode`,void 0),e([f({readOnly:!0,value:`belowSelected`})],b.prototype,`floorVisibilityMode`,null),e([f()],b.prototype,`hasFacilities`,null),e([f()],b.prototype,`hasLevels`,null),e([f()],b.prototype,`hasMultipleSites`,null),e([f({readOnly:!0})],b.prototype,`isNormalMode`,null),e([f({value:void 0})],b.prototype,`level`,null),e([f({value:!1})],b.prototype,`longNames`,null),e([f()],b.prototype,`levelsExpanded`,void 0),e([f()],b.prototype,`mediaLayer`,void 0),e([f({value:!1})],b.prototype,`minimized`,null),e([f()],b.prototype,`overlaysByFacility`,void 0),e([f()],b.prototype,`overlaysByLevel`,void 0),e([f({value:!1})],b.prototype,`pinnedLevels`,null),e([f()],b.prototype,`searchTerm`,void 0),e([f({readOnly:!0})],b.prototype,`selectedVerticalOrder`,null),e([f({value:void 0})],b.prototype,`site`,null),e([f({readOnly:!0})],b.prototype,`state`,null),e([f({readOnly:!0,value:!1})],b.prototype,`useVerticalOrder`,null),e([f()],b.prototype,`view`,void 0),e([f()],b.prototype,`_viewHeightBreakpoint`,void 0),e([f()],b.prototype,`_viewWidthBreakpoint`,void 0),e([f()],b.prototype,`updateWebDocument`,null),b=e([p(`esri.widgets.FloorFilter.FloorFilterViewModel`)],b);async function x(e,t,n){let r={features:[]};await e.load();let i=(e.type===`sublayer`?e.sourceJSON?.maxRecordCount:e.capabilities.query.maxRecordCount)||2e3,a=async()=>{let n=t.clone();return await e.queryObjectIds(n,void 0)},o=async n=>{let r=t.clone();r.where=null,r.objectIds=n.objectIds,n.features=(await e.queryFeatures(r,void 0))?.features??null},s=await a(),c=i,l=[],u=[];for(let e=0,t=s.length;e<t;e+=c){let t=s.slice(e,e+c);t.length>0&&l.push({objectIds:t,features:null})}for(let e=0,t=l.length;e<t;e+=3){let t=l.slice(e,e+3);t.length>0&&u.push({pages:t})}for await(let e of u){let t=[];for(let n of e.pages)t.push(o(n));t.length>0&&await Promise.all(t)}for(let e of l)e.features?.length&&r.features.push(...e.features);return r}const S=b;export{S as default};
@@ -71,7 +71,7 @@ export interface LocateEvents extends LocateViewModelEvents {}
71
71
  * >
72
72
  * > **Known Limitation**
73
73
  * >
74
- * > The Locate widget does not work concurrently with the [Track](https://developers.arcgis.com/javascript/latest/references/core/widgets/Track/) widget.
74
+ * > The Locate widget does not work concurrently with the [Track component](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-track/).
75
75
  * > Only one of the widgets can be used at a time.
76
76
  *
77
77
  * You can use the view's [DefaultUI](https://developers.arcgis.com/javascript/latest/references/core/views/ui/DefaultUI/) to add widgets
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../assets.js";import n from"../../Graphic.js";import r from"../../PopupTemplate.js";import{isSome as i}from"../../core/arrayUtils.js";import a from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import s from"../../core/Logger.js";import{mappedFind as c}from"../../core/maybe.js";import{eachAlways as l,after as u}from"../../core/promiseUtils.js";import{watch as d,initial as f,whenOnce as p}from"../../core/reactiveUtils.js";import{property as m,subclass as h}from"../../core/accessorSupport/decorators.js";import g from"../../geometry/Point.js";import _ from"../../geometry/SpatialReference.js";import{getPointWithElevation as v}from"../../geometry/support/geometryUtils.js";import{getPopupLayer as y}from"../../popup/support/featureUtils.js";import b from"../../portal/Portal.js";import{isApiKeyApplicable as x}from"../../support/apiKeyUtils.js";import S from"../../symbols/PictureMarkerSymbol.js";import C from"../../symbols/SimpleFillSymbol.js";import w from"../../symbols/SimpleLineSymbol.js";import T from"../../symbols/TextSymbol.js";import{highlightsSupported as E}from"../../views/support/layerViewUtils.js";import D from"./LayerSearchSource.js";import O from"./LocatorSearchSource.js";import{SourceCollection as k}from"./types.js";import{isSearchableLayer as A}from"./support/layerSearchUtils.js";import{isArcGISWorldGeocoder as j,meteredArcGISLocatorUrl as M,isProxiedArcGISWorldGeocoder as N,isMeteredArcGISWorldGeocoder as P}from"./support/locatorUtils.js";import{supported as F,getCurrentPosition as I,positionToPoint as L}from"../support/geolocationUtils.js";import{GoTo as R}from"../support/GoTo.js";function z(e,t){return e.hasOwnProperty(t)&&e[t]!=null&&e[t]!==``}const B=`highlight`,V=_.WGS84,H=/<[\s\S]*?>/g;let U=class extends R(o){constructor(e){super(e),this._defaultPopupTemplate=new r({content:`{Match_addr}`}),this._gotoController=null,this._searching=null,this._updatingPromise=null,this._createdFeatureLayers=[],this.autoNavigate=!0,this.autoSelect=!0,this.defaultSources=new k,this.defaultSymbols={point:new S({url:t(`esri/images/search/search-symbol-32.png`),size:24,width:24,height:24}),polyline:new w({color:[130,130,130,1],width:2}),polygon:new C({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=b.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.resultLocation=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new k,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){this.addHandles([d(()=>[this.includeDefaultSources,this.view,this.portal],()=>this._update(),f),d(()=>this.messages,()=>{this._defaultPopupTemplate.title=this.messages?.searchResult??``,this._update()},f)])}destroy(){this._destroyFeatureLayers(),this._abortGoTo(),this.clearGraphics()}static{this.ALL_INDEX=-1}get activeSource(){return this.allSources.at(this.activeSourceIndex)??null}get activeSourceIndex(){return this.allSources.length===1||!this.searchAllEnabled?0:-1}set activeSourceIndex(e){this._overrideIfSome(`activeSourceIndex`,e)}get allPlaceholder(){return this.messages?.allPlaceholder}set allPlaceholder(e){this._overrideIfSome(`allPlaceholder`,e)}get allSources(){let{sources:e,defaultSources:t,includeDefaultSources:n}=this,r=typeof n==`function`?n.call(null,{sources:e,defaultSources:t}):n?t.concat(e):e,i=this._get(`allSources`)||new k;return i.removeAll(),i.addMany(r.filter(Boolean)),i}get defaultPopupTemplate(){return this._defaultPopupTemplate}set defaultPopupTemplate(e){this._overrideIfSome(`defaultPopupTemplate`,e)}get locationEnabled(){return this._get(`locationEnabled`)||F()}set locationEnabled(e){if(e===void 0){this._clearOverride(`locationEnabled`);return}let t=F();if(e&&!t){let e=new a(`locationEnabled:geolocation-unsupported`,`Geolocation API is unsupported.`,{geolocation:navigator.geolocation});s.getLogger(this).error(e)}this._override(`locationEnabled`,!!e&&t)}get placeholder(){let{allSources:e,activeSourceIndex:t,allPlaceholder:n}=this;return t===-1?n??``:e.at(t)?.placeholder??``}set searchTerm(e){this._set(`searchTerm`,e||``),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set(`selectedSuggestion`,null),e===``&&this._clear()}get searchTerm(){return this._get(`searchTerm`)||``}get state(){return this._searching?`searching`:this.updating?`loading`:this.allSources.length===0?`disabled`:`ready`}get updating(){return this._updatingPromise!=null}clear(){this.searchTerm=``}clearGraphics(){this._removeHighlight();let{view:e,resultGraphic:t}=this;e&&t&&e.graphics.remove(t),this._set(`resultLocation`,null),this._set(`resultGraphic`,null)}search(e,t){this.emit(`search-start`),this.clearGraphics();let n=(async()=>{try{let n=await this._createSuggestionForSearch(e);await this.when();let r=await this._getResultsFromSources(n,t);if(t?.signal?.aborted)return null;let i={activeSourceIndex:this.activeSourceIndex,searchTerm:n.text??``,numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(i,r,n);let a=this._getFirstResult(i.results),o=(n.location&&a?a.name:n.text)?.replaceAll(H,``);return this._set(`searchTerm`,o),(n.key&&typeof n.sourceIndex==`number`||n.location)&&this._set(`selectedSuggestion`,n),this._set(`results`,i.results),this._set(`resultCount`,i.results.reduce((e,t)=>e+(t.results?.length??0),0)),this.emit(`search-complete`,i),await this._selectFirstResult(a),i}finally{this._clearSearching()}})();return this._searching=n,n}async searchNearby(e){if(!this.locationEnabled){let e=new a(`searchNearby:geolocation-unsupported`,`Geolocation API is unsupported.`,{geolocation:navigator.geolocation});throw s.getLogger(this).error(e),e}let t=(async()=>{try{let t=await I(),n=await L({position:t,view:this.view},e);return await this.search(n,e)}finally{this._clearSearching()}})();return this._searching=t,t}async select(e){if(this.clearGraphics(),!e){let t=new a(`select:missing-parameter`,`Cannot select without a searchResult.`,{value:e});throw s.getLogger(this).error(t),t}let{view:t}=this,r=z(e,`sourceIndex`)?e.sourceIndex:this._getSourceIndexOfResult(e),i=r==null?null:this.allSources.at(r);if(!i){let e=new a(`select:missing-source`,`Cannot select without a source.`,{source:i});throw s.getLogger(this).error(e),e}let o=i instanceof D?this._getLayerSourcePopupTemplate(i):i.popupTemplate,c=i.resultSymbol||this._getDefaultSymbol(e),u=z(i,`resultGraphicEnabled`)?!!i.resultGraphicEnabled:this.resultGraphicEnabled,d=z(i,`autoNavigate`)?!!i.autoNavigate:this.autoNavigate,f=z(i,`popupEnabled`)?!!i.popupEnabled:this.popupEnabled,p=f?o||this.popupTemplate||this.defaultPopupTemplate:null,{feature:m}=e;if(!m){let e=new a(`select:missing-feature`,`Cannot select without a feature.`,{feature:m});throw s.getLogger(this).error(e),e}let{attributes:h,geometry:g}=m,_=y(m),b=null;if(g){let{labelPointExecute:e}=await import(`../../geometry/operators/labelPointOperator.js`);b=e(g)}let x={layerViewQuery:this._getLayerView(m),elevationQuery:t&&b!=null?v(b,t):Promise.resolve(b)},S=await l(x),C=S.layerViewQuery.value,w=S.elevationQuery.value;c instanceof T&&(c.text=e.name);let O=t&&d?e.target||e.extent:null;await(O==null?Promise.resolve():this._goToSearchResult(O));let k=C?m:new n({geometry:g,symbol:c,attributes:h,layer:_,origin:m.origin,popupTemplate:p});return C&&E(C)&&!f&&this._highlightFeature({graphic:k,layerView:C}),!C&&u&&t&&t.graphics.push(k),this._setResultFloor(e),this._set(`selectedResult`,e),this._set(`resultGraphic`,k),this._set(`resultLocation`,w),this.emit(`select-result`,{popupEnabled:f,result:e,source:i,sourceIndex:r}),e}async suggest(e,t,n){let r=e||this.searchTerm;this.emit(`suggest-start`,{searchTerm:r}),await this._suggestTimer(t,n);let i=await this._suggestImmediate(r,n);return this._set(`suggestions`,i?.results),this._set(`suggestionCount`,i?.results.reduce((e,t)=>e+(t.results?.length??0),0)??null),this.emit(`suggest-complete`,i),i}async when(){await p(()=>!this.updating)}async _update(){let{portal:e,view:t}=this;if(this.includeDefaultSources){let n=this._updatingPromise=l([e?.load(),t?.when()]);if(this.destroyed||(await n,n!==this._updatingPromise))return}this.destroyed||this._updateDefaultSources(),this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){let e=this.portal?.helperServices?.geocode;return e?e.map(e=>{if(e.placefinding===!1)return;let t=j(e.url)&&x(e.url)?{url:M}:null,n=O.fromJSON({...e,...t}),r=n.url;if(j(r)||N(r)||P(r)){let e=n.outFields??[`Addr_type`,`Match_addr`,`StAddr`,`City`],t=(n.placeholder||this.messages?.placeholder)??``,r=typeof n.defaultZoomScale==`number`?n.defaultZoomScale:2500;n.singleLineFieldName=`SingleLine`,n.outFields=e,n.placeholder=t,n.defaultZoomScale=r}if(n.singleLineFieldName)return n}).filter(i):[]}_destroyFeatureLayers(){this._createdFeatureLayers.forEach(e=>e?.destroy()),this._createdFeatureLayers=[]}_getLayerSources(e,t){let n=this.view?.map;return e.map(e=>{let r=n.findLayerById(e.id);if(!r)return;let i=this._getLayerJSON(e),a=D.fromJSON(i);return a.placeholder=t,this._getLayer(r,i).then(e=>{a.layer=e}),a}).filter(i).toArray()}_getTableSources(e,t){let n=this.view?.map;return e.map(e=>{if(!e.id)return;let r=n.findTableById(e.id);if(!r)return;let i=this._getLayerJSON(e),a=D.fromJSON(i);return a.placeholder=t,this._getLayer(r,i).then(e=>{a.layer=e}),a}).filter(i).toArray()}_convertApplicationProperties(){let e=(this.view?.map)?.applicationProperties?.viewing?.search;if(!e)return[];let{enabled:t,hintText:n,layers:r,tables:i}=e;if(!t)return[];let a=this._getLayerSources(r,n),o=this._getTableSources(i,n);return[...a,...o]}async _getSubLayer(e,t){if(await e.load(),!e.allSublayers)throw Error();let n=e.allSublayers.find(e=>e.id===t.subLayer);if(!n)throw Error();let r=await n.createFeatureLayer?.();if(!r)throw Error();return this._createdFeatureLayers.push(r),r}async _getBuildingSubLayer(e,t){await e.load();let n=e.allSublayers.find(e=>e.id===t.subLayer);if(n?.type!==`building-component`||(await n.load(),n.associatedLayer==null))throw Error();return await n.associatedLayer.load(),n}async _getLayer(e,t){if(e.type===`map-image`)try{return await this._getSubLayer(e,t)}catch{let t=new a(`search:create-featurelayer`,`Could not create a FeatureLayer from the MapImageLayer`,{layer:e});return s.getLogger(this).error(t),null}return e.type===`building-scene`?this._getBuildingSubLayer(e,t):(await e.load(),e.capabilities?.operations?.supportsQuery?e:null)}_getLayerJSON(e){return typeof e.toJSON==`function`?e.toJSON():e}_updateDefaultSources(){let{defaultSources:e,includeDefaultSources:t}=this;this._destroyFeatureLayers(),e.removeAll(),t&&e.addMany([...this._convertApplicationProperties(),...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set(`resultCount`,null),this._set(`results`,null),this._set(`suggestions`,null),this._set(`suggestionCount`,null),this._set(`selectedResult`,null),this._set(`selectedSuggestion`,null),this.emit(`search-clear`)}_suggestTimer(e,t){let n=e??this.suggestionDelay;return u(n,null,t?.signal)}async _createLocationForSearch(e){if(e instanceof n&&e.geometry){let{labelPointExecute:t}=await import(`../../geometry/operators/labelPointOperator.js`);return t(e.geometry)}return e instanceof g?e:Array.isArray(e)&&e.length===2?new g({longitude:e[0],latitude:e[1]}):null}async _createSuggestionForSearch(e){if(e&&z(e,`key`)&&z(e,`text`)&&z(e,`sourceIndex`))return e;let t=await this._createLocationForSearch(e),n=typeof e==`string`?e:this.searchTerm,{selectedSuggestion:r,selectedResult:i}=this,a=!e&&r&&i,o=a&&r.key===i.key&&r.sourceIndex===i.sourceIndex,s=a&&r.location;return o||s?r:{location:t,text:t?``:n,sourceIndex:null,key:null}}_getFirstResult(e){return c(e,({results:e})=>e?.[0])??null}async _selectFirstResult(e){return!this.autoSelect||!e?null:this.select(e)}async _suggestImmediate(e,t){await this.when();let n=await this._getSuggestionsFromSources(e,t);if(t?.signal?.aborted)return null;let r={activeSourceIndex:this.activeSourceIndex,searchTerm:e??``,numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(r,n),r}_formatSourceResponse(e,t,n){let r=t?.value||[],i=t?.error,a=this.allSources.at(n);if(i){let t={sourceIndex:n,source:a,error:i};e.errors.push(t),s.getLogger(this).error(i),e.numErrors++}else{let t={sourceIndex:n,source:a,results:r};e.results.push(t),e.numResults+=r.length}}_formatResponse(e,t,n){if(t){if(e.activeSourceIndex===-1){let r=n&&z(n,`sourceIndex`)&&n.sourceIndex!==-1?n.sourceIndex:void 0;t.forEach((t,n)=>{let i=r===void 0?n:r;this._formatSourceResponse(e,t,i)})}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}}async _getResultsFromSources(e,t){let{allSources:n}=this,r=!e.location&&z(e,`sourceIndex`)?e.sourceIndex:this.activeSourceIndex,i=[];if(!n.length){let e=new a(`search:no-sources-defined`,`At least one source is required.`,{allSources:n});throw s.getLogger(this).error(e),e}return r===-1?n.forEach((n,r)=>{i.push(this._getResultsFromSource(e,r,t))}):i.push(this._getResultsFromSource(e,r,t)),l(i)}async _getSuggestionsFromSources(e,t){let{allSources:n,activeSourceIndex:r}=this,i=[];if(!n.length){let e=new a(`suggest:no-sources-defined`,`At least one source is required.`,{allSources:n});throw s.getLogger(this).error(e),e}return r===-1?n.forEach((n,r)=>{i.push(this._getSuggestionsFromSource(e,r,t))}):i.push(this._getSuggestionsFromSource(e,r,t)),l(i)}async _getResultsFromSource(e,t,n){let r=t==null?null:this.allSources.at(t);if(!r)return null;let{location:i=null}=e,a=this.view?.spatialReference??V,o=z(r,`maxResults`)?r.maxResults:this.maxResults,s=r instanceof D&&z(r,`exactMatch`)?r.exactMatch:!1,{view:c}=this;return r.getResults?.({exactMatch:s,location:i,maxResults:o,sourceIndex:t,spatialReference:a,suggestResult:e,view:c},n)}async _getSuggestionsFromSource(e,t,n){let r=this.allSources.at(t);if(!r)return null;e??=``;let i=z(r,`suggestionsEnabled`)?r.suggestionsEnabled:this.suggestionsEnabled,a=e?.length,o=z(r,`minSuggestCharacters`)?r.minSuggestCharacters:this.minSuggestCharacters;if(i&&e.trim()&&a>=o){let i=this.view?.spatialReference||V,a=z(r,`maxSuggestions`)?r.maxSuggestions:this.maxSuggestions,{view:o}=this,s=r instanceof D&&z(r,`exactMatch`)?r.exactMatch:!1;return r.getSuggestions?.({view:o,sourceIndex:t,suggestTerm:e,spatialReference:i,maxSuggestions:a,exactMatch:s},n)}return null}_getLayerSourcePopupTemplate(e){let{layer:t}=e;if(t)return z(e,`popupTemplate`)?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){return c(this.results??[],({results:t,sourceIndex:n})=>t?.includes(e)?n:null)??null}async _goToSearchResult(e){this._abortGoTo();let t=new AbortController;this._gotoController=t;let n={target:{target:e},options:{signal:t.signal}};e||(n.options.animate=!1),await this.callGoTo(n),this._gotoController=null}_getDefaultSymbol(e){let{defaultSymbols:t}=this,n=e.feature?.geometry;if(n==null)return null;switch(n.type){case`point`:case`multipoint`:return t.point;case`polyline`:return t.polyline;case`extent`:case`polygon`:return t.polygon;default:return null}}_removeHighlight(){this.removeHandles(B)}async _getLayerView(e){let{view:t}=this;if(!e||!t)return null;let n=y(e);return!n||n.type===`building-component`||n.type===`subtype-sublayer`?null:(await t.when(),t.whenLayerView(n))}_highlightFeature(e){let{graphic:t,layerView:n}=e,{attributes:r}=t,i=y(t);if(!A(i))return;let{objectIdField:a}=i,o=(a&&r?.[a])??null,s=n.highlight(o??t);this.addHandles(s,B)}_setResultFloor(e){let{view:t}=this,n=e.feature?.attributes,r=y(e.feature);if(A(r)&&r.floorInfo?.floorField&&n){let e=n[r.floorInfo.floorField];t?.emit(`select-result-floor`,e)}}};e([m()],U.prototype,`_searching`,void 0),e([m()],U.prototype,`_updatingPromise`,void 0),e([m({readOnly:!0,value:null})],U.prototype,`activeSource`,null),e([m()],U.prototype,`activeSourceIndex`,null),e([m()],U.prototype,`allPlaceholder`,null),e([m({readOnly:!0})],U.prototype,`allSources`,null),e([m()],U.prototype,`autoNavigate`,void 0),e([m()],U.prototype,`autoSelect`,void 0),e([m({type:r})],U.prototype,`defaultPopupTemplate`,null),e([m({readOnly:!0})],U.prototype,`defaultSources`,void 0),e([m()],U.prototype,`defaultSymbols`,void 0),e([m()],U.prototype,`includeDefaultSources`,void 0),e([m()],U.prototype,`locationEnabled`,null),e([m()],U.prototype,`maxInputLength`,void 0),e([m()],U.prototype,`maxResults`,void 0),e([m()],U.prototype,`maxSuggestions`,void 0),e([m()],U.prototype,`messages`,void 0),e([m()],U.prototype,`minSuggestCharacters`,void 0),e([m({readOnly:!0})],U.prototype,`placeholder`,null),e([m()],U.prototype,`popupEnabled`,void 0),e([m({type:r})],U.prototype,`popupTemplate`,void 0),e([m({type:b})],U.prototype,`portal`,void 0),e([m()],U.prototype,`resultCount`,void 0),e([m()],U.prototype,`resultGraphicEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`resultGraphic`,void 0),e([m({readOnly:!0})],U.prototype,`resultLocation`,void 0),e([m({readOnly:!0})],U.prototype,`results`,void 0),e([m({readOnly:!0})],U.prototype,`selectedSuggestion`,void 0),e([m()],U.prototype,`searchAllEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`selectedResult`,void 0),e([m()],U.prototype,`searchTerm`,null),e([m({type:k})],U.prototype,`sources`,void 0),e([m({readOnly:!0})],U.prototype,`state`,null),e([m()],U.prototype,`suggestionDelay`,void 0),e([m()],U.prototype,`suggestionCount`,void 0),e([m({readOnly:!0})],U.prototype,`suggestions`,void 0),e([m()],U.prototype,`suggestionsEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`updating`,null),e([m()],U.prototype,`view`,void 0),e([m()],U.prototype,`clear`,null),U=e([h(`esri.widgets.Search.SearchViewModel`)],U);const W=U;export{W as default};
2
+ import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../assets.js";import n from"../../Graphic.js";import r from"../../PopupTemplate.js";import{isSome as i}from"../../core/arrayUtils.js";import a from"../../core/Error.js";import{EventedAccessor as o}from"../../core/Evented.js";import s from"../../core/Logger.js";import{mappedFind as c}from"../../core/maybe.js";import{eachAlways as l,after as u}from"../../core/promiseUtils.js";import{watch as d,initial as f,whenOnce as p}from"../../core/reactiveUtils.js";import{property as m,subclass as h}from"../../core/accessorSupport/decorators.js";import g from"../../geometry/Point.js";import _ from"../../geometry/SpatialReference.js";import{getPointWithElevation as v}from"../../geometry/support/geometryUtils.js";import{getPopupLayer as y}from"../../popup/support/featureUtils.js";import b from"../../portal/Portal.js";import{isApiKeyApplicable as x}from"../../support/apiKeyUtils.js";import S from"../../symbols/PictureMarkerSymbol.js";import C from"../../symbols/SimpleFillSymbol.js";import w from"../../symbols/SimpleLineSymbol.js";import T from"../../symbols/TextSymbol.js";import{highlightsSupported as E}from"../../views/support/layerViewUtils.js";import D from"./LayerSearchSource.js";import O from"./LocatorSearchSource.js";import{SourceCollection as k}from"./types.js";import{isSearchableLayer as A}from"./support/layerSearchUtils.js";import{isArcGISWorldGeocoder as j,meteredArcGISLocatorUrl as M,isProxiedArcGISWorldGeocoder as N,isMeteredArcGISWorldGeocoder as P}from"./support/locatorUtils.js";import{supported as F,getCurrentPosition as I,positionToPoint as L}from"../support/geolocationUtils.js";import{GoTo as R}from"../support/GoTo.js";function z(e,t){return e.hasOwnProperty(t)&&e[t]!=null&&e[t]!==``}const B=`highlight`,V=_.WGS84,H=/<[\s\S]*?>/g;let U=class extends R(o){constructor(e){super(e),this._defaultPopupTemplate=new r({content:`{Match_addr}`}),this._gotoController=null,this._searching=null,this._updatingPromise=null,this._createdFeatureLayers=[],this.autoNavigate=!0,this.autoSelect=!0,this.defaultSources=new k,this.defaultSymbols={point:new S({url:t(`esri/images/search/search-symbol-32.png`),size:24,width:24,height:24}),polyline:new w({color:[130,130,130,1],width:2}),polygon:new C({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=b.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.resultLocation=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new k,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){this.addHandles([d(()=>[this.includeDefaultSources,this.view,this.portal],()=>this._update(),f),d(()=>this.messages,()=>{this._defaultPopupTemplate.title=this.messages?.searchResult??``,this._update()},f)])}destroy(){this._destroyFeatureLayers(),this._abortGoTo(),this.clearGraphics()}static{this.ALL_INDEX=-1}get activeSource(){return this.allSources.at(this.activeSourceIndex)??null}get activeSourceIndex(){return this.allSources.length===1||!this.searchAllEnabled?0:-1}set activeSourceIndex(e){this._overrideIfSome(`activeSourceIndex`,e)}get allPlaceholder(){return this.messages?.allPlaceholder}set allPlaceholder(e){this._overrideIfSome(`allPlaceholder`,e)}get allSources(){let{sources:e,defaultSources:t,includeDefaultSources:n}=this,r=typeof n==`function`?n.call(null,{sources:e,defaultSources:t}):n?t.concat(e):e,i=this._get(`allSources`)||new k;return i.removeAll(),i.addMany(r.filter(Boolean)),i}get defaultPopupTemplate(){return this._defaultPopupTemplate}set defaultPopupTemplate(e){this._overrideIfSome(`defaultPopupTemplate`,e)}get locationEnabled(){return this._get(`locationEnabled`)||F()}set locationEnabled(e){if(e===void 0){this._clearOverride(`locationEnabled`);return}let t=F();if(e&&!t){let e=new a(`locationEnabled:geolocation-unsupported`,`Geolocation API is unsupported.`,{geolocation:navigator.geolocation});s.getLogger(this).error(e)}this._override(`locationEnabled`,!!e&&t)}get placeholder(){let{allSources:e,activeSourceIndex:t,allPlaceholder:n}=this;return t===-1?n??``:e.at(t)?.placeholder??``}set searchTerm(e){this._set(`searchTerm`,e||``),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set(`selectedSuggestion`,null),e===``&&this._clear()}get searchTerm(){return this._get(`searchTerm`)||``}get state(){return this._searching?`searching`:this.updating?`loading`:this.allSources.length===0?`disabled`:`ready`}get updating(){return this._updatingPromise!=null}clear(){this.searchTerm=``}clearGraphics(){this._removeHighlight();let{view:e,resultGraphic:t}=this;e&&t&&e.graphics.remove(t),this._set(`resultLocation`,null),this._set(`resultGraphic`,null)}search(e,t){this.emit(`search-start`),this.clearGraphics();let n=(async()=>{try{let n=await this._createSuggestionForSearch(e);await this.when();let r=await this._getResultsFromSources(n,t);if(t?.signal?.aborted)return null;let i={activeSourceIndex:this.activeSourceIndex,searchTerm:n.text??``,numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(i,r,n);let a=this._getFirstResult(i.results),o=(n.location&&a?a.name:n.text)?.replaceAll(H,``);return this._set(`searchTerm`,o),(n.key&&typeof n.sourceIndex==`number`||n.location)&&this._set(`selectedSuggestion`,n),this._set(`results`,i.results),this._set(`resultCount`,i.results.reduce((e,t)=>e+(t.results?.length??0),0)),this.emit(`search-complete`,i),await this._selectFirstResult(a),i}finally{this._clearSearching()}})();return this._searching=n,n}async searchNearby(e){if(!this.locationEnabled){let e=new a(`searchNearby:geolocation-unsupported`,`Geolocation API is unsupported.`,{geolocation:navigator.geolocation});throw s.getLogger(this).error(e),e}let t=(async()=>{try{let t=await I(),n=await L({position:t,view:this.view},e);return await this.search(n,e)}finally{this._clearSearching()}})();return this._searching=t,t}async select(e){if(this.clearGraphics(),!e){let t=new a(`select:missing-parameter`,`Cannot select without a searchResult.`,{value:e});throw s.getLogger(this).error(t),t}let{view:t}=this,r=z(e,`sourceIndex`)?e.sourceIndex:this._getSourceIndexOfResult(e),i=r==null?null:this.allSources.at(r);if(!i){let e=new a(`select:missing-source`,`Cannot select without a source.`,{source:i});throw s.getLogger(this).error(e),e}let o=i instanceof D?this._getLayerSourcePopupTemplate(i):i.popupTemplate,c=i.resultSymbol||this._getDefaultSymbol(e),u=z(i,`resultGraphicEnabled`)?!!i.resultGraphicEnabled:this.resultGraphicEnabled,d=z(i,`autoNavigate`)?!!i.autoNavigate:this.autoNavigate,f=z(i,`popupEnabled`)?!!i.popupEnabled:this.popupEnabled,p=f?o||this.popupTemplate||this.defaultPopupTemplate:null,{feature:m}=e;if(!m){let e=new a(`select:missing-feature`,`Cannot select without a feature.`,{feature:m});throw s.getLogger(this).error(e),e}let{attributes:h,geometry:g}=m,_=y(m),b=null;if(g){let{labelPointExecute:e}=await import(`../../geometry/operators/labelPointOperator.js`);b=e(g)}let x={layerViewQuery:this._getLayerView(m),elevationQuery:t&&b!=null?v(b,t):Promise.resolve(b)},S=await l(x),C=S.layerViewQuery.value,w=S.elevationQuery.value;c instanceof T&&(c.text=e.name);let O=t&&d?e.target||e.extent:null;await(O==null?Promise.resolve():this._goToSearchResult(O));let k=C?m:new n({geometry:g,symbol:c,attributes:h,layer:_,origin:m.origin,popupTemplate:p});return C&&E(C)&&!f&&this._highlightFeature({graphic:k,layerView:C}),!C&&u&&t&&t.graphics.push(k),this._setResultFloor(e),this._set(`selectedResult`,e),this._set(`resultGraphic`,k),this._set(`resultLocation`,w),this.emit(`select-result`,{popupEnabled:f,result:e,source:i,sourceIndex:r}),e}async suggest(e,t,n){let r=e||this.searchTerm;this.emit(`suggest-start`,{searchTerm:r}),await this._suggestTimer(t,n);let i=await this._suggestImmediate(r,n);return this._set(`suggestions`,i?.results),this._set(`suggestionCount`,i?.results.reduce((e,t)=>e+(t.results?.length??0),0)??null),this.emit(`suggest-complete`,i),i}async when(){await p(()=>!this.updating)}async _update(){let{portal:e,view:t}=this;if(!this.includeDefaultSources){this._updateDefaultSources(),this._updatingPromise=null;return}let n=l([e?.load(),t?.when()]).then(async()=>{this.destroyed||n!==this._updatingPromise||await this._updateDefaultSources()});this._updatingPromise=n,await n,n===this._updatingPromise&&(this._updatingPromise=null)}_clearSearching(){this._searching=null}_convertHelperServices(){let e=this.portal?.helperServices?.geocode;return e?e.map(e=>{if(e.placefinding===!1)return;let t=j(e.url)&&x(e.url)?{url:M}:null,n=O.fromJSON({...e,...t}),r=n.url;if(j(r)||N(r)||P(r)){let e=n.outFields??[`Addr_type`,`Match_addr`,`StAddr`,`City`],t=(n.placeholder||this.messages?.placeholder)??``,r=typeof n.defaultZoomScale==`number`?n.defaultZoomScale:2500;n.singleLineFieldName=`SingleLine`,n.outFields=e,n.placeholder=t,n.defaultZoomScale=r}if(n.singleLineFieldName)return n}).filter(i):[]}_destroyFeatureLayers(){this._createdFeatureLayers.forEach(e=>e?.destroy()),this._createdFeatureLayers=[]}async _getLayerSources(e,t){let n=this.view?.map;return(await l(e.map(async e=>{let r=n.findLayerById(e.id);if(!r)return;let i=this._getLayerJSON(e),a=await this._getLayer(r,i);if(!a)return;let o=D.fromJSON(i);return o.placeholder=t,o.layer=a,o}).toArray())).map(({value:e})=>e).filter(i)}async _getTableSources(e,t){let n=this.view?.map;return(await l(e.map(async e=>{if(!e.id)return;let r=n.findTableById(e.id);if(!r)return;let i=this._getLayerJSON(e),a=await this._getLayer(r,i);if(!a)return;let o=D.fromJSON(i);return o.placeholder=t,o.layer=a,o}).toArray())).map(({value:e})=>e).filter(i)}async _convertApplicationProperties(){let e=(this.view?.map)?.applicationProperties?.viewing?.search;if(!e)return[];let{enabled:t,hintText:n,layers:r,tables:i}=e;if(!t)return[];let[a,o]=await Promise.all([this._getLayerSources(r,n),this._getTableSources(i,n)]);return[...a,...o]}async _getSubLayer(e,t){let n=this._updatingPromise;if(await e.load(),!e.allSublayers)throw Error();let r=e.allSublayers.find(e=>e.id===t.subLayer);if(!r)throw Error();let i=await r.createFeatureLayer?.();if(!i)throw Error();if(this.destroyed||n!==this._updatingPromise)return i.destroy(),null;this._createdFeatureLayers.push(i);try{await i.load()}catch(e){throw this._createdFeatureLayers=this._createdFeatureLayers.filter(e=>e!==i),i.destroy(),e}return this.destroyed||n!==this._updatingPromise?(this._createdFeatureLayers=this._createdFeatureLayers.filter(e=>e!==i),i.destroy(),null):i}async _getBuildingSubLayer(e,t){await e.load();let n=e.allSublayers.find(e=>e.id===t.subLayer);if(n?.type!==`building-component`||(await n.load(),n.associatedLayer==null))throw Error();return await n.associatedLayer.load(),n}async _getLayer(e,t){if(e.type===`map-image`)try{return await this._getSubLayer(e,t)}catch{let t=new a(`search:create-featurelayer`,`Could not create a FeatureLayer from the MapImageLayer`,{layer:e});return s.getLogger(this).error(t),null}return e.type===`building-scene`?this._getBuildingSubLayer(e,t):(await e.load(),e.capabilities?.operations?.supportsQuery?e:null)}_getLayerJSON(e){return typeof e.toJSON==`function`?e.toJSON():e}async _updateDefaultSources(){let{defaultSources:e,includeDefaultSources:t}=this,n=this._updatingPromise;if(this._destroyFeatureLayers(),e.removeAll(),t){let t=await this._convertApplicationProperties();if(this.destroyed||n!==this._updatingPromise)return;e.addMany([...t,...this._convertHelperServices()])}}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set(`resultCount`,null),this._set(`results`,null),this._set(`suggestions`,null),this._set(`suggestionCount`,null),this._set(`selectedResult`,null),this._set(`selectedSuggestion`,null),this.emit(`search-clear`)}_suggestTimer(e,t){let n=e??this.suggestionDelay;return u(n,null,t?.signal)}async _createLocationForSearch(e){if(e instanceof n&&e.geometry){let{labelPointExecute:t}=await import(`../../geometry/operators/labelPointOperator.js`);return t(e.geometry)}return e instanceof g?e:Array.isArray(e)&&e.length===2?new g({longitude:e[0],latitude:e[1]}):null}async _createSuggestionForSearch(e){if(e&&z(e,`key`)&&z(e,`text`)&&z(e,`sourceIndex`))return e;let t=await this._createLocationForSearch(e),n=typeof e==`string`?e:this.searchTerm,{selectedSuggestion:r,selectedResult:i}=this,a=!e&&r&&i,o=a&&r.key===i.key&&r.sourceIndex===i.sourceIndex,s=a&&r.location;return o||s?r:{location:t,text:t?``:n,sourceIndex:null,key:null}}_getFirstResult(e){return c(e,({results:e})=>e?.[0])??null}async _selectFirstResult(e){return!this.autoSelect||!e?null:this.select(e)}async _suggestImmediate(e,t){await this.when();let n=await this._getSuggestionsFromSources(e,t);if(t?.signal?.aborted)return null;let r={activeSourceIndex:this.activeSourceIndex,searchTerm:e??``,numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(r,n),r}_formatSourceResponse(e,t,n){let r=t?.value||[],i=t?.error,a=this.allSources.at(n);if(i){let t={sourceIndex:n,source:a,error:i};e.errors.push(t),s.getLogger(this).error(i),e.numErrors++}else{let t={sourceIndex:n,source:a,results:r};e.results.push(t),e.numResults+=r.length}}_formatResponse(e,t,n){if(t){if(e.activeSourceIndex===-1){let r=n&&z(n,`sourceIndex`)&&n.sourceIndex!==-1?n.sourceIndex:void 0;t.forEach((t,n)=>{let i=r===void 0?n:r;this._formatSourceResponse(e,t,i)})}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}}async _getResultsFromSources(e,t){let{allSources:n}=this,r=!e.location&&z(e,`sourceIndex`)?e.sourceIndex:this.activeSourceIndex,i=[];if(!n.length){let e=new a(`search:no-sources-defined`,`At least one source is required.`,{allSources:n});throw s.getLogger(this).error(e),e}return r===-1?n.forEach((n,r)=>{i.push(this._getResultsFromSource(e,r,t))}):i.push(this._getResultsFromSource(e,r,t)),l(i)}async _getSuggestionsFromSources(e,t){let{allSources:n,activeSourceIndex:r}=this,i=[];if(!n.length){let e=new a(`suggest:no-sources-defined`,`At least one source is required.`,{allSources:n});throw s.getLogger(this).error(e),e}return r===-1?n.forEach((n,r)=>{i.push(this._getSuggestionsFromSource(e,r,t))}):i.push(this._getSuggestionsFromSource(e,r,t)),l(i)}async _getResultsFromSource(e,t,n){let r=t==null?null:this.allSources.at(t);if(!r)return null;let{location:i=null}=e,a=this.view?.spatialReference??V,o=z(r,`maxResults`)?r.maxResults:this.maxResults,s=r instanceof D&&z(r,`exactMatch`)?r.exactMatch:!1,{view:c}=this;return r.getResults?.({exactMatch:s,location:i,maxResults:o,sourceIndex:t,spatialReference:a,suggestResult:e,view:c},n)}async _getSuggestionsFromSource(e,t,n){let r=this.allSources.at(t);if(!r)return null;e??=``;let i=z(r,`suggestionsEnabled`)?r.suggestionsEnabled:this.suggestionsEnabled,a=e?.length,o=z(r,`minSuggestCharacters`)?r.minSuggestCharacters:this.minSuggestCharacters;if(i&&e.trim()&&a>=o){let i=this.view?.spatialReference||V,a=z(r,`maxSuggestions`)?r.maxSuggestions:this.maxSuggestions,{view:o}=this,s=r instanceof D&&z(r,`exactMatch`)?r.exactMatch:!1;return r.getSuggestions?.({view:o,sourceIndex:t,suggestTerm:e,spatialReference:i,maxSuggestions:a,exactMatch:s},n)}return null}_getLayerSourcePopupTemplate(e){let{layer:t}=e;if(t)return z(e,`popupTemplate`)?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){return c(this.results??[],({results:t,sourceIndex:n})=>t?.includes(e)?n:null)??null}async _goToSearchResult(e){this._abortGoTo();let t=new AbortController;this._gotoController=t;let n={target:{target:e},options:{signal:t.signal}};e||(n.options.animate=!1),await this.callGoTo(n),this._gotoController=null}_getDefaultSymbol(e){let{defaultSymbols:t}=this,n=e.feature?.geometry;if(n==null)return null;switch(n.type){case`point`:case`multipoint`:return t.point;case`polyline`:return t.polyline;case`extent`:case`polygon`:return t.polygon;default:return null}}_removeHighlight(){this.removeHandles(B)}async _getLayerView(e){let{view:t}=this;if(!e||!t)return null;let n=y(e);return!n||n.type===`building-component`||n.type===`subtype-sublayer`?null:(await t.when(),t.whenLayerView(n))}_highlightFeature(e){let{graphic:t,layerView:n}=e,{attributes:r}=t,i=y(t);if(!A(i))return;let{objectIdField:a}=i,o=(a&&r?.[a])??null,s=n.highlight(o??t);this.addHandles(s,B)}_setResultFloor(e){let{view:t}=this,n=e.feature?.attributes,r=y(e.feature);if(A(r)&&r.floorInfo?.floorField&&n){let e=n[r.floorInfo.floorField];t?.emit(`select-result-floor`,e)}}};e([m()],U.prototype,`_searching`,void 0),e([m()],U.prototype,`_updatingPromise`,void 0),e([m({readOnly:!0,value:null})],U.prototype,`activeSource`,null),e([m()],U.prototype,`activeSourceIndex`,null),e([m()],U.prototype,`allPlaceholder`,null),e([m({readOnly:!0})],U.prototype,`allSources`,null),e([m()],U.prototype,`autoNavigate`,void 0),e([m()],U.prototype,`autoSelect`,void 0),e([m({type:r})],U.prototype,`defaultPopupTemplate`,null),e([m({readOnly:!0})],U.prototype,`defaultSources`,void 0),e([m()],U.prototype,`defaultSymbols`,void 0),e([m()],U.prototype,`includeDefaultSources`,void 0),e([m()],U.prototype,`locationEnabled`,null),e([m()],U.prototype,`maxInputLength`,void 0),e([m()],U.prototype,`maxResults`,void 0),e([m()],U.prototype,`maxSuggestions`,void 0),e([m()],U.prototype,`messages`,void 0),e([m()],U.prototype,`minSuggestCharacters`,void 0),e([m({readOnly:!0})],U.prototype,`placeholder`,null),e([m()],U.prototype,`popupEnabled`,void 0),e([m({type:r})],U.prototype,`popupTemplate`,void 0),e([m({type:b})],U.prototype,`portal`,void 0),e([m()],U.prototype,`resultCount`,void 0),e([m()],U.prototype,`resultGraphicEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`resultGraphic`,void 0),e([m({readOnly:!0})],U.prototype,`resultLocation`,void 0),e([m({readOnly:!0})],U.prototype,`results`,void 0),e([m({readOnly:!0})],U.prototype,`selectedSuggestion`,void 0),e([m()],U.prototype,`searchAllEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`selectedResult`,void 0),e([m()],U.prototype,`searchTerm`,null),e([m({type:k})],U.prototype,`sources`,void 0),e([m({readOnly:!0})],U.prototype,`state`,null),e([m()],U.prototype,`suggestionDelay`,void 0),e([m()],U.prototype,`suggestionCount`,void 0),e([m({readOnly:!0})],U.prototype,`suggestions`,void 0),e([m()],U.prototype,`suggestionsEnabled`,void 0),e([m({readOnly:!0})],U.prototype,`updating`,null),e([m()],U.prototype,`view`,void 0),e([m()],U.prototype,`clear`,null),U=e([h(`esri.widgets.Search.SearchViewModel`)],U);const W=U;export{W as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{substitute as e,formatDate as t}from"../../../intl.js";import n from"../../../core/Error.js";import{clone as r}from"../../../core/lang.js";import i from"../../../core/Logger.js";import{mappedFind as a}from"../../../core/maybe.js";import{getMetersPerUnitForSR as o}from"../../../core/units.js";import s from"../../../geometry/Polygon.js";import{getExtentFromGeometry as c,scaleExtent as l}from"../../../geometry/support/geometryUtils.js";import{getPopupLayer as u}from"../../../popup/support/featureUtils.js";import d from"../../../rest/support/FullTextSearch.js";const f=/https?:\/\/services.*\.arcgis\.com/i,p=/(?:\{([^}]+)\})/g,m=()=>i.getLogger(`esri.widgets.Search.support.layerSearchUtils`);function h(e,t){let{exactMatch:r=!1,location:i,maxResults:a,spatialReference:s,source:c,sourceIndex:l,suggestResult:u,view:d}=e,{layer:f,zoomScale:p}=c,h=d?.scale,g=_(c,d),x=t?.signal;return y(f).then(()=>{let e=f.popupTemplate;return e?e.getRequiredFields(f.fieldsIndex):null}).then(e=>{let{objectIdField:t,returnZ:_}=f,y=O(c);if(!A(f,y))throw m().error(`invalid-field: displayField is invalid.`),new n(`getResults():invalid-field`,`displayField is invalid.`);let S=e?.length?e:[y],w=c.outFields||S,T=v(w);if(!w.includes(t)&&!T&&w.push(t),f.floorInfo?.floorField&&w.push(f.floorInfo.floorField),!(T||k(f,w)))throw m().error(`invalid-field: outField is invalid.`),new n(`getResults():invalid-field`,`outField is invalid.`);let D=f.createQuery(),{orderByFields:j}=c;if(j&&(D.orderByFields=j),s){D.outSpatialReference=s;let e=1/o(s);e&&(D.maxAllowableOffset=e)}let M=f.geometryType===`mesh`||f.geometryType===`multipatch`;if(D.returnZ=f.capabilities?.data?.supportsZ&&!M&&_!==!1,D.returnGeometry=!0,D.multipatchOption=M?`xyFootprint`:null,w&&(D.outFields=w),i)D.geometry=i;else if(u.key)D.objectIds=[u.key];else{let e=c.searchFields||[y];if(!k(f,e))throw m().error(`invalid-field: search field is invalid.`),new n(`getResults():invalid-field`,`search field is invalid.`);E(f)&&(D.num=a),g&&(D.geometry=g);let t=u.text;if(!t?.trim()||(C({source:c,searchTerm:t,searchFields:e,exactMatch:r,query:D,type:`search`}),!b(D)))return[]}return f.queryFeatures(D,{signal:x}).then(async e=>{let{labelPointExecute:t}=await import(`../../../geometry/operators/labelPointOperator.js`);return K(e,d,c,l,y,h,p,t)})})}function g(e,t){let{source:r,spatialReference:i,view:a,suggestTerm:o,maxSuggestions:s,sourceIndex:c,exactMatch:l}=e,{layer:u}=r,d=t?.signal,f=_(r,a);return y(u).then(()=>{if(!E(u))return[];let e=O(r),t=r.searchFields||[e],a=[];r.suggestionTemplate?r.suggestionTemplate.replaceAll(p,(e,t)=>(a.push(t),e)):a.push(e);let h=v(a);!a.includes(u.objectIdField)&&!h&&a.push(u.objectIdField);let g=A(u,e),_=h||k(u,a),y=k(u,t);if(!g)throw m().error(`invalid-field: displayField is invalid.`),new n(`getSuggestions():invalid-field`,`displayField is invalid.`);if(!_)throw m().error(`invalid-field: outField is invalid.`),new n(`getSuggestions():invalid-field`,`outField is invalid.`);if(!y)throw m().error(`invalid-field: search field is invalid.`),new n(`getSuggestions():invalid-field`,`search field is invalid.`);let x=u.createQuery(),{orderByFields:S}=r;return S&&(x.orderByFields=S),x.outSpatialReference=i,x.returnGeometry=!1,x.num=s,x.outFields=a,f&&(x.geometry=f),!o.trim()||(C({source:r,searchTerm:o,searchFields:t,exactMatch:l,query:x,type:`suggest`}),!b(x))?[]:u.queryFeatures(x,{signal:d}).then(t=>U(t,r,c,e))})}function _(e,t){let{filter:n,withinViewEnabled:r}=e,i=t?.extent;return n?.geometry??(r&&i?i:void 0)}function v(e){return e&&e.includes(`*`)}async function y(e){e&&await e.load()}function b(e){return!!(e.fullText||e.where)}function x(e,t){let n=e?.indexes;return!n||!t?.length?!1:n.filter(e=>e.indexType===`FullText`).some(e=>{let n=e.fields?.split(`,`).map(e=>e.trim().toLowerCase())||[];return t.every(e=>n.includes(e.toLowerCase()))})}function S({text:e,searchFields:t,searchType:n=`prefix`}){return(n===`simple`?[e.trim()]:e.trim().split(` `)).filter(e=>!!e.trim()).map(e=>new d({onFields:t,searchTerm:e,searchType:n}))}function C({source:e,searchTerm:t,searchFields:n,exactMatch:r,query:i,type:a}){let{layer:o,filter:s,prefix:c=``,suffix:l=``,searchMode:u}=e,d=w(u,r,o,n);d.fullTextSearchType&&t&&(i.fullText=S({text:t,searchFields:n,searchType:d.fullTextSearchType})),i.where=L({searchTerm:N(`${c}${t}${l}`),layer:o,searchFields:n,filter:s,exactMatch:d.exactMatch,query:i,type:a})}function w(e,t,n,r){let i=T(n)&&x(n,r),a=e??(t?`simple`:`starts-with`);return a===`simple`?{exactMatch:!0,fullTextSearchType:null}:e===`starts-with`?{exactMatch:!1,fullTextSearchType:null}:a===`full-text-simple`?i?{exactMatch:!1,fullTextSearchType:`simple`}:{exactMatch:!0,fullTextSearchType:null}:i?{exactMatch:!1,fullTextSearchType:`prefix`}:{exactMatch:!1,fullTextSearchType:null}}function T(e){return e?.capabilities?.query?.supportsFullTextSearch??!1}function E(e){return e?.capabilities?.query?.supportsPagination??!1}function D(e){return e?.fieldsIndex?.fields?.find(e=>e.type===`string`)?.name??``}function O(e){return e.displayField||e.layer.displayField||D(e.layer)}function k(e,t){return!e||!t?.length?!1:t.every(t=>A(e,t))}function A(e,t){return!!e.getField(t)}function j(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!0;return!1}function M({codedValues:e},t,n){return a(e??[],e=>{let r=e.name,i=n?r:r.toLowerCase();return(n?t:t.toLowerCase())===i?e.code.toString():null})??null}function N(e){return e.replaceAll(`'`,`''`)}function P(e,t){let n=t?.where;return n?`(${e}) AND (${n})`:e}function F({currentTerm:e,field:t,filter:n,exactMatch:r,url:i,type:a}){let o=t?.type,s=t?.name;if(o===`string`||o===`date`||o===`global-id`){let t=f.test(i??``),o=t&&j(e)?`N`:``;return P(r&&a===`search`?`${s} = ${o}'${e}'`:t?`${s} LIKE ${o}${`'${e}%'`}`:`${`LOWER(${s})`} LIKE ${o}${`'${e.toLowerCase()}%'`}`,n)}if(o===`oid`||o===`small-integer`||o===`integer`||o===`single`||o===`double`){let t=Number(e);return isNaN(t)?null:P(`${s} = ${t}`,n)}return P(`${s} = ${e}`,n)}function I(e,t){return e?` OR (${t})`:`(${t})`}function L({searchTerm:e,layer:t,searchFields:n,filter:r,exactMatch:i,query:a,type:o}){let{definitionExpression:s,url:c}=t,l=``;if(!a.fullText&&e&&n&&n.forEach(n=>{let a=t.getField(n),s=t.getFieldDomain?.(n),u=(s?.type===`coded-value`?M(s,e,i):null)||e||null;if(u!==null){let e=F({currentTerm:u,field:a,filter:r,exactMatch:i,url:c,type:o});e&&(l+=I(l,e))}}),a.fullText){let e=r?.where;return s&&e?`(${s}) AND (${e})`:s||e||``}return s&&l?`(${s}) AND (${l})`:l}function R(e,t){let n=null,{codedValues:r}=e;return r&&r.length&&r.some(e=>e.code===t&&(n=e.name,!0)),n}function z(e,t){return e[t]??e[Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase())]}function B(e){return!!e&&`getField`in e&&`queryFeatures`in e}function V(n,r,i){let a=u(n);if(!B(a))return``;let{attributes:o}=n,s=a.getFieldDomain?.(i,{feature:n});if(r)return e(r,o);if(i&&o){let e=a.getField(i),n=z(o,i);return n==null?``:s?.type===`coded-value`?R(s,n)??``:e?.type===`date`?t(new Date(n)):typeof n==`number`?n.toString():typeof n==`string`?n.trim():``}return``}function H(e,t,n,r){let i=u(e),{attributes:a}=e,o=B(i)&&i.objectIdField?a[i.objectIdField]:null;return{text:V(e,t.suggestionTemplate,r),key:o,sourceIndex:n}}function U(e,t,n,r){return e.features.map(e=>H(e,t,n,r))}function W(e){return e!=null&&e.minScale!=null&&e.maxScale!=null}function G(e,t,n,i,a,o,d,f){let p=e.clone(),m=u(e);p.layer=m,p.origin=e.origin;let h=B(m)?m.objectIdField:void 0,g=h?e.attributes[h]:null,_=V(e,n.searchTemplate,a);o!=null&&W(m)&&(m.minScale&&m.minScale<o?o=m.minScale:m.maxScale&&m.maxScale>o&&(o=m.maxScale));let v=c(p.geometry,t,o,f),y=typeof d==`number`&&v?l(r(v),t??void 0,d):v,b=e.clone();return b.layer=m,b.origin=e.origin,y!=null&&(b.geometry=s.fromExtent(y)),{extent:y,target:b,feature:p,key:g,name:_,sourceIndex:i}}function K(e,t,n,r,i,a,o,s){return e.features.map(e=>G(e,t,n,r,i,a,o,s))}export{S as createFullTextSearchInfos,h as getResults,g as getSuggestions,B as isSearchableLayer};
2
+ import{substitute as e,formatDate as t}from"../../../intl.js";import n from"../../../core/Error.js";import{clone as r}from"../../../core/lang.js";import i from"../../../core/Logger.js";import{mappedFind as a}from"../../../core/maybe.js";import{getMetersPerUnitForSR as o}from"../../../core/units.js";import s from"../../../geometry/Polygon.js";import{getExtentFromGeometry as c,scaleExtent as l}from"../../../geometry/support/geometryUtils.js";import{getPopupLayer as u}from"../../../popup/support/featureUtils.js";import d from"../../../rest/support/FullTextSearch.js";const f=/https?:\/\/services.*\.arcgis\.com/i,p=/(?:\{([^}]+)\})/g,m=()=>i.getLogger(`esri.widgets.Search.support.layerSearchUtils`);function h(e,t){let{exactMatch:r=!1,location:i,maxResults:a,spatialReference:s,source:c,sourceIndex:l,suggestResult:u,view:d}=e,{layer:f,zoomScale:p}=c,h=d?.scale,g=_(c,d),x=t?.signal;return y(f).then(()=>{let e=f.popupTemplate;return e?e.getRequiredFields(f.fieldsIndex):null}).then(e=>{let{objectIdField:t,returnZ:_}=f,y=O(c);if(!A(f,y))throw m().error(`invalid-field: displayField is invalid.`),new n(`getResults():invalid-field`,`displayField is invalid.`);let S=e?.length?e:[y],w=c.outFields||S,T=v(w);if(!w.includes(t)&&!T&&w.push(t),f.floorInfo?.floorField&&w.push(f.floorInfo.floorField),!(T||k(f,w)))throw m().error(`invalid-field: outField is invalid.`),new n(`getResults():invalid-field`,`outField is invalid.`);let D=f.createQuery(),{orderByFields:j}=c;if(j&&(D.orderByFields=j),s){D.outSpatialReference=s;let e=1/o(s);e&&(D.maxAllowableOffset=e)}let M=f.geometryType===`mesh`||f.geometryType===`multipatch`;if(D.returnZ=f.capabilities?.data?.supportsZ&&!M&&_!==!1,D.returnGeometry=!0,D.multipatchOption=M?`xyFootprint`:null,w&&(D.outFields=w),i)D.geometry=i;else if(u.key)D.objectIds=[u.key];else{let e=c.searchFields||[y];if(!k(f,e))throw m().error(`invalid-field: search field is invalid.`),new n(`getResults():invalid-field`,`search field is invalid.`);E(f)&&(D.num=a),g&&(D.geometry=g);let t=u.text;if(!t?.trim()||(C({source:c,searchTerm:t,searchFields:e,exactMatch:r,query:D,type:`search`}),!b(D)))return[]}return f.queryFeatures(D,{signal:x}).then(async e=>{let{labelPointExecute:t}=await import(`../../../geometry/operators/labelPointOperator.js`);return K(e,d,c,l,y,h,p,t)})})}function g(e,t){let{source:r,spatialReference:i,view:a,suggestTerm:o,maxSuggestions:s,sourceIndex:c,exactMatch:l}=e,{layer:u}=r,d=t?.signal,f=_(r,a);return y(u).then(()=>{if(!E(u))return[];let e=O(r),t=r.searchFields||[e],a=[];r.suggestionTemplate?r.suggestionTemplate.replaceAll(p,(e,t)=>(a.push(t),e)):a.push(e);let h=v(a);!a.includes(u.objectIdField)&&!h&&a.push(u.objectIdField);let g=A(u,e),_=h||k(u,a),y=k(u,t);if(!g)throw m().error(`invalid-field: displayField is invalid.`),new n(`getSuggestions():invalid-field`,`displayField is invalid.`);if(!_)throw m().error(`invalid-field: outField is invalid.`),new n(`getSuggestions():invalid-field`,`outField is invalid.`);if(!y)throw m().error(`invalid-field: search field is invalid.`),new n(`getSuggestions():invalid-field`,`search field is invalid.`);let x=u.createQuery(),{orderByFields:S}=r;return S&&(x.orderByFields=S),x.outSpatialReference=i,x.returnGeometry=!1,x.num=s,x.outFields=a,f&&(x.geometry=f),!o.trim()||(C({source:r,searchTerm:o,searchFields:t,exactMatch:l,query:x,type:`suggest`}),!b(x))?[]:u.queryFeatures(x,{signal:d}).then(t=>U(t,r,c,e))})}function _(e,t){let{filter:n,withinViewEnabled:r}=e,i=t?.extent;return n?.geometry??(r&&i?i:void 0)}function v(e){return e&&e.includes(`*`)}async function y(e){if(!e)throw new n(`search:missing-layer`,`A layer is required for a layer search source.`);await e.load()}function b(e){return!!(e.fullText||e.where)}function x(e,t){let n=e?.indexes;return!n||!t?.length?!1:n.filter(e=>e.indexType===`FullText`).some(e=>{let n=e.fields?.split(`,`).map(e=>e.trim().toLowerCase())||[];return t.every(e=>n.includes(e.toLowerCase()))})}function S({text:e,searchFields:t,searchType:n=`prefix`}){return(n===`simple`?[e.trim()]:e.trim().split(` `)).filter(e=>!!e.trim()).map(e=>new d({onFields:t,searchTerm:e,searchType:n}))}function C({source:e,searchTerm:t,searchFields:n,exactMatch:r,query:i,type:a}){let{layer:o,filter:s,prefix:c=``,suffix:l=``,searchMode:u}=e,d=w(u,r,o,n);d.fullTextSearchType&&t&&(i.fullText=S({text:t,searchFields:n,searchType:d.fullTextSearchType})),i.where=L({searchTerm:N(`${c}${t}${l}`),layer:o,searchFields:n,filter:s,exactMatch:d.exactMatch,query:i,type:a})}function w(e,t,n,r){let i=T(n)&&x(n,r),a=e??(t?`simple`:`starts-with`);return a===`simple`?{exactMatch:!0,fullTextSearchType:null}:e===`starts-with`?{exactMatch:!1,fullTextSearchType:null}:a===`full-text-simple`?i?{exactMatch:!1,fullTextSearchType:`simple`}:{exactMatch:!0,fullTextSearchType:null}:i?{exactMatch:!1,fullTextSearchType:`prefix`}:{exactMatch:!1,fullTextSearchType:null}}function T(e){return e?.capabilities?.query?.supportsFullTextSearch??!1}function E(e){return e?.capabilities?.query?.supportsPagination??!1}function D(e){return e?.fieldsIndex?.fields?.find(e=>e.type===`string`)?.name??``}function O(e){return e.displayField||e.layer.displayField||D(e.layer)}function k(e,t){return!e||!t?.length?!1:t.every(t=>A(e,t))}function A(e,t){return!!e.getField(t)}function j(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!0;return!1}function M({codedValues:e},t,n){return a(e??[],e=>{let r=e.name,i=n?r:r.toLowerCase();return(n?t:t.toLowerCase())===i?e.code.toString():null})??null}function N(e){return e.replaceAll(`'`,`''`)}function P(e,t){let n=t?.where;return n?`(${e}) AND (${n})`:e}function F({currentTerm:e,field:t,filter:n,exactMatch:r,url:i,type:a}){let o=t?.type,s=t?.name;if(o===`string`||o===`date`||o===`global-id`){let t=f.test(i??``),o=t&&j(e)?`N`:``;return P(r&&a===`search`?`${s} = ${o}'${e}'`:t?`${s} LIKE ${o}${`'${e}%'`}`:`${`LOWER(${s})`} LIKE ${o}${`'${e.toLowerCase()}%'`}`,n)}if(o===`oid`||o===`small-integer`||o===`integer`||o===`single`||o===`double`){let t=Number(e);return isNaN(t)?null:P(`${s} = ${t}`,n)}return P(`${s} = ${e}`,n)}function I(e,t){return e?` OR (${t})`:`(${t})`}function L({searchTerm:e,layer:t,searchFields:n,filter:r,exactMatch:i,query:a,type:o}){let{definitionExpression:s,url:c}=t,l=``;if(!a.fullText&&e&&n&&n.forEach(n=>{let a=t.getField(n),s=t.getFieldDomain?.(n),u=(s?.type===`coded-value`?M(s,e,i):null)||e||null;if(u!==null){let e=F({currentTerm:u,field:a,filter:r,exactMatch:i,url:c,type:o});e&&(l+=I(l,e))}}),a.fullText){let e=r?.where;return s&&e?`(${s}) AND (${e})`:s||e||``}return s&&l?`(${s}) AND (${l})`:l}function R(e,t){let n=null,{codedValues:r}=e;return r&&r.length&&r.some(e=>e.code===t&&(n=e.name,!0)),n}function z(e,t){return e[t]??e[Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase())]}function B(e){return!!e&&`getField`in e&&`queryFeatures`in e}function V(n,r,i){let a=u(n);if(!B(a))return``;let{attributes:o}=n,s=a.getFieldDomain?.(i,{feature:n});if(r)return e(r,o);if(i&&o){let e=a.getField(i),n=z(o,i);return n==null?``:s?.type===`coded-value`?R(s,n)??``:e?.type===`date`?t(new Date(n)):typeof n==`number`?n.toString():typeof n==`string`?n.trim():``}return``}function H(e,t,n,r){let i=u(e),{attributes:a}=e,o=B(i)&&i.objectIdField?a[i.objectIdField]:null;return{text:V(e,t.suggestionTemplate,r),key:o,sourceIndex:n}}function U(e,t,n,r){return e.features.map(e=>H(e,t,n,r))}function W(e){return e!=null&&e.minScale!=null&&e.maxScale!=null}function G(e,t,n,i,a,o,d,f){let p=e.clone(),m=u(e);p.layer=m,p.origin=e.origin;let h=B(m)?m.objectIdField:void 0,g=h?e.attributes[h]:null,_=V(e,n.searchTemplate,a);o!=null&&W(m)&&(m.minScale&&m.minScale<o?o=m.minScale:m.maxScale&&m.maxScale>o&&(o=m.maxScale));let v=c(p.geometry,t,o,f),y=typeof d==`number`&&v?l(r(v),t??void 0,d):v,b=e.clone();return b.layer=m,b.origin=e.origin,y!=null&&(b.geometry=s.fromExtent(y)),{extent:y,target:b,feature:p,key:g,name:_,sourceIndex:i}}function K(e,t,n,r,i,a,o,s){return e.features.map(e=>G(e,t,n,r,i,a,o,s))}export{S as createFullTextSearchInfos,h as getResults,g as getSuggestions,B as isSearchableLayer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../Graphic.js";import{isSome as n}from"../../core/arrayUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import{handlesGroup as o,makeHandle as s,drainHandles as c,destroyHandle as l}from"../../core/handleUtils.js";import has from"../../core/has.js";import u from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as f,removeMaybe as p}from"../../core/maybe.js";import{createAbortError as m,ignoreAbortErrors as h,whenOrAbort as g}from"../../core/promiseUtils.js";import{watch as _,syncAndInitial as v,on as ee,when as te,sync as ne,whenOnce as y}from"../../core/reactiveUtils.js";import{property as b,subclass as re}from"../../core/accessorSupport/decorators.js";import{trackAccess as x}from"../../core/accessorSupport/tracking.js";import{SimpleObservable as ie}from"../../core/accessorSupport/tracking/SimpleObservable.js";import{UpdatingHandles as S}from"../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ae}from"../../geometry/ellipsoidUtils.js";import{canProjectWithoutEngine as oe,isLoaded as se,load as ce,project as le}from"../../geometry/projectionUtils.js";import{geometryToCoordinates as C}from"../../geometry/support/coordsUtils.js";import{equals as ue}from"../../geometry/support/spatialReferenceUtils.js";import de from"../../layers/GraphicsLayer.js";import{isIntegratedMeshLayer as fe}from"../../layers/support/layerUtils.js";import{getEffectiveElevationInfo as pe}from"../../support/elevationInfoUtils.js";import me from"../../symbols/FillSymbol3DLayer.js";import he from"../../symbols/MeshSymbol3D.js";import ge from"../../symbols/SimpleFillSymbol.js";import _e from"../../symbols/SimpleLineSymbol.js";import w from"../../symbols/SimpleMarkerSymbol.js";import T from"../../symbols/TextSymbol.js";import{symbolTypes as E}from"../../symbols/support/typeUtils.js";import{isSupportedObjectResultMessage as D}from"../../views/3d/interactive/editingTools/isSupportedObjectUtils.js";import{isSupportedObject as ve}from"../../views/3d/interactive/editingTools/move/isSupportedObject.js";import{isSupportedObject as ye}from"../../views/3d/interactive/editingTools/reshape/isSupportedObject.js";import{isSupportedGraphic as be}from"../../views/3d/interactive/editingTools/transform/isSupportedGraphic.js";import{addUniqueLayer as O}from"../../views/draw/support/layerUtils.js";import{ViewEventPriorities as k}from"../../views/input/InputManager.js";import{sketchKeys as A}from"../../views/interactive/keybindings.js";import{bindViewToolOptions as xe}from"../../views/interactive/options/bindViewToolOptions.js";import j from"../../views/interactive/options/InteractiveToolOptions.js";import M from"../../views/interactive/sketch/SketchLabelOptions.js";import N from"../../views/interactive/sketch/SketchOptions.js";import Se from"../../views/interactive/sketch/SketchTooltipOptions.js";import Ce from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as P}from"../../views/interactive/snapping/SnappingManager.js";import{acquireForViewOptions as we}from"../../views/interactive/snapping/SnappingManagerPool.js";import F from"../../views/interactive/snapping/SnappingOptions.js";import{setupSnappingToggleHandles as I}from"../../views/interactive/snapping/snappingUtils.js";import{GeometryWorkerHandle as Te}from"../../views/support/GeometryWorkerHandle.js";import{defaultHighlightName as Ee}from"../../views/support/HighlightDefaults.js";import{findFirstGraphicHit as De}from"../../views/support/hitTestSelectUtils.js";import{createScreenPointFromEvent as L}from"../../views/support/screenUtils.js";import Oe from"./adapters/layer/GraphicsLayerAdapter.js";import ke from"./adapters/layer/MapNotesLayerAdapter.js";import Ae from"./adapters/layer/SketchLayerAdapter.js";import{CreateOperationHandle as je,DrawToolOperationHandle as Me,UpdateOperationHandle as R}from"./support/OperationHandle.js";import{PluginManager as Ne}from"./support/PluginManager.js";import{SettingsManager as Pe}from"./support/SettingsManager.js";import{getLegacyTool as z,isCompletelyDegenerate as Fe,graphicsHaveTooFewVerticesForBox as B,getModeFromCreateOptions as Ie,getDrawToolGeometryTypeFromCreateTool as Le}from"./support/sketchUtils.js";const V={defaultZ:0},H={reshapeOptions:{edgeOperation:`split`,shapeOperation:`move`,vertexOperation:`move`,enableCreateCurveFromStraightEdge:!0},enableMoveAllGraphics:!0,enableRotation:!0,enableScaling:!0,multipleSelectionEnabled:!0,preserveAspectRatio:!1,toggleToolOnClick:!0,enableZ:!0,highlightOptions:{enabled:!0,name:Ee},tool:`transform`},U=Symbol(),W=Symbol();let G=class extends a{constructor(e){super(e),this._defaultSnappingManager=null,this._operationContext=null,this._internalGraphicsLayer=new de({listMode:`hide`,internal:!0,title:`SVM Internal`}),this._pluginManager=new Ne({sketchViewModel:this}),this.settingsManager=new Pe({availablePlugins:()=>this.pluginManager.visiblePluginsFlat}),this._operationHandle=null,this._updatingHandles=new S,this._toolTransitionHandles=new S,this._drawToolSimplifyAbortController=null,this._geometryWorkerHandle=new Te,this._viewHandlesKey=`viewHandles`,this.activeFillSymbol=null,this.activeLineSymbol=null,this.activeVertexSymbol=null,this.allowDeleteKey=!0,this.activeUpdateOptions=null,this.layer=null,this.pointSymbol=new w({style:`circle`,size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.polygonSymbol=new ge({color:[150,150,150,.2],outline:{color:[50,50,50],width:2}}),this.polylineSymbol=new _e({color:[130,130,130,1],width:2}),this.meshSymbol=new he({symbolLayers:new r([new me])}),this.updateGraphics=new r,this.updateOnGraphicClick=!0,this.useViewOptions=!1,this.cancelUpdateOnClickAway=!0,this.creationMode=`single`,this.vertexSymbol=new w({style:`circle`,size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.sketchOptions=new N,this.useLegacyCreateTools=!0,this._moduleLoaderAbortController=null,this._viewReadyAbortController=null,this._sketchContinuationFlag=!1,this._onLayerAdapterChange=async()=>{let{_layerAdapter:e}=this;if(this.removeHandles(W),!e)return;let t=[e.onGraphicsChange(e=>this._onLayerGraphicsChangeCallback(e)),_(()=>e.elevationInfo,e=>{e!==this._internalGraphicsLayer.elevationInfo&&(this.cancel(),this._internalGraphicsLayer&&(this._internalGraphicsLayer.elevationInfo=e))},v)].filter(n);this.addHandles(t,W)},this._originalPopupEnabled=null,this.defaultCreateOptions=V,this.defaultUpdateOptions=H,this.snappingOptions=e?.snappingManager?.options??e?.snappingOptions??new F,this.textSymbol=new T({text:`text`})}initialize(){this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe()),this.addHandles([ee(()=>this.view?.map?.layers,`change`,e=>{this.layer&&e.removed.includes(this.layer)&&this.cancel()}),_(()=>this._layerAdapter,()=>this._onLayerAdapterChange(),v),_(()=>this.view,e=>{this._defaultSnappingManager=d(this._defaultSnappingManager),e&&(this.snappingManager||(this._defaultSnappingManager=new P({view:e,options:this.snappingOptions})),e.type===`2d`?(import(`../../views/2d/interactive/editingTools.js`),this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe())):e.type===`3d`&&(import(`../../views/3d/interactive/editingTools.js`),import(`../../views/3d/layers/GraphicsLayerView3D.js`)))},v),_(()=>this.view?.spatialReference,(e,t)=>{e&&t&&!e.equals(t)&&this.cancel()})]),I(this,void 0,()=>this._operationSnappingManager?.options??this.snappingOptions)}destroy(){this.cancel(),this._removeDefaultLayer(),this._defaultSnappingManager=d(this._defaultSnappingManager),this._destroyOperationContext(),this._set(`snappingManager`,null),this._set(`view`,null),this._updatingHandles.destroy(),this._toolTransitionHandles.destroy(),this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),this._geometryWorkerHandle.destroy(),this._pluginManager?.destroy(),this.emit(`destroy`)}get _operationSnappingManager(){return this._operationContext?.snappingManager??this.snappingManager}get _operationToolOptions(){return this._operationContext?.toolOptions??this.sketchOptions}get _layerAdapter(){let{layer:e}=this;switch(e?.type){case`graphics`:return new Oe(e);case`map-notes`:return new ke(e);case`sketch`:return new Ae(e);case void 0:default:return null}}get activeTool(){return this._operationHandle?.tool??null}get geometrySimplificationInProgress(){return!!this._drawToolSimplifyAbortController}get activeCreateToolDrawMode(){let e=this._operationHandle;if(e?.type===`create`&&e.activeComponent&&`mode`in e.activeComponent)return e.activeComponent.mode;if(e?.activeComponent?.type===`draw-2.0`){let t=e.activeComponent.pluginStack.map(e=>e.configuration).filter(n).toArray();if(t.length>0)return this._pluginManager?.getDrawingModeEquivalentToPluginStack(t)}return null}get activeTooltip(){let{activeComponent:e,destroyed:t}=this,n=!t&&e&&`tooltip`in e?e.tooltip:null;return n?.visible?n:null}get activeComponent(){return this._operationHandle?.activeComponent??null}get createGraphic(){return this.activeComponent!=null&&(this.activeComponent.type===`draw-3d`||this.activeComponent.type===`draw-2d`)?this.activeComponent.graphic:this._get(`createGraphic`)}get defaultCreateOptions(){return this._get(`defaultCreateOptions`)}set defaultCreateOptions(e){this._set(`defaultCreateOptions`,{...V,...e})}get defaultUpdateOptions(){return this._get(`defaultUpdateOptions`)}set defaultUpdateOptions(e){this._set(`defaultUpdateOptions`,{...H,...e,reshapeOptions:{...H.reshapeOptions,...e?.reshapeOptions},highlightOptions:{...H.highlightOptions,...e?.highlightOptions}})}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get textSymbol(){return this._get(`textSymbol`)}set textSymbol(e){this._set(`textSymbol`,e)}get snappingOptions(){return this.snappingManager?.options??this._get(`snappingOptions`)}set snappingOptions(e){this._defaultSnappingManager!=null&&(this._defaultSnappingManager.options=e),this._set(`snappingOptions`,e)}get snappingManager(){return this._isOverridden(`snappingManager`)?this._get(`snappingManager`):this._defaultSnappingManager}set snappingManager(e){if(e)this._isOverridden(`snappingManager`)||(this._defaultSnappingManager=d(this._defaultSnappingManager)),this._override(`snappingManager`,e);else{let{view:e}=this;!this._defaultSnappingManager&&e&&(this._defaultSnappingManager=new P({options:this.snappingOptions,view:e})),this._clearOverride(`snappingManager`)}}get state(){let e=!!(this.view?.ready&&this.layer),t=this._operationHandle;return e&&t?`active`:e?`ready`:`disabled`}get toolTransitionInProgress(){return this._toolTransitionHandles.updating||!!this.drawTool?.lifecycleManager.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get updating(){return this.toolTransitionInProgress||this.activeComponent&&`updating`in this.activeComponent&&this.activeComponent.updating||!!(this._updatingHandles.updating||this._drawToolSimplifyAbortController||this.snappingManager?.updating||this.drawTool?.updating)}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}get view(){return this._get(`view`)}set view(e){let t=this._get(`view`);if(t){let{container:e,map:n}=t;e&&this._clearCursor(),n?.remove(this._internalGraphicsLayer),this.removeHandles(this._viewHandlesKey),this.cancel()}let n=`view-ready`;this.removeHandles(n),e&&this.addHandles(te(()=>e.ready,t=>{this.removeHandles(this._viewHandlesKey),t&&this.addHandles(this._generateViewHandles(e),this._viewHandlesKey)},v),n),this._set(`view`,e),this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe())}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||this.view?.type!==`2d`}get pluginManager(){return this._pluginManager}get drawTool(){return this.activeComponent?.type===`draw-2.0`?this.activeComponent:null}get activePluginConfigurations(){return this.drawTool?.pluginStack.toArray().map(e=>e.configuration).filter(n)??[]}get rootPlugins(){return this._pluginManager?.availablePlugins}set rootPlugins(e){this._overrideIfSome(`rootPlugins`,e)}get effectiveAvailablePlugins(){if(this.isUsingLegacyCreateTools)return null;let e=this.view?.type??`2d`,{firstPluginWithSwappableLeaf:t}=this;return t?t.availableDownstreamPlugins.filter(t=>!t.excludedViews?.includes(e)):this.rootPlugins?.filter(t=>!t.excludedViews?.includes(e)).filter(n)??[]}get firstPluginWithSwappableLeaf(){let e=this.view?.type??`2d`;return this.drawTool?.pluginStack.toArray().map(e=>e.configuration).findLast(t=>t!=null&&!t.hidden&&t.availableDownstreamPlugins&&t.availableDownstreamPlugins.filter(t=>!t.excludedViews?.includes(e))?.length>1)}get multiplePluginsActive(){return this.drawTool?this.drawTool.pluginStack.length>1:!1}replaceLeaf(e){this.drawTool?.replaceLeaf(e)}addGraphic(e){this._layerAdapter?.add(e)}addGraphics(e){this._layerAdapter?.addMany(e)}hasGraphic(e){return!!this._layerAdapter?.has(e)}removeGraphic(e){this._layerAdapter?.remove(e)}removeGraphics(e){this._layerAdapter?.removeMany(e)}removeAllGraphics(){this._layerAdapter?.removeAll()}cancel(){this._moduleLoaderAbortController=f(this._moduleLoaderAbortController),this._viewReadyAbortController=f(this._viewReadyAbortController),this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),this._sketchContinuationFlag=!0,this._operationHandle?.cancel()}complete(){this._operationHandle?.complete()}delete(){let{state:e,updateGraphics:t}=this;if(e===`active`&&t.length){let{activeTool:e}=this,n=t.toArray();this.removeGraphics(n),this.cancel(),this._emitDeleteEvent({graphics:n,tool:e})}}duplicate(){if(this.state===`active`&&this.updateGraphics.length){let e=this.updateGraphics.map(e=>e.clone()).toArray();return this.addGraphics(e),this.emit(`duplicate`,{graphics:e,type:`duplicate`}),e}return[]}async create(e,t){return this._toolTransitionHandles.addPromise(this._create(e,t))}async _create(e,t){this.cancel(),await this._updatingHandles.addPromise(this._waitViewReady());let{view:n,layer:r}=this;if(!n||this.state===`disabled`)throw r||this._logMissingLayer(),m();if(n.activeTool!=null&&(n.activeTool=null),!e){this._logError(`sketch:missing-parameter`,`Missing parameter 'tool'.`);return}O(n,this._internalGraphicsLayer);let i=this._createOperationContext(n),a;try{a=await this._updatingHandles.addPromise(this._setupCreateOperation(e,t))}catch(e){throw this._destroyOperationContext(i),e}if(a==null||this.destroyed||i!==this._operationContext){let e=i===this._operationContext;a?.onEnd(),d(a),this._destroyOperationContext(i),e&&n.map?.remove(this._internalGraphicsLayer);return}let o=z(e);a.on(`complete`,()=>{if(a===this._operationHandle){let n=this.createGraphic,r=this._operationHandle.cancelled;if(this._operationHandle.destroy(),this._operationHandle=null,this._destroyOperationContext(),this._set(`createGraphic`,null),this.view?.map?.remove(this._internalGraphicsLayer),!a.cancelled&&n!=null&&this.addGraphic(n),this._sketchContinuationFlag=!1,this.emit(`create`,{graphic:n,state:r?`cancel`:`complete`,tool:o??`point`,toolEventInfo:null,type:`create`}),r||this._sketchContinuationFlag)return;let{creationMode:i}=this;if(i===`continuous`){if(t?.geometryToPlace)return;this._updatingHandles.consumePromise(h(this.create(e,t)))}else i===`update`&&n&&this._updatingHandles.consumePromise(h(this.update([n])))}}),this._operationHandle=a,n.ready&&n.focus()}async place(e,t){return await e.load(),this.create(`mesh`,{mode:`click`,hasZ:e.hasZ,geometryToPlace:e,...t})}async update(e,t){return this._toolTransitionHandles.addPromise(this._update(e,t))}async _update(e,t){this.cancel(),await this._updatingHandles.addPromise(this._waitViewReady());let{layer:n,view:r,state:i}=this;if(!r||i===`disabled`)throw n||this._logMissingLayer(),m();r.activeTool!=null&&(r.activeTool=null);let a=Array.isArray(e)?e:[e];if(e==null||!a?.length){this._logError(`sketch:missing-parameter`,`Missing parameter 'graphics'.`);return}if(a.some(e=>this.hasGraphic(e)?e.geometry==null&&(this._logError(`sketch:invalid-parameter`,`Parameter 'graphics' contains one or more graphics with an unsupported geometry.`),!0):(this._logError(`sketch:invalid-parameter`,`Parameter 'graphics' contains one or more graphics missing from the supplied GraphicsLayer.`),!0)))return;let o=this._createOperationContext(r),s;try{s=await this._updatingHandles.addPromise(this._setupUpdateOperation(a,t))}catch(e){throw this._destroyOperationContext(o),e}this.destroyed||s==null||$(s)||o!==this._operationContext?(s&&!$(s)&&(s.onEnd(),s.destroy()),this._destroyOperationContext(o)):(O(r,this._internalGraphicsLayer),this._setUpdateOperationHandle(s,t),this.emit(`update`,{graphics:a,state:`start`,aborted:!1,tool:s.tool,toolEventInfo:null,type:`update`}))}async _updateSpatialReference(e){let t=this.view;if(!t)this._logMissingView();else{e=Array.isArray(e)?e:[e];for(let n of e)n.geometry!=null&&n.geometry.type!==`mesh`&&!ue(n.geometry.spatialReference,t.spatialReference)&&(!oe(n.geometry.spatialReference,t.spatialReference)&&!se()&&await ce(),n.geometry=le(n.geometry,t.spatialReference))}}undo(){this.canUndo()&&this._operationHandle?.undo()}redo(){this.canRedo()&&this._operationHandle?.redo()}canUndo(){return!!this._operationHandle?.canUndo()}canRedo(){return!!this._operationHandle?.canRedo()}toggleUpdateTool(){this._updatingHandles.consumePromise(this._operationHandle?.toggleTool())}_createOperationContext(e){this._destroyOperationContext();let t=this.useViewOptions?e.options:null,n=t?we(e):null,r=t?new j:this.sketchOptions,i;if(t){let{values:t}=r;i=o([xe(r,()=>e.options,()=>this.sketchOptions),_(()=>t.directionMode,e=>{this.sketchOptions.values.directionMode=e},ne)])}return this._operationContext={snappingManager:n?.snappingManager??this.snappingManager,toolOptions:r,...o([n,i])}}_destroyOperationContext(e=this._operationContext){e===this._operationContext?this._operationContext=p(this._operationContext):p(e)}async _getFirstHit(e){let t=this.view;if(!t)return this._logMissingView(),null;if(t.type===`2d`){let n=[];t.map.allLayers.forEach(e=>{(e.type===`vector-tile`||e.type===`imagery`)&&n.push(e)});let r=await t.hitTest(e,{exclude:n});return De(r.results)}let n=[t.map.ground];t.map.allLayers.forEach(e=>{fe(e)&&(!has(`enable-feature:im-as-ground`)||e.isUsedAsGroundLayer)&&n.push(e)});let r=await t.hitTest(e,{exclude:n});if(r.results.length>0){let e=r.results[0];if(e!=null&&e.type===`graphic`&&e.graphic&&(!r.ground.mapPoint||t.map.ground.opacity<1||r.ground.distance-(e.distance??0)>-Math.min(3*r.ground.distance,t.viewingMode===`global`?ae(t.renderCoordsHelper.spatialReference).radius/t.renderCoordsHelper.unitInMeters:1/0)))return e}return null}_generateViewHandles(e){return[e.on(`immediate-click`,async e=>{let t=this.state===`active`&&this._operationHandle?.type===`create`;this.state!==`disabled`&&!t&&this.updateOnGraphicClick&&await this._toolTransitionHandles.addPromise(this._handleImmediateClick(e))},k.WIDGET)]}async _handleImmediateClick(e){let t=await e.defer(()=>this._getFirstHit(L(e))),n=null;if(t!=null){let r=t.graphic;this.updateGraphics.includes(r)||this.hasGraphic(r)?(e.stopPropagation(),n=r):this.view?.type===`2d`&&!this._isComponentGraphic(r)&&this.state===`active`&&this.cancel()}else this.state===`active`&&this.cancelUpdateOnClickAway&&this.cancel();n!=null&&!this.updateGraphics.includes(n)&&await this.update([n],{...this.defaultUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions}})}async _setupCreateOperation(e,t){let n=this.view;if(!n)return this._logMissingView(),null;let r={hasZ:n.type===`3d`,...this.defaultCreateOptions,...t},i=typeof e==`string`?this.pluginManager?.getPluginsEquivalentToCreateTool(e,r.mode):e,a=z(e);if(i&&!this.isUsingLegacyCreateTools){let e=await this._setupDrawTool(i,r,a??`polyline`);if(e)return this._setupDrawToolOperationHandle(e,a??`point`)}if(!a)return null;let o=await this._setupDrawGraphicTool(a,n,r);return o==null?null:(n.tools.add(o),n.activeTool=o,this._setupCreateOperationHandle(o,a))}async _setupDrawGraphicTool(e,t,n){if(e===`multipoint`&&t.type===`3d`)return this._logError(`sketch:create`,`Multipoint geometries are not supported in SceneView.`),null;if(!t)return this._logMissingView(),null;let{cursor:r,defaultZ:i,hasZ:a,geometryToPlace:o,graphicProperties:s,mode:c,preserveAspectRatio:l}=n,u=Ie(c,e),d=Le(e),f=n?.optionsPerTool?.has(e)?n.optionsPerTool.get(e):{},p=f?.preserveAspectRatio??l??e!==`rectangle`,m={centered:e!==`rectangle`&&!(e===`circle`&&!p),cursor:r,defaultZ:i,forceUniformSize:p,graphicProperties:{...s,attributes:{...s?.attributes}},geometryToPlace:o,geometryType:d,mode:u,graphicSymbol:n.graphicSymbol??this._getGraphicSymbolFromTool(e),hasZ:a,snappingManager:this._operationSnappingManager,snapToScene:!1,view:t,...f};return t.type===`2d`?this._makeDrawGraphicTool2D(m):this._makeDrawGraphicTool3D(m)}async _makeDrawGraphicTool2D(e){let t=await this._requireModule(import(`../../views/2d/interactive/editingTools.js`));return $(t)||this.destroyed?null:new t.module.DrawGraphicTool2D({...e,activeVertexSymbol:this.activeVertexSymbol,regularVerticesSymbol:this.vertexSymbol,activeLineSymbol:this.activeLineSymbol,activeFillSymbol:ze(e.geometryType)?this.activeFillSymbol:null,toolOptions:this._operationToolOptions})}async _makeDrawGraphicTool3D(e){let t=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));return $(t)||this.destroyed?null:new t.module.DrawGraphicTool3D({...e,elevationInfo:this._layerAdapter?.elevationInfo,snapToScene:!0,toolOptions:this._operationToolOptions})}_setupCreateOperationHandle(e,t){let n=this.view;if(!n)return this._logMissingView(),null;let r=null,i=e.forceUniformSize,a=e.centered,o=new ie,l=[s(()=>o.destroy()),n.on(`key-down`,t=>{if(t.key===A.pan)t.stopPropagation(),t.repeat||(e.enabled=!1);else if(t.key===A.complete)t.stopPropagation(),e.completeCreateOperation();else if(t.key===A.vertexAdd&&!t.repeat){let n=e.drawOperation.geometryType;(n===`polyline`||n===`polygon`||n===`multipoint`)&&(t.stopPropagation(),e.drawOperation.commitStagedVertex())}else t.key===A.undo?(t.stopPropagation(),u.undo()):t.key===A.redo?(t.stopPropagation(),u.redo()):t.key===A.constraint&&(e.geometryType===`rectangle`||e.geometryType===`circle`)&&!t.repeat?(e.forceUniformSize=!i,t.stopPropagation()):t.key===A.center&&(t.repeat||(e.centered=!a,t.stopPropagation()))},k.WIDGET),n.on(`key-up`,t=>{t.key===A.pan?e.enabled=!0:t.key===A.constraint&&(e.geometryType===`rectangle`||e.geometryType===`circle`)?(e.forceUniformSize=i,t.stopPropagation()):t.key===A.center&&(e.centered=a,t.stopPropagation())},k.WIDGET),e.on(`vertex-update`,()=>{o.notify()}),e.on(`vertex-add`,t=>{switch(o.notify(),r=r==null?`start`:`active`,t.operation){case`apply`:this.emit(`create`,{graphic:e.graphic,state:r,tool:this.activeTool,toolEventInfo:t,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[e.graphic],tool:e.geometryType});break;case`redo`:this._emitRedoEvent({graphics:[e.graphic],tool:e.geometryType})}}),e.on(`cursor-update`,t=>{e.drawOperation.numCommittedVertices>0&&this.emit(`create`,{graphic:e.graphic,state:`active`,tool:this.activeTool,toolEventInfo:{coordinates:t.vertices[0].coordinates,type:`cursor-update`},type:`create`})}),e.on(`vertex-remove`,t=>{switch(o.notify(),t.operation){case`apply`:this.emit(`create`,{graphic:e.graphic,state:`active`,tool:this.activeTool,toolEventInfo:t,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[e.graphic],tool:e.geometryType});break;case`redo`:this._emitRedoEvent({graphics:[e.graphic],tool:e.geometryType})}}),e.on(`complete`,e=>{this._set(`createGraphic`,e.graphic),r=`complete`,e.aborted?u&&u.cancel():u&&u.complete()}),_(()=>this._getGraphicSymbolFromTool(t),t=>{e.graphicSymbol=t})],u=new je({activeComponent:e,type:`create`,onEnd:()=>{c(l),n.tools?.remove(e)},undo:()=>{e.canUndo&&e.undo()},redo:()=>{e.canRedo&&e.redo()},canUndo:()=>(x(o),e.canUndo),canRedo:()=>(x(o),e.canRedo)});return u}_setupDrawToolOperationHandle(e,t){let r=this.view;if(!r)return this._logMissingView(),null;let i=null,a=[r.on(`key-down`,t=>{t.key===A.pan&&(t.stopPropagation(),t.repeat||(e.editable=!1))},k.WIDGET),r.on(`key-up`,t=>{t.key===A.pan&&(e.editable=!0)},k.WIDGET),e.on(`before-vertex-add`,t=>{let n=e.mostUpstreamPlugin?.configuration;if(n&&`legacyCreateTool`in n&&(n?.legacyCreateTool===`point`||n.legacyCreateTool===`text`)){let e=t.detail.originalEvent;e&&`key`in e&&e.key===A.vertexAdd&&t.preventDefault()}}),e.on(`before-complete`,t=>{let n=e.getGeometryIfCompleted();(!n||Fe(n))&&t.preventDefault()}),e.on([`vertex-add`,`vertex-remove`],r=>{switch(this.createGraphic&&(this.createGraphic.geometry=e.getGeometryIfCompleted()),i=i==null&&r.type!==`vertex-remove`?`start`:`active`,r.operation){case`apply`:this.emit(`create`,{graphic:this.createGraphic,state:i,tool:this.activeTool,toolEventInfo:r,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[this.createGraphic].filter(n),tool:t});break;case`redo`:this._emitRedoEvent({graphics:[this.createGraphic].filter(n),tool:t})}}),e.on(`cursor-update`,t=>{this.createGraphic&&(this.createGraphic.geometry=e.unprocessedGeometry),(t.vertices[0]?.vertexIndex>0||t.vertices[0]?.componentIndex>0)&&this.emit(`create`,{graphic:this.createGraphic,state:`active`,tool:this.activeTool,toolEventInfo:{coordinates:t.vertices[0].coordinates,type:`cursor-update`},type:`create`})}),e.on(`complete`,async({geometry:t,isSimple:n})=>{let r=this.createGraphic,i=!!t&&t.type!==`mesh`&&t.type!==`extent`&&!n;if(r&&(r.geometry=n?t:e.unprocessedGeometry??t),!i||!r)o.complete();else{this._internalGraphicsLayer.add(this.createGraphic);let e=new AbortController;this._drawToolSimplifyAbortController?.abort(),this._drawToolSimplifyAbortController=e,await this._updatingHandles.addPromise(h(this._finalizeDrawToolCompletion({abortController:e,geometry:t,graphic:r,handle:o})))}})],o=new Me({activeComponent:e,type:`create`,onEnd:()=>{c(a),r.tools.remove(e)},undo:()=>e.undo(),redo:()=>e.redo(),canUndo:()=>e.canUndo,canRedo:()=>e.canRedo});return a.push(e.on(`cancel`,()=>{this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),o.cancel()})),o}async _finalizeDrawToolCompletion({abortController:e,geometry:t,graphic:n,handle:r}){let i=this.view?.acquireCursor(`progress`,`high`);i&&this.addHandles(i);let a=()=>e.signal.aborted?(n&&(this._layerAdapter?.remove(n),this._internalGraphicsLayer?.remove(n)),this._set(`createGraphic`,null),!0):!1;try{let i=await this._geometryWorkerHandle.simplify(t,e.signal);if(a())return;n.geometry=i??t,this._internalGraphicsLayer?.remove(n),r.complete()}finally{i?.remove(),this._drawToolSimplifyAbortController===e&&(this._drawToolSimplifyAbortController=null)}}_getGraphicSymbolFromTool(e){switch(e){case`point`:case`multipoint`:return this.pointSymbol;case`polyline`:case`freehandPolyline`:return this.polylineSymbol;case`circle`:case`rectangle`:case`polygon`:case`freehandPolygon`:return this.polygonSymbol;case`mesh`:return this.meshSymbol;case`text`:return this.textSymbol}}async _setupUpdateOperation(e,t){let{view:n}=this;if(!n)return this._logMissingView(),null;let r={...this.defaultUpdateOptions,...t,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...t?.reshapeOptions},highlightOptions:{...this.defaultUpdateOptions.highlightOptions,...t?.highlightOptions}};this.activeUpdateOptions=r;let i=r.tool??H.tool;if(this.removeGraphics(e),this.addGraphics(e),n.type===`3d`){if(e.length===0)return null;switch(i){case`move`:return this._setupMove3DOperation(e,r,n,i);case`reshape`:return e.length>1?(this._logError(`sketch:reshape-multiple`,`Reshape operation does not support multiple graphics.`),null):this._setupReshape3DOperation(e[0],r,n);case`transform`:return this._setupGraphicTransform3DOperation(e,r,n)}}switch(i){case`move`:return this._setupMove2DOperation(e,r,n);case`reshape`:return e.length>1?(this._logError(`sketch:reshape-multiple`,`Reshape operation does not support multiple graphics.`),null):this._setupTransformOrReshape2DOperation(e,i,r,n);case`transform`:return B(e)&&(i=`reshape`),this._setupTransformOrReshape2DOperation(e,i,r,n)}}async _setupMove3DOperation(e,t,n,r,i=!1){let a=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(a))return a;let{ManipulatedObject3DGraphic:o,MoveTool3D:s}=a.module,l=new Map,u=()=>{l.forEach(e=>e.destroy()),l.clear()};for(let t of e){let e=new o({view:n,graphic:t}),r=ve(e);if(r!==0)return u(),this._logError(`sketch:move`,`Move operation not supported for provided graphic(s) (${D(r)}).`),null;l.set(t,e)}let d=new s({view:n,enableZ:t.enableZ,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(d),d.objects.addMany(Array.from(l.values())),i||this.updateGraphics.addMany(e);let f=[],p=new R({activeComponent:d,tool:r,type:`update`,onEnd:()=>{c(f),Q(n,d),u()},undo:()=>{X(this.view,d),q(p,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r})},redo:()=>{J(p,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r})},addToSelection:async e=>{this.updateGraphics.push(e);let t=new o({view:n,graphic:e});l.set(e,t),d.objects.push(t),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);if(p.history.undo.forEach(e=>e.updates.splice(t,1)),p.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),this.updateGraphics.length===0){p.complete();return}let n=l.get(e);n&&(d.objects.remove(n),n.destroy(),l.delete(e))},toggleTool:async()=>{if(this.updateGraphics.length!==1||t.toggleToolOnClick===!1||r!==`transform`)return;let e=this.updateGraphics.at(0),i=await this._updatingHandles.addPromise(this._setupReshape3DOperation(e,t,n,!0));i&&!$(i)&&(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(i,t))}});return f.push(...this._getHandlesForComponent(p,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(p,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(p,e)},k.WIDGET)),p}_setupGraphicTransform3DOperation(e,t,n,r=!1){if(e.length===1&&be(e[0])===0){let i=e[0],a=i.geometry;if(a!=null&&(a.type===`point`||a.type===`mesh`))return this._setupPointTransform3DOperation(i,t,n);if(a!=null&&(a.type===`polygon`||a.type===`polyline`))return this._setupPolyTransform3DOperation(i,t,n,r)}return this._setupMove3DOperation(e,t,n,`transform`,r)}async _setupPointTransform3DOperation(e,t,n){let r=`transform`,{enableRotation:i,enableScaling:a,enableZ:o}=t,s=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(s))return s;let{TransformTool3D:l,ManipulatedObject3DGraphic:u}=s.module,d=new u({graphic:e,view:n}),f=new l({object:d,view:n,enableRotation:i,enableScaling:a,enableZ:o,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(f),this.updateGraphics.add(e);let p=[],m=new R({activeComponent:f,tool:r,type:`update`,onEnd:()=>{c(p),Q(n,f),d.destroy()},undo:()=>{X(this.view,f),q(m,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r})},redo:()=>{J(m,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r})},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(m,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),m.complete()},toggleTool:async()=>{}});return p.push(...this._getHandlesForComponent(m,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(m,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(m,e)},k.WIDGET)),m}async _setupPolyTransform3DOperation(e,t,n,r=!1){let i=`transform`,{enableRotation:a,enableScaling:o,enableZ:s,preserveAspectRatio:l}=t,u=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(u))return u;let{ManipulatedObject3DGraphic:d,ExtentTransformTool:f}=u.module,p=this.view?.inputManager?.isModifierKeyDown(A.constraint),m=new d({view:n,graphic:e}),h=new f({object:m,view:n,enableRotation:a,enableScaling:o,enableZ:s,preserveAspectRatio:!!l!=!!p,toolOptions:this._operationToolOptions});n.tools.add(h),r||this.updateGraphics.add(e);let g=[],_=new R({activeComponent:h,tool:i,type:`update`,onEnd:()=>{c(g),Q(n,h),m.destroy()},canUndo:()=>!h.destroyed&&h.canUndo,undo:()=>{h.destroyed||(h.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},canRedo:()=>!h.destroyed&&h.canRedo,redo:()=>{h.destroyed||(h.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(_,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),_.complete()},toggleTool:async()=>{if(this.updateGraphics.length!==1||t.toggleToolOnClick===!1)return;let r=await this._updatingHandles.addPromise(this._setupReshape3DOperation(e,t,n,!0));r&&!$(r)&&(_.onEnd(),_.destroy(),this._setUpdateOperationHandle(r,t))}});return g.push(...this._getHandlesForComponent(_,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(_,e,t),k.WIDGET),n.on(`key-down`,e=>this._getCommonUpdateOperationKeyDownHandlers(_,e),k.WIDGET),n.on(`key-down`,e=>{e.key===A.constraint&&!e.repeat&&(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())},k.WIDGET),n.on(`key-up`,e=>{e.key===A.constraint&&(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())},k.WIDGET)),_}async _setupMove2DOperation(e,t,n){let r=`move`;this.updateGraphics.addMany(e),await this._updatingHandles.addPromise(this._updateSpatialReference(e));let i=await this._updatingHandles.addPromise(this._getGraphicMover(e,t,n));if($(i))return i;let a=new R({activeComponent:i,tool:r,type:`update`,onEnd:()=>{this._clearCursor(),c(l),c(s),i.destroy(),this._internalGraphicsLayer?.removeMany([...this.updateGraphics.toArray()])},undo:()=>{let e=this.updateGraphics.toArray();q(a,e),a.refreshComponent(),this._emitUndoEvent({graphics:e,tool:r})},redo:()=>{let e=this.updateGraphics.toArray();J(a,e),a.refreshComponent(),this._emitRedoEvent({graphics:e,tool:r})},addToSelection:async e=>{await this._updatingHandles.addPromise(this._updateSpatialReference(e)),this.updateGraphics.push(e),i.graphics=this.updateGraphics.toArray(),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);a.history.undo.forEach(e=>e.updates.splice(t,1)),a.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e);let n=this.updateGraphics.toArray();this.emit(`update`,{graphics:n,state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),this.updateGraphics.length===0?a.complete():i.graphics=n}}),o=!1,s=[n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(a,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(a,e),e.key===A.constraint&&!e.repeat&&(o=!0,i.enableMoveAllGraphics=!i.enableMoveAllGraphics)},k.WIDGET),n.on(`key-up`,e=>{e.key===A.constraint&&o&&(o=!1,i.enableMoveAllGraphics=!i.enableMoveAllGraphics)},k.WIDGET)],l=this._getHandlesForComponent(a,t);return a}async _setupReshape3DOperation(e,t,n,r=!1){let i=`reshape`,a=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(a))return a;let{ManipulatedObject3DGraphic:o,ReshapeTool3D:s}=a.module,l=new o({view:n,graphic:e}),u=ye(l);if(u!==0)return l.destroy(),this._logError(`sketch:reshape`,`Reshape operation not supported for provided graphic(s) (${D(u)}).`),null;let d=t.reshapeOptions,f=new s({view:n,object:l,enableZVertex:t.enableZ&&d?.vertexOperation===`move`,enableZShape:t.enableZ&&d?.shapeOperation===`move`,enableMoveObject:d?.shapeOperation===`move`||d?.shapeOperation===`move-xy`,enableMidpoints:d?.edgeOperation===`split`,enableEdgeOffset:d?.edgeOperation===`offset`,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(f),r||this.updateGraphics.add(l.graphic);let p=[],m=new R({activeComponent:f,tool:i,type:`update`,onEnd:()=>{c(p),Q(n,f),l.destroy()},canUndo:()=>!f.destroyed&&f.canUndo,undo:()=>{f.destroyed||(f.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},canRedo:()=>!f.destroyed&&f.canRedo,redo:()=>{f.destroyed||(f.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(m,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),m.complete()},toggleTool:async()=>{t.toggleToolOnClick!==!1&&await this._replaceUpdateOperationHandle(m,t,()=>this._setupGraphicTransform3DOperation(this.updateGraphics.toArray(),t,n,!0))}});return p.push(...this._getHandlesForComponent(m,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(m,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(m,e)},k.WIDGET)),m}async _setupTransformOrReshape2DOperation(e,t,n,r){this.updateGraphics.addMany(e),await this._updatingHandles.addPromise(this._updateSpatialReference(e));let i=await this._updatingHandles.addPromise(t===`transform`?this._getBox(e,n,r):this._getReshape(e,n,r));if($(i))return i;let a=new R({activeComponent:i,type:`update`,onEnd:()=>{c(s),c(o),a.activeComponent&&!a.activeComponent.destroyed&&a.activeComponent.destroy(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray())},undo:()=>{q(a,this.updateGraphics.toArray()),a.refreshComponent(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a.tool})},redo:()=>{J(a,this.updateGraphics.toArray()),a.refreshComponent(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a.tool})},addToSelection:async e=>{let t=a.activeComponent;if(t?.type===`reshape`){let t=[...this.updateGraphics,e];if(this.updateGraphics.removeAll(),!await this._replaceUpdateOperationHandle(a,n,()=>this._setupTransformOrReshape2DOperation(t,`transform`,n,r)))return}else this.updateGraphics.add(e),t=t,t.graphics=this.updateGraphics.toArray(),t.refresh(),a.resetHistory();this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);a.history.undo.forEach(e=>e.updates.splice(t,1)),a.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e);let n=this.updateGraphics.toArray();n.length===0?a.complete():B(n)?await a.toggleTool():a.activeComponent.graphics=n,this.emit(`update`,{graphics:n,state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`})},toggleTool:async()=>{if(this.updateGraphics.length>1)return;let e=this.updateGraphics.at(0),t=e.geometry;if(t!=null&&(a.tool===`reshape`&&t.type===`point`||a.tool===`transform`&&t.type===`extent`))return;let i=null,o={...this.defaultUpdateOptions,...n,...this.activeUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...n?.reshapeOptions,...this.activeUpdateOptions?.reshapeOptions},highlightOptions:{...this.defaultUpdateOptions.highlightOptions,...n?.highlightOptions,...this.activeUpdateOptions?.highlightOptions}};a.tool===`transform`?i=await this._updatingHandles.addPromise(this._getReshape([e],o,r)):a.tool===`reshape`&&(i=await this._updatingHandles.addPromise(this._getBox([e],o,r))),!$(i)&&(a.activeComponent?.destroy(),a.activeComponent=i,a.activeComponent&&(c(s),s=this._getHandlesForComponent(a,o)))}}),o=[r.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(a,e,n),k.WIDGET),r.on(`key-down`,e=>{if(this._getCommonUpdateOperationKeyDownHandlers(a,e),e.key===A.constraint&&!e.repeat&&a){let e=a.activeComponent;e?.type===`box`&&(e.preserveAspectRatio=!e.preserveAspectRatio)}},k.WIDGET),r.on(`key-up`,e=>{if(e.key===A.constraint&&a){let e=a.activeComponent;e?.type===`box`&&(e.preserveAspectRatio=!e.preserveAspectRatio)}},k.WIDGET)],s=this._getHandlesForComponent(a,n);return a}async _getGraphicMover(e,t,n){let{enableMoveAllGraphics:r,highlightOptions:i}=t,a=await this._requireModule(import(`../../views/draw/support/GraphicMover.js`));return $(a)?a:new a.module.default({enableMoveAllGraphics:r,highlightName:i?.name,highlightsEnabled:!!i?.enabled,indicatorsEnabled:!1,graphics:e,view:n,callbacks:{onGraphicMoveStart:({dx:e,dy:t,graphic:n})=>{this._displayCursor(`grabbing`),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move-start`},type:`update`})},onGraphicMove:({dx:e,dy:t,graphic:n})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move`},type:`update`}),onGraphicMoveStop:({dx:e,dy:t,graphic:n})=>{this._displayCursor(`pointer`),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move-stop`},type:`update`})},onGraphicPointerOver:()=>this._displayCursor(`move`),onGraphicPointerOut:()=>this._clearCursor()}})}async _getBox(e,t,n){let{enableRotation:r,enableScaling:i,highlightOptions:a,preserveAspectRatio:o}=t,s=await this._requireModule(import(`../../views/draw/support/Box.js`));if($(s))return s;let c=this.view?.inputManager?.isModifierKeyDown(A.constraint),l=new s.module.default({graphics:e,enableRotation:r,enableScaling:i,highlightName:a?.name,highlightsEnabled:!!a?.enabled,preserveAspectRatio:!!o!=!!c,layer:this._internalGraphicsLayer,view:n,toolOptions:this._operationToolOptions,callbacks:{onMoveStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onMove:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onMoveStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScaleStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScale:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScaleStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotateStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotate:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotateStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`})}});return l.addHandles(_(()=>[this.activeUpdateOptions?.enableRotation,this.activeUpdateOptions?.enableScaling],([e,n])=>{l.enableRotation=e??t.enableRotation??!0,l.enableScaling=n??t.enableScaling??!0,l.refresh()},v)),l}async _getReshape(e,t,n){let{highlightOptions:r,reshapeOptions:i}=t,a=i?.edgeOperation===`split`,o=i?.shapeOperation===`move`,s=!!i?.enableCreateCurveFromStraightEdge,c=await this._requireModule(import(`../../views/draw/support/Reshape.js`));return $(c)?c:new c.module.default({enableMidpoints:a,enableMovement:o,enableCurveOnMidpoint:s,graphic:e[0],highlightName:r?.name,highlightsEnabled:!!r?.enabled,layer:this._internalGraphicsLayer,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions,view:n,callbacks:{onReshapeStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onReshape:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onReshapeStop:({mover:e,type:t})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e,type:t},type:`update`}),onMoveStart:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onMove:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onMoveStop:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onVertexAdd:({added:e,type:t,vertices:n})=>{let r=e.map(e=>C(e.geometry));this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:r,vertices:n,type:t},type:`update`})},onVertexRemove:({removed:e,type:t,vertices:n})=>{let r=e.map(e=>C(e.geometry));this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{removed:r,vertices:n,type:t},type:`update`})}}})}_getHandlesForComponent(e,t){let n=e.activeComponent;if(!n)return[];switch(n.type){case`graphic-mover`:return[n.on(`graphic-click`,({graphic:n,viewEvent:r})=>{r.native?.shiftKey&&t.multipleSelectionEnabled&&(r.stopPropagation(),this._updatingHandles.consumePromise(e.removeFromSelection(n)))}),n.on(`graphic-move-start`,t=>e.addToHistory(Z(t.allGraphics)))];case`box`:return[n.on(`graphic-click`,n=>this._onTransformOrReshape2DGraphicClick(e,t,n)),n.on(`move-start`,t=>e.addToHistory(Z(t.graphics))),n.on(`rotate-start`,t=>e.addToHistory(Z(t.graphics))),n.on(`scale-start`,t=>e.addToHistory(Z(t.graphics)))];case`reshape`:return[n.on(`graphic-click`,n=>this._onTransformOrReshape2DGraphicClick(e,t,n)),n.on(`move-start`,t=>e.addToHistory(Z([t.mover]))),n.on(`reshape-start`,t=>e.addToHistory(Z([t.graphic]))),n.on(`vertex-add`,t=>e.addToHistory(Z([t.oldGraphic]))),n.on(`vertex-remove`,t=>e.addToHistory(Z([t.oldGraphic])))];case`move-3d`:return[n.events.on(`record-undo`,({updates:t})=>{e.addToHistory({updates:t})}),n.events.on(`move-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move-start`},type:`update`})}),n.events.on(`move`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e.dx,dy:e.dy,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move`},type:`update`})}),n.events.on(`move-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move-stop`},type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})];case`transform-3d`:return[n.events.on(`record-undo`,({updates:t})=>{e.addToHistory({updates:t})}),n.events.on(`translate-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move-start`},type:`update`})}),n.events.on(`translate-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move-stop`},type:`update`})}),n.events.on(`rotate-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate-start`},type:`update`})}),n.events.on(`rotate-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate-stop`},type:`update`})}),n.events.on(`scale-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale-start`},type:`update`})}),n.events.on(`scale-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale-stop`},type:`update`})}),n.events.on(`translate`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move`},type:`update`})}),n.events.on(`rotate`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate`},type:`update`})}),n.events.on(`scale`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale`},type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})];case`reshape-3d`:return[n.events.on(`reshape`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e,mover:e.object.graphic},type:`update`})}),n.events.on(`move`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e,mover:e.object.graphic},type:`update`})}),n.events.on(`vertex-add`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:e,type:`update`})}),n.events.on(`vertex-remove`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:e,type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})]}}_onTransformOrReshape2DGraphicClick(e,t,n){let{graphic:r,viewEvent:i}=n;i.native?.shiftKey&&this.hasGraphic(r)?(i.stopPropagation(),this._updatingHandles.consumePromise(e.removeFromSelection(r))):t.toggleToolOnClick&&(i.stopPropagation(),this._updatingHandles.consumePromise(e.toggleTool()))}async _replaceUpdateOperationHandle(e,t,n){let r=this._operationContext;e.onEnd(),e.destroy();let i=await this._updatingHandles.addPromise(n());return!i||$(i)||r!==this._operationContext?(i&&!$(i)&&(i.onEnd(),i.destroy()),this._destroyOperationContext(r),!1):(this._setUpdateOperationHandle(i,t),!0)}_setUpdateOperationHandle(e,t){this._operationHandle=e;let n=this.view?.map;this._disablePopup(t),e.on(`complete`,()=>{if(e===this._operationHandle){let r=this.updateGraphics.toArray(),i=this._operationHandle.tool;this._operationHandle.destroy(),this._operationHandle=null,this._destroyOperationContext(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray()),this.updateGraphics.removeAll(),n&&n.remove(this._internalGraphicsLayer),this._restorePopup(t),this.emit(`update`,{graphics:r,state:`complete`,aborted:e.cancelled,tool:i,toolEventInfo:null,type:`update`})}})}_getCommonUpdateOperationClickHandlers(e,t,n){return this._updatingHandles.addPromise(this._handleCommonUpdateOperationClick(e,t,n))}async _handleCommonUpdateOperationClick(e,t,n){let r=L(t),i=await t.defer(()=>this._getFirstHit(r));if(i==null){this.cancelUpdateOnClickAway&&e.complete();return}let a=t.native.shiftKey?this._toggleSelection([i.graphic],e,n):null;a?(t.stopPropagation(),await a):this.updateGraphics.includes(i.graphic)?this._shouldTemporarilyDisablePopup(n)&&t.stopPropagation():e.complete()}async _toggleSelection(e,t,n){let r=!!n.multipleSelectionEnabled;for(let n of e)if(n!=null&&r&&this.hasGraphic(n))return this.updateGraphics.includes(n)?await t.removeFromSelection(n):await t.addToSelection(n)}_getCommonUpdateOperationKeyDownHandlers(e,t){if(!e)return;let n=t.key;n===A.undo&&e.canUndo()?(t.stopPropagation(),e.undo()):n===A.redo&&e.canRedo()?(t.stopPropagation(),e.redo()):n===A.cancel?(t.stopPropagation(),e.cancel()):this.allowDeleteKey&&A.delete.includes(n)&&this._onDeleteKey(t)}_onDeleteKey(e){this._operationHandle&&this._operationHandle.type===`update`&&this.activeComponent!=null&&(e.stopPropagation(),this.delete())}_removeDefaultLayer(){this._internalGraphicsLayer&&=(this.view?.map?.remove(this._internalGraphicsLayer),d(this._internalGraphicsLayer))}_isComponentGraphic(e){let{activeComponent:t}=this;return!e||t==null?!1:e.attributes?.esriSketchTool||t.type===`draw-2d`&&t.graphic===e||(t.type===`box`||t.type===`reshape`)&&t.isUIGraphic(e)}_clearCursor(){this.removeHandles(U)}_displayCursor(e){this.removeHandles(U),this.view?.container&&e!=null&&this.addHandles(this.view.acquireCursor(e,`high`),U)}_logError(e,t,n){u.getLogger(this).error(new i(e,t,n))}async _requireModule(e){let t=new AbortController;this._moduleLoaderAbortController=t;let n=await e;return this._moduleLoaderAbortController!==t||t.signal.aborted?{requireError:`aborted`}:{module:n}}_emitUndoEvent(e){this.emit(`undo`,{...e,type:`undo`})}_emitRedoEvent(e){this.emit(`redo`,{...e,type:`redo`})}_emitDeleteEvent(e){this.emit(`delete`,{...e,type:`delete`})}_onLayerGraphicsChangeCallback(e){if(this._operationHandle!=null){let{updateGraphics:t}=this;for(let n of e.removed)if(t.includes(n)){if(t.length>1)this._updatingHandles.consumePromise(this._operationHandle.removeFromSelection(n));else{this._operationHandle.cancel();break}}}}async _setupAdvancedDrawToolIntegrationMaybe(){this.isUsingLegacyCreateTools||this.pluginManager.loaded||await this.pluginManager.loadPlugins()}async _setupDrawTool(e,n,r){if(this.isUsingLegacyCreateTools||!this._pluginManager)return null;let i=this.view,a=await import(`../../views/draw/DrawTool.js`);await this.pluginManager.loadPlugins();let o=await this.pluginManager.makeRenderer({customSymbol:n.graphicSymbol,useTextSymbol:r===`text`}),s=new a.DrawTool({view:i,elevationInfo:this._layerAdapter?.elevationInfo??pe(i.type===`3d`),hasZ:!!n.hasZ,toolOptions:this._operationToolOptions,renderer:o,defaultZ:n.defaultZ??0,directionOptions:n.directionOptions,snappingManager:this._operationSnappingManager,enableVertexVisuals:r!==`rectangle`&&r!==`circle`,readPluginSetting:(e,t)=>this.settingsManager.getValue(t)});s.addHandles(l(o));let c=new t({...n.graphicProperties,attributes:{...n.graphicProperties?.attributes},symbol:n.graphicSymbol??this._getGraphicSymbolFromTool(r)});return n.graphicSymbol||s.addHandles(_(()=>this._getGraphicSymbolFromTool(r),e=>c.symbol=e)),this._set(`createGraphic`,c),i.addAndActivateTool(s),s.begin(e),s}get test(){}wait(){return y(()=>!this.updating)}_shouldTemporarilyDisablePopup(e){return this.updateOnGraphicClick||(e?.toggleToolOnClick??!1)}_disablePopup(e){this._shouldTemporarilyDisablePopup(e)&&this.view&&this._originalPopupEnabled==null&&(this._originalPopupEnabled=this.view.popupEnabled,this.view.popupEnabled=!1)}_restorePopup(e){this._shouldTemporarilyDisablePopup(e)&&this.view&&this._originalPopupEnabled!=null&&(this.view.popupEnabled=this._originalPopupEnabled,this._originalPopupEnabled=null)}async _waitViewReady(){let e=this.view;e?(f(this._viewReadyAbortController),this._viewReadyAbortController=new AbortController,await g(y(()=>e?.ready),this._viewReadyAbortController.signal)):this._logMissingView()}_logMissingView(){this._logError(`sketch:missing-property`,K(`view`))}_logMissingLayer(){this._logError(Re,K(`layer`))}};e([b()],G.prototype,`_defaultSnappingManager`,void 0),e([b()],G.prototype,`_operationContext`,void 0),e([b()],G.prototype,`_layerAdapter`,null),e([b()],G.prototype,`_pluginManager`,void 0),e([b({readOnly:!0})],G.prototype,`settingsManager`,void 0),e([b()],G.prototype,`_operationHandle`,void 0),e([b({readOnly:!0})],G.prototype,`_updatingHandles`,void 0),e([b({readOnly:!0})],G.prototype,`_toolTransitionHandles`,void 0),e([b()],G.prototype,`_drawToolSimplifyAbortController`,void 0),e([b({readOnly:!0})],G.prototype,`activeTool`,null),e([b()],G.prototype,`geometrySimplificationInProgress`,null),e([b({readOnly:!0})],G.prototype,`activeCreateToolDrawMode`,null),e([b()],G.prototype,`activeTooltip`,null),e([b({types:E})],G.prototype,`activeFillSymbol`,void 0),e([b()],G.prototype,`activeLineSymbol`,void 0),e([b()],G.prototype,`activeVertexSymbol`,void 0),e([b()],G.prototype,`allowDeleteKey`,void 0),e([b({readOnly:!0})],G.prototype,`createGraphic`,null),e([b()],G.prototype,`defaultCreateOptions`,null),e([b()],G.prototype,`defaultUpdateOptions`,null),e([b()],G.prototype,`activeUpdateOptions`,void 0),e([b({type:M,nonNullable:!0})],G.prototype,`labelOptions`,null),e([b()],G.prototype,`layer`,void 0),e([b({types:E})],G.prototype,`pointSymbol`,void 0),e([b({types:E})],G.prototype,`polygonSymbol`,void 0),e([b({types:E})],G.prototype,`polylineSymbol`,void 0),e([b()],G.prototype,`meshSymbol`,void 0),e([b({type:T})],G.prototype,`textSymbol`,null),e([b({type:F,nonNullable:!0})],G.prototype,`snappingOptions`,null),e([b()],G.prototype,`snappingManager`,null),e([b({readOnly:!0})],G.prototype,`state`,null),e([b()],G.prototype,`toolTransitionInProgress`,null),e([b({type:Se,nonNullable:!0})],G.prototype,`tooltipOptions`,null),e([b({readOnly:!0})],G.prototype,`updateGraphics`,void 0),e([b()],G.prototype,`updateOnGraphicClick`,void 0),e([b()],G.prototype,`useViewOptions`,void 0),e([b()],G.prototype,`cancelUpdateOnClickAway`,void 0),e([b()],G.prototype,`updating`,null),e([b()],G.prototype,`creationMode`,void 0),e([b({type:Ce,nonNullable:!0})],G.prototype,`valueOptions`,null),e([b({types:E})],G.prototype,`vertexSymbol`,void 0),e([b({value:null})],G.prototype,`view`,null),e([b({constructOnly:!0,type:N})],G.prototype,`sketchOptions`,void 0),e([b()],G.prototype,`useLegacyCreateTools`,void 0),e([b()],G.prototype,`isUsingLegacyCreateTools`,null),e([b()],G.prototype,`pluginManager`,null),e([b()],G.prototype,`drawTool`,null),e([b()],G.prototype,`activePluginConfigurations`,null),e([b()],G.prototype,`rootPlugins`,null),e([b()],G.prototype,`effectiveAvailablePlugins`,null),e([b()],G.prototype,`firstPluginWithSwappableLeaf`,null),e([b()],G.prototype,`multiplePluginsActive`,null),G=e([re(`esri.widgets.Sketch.SketchViewModel`)],G);const Re=`sketch:missing-property`,K=e=>`Property '${e}' is missing on SketchViewModel.`;function ze(e){return e===`polygon`||e===`rectangle`||e===`circle`}function q(e,t){Y(`undo`,e.history.undo,e.history.redo,t)}function J(e,t){Y(`redo`,e.history.redo,e.history.undo,t)}function Y(e,t,n,r){let i=t.pop();if(!i)return;let a=i.updates,o=[];r.forEach((t,n)=>{let r=a[n];r!=null&&(`geometry`in r&&r.geometry!=null&&(o.push({geometry:t.geometry}),t.geometry=r.geometry),`symbol`in r&&r.symbol!=null&&(o.push({symbol:t.symbol}),t.symbol=r.symbol),`undo`in r&&(o.push(r),r[e](t)))}),n.push({updates:o})}function X(e,t){e!=null&&t.hasGrabbedManipulators&&(e.activeTool=null)}function Z(e){return{updates:e.map(({geometry:e})=>e?.type===`mesh`?{geometry:e.cloneShallow()}:{geometry:e})}}function Q(e,t){e.tools?.remove(t),t.destroyed||t.destroy()}function $(e){return`requireError`in e&&e.requireError===`aborted`}export{G as default};
2
+ import{__decorate as e}from"tslib";import t from"../../Graphic.js";import{isSome as n}from"../../core/arrayUtils.js";import r from"../../core/Collection.js";import i from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import{handlesGroup as o,makeHandle as s,drainHandles as c,destroyHandle as l}from"../../core/handleUtils.js";import has from"../../core/has.js";import u from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as f,removeMaybe as p}from"../../core/maybe.js";import{createAbortError as m,ignoreAbortErrors as h,whenOrAbort as g}from"../../core/promiseUtils.js";import{watch as _,syncAndInitial as v,on as ee,when as te,sync as ne,whenOnce as y}from"../../core/reactiveUtils.js";import{property as b,subclass as re}from"../../core/accessorSupport/decorators.js";import{trackAccess as x}from"../../core/accessorSupport/tracking.js";import{SimpleObservable as ie}from"../../core/accessorSupport/tracking/SimpleObservable.js";import{UpdatingHandles as S}from"../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ae}from"../../geometry/ellipsoidUtils.js";import{canProjectWithoutEngine as oe,isLoaded as se,load as ce,project as le}from"../../geometry/projectionUtils.js";import{geometryToCoordinates as C}from"../../geometry/support/coordsUtils.js";import{equals as ue}from"../../geometry/support/spatialReferenceUtils.js";import de from"../../layers/GraphicsLayer.js";import{isIntegratedMeshLayer as fe}from"../../layers/support/layerUtils.js";import{getEffectiveElevationInfo as pe}from"../../support/elevationInfoUtils.js";import me from"../../symbols/FillSymbol3DLayer.js";import he from"../../symbols/MeshSymbol3D.js";import ge from"../../symbols/SimpleFillSymbol.js";import _e from"../../symbols/SimpleLineSymbol.js";import w from"../../symbols/SimpleMarkerSymbol.js";import T from"../../symbols/TextSymbol.js";import{symbolTypes as E}from"../../symbols/support/typeUtils.js";import{isSupportedObjectResultMessage as D}from"../../views/3d/interactive/editingTools/isSupportedObjectUtils.js";import{isSupportedObject as ve}from"../../views/3d/interactive/editingTools/move/isSupportedObject.js";import{isSupportedObject as ye}from"../../views/3d/interactive/editingTools/reshape/isSupportedObject.js";import{isSupportedGraphic as be}from"../../views/3d/interactive/editingTools/transform/isSupportedGraphic.js";import{addUniqueLayer as O}from"../../views/draw/support/layerUtils.js";import{ViewEventPriorities as k}from"../../views/input/InputManager.js";import{sketchKeys as A}from"../../views/interactive/keybindings.js";import{bindViewToolOptions as xe}from"../../views/interactive/options/bindViewToolOptions.js";import j from"../../views/interactive/options/InteractiveToolOptions.js";import M from"../../views/interactive/sketch/SketchLabelOptions.js";import N from"../../views/interactive/sketch/SketchOptions.js";import Se from"../../views/interactive/sketch/SketchTooltipOptions.js";import Ce from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as P}from"../../views/interactive/snapping/SnappingManager.js";import{acquireForViewOptions as we}from"../../views/interactive/snapping/SnappingManagerPool.js";import F from"../../views/interactive/snapping/SnappingOptions.js";import{setupSnappingToggleHandles as I}from"../../views/interactive/snapping/snappingUtils.js";import{GeometryWorkerHandle as Te}from"../../views/support/GeometryWorkerHandle.js";import{defaultHighlightName as Ee}from"../../views/support/HighlightDefaults.js";import{findFirstGraphicHit as De}from"../../views/support/hitTestSelectUtils.js";import{createScreenPointFromEvent as L}from"../../views/support/screenUtils.js";import Oe from"./adapters/layer/GraphicsLayerAdapter.js";import ke from"./adapters/layer/MapNotesLayerAdapter.js";import Ae from"./adapters/layer/SketchLayerAdapter.js";import{CreateOperationHandle as je,DrawToolOperationHandle as Me,UpdateOperationHandle as R}from"./support/OperationHandle.js";import{PluginManager as Ne}from"./support/PluginManager.js";import{SettingsManager as Pe}from"./support/SettingsManager.js";import{getLegacyTool as z,isCompletelyDegenerate as Fe,graphicsHaveTooFewVerticesForBox as B,getModeFromCreateOptions as Ie,getDrawToolGeometryTypeFromCreateTool as Le}from"./support/sketchUtils.js";const V={defaultZ:0},H={reshapeOptions:{edgeOperation:`split`,shapeOperation:`move`,vertexOperation:`move`,enableCreateCurveFromStraightEdge:!0},enableMoveAllGraphics:!0,enableRotation:!0,enableScaling:!0,multipleSelectionEnabled:!0,preserveAspectRatio:!1,toggleToolOnClick:!0,enableZ:!0,highlightOptions:{enabled:!0,name:Ee},tool:`transform`},U=Symbol(),W=Symbol();let G=class extends a{constructor(e){super(e),this._defaultSnappingManager=null,this._operationContext=null,this._internalGraphicsLayer=new de({listMode:`hide`,internal:!0,title:`SVM Internal`}),this._pluginManager=new Ne({sketchViewModel:this}),this.settingsManager=new Pe({availablePlugins:()=>this.pluginManager.visiblePluginsFlat}),this._operationHandle=null,this._updatingHandles=new S,this._toolTransitionHandles=new S,this._drawToolSimplifyAbortController=null,this._geometryWorkerHandle=new Te,this._viewHandlesKey=`viewHandles`,this.activeFillSymbol=null,this.activeLineSymbol=null,this.activeVertexSymbol=null,this.allowDeleteKey=!0,this.activeUpdateOptions=null,this.layer=null,this.pointSymbol=new w({style:`circle`,size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.polygonSymbol=new ge({color:[150,150,150,.2],outline:{color:[50,50,50],width:2}}),this.polylineSymbol=new _e({color:[130,130,130,1],width:2}),this.meshSymbol=new he({symbolLayers:new r([new me])}),this.updateGraphics=new r,this.updateOnGraphicClick=!0,this.useViewOptions=!1,this.cancelUpdateOnClickAway=!0,this.creationMode=`single`,this.vertexSymbol=new w({style:`circle`,size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.sketchOptions=new N,this.useLegacyCreateTools=!0,this._moduleLoaderAbortController=null,this._viewReadyAbortController=null,this._sketchContinuationFlag=!1,this._onLayerAdapterChange=async()=>{let{_layerAdapter:e}=this;if(this.removeHandles(W),!e)return;let t=[e.onGraphicsChange(e=>this._onLayerGraphicsChangeCallback(e)),_(()=>e.elevationInfo,e=>{e!==this._internalGraphicsLayer.elevationInfo&&(this.cancel(),this._internalGraphicsLayer&&(this._internalGraphicsLayer.elevationInfo=e))},v)].filter(n);this.addHandles(t,W)},this._originalPopupEnabled=null,this.defaultCreateOptions=V,this.defaultUpdateOptions=H,this.snappingOptions=e?.snappingManager?.options??e?.snappingOptions??new F,this.textSymbol=new T({text:`text`})}initialize(){this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe()),this.addHandles([ee(()=>this.view?.map?.layers,`change`,e=>{this.layer&&e.removed.includes(this.layer)&&this.cancel()}),_(()=>this._layerAdapter,()=>this._onLayerAdapterChange(),v),_(()=>this.view,e=>{this._defaultSnappingManager=d(this._defaultSnappingManager),e&&(this.snappingManager||(this._defaultSnappingManager=new P({view:e,options:this.snappingOptions})),e.type===`2d`?(import(`../../views/2d/interactive/editingTools.js`),this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe())):e.type===`3d`&&(import(`../../views/3d/interactive/editingTools.js`),import(`../../views/3d/layers/GraphicsLayerView3D.js`)))},v),_(()=>this.view?.spatialReference,(e,t)=>{e&&t&&!e.equals(t)&&this.cancel()})]),I(this,void 0,()=>this._operationSnappingManager?.options??this.snappingOptions)}destroy(){this.cancel(),this._removeDefaultLayer(),this._defaultSnappingManager=d(this._defaultSnappingManager),this._destroyOperationContext(),this._set(`snappingManager`,null),this._set(`view`,null),this._updatingHandles.destroy(),this._toolTransitionHandles.destroy(),this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),this._geometryWorkerHandle.destroy(),this._pluginManager?.destroy(),this.emit(`destroy`)}get _operationSnappingManager(){return this._operationContext?.snappingManager??this.snappingManager}get _operationToolOptions(){return this._operationContext?.toolOptions??this.sketchOptions}get _layerAdapter(){let{layer:e}=this;switch(e?.type){case`graphics`:return new Oe(e);case`map-notes`:return new ke(e);case`sketch`:return new Ae(e);case void 0:default:return null}}get activeTool(){return this._operationHandle?.tool??null}get geometrySimplificationInProgress(){return!!this._drawToolSimplifyAbortController}get activeCreateToolDrawMode(){let e=this._operationHandle;if(e?.type===`create`&&e.activeComponent&&`mode`in e.activeComponent)return e.activeComponent.mode;if(e?.activeComponent?.type===`draw-2.0`){let t=e.activeComponent.pluginStack.map(e=>e.configuration).filter(n).toArray();if(t.length>0)return this._pluginManager?.getDrawingModeEquivalentToPluginStack(t)}return null}get activeTooltip(){let{activeComponent:e,destroyed:t}=this,n=!t&&e&&`tooltip`in e?e.tooltip:null;return n?.visible?n:null}get activeComponent(){return this._operationHandle?.activeComponent??null}get createGraphic(){return this.activeComponent!=null&&(this.activeComponent.type===`draw-3d`||this.activeComponent.type===`draw-2d`)?this.activeComponent.graphic:this._get(`createGraphic`)}get defaultCreateOptions(){return this._get(`defaultCreateOptions`)}set defaultCreateOptions(e){this._set(`defaultCreateOptions`,{...V,...e})}get defaultUpdateOptions(){return this._get(`defaultUpdateOptions`)}set defaultUpdateOptions(e){this._set(`defaultUpdateOptions`,{...H,...e,reshapeOptions:{...H.reshapeOptions,...e?.reshapeOptions},highlightOptions:{...H.highlightOptions,...e?.highlightOptions}})}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get textSymbol(){return this._get(`textSymbol`)}set textSymbol(e){this._set(`textSymbol`,e)}get snappingOptions(){return this.snappingManager?.options??this._get(`snappingOptions`)}set snappingOptions(e){this._defaultSnappingManager!=null&&(this._defaultSnappingManager.options=e),this._set(`snappingOptions`,e)}get snappingManager(){return this._isOverridden(`snappingManager`)?this._get(`snappingManager`):this._defaultSnappingManager}set snappingManager(e){if(e)this._isOverridden(`snappingManager`)||(this._defaultSnappingManager=d(this._defaultSnappingManager)),this._override(`snappingManager`,e);else{let{view:e}=this;!this._defaultSnappingManager&&e&&(this._defaultSnappingManager=new P({options:this.snappingOptions,view:e})),this._clearOverride(`snappingManager`)}}get state(){let e=!!(this.view?.ready&&this.layer),t=this._operationHandle;return e&&t?`active`:e?`ready`:`disabled`}get toolTransitionInProgress(){return this._toolTransitionHandles.updating||!!this.drawTool?.lifecycleManager.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get updating(){return this.toolTransitionInProgress||this.activeComponent&&`updating`in this.activeComponent&&this.activeComponent.updating||!!(this._updatingHandles.updating||this._drawToolSimplifyAbortController||this.snappingManager?.updating||this.drawTool?.updating)}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}get view(){return this._get(`view`)}set view(e){let t=this._get(`view`);if(t===e)return;if(t){let{container:e,map:n}=t;e&&this._clearCursor(),n?.remove(this._internalGraphicsLayer),this.removeHandles(this._viewHandlesKey),this.cancel()}let n=`view-ready`;this.removeHandles(n),e&&this.addHandles(te(()=>e.ready,t=>{this.removeHandles(this._viewHandlesKey),t&&this.addHandles(this._generateViewHandles(e),this._viewHandlesKey)},v),n),this._set(`view`,e),this._updatingHandles.consumePromise(this._setupAdvancedDrawToolIntegrationMaybe())}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||this.view?.type!==`2d`}get pluginManager(){return this._pluginManager}get drawTool(){return this.activeComponent?.type===`draw-2.0`?this.activeComponent:null}get activePluginConfigurations(){return this.drawTool?.pluginStack.toArray().map(e=>e.configuration).filter(n)??[]}get rootPlugins(){return this._pluginManager?.availablePlugins}set rootPlugins(e){this._overrideIfSome(`rootPlugins`,e)}get effectiveAvailablePlugins(){if(this.isUsingLegacyCreateTools)return null;let e=this.view?.type??`2d`,{firstPluginWithSwappableLeaf:t}=this;return t?t.availableDownstreamPlugins.filter(t=>!t.excludedViews?.includes(e)):this.rootPlugins?.filter(t=>!t.excludedViews?.includes(e)).filter(n)??[]}get firstPluginWithSwappableLeaf(){let e=this.view?.type??`2d`;return this.drawTool?.pluginStack.toArray().map(e=>e.configuration).findLast(t=>t!=null&&!t.hidden&&t.availableDownstreamPlugins&&t.availableDownstreamPlugins.filter(t=>!t.excludedViews?.includes(e))?.length>1)}get multiplePluginsActive(){return this.drawTool?this.drawTool.pluginStack.length>1:!1}replaceLeaf(e){this.drawTool?.replaceLeaf(e)}addGraphic(e){this._layerAdapter?.add(e)}addGraphics(e){this._layerAdapter?.addMany(e)}hasGraphic(e){return!!this._layerAdapter?.has(e)}removeGraphic(e){this._layerAdapter?.remove(e)}removeGraphics(e){this._layerAdapter?.removeMany(e)}removeAllGraphics(){this._layerAdapter?.removeAll()}cancel(){this._moduleLoaderAbortController=f(this._moduleLoaderAbortController),this._viewReadyAbortController=f(this._viewReadyAbortController),this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),this._sketchContinuationFlag=!0,this._operationHandle?.cancel()}complete(){this._operationHandle?.complete()}delete(){let{state:e,updateGraphics:t}=this;if(e===`active`&&t.length){let{activeTool:e}=this,n=t.toArray();this.removeGraphics(n),this.cancel(),this._emitDeleteEvent({graphics:n,tool:e})}}duplicate(){if(this.state===`active`&&this.updateGraphics.length){let e=this.updateGraphics.map(e=>e.clone()).toArray();return this.addGraphics(e),this.emit(`duplicate`,{graphics:e,type:`duplicate`}),e}return[]}async create(e,t){return this._toolTransitionHandles.addPromise(this._create(e,t))}async _create(e,t){this.cancel(),await this._updatingHandles.addPromise(this._waitViewReady());let{view:n,layer:r}=this;if(!n||this.state===`disabled`)throw r||this._logMissingLayer(),m();if(n.activeTool!=null&&(n.activeTool=null),!e){this._logError(`sketch:missing-parameter`,`Missing parameter 'tool'.`);return}O(n,this._internalGraphicsLayer);let i=this._createOperationContext(n),a;try{a=await this._updatingHandles.addPromise(this._setupCreateOperation(e,t))}catch(e){throw this._destroyOperationContext(i),e}if(a==null||this.destroyed||i!==this._operationContext){let e=i===this._operationContext;a?.onEnd(),d(a),this._destroyOperationContext(i),e&&n.map?.remove(this._internalGraphicsLayer);return}let o=z(e);a.on(`complete`,()=>{if(a===this._operationHandle){let n=this.createGraphic,r=this._operationHandle.cancelled;if(this._operationHandle.destroy(),this._operationHandle=null,this._destroyOperationContext(),this._set(`createGraphic`,null),this.view?.map?.remove(this._internalGraphicsLayer),!a.cancelled&&n!=null&&this.addGraphic(n),this._sketchContinuationFlag=!1,this.emit(`create`,{graphic:n,state:r?`cancel`:`complete`,tool:o??`point`,toolEventInfo:null,type:`create`}),r||this._sketchContinuationFlag)return;let{creationMode:i}=this;if(i===`continuous`){if(t?.geometryToPlace)return;this._updatingHandles.consumePromise(h(this.create(e,t)))}else i===`update`&&n&&this._updatingHandles.consumePromise(h(this.update([n])))}}),this._operationHandle=a,n.ready&&n.focus()}async place(e,t){return await e.load(),this.create(`mesh`,{mode:`click`,hasZ:e.hasZ,geometryToPlace:e,...t})}async update(e,t){return this._toolTransitionHandles.addPromise(this._update(e,t))}async _update(e,t){this.cancel(),await this._updatingHandles.addPromise(this._waitViewReady());let{layer:n,view:r,state:i}=this;if(!r||i===`disabled`)throw n||this._logMissingLayer(),m();r.activeTool!=null&&(r.activeTool=null);let a=Array.isArray(e)?e:[e];if(e==null||!a?.length){this._logError(`sketch:missing-parameter`,`Missing parameter 'graphics'.`);return}if(a.some(e=>this.hasGraphic(e)?e.geometry==null&&(this._logError(`sketch:invalid-parameter`,`Parameter 'graphics' contains one or more graphics with an unsupported geometry.`),!0):(this._logError(`sketch:invalid-parameter`,`Parameter 'graphics' contains one or more graphics missing from the supplied GraphicsLayer.`),!0)))return;let o=this._createOperationContext(r),s;try{s=await this._updatingHandles.addPromise(this._setupUpdateOperation(a,t))}catch(e){throw this._destroyOperationContext(o),e}this.destroyed||s==null||$(s)||o!==this._operationContext?(s&&!$(s)&&(s.onEnd(),s.destroy()),this._destroyOperationContext(o)):(O(r,this._internalGraphicsLayer),this._setUpdateOperationHandle(s,t),this.emit(`update`,{graphics:a,state:`start`,aborted:!1,tool:s.tool,toolEventInfo:null,type:`update`}))}async _updateSpatialReference(e){let t=this.view;if(!t)this._logMissingView();else{e=Array.isArray(e)?e:[e];for(let n of e)n.geometry!=null&&n.geometry.type!==`mesh`&&!ue(n.geometry.spatialReference,t.spatialReference)&&(!oe(n.geometry.spatialReference,t.spatialReference)&&!se()&&await ce(),n.geometry=le(n.geometry,t.spatialReference))}}undo(){this.canUndo()&&this._operationHandle?.undo()}redo(){this.canRedo()&&this._operationHandle?.redo()}canUndo(){return!!this._operationHandle?.canUndo()}canRedo(){return!!this._operationHandle?.canRedo()}toggleUpdateTool(){this._updatingHandles.consumePromise(this._operationHandle?.toggleTool())}_createOperationContext(e){this._destroyOperationContext();let t=this.useViewOptions?e.options:null,n=t?we(e):null,r=t?new j:this.sketchOptions,i;if(t){let{values:t}=r;i=o([xe(r,()=>e.options,()=>this.sketchOptions),_(()=>t.directionMode,e=>{this.sketchOptions.values.directionMode=e},ne)])}return this._operationContext={snappingManager:n?.snappingManager??this.snappingManager,toolOptions:r,...o([n,i])}}_destroyOperationContext(e=this._operationContext){e===this._operationContext?this._operationContext=p(this._operationContext):p(e)}async _getFirstHit(e){let t=this.view;if(!t)return this._logMissingView(),null;if(t.type===`2d`){let n=[];t.map.allLayers.forEach(e=>{(e.type===`vector-tile`||e.type===`imagery`)&&n.push(e)});let r=await t.hitTest(e,{exclude:n});return De(r.results)}let n=[t.map.ground];t.map.allLayers.forEach(e=>{fe(e)&&(!has(`enable-feature:im-as-ground`)||e.isUsedAsGroundLayer)&&n.push(e)});let r=await t.hitTest(e,{exclude:n});if(r.results.length>0){let e=r.results[0];if(e!=null&&e.type===`graphic`&&e.graphic&&(!r.ground.mapPoint||t.map.ground.opacity<1||r.ground.distance-(e.distance??0)>-Math.min(3*r.ground.distance,t.viewingMode===`global`?ae(t.renderCoordsHelper.spatialReference).radius/t.renderCoordsHelper.unitInMeters:1/0)))return e}return null}_generateViewHandles(e){return[e.on(`immediate-click`,async e=>{let t=this.state===`active`&&this._operationHandle?.type===`create`;this.state!==`disabled`&&!t&&this.updateOnGraphicClick&&await this._toolTransitionHandles.addPromise(this._handleImmediateClick(e))},k.WIDGET)]}async _handleImmediateClick(e){let t=await e.defer(()=>this._getFirstHit(L(e))),n=null;if(t!=null){let r=t.graphic;this.updateGraphics.includes(r)||this.hasGraphic(r)?(e.stopPropagation(),n=r):this.view?.type===`2d`&&!this._isComponentGraphic(r)&&this.state===`active`&&this.cancel()}else this.state===`active`&&this.cancelUpdateOnClickAway&&this.cancel();n!=null&&!this.updateGraphics.includes(n)&&await this.update([n],{...this.defaultUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions}})}async _setupCreateOperation(e,t){let n=this.view;if(!n)return this._logMissingView(),null;let r={hasZ:n.type===`3d`,...this.defaultCreateOptions,...t},i=typeof e==`string`?this.pluginManager?.getPluginsEquivalentToCreateTool(e,r):e,a=z(e);if(i&&!this.isUsingLegacyCreateTools){let e=await this._setupDrawTool(i,r,a??`polyline`);if(e)return this._setupDrawToolOperationHandle(e,a??`point`)}if(!a)return null;let o=await this._setupDrawGraphicTool(a,n,r);return o==null?null:(n.tools.add(o),n.activeTool=o,this._setupCreateOperationHandle(o,a))}async _setupDrawGraphicTool(e,t,n){if(e===`multipoint`&&t.type===`3d`)return this._logError(`sketch:create`,`Multipoint geometries are not supported in SceneView.`),null;if(!t)return this._logMissingView(),null;let{cursor:r,defaultZ:i,hasZ:a,geometryToPlace:o,graphicProperties:s,mode:c,preserveAspectRatio:l}=n,u=Ie(c,e),d=Le(e),f=n?.optionsPerTool?.has(e)?n.optionsPerTool.get(e):{},p=f?.preserveAspectRatio??l??e!==`rectangle`,m={centered:e!==`rectangle`&&!(e===`circle`&&!p),cursor:r,defaultZ:i,forceUniformSize:p,graphicProperties:{...s,attributes:{...s?.attributes}},geometryToPlace:o,geometryType:d,mode:u,graphicSymbol:n.graphicSymbol??this._getGraphicSymbolFromTool(e),hasZ:a,snappingManager:this._operationSnappingManager,snapToScene:!1,view:t,...f};return t.type===`2d`?this._makeDrawGraphicTool2D(m):this._makeDrawGraphicTool3D(m)}async _makeDrawGraphicTool2D(e){let t=await this._requireModule(import(`../../views/2d/interactive/editingTools.js`));return $(t)||this.destroyed?null:new t.module.DrawGraphicTool2D({...e,activeVertexSymbol:this.activeVertexSymbol,regularVerticesSymbol:this.vertexSymbol,activeLineSymbol:this.activeLineSymbol,activeFillSymbol:ze(e.geometryType)?this.activeFillSymbol:null,toolOptions:this._operationToolOptions})}async _makeDrawGraphicTool3D(e){let t=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));return $(t)||this.destroyed?null:new t.module.DrawGraphicTool3D({...e,elevationInfo:this._layerAdapter?.elevationInfo,snapToScene:!0,toolOptions:this._operationToolOptions})}_setupCreateOperationHandle(e,t){let n=this.view;if(!n)return this._logMissingView(),null;let r=null,i=e.forceUniformSize,a=e.centered,o=new ie,l=[s(()=>o.destroy()),n.on(`key-down`,t=>{if(t.key===A.pan)t.stopPropagation(),t.repeat||(e.enabled=!1);else if(t.key===A.complete)t.stopPropagation(),e.completeCreateOperation();else if(t.key===A.vertexAdd&&!t.repeat){let n=e.drawOperation.geometryType;(n===`polyline`||n===`polygon`||n===`multipoint`)&&(t.stopPropagation(),e.drawOperation.commitStagedVertex())}else t.key===A.undo?(t.stopPropagation(),u.undo()):t.key===A.redo?(t.stopPropagation(),u.redo()):t.key===A.constraint&&(e.geometryType===`rectangle`||e.geometryType===`circle`)&&!t.repeat?(e.forceUniformSize=!i,t.stopPropagation()):t.key===A.center&&(t.repeat||(e.centered=!a,t.stopPropagation()))},k.WIDGET),n.on(`key-up`,t=>{t.key===A.pan?e.enabled=!0:t.key===A.constraint&&(e.geometryType===`rectangle`||e.geometryType===`circle`)?(e.forceUniformSize=i,t.stopPropagation()):t.key===A.center&&(e.centered=a,t.stopPropagation())},k.WIDGET),e.on(`vertex-update`,()=>{o.notify()}),e.on(`vertex-add`,t=>{switch(o.notify(),r=r==null?`start`:`active`,t.operation){case`apply`:this.emit(`create`,{graphic:e.graphic,state:r,tool:this.activeTool,toolEventInfo:t,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[e.graphic],tool:e.geometryType});break;case`redo`:this._emitRedoEvent({graphics:[e.graphic],tool:e.geometryType})}}),e.on(`cursor-update`,t=>{e.drawOperation.numCommittedVertices>0&&this.emit(`create`,{graphic:e.graphic,state:`active`,tool:this.activeTool,toolEventInfo:{coordinates:t.vertices[0].coordinates,type:`cursor-update`},type:`create`})}),e.on(`vertex-remove`,t=>{switch(o.notify(),t.operation){case`apply`:this.emit(`create`,{graphic:e.graphic,state:`active`,tool:this.activeTool,toolEventInfo:t,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[e.graphic],tool:e.geometryType});break;case`redo`:this._emitRedoEvent({graphics:[e.graphic],tool:e.geometryType})}}),e.on(`complete`,e=>{this._set(`createGraphic`,e.graphic),r=`complete`,e.aborted?u&&u.cancel():u&&u.complete()}),_(()=>this._getGraphicSymbolFromTool(t),t=>{e.graphicSymbol=t})],u=new je({activeComponent:e,type:`create`,onEnd:()=>{c(l),n.tools?.remove(e)},undo:()=>{e.canUndo&&e.undo()},redo:()=>{e.canRedo&&e.redo()},canUndo:()=>(x(o),e.canUndo),canRedo:()=>(x(o),e.canRedo)});return u}_setupDrawToolOperationHandle(e,t){let r=this.view;if(!r)return this._logMissingView(),null;let i=null,a=[r.on(`key-down`,t=>{t.key===A.pan&&(t.stopPropagation(),t.repeat||(e.editable=!1))},k.WIDGET),r.on(`key-up`,t=>{t.key===A.pan&&(e.editable=!0)},k.WIDGET),e.on(`before-vertex-add`,t=>{let n=e.mostUpstreamPlugin?.configuration;if(n&&`legacyCreateTool`in n&&(n?.legacyCreateTool===`point`||n.legacyCreateTool===`text`)){let e=t.detail.originalEvent;e&&`key`in e&&e.key===A.vertexAdd&&t.preventDefault()}}),e.on(`before-complete`,t=>{let n=e.getGeometryIfCompleted();(!n||Fe(n))&&t.preventDefault()}),e.on([`vertex-add`,`vertex-remove`],r=>{switch(this.createGraphic&&(this.createGraphic.geometry=e.getGeometryIfCompleted()),i=i==null&&r.type!==`vertex-remove`?`start`:`active`,r.operation){case`apply`:this.emit(`create`,{graphic:this.createGraphic,state:i,tool:this.activeTool,toolEventInfo:r,type:`create`});break;case`undo`:this._emitUndoEvent({graphics:[this.createGraphic].filter(n),tool:t});break;case`redo`:this._emitRedoEvent({graphics:[this.createGraphic].filter(n),tool:t})}}),e.on(`cursor-update`,t=>{this.createGraphic&&(this.createGraphic.geometry=e.unprocessedGeometry),(t.vertices[0]?.vertexIndex>0||t.vertices[0]?.componentIndex>0)&&this.emit(`create`,{graphic:this.createGraphic,state:`active`,tool:this.activeTool,toolEventInfo:{coordinates:t.vertices[0].coordinates,type:`cursor-update`},type:`create`})}),e.on(`complete`,async({geometry:t,isSimple:n})=>{let r=this.createGraphic,i=!!t&&t.type!==`mesh`&&t.type!==`extent`&&!n;if(r&&(r.geometry=n?t:e.unprocessedGeometry??t),!i||!r)o.complete();else{this._internalGraphicsLayer.add(this.createGraphic);let e=new AbortController;this._drawToolSimplifyAbortController?.abort(),this._drawToolSimplifyAbortController=e,await this._updatingHandles.addPromise(h(this._finalizeDrawToolCompletion({abortController:e,geometry:t,graphic:r,handle:o})))}})],o=new Me({activeComponent:e,type:`create`,onEnd:()=>{c(a),r.tools.remove(e)},undo:()=>e.undo(),redo:()=>e.redo(),canUndo:()=>e.canUndo,canRedo:()=>e.canRedo});return a.push(e.on(`cancel`,()=>{this._drawToolSimplifyAbortController=f(this._drawToolSimplifyAbortController),o.cancel()})),o}async _finalizeDrawToolCompletion({abortController:e,geometry:t,graphic:n,handle:r}){let i=this.view?.acquireCursor(`progress`,`high`);i&&this.addHandles(i);let a=()=>e.signal.aborted?(n&&(this._layerAdapter?.remove(n),this._internalGraphicsLayer?.remove(n)),this._set(`createGraphic`,null),!0):!1;try{let i=await this._geometryWorkerHandle.simplify(t,e.signal);if(a())return;n.geometry=i??t,this._internalGraphicsLayer?.remove(n),r.complete()}finally{i?.remove(),this._drawToolSimplifyAbortController===e&&(this._drawToolSimplifyAbortController=null)}}_getGraphicSymbolFromTool(e){switch(e){case`point`:case`multipoint`:return this.pointSymbol;case`polyline`:case`freehandPolyline`:return this.polylineSymbol;case`circle`:case`rectangle`:case`polygon`:case`freehandPolygon`:return this.polygonSymbol;case`mesh`:return this.meshSymbol;case`text`:return this.textSymbol}}async _setupUpdateOperation(e,t){let{view:n}=this;if(!n)return this._logMissingView(),null;let r={...this.defaultUpdateOptions,...t,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...t?.reshapeOptions},highlightOptions:{...this.defaultUpdateOptions.highlightOptions,...t?.highlightOptions}};this.activeUpdateOptions=r;let i=r.tool??H.tool;if(this.removeGraphics(e),this.addGraphics(e),n.type===`3d`){if(e.length===0)return null;switch(i){case`move`:return this._setupMove3DOperation(e,r,n,i);case`reshape`:return e.length>1?(this._logError(`sketch:reshape-multiple`,`Reshape operation does not support multiple graphics.`),null):this._setupReshape3DOperation(e[0],r,n);case`transform`:return this._setupGraphicTransform3DOperation(e,r,n)}}switch(i){case`move`:return this._setupMove2DOperation(e,r,n);case`reshape`:return e.length>1?(this._logError(`sketch:reshape-multiple`,`Reshape operation does not support multiple graphics.`),null):this._setupTransformOrReshape2DOperation(e,i,r,n);case`transform`:return B(e)&&(i=`reshape`),this._setupTransformOrReshape2DOperation(e,i,r,n)}}async _setupMove3DOperation(e,t,n,r,i=!1){let a=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(a))return a;let{ManipulatedObject3DGraphic:o,MoveTool3D:s}=a.module,l=new Map,u=()=>{l.forEach(e=>e.destroy()),l.clear()};for(let t of e){let e=new o({view:n,graphic:t}),r=ve(e);if(r!==0)return u(),this._logError(`sketch:move`,`Move operation not supported for provided graphic(s) (${D(r)}).`),null;l.set(t,e)}let d=new s({view:n,enableZ:t.enableZ,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(d),d.objects.addMany(Array.from(l.values())),i||this.updateGraphics.addMany(e);let f=[],p=new R({activeComponent:d,tool:r,type:`update`,onEnd:()=>{c(f),Q(n,d),u()},undo:()=>{X(this.view,d),q(p,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r})},redo:()=>{J(p,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r})},addToSelection:async e=>{this.updateGraphics.push(e);let t=new o({view:n,graphic:e});l.set(e,t),d.objects.push(t),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);if(p.history.undo.forEach(e=>e.updates.splice(t,1)),p.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),this.updateGraphics.length===0){p.complete();return}let n=l.get(e);n&&(d.objects.remove(n),n.destroy(),l.delete(e))},toggleTool:async()=>{if(this.updateGraphics.length!==1||t.toggleToolOnClick===!1||r!==`transform`)return;let e=this.updateGraphics.at(0),i=await this._updatingHandles.addPromise(this._setupReshape3DOperation(e,t,n,!0));i&&!$(i)&&(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(i,t))}});return f.push(...this._getHandlesForComponent(p,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(p,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(p,e)},k.WIDGET)),p}_setupGraphicTransform3DOperation(e,t,n,r=!1){if(e.length===1&&be(e[0])===0){let i=e[0],a=i.geometry;if(a!=null&&(a.type===`point`||a.type===`mesh`))return this._setupPointTransform3DOperation(i,t,n);if(a!=null&&(a.type===`polygon`||a.type===`polyline`))return this._setupPolyTransform3DOperation(i,t,n,r)}return this._setupMove3DOperation(e,t,n,`transform`,r)}async _setupPointTransform3DOperation(e,t,n){let r=`transform`,{enableRotation:i,enableScaling:a,enableZ:o}=t,s=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(s))return s;let{TransformTool3D:l,ManipulatedObject3DGraphic:u}=s.module,d=new u({graphic:e,view:n}),f=new l({object:d,view:n,enableRotation:i,enableScaling:a,enableZ:o,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(f),this.updateGraphics.add(e);let p=[],m=new R({activeComponent:f,tool:r,type:`update`,onEnd:()=>{c(p),Q(n,f),d.destroy()},undo:()=>{X(this.view,f),q(m,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r})},redo:()=>{J(m,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r})},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(m,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),m.complete()},toggleTool:async()=>{}});return p.push(...this._getHandlesForComponent(m,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(m,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(m,e)},k.WIDGET)),m}async _setupPolyTransform3DOperation(e,t,n,r=!1){let i=`transform`,{enableRotation:a,enableScaling:o,enableZ:s,preserveAspectRatio:l}=t,u=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(u))return u;let{ManipulatedObject3DGraphic:d,ExtentTransformTool:f}=u.module,p=this.view?.inputManager?.isModifierKeyDown(A.constraint),m=new d({view:n,graphic:e}),h=new f({object:m,view:n,enableRotation:a,enableScaling:o,enableZ:s,preserveAspectRatio:!!l!=!!p,toolOptions:this._operationToolOptions});n.tools.add(h),r||this.updateGraphics.add(e);let g=[],_=new R({activeComponent:h,tool:i,type:`update`,onEnd:()=>{c(g),Q(n,h),m.destroy()},canUndo:()=>!h.destroyed&&h.canUndo,undo:()=>{h.destroyed||(h.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},canRedo:()=>!h.destroyed&&h.canRedo,redo:()=>{h.destroyed||(h.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(_,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),_.complete()},toggleTool:async()=>{if(this.updateGraphics.length!==1||t.toggleToolOnClick===!1)return;let r=await this._updatingHandles.addPromise(this._setupReshape3DOperation(e,t,n,!0));r&&!$(r)&&(_.onEnd(),_.destroy(),this._setUpdateOperationHandle(r,t))}});return g.push(...this._getHandlesForComponent(_,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(_,e,t),k.WIDGET),n.on(`key-down`,e=>this._getCommonUpdateOperationKeyDownHandlers(_,e),k.WIDGET),n.on(`key-down`,e=>{e.key===A.constraint&&!e.repeat&&(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())},k.WIDGET),n.on(`key-up`,e=>{e.key===A.constraint&&(h.preserveAspectRatio=!h.preserveAspectRatio,e.stopPropagation())},k.WIDGET)),_}async _setupMove2DOperation(e,t,n){let r=`move`;this.updateGraphics.addMany(e),await this._updatingHandles.addPromise(this._updateSpatialReference(e));let i=await this._updatingHandles.addPromise(this._getGraphicMover(e,t,n));if($(i))return i;let a=new R({activeComponent:i,tool:r,type:`update`,onEnd:()=>{this._clearCursor(),c(l),c(s),i.destroy(),this._internalGraphicsLayer?.removeMany([...this.updateGraphics.toArray()])},undo:()=>{let e=this.updateGraphics.toArray();q(a,e),a.refreshComponent(),this._emitUndoEvent({graphics:e,tool:r})},redo:()=>{let e=this.updateGraphics.toArray();J(a,e),a.refreshComponent(),this._emitRedoEvent({graphics:e,tool:r})},addToSelection:async e=>{await this._updatingHandles.addPromise(this._updateSpatialReference(e)),this.updateGraphics.push(e),i.graphics=this.updateGraphics.toArray(),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);a.history.undo.forEach(e=>e.updates.splice(t,1)),a.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e);let n=this.updateGraphics.toArray();this.emit(`update`,{graphics:n,state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),this.updateGraphics.length===0?a.complete():i.graphics=n}}),o=!1,s=[n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(a,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(a,e),e.key===A.constraint&&!e.repeat&&(o=!0,i.enableMoveAllGraphics=!i.enableMoveAllGraphics)},k.WIDGET),n.on(`key-up`,e=>{e.key===A.constraint&&o&&(o=!1,i.enableMoveAllGraphics=!i.enableMoveAllGraphics)},k.WIDGET)],l=this._getHandlesForComponent(a,t);return a}async _setupReshape3DOperation(e,t,n,r=!1){let i=`reshape`,a=await this._requireModule(import(`../../views/3d/interactive/editingTools.js`));if($(a))return a;let{ManipulatedObject3DGraphic:o,ReshapeTool3D:s}=a.module,l=new o({view:n,graphic:e}),u=ye(l);if(u!==0)return l.destroy(),this._logError(`sketch:reshape`,`Reshape operation not supported for provided graphic(s) (${D(u)}).`),null;let d=t.reshapeOptions,f=new s({view:n,object:l,enableZVertex:t.enableZ&&d?.vertexOperation===`move`,enableZShape:t.enableZ&&d?.shapeOperation===`move`,enableMoveObject:d?.shapeOperation===`move`||d?.shapeOperation===`move-xy`,enableMidpoints:d?.edgeOperation===`split`,enableEdgeOffset:d?.edgeOperation===`offset`,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions});n.tools.add(f),r||this.updateGraphics.add(l.graphic);let p=[],m=new R({activeComponent:f,tool:i,type:`update`,onEnd:()=>{c(p),Q(n,f),l.destroy()},canUndo:()=>!f.destroyed&&f.canUndo,undo:()=>{f.destroyed||(f.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},canRedo:()=>!f.destroyed&&f.canRedo,redo:()=>{f.destroyed||(f.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i}))},addToSelection:async e=>{this.updateGraphics.add(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`}),await this._replaceUpdateOperationHandle(m,t,()=>this._setupMove3DOperation(this.updateGraphics.toArray(),t,n,`transform`,!0))},removeFromSelection:async e=>{this.updateGraphics.remove(e),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`}),m.complete()},toggleTool:async()=>{t.toggleToolOnClick!==!1&&await this._replaceUpdateOperationHandle(m,t,()=>this._setupGraphicTransform3DOperation(this.updateGraphics.toArray(),t,n,!0))}});return p.push(...this._getHandlesForComponent(m,t),n.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(m,e,t),k.WIDGET),n.on(`key-down`,e=>{this._getCommonUpdateOperationKeyDownHandlers(m,e)},k.WIDGET)),m}async _setupTransformOrReshape2DOperation(e,t,n,r){this.updateGraphics.addMany(e),await this._updatingHandles.addPromise(this._updateSpatialReference(e));let i=await this._updatingHandles.addPromise(t===`transform`?this._getBox(e,n,r):this._getReshape(e,n,r));if($(i))return i;let a=new R({activeComponent:i,type:`update`,onEnd:()=>{c(s),c(o),a.activeComponent&&!a.activeComponent.destroyed&&a.activeComponent.destroy(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray())},undo:()=>{q(a,this.updateGraphics.toArray()),a.refreshComponent(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a.tool})},redo:()=>{J(a,this.updateGraphics.toArray()),a.refreshComponent(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a.tool})},addToSelection:async e=>{let t=a.activeComponent;if(t?.type===`reshape`){let t=[...this.updateGraphics,e];if(this.updateGraphics.removeAll(),!await this._replaceUpdateOperationHandle(a,n,()=>this._setupTransformOrReshape2DOperation(t,`transform`,n,r)))return}else this.updateGraphics.add(e),t=t,t.graphics=this.updateGraphics.toArray(),t.refresh(),a.resetHistory();this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[e],removed:[],type:`selection-change`},type:`update`})},removeFromSelection:async e=>{let t=this.updateGraphics.indexOf(e);a.history.undo.forEach(e=>e.updates.splice(t,1)),a.history.redo.forEach(e=>e.updates.splice(t,1)),this.updateGraphics.remove(e);let n=this.updateGraphics.toArray();n.length===0?a.complete():B(n)?await a.toggleTool():a.activeComponent.graphics=n,this.emit(`update`,{graphics:n,state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[e],type:`selection-change`},type:`update`})},toggleTool:async()=>{if(this.updateGraphics.length>1)return;let e=this.updateGraphics.at(0),t=e.geometry;if(t!=null&&(a.tool===`reshape`&&t.type===`point`||a.tool===`transform`&&t.type===`extent`))return;let i=null,o={...this.defaultUpdateOptions,...n,...this.activeUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...n?.reshapeOptions,...this.activeUpdateOptions?.reshapeOptions},highlightOptions:{...this.defaultUpdateOptions.highlightOptions,...n?.highlightOptions,...this.activeUpdateOptions?.highlightOptions}};a.tool===`transform`?i=await this._updatingHandles.addPromise(this._getReshape([e],o,r)):a.tool===`reshape`&&(i=await this._updatingHandles.addPromise(this._getBox([e],o,r))),!$(i)&&(a.activeComponent?.destroy(),a.activeComponent=i,a.activeComponent&&(c(s),s=this._getHandlesForComponent(a,o)))}}),o=[r.on(`immediate-click`,e=>this._getCommonUpdateOperationClickHandlers(a,e,n),k.WIDGET),r.on(`key-down`,e=>{if(this._getCommonUpdateOperationKeyDownHandlers(a,e),e.key===A.constraint&&!e.repeat&&a){let e=a.activeComponent;e?.type===`box`&&(e.preserveAspectRatio=!e.preserveAspectRatio)}},k.WIDGET),r.on(`key-up`,e=>{if(e.key===A.constraint&&a){let e=a.activeComponent;e?.type===`box`&&(e.preserveAspectRatio=!e.preserveAspectRatio)}},k.WIDGET)],s=this._getHandlesForComponent(a,n);return a}async _getGraphicMover(e,t,n){let{enableMoveAllGraphics:r,highlightOptions:i}=t,a=await this._requireModule(import(`../../views/draw/support/GraphicMover.js`));return $(a)?a:new a.module.default({enableMoveAllGraphics:r,highlightName:i?.name,highlightsEnabled:!!i?.enabled,indicatorsEnabled:!1,graphics:e,view:n,callbacks:{onGraphicMoveStart:({dx:e,dy:t,graphic:n})=>{this._displayCursor(`grabbing`),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move-start`},type:`update`})},onGraphicMove:({dx:e,dy:t,graphic:n})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move`},type:`update`}),onGraphicMoveStop:({dx:e,dy:t,graphic:n})=>{this._displayCursor(`pointer`),this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:`move-stop`},type:`update`})},onGraphicPointerOver:()=>this._displayCursor(`move`),onGraphicPointerOut:()=>this._clearCursor()}})}async _getBox(e,t,n){let{enableRotation:r,enableScaling:i,highlightOptions:a,preserveAspectRatio:o}=t,s=await this._requireModule(import(`../../views/draw/support/Box.js`));if($(s))return s;let c=this.view?.inputManager?.isModifierKeyDown(A.constraint),l=new s.module.default({graphics:e,enableRotation:r,enableScaling:i,highlightName:a?.name,highlightsEnabled:!!a?.enabled,preserveAspectRatio:!!o!=!!c,layer:this._internalGraphicsLayer,view:n,toolOptions:this._operationToolOptions,callbacks:{onMoveStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onMove:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onMoveStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScaleStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScale:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onScaleStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotateStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotate:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onRotateStop:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`})}});return l.addHandles(_(()=>[this.activeUpdateOptions?.enableRotation,this.activeUpdateOptions?.enableScaling],([e,n])=>{l.enableRotation=e??t.enableRotation??!0,l.enableScaling=n??t.enableScaling??!0,l.refresh()},v)),l}async _getReshape(e,t,n){let{highlightOptions:r,reshapeOptions:i}=t,a=i?.edgeOperation===`split`,o=i?.shapeOperation===`move`,s=!!i?.enableCreateCurveFromStraightEdge,c=await this._requireModule(import(`../../views/draw/support/Reshape.js`));return $(c)?c:new c.module.default({enableMidpoints:a,enableMovement:o,enableCurveOnMidpoint:s,graphic:e[0],highlightName:r?.name,highlightsEnabled:!!r?.enabled,layer:this._internalGraphicsLayer,snappingManager:this._operationSnappingManager,toolOptions:this._operationToolOptions,view:n,callbacks:{onReshapeStart:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onReshape:e=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e},type:`update`}),onReshapeStop:({mover:e,type:t})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e,type:t},type:`update`}),onMoveStart:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onMove:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onMoveStop:({dx:e,dy:t,mover:n,type:r})=>this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e,dy:t,mover:n,type:r},type:`update`}),onVertexAdd:({added:e,type:t,vertices:n})=>{let r=e.map(e=>C(e.geometry));this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{added:r,vertices:n,type:t},type:`update`})},onVertexRemove:({removed:e,type:t,vertices:n})=>{let r=e.map(e=>C(e.geometry));this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{removed:r,vertices:n,type:t},type:`update`})}}})}_getHandlesForComponent(e,t){let n=e.activeComponent;if(!n)return[];switch(n.type){case`graphic-mover`:return[n.on(`graphic-click`,({graphic:n,viewEvent:r})=>{r.native?.shiftKey&&t.multipleSelectionEnabled&&(r.stopPropagation(),this._updatingHandles.consumePromise(e.removeFromSelection(n)))}),n.on(`graphic-move-start`,t=>e.addToHistory(Z(t.allGraphics)))];case`box`:return[n.on(`graphic-click`,n=>this._onTransformOrReshape2DGraphicClick(e,t,n)),n.on(`move-start`,t=>e.addToHistory(Z(t.graphics))),n.on(`rotate-start`,t=>e.addToHistory(Z(t.graphics))),n.on(`scale-start`,t=>e.addToHistory(Z(t.graphics)))];case`reshape`:return[n.on(`graphic-click`,n=>this._onTransformOrReshape2DGraphicClick(e,t,n)),n.on(`move-start`,t=>e.addToHistory(Z([t.mover]))),n.on(`reshape-start`,t=>e.addToHistory(Z([t.graphic]))),n.on(`vertex-add`,t=>e.addToHistory(Z([t.oldGraphic]))),n.on(`vertex-remove`,t=>e.addToHistory(Z([t.oldGraphic])))];case`move-3d`:return[n.events.on(`record-undo`,({updates:t})=>{e.addToHistory({updates:t})}),n.events.on(`move-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move-start`},type:`update`})}),n.events.on(`move`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:e.dx,dy:e.dy,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move`},type:`update`})}),n.events.on(`move-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.objects.length>0?e.objects[0].graphic:null,type:`move-stop`},type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})];case`transform-3d`:return[n.events.on(`record-undo`,({updates:t})=>{e.addToHistory({updates:t})}),n.events.on(`translate-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move-start`},type:`update`})}),n.events.on(`translate-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move-stop`},type:`update`})}),n.events.on(`rotate-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate-start`},type:`update`})}),n.events.on(`rotate-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate-stop`},type:`update`})}),n.events.on(`scale-start`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale-start`},type:`update`})}),n.events.on(`scale-stop`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale-stop`},type:`update`})}),n.events.on(`translate`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,dx:e.dxScreen,dy:e.dyScreen,type:`move`},type:`update`})}),n.events.on(`rotate`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,angle:e.angle,type:`rotate`},type:`update`})}),n.events.on(`scale`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{mover:e.object.graphic,xScale:e.xScale,yScale:e.yScale,type:`scale`},type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})];case`reshape-3d`:return[n.events.on(`reshape`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e,mover:e.object.graphic},type:`update`})}),n.events.on(`move`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:{...e,mover:e.object.graphic},type:`update`})}),n.events.on(`vertex-add`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:e,type:`update`})}),n.events.on(`vertex-remove`,e=>{this.emit(`update`,{graphics:this.updateGraphics.toArray(),state:`active`,aborted:!1,tool:this.activeTool,toolEventInfo:e,type:`update`})}),n.events.on(`immediate-click`,n=>{this._updatingHandles.consumePromise(n.shiftKey?this._toggleSelection([n.object.graphic],e,t):e.toggleTool())})]}}_onTransformOrReshape2DGraphicClick(e,t,n){let{graphic:r,viewEvent:i}=n;i.native?.shiftKey&&this.hasGraphic(r)?(i.stopPropagation(),this._updatingHandles.consumePromise(e.removeFromSelection(r))):t.toggleToolOnClick&&(i.stopPropagation(),this._updatingHandles.consumePromise(e.toggleTool()))}async _replaceUpdateOperationHandle(e,t,n){let r=this._operationContext;e.onEnd(),e.destroy();let i=await this._updatingHandles.addPromise(n());return!i||$(i)||r!==this._operationContext?(i&&!$(i)&&(i.onEnd(),i.destroy()),this._destroyOperationContext(r),!1):(this._setUpdateOperationHandle(i,t),!0)}_setUpdateOperationHandle(e,t){this._operationHandle=e;let n=this.view?.map;this._disablePopup(t),e.on(`complete`,()=>{if(e===this._operationHandle){let r=this.updateGraphics.toArray(),i=this._operationHandle.tool;this._operationHandle.destroy(),this._operationHandle=null,this._destroyOperationContext(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray()),this.updateGraphics.removeAll(),n&&n.remove(this._internalGraphicsLayer),this._restorePopup(t),this.emit(`update`,{graphics:r,state:`complete`,aborted:e.cancelled,tool:i,toolEventInfo:null,type:`update`})}})}_getCommonUpdateOperationClickHandlers(e,t,n){return this._updatingHandles.addPromise(this._handleCommonUpdateOperationClick(e,t,n))}async _handleCommonUpdateOperationClick(e,t,n){let r=L(t),i=await t.defer(()=>this._getFirstHit(r));if(i==null){this.cancelUpdateOnClickAway&&e.complete();return}let a=t.native.shiftKey?this._toggleSelection([i.graphic],e,n):null;a?(t.stopPropagation(),await a):this.updateGraphics.includes(i.graphic)?this._shouldTemporarilyDisablePopup(n)&&t.stopPropagation():e.complete()}async _toggleSelection(e,t,n){let r=!!n.multipleSelectionEnabled;for(let n of e)if(n!=null&&r&&this.hasGraphic(n))return this.updateGraphics.includes(n)?await t.removeFromSelection(n):await t.addToSelection(n)}_getCommonUpdateOperationKeyDownHandlers(e,t){if(!e)return;let n=t.key;n===A.undo&&e.canUndo()?(t.stopPropagation(),e.undo()):n===A.redo&&e.canRedo()?(t.stopPropagation(),e.redo()):n===A.cancel?(t.stopPropagation(),e.cancel()):this.allowDeleteKey&&A.delete.includes(n)&&this._onDeleteKey(t)}_onDeleteKey(e){this._operationHandle&&this._operationHandle.type===`update`&&this.activeComponent!=null&&(e.stopPropagation(),this.delete())}_removeDefaultLayer(){this._internalGraphicsLayer&&=(this.view?.map?.remove(this._internalGraphicsLayer),d(this._internalGraphicsLayer))}_isComponentGraphic(e){let{activeComponent:t}=this;return!e||t==null?!1:e.attributes?.esriSketchTool||t.type===`draw-2d`&&t.graphic===e||(t.type===`box`||t.type===`reshape`)&&t.isUIGraphic(e)}_clearCursor(){this.removeHandles(U)}_displayCursor(e){this.removeHandles(U),this.view?.container&&e!=null&&this.addHandles(this.view.acquireCursor(e,`high`),U)}_logError(e,t,n){u.getLogger(this).error(new i(e,t,n))}async _requireModule(e){let t=new AbortController;this._moduleLoaderAbortController=t;let n=await e;return this._moduleLoaderAbortController!==t||t.signal.aborted?{requireError:`aborted`}:{module:n}}_emitUndoEvent(e){this.emit(`undo`,{...e,type:`undo`})}_emitRedoEvent(e){this.emit(`redo`,{...e,type:`redo`})}_emitDeleteEvent(e){this.emit(`delete`,{...e,type:`delete`})}_onLayerGraphicsChangeCallback(e){if(this._operationHandle!=null){let{updateGraphics:t}=this;for(let n of e.removed)if(t.includes(n)){if(t.length>1)this._updatingHandles.consumePromise(this._operationHandle.removeFromSelection(n));else{this._operationHandle.cancel();break}}}}async _setupAdvancedDrawToolIntegrationMaybe(){this.isUsingLegacyCreateTools||this.pluginManager.loaded||await this.pluginManager.loadPlugins()}async _setupDrawTool(e,n,r){if(this.isUsingLegacyCreateTools||!this._pluginManager)return null;let i=this.view,a=await import(`../../views/draw/DrawTool.js`);await this.pluginManager.loadPlugins();let o=await this.pluginManager.makeRenderer({customSymbol:n.graphicSymbol,useTextSymbol:r===`text`}),s=new a.DrawTool({view:i,elevationInfo:this._layerAdapter?.elevationInfo??pe(i.type===`3d`),hasZ:!!n.hasZ,toolOptions:this._operationToolOptions,renderer:o,defaultZ:n.defaultZ??0,directionOptions:n.directionOptions,snappingManager:this._operationSnappingManager,enableVertexVisuals:r!==`rectangle`&&r!==`circle`,readPluginSetting:(e,t)=>this.settingsManager.getValue(t)});s.addHandles(l(o));let c=new t({...n.graphicProperties,attributes:{...n.graphicProperties?.attributes},symbol:n.graphicSymbol??this._getGraphicSymbolFromTool(r)});return n.graphicSymbol||s.addHandles(_(()=>this._getGraphicSymbolFromTool(r),e=>c.symbol=e)),this._set(`createGraphic`,c),i.addAndActivateTool(s),s.begin(e),s}get test(){}wait(){return y(()=>!this.updating)}_shouldTemporarilyDisablePopup(e){return this.updateOnGraphicClick||(e?.toggleToolOnClick??!1)}_disablePopup(e){this._shouldTemporarilyDisablePopup(e)&&this.view&&this._originalPopupEnabled==null&&(this._originalPopupEnabled=this.view.popupEnabled,this.view.popupEnabled=!1)}_restorePopup(e){this._shouldTemporarilyDisablePopup(e)&&this.view&&this._originalPopupEnabled!=null&&(this.view.popupEnabled=this._originalPopupEnabled,this._originalPopupEnabled=null)}async _waitViewReady(){let e=this.view;e?(f(this._viewReadyAbortController),this._viewReadyAbortController=new AbortController,await g(y(()=>e?.ready),this._viewReadyAbortController.signal)):this._logMissingView()}_logMissingView(){this._logError(`sketch:missing-property`,K(`view`))}_logMissingLayer(){this._logError(Re,K(`layer`))}};e([b()],G.prototype,`_defaultSnappingManager`,void 0),e([b()],G.prototype,`_operationContext`,void 0),e([b()],G.prototype,`_layerAdapter`,null),e([b()],G.prototype,`_pluginManager`,void 0),e([b({readOnly:!0})],G.prototype,`settingsManager`,void 0),e([b()],G.prototype,`_operationHandle`,void 0),e([b({readOnly:!0})],G.prototype,`_updatingHandles`,void 0),e([b({readOnly:!0})],G.prototype,`_toolTransitionHandles`,void 0),e([b()],G.prototype,`_drawToolSimplifyAbortController`,void 0),e([b({readOnly:!0})],G.prototype,`activeTool`,null),e([b()],G.prototype,`geometrySimplificationInProgress`,null),e([b({readOnly:!0})],G.prototype,`activeCreateToolDrawMode`,null),e([b()],G.prototype,`activeTooltip`,null),e([b({types:E})],G.prototype,`activeFillSymbol`,void 0),e([b()],G.prototype,`activeLineSymbol`,void 0),e([b()],G.prototype,`activeVertexSymbol`,void 0),e([b()],G.prototype,`allowDeleteKey`,void 0),e([b({readOnly:!0})],G.prototype,`createGraphic`,null),e([b()],G.prototype,`defaultCreateOptions`,null),e([b()],G.prototype,`defaultUpdateOptions`,null),e([b()],G.prototype,`activeUpdateOptions`,void 0),e([b({type:M,nonNullable:!0})],G.prototype,`labelOptions`,null),e([b()],G.prototype,`layer`,void 0),e([b({types:E})],G.prototype,`pointSymbol`,void 0),e([b({types:E})],G.prototype,`polygonSymbol`,void 0),e([b({types:E})],G.prototype,`polylineSymbol`,void 0),e([b()],G.prototype,`meshSymbol`,void 0),e([b({type:T})],G.prototype,`textSymbol`,null),e([b({type:F,nonNullable:!0})],G.prototype,`snappingOptions`,null),e([b()],G.prototype,`snappingManager`,null),e([b({readOnly:!0})],G.prototype,`state`,null),e([b()],G.prototype,`toolTransitionInProgress`,null),e([b({type:Se,nonNullable:!0})],G.prototype,`tooltipOptions`,null),e([b({readOnly:!0})],G.prototype,`updateGraphics`,void 0),e([b()],G.prototype,`updateOnGraphicClick`,void 0),e([b()],G.prototype,`useViewOptions`,void 0),e([b()],G.prototype,`cancelUpdateOnClickAway`,void 0),e([b()],G.prototype,`updating`,null),e([b()],G.prototype,`creationMode`,void 0),e([b({type:Ce,nonNullable:!0})],G.prototype,`valueOptions`,null),e([b({types:E})],G.prototype,`vertexSymbol`,void 0),e([b({value:null})],G.prototype,`view`,null),e([b({constructOnly:!0,type:N})],G.prototype,`sketchOptions`,void 0),e([b()],G.prototype,`useLegacyCreateTools`,void 0),e([b()],G.prototype,`isUsingLegacyCreateTools`,null),e([b()],G.prototype,`pluginManager`,null),e([b()],G.prototype,`drawTool`,null),e([b()],G.prototype,`activePluginConfigurations`,null),e([b()],G.prototype,`rootPlugins`,null),e([b()],G.prototype,`effectiveAvailablePlugins`,null),e([b()],G.prototype,`firstPluginWithSwappableLeaf`,null),e([b()],G.prototype,`multiplePluginsActive`,null),G=e([re(`esri.widgets.Sketch.SketchViewModel`)],G);const Re=`sketch:missing-property`,K=e=>`Property '${e}' is missing on SketchViewModel.`;function ze(e){return e===`polygon`||e===`rectangle`||e===`circle`}function q(e,t){Y(`undo`,e.history.undo,e.history.redo,t)}function J(e,t){Y(`redo`,e.history.redo,e.history.undo,t)}function Y(e,t,n,r){let i=t.pop();if(!i)return;let a=i.updates,o=[];r.forEach((t,n)=>{let r=a[n];r!=null&&(`geometry`in r&&r.geometry!=null&&(o.push({geometry:t.geometry}),t.geometry=r.geometry),`symbol`in r&&r.symbol!=null&&(o.push({symbol:t.symbol}),t.symbol=r.symbol),`undo`in r&&(o.push(r),r[e](t)))}),n.push({updates:o})}function X(e,t){e!=null&&t.hasGrabbedManipulators&&(e.activeTool=null)}function Z(e){return{updates:e.map(({geometry:e})=>e?.type===`mesh`?{geometry:e.cloneShallow()}:{geometry:e})}}function Q(e,t){e.tools?.remove(t),t.destroyed||t.destroy()}function $(e){return`requireError`in e&&e.requireError===`aborted`}export{G as default};