@arcgis/core 5.0.0-next.38 → 5.0.0-next.39

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 (108) hide show
  1. package/Color.js +1 -1
  2. package/analysis/DimensionSimpleStyle.js +1 -1
  3. package/analysis/ElevationProfileAnalysis.js +1 -1
  4. package/assets/esri/core/workers/RemoteClient.js +1 -1
  5. package/assets/esri/core/workers/chunks/02a65563779b4c64b2cf.js +1 -0
  6. package/assets/esri/core/workers/chunks/{328106e181e5957ceaa5.js → 09ac2bbc7327e6e6b5a2.js} +1 -1
  7. package/assets/esri/core/workers/chunks/1a9ed3c59a9a8bafb251.js +1 -0
  8. package/assets/esri/core/workers/chunks/{b96af22ec1470905e4fb.js → 1c857191e5898aba50fe.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{3904f8732c9953cb177d.js → 28b235b56a83c498d73f.js} +1 -1
  10. package/assets/esri/core/workers/chunks/36d15c35fbbd4dedd5cb.js +1 -0
  11. package/assets/esri/core/workers/chunks/48f805929fe6241952f5.js +1 -0
  12. package/assets/esri/core/workers/chunks/4c278fb2d51ca6226050.js +1 -0
  13. package/assets/esri/core/workers/chunks/6052eccb9395c8efb295.js +1 -0
  14. package/assets/esri/core/workers/chunks/{50ffb22c48fadd36c748.js → 613cbac9cb925cd20b48.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{febce0d80f019dc2a427.js → 646f58b69d2354f1ef27.js} +1 -1
  16. package/assets/esri/core/workers/chunks/7eab0bb42f9f062522ef.js +1 -0
  17. package/assets/esri/core/workers/chunks/{5e34a183420e7007a989.js → 8e8d5422f57269d8c8d2.js} +1 -1
  18. package/assets/esri/core/workers/chunks/9100330ed4b4437c819d.js +1 -0
  19. package/assets/esri/core/workers/chunks/95cb062cae4c31c07124.js +1 -0
  20. package/assets/esri/core/workers/chunks/{7ab237d19b84d89ff483.js → 96f798ee286b59396131.js} +50 -50
  21. package/assets/esri/core/workers/chunks/{e9bc3c6482ba778c9349.js → 9d95f38da21f97214f83.js} +1 -1
  22. package/assets/esri/core/workers/chunks/ad4fcb73cfe9a1e4b710.js +1 -0
  23. package/assets/esri/core/workers/chunks/{a8a017d7969562d21d2e.js → b48aceaeefa07214e430.js} +1 -1
  24. package/assets/esri/core/workers/chunks/c1a4d1ec0125617374b4.js +1 -0
  25. package/assets/esri/core/workers/chunks/{d2a6f035022a3f060ffa.js → c320a29df40e85fb4a8e.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{27ec791318e81285c222.js → dca6a61fd239cf1ff90c.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{2f9129003f77bfeab2f9.js → e66bcdfd75e0113d1cec.js} +1 -1
  28. package/assets/esri/core/workers/chunks/f1381c5a2a1de1ef9139.js +1 -0
  29. package/assets/esri/core/workers/chunks/f21cb5b34d4d1e3af1a9.js +1 -0
  30. package/chunks/ChapmanAtmosphere.glsl.js +20 -20
  31. package/chunks/HUDMaterial.glsl.js +38 -38
  32. package/chunks/Haze.glsl.js +23 -23
  33. package/config.js +1 -1
  34. package/core/Collection.js +1 -1
  35. package/core/CollectionFlattener.js +1 -1
  36. package/core/arrayUtils.js +1 -1
  37. package/interfaces.d.ts +50 -0
  38. package/kernel.js +1 -1
  39. package/layers/ImageryTileLayer.js +1 -1
  40. package/layers/RouteLayer.js +1 -1
  41. package/layers/support/FeatureReductionCluster.js +1 -1
  42. package/layers/support/LabelClass.js +1 -1
  43. package/package.json +3 -3
  44. package/renderers/FlowRenderer.js +1 -1
  45. package/renderers/HeatmapRenderer.js +1 -1
  46. package/renderers/PieChartRenderer.js +1 -1
  47. package/rest/route/utils.js +1 -1
  48. package/rest/support/PointBarrier.js +1 -1
  49. package/rest/support/Stop.js +1 -1
  50. package/support/revision.js +1 -1
  51. package/symbols/Font.js +1 -1
  52. package/symbols/IconSymbol3DLayer.js +1 -1
  53. package/symbols/LineSymbol.js +1 -1
  54. package/symbols/LineSymbol3DLayer.js +1 -1
  55. package/symbols/MarkerSymbol.js +1 -1
  56. package/symbols/PictureFillSymbol.js +1 -1
  57. package/symbols/PictureMarkerSymbol.js +1 -1
  58. package/symbols/TextSymbol.js +1 -1
  59. package/symbols/TextSymbol3DLayer.js +1 -1
  60. package/symbols/callouts/LineCallout3D.js +1 -1
  61. package/symbols/edges/Edges3D.js +1 -1
  62. package/symbols/support/Symbol3DIconOutline.js +1 -1
  63. package/symbols/support/Symbol3DOutline.js +1 -1
  64. package/symbols/support/Symbol3DVerticalOffset.js +1 -1
  65. package/views/2d/layers/RouteLayerView2D.js +1 -1
  66. package/views/2d/layers/support/RouteLayerInteraction.js +1 -1
  67. package/views/2d/layers/support/util.js +1 -1
  68. package/views/3d/camera/intersectionUtils.js +1 -1
  69. package/views/3d/environment/ChapmanApproximation.glsl.js +8 -8
  70. package/views/3d/environment/ChapmanAtmosphere.glsl.js +1 -1
  71. package/views/3d/environment/ChapmanRaymarching.glsl.js +16 -15
  72. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  73. package/views/3d/layers/graphics/Graphics3DGraphic.js +1 -1
  74. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  75. package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
  76. package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
  77. package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
  78. package/views/3d/state/NearFarHeuristic.js +1 -1
  79. package/views/3d/terrain/OverlayRenderer.js +1 -1
  80. package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +12 -12
  81. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  82. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBuffer.js +1 -1
  83. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferLayout.js +1 -1
  84. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferUtils.js +5 -0
  85. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBuffer.js +5 -0
  86. package/views/3d/webgl-engine/shaders/TerrainTechnique.js +1 -1
  87. package/views/View.js +1 -1
  88. package/views/analysis/ElevationProfile/ElevationProfileTool.js +1 -1
  89. package/views/draw/support/Reshape.js +1 -1
  90. package/views/layers/GroupLayerView.js +1 -1
  91. package/views/support/Scheduler.js +1 -1
  92. package/widgets/OrientedImageryViewer/components/ImageOverlays.js +1 -1
  93. package/widgets/ScaleRangeSlider.js +1 -1
  94. package/widgets/Slider.js +1 -1
  95. package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
  96. package/assets/esri/core/workers/chunks/1d877c3c96c40eab906c.js +0 -1
  97. package/assets/esri/core/workers/chunks/22f745539ca54d8cd30d.js +0 -1
  98. package/assets/esri/core/workers/chunks/42f3e83826b3a3dedaaa.js +0 -1
  99. package/assets/esri/core/workers/chunks/44471962c30344dfafdf.js +0 -1
  100. package/assets/esri/core/workers/chunks/8ca83a9af9d24b192128.js +0 -1
  101. package/assets/esri/core/workers/chunks/9527f1a611557a7af237.js +0 -1
  102. package/assets/esri/core/workers/chunks/ad3a4d139613b4c0e0b4.js +0 -1
  103. package/assets/esri/core/workers/chunks/c1c77a00f639eaee9c0d.js +0 -1
  104. package/assets/esri/core/workers/chunks/c8d2cce4a426c72ab173.js +0 -1
  105. package/assets/esri/core/workers/chunks/e3be67c762af672ec602.js +0 -1
  106. package/assets/esri/core/workers/chunks/eefad79be500667af96e.js +0 -1
  107. package/assets/esri/core/workers/chunks/f8caceeaa14d99c35526.js +0 -1
  108. package/assets/esri/core/workers/chunks/f919f0db9f9ec0c649b9.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{removeUnordered as e,filterInPlace as t}from"../../core/arrayUtils.js";import s from"../../core/Handles.js";import"../../core/has.js";import r from"../../core/Logger.js";import{removeMaybe as i}from"../../core/maybe.js";import{recordPerformance as a}from"../../core/performance.js";import n from"../../core/PerformanceSampler.js";import{isAborted as u,createAbortError as _,when as h,isPromiseLike as o,ignoreAbortErrors as E}from"../../core/promiseUtils.js";import{watch as d,initial as T,when as c}from"../../core/reactiveUtils.js";import{signal as m}from"../../core/signal.js";import{Milliseconds as l}from"../../core/time.js";import g from"./debugFlags.js";import{PromiseQueue as R}from"./PromiseQueue.js";import{Yield as I}from"./Yield.js";function f(){return new C}const p={RESOURCE_CONTROLLER_IMMEDIATE:"immediate",RESOURCE_CONTROLLER:"schedule",SLIDE:"slide",STREAM_DATA_LOADER:"stream loader",ELEVATION_QUERY:"elevation query",TERRAIN_SURFACE:"terrain",SURFACE_GEOMETRY_UPDATES:"surface geometry updates",LOD_RENDERER:"LoD renderer",GRAPHICS_CORE:"Graphics3D",I3S_CONTROLLER:"I3S",POINT_CLOUD_LAYER:"point cloud",FEATURE_TILE_FETCHER:"feature fetcher",STREAM_CONTROLLER:"stream controller",OVERLAY:"overlay",OVERLAY_RENDERER:"overlay renderer",STAGE:"stage",GRAPHICS_DECONFLICTOR:"graphics deconflictor",FILTER_VISIBILITY:"graphics filter visibility",SCALE_VISIBILITY:"graphics scale visibility",FRUSTUM_VISIBILITY:"graphics frustum visibility",POINT_OF_INTEREST_FREQUENT:"POI frequent",POINT_OF_INTEREST_INFREQUENT:"POI infrequent",LABELER:"labeler",FEATURE_QUERY_ENGINE:"feature query",FEATURE_TILE_TREE:"feature tile tree",FEATURE_TILE_TREE_ACTIVE:"fast feature tile tree",ELEVATION_ALIGNMENT:"elevation alignment",ELEVATION_ALIGNMENT_SCENE:"elevation alignment scene",TEXT_TEXTURE_ATLAS:"text texture atlas",TEXTURE_UNLOAD:"texture unload",LINE_OF_SIGHT_TOOL:"line of sight tool",LINE_OF_SIGHT_TOOL_INTERACTIVE:"interactive line of sight tool",ELEVATION_PROFILE:"elevation profile",SNAPPING:"snapping",SHADOW_ACCUMULATOR:"shadow accumulator",CLOUDS_GENERATOR:"clouds generator",FLOW_GENERATOR:"flow generator",MAPVIEW_FETCH_QUEUE:"mapview fetch queue",MAPVIEW_LAYERVIEW_UPDATE:"mapview layerview update",MAPVIEW_VECTOR_TILE_PARSING_QUEUE:"mapview vector tile parsing queue",NONE:0,TEST_PRIO:1},L=0,A=new Map([[p.RESOURCE_CONTROLLER_IMMEDIATE,L],[p.RESOURCE_CONTROLLER,4],[p.SLIDE,L],[p.STREAM_DATA_LOADER,L],[p.ELEVATION_QUERY,L],[p.TERRAIN_SURFACE,1],[p.SURFACE_GEOMETRY_UPDATES,1],[p.LOD_RENDERER,2],[p.GRAPHICS_CORE,2],[p.I3S_CONTROLLER,2],[p.POINT_CLOUD_LAYER,2],[p.FEATURE_TILE_FETCHER,2],[p.STREAM_CONTROLLER,2],[p.CLOUDS_GENERATOR,2],[p.OVERLAY,4],[p.OVERLAY_RENDERER,4],[p.STAGE,4],[p.GRAPHICS_DECONFLICTOR,4],[p.FILTER_VISIBILITY,4],[p.SCALE_VISIBILITY,4],[p.FRUSTUM_VISIBILITY,4],[p.POINT_OF_INTEREST_FREQUENT,6],[p.POINT_OF_INTEREST_INFREQUENT,30],[p.LABELER,8],[p.FEATURE_QUERY_ENGINE,8],[p.FEATURE_TILE_TREE,16],[p.FEATURE_TILE_TREE_ACTIVE,L],[p.ELEVATION_ALIGNMENT,12],[p.ELEVATION_ALIGNMENT_SCENE,14],[p.TEXT_TEXTURE_ATLAS,12],[p.TEXTURE_UNLOAD,12],[p.LINE_OF_SIGHT_TOOL,16],[p.LINE_OF_SIGHT_TOOL_INTERACTIVE,L],[p.SNAPPING,L],[p.SHADOW_ACCUMULATOR,30],[p.FLOW_GENERATOR,12],[p.MAPVIEW_FETCH_QUEUE,L],[p.MAPVIEW_LAYERVIEW_UPDATE,2],[p.MAPVIEW_VECTOR_TILE_PARSING_QUEUE,L]]);function O(e){return A.has(e)?A.get(e):"number"==typeof e?e:1}const N=l(6.5),b=l(1),k=l(30),S=l(1e3/30),P=l(100),U=.9;class C{get updating(){return this._updating.value}_updatingChanged(){this._updating.value=this._tasks.some(e=>e.needsUpdate)}constructor(){this._updating=m(!0),this._microTaskQueued=!1,this._frameNumber=0,this.performanceInfo={total:new n("total"),tasks:new Map},this._frameTaskTimes=new Map,this._budget=new y,this.state=1,this._tasks=new Array,this._runQueue=new Array,this._load=0,this._forceTask=!1,this._debug=!1,this._debugHandle=d(()=>g.SCHEDULER_LOG_SLOW_TASKS,e=>this._debug=e,T);for(const e of Object.keys(p))this.performanceInfo.tasks.set(p[e],new n(String(p[e])))}destroy(){this._tasks.forEach(e=>e.remove()),this._tasks.length=0,this._runQueue.length=0,i(this._debugHandle),this._microTaskQueued=!1,this._updatingChanged()}taskRunningChanged(e){this._updatingChanged(),e&&this._budget.remaining>0&&!this._microTaskQueued&&(this._microTaskQueued=!0,queueMicrotask(()=>{this._microTaskQueued&&(this._microTaskQueued=!1,this._budget.remaining>0&&this._schedule()&&this._runFrame())}))}registerTask(e,t){const s=new F(this,e,t);return this._tasks.push(s),this._updatingChanged(),this.performanceInfo.tasks.has(e)||this.performanceInfo.tasks.set(e,new n(e)),s}get load(){return this._load}frame(e){if(this._startFrameTaskTimes(),this._updateBudget(e)){const e=this._budget.now();this._runFrame();const t=this._budget.now();this._recordFrameTaskTimes(t-e);const s=2===this.state?"Idle":1===this.state?"Interacting":"Animating";return a(`${s} Frame Tasks`,e,t,"Maps SDK","Scheduling"),!0}return this._recordFrameTaskTimes(0),!1}_updateBudget(e){this._test&&(this._test.usedBudget=0),++this._frameNumber;let t=N,s=e.frameDuration,r=b;switch(this.state){case 2:t=l(0),s=l(Math.max(P,e.frameDuration)),r=k;break;case 1:s=l(Math.max(S,e.frameDuration))}return s=l(s-e.elapsedFrameTime-t),2!==this.state&&s<b&&!this._forceTask?(this._forceTask=!0,!1):(s=l(Math.max(s,r)),this._budget.reset(s),this._updateLoad(),this._schedule())}_runFrame(){switch(this._forceTask=!1,this._microTaskQueued=!1,this.state){case 2:this._runIdle();break;case 1:this._runInteracting();break;default:this._runAnimating()}this._test&&(this._test.usedBudget=this._budget.elapsed)}stopFrame(){this._budget.reset(l(0)),this._budget.madeProgress()}removeTask(t){e(this._tasks,t),e(this._runQueue,t),this._updatingChanged()}_updateTask(e){this._tasks.forEach(t=>{t.name===e&&t.setPriority(e)})}_getState(e){if(this._runQueue.some(t=>t.name===e))return"s";let t="i";return this._tasks.forEach(s=>{s.name===e&&s.needsUpdate&&(s.schedulePriority<=1?t="r":"r"!==t&&(t="w"))}),t}_getRuntime(e){let t=0;return this._tasks.forEach(s=>{s.name===e&&(t+=s.runtime)}),t}_resetRuntimes(){this._tasks.forEach(e=>e.runtime=0)}_getRunning(){const e=new Map;if(this._tasks.forEach(t=>{t.needsUpdate&&e.set(t.name,(e.get(t.name)||0)+1)}),0===e.size)return null;let t="";return e.forEach((e,s)=>{t+=e>1?` ${e}x ${s}`:` ${s}`}),t}_runIdle(){this._run()}_runInteracting(){this._run()}_runAnimating(){this._run()}_updateLoad(){const e=this._tasks.reduce((e,t)=>t.needsUpdate?++e:e,0);this._load=this._load*U+e*(1-U)}_schedule(){for(t(this._runQueue,e=>!!e.needsUpdate||(e.schedulePriority=e.basePriority,!1)),this._tasks.forEach(e=>{e.basePriority===L&&e.needsUpdate&&!this._runQueue.includes(e)&&e.blockFrame!==this._frameNumber&&this._runQueue.unshift(e)});0===this._runQueue.length;){let e=!1,t=0;if(this._tasks.forEach(s=>{if(s.needsUpdate&&0!==s.schedulePriority&&s.basePriority!==L&&s.blockFrame!==this._frameNumber)if(e=!0,t=Math.max(t,s.basePriority),1===s.schedulePriority)s.schedulePriority=0,this._runQueue.push(s);else--s.schedulePriority}),!e)return this._updatingChanged(),!1}return this._updatingChanged(),!0}_run(){do{for(;this._runQueue.length>0;){const t=this._budget.now(),s=this._runQueue.pop();this._budget.resetProgress();try{s.task.runTask(this._budget)===I&&(s.blockFrame=this._frameNumber)}catch(e){r.getLogger("esri.views.support.Scheduler").error(`Exception in task "${s.name}"`,e),s.blockFrame=this._frameNumber}!this._budget.hasProgressed&&s.blockFrame!==this._frameNumber&&s.needsUpdate&&(s.name,p.I3S_CONTROLLER,s.blockFrame=this._frameNumber),s.schedulePriority=s.basePriority;const i=this._budget.now(),n=i-t;if(a(`${s.name}`,t,i,"Maps SDK","Scheduling"),s.runtime+=n,this._frameTaskTimes.set(s.priority,this._frameTaskTimes.get(s.priority)+n),this._budget.remaining<=0)return void this._updatingChanged()}}while(this._schedule());this._updatingChanged()}_startFrameTaskTimes(){for(const e of Object.keys(p))this._frameTaskTimes.set(p[e],0)}_recordFrameTaskTimes(e){this._frameTaskTimes.forEach((e,t)=>this.performanceInfo.tasks.get(t).push(e)),this.performanceInfo.total.push(e)}get test(){return this._test}}class F{get task(){return this._task.value}get readyToRun(){return this._queue.readyToRun}get updating(){return this._queue.updating}constructor(e,t,r){this._scheduler=e,this.name=t,this.blockFrame=0,this.runtime=0,this._queue=new R,this._handles=new s,this._basePriority=O(t),this.schedulePriority=this._basePriority,this._task=m(null!=r?r:this._queue),this._handles.add(c(()=>this.task.readyToRun,t=>e.taskRunningChanged(t)))}remove(){this.processQueue(w),this._scheduler.removeTask(this),this.schedule=Q.schedule,this.reschedule=Q.reschedule,this.scheduleGenerator=Q.scheduleGenerator,this._handles.destroy()}get basePriority(){return this._basePriority}setPriority(e){if(this.name===e)return;this.name=e;const t=O(e);this._basePriority!==L&&0===this.schedulePriority||(this.schedulePriority=t),this._basePriority=t}get priority(){return this.name}set priority(e){this.setPriority(e)}get needsUpdate(){return this.readyToRun||!this.task.destroyed&&this.task.readyToRun}schedule(e,t,s){return this._queue.push(e,t,s)}reschedule(e,t,s){return this._queue.unshift(e,t,s)}scheduleGenerator(e,t,s){return this._queue.pushGenerator(e,t,s)}processQueue(e){return this._queue.runTask(e)}}class y{constructor(){this._begin=performance?.now()??0,this._budget=0,this._done=!1,this._progressed=!1,this._enabled=!0}run(e){return!this.done&&(!0===e()&&this.madeProgress(),!0)}get done(){return this._done}get budget(){return this._budget}madeProgress(){return this._progressed=!0,this._done=this.elapsed>=this._budget&&this._enabled,this._done}get enabled(){return this._enabled}set enabled(e){this._enabled=e}reset(e){this._begin=this.now(),this._budget=e,this.resetProgress()}get remaining(){return Math.max(this._budget-this.elapsed,0)}now(){return performance.now()}get elapsed(){return this.now()-this._begin}resetProgress(){this._progressed=!1,this._done=!1}get hasProgressed(){return this._progressed}}const w=new y;function D(e){const t=new y;return t.reset(e),t}w.enabled=!1;class M{remove(){}processQueue(){}schedule(e,t,s){try{if(u(t)){const e=_();return s?Promise.resolve(s(e)):Promise.reject(e)}return h(e(w))}catch(r){return Promise.reject(r)}}reschedule(e,t,s){return this.schedule(e,t,s)}async scheduleGenerator(e,t,s){if(u(t)){const e=_();if(s)return s(e);throw e}const r=e(w);for(;;){const e=r.next(w),i=o(e)?await e:e;if(u(t)){const e=_();if(s){const t=s(e),i=r.return(null);return o(i)&&await E(i),t}const t=r.throw(e);throw o(t)&&await E(t),e}if(i.done)return i.value}}}const Q=new M;export{Q as ImmediateTask,p as TaskPriority,O as getTaskPriority,D as makeBudget,f as newScheduler,w as noBudget,A as taskPriorities};
5
+ import{removeUnordered as e,filterInPlace as t}from"../../core/arrayUtils.js";import s from"../../core/Handles.js";import"../../core/has.js";import r from"../../core/Logger.js";import{removeMaybe as i}from"../../core/maybe.js";import{recordPerformance as a}from"../../core/performance.js";import n from"../../core/PerformanceSampler.js";import{isAborted as u,createAbortError as _,when as h,isPromiseLike as o,ignoreAbortErrors as E}from"../../core/promiseUtils.js";import{watch as d,initial as T,when as c}from"../../core/reactiveUtils.js";import{signal as m}from"../../core/signal.js";import{Milliseconds as l}from"../../core/time.js";import R from"./debugFlags.js";import{PromiseQueue as g}from"./PromiseQueue.js";import{Yield as I}from"./Yield.js";function p(){return new C}const f={RESOURCE_CONTROLLER_IMMEDIATE:"immediate",RESOURCE_CONTROLLER:"schedule",SLIDE:"slide",STREAM_DATA_LOADER:"stream loader",ELEVATION_QUERY:"elevation query",TERRAIN_SURFACE:"terrain",SURFACE_GEOMETRY_UPDATES:"surface geometry updates",LOD_RENDERER:"LoD renderer",GRAPHICS_CORE:"Graphics3D",I3S_CONTROLLER:"I3S",POINT_CLOUD_LAYER:"point cloud",FEATURE_TILE_FETCHER:"feature fetcher",STREAM_CONTROLLER:"stream controller",OVERLAY:"overlay",OVERLAY_RENDERER:"overlay renderer",STAGE:"stage",GRAPHICS_DECONFLICTOR:"graphics deconflictor",FILTER_VISIBILITY:"graphics filter visibility",SCALE_VISIBILITY:"graphics scale visibility",FRUSTUM_VISIBILITY:"graphics frustum visibility",POINT_OF_INTEREST_FREQUENT:"POI frequent",POINT_OF_INTEREST_INFREQUENT:"POI infrequent",LABELER:"labeler",FEATURE_QUERY_ENGINE:"feature query",FEATURE_TILE_TREE:"feature tile tree",FEATURE_TILE_TREE_ACTIVE:"fast feature tile tree",ELEVATION_ALIGNMENT:"elevation alignment",ELEVATION_ALIGNMENT_SCENE:"elevation alignment scene",TEXT_TEXTURE_ATLAS:"text texture atlas",TEXTURE_UNLOAD:"texture unload",LINE_OF_SIGHT_TOOL:"line of sight tool",LINE_OF_SIGHT_TOOL_INTERACTIVE:"interactive line of sight tool",ELEVATION_PROFILE:"elevation profile",SNAPPING:"snapping",SHADOW_ACCUMULATOR:"shadow accumulator",CLOUDS_GENERATOR:"clouds generator",FLOW_GENERATOR:"flow generator",MAPVIEW_FETCH_QUEUE:"mapview fetch queue",MAPVIEW_LAYERVIEW_UPDATE:"mapview layerview update",MAPVIEW_VECTOR_TILE_PARSING_QUEUE:"mapview vector tile parsing queue",NONE:0,TEST_PRIO:1},L=0,O=new Map([[f.RESOURCE_CONTROLLER_IMMEDIATE,L],[f.RESOURCE_CONTROLLER,4],[f.SLIDE,L],[f.STREAM_DATA_LOADER,L],[f.ELEVATION_QUERY,L],[f.TERRAIN_SURFACE,1],[f.SURFACE_GEOMETRY_UPDATES,1],[f.LOD_RENDERER,2],[f.GRAPHICS_CORE,2],[f.I3S_CONTROLLER,2],[f.POINT_CLOUD_LAYER,2],[f.FEATURE_TILE_FETCHER,2],[f.STREAM_CONTROLLER,2],[f.CLOUDS_GENERATOR,2],[f.OVERLAY,4],[f.OVERLAY_RENDERER,4],[f.STAGE,4],[f.GRAPHICS_DECONFLICTOR,4],[f.FILTER_VISIBILITY,4],[f.SCALE_VISIBILITY,4],[f.FRUSTUM_VISIBILITY,4],[f.POINT_OF_INTEREST_FREQUENT,6],[f.POINT_OF_INTEREST_INFREQUENT,30],[f.LABELER,8],[f.FEATURE_QUERY_ENGINE,8],[f.FEATURE_TILE_TREE,16],[f.FEATURE_TILE_TREE_ACTIVE,L],[f.ELEVATION_ALIGNMENT,12],[f.ELEVATION_ALIGNMENT_SCENE,14],[f.TEXT_TEXTURE_ATLAS,12],[f.TEXTURE_UNLOAD,12],[f.LINE_OF_SIGHT_TOOL,16],[f.LINE_OF_SIGHT_TOOL_INTERACTIVE,L],[f.SNAPPING,L],[f.SHADOW_ACCUMULATOR,30],[f.FLOW_GENERATOR,12],[f.MAPVIEW_FETCH_QUEUE,L],[f.MAPVIEW_LAYERVIEW_UPDATE,2],[f.MAPVIEW_VECTOR_TILE_PARSING_QUEUE,L]]);function A(e){return O.has(e)?O.get(e):"number"==typeof e?e:1}const N=l(6.5),b=l(1),S=l(30),k=l(1e3/30),P=l(100),U=.9;class C{get updating(){return this._updating.value}_updatingChanged(){this._updating.value=this._tasks.some(e=>e.needsUpdate)}constructor(){this._updating=m(!0),this._microTaskQueued=!1,this._frameNumber=0,this.performanceInfo={total:new n("total"),tasks:new Map},this._frameTaskTimes=new Map,this._budget=new y,this.state=1,this._tasks=new Array,this._runQueue=new Array,this._load=0,this._forceTask=!1,this._debug=!1,this._debugHandle=d(()=>R.SCHEDULER_LOG_SLOW_TASKS,e=>this._debug=e,T);for(const e of Object.keys(f))this.performanceInfo.tasks.set(f[e],new n(String(f[e])))}destroy(){this._tasks.forEach(e=>e.remove()),this._tasks.length=0,this._runQueue.length=0,i(this._debugHandle),this._microTaskQueued=!1,this._updatingChanged()}taskRunningChanged(e){this._updatingChanged(),e&&this._budget.remaining>0&&!this._microTaskQueued&&(this._microTaskQueued=!0,queueMicrotask(()=>{this._microTaskQueued&&(this._microTaskQueued=!1,this._budget.remaining>0&&this._schedule()&&this._runFrame())}))}registerTask(e,t){const s=new F(this,e,t);return this._tasks.push(s),this._updatingChanged(),this.performanceInfo.tasks.has(e)||this.performanceInfo.tasks.set(e,new n(e)),s}get load(){return this._load}frame(e){if(this._startFrameTaskTimes(),this._updateBudget(e)){const e=this._budget.now();this._runFrame();const t=this._budget.now();this._recordFrameTaskTimes(t-e);const s=2===this.state?"Idle":1===this.state?"Interacting":"Animating";return a(`${s} Frame Tasks`,e,t,"Maps SDK","Scheduling"),!0}return this._recordFrameTaskTimes(0),!1}_updateBudget(e){this._test&&(this._test.usedBudget=0),++this._frameNumber;let t=N,s=e.frameDuration,r=b;switch(this.state){case 2:t=l(0),s=l(Math.max(P,e.frameDuration)),r=S;break;case 1:s=l(Math.max(k,e.frameDuration))}return s=l(s-e.elapsedFrameTime-t),2!==this.state&&s<b&&!this._forceTask?(this._forceTask=!0,!1):(s=l(Math.max(s,r)),this._budget.reset(s),this._updateLoad(),this._schedule())}_runFrame(){this._forceTask=!1,this._microTaskQueued=!1,this._run(),this._test&&(this._test.usedBudget=this._budget.elapsed)}stopFrame(){this._budget.reset(l(0)),this._budget.madeProgress()}removeTask(t){e(this._tasks,t),e(this._runQueue,t),this._updatingChanged()}_updateTask(e){this._tasks.forEach(t=>{t.name===e&&t.setPriority(e)})}_getState(e){if(this._runQueue.some(t=>t.name===e))return"s";let t="i";return this._tasks.forEach(s=>{s.name===e&&s.needsUpdate&&(s.schedulePriority<=1?t="r":"r"!==t&&(t="w"))}),t}_getRuntime(e){let t=0;return this._tasks.forEach(s=>{s.name===e&&(t+=s.runtime)}),t}_resetRuntimes(){this._tasks.forEach(e=>e.runtime=0)}_getRunning(){const e=new Map;if(this._tasks.forEach(t=>{t.needsUpdate&&e.set(t.name,(e.get(t.name)||0)+1)}),0===e.size)return null;let t="";return e.forEach((e,s)=>{t+=e>1?` ${e}x ${s}`:` ${s}`}),t}_updateLoad(){const e=this._tasks.reduce((e,t)=>t.needsUpdate?++e:e,0);this._load=this._load*U+e*(1-U)}_schedule(){for(t(this._runQueue,e=>!!e.needsUpdate||(e.schedulePriority=e.basePriority,!1)),this._tasks.forEach(e=>{e.basePriority===L&&e.needsUpdate&&!this._runQueue.includes(e)&&e.blockFrame!==this._frameNumber&&this._runQueue.unshift(e)});0===this._runQueue.length;){let e=!1,t=0;if(this._tasks.forEach(s=>{if(s.needsUpdate&&0!==s.schedulePriority&&s.basePriority!==L&&s.blockFrame!==this._frameNumber)if(e=!0,t=Math.max(t,s.basePriority),1===s.schedulePriority)s.schedulePriority=0,this._runQueue.push(s);else--s.schedulePriority}),!e)return this._updatingChanged(),!1}return this._updatingChanged(),!0}_run(){do{for(;this._runQueue.length>0;){const t=this._budget.now(),s=this._runQueue.pop();this._budget.resetProgress();try{s.task.runTask(this._budget)===I&&(s.blockFrame=this._frameNumber)}catch(e){r.getLogger("esri.views.support.Scheduler").error(`Exception in task "${s.name}"`,e),s.blockFrame=this._frameNumber}!this._budget.hasProgressed&&s.blockFrame!==this._frameNumber&&s.needsUpdate&&(s.name,f.I3S_CONTROLLER,s.blockFrame=this._frameNumber),s.schedulePriority=s.basePriority;const i=this._budget.now(),n=i-t;if(a(`${s.name}`,t,i,"Maps SDK","Scheduling"),s.runtime+=n,this._frameTaskTimes.set(s.priority,this._frameTaskTimes.get(s.priority)+n),this._budget.remaining<=0)return void this._updatingChanged()}}while(this._schedule());this._updatingChanged()}_startFrameTaskTimes(){for(const e of Object.keys(f))this._frameTaskTimes.set(f[e],0)}_recordFrameTaskTimes(e){this._frameTaskTimes.forEach((e,t)=>this.performanceInfo.tasks.get(t).push(e)),this.performanceInfo.total.push(e)}get test(){return this._test}}class F{get task(){return this._task.value}get readyToRun(){return this._queue.readyToRun}get updating(){return this._queue.updating}constructor(e,t,r){this._scheduler=e,this.name=t,this.blockFrame=0,this.runtime=0,this._queue=new g,this._handles=new s,this._basePriority=A(t),this.schedulePriority=this._basePriority,this._task=m(null!=r?r:this._queue),this._handles.add(c(()=>this.task.readyToRun,t=>e.taskRunningChanged(t)))}remove(){this.processQueue(w),this._scheduler.removeTask(this),this.schedule=Q.schedule,this.reschedule=Q.reschedule,this.scheduleGenerator=Q.scheduleGenerator,this._handles.destroy()}get basePriority(){return this._basePriority}setPriority(e){if(this.name===e)return;this.name=e;const t=A(e);this._basePriority!==L&&0===this.schedulePriority||(this.schedulePriority=t),this._basePriority=t}get priority(){return this.name}set priority(e){this.setPriority(e)}get needsUpdate(){return this.readyToRun||!this.task.destroyed&&this.task.readyToRun}schedule(e,t,s){return this._queue.push(e,t,s)}reschedule(e,t,s){return this._queue.unshift(e,t,s)}scheduleGenerator(e,t,s){return this._queue.pushGenerator(e,t,s)}processQueue(e){return this._queue.runTask(e)}}class y{constructor(){this._begin=performance?.now()??0,this._budget=0,this._done=!1,this._progressed=!1,this._enabled=!0}run(e){return!this.done&&(!0===e()&&this.madeProgress(),!0)}get done(){return this._done}get budget(){return this._budget}madeProgress(){return this._progressed=!0,this._done=this.elapsed>=this._budget&&this._enabled,this._done}get enabled(){return this._enabled}set enabled(e){this._enabled=e}reset(e){this._begin=this.now(),this._budget=e,this.resetProgress()}get remaining(){return Math.max(this._budget-this.elapsed,0)}now(){return performance.now()}get elapsed(){return this.now()-this._begin}resetProgress(){this._progressed=!1,this._done=!1}get hasProgressed(){return this._progressed}}const w=new y;function D(e){const t=new y;return t.reset(e),t}w.enabled=!1;class M{remove(){}processQueue(){}schedule(e,t,s){try{if(u(t)){const e=_();return s?Promise.resolve(s(e)):Promise.reject(e)}return h(e(w))}catch(r){return Promise.reject(r)}}reschedule(e,t,s){return this.schedule(e,t,s)}async scheduleGenerator(e,t,s){if(u(t)){const e=_();if(s)return s(e);throw e}const r=e(w);for(;;){const e=r.next(w),i=o(e)?await e:e;if(u(t)){const e=_();if(s){const t=s(e),i=r.return(null);return o(i)&&await E(i),t}const t=r.throw(e);throw o(t)&&await E(t),e}if(i.done)return i.value}}}const Q=new M;export{Q as ImmediateTask,f as TaskPriority,A as getTaskPriority,D as makeBudget,p as newScheduler,w as noBudget,O as taskPriorities};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../core/Collection.js";import{IdentifiableMixin as s}from"../../../core/Identifiable.js";import{watch as a,syncAndInitial as i,on as o}from"../../../core/reactiveUtils.js";import{property as r,subclass as l}from"../../../core/accessorSupport/decorators.js";import{isEditableLayer as n}from"../../../layers/support/editableLayers.js";import c from"../../../support/actions/ActionToggle.js";import d from"../../Widget.js";import{css as h}from"../css.js";import{isValidDataCaptureLayer as p}from"../dataCaptureUtils.js";import m from"./OverlayLayersList.js";import{loadCalciteComponents as u}from"../../support/componentsUtils.js";import{globalCss as y}from"../../support/globalCss.js";import{tsx as g}from"../../support/widget.js";let L=class extends(s(d)){constructor(e){super(e),this._previousAction=null,this.closed=!1,this.dataCaptureEnabled=!1,this.dataCaptureLayer=null,this.imageGeometryField=null,this.imageReferenceField=null,this.layerList=new m({selectionMode:"multiple"}),this.messages=null,this.overlayedLayers=new t,this.showCameraLocations=!1,this.showMapFeatures=!1,this._createSelectedItemsHandle=()=>{this.removeHandles("selected-items"),this.addHandles(this._trackLayerSelectionChanges(),"selected-items")},this._createDataCaptureLayerHandle=()=>a(()=>({dataCaptureLayer:this.dataCaptureLayer,operationalItems:this.layerList.operationalItems}),({dataCaptureLayer:e,operationalItems:t},s)=>{if(!e&&s?.dataCaptureLayer){const e=t.find(e=>e.layer===s.dataCaptureLayer);e&&e.actionsSections?.items.forEach(e=>{e.items.forEach(e=>{"create-features"===e.id&&(e.value=!1)})})}},i),this._handleSelectedItemsChange=({added:e,removed:t})=>{e.forEach(e=>{this.overlayedLayers.includes(e.layer)||this.onLayerSelected?.(e)}),t.forEach(e=>{this.overlayedLayers.includes(e.layer)&&this.onLayerDeselected?.(e)}),this.overlayedLayers.removeAll(),this.overlayedLayers.addMany(this.layerList.selectedItems.items.map(e=>e.layer))},this._layerListTriggerActionHandle=()=>o(()=>this.layerList,"trigger-action",e=>{const{action:t,item:{layer:s}}=e;switch(this._resetPreviousAction(t),t.id){case"create-features":this._toggleDataCaptureLayer(t,s);break;case"show-all-features":{const e=s?.id;e&&this.onFilterCapturedFeatures?.(e);break}}}),this._resetPreviousAction=e=>{"toggle"===this._previousAction?.type&&this._previousAction!==e&&(this._previousAction.value=!1,this._previousAction=null)},this._toggleDataCaptureLayer=(e,t)=>{this._previousAction=e;const s=e.value;this.dataCaptureLayer=s?t:null,this.onDataCaptureLayerChanged?.(this.dataCaptureLayer)},this._trackLayerSelectionChanges=()=>o(()=>this.layerList.selectedItems,"change",this._handleSelectedItemsChange),this._watchLayerListForListItemCreatedFunction=()=>a(()=>({layerList:this.layerList,listItemCreatedFunction:this._listItemCreatedFunction}),()=>{this.layerList.listItemCreatedFunction=this._listItemCreatedFunction},i),this._watchSelectedItems=()=>a(()=>this.layerList.selectedItems,this._createSelectedItemsHandle,i)}initialize(){this.addHandles([this._watchSelectedItems(),this._layerListTriggerActionHandle(),this._watchLayerListForListItemCreatedFunction(),this._createDataCaptureLayerHandle()])}loadDependencies(){return u({list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}get _listItemCreatedFunction(){const{dataCaptureEnabled:e,imageGeometryField:t,imageReferenceField:s}=this;return e&&t&&s?async e=>{const{item:a}=e,i=a.layer,{dataCaptureLayer:o,overlayedLayers:r,messages:{createFeaturesFromImage:l,showFeatures:c},layerList:d}=this,h=r.includes(i),{selectedItems:m}=d;if(C(h,m,a),await(i?.load()),!i||!p(i,t,s)||!n(i))return;const u=o===i,y=_([l,c],a,m,u);u&&(this._previousAction=y)}:null}get view(){return this.layerList?.view}set view(e){this.layerList.view=e}_renderCameraLocationsSwitch(e){return g("calcite-list-item",{bind:this,label:this.messages.overlayCameraLocations,onclick:this._toggleShowCameraLocations},g("calcite-switch",{bind:this,checked:e,class:h.overlaysSwitch,onchange:this._toggleShowCameraLocations,scale:"s",slot:"actions-end"}))}_renderOverlayMapFeatures(e){return g("calcite-list-item",{bind:this,label:this.messages?.overlayMapFeatures,onclick:this._toggleShowMapFeatures},g("calcite-switch",{bind:this,checked:e,class:h.overlaysSwitch,onchange:this._toggleShowMapFeatures,scale:"s",slot:"actions-end"}))}_renderList(e){return e?g("div",{class:h.imageOverlaysLayerList},this.layerList.render()):null}_renderPanel(){const{closed:e,messages:t,showCameraLocations:s,showMapFeatures:a}=this;return g("calcite-panel",{bind:this,closable:!0,closed:e,heading:t.imageOverlays,onCalcitePanelClose:this.onImageOverlaysClosed},g("calcite-list",{label:t.imageOverlays},this._renderCameraLocationsSwitch(s),this._renderOverlayMapFeatures(a)),this._renderList(a))}_toggleShowCameraLocations(e){e.stopPropagation(),this.showCameraLocations=!this.showCameraLocations,this.onShowCameraLocationsChanged?.(this.showCameraLocations)}_toggleShowMapFeatures(e){e.stopPropagation(),this.showMapFeatures=!this.showMapFeatures,this.onShowMapFeaturesChanged?.(this.showMapFeatures)}render(){const e=this.layerList.operationalItems.items.length,t=this.showMapFeatures&&0===e,s=this.showMapFeatures&&e>0,a={[y.widget]:!0,[h.imageOverlaysNoResult]:t,[h.imageOverlaysIncreasedHeight]:s,[h.imageOverlays]:!t&&!s};return g("div",{class:this.classes(a)},this._renderPanel())}};e([r()],L.prototype,"_previousAction",void 0),e([r()],L.prototype,"_listItemCreatedFunction",null),e([r()],L.prototype,"closed",void 0),e([r()],L.prototype,"dataCaptureEnabled",void 0),e([r()],L.prototype,"dataCaptureLayer",void 0),e([r()],L.prototype,"imageGeometryField",void 0),e([r()],L.prototype,"imageReferenceField",void 0),e([r()],L.prototype,"layerList",void 0),e([r()],L.prototype,"messages",void 0),e([r()],L.prototype,"onDataCaptureLayerChanged",void 0),e([r()],L.prototype,"onFilterCapturedFeatures",void 0),e([r()],L.prototype,"onImageOverlaysClosed",void 0),e([r()],L.prototype,"onLayerDeselected",void 0),e([r()],L.prototype,"onLayerSelected",void 0),e([r()],L.prototype,"onShowCameraLocationsChanged",void 0),e([r()],L.prototype,"onShowMapFeaturesChanged",void 0),e([r()],L.prototype,"overlayedLayers",void 0),e([r()],L.prototype,"showCameraLocations",void 0),e([r()],L.prototype,"showMapFeatures",void 0),e([r()],L.prototype,"view",null),L=e([l("esri.widgets.OrientedImageryViewer.components.ImageOverlays")],L);const v=L;function C(e,t,s){e&&t.items.push(s)}function w(e,s){const a=new t;a.add(e[0]),a.add(e[1]),s.actionsSections=new t([a])}function _(e,t,s,o=!1){const r=new c({icon:"pencil",id:"create-features",title:e[0],value:o}),l=new c({icon:"list-show-all",id:"show-all-features",title:e[1],value:o});return t.addHandles(a(()=>s.includes(t),e=>{r.visible=e,l.visible=e},i)),w([r,l],t),r}export{v as default};
5
+ import{__decorate as e}from"tslib";import t from"../../../core/Collection.js";import{IdentifiableMixin as s}from"../../../core/Identifiable.js";import{watch as a,syncAndInitial as i,on as o}from"../../../core/reactiveUtils.js";import{property as r,subclass as l}from"../../../core/accessorSupport/decorators.js";import{isEditableLayer as n}from"../../../layers/support/editableLayers.js";import c from"../../../support/actions/ActionToggle.js";import d from"../../Widget.js";import{css as h}from"../css.js";import{isValidDataCaptureLayer as p}from"../dataCaptureUtils.js";import m from"./OverlayLayersList.js";import{loadCalciteComponents as u}from"../../support/componentsUtils.js";import{globalCss as y}from"../../support/globalCss.js";import{tsx as g}from"../../support/widget.js";let L=class extends(s(d)){constructor(e){super(e),this._previousAction=null,this.closed=!1,this.dataCaptureEnabled=!1,this.dataCaptureLayer=null,this.imageGeometryField=null,this.imageReferenceField=null,this.layerList=new m({selectionMode:"multiple"}),this.messages=null,this.overlayedLayers=new t,this.showCameraLocations=!1,this.showMapFeatures=!1,this._createSelectedItemsHandle=()=>{this.removeHandles("selected-items"),this.addHandles(this._trackLayerSelectionChanges(),"selected-items")},this._createDataCaptureLayerHandle=()=>a(()=>({dataCaptureLayer:this.dataCaptureLayer,operationalItems:this.layerList.operationalItems}),({dataCaptureLayer:e,operationalItems:t},s)=>{if(!e&&s?.dataCaptureLayer){const e=t.find(e=>e.layer===s.dataCaptureLayer);e&&e.actionsSections?.items.forEach(e=>{e.items.forEach(e=>{"create-features"===e.id&&(e.value=!1)})})}},i),this._handleSelectedItemsChange=({added:e,removed:t})=>{e.forEach(e=>{this.overlayedLayers.includes(e.layer)||this.onLayerSelected?.(e)}),t.forEach(e=>{this.overlayedLayers.includes(e.layer)&&this.onLayerDeselected?.(e)}),this.overlayedLayers.removeAll(),this.overlayedLayers.addMany(this.layerList.selectedItems.items.map(e=>e.layer))},this._layerListTriggerActionHandle=()=>o(()=>this.layerList,"trigger-action",e=>{const{action:t,item:{layer:s}}=e;switch(this._resetPreviousAction(t),t.id){case"create-features":this._toggleDataCaptureLayer(t,s);break;case"show-all-features":{const e=s?.id;e&&this.onFilterCapturedFeatures?.(e);break}}}),this._resetPreviousAction=e=>{"toggle"===this._previousAction?.type&&this._previousAction!==e&&(this._previousAction.value=!1,this._previousAction=null)},this._toggleDataCaptureLayer=(e,t)=>{this._previousAction=e;const s=e.value;this.dataCaptureLayer=s?t:null,this.onDataCaptureLayerChanged?.(this.dataCaptureLayer)},this._trackLayerSelectionChanges=()=>o(()=>this.layerList.selectedItems,"change",this._handleSelectedItemsChange),this._watchLayerListForListItemCreatedFunction=()=>a(()=>({layerList:this.layerList,listItemCreatedFunction:this._listItemCreatedFunction}),()=>{this.layerList.listItemCreatedFunction=this._listItemCreatedFunction},i),this._watchSelectedItems=()=>a(()=>this.layerList.selectedItems,this._createSelectedItemsHandle,i)}initialize(){this.addHandles([this._watchSelectedItems(),this._layerListTriggerActionHandle(),this._watchLayerListForListItemCreatedFunction(),this._createDataCaptureLayerHandle()])}loadDependencies(){return u({list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}get _listItemCreatedFunction(){const{dataCaptureEnabled:e,imageGeometryField:t,imageReferenceField:s}=this;return e&&t&&s?async e=>{const{item:a}=e,i=a.layer,{dataCaptureLayer:o,overlayedLayers:r,messages:{createFeaturesFromImage:l,showFeatures:c},layerList:d}=this,h=r.includes(i),{selectedItems:m}=d;if(C(h,m,a),await(i?.load()),!i||!p(i,t,s)||!n(i))return;const u=o===i,y=_([l,c],a,m,u);u&&(this._previousAction=y)}:null}get view(){return this.layerList?.view}set view(e){this.layerList.view=e}_renderCameraLocationsSwitch(e){return g("calcite-list-item",{bind:this,label:this.messages.overlayCameraLocations,onclick:this._toggleShowCameraLocations},g("calcite-switch",{bind:this,checked:e,class:h.overlaysSwitch,onchange:this._toggleShowCameraLocations,scale:"s",slot:"actions-end"}))}_renderOverlayMapFeatures(e){return g("calcite-list-item",{bind:this,label:this.messages?.overlayMapFeatures,onclick:this._toggleShowMapFeatures},g("calcite-switch",{bind:this,checked:e,class:h.overlaysSwitch,onchange:this._toggleShowMapFeatures,scale:"s",slot:"actions-end"}))}_renderList(e){return e?g("div",{class:h.imageOverlaysLayerList},this.layerList.render()):null}_renderPanel(){const{closed:e,messages:t,showCameraLocations:s,showMapFeatures:a}=this;return g("calcite-panel",{bind:this,closable:!0,closed:e,heading:t.imageOverlays,onCalcitePanelClose:this.onImageOverlaysClosed},g("calcite-list",{label:t.imageOverlays},this._renderCameraLocationsSwitch(s),this._renderOverlayMapFeatures(a)),this._renderList(a))}_toggleShowCameraLocations(e){e.stopPropagation(),this.showCameraLocations=!this.showCameraLocations,this.onShowCameraLocationsChanged?.(this.showCameraLocations)}_toggleShowMapFeatures(e){e.stopPropagation(),this.showMapFeatures=!this.showMapFeatures,this.onShowMapFeaturesChanged?.(this.showMapFeatures)}render(){const e=this.layerList.operationalItems.items.length,t=this.showMapFeatures&&0===e,s=this.showMapFeatures&&e>0,a={[y.widget]:!0,[h.imageOverlaysNoResult]:t,[h.imageOverlaysIncreasedHeight]:s,[h.imageOverlays]:!t&&!s};return g("div",{class:this.classes(a)},this._renderPanel())}};e([r()],L.prototype,"_previousAction",void 0),e([r()],L.prototype,"_listItemCreatedFunction",null),e([r()],L.prototype,"closed",void 0),e([r()],L.prototype,"dataCaptureEnabled",void 0),e([r()],L.prototype,"dataCaptureLayer",void 0),e([r()],L.prototype,"imageGeometryField",void 0),e([r()],L.prototype,"imageReferenceField",void 0),e([r()],L.prototype,"layerList",void 0),e([r()],L.prototype,"messages",void 0),e([r()],L.prototype,"onDataCaptureLayerChanged",void 0),e([r()],L.prototype,"onFilterCapturedFeatures",void 0),e([r()],L.prototype,"onImageOverlaysClosed",void 0),e([r()],L.prototype,"onLayerDeselected",void 0),e([r()],L.prototype,"onLayerSelected",void 0),e([r()],L.prototype,"onShowCameraLocationsChanged",void 0),e([r()],L.prototype,"onShowMapFeaturesChanged",void 0),e([r()],L.prototype,"overlayedLayers",void 0),e([r()],L.prototype,"showCameraLocations",void 0),e([r()],L.prototype,"showMapFeatures",void 0),e([r()],L.prototype,"view",null),L=e([l("esri.widgets.OrientedImageryViewer.components.ImageOverlays")],L);const v=L;function C(e,t,s){e&&t.push(s)}function w(e,s){const a=new t;a.add(e[0]),a.add(e[1]),s.actionsSections=new t([a])}function _(e,t,s,o=!1){const r=new c({icon:"pencil",id:"create-features",title:e[0],value:o}),l=new c({icon:"list-show-all",id:"show-all-features",title:e[1],value:o});return t.addHandles(a(()=>s.includes(t),e=>{r.visible=e,l.visible=e},i)),w([r,l],t),r}export{v as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{formatNumber as t,substitute as i}from"../intl.js";import{on as l}from"../core/events.js";import{destroyMaybe as a}from"../core/maybe.js";import{watch as s,when as n,initial as o}from"../core/reactiveUtils.js";import{property as r,cast as c,subclass as d}from"../core/accessorSupport/decorators.js";import m from"./Slider.js";import u from"./Widget.js";import{css as p}from"./ScaleRangeSlider/css.js";import{getScalePreviewSource as v,getScalePreviewSpriteBackgroundPosition as h}from"./ScaleRangeSlider/scalePreviewUtils.js";import S from"./ScaleRangeSlider/ScaleRanges.js";import M from"./ScaleRangeSlider/ScaleRangeSliderViewModel.js";import{loadCalciteComponents as b}from"./support/componentsUtils.js";import{globalCss as g}from"./support/globalCss.js";import{messageBundle as _,tsx as w}from"./support/widget.js";import{storeNode as f,setFocus as y}from"./support/widgetUtils.js";const x={preview:!0,scaleMenus:{maxScaleMenu:!0,minScaleMenu:!0}},I={maximumFractionDigits:0},L="1:",T=16;let C=class extends u{constructor(e,t){super(e,t),this._activeMenu=null,this._activeThumb=null,this._customInput=null,this._maxThumbNode=null,this._minThumbNode=null,this._previewAutoCloseTimeoutId=void 0,this._previewPopover=null,this._slider=new m({thumbCreatedFunction:(e,t,i)=>{0===e?this._minThumbNode=i:1===e&&(this._maxThumbNode=i),this.addHandles([l(i,"mouseenter",()=>{this._activeThumb=e,this.scheduleRender()}),l(i,"mouseleave",()=>{this._previewAutoCloseTimeoutId||(this._activeThumb=null,this.scheduleRender())})])}}),this.disabled=!1,this.messages=null,this.region="US",this.showWorldValue=!1,this.viewModel=new M,this.visibleElements=x,this._afterInputNumberCreate=e=>{"value"in e&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._customInput=e},this._handleCustomScaleInputChange=(e,t)=>{const{viewModel:{scaleRanges:i}}=this,l=Number.parseFloat(t.value);Number.isNaN(l)?t.value=e:this._setScale(i.clampScale(l))}}loadDependencies(){return b({button:()=>import("@esri/calcite-components/dist/components/calcite-button"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover")})}initialize(){this.addHandles([s(()=>this.viewModel,e=>this._slider.viewModel=e?.sliderViewModel??null,o),s(()=>this._interactive,e=>{this._slider.disabled=!e,e||this._setActiveMenu(null)},o),this._slider.on("thumb-drag",({index:e})=>{this._activeThumb=e,clearTimeout(this._previewAutoCloseTimeoutId);const t=250;this._previewAutoCloseTimeoutId=setTimeout(()=>{this._previewAutoCloseTimeoutId=void 0,this._activeThumb=null},t)}),n(()=>!0===this.view?.stationary,()=>this.scheduleRender())])}destroy(){this._slider=a(this._slider)}get _maxScaleMenuEnabled(){const{scaleMenus:e}=this.visibleElements;return!0===e||"boolean"!=typeof e&&e.maxScaleMenu}get _minScaleMenuEnabled(){const{scaleMenus:e}=this.visibleElements;return!0===e||"boolean"!=typeof e&&e.minScaleMenu}get _interactive(){return"disabled"!==this.viewModel?.state&&!this.disabled}get effectiveMaxScale(){return this.viewModel.effectiveMaxScale}get effectiveMinScale(){return this.viewModel.effectiveMinScale}get effectiveMaxScaleLimit(){return this.viewModel.effectiveMaxScaleLimit}get effectiveMinScaleLimit(){return this.viewModel.effectiveMinScaleLimit}get icon(){return"actual-size"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxScale(){return this.viewModel.maxScale}set maxScale(e){this.viewModel.maxScale=e}get maxScaleLimit(){return this.viewModel.maxScaleLimit}set maxScaleLimit(e){this.viewModel.maxScaleLimit=e}get mode(){return this.viewModel.mode}set mode(e){this.viewModel.mode=e}get minScale(){return this.viewModel.minScale}set minScale(e){this.viewModel.minScale=e}get minScaleLimit(){return this.viewModel.minScaleLimit}set minScaleLimit(e){this.viewModel.minScaleLimit=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}castVisibleElements(e){return{...x,...e,scaleMenus:"boolean"==typeof e?.scaleMenus?e.scaleMenus:{...x.scaleMenus,...e?.scaleMenus}}}formatScale(e){return`${L}${t(e,I)}`}render(){const{_interactive:e,_slider:t,label:i,view:l,viewModel:{state:a}}=this,s=this._getLabel("min"),n=this._getLabel("max"),{segmentElements:o}=t,r=o.at("min-scale-only"===this.mode?-1:-2);return r&&r.classList.add(p.segmentElementActive),w("div",{"aria-label":i,class:this.classes(p.base,g.widget,e?null:g.disabled)},w("div",{class:p.scaleIndicatorWrapper,dir:"ltr"},"ready"===a&&l?this._renderCurrentScaleIndicator():null,t.render(),this._renderPreviewPopover()),w("div",{class:p.scaleMenuContainer},this._minScaleMenuEnabled&&s?this._renderScaleMenuToggle("min",s):null,w("div",{class:p.scaleMenuSeparator}),this._maxScaleMenuEnabled&&n?this._renderScaleMenuToggle("max",n):null))}_renderPreviewPopover(){const{_activeThumb:e}=this,t=null!=e&&this.visibleElements.preview,i=t?0===e?this._minThumbNode:this._maxThumbNode:"";return w("calcite-popover",{afterCreate:f,afterUpdate:()=>this._previewPopover?.reposition(),bind:this,"data-node-ref":"_previewPopover",label:this.messages.preview,offsetDistance:T,open:t,overlayPositioning:"fixed",placement:"top",referenceElement:i,triggerDisabled:!0},this._renderScalePreview())}_renderScalePreview(){const{_activeThumb:e,_slider:t,region:i,viewModel:{scaleRanges:l}}=this,a=0===e||"range"!==this.mode?t.values[0]:t.values[1],s=Object.keys(S.RecommendedScales).indexOf(l.findScaleRangeByIndex(a).id),n={backgroundImage:v(i),backgroundPosition:h(s)};return w("div",{class:p.scalePreview},w("div",{class:p.scalePreviewThumbnail,styles:n}))}_getLabel(e){const{_slider:t,messages:i,mode:l,viewModel:{scaleRanges:a}}=this,[s,n]=t.values,o="min"===e||"range"!==l?s:n,r=i.scaleRangeLabels[a.findScaleRangeByIndex(o).id];switch(l){case"range":return r;case"max-scale-only":return"min"===e?null:r;case"min-scale-only":return"min"===e?r:null}}_renderScaleMenuToggle(e,t){const{_activeMenu:i,_interactive:l}=this,a=i===e;return[w("calcite-dropdown",{closeOnSelectDisabled:!0,"data-type":e,open:a,overlayPositioning:"fixed",placement:"max"===e?"bottom-end":"bottom-start",scale:"s",onCalciteDropdownClose:({currentTarget:t})=>{this._activeMenu===e&&this._setActiveMenu(null),y(t.querySelector("calcite-button"))},onCalciteDropdownOpen:()=>this._setActiveMenu(e)},w("calcite-button",{appearance:a?"outline":"transparent","aria-pressed":a.toString(),class:p.scaleMenuToggle,disabled:!l,iconEnd:"chevron-down",scale:"s",slot:"trigger"},t),a&&"max"===e?this._renderMaxScaleMenu():null,a&&"min"===e?this._renderMinScaleMenu():null)]}_renderMinScaleMenu(){const{effectiveMaxScale:e,effectiveMinScaleLimit:t,view:i,viewModel:{scaleRanges:l}}=this,a=i?i.scale:void 0;return this._renderScaleMenu({type:"min",min:t,max:l.findScaleRange(e).minScale,viewScale:a})}_renderMaxScaleMenu(){const{effectiveMinScale:e,effectiveMaxScaleLimit:t,view:i,viewModel:{scaleRanges:l}}=this,a=i?i.scale:void 0;return this._renderScaleMenu({type:"max",min:l.findScaleRange(e).maxScale,max:t,viewScale:a})}_renderScaleMenu({viewScale:e,min:t,max:i,type:l}){const{effectiveMaxScale:a,effectiveMinScale:s,messages:n,showWorldValue:o}=this,r="max"===l?a:s,c=S.fromScaleRange({minScale:t,maxScale:i}),d=this.messages.featuredScaleLabels,m=S.RecommendedScales,u=Object.keys(m).filter(e=>c.contains(m[e])).map(e=>this._renderScaleMenuItem({scaleLabel:d[e],scaleValue:m[e],isSelected:r===m[e],valueVisible:"world"!==e||o}));return w("calcite-dropdown-group",{key:`${this.id}__scale-menu--${l}`},this._renderCustomScaleValue({currentScale:r}),null!=e?this._renderScaleMenuItem({scaleValue:e,scaleLabel:n.featuredScaleLabels.current,isSelected:r===e,valueVisible:!0}):null,u)}_renderCustomScaleValue({currentScale:e}){const{messages:t}=this,i=Math.round(e).toString();return w("calcite-dropdown-item",{afterCreate:e=>{y(e)},key:"custom-scale",label:t.featuredScaleLabels.custom,onCalciteDropdownItemSelect:()=>{y(this._customInput)}},w("calcite-label",{scale:"s"},w("span",null,t.featuredScaleLabels.custom),w("calcite-input-number",{afterCreate:this._afterInputNumberCreate,groupSeparator:!0,inputMode:"numeric",max:S.RecommendedScales.world,min:0,numberButtonType:"none",placeholder:t.customScaleInputTooltip,prefixText:L,scale:"s",step:1,value:i,onCalciteInputNumberChange:({currentTarget:e})=>this._handleCustomScaleInputChange(i,e)})))}_renderScaleMenuItem(e){const{scaleValue:t,scaleLabel:i,valueVisible:l,isSelected:a}=e;return w("calcite-dropdown-item",{key:i,label:i,selected:a,onCalciteDropdownItemSelect:this._setScale.bind(this,t)},i,l?w("div",{class:p.scaleMenuSubLabel},this.formatScale(t)):void 0)}_renderCurrentScaleIndicator(){const{_slider:e,messages:t,view:l,viewModel:{scaleRanges:a}}=this,s=a.clampScale(l.scale),n=this.viewModel.mapScaleToSlider(s),o=n/e.max,r=t.scaleRangeLabels[a.findScaleRangeByIndex(n).id],c=i(t.currentScaleTooltip,{scaleLabel:r});return w("div",{class:p.scaleIndicatorContainer,key:"scale-indicator"},w("div",{"aria-label":c,class:p.scaleIndicator,styles:{left:100*o+"%"},title:c},this.renderCurrentScaleIndicatorIcon()))}renderCurrentScaleIndicatorIcon(){return w("calcite-icon",{class:p.scaleIndicatorIcon,icon:"caret-up",scale:"s"})}_setScale(e){"max"===this._activeMenu?this.maxScale=Math.min(e,this.effectiveMinScale-1):this.minScale=Math.max(e,this.effectiveMaxScale+1),this._setActiveMenu(null)}_setActiveMenu(e){this._activeMenu=e}};e([r()],C.prototype,"_activeMenu",void 0),e([r()],C.prototype,"_activeThumb",void 0),e([r()],C.prototype,"_customInput",void 0),e([r()],C.prototype,"_maxScaleMenuEnabled",null),e([r()],C.prototype,"_minScaleMenuEnabled",null),e([r()],C.prototype,"_slider",void 0),e([r({readOnly:!0})],C.prototype,"_interactive",null),e([r()],C.prototype,"disabled",void 0),e([r()],C.prototype,"effectiveMaxScale",null),e([r()],C.prototype,"effectiveMinScale",null),e([r()],C.prototype,"effectiveMaxScaleLimit",null),e([r()],C.prototype,"effectiveMinScaleLimit",null),e([r()],C.prototype,"icon",null),e([r()],C.prototype,"label",null),e([r()],C.prototype,"layer",null),e([r()],C.prototype,"maxScale",null),e([r()],C.prototype,"maxScaleLimit",null),e([r(),_("esri/widgets/ScaleRangeSlider/t9n/ScaleRangeSlider")],C.prototype,"messages",void 0),e([r()],C.prototype,"mode",null),e([r()],C.prototype,"minScale",null),e([r()],C.prototype,"minScaleLimit",null),e([r()],C.prototype,"region",void 0),e([r()],C.prototype,"showWorldValue",void 0),e([r()],C.prototype,"view",null),e([r()],C.prototype,"viewModel",void 0),e([r()],C.prototype,"visibleElements",void 0),e([c("visibleElements")],C.prototype,"castVisibleElements",null),C=e([d("esri.widgets.ScaleRangeSlider")],C);const R=C;export{R as default};
5
+ import{__decorate as e}from"tslib";import{formatNumber as t,substitute as i}from"../intl.js";import{on as l}from"../core/events.js";import{destroyMaybe as a}from"../core/maybe.js";import{watch as s,when as n,initial as o}from"../core/reactiveUtils.js";import{property as r,cast as c,subclass as d}from"../core/accessorSupport/decorators.js";import m from"./Slider.js";import u from"./Widget.js";import{css as p}from"./ScaleRangeSlider/css.js";import{getScalePreviewSource as v,getScalePreviewSpriteBackgroundPosition as h}from"./ScaleRangeSlider/scalePreviewUtils.js";import S from"./ScaleRangeSlider/ScaleRanges.js";import M from"./ScaleRangeSlider/ScaleRangeSliderViewModel.js";import{loadCalciteComponents as b}from"./support/componentsUtils.js";import{globalCss as g}from"./support/globalCss.js";import{messageBundle as _,tsx as w}from"./support/widget.js";import{storeNode as f,setFocus as y}from"./support/widgetUtils.js";const x={preview:!0,scaleMenus:{maxScaleMenu:!0,minScaleMenu:!0}},I={maximumFractionDigits:0},L="1:",T=16;let C=class extends u{constructor(e,t){super(e,t),this._activeMenu=null,this._activeThumb=null,this._customInput=null,this._maxThumbNode=null,this._minThumbNode=null,this._previewAutoCloseTimeoutId=void 0,this._previewPopover=null,this._slider=new m({thumbCreatedFunction:(e,t,i)=>{0===e?this._minThumbNode=i:1===e&&(this._maxThumbNode=i),this.addHandles([l(i,"mouseenter",()=>{this._activeThumb=e,this.scheduleRender()}),l(i,"mouseleave",()=>{this._previewAutoCloseTimeoutId||(this._activeThumb=null,this.scheduleRender())})])}}),this.disabled=!1,this.messages=null,this.region="US",this.showWorldValue=!1,this.viewModel=new M,this.visibleElements=x,this._afterInputNumberCreate=e=>{"value"in e&&null!=e.value&&"setNumberValue"in e&&e.setNumberValue({committing:!1,value:e.value,origin:"direct"}),this._customInput=e},this._handleCustomScaleInputChange=(e,t)=>{const{viewModel:{scaleRanges:i}}=this,l=Number.parseFloat(t.value);Number.isNaN(l)?t.value=e:this._setScale(i.clampScale(l))}}loadDependencies(){return b({button:()=>import("@esri/calcite-components/dist/components/calcite-button"),dropdown:()=>import("@esri/calcite-components/dist/components/calcite-dropdown"),"dropdown-group":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-group"),"dropdown-item":()=>import("@esri/calcite-components/dist/components/calcite-dropdown-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),"input-number":()=>import("@esri/calcite-components/dist/components/calcite-input-number"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),popover:()=>import("@esri/calcite-components/dist/components/calcite-popover")})}initialize(){this.addHandles([s(()=>this.viewModel,e=>this._slider.viewModel=e?.sliderViewModel??null,o),s(()=>this._interactive,e=>{this._slider.disabled=!e,e||this._setActiveMenu(null)},o),this._slider.on("thumb-drag",({index:e})=>{this._activeThumb=e,clearTimeout(this._previewAutoCloseTimeoutId);const t=250;this._previewAutoCloseTimeoutId=setTimeout(()=>{this._previewAutoCloseTimeoutId=void 0,this._activeThumb=null},t)}),n(()=>!0===this.view?.stationary,()=>this.scheduleRender())])}destroy(){this._slider=a(this._slider)}get _maxScaleMenuEnabled(){const{scaleMenus:e}=this.visibleElements;return!0===e||"boolean"!=typeof e&&!0===e?.maxScaleMenu}get _minScaleMenuEnabled(){const{scaleMenus:e}=this.visibleElements;return!0===e||"boolean"!=typeof e&&!0===e?.minScaleMenu}get _interactive(){return"disabled"!==this.viewModel?.state&&!this.disabled}get effectiveMaxScale(){return this.viewModel.effectiveMaxScale}get effectiveMinScale(){return this.viewModel.effectiveMinScale}get effectiveMaxScaleLimit(){return this.viewModel.effectiveMaxScaleLimit}get effectiveMinScaleLimit(){return this.viewModel.effectiveMinScaleLimit}get icon(){return"actual-size"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxScale(){return this.viewModel.maxScale}set maxScale(e){this.viewModel.maxScale=e}get maxScaleLimit(){return this.viewModel.maxScaleLimit}set maxScaleLimit(e){this.viewModel.maxScaleLimit=e}get mode(){return this.viewModel.mode}set mode(e){this.viewModel.mode=e}get minScale(){return this.viewModel.minScale}set minScale(e){this.viewModel.minScale=e}get minScaleLimit(){return this.viewModel.minScaleLimit}set minScaleLimit(e){this.viewModel.minScaleLimit=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}castVisibleElements(e){return{...x,...e,scaleMenus:"boolean"==typeof e?.scaleMenus?e.scaleMenus:{...x.scaleMenus,...e?.scaleMenus}}}formatScale(e){return`${L}${t(e,I)}`}render(){const{_interactive:e,_slider:t,label:i,view:l,viewModel:{state:a}}=this,s=this._getLabel("min"),n=this._getLabel("max"),{segmentElements:o}=t,r=o.at("min-scale-only"===this.mode?-1:-2);return r&&r.classList.add(p.segmentElementActive),w("div",{"aria-label":i,class:this.classes(p.base,g.widget,e?null:g.disabled)},w("div",{class:p.scaleIndicatorWrapper,dir:"ltr"},"ready"===a&&l?this._renderCurrentScaleIndicator():null,t.render(),this._renderPreviewPopover()),w("div",{class:p.scaleMenuContainer},this._minScaleMenuEnabled&&s?this._renderScaleMenuToggle("min",s):null,w("div",{class:p.scaleMenuSeparator}),this._maxScaleMenuEnabled&&n?this._renderScaleMenuToggle("max",n):null))}_renderPreviewPopover(){const{_activeThumb:e}=this,t=null!=e&&this.visibleElements.preview,i=t?0===e?this._minThumbNode:this._maxThumbNode:"";return w("calcite-popover",{afterCreate:f,afterUpdate:()=>this._previewPopover?.reposition(),bind:this,"data-node-ref":"_previewPopover",label:this.messages.preview,offsetDistance:T,open:t,overlayPositioning:"fixed",placement:"top",referenceElement:i,triggerDisabled:!0},this._renderScalePreview())}_renderScalePreview(){const{_activeThumb:e,_slider:t,region:i,viewModel:{scaleRanges:l}}=this,a=0===e||"range"!==this.mode?t.values[0]:t.values[1],s=Object.keys(S.RecommendedScales).indexOf(l.findScaleRangeByIndex(a).id),n={backgroundImage:v(i),backgroundPosition:h(s)};return w("div",{class:p.scalePreview},w("div",{class:p.scalePreviewThumbnail,styles:n}))}_getLabel(e){const{_slider:t,messages:i,mode:l,viewModel:{scaleRanges:a}}=this,[s,n]=t.values,o="min"===e||"range"!==l?s:n,r=i.scaleRangeLabels[a.findScaleRangeByIndex(o).id];switch(l){case"range":return r;case"max-scale-only":return"min"===e?null:r;case"min-scale-only":return"min"===e?r:null}}_renderScaleMenuToggle(e,t){const{_activeMenu:i,_interactive:l}=this,a=i===e;return[w("calcite-dropdown",{closeOnSelectDisabled:!0,"data-type":e,open:a,overlayPositioning:"fixed",placement:"max"===e?"bottom-end":"bottom-start",scale:"s",onCalciteDropdownClose:({currentTarget:t})=>{this._activeMenu===e&&this._setActiveMenu(null),y(t.querySelector("calcite-button"))},onCalciteDropdownOpen:()=>this._setActiveMenu(e)},w("calcite-button",{appearance:a?"outline":"transparent","aria-pressed":a.toString(),class:p.scaleMenuToggle,disabled:!l,iconEnd:"chevron-down",scale:"s",slot:"trigger"},t),a&&"max"===e?this._renderMaxScaleMenu():null,a&&"min"===e?this._renderMinScaleMenu():null)]}_renderMinScaleMenu(){const{effectiveMaxScale:e,effectiveMinScaleLimit:t,view:i,viewModel:{scaleRanges:l}}=this,a=i?i.scale:void 0;return this._renderScaleMenu({type:"min",min:t,max:l.findScaleRange(e).minScale,viewScale:a})}_renderMaxScaleMenu(){const{effectiveMinScale:e,effectiveMaxScaleLimit:t,view:i,viewModel:{scaleRanges:l}}=this,a=i?i.scale:void 0;return this._renderScaleMenu({type:"max",min:l.findScaleRange(e).maxScale,max:t,viewScale:a})}_renderScaleMenu({viewScale:e,min:t,max:i,type:l}){const{effectiveMaxScale:a,effectiveMinScale:s,messages:n,showWorldValue:o}=this,r="max"===l?a:s,c=S.fromScaleRange({minScale:t,maxScale:i}),d=this.messages.featuredScaleLabels,m=S.RecommendedScales,u=Object.keys(m).filter(e=>c.contains(m[e])).map(e=>this._renderScaleMenuItem({scaleLabel:d[e],scaleValue:m[e],isSelected:r===m[e],valueVisible:"world"!==e||o}));return w("calcite-dropdown-group",{key:`${this.id}__scale-menu--${l}`},this._renderCustomScaleValue({currentScale:r}),null!=e?this._renderScaleMenuItem({scaleValue:e,scaleLabel:n.featuredScaleLabels.current,isSelected:r===e,valueVisible:!0}):null,u)}_renderCustomScaleValue({currentScale:e}){const{messages:t}=this,i=Math.round(e).toString();return w("calcite-dropdown-item",{afterCreate:e=>{y(e)},key:"custom-scale",label:t.featuredScaleLabels.custom,onCalciteDropdownItemSelect:()=>{y(this._customInput)}},w("calcite-label",{scale:"s"},w("span",null,t.featuredScaleLabels.custom),w("calcite-input-number",{afterCreate:this._afterInputNumberCreate,groupSeparator:!0,inputMode:"numeric",max:S.RecommendedScales.world,min:0,numberButtonType:"none",placeholder:t.customScaleInputTooltip,prefixText:L,scale:"s",step:1,value:i,onCalciteInputNumberChange:({currentTarget:e})=>this._handleCustomScaleInputChange(i,e)})))}_renderScaleMenuItem(e){const{scaleValue:t,scaleLabel:i,valueVisible:l,isSelected:a}=e;return w("calcite-dropdown-item",{key:i,label:i,selected:a,onCalciteDropdownItemSelect:this._setScale.bind(this,t)},i,l?w("div",{class:p.scaleMenuSubLabel},this.formatScale(t)):void 0)}_renderCurrentScaleIndicator(){const{_slider:e,messages:t,view:l,viewModel:{scaleRanges:a}}=this,s=a.clampScale(l.scale),n=this.viewModel.mapScaleToSlider(s),o=n/e.max,r=t.scaleRangeLabels[a.findScaleRangeByIndex(n).id],c=i(t.currentScaleTooltip,{scaleLabel:r});return w("div",{class:p.scaleIndicatorContainer,key:"scale-indicator"},w("div",{"aria-label":c,class:p.scaleIndicator,styles:{left:100*o+"%"},title:c},this.renderCurrentScaleIndicatorIcon()))}renderCurrentScaleIndicatorIcon(){return w("calcite-icon",{class:p.scaleIndicatorIcon,icon:"caret-up",scale:"s"})}_setScale(e){"max"===this._activeMenu?this.maxScale=Math.min(e,this.effectiveMinScale-1):this.minScale=Math.max(e,this.effectiveMaxScale+1),this._setActiveMenu(null)}_setActiveMenu(e){this._activeMenu=e}};e([r()],C.prototype,"_activeMenu",void 0),e([r()],C.prototype,"_activeThumb",void 0),e([r()],C.prototype,"_customInput",void 0),e([r()],C.prototype,"_maxScaleMenuEnabled",null),e([r()],C.prototype,"_minScaleMenuEnabled",null),e([r()],C.prototype,"_slider",void 0),e([r({readOnly:!0})],C.prototype,"_interactive",null),e([r()],C.prototype,"disabled",void 0),e([r()],C.prototype,"effectiveMaxScale",null),e([r()],C.prototype,"effectiveMinScale",null),e([r()],C.prototype,"effectiveMaxScaleLimit",null),e([r()],C.prototype,"effectiveMinScaleLimit",null),e([r()],C.prototype,"icon",null),e([r()],C.prototype,"label",null),e([r()],C.prototype,"layer",null),e([r()],C.prototype,"maxScale",null),e([r()],C.prototype,"maxScaleLimit",null),e([r(),_("esri/widgets/ScaleRangeSlider/t9n/ScaleRangeSlider")],C.prototype,"messages",void 0),e([r()],C.prototype,"mode",null),e([r()],C.prototype,"minScale",null),e([r()],C.prototype,"minScaleLimit",null),e([r()],C.prototype,"region",void 0),e([r()],C.prototype,"showWorldValue",void 0),e([r()],C.prototype,"view",null),e([r()],C.prototype,"viewModel",void 0),e([r()],C.prototype,"visibleElements",void 0),e([c("visibleElements")],C.prototype,"castVisibleElements",null),C=e([d("esri.widgets.ScaleRangeSlider")],C);const R=C;export{R as default};
package/widgets/Slider.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import i from"../core/Collection.js";import{assertIsSome as n}from"../core/maybe.js";import{property as s,cast as o,subclass as r}from"../core/accessorSupport/decorators.js";import a from"./Widget.js";import{css as l}from"./Slider/css.js";import h from"./Slider/SliderViewModel.js";import{globalCss as u}from"./support/globalCss.js";import{messageBundle as d,tsx as c}from"./support/widget.js";import{onResize as m}from"./support/widgetUtils.js";const _={showInput:"Enter",hideInput1:"Enter",hideInput2:"Escape",hideInput3:"Tab",moveAnchorUp:"ArrowUp",moveAnchorDown:"ArrowDown",moveAnchorLeft:"ArrowLeft",moveAnchorRight:"ArrowRight",moveAnchorToMax:"End",moveAnchorToMin:"Home"},p={labels:!1,rangeLabels:!1};let v=class extends a{constructor(e,t){super(e,t),this._activeLabelInputIndex=null,this._anchorElements=[],this._dragged=!1,this._dragStartInfo=null,this._focusedAnchorIndex=null,this._isMinInputActive=!1,this._isMaxInputActive=!1,this._lastMovedHandleIndex=null,this._positionPrecision=5,this._segmentDragStartInfo=null,this._trackHeight=null,this._trackWidth=null,this._zIndices=[],this._zIndexOffset=3,this.disabled=!1,this.draggableSegmentsEnabled=!0,this.effectiveSegmentElements=new i,this.extraNodes=[],this.inputCreatedFunction=null,this.labelElements=new i,this.labelInputsEnabled=!1,this.maxLabelElement=null,this.messages=null,this.minLabelElement=null,this.rangeLabelInputsEnabled=!1,this.segmentElements=new i,this.snapOnClickEnabled=!0,this.steps=null,this.syncedSegmentsEnabled=!1,this.thumbCreatedFunction=null,this.thumbElements=new i,this.tickElements=new i,this.trackElement=null,this.viewModel=new h,this.visibleElements={...p},this._onAnchorPointerDown=this._onAnchorPointerDown.bind(this),this._onAnchorPointerMove=this._onAnchorPointerMove.bind(this),this._onAnchorPointerUp=this._onAnchorPointerUp.bind(this),this._onLabelPointerDown=this._onLabelPointerDown.bind(this),this._onLabelPointerUp=this._onLabelPointerUp.bind(this),this._onSegmentPointerDown=this._onSegmentPointerDown.bind(this),this._onSegmentPointerMove=this._onSegmentPointerMove.bind(this),this._onSegmentPointerUp=this._onSegmentPointerUp.bind(this),this._onTrackPointerDown=this._onTrackPointerDown.bind(this),this._onTrackPointerMove=this._onTrackPointerMove.bind(this),this._onTrackPointerUp=this._onTrackPointerUp.bind(this)}destroy(){document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove),document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),this.labelElements.removeAll(),this.labelElements.destroy(),this.segmentElements.removeAll(),this.segmentElements.destroy(),this.effectiveSegmentElements.removeAll(),this.effectiveSegmentElements.destroy(),this.thumbElements.removeAll(),this.thumbElements.destroy(),this.tickElements.removeAll(),this.tickElements.destroy()}get _isDisabled(){return this.disabled||"disabled"===this.state}get effectiveMax(){return this.viewModel.effectiveMax}set effectiveMax(e){this.viewModel.effectiveMax=e}get effectiveMin(){return this.viewModel.effectiveMin}set effectiveMin(e){this.viewModel.effectiveMin=e}get inputFormatFunction(){return this.viewModel.inputFormatFunction}set inputFormatFunction(e){this.viewModel.inputFormatFunction=e}get inputParseFunction(){return this.viewModel.inputParseFunction}set inputParseFunction(e){this.viewModel.inputParseFunction=e}get icon(){return"caret-double-horizontal"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get labelFormatFunction(){return this.viewModel.labelFormatFunction}set labelFormatFunction(e){this.viewModel.labelFormatFunction=e}get labels(){return this.viewModel.labels}set layout(e){["vertical","vertical-reversed","horizontal","horizontal-reversed"].includes(e)||(e="horizontal"),this._set("layout",e)}get max(){return this.viewModel.max}set max(e){this.viewModel.max=e}get min(){return this.viewModel.min}set min(e){this.viewModel.min=e}get precision(){return this.viewModel.precision}set precision(e){this.viewModel.precision=e}get state(){const{_activeLabelInputIndex:e,_isMaxInputActive:t,_isMinInputActive:i,_dragStartInfo:n,_segmentDragStartInfo:s,disabled:o,viewModel:r}=this;return o?"disabled":!(null===e&&!t&&!i)?"editing":null!=n||null!=s?"dragging":r.state}get thumbsConstrained(){return this.viewModel.thumbsConstrained}set thumbsConstrained(e){this.viewModel.thumbsConstrained=e}set tickConfigs(e){this._set("tickConfigs",e),this.scheduleRender()}get values(){return this.viewModel.values}set values(e){this.viewModel.values=e}castVisibleElements(e){return{...p,...e}}render(){const{label:e}=this,t=this.classes(l.base,u.widget,this._isHorizontalLayout()?l.horizontalLayout:l.verticalLayout,this._isReversedLayout()?l.reversed:null,this._isDisabled?u.disabled:null);return this._storeTrackDimensions(),c("div",{afterCreate:this._afterContainerCreate,"aria-label":e,bind:this,class:t,"touch-action":"none"},this._renderContent())}toNextStep(e){this._toStep(e,1)}toPreviousStep(e){this._toStep(e,-1)}getCurrentPosition(){return this._positionFromValue(this.values?.[0]??0)}_renderContent(){const{max:e,min:t}=this;if(!(null==t||null==e||t>=e))return[this._renderMin(),this._renderSliderContainer(),this._renderMax()]}_renderSliderContainer(){return c("div",{bind:this,class:l.contentElement,key:"slider-container"},this._renderTrackElement(),this._renderTicksContainer(),this._renderExtraContentElements())}_renderTrackElement(){return c("div",{afterCreate:this._afterTrackCreate,afterRemoved:this._afterTrackRemoved,bind:this,class:l.trackElement,"touch-action":"none"},this._renderEffectiveSegmentElements(),this._renderSegmentElements(),this._renderAnchorElements())}_renderEffectiveSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=null!=this.effectiveMax,t=null!=this.effectiveMin;if(!e&&!t)return;const{max:i,min:n,viewModel:s}=this,o=s.getBounds(),r=[];return t&&r.push(this._renderEffectiveSegmentElement(n,o.min,!0)),e&&r.push(this._renderEffectiveSegmentElement(o.max,i,!1)),r}_renderSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=this.values.length,t=[];for(let i=0;i<=e;i++)t.push(this._renderSegmentElement(i));return t}_renderSegmentElement(e){const{_trackHeight:t,_trackWidth:i,draggableSegmentsEnabled:n,id:s,state:o}=this,r=this.values,a=this._isHorizontalLayout(),h=a?i:t,u=this.viewModel.getBounds(),d=this._positionFromValue(u.max),m=this._positionFromValue(u.min),_=e===r?.length?null:e,p=0===e?null:e-1,v=null!=_,g=null!=p;let f,b;const E=[...r].sort((e,t)=>e-t);this._isReversedLayout()?(f=g?this._positionFromValue(E[p]):m,b=v?this._positionFromValue(E[_]):d):(f=v?this._positionFromValue(E[_]):d,b=g?this._positionFromValue(E[p]):m);const x=this._applyPrecisionToPosition(100*b/h),y=(f-b)/h,P=a?`transform: translate(${x}%, 0px) scale(${y}, 1);`:`transform: translate(0px, ${x}%) scale(1, ${y});`,k=this.classes(l.segmentElement,l.segmentElementIndexPrefix+e,n&&v&&g&&"disabled"!==o?l.segmentElementInteractive:null);return c("div",{afterCreate:this._afterSegmentCreate,afterRemoved:this._afterSegmentRemoved,bind:this,class:k,"data-max-thumb-index":_,"data-min-thumb-index":p,"data-segment-index":e,key:`${s}-segment-${e}`,style:P,"touch-action":"none"})}_renderEffectiveSegmentElement(e,t,i){const{_trackHeight:n,_trackWidth:s,layout:o}=this,r=this._positionFromValue(e),a=this._positionFromValue(t),h=this._isHorizontalLayout(),u=h?s:n,d=this._applyPrecisionToPosition(100*r/u);let m=null;if("horizontal"===o){const e=i?u-a:a,t=r===u?0:d;m=`clip-path: inset(0% ${a===u?0:this._applyPrecisionToPosition(e/u*100)}% 0% ${t}%);`}else{const e=(a-r)/u;m=h?`transform: translate(${d}%, 0px) scale(${e}, 1);`:`transform: translate(0px, ${d}%) scale(1, ${e});`}const _=i?l.effectiveMinSegmentElement:l.effectiveMaxSegmentElement,p=this.classes(l.segmentElement,l.effectiveSegmentElement,_);return c("div",{afterCreate:this._afterEffectiveSegmentCreate,afterRemoved:this._afterEffectiveSegmentRemoved,bind:this,class:p,style:m,"touch-action":"none"})}_renderAnchorElements(){const{trackElement:e,values:t}=this;if(t?.length)return this._zIndices=t.map((e,i)=>{const n=this._positionFromValue(e),s=this._positionToPercent(n),o=(this._isHorizontalLayout()?s>50:s<50)?-1:1;return this._zIndexOffset+(t.length+o*i)}),e&&t&&t.length?t.map((e,t)=>this._renderAnchorElement(e,t)):null}_renderAnchorElement(e,i){const n=this._positionFromValue(e),s=this._valueFromPosition(n);if(null==s||isNaN(s))return;const{_dragStartInfo:o,_lastMovedHandleIndex:r,id:a,layout:h,visibleElements:{labels:u}}=this,d=this.values,m=o?.index===i,_=r===i,p=this.classes(l.anchorElement,l.anchorElementIndexPrefix+i,m?l.movingAnchorElement:null,_?l.lastMovedAnchorElement:null),v=this.labels.values[i],g=this._getStyleForAnchor(e,i,m||_),{min:f,max:b}=this.viewModel.getBoundsForValueAtIndex(i),{disabled:E,messages:x}=this,y=2===d.length?t(0===i?x.rangeMinimum:x.rangeMaximum,{value:e}):v,P=1===d.length?null:0===i?`${a}-handle-${i+1}`:i===d.length-1?`${a}-handle-${i-1}`:`${a}-handle-${i-1} ${a}-handle-${i+1}`;return c("div",{afterCreate:this._afterAnchorCreate,afterRemoved:this._afterAnchorRemoved,afterUpdate:this._afterAnchorUpdate,"aria-controls":P,"aria-label":x.sliderValue,"aria-labelledby":u?`${a}-label-${i}`:null,"aria-orientation":h,"aria-valuemax":b?.toString(),"aria-valuemin":f?.toString(),"aria-valuenow":e.toString(),"aria-valuetext":y,bind:this,class:p,"data-thumb-index":i,"data-value":e,id:`${a}-handle-${i}`,key:`${a}-handle-${i}`,onkeydown:this._onAnchorKeyDown,role:"slider",style:g,tabIndex:E?-1:0,"touch-action":"none"},c("span",{afterCreate:this._afterThumbCreate,afterRemoved:this._afterThumbRemoved,bind:this,class:l.thumbElement,"data-thumb-index":i,"touch-action":"none"}),this.renderThumbLabel(i))}renderThumbLabel(e){const{id:t,labels:i,labelInputsEnabled:n,state:s}=this,o=this.visibleElements.labels,r=i.values[e],a=this.classes(l.labelElement,o?null:u.hidden,n&&"disabled"!==s?l.labelElementInteractive:null);return c("span",{afterCreate:this._afterLabelCreate,afterRemoved:this._afterLabelRemoved,"aria-hidden":(!o).toString(),bind:this,class:a,"data-thumb-index":e,id:`${t}-label-${e}`,key:`${t}-label-${e}`,role:n?"button":void 0,"touch-action":"none"},this._activeLabelInputIndex===e?this._renderValueInput(e):r)}_renderValueInput(e){const{disabled:t,values:i}=this;if(null==i)return;const n=i[e];return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.sliderValue,bind:this,class:l.labelInput,"data-input-index":e,"data-input-type":"thumb",key:`value-input-${e}`,onblur:this._onLabelInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:t?-1:0,type:"text",value:this._formatInputValue(n,"value",e)})}_renderMax(){const{_isMaxInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(l.maxElement,{[u.hidden]:!s,[l.maxElementInteractive]:i&&"disabled"!==n,[l.rangeElementActive]:e});return c("div",{afterCreate:this._afterMaxLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMaxLabelClick,onkeydown:this._onMaxLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMaxInput():t.max)}_renderMin(){const{_isMinInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(l.minElement,{[u.hidden]:!s,[l.minElementInteractive]:i&&"disabled"!==n,[l.rangeElementActive]:e});return c("div",{afterCreate:this._afterMinLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMinLabelClick,onkeydown:this._onMinLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMinInput():t.min)}_renderMaxInput(){return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.maximumValue,bind:this,class:l.rangeInput,"data-input-type":"max",onblur:this._onMaxInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.max,"max")})}_renderMinInput(){return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.minimumValue,bind:this,class:l.rangeInput,"data-input-type":"min",onblur:this._onMinInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.min,"min")})}_renderExtraContentElements(){return c("div",{bind:this,class:l.extraContentElement},this.extraNodes)}_renderTicksContainer(){if(this.tickConfigs&&this.trackElement&&(0!==this._trackHeight||0!==this._trackWidth))return this.tickConfigs.map((e,t)=>c("div",{class:this.classes(l.ticksContainerElement),key:"ticks-container"},this._renderTicks(e,t)))}_renderTicks(e,t){const{mode:n,values:s}=e;if(this.tickElements.at(t)||this.tickElements.add(new i,t),"position"===n){const i=Array.isArray(s)?s:[s];return this._calculateTickPositions(i).map((i,n)=>this._renderTickGroup(e,n,t,i))}if("percent"===n&&Array.isArray(s)){const i=this.min??0,n=(this.max??0)-i,o=s.map(e=>this._applyPrecisionToPosition(e/100*n+i));return this._calculateTickPositions(o).map((i,n)=>this._renderTickGroup(e,n,t,i))}const o=Array.isArray(s)&&s.length?s[0]:isNaN(s)?null:s,r=this._getTickCounts(o,e);return this._calculateEquidistantTickPositions(r).map((i,n)=>this._renderTickGroup(e,n,t,i))}_renderTickGroup(e,t,i,n){const s="position"===e.mode?Array.isArray(e.values)?e.values[t]:e.values:this._valueFromPosition(n);if(null!=s&&!isNaN(s))return c("div",{afterCreate:this._afterTickGroupCreate,afterRemoved:this._afterTickGroupRemoved,bind:this,"data-config":e,"data-position":n,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":s,key:`tick-group-${t}`,onclick:this._onTickGroupClick},this._renderTickLine(e,t,i,s),e.labelsVisible?this._renderTickLabel(e,t,i,s):null)}_renderTickLine(e,t,i,n){return c("div",{afterCreate:this._afterTickLineCreate,"aria-valuenow":n.toString(),bind:this,class:l.tickElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:this._getPositionStyleForElement(n)})}_renderTickLabel(e,t,i,n){const s=e.labelFormatFunction?e.labelFormatFunction(n,"tick",t):this.viewModel.getLabelForValue(n,"tick",t);return c("div",{afterCreate:this._afterTickLabelCreate,"aria-label":s,"aria-valuenow":n.toString(),"aria-valuetext":s,bind:this,class:l.tickLabelElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:`transform: translate(-50%); ${this._getPositionStyleForElement(n)}`},s)}_afterContainerCreate(e){this.addHandles(m(e,()=>this.scheduleRender()))}_afterTrackCreate(e){this._set("trackElement",e),e.addEventListener("pointerdown",this._onTrackPointerDown),this.scheduleRender()}_afterTrackRemoved(e){e.removeEventListener("pointerdown",this._onTrackPointerDown),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp)}_afterSegmentCreate(e){this.segmentElements.add(e),e.addEventListener("pointerdown",this._onSegmentPointerDown)}_afterSegmentRemoved(e){this.segmentElements.remove(e),e.removeEventListener("pointerdown",this._onSegmentPointerDown)}_afterEffectiveSegmentCreate(e){this.effectiveSegmentElements.add(e)}_afterEffectiveSegmentRemoved(e){this.effectiveSegmentElements.remove(e)}_afterAnchorCreate(e){if(this._anchorElements.push(e),e.addEventListener("pointerdown",this._onAnchorPointerDown),this.thumbCreatedFunction){const t=g(e),i=y(e),n=this.thumbElements.at(t),s=this.labelElements.at(t)||null;this.thumbCreatedFunction(t,i,n,s)}}_afterAnchorUpdate(e){if(null!=this._focusedAnchorIndex){g(e)===this._focusedAnchorIndex&&(e.focus(),this._focusedAnchorIndex=null)}}_afterAnchorRemoved(e){const t=this._anchorElements.indexOf(e,0);t>-1&&this._anchorElements.splice(t,1),e.removeEventListener("pointerdown",this._onAnchorPointerDown)}_afterThumbCreate(e){this.thumbElements.add(e)}_afterThumbRemoved(e){this.thumbElements.remove(e)}_afterLabelCreate(e){this.labelElements.add(e),e.addEventListener("pointerdown",this._onLabelPointerDown),e.addEventListener("pointerup",this._onLabelPointerUp)}_afterLabelRemoved(e){this.labelElements.remove(e),e.removeEventListener("pointerdown",this._onLabelPointerDown),e.removeEventListener("pointerup",this._onLabelPointerUp)}_afterInputCreate(e){if(e.focus(),e.select(),this.inputCreatedFunction){const t=e.getAttribute("data-input-type"),i="thumb"===t?f(e):null;this.inputCreatedFunction(e,t,i)}}_afterTickLineCreate(e){const t=P(e),i=k(e),n=this.tickElements.at(t),s=n.at(i);s?s.tickElement=e:n.add({groupElement:null,tickElement:e,labelElement:null},i)}_afterTickLabelCreate(e){const t=P(e),i=k(e),n=this.tickElements.at(t),s=n.at(i);s?s.labelElement=e:n.add({groupElement:null,labelElement:e,tickElement:null},i)}_afterTickGroupRemoved(e){const t=P(e),i=this.tickElements.items[t],n=i?.find(t=>t.groupElement===e);n&&i.remove(n)}_afterTickGroupCreate(e){const t=I(e);if(t?.tickCreatedFunction){const i=P(e),n=k(e),s=y(e),o=this.tickElements?.at(i)?.at(n);if(o){o.groupElement=e;const i=o.tickElement||null,n=o.labelElement||null;t.tickCreatedFunction(s,i,n)}}}_afterMaxLabelCreate(e){this._set("maxLabelElement",e)}_afterMinLabelCreate(e){this._set("minLabelElement",e)}_onAnchorKeyDown(e){if(this._isDisabled||"editing"===this.state)return;const{key:t,target:i}=e,n=this.values,s=g(i),o=this._anchorElements[s],r=n[s],a=[_.moveAnchorUp,_.moveAnchorDown,_.moveAnchorLeft,_.moveAnchorRight];if(t===_.showInput&&this.labelInputsEnabled)this._activeLabelInputIndex=s;else if(a.includes(t)){e.preventDefault();const{steps:i}=this,n=t===_.moveAnchorUp||t===_.moveAnchorRight?1:-1;if(null!=i)this._toStep(s,this._isReversedLayout()?-1*n:n);else{const{precision:e}=this,t=this._getPositionOfElement(o),i=this._valueFromPosition(t),r=this._isHorizontalLayout()?n:-1*n;let a;a=0===e?this._positionFromValue(i+r):1===e?this._positionFromValue(i+.1*r):t+r,this._toPosition(s,a)}const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}else if(t===_.moveAnchorToMax||t===_.moveAnchorToMin){e.preventDefault();const{min:i,max:n}=this._getAnchorBoundsInPixels(s),o=this._isPositionInverted()?t===_.moveAnchorToMax?i:n:t===_.moveAnchorToMin?i:n;this._toPosition(s,o);const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}}_onAnchorPointerDown(e){if(this._isDisabled)return;const{target:t,clientX:i,clientY:n}=e,s=g(t);null!=s&&(e.preventDefault(),this._anchorElements[s]&&this._anchorElements[s].focus(),this._storeTrackDimensions(),this._dragStartInfo={clientX:i,clientY:n,index:s,position:this._getPositionOfElement(this._anchorElements[s])},document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onAnchorPointerMove(e){if("editing"===this.state||!this._dragStartInfo)return;e.preventDefault();const{values:t,_anchorElements:i,_dragged:n,_dragStartInfo:s,_dragStartInfo:{index:o,position:r}}=this,{clientX:a,clientY:l}=e,h=n?"drag":"start",u=i[o],d=this._getPositionOfElement(u),c=this._applyPrecisionToPosition(this._isHorizontalLayout()?r+a-s.clientX:r+l-s.clientY);if(d===c)return;const m=t[o];this._dragged=!0,this._toPosition(o,c);const _=this.values[o];n?m!==_&&this._emitThumbDragEvent({index:o,state:h,value:_}):this._emitThumbDragEvent({index:o,state:h,value:m})}_onAnchorPointerUp(e){if(document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),!this._dragStartInfo)return;e.preventDefault();const{index:t}=this._dragStartInfo,i=this._dragged,n=this.values[t];this._dragged=!1,this._dragStartInfo=null,this._lastMovedHandleIndex=t,i?this._emitThumbDragEvent({index:t,state:"stop",value:n}):(this.scheduleRender(),"editing"!==this.state&&this._emitThumbClickEvent({index:t,value:n}))}_onTrackPointerDown(e){const{_dragStartInfo:t,snapOnClickEnabled:i,state:n,values:s}=this;if(this._isDisabled||"editing"===n||t)return;if(document.addEventListener("pointermove",this._onTrackPointerMove),document.addEventListener("pointerup",this._onTrackPointerUp),!i||!s?.length)return;const{steps:o}=this,{clientX:r,clientY:a}=e,l=this._getCursorPositionFromEvent(e),h=this._valueFromPosition(l),u=this._getIndexOfNearestValue(h),d=s[u],c=s.some((e,t)=>e===d&&t!==u)&&h>d?s.lastIndexOf(d):u;if(null==c)return;const m=s[c],_=null!=o?this._calculateNearestStepPosition(l):l;this._toPosition(c,_),this._dragged=!0,this._dragStartInfo={clientX:r,clientY:a,index:c,position:_},this._focusedAnchorIndex=c,this._emitThumbDragEvent({index:c,state:"start",value:m});const p=this.values[c];m!==p&&this._emitThumbDragEvent({index:c,state:"drag",value:p}),document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove)}_onTrackPointerMove(e){e.preventDefault(),this._dragged=!0}_onTrackPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp),this.snapOnClickEnabled||(this._dragged=!1),!this._dragged){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitTrackClickEvent({value:i})}}_onSegmentPointerDown(e){e.preventDefault();const t=e.target,i=b(t),n=E(t),s=x(t);if(this._isDisabled||null==n||null==s)return;e.stopPropagation(),this._storeTrackDimensions(),document.addEventListener("pointerup",this._onSegmentPointerUp);const o=this._getAnchorDetails(n),r=this._getAnchorDetails(s);this.syncedSegmentsEnabled?(this.segmentElements.forEach(e=>e.classList.add(l.segmentElementActive)),this._anchorElements.forEach(e=>e.classList.add(l.anchorElementActive))):(this.segmentElements.at(i).classList.add(l.segmentElementActive),this._anchorElements[o.index]?.classList.add(l.anchorElementActive),this._anchorElements[r.index]?.classList.add(l.anchorElementActive)),this._segmentDragStartInfo={cursorPosition:this._getCursorPositionFromEvent(e),index:i,details:this._normalizeSegmentDetails({min:o,max:r})},this.draggableSegmentsEnabled&&(document.addEventListener("pointermove",this._onSegmentPointerMove),this._emitSegmentDragEvent({index:i,state:"start",thumbIndices:[n,s]}))}_onSegmentPointerMove(e){if(!this._segmentDragStartInfo)return;e.preventDefault();const{_trackHeight:t,_trackWidth:i,_segmentDragStartInfo:{index:n,cursorPosition:s,details:{min:o,max:r}}}=this,{index:a,position:l,value:h}=o,{index:u,position:d,value:c}=r;this._dragged=!0;const m=this._getCursorPositionFromEvent(e);if(m===s)return;const _=this._positionToPercent(s),p=this._positionToPercent(m)-_,v=this._positionToPercent(l)+p,g=this._positionToPercent(d)+p,{min:f}=this._getAnchorBoundsAsPercents(a),{max:b}=this._getAnchorBoundsAsPercents(u);let E=!1,x=!1;if(v<f?E=!0:g>b&&(x=!0),E){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(a),i=this._isPositionInverted()?t:e,n=i,s=c+(i-h),o=s-this.values[u];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[n,s]))}if(x){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(u),i=this._isPositionInverted()?e:t,n=i,s=h+(i-c),o=s-this.values[a];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[s,n]))}const y=this._isHorizontalLayout()?i:t,P=g/100*y,k=v/100*y,I=this.values,A=[I[a],I[u]],M=this._getValueForAnchorAtPosition(a,k),L=this._getValueForAnchorAtPosition(u,P);this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(M-A[0]):this._updateAnchorValues([a,u],[M,L]);[this.values[a],this.values[u]].every((e,t)=>e===A[t])||this._emitSegmentDragEvent({index:n,state:"drag",thumbIndices:[a,u]})}_onSegmentPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointerup",this._onSegmentPointerUp),document.removeEventListener("pointermove",this._onSegmentPointerMove),!this._segmentDragStartInfo)return;const{_dragged:t}=this,i=this.min,n=this.max,s=this.values,{index:o,details:{min:{index:r},max:{index:a}}}=this._segmentDragStartInfo;if(this.segmentElements.forEach(e=>e.classList.remove(l.segmentElementActive)),this._anchorElements.forEach(e=>e.classList.remove(l.anchorElementActive)),this.draggableSegmentsEnabled){const e=n-i,t=s[r],l=s[a];this._lastMovedHandleIndex=t===l?t>e/2?r:a:null,this._dragged=!1,this._segmentDragStartInfo=null,this._emitSegmentDragEvent({index:o,state:"stop",thumbIndices:[r,a]})}if(!t){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitSegmentClickEvent({index:o,value:i,thumbIndices:[r,a]})}}_onTickGroupClick(e){const t=e.target;if(I(t)){const e=P(t),i=k(t),n=y(t);this._emitTickClickEvent({configIndex:e,groupIndex:i,value:n})}}_storeTrackDimensions(){if(this.trackElement){const e=this._getDimensions(this.trackElement);this._trackHeight=this._applyPrecisionToPosition(e.height),this._trackWidth=this._applyPrecisionToPosition(e.width)}}_onLabelPointerDown(){this._isDisabled||(this._dragged=!1,document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onLabelPointerMove(){this._isDisabled||(this._dragged=!0)}_onLabelPointerUp(e){if(this._isDisabled)return;const t=g(e.target);this.labelInputsEnabled&&!this._dragged&&null!=t&&(this._activeLabelInputIndex=t),this._dragged=!1,document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove)}_onLabelInputBlur(e){const{_activeLabelInputIndex:t,values:i,viewModel:n}=this,s=e.target.value;if(this._activeLabelInputIndex=null,!s||null==t||null==i)return;const o=this._parseInputValue(s,"value",t),r=i[t],{min:a,max:l}=this.viewModel.getBoundsForValueAtIndex(t);if(o<a||o>l)return;n.setValue(t,o);const h=this.values[t];r!==h&&this._emitThumbChangeEvent({index:t,oldValue:r,value:h})}_onInputKeyDown(e){if(this._isDisabled)return;const{key:t,target:i}=e,{hideInput1:n,hideInput2:s,hideInput3:o}=_,{_activeLabelInputIndex:r,_anchorElements:a}=this,l=i;if(t===n||t===s||t===o){e.stopPropagation();const t=r;l.blur(),null!=t?a[t].focus():l.parentElement?.focus()}}_onMaxLabelClick(){this._isDisabled||(this._emitMaxRangeLabelClickEvent({type:"max-click",value:this.max}),this.rangeLabelInputsEnabled&&(this._isMaxInputActive=!0))}_onMaxLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMaxInputActive=!0)}_onMaxInputBlur(e){const t=e.target.value;if(this._isMaxInputActive=!1,!t)return;const i=this.max,n=this._parseInputValue(t,"max");n<=this.min||(this.viewModel.set("max",n),this.max!==i&&this._emitMaxChangeEvent({oldValue:i,value:this.max}))}_onMinLabelClick(){this._isDisabled||(this._emitMinRangeLabelClickEvent({type:"min-click",value:this.min}),this.rangeLabelInputsEnabled&&(this._isMinInputActive=!0))}_onMinLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMinInputActive=!0)}_onMinInputBlur(e){const t=e.target.value;if(this._isMinInputActive=!1,!t)return;const i=this.min,n=this._parseInputValue(t,"min");n>=this.max||(this.viewModel.set("min",n),this.min!==i&&this._emitMinChangeEvent({oldValue:i,value:this.min}))}_positionFromValue(e){const{_trackHeight:t,_trackWidth:i}=this,n=this.min??0,s=this.max??0,o=s-n;if(0===o||null==e)return 0;const r=this._isHorizontalLayout();let a=r?this._applyPrecisionToPosition(i*(e-n)/o):this._applyPrecisionToPosition(t*(s-e)/o);return this._isReversedLayout()&&(a=r?i-a:t-a),a}_valueFromPosition(e){const{_trackHeight:t,_trackWidth:i,precision:n}=this,s=this.min??0,o=this.max??0,r=o-s;let a=this._isHorizontalLayout()?e*r/i+s:r*(1e3-e/t*1e3)/1e3+s;return this._isReversedLayout()&&(a=o+s-a),parseFloat(a.toFixed(n))}_positionToPercent(e){const{_trackHeight:t,_trackWidth:i}=this,n=100*e/(this._isHorizontalLayout()?i:t);return this._applyPrecisionToPosition(n)}_applyPrecisionToPosition(e){return parseFloat(e.toFixed(this._positionPrecision))}_isPositionInverted(){const{layout:e}=this;return"horizontal-reversed"===e||"vertical"===e}_isHorizontalLayout(){return this.layout.includes("horizontal")}_isReversedLayout(){return this.layout.includes("reversed")}_normalizeSegmentDetails(e){if(this._isPositionInverted()){const{min:t,max:i}=e;return{min:i,max:t}}return e}_parseInputValue(e,t,i){return this.inputParseFunction?this.inputParseFunction(e,t,i):this.viewModel.defaultInputParseFunction(e)}_formatInputValue(e,t,i){return this.inputFormatFunction?this.inputFormatFunction(e,t,i):this.viewModel.defaultInputFormatFunction(e)}_getAnchorDetails(e){const t=this.values,i=[...t].sort((e,t)=>e-t)[e],n=t.indexOf(i);return{index:n,position:this._getPositionOfElement(this._anchorElements[n]),value:i}}_updateAnchorStyle(e,t){const i=this._anchorElements[e];i&&(this._isHorizontalLayout()?i.style.left=`${t}`:i.style.top=`${t}`)}_getStyleForAnchor(e,t,i){const n=this._getPositionStyleForElement(e);if(1===this.values?.length)return`${n}`;const s=this._zIndices[t];return`${n}; z-index: ${i?this._zIndexOffset+s:s}`}_getPositionStyleForElement(e){const t=this._positionFromValue(e),i=this._positionToPercent(t);return`${this._isHorizontalLayout()?"left":"top"}: ${i}%`}_getPositionOfElement(e){const t=this._getDimensions(e.offsetParent),i=this._getDimensions(e);return this._isHorizontalLayout()?this._applyPrecisionToPosition(i.left-t.left):this._applyPrecisionToPosition(i.top-t.top)}_updateAnchorValues(e,t){e.forEach((e,i)=>this._toValue(e,t[i]))}_updateAnchorValuesByDifference(e){const{min:t,max:i,values:n}=this;n?.forEach((n,s)=>this._toValue(s,Math.max(Math.min(n+e,i),t)))}_toValue(e,t){if(null!=this.steps){t=this._getStepValues()[this._getIndexOfNearestStepValue(t)]}this._updateAnchorStyle(e,this._getPositionStyleForElement(t)),this.viewModel.setValue(e,t)}_toPosition(e,t){const i=null!=this.steps?this._getStepValueForAnchorAtPosition(e,t):this._getValueForAnchorAtPosition(e,t);this._updateAnchorStyle(e,this._getPositionStyleForElement(i)),this.viewModel.setValue(e,i)}_getValueForAnchorAtPosition(e,t){const{min:i,max:n}=this._getAnchorBoundsInPixels(e),{min:s,max:o}=this.viewModel.getBoundsForValueAtIndex(e);let r,a,l=null;return this._isPositionInverted()?(r=s,a=o):(r=o,a=s),l=t>n?r:t<i?a:this._valueFromPosition(t),l>o?l=o:l<s&&(l=s),l}_getStepValueForAnchorAtPosition(e,t){const i=this._getStepValues(),n=this._calculateNearestStepPosition(t),s=this._getValueForAnchorAtPosition(e,n);return i[this._getIndexOfNearestStepValue(s)]}_getAnchorBoundsAsPercents(e){const{min:t,max:i}=this._getAnchorBoundsInPixels(e);return{min:this._positionToPercent(t),max:this._positionToPercent(i)}}_getAnchorBoundsInPixels(e){const{_anchorElements:t,_trackHeight:i,_trackWidth:n,effectiveMax:s,effectiveMin:o,thumbsConstrained:r}=this,a=t[e-1],l=t[e+1],h=this._isHorizontalLayout()?n:i;let u,d;return this._isPositionInverted()?(u=null!=o?this._positionFromValue(o):h,d=null!=s?this._positionFromValue(s):0):(u=null!=s?this._positionFromValue(s):h,d=null!=o?this._positionFromValue(o):0),r?this._isPositionInverted()?{max:a?this._getPositionOfElement(a):u,min:l?this._getPositionOfElement(l):d}:{max:l?this._getPositionOfElement(l):u,min:a?this._getPositionOfElement(a):d}:{max:u,min:d}}_getIndexOfNearestValue(e){const t=this.values;return t.indexOf(t.reduce((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t))}_getCursorPositionFromEvent(e){const t=this._getDimensions(this.trackElement);return this._isHorizontalLayout()?this._applyPrecisionToPosition(e.clientX-t.left):this._applyPrecisionToPosition(e.clientY-t.top)}_getStepValues(){const{steps:e}=this;if(Array.isArray(e))return e;const{max:t,min:i}=this;if(null==i||null==t||null==e)return[];const n=Math.ceil((t-i)/e),s=[];for(let o=0;o<=n;o++){const n=i+e*o;s.push(n>t?t:n)}return s}_toStep(e,t){const i=this.values[e],n=this._getStepValues(),s=n.indexOf(i);let o=null;if(s>-1){let i=n[s+t];isNaN(i)&&(i=n[s]);const r=this._positionFromValue(i);o=this._getStepValueForAnchorAtPosition(e,r)}else{o=n[this._getIndexOfNearestStepValue(i)+t]}this.viewModel.setValue(e,o)}_getIndexOfNearestStepValue(e){const{steps:t}=this;if(null==t)return null;const i=this._getStepValues(),n=i.reduce((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t);return i.indexOf(n)}_calculateNearestStepPosition(e){const t=this._valueFromPosition(e),i=this._getIndexOfNearestStepValue(t),n=this._getStepValues();return this._positionFromValue(n[i])}_getTickCounts(e,t){const{mode:i}=t;return"count"===i||"position"===i?e||0:"percent"===i&&100/e||0}_calculateTickPositions(e){return e.map(e=>this._positionFromValue(e))}_calculateEquidistantTickPositions(e){const{_trackWidth:t,_trackHeight:i}=this,n=this._isHorizontalLayout()?t:i,s=n/(e-1),o=[];if(1===e)return[n/2];for(let r=0;r<e;r++){const e=r*s;e<=n&&o.push(e)}return o}_getDimensions(e){return n(e),e.getBoundingClientRect()}_emitTrackClickEvent(e){this.emit("track-click",{...e,type:"track-click"})}_emitTickClickEvent(e){this.emit("tick-click",{...e,type:"tick-click"})}_emitMaxChangeEvent(e){this.emit("max-change",{...e,type:"max-change"})}_emitMinChangeEvent(e){this.emit("min-change",{...e,type:"min-change"})}_emitThumbChangeEvent(e){this.emit("thumb-change",{...e,type:"thumb-change"})}_emitThumbClickEvent(e){this.emit("thumb-click",{...e,type:"thumb-click"})}_emitThumbDragEvent(e){this.emit("thumb-drag",{...e,type:"thumb-drag"})}_emitSegmentClickEvent(e){this.emit("segment-click",{...e,type:"segment-click"})}_emitSegmentDragEvent(e){this.emit("segment-drag",{...e,type:"segment-drag"})}_emitMinRangeLabelClickEvent(e){this.emit("min-click",e)}_emitMaxRangeLabelClickEvent(e){this.emit("min-click",e)}};function g(e){return e?.["data-thumb-index"]}function f(e){return e?.["data-input-index"]}function b(e){return e?.["data-segment-index"]}function E(e){return e?.["data-min-thumb-index"]}function x(e){return e?.["data-max-thumb-index"]}function y(e){return e?.["data-value"]}function P(e){return e?.["data-tick-config-index"]}function k(e){return e?.["data-tick-group-index"]}function I(e){return e?.["data-config"]}e([s()],v.prototype,"_activeLabelInputIndex",void 0),e([s()],v.prototype,"_dragStartInfo",void 0),e([s()],v.prototype,"_isMinInputActive",void 0),e([s()],v.prototype,"_isMaxInputActive",void 0),e([s()],v.prototype,"_segmentDragStartInfo",void 0),e([s({readOnly:!0})],v.prototype,"_isDisabled",null),e([s()],v.prototype,"disabled",void 0),e([s()],v.prototype,"draggableSegmentsEnabled",void 0),e([s()],v.prototype,"effectiveMax",null),e([s()],v.prototype,"effectiveMin",null),e([s({readOnly:!0})],v.prototype,"effectiveSegmentElements",void 0),e([s()],v.prototype,"extraNodes",void 0),e([s()],v.prototype,"inputCreatedFunction",void 0),e([s()],v.prototype,"inputFormatFunction",null),e([s()],v.prototype,"inputParseFunction",null),e([s()],v.prototype,"icon",null),e([s()],v.prototype,"label",null),e([s({readOnly:!0})],v.prototype,"labelElements",void 0),e([s()],v.prototype,"labelInputsEnabled",void 0),e([s()],v.prototype,"labelFormatFunction",null),e([s({readOnly:!0})],v.prototype,"labels",null),e([s({value:"horizontal"})],v.prototype,"layout",null),e([s()],v.prototype,"max",null),e([s({readOnly:!0})],v.prototype,"maxLabelElement",void 0),e([s(),d("esri/widgets/Slider/t9n/Slider")],v.prototype,"messages",void 0),e([s()],v.prototype,"min",null),e([s({readOnly:!0})],v.prototype,"minLabelElement",void 0),e([s()],v.prototype,"precision",null),e([s()],v.prototype,"rangeLabelInputsEnabled",void 0),e([s({readOnly:!0})],v.prototype,"segmentElements",void 0),e([s()],v.prototype,"snapOnClickEnabled",void 0),e([s({readOnly:!0})],v.prototype,"state",null),e([s()],v.prototype,"steps",void 0),e([s()],v.prototype,"syncedSegmentsEnabled",void 0),e([s()],v.prototype,"thumbsConstrained",null),e([s()],v.prototype,"thumbCreatedFunction",void 0),e([s({readOnly:!0})],v.prototype,"thumbElements",void 0),e([s()],v.prototype,"tickConfigs",null),e([s({readOnly:!0})],v.prototype,"tickElements",void 0),e([s({readOnly:!0})],v.prototype,"trackElement",void 0),e([s()],v.prototype,"values",null),e([s({type:h})],v.prototype,"viewModel",void 0),e([s()],v.prototype,"visibleElements",void 0),e([o("visibleElements")],v.prototype,"castVisibleElements",null),v=e([r("esri.widgets.Slider")],v);const A=v;export{A as default};
5
+ import{__decorate as e}from"tslib";import{substitute as t}from"../intl.js";import i from"../core/Collection.js";import{assertIsSome as n}from"../core/maybe.js";import{property as s,cast as o,subclass as r}from"../core/accessorSupport/decorators.js";import a from"./Widget.js";import{css as l}from"./Slider/css.js";import h from"./Slider/SliderViewModel.js";import{globalCss as u}from"./support/globalCss.js";import{messageBundle as d,tsx as c}from"./support/widget.js";import{onResize as m}from"./support/widgetUtils.js";const _={showInput:"Enter",hideInput1:"Enter",hideInput2:"Escape",hideInput3:"Tab",moveAnchorUp:"ArrowUp",moveAnchorDown:"ArrowDown",moveAnchorLeft:"ArrowLeft",moveAnchorRight:"ArrowRight",moveAnchorToMax:"End",moveAnchorToMin:"Home"},p={labels:!1,rangeLabels:!1};let v=class extends a{constructor(e,t){super(e,t),this._activeLabelInputIndex=null,this._anchorElements=[],this._dragged=!1,this._dragStartInfo=null,this._focusedAnchorIndex=null,this._isMinInputActive=!1,this._isMaxInputActive=!1,this._lastMovedHandleIndex=null,this._positionPrecision=5,this._segmentDragStartInfo=null,this._trackHeight=null,this._trackWidth=null,this._zIndices=[],this._zIndexOffset=3,this.disabled=!1,this.draggableSegmentsEnabled=!0,this.effectiveSegmentElements=new i,this.extraNodes=[],this.inputCreatedFunction=null,this.labelElements=new i,this.labelInputsEnabled=!1,this.maxLabelElement=null,this.messages=null,this.minLabelElement=null,this.rangeLabelInputsEnabled=!1,this.segmentElements=new i,this.snapOnClickEnabled=!0,this.steps=null,this.syncedSegmentsEnabled=!1,this.thumbCreatedFunction=null,this.thumbElements=new i,this.tickElements=new i,this.trackElement=null,this.viewModel=new h,this.visibleElements={...p},this._onAnchorPointerDown=this._onAnchorPointerDown.bind(this),this._onAnchorPointerMove=this._onAnchorPointerMove.bind(this),this._onAnchorPointerUp=this._onAnchorPointerUp.bind(this),this._onLabelPointerDown=this._onLabelPointerDown.bind(this),this._onLabelPointerUp=this._onLabelPointerUp.bind(this),this._onSegmentPointerDown=this._onSegmentPointerDown.bind(this),this._onSegmentPointerMove=this._onSegmentPointerMove.bind(this),this._onSegmentPointerUp=this._onSegmentPointerUp.bind(this),this._onTrackPointerDown=this._onTrackPointerDown.bind(this),this._onTrackPointerMove=this._onTrackPointerMove.bind(this),this._onTrackPointerUp=this._onTrackPointerUp.bind(this)}destroy(){document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove),document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),this.labelElements.removeAll(),this.labelElements.destroy(),this.segmentElements.removeAll(),this.segmentElements.destroy(),this.effectiveSegmentElements.removeAll(),this.effectiveSegmentElements.destroy(),this.thumbElements.removeAll(),this.thumbElements.destroy(),this.tickElements.removeAll(),this.tickElements.destroy()}get _isDisabled(){return this.disabled||"disabled"===this.state}get effectiveMax(){return this.viewModel.effectiveMax}set effectiveMax(e){this.viewModel.effectiveMax=e}get effectiveMin(){return this.viewModel.effectiveMin}set effectiveMin(e){this.viewModel.effectiveMin=e}get inputFormatFunction(){return this.viewModel.inputFormatFunction}set inputFormatFunction(e){this.viewModel.inputFormatFunction=e}get inputParseFunction(){return this.viewModel.inputParseFunction}set inputParseFunction(e){this.viewModel.inputParseFunction=e}get icon(){return"caret-double-horizontal"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get labelFormatFunction(){return this.viewModel.labelFormatFunction}set labelFormatFunction(e){this.viewModel.labelFormatFunction=e}get labels(){return this.viewModel.labels}set layout(e){["vertical","vertical-reversed","horizontal","horizontal-reversed"].includes(e)||(e="horizontal"),this._set("layout",e)}get max(){return this.viewModel.max}set max(e){this.viewModel.max=e}get min(){return this.viewModel.min}set min(e){this.viewModel.min=e}get precision(){return this.viewModel.precision}set precision(e){this.viewModel.precision=e}get state(){const{_activeLabelInputIndex:e,_isMaxInputActive:t,_isMinInputActive:i,_dragStartInfo:n,_segmentDragStartInfo:s,disabled:o,viewModel:r}=this;return o?"disabled":!(null===e&&!t&&!i)?"editing":null!=n||null!=s?"dragging":r.state}get thumbsConstrained(){return this.viewModel.thumbsConstrained}set thumbsConstrained(e){this.viewModel.thumbsConstrained=e}set tickConfigs(e){this._set("tickConfigs",e),this.scheduleRender()}get values(){return this.viewModel.values}set values(e){this.viewModel.values=e}castVisibleElements(e){return{...p,...e}}render(){const{label:e}=this,t=this.classes(l.base,u.widget,this._isHorizontalLayout()?l.horizontalLayout:l.verticalLayout,this._isReversedLayout()?l.reversed:null,this._isDisabled?u.disabled:null);return this._storeTrackDimensions(),c("div",{afterCreate:this._afterContainerCreate,"aria-label":e,bind:this,class:t,"touch-action":"none"},this._renderContent())}toNextStep(e){this._toStep(e,1)}toPreviousStep(e){this._toStep(e,-1)}getCurrentPosition(){return this._positionFromValue(this.values?.[0]??0)}_renderContent(){const{max:e,min:t}=this;if(!(null==t||null==e||t>=e))return[this._renderMin(),this._renderSliderContainer(),this._renderMax()]}_renderSliderContainer(){return c("div",{bind:this,class:l.contentElement,key:"slider-container"},this._renderTrackElement(),this._renderTicksContainer(),this._renderExtraContentElements())}_renderTrackElement(){return c("div",{afterCreate:this._afterTrackCreate,afterRemoved:this._afterTrackRemoved,bind:this,class:l.trackElement,"touch-action":"none"},this._renderEffectiveSegmentElements(),this._renderSegmentElements(),this._renderAnchorElements())}_renderEffectiveSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=null!=this.effectiveMax,t=null!=this.effectiveMin;if(!e&&!t)return;const{max:i,min:n,viewModel:s}=this,o=s.getBounds(),r=[];return t&&r.push(this._renderEffectiveSegmentElement(n,o.min,!0)),e&&r.push(this._renderEffectiveSegmentElement(o.max,i,!1)),r}_renderSegmentElements(){if(!this.trackElement||!this.values?.length)return;const e=this.values.length,t=[];for(let i=0;i<=e;i++)t.push(this._renderSegmentElement(i));return t}_renderSegmentElement(e){const{_trackHeight:t,_trackWidth:i,draggableSegmentsEnabled:n,id:s,state:o}=this,r=this.values,a=this._isHorizontalLayout(),h=a?i:t,u=this.viewModel.getBounds(),d=this._positionFromValue(u.max),m=this._positionFromValue(u.min),_=e===r?.length?null:e,p=0===e?null:e-1,v=null!=_,g=null!=p;let f,b;const E=[...r].sort((e,t)=>e-t);this._isReversedLayout()?(f=g?this._positionFromValue(E[p]):m,b=v?this._positionFromValue(E[_]):d):(f=v?this._positionFromValue(E[_]):d,b=g?this._positionFromValue(E[p]):m);const x=this._applyPrecisionToPosition(100*b/h),y=(f-b)/h,P=a?`transform: translate(${x}%, 0px) scale(${y}, 1);`:`transform: translate(0px, ${x}%) scale(1, ${y});`,k=this.classes(l.segmentElement,l.segmentElementIndexPrefix+e,n&&v&&g&&"disabled"!==o?l.segmentElementInteractive:null);return c("div",{afterCreate:this._afterSegmentCreate,afterRemoved:this._afterSegmentRemoved,bind:this,class:k,"data-max-thumb-index":_,"data-min-thumb-index":p,"data-segment-index":e,key:`${s}-segment-${e}`,style:P,"touch-action":"none"})}_renderEffectiveSegmentElement(e,t,i){const{_trackHeight:n,_trackWidth:s,layout:o}=this,r=this._positionFromValue(e),a=this._positionFromValue(t),h=this._isHorizontalLayout(),u=h?s:n,d=this._applyPrecisionToPosition(100*r/u);let m=null;if("horizontal"===o){const e=i?u-a:a,t=r===u?0:d;m=`clip-path: inset(0% ${a===u?0:this._applyPrecisionToPosition(e/u*100)}% 0% ${t}%);`}else{const e=(a-r)/u;m=h?`transform: translate(${d}%, 0px) scale(${e}, 1);`:`transform: translate(0px, ${d}%) scale(1, ${e});`}const _=i?l.effectiveMinSegmentElement:l.effectiveMaxSegmentElement,p=this.classes(l.segmentElement,l.effectiveSegmentElement,_);return c("div",{afterCreate:this._afterEffectiveSegmentCreate,afterRemoved:this._afterEffectiveSegmentRemoved,bind:this,class:p,style:m,"touch-action":"none"})}_renderAnchorElements(){const{trackElement:e,values:t}=this;if(t?.length)return this._zIndices=t.map((e,i)=>{const n=this._positionFromValue(e),s=this._positionToPercent(n),o=(this._isHorizontalLayout()?s>50:s<50)?-1:1;return this._zIndexOffset+(t.length+o*i)}),e&&t&&t.length?t.map((e,t)=>this._renderAnchorElement(e,t)):null}_renderAnchorElement(e,i){const n=this._positionFromValue(e),s=this._valueFromPosition(n);if(null==s||isNaN(s))return;const{_dragStartInfo:o,_lastMovedHandleIndex:r,id:a,layout:h,visibleElements:{labels:u}}=this,d=this.values,m=o?.index===i,_=r===i,p=this.classes(l.anchorElement,l.anchorElementIndexPrefix+i,m?l.movingAnchorElement:null,_?l.lastMovedAnchorElement:null),v=this.labels.values[i],g=this._getStyleForAnchor(e,i,m||_),{min:f,max:b}=this.viewModel.getBoundsForValueAtIndex(i),{disabled:E,messages:x}=this,y=2===d.length?t(0===i?x.rangeMinimum:x.rangeMaximum,{value:e}):v,P=1===d.length?null:0===i?`${a}-handle-${i+1}`:i===d.length-1?`${a}-handle-${i-1}`:`${a}-handle-${i-1} ${a}-handle-${i+1}`;return c("div",{afterCreate:this._afterAnchorCreate,afterRemoved:this._afterAnchorRemoved,afterUpdate:this._afterAnchorUpdate,"aria-controls":P,"aria-label":x.sliderValue,"aria-labelledby":u?`${a}-label-${i}`:null,"aria-orientation":h,"aria-valuemax":b?.toString(),"aria-valuemin":f?.toString(),"aria-valuenow":e.toString(),"aria-valuetext":y,bind:this,class:p,"data-thumb-index":i,"data-value":e,id:`${a}-handle-${i}`,key:`${a}-handle-${i}`,onkeydown:this._onAnchorKeyDown,role:"slider",style:g,tabIndex:E?-1:0,"touch-action":"none"},c("span",{afterCreate:this._afterThumbCreate,afterRemoved:this._afterThumbRemoved,bind:this,class:l.thumbElement,"data-thumb-index":i,"touch-action":"none"}),this.renderThumbLabel(i))}renderThumbLabel(e){const{id:t,labels:i,labelInputsEnabled:n,state:s}=this,o=this.visibleElements.labels,r=i.values[e],a=this.classes(l.labelElement,o?null:u.hidden,n&&"disabled"!==s?l.labelElementInteractive:null);return c("span",{afterCreate:this._afterLabelCreate,afterRemoved:this._afterLabelRemoved,"aria-hidden":(!o).toString(),bind:this,class:a,"data-thumb-index":e,id:`${t}-label-${e}`,key:`${t}-label-${e}`,role:n?"button":void 0,"touch-action":"none"},this._activeLabelInputIndex===e?this._renderValueInput(e):r)}_renderValueInput(e){const{disabled:t,values:i}=this;if(null==i)return;const n=i[e];return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.sliderValue,bind:this,class:l.labelInput,"data-input-index":e,"data-input-type":"thumb",key:`value-input-${e}`,onblur:this._onLabelInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:t?-1:0,type:"text",value:this._formatInputValue(n,"value",e)})}_renderMax(){const{_isMaxInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(l.maxElement,{[u.hidden]:!s,[l.maxElementInteractive]:i&&"disabled"!==n,[l.rangeElementActive]:e});return c("div",{afterCreate:this._afterMaxLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMaxLabelClick,onkeydown:this._onMaxLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMaxInput():t.max)}_renderMin(){const{_isMinInputActive:e,labels:t,rangeLabelInputsEnabled:i,state:n}=this,s=this.visibleElements.rangeLabels,o=this.classes(l.minElement,{[u.hidden]:!s,[l.minElementInteractive]:i&&"disabled"!==n,[l.rangeElementActive]:e});return c("div",{afterCreate:this._afterMinLabelCreate,"aria-hidden":(!s).toString(),bind:this,class:o,onclick:this._onMinLabelClick,onkeydown:this._onMinLabelKeyDown,role:i?"button":void 0,tabIndex:!this.disabled&&i?0:-1},e?this._renderMinInput():t.min)}_renderMaxInput(){return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.maximumValue,bind:this,class:l.rangeInput,"data-input-type":"max",onblur:this._onMaxInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.max,"max")})}_renderMinInput(){return c("input",{afterCreate:this._afterInputCreate,"aria-label":this.messages.minimumValue,bind:this,class:l.rangeInput,"data-input-type":"min",onblur:this._onMinInputBlur,onkeydown:this._onInputKeyDown,required:!0,tabIndex:this.disabled?-1:0,type:"text",value:this._formatInputValue(this.min,"min")})}_renderExtraContentElements(){return c("div",{bind:this,class:l.extraContentElement},this.extraNodes)}_renderTicksContainer(){if(this.tickConfigs&&this.trackElement&&(0!==this._trackHeight||0!==this._trackWidth))return this.tickConfigs.map((e,t)=>c("div",{class:this.classes(l.ticksContainerElement),key:"ticks-container"},this._renderTicks(e,t)))}_renderTicks(e,t){const{mode:n,values:s}=e;if(this.tickElements.at(t)||this.tickElements.add(new i,t),"position"===n){const i=Array.isArray(s)?s:[s];return this._calculateTickPositions(i).map((i,n)=>this._renderTickGroup(e,n,t,i))}if("percent"===n&&Array.isArray(s)){const i=this.min??0,n=(this.max??0)-i,o=s.map(e=>this._applyPrecisionToPosition(e/100*n+i));return this._calculateTickPositions(o).map((i,n)=>this._renderTickGroup(e,n,t,i))}const o=Array.isArray(s)&&s.length?s[0]:isNaN(s)?null:s,r=this._getTickCounts(o,e);return this._calculateEquidistantTickPositions(r).map((i,n)=>this._renderTickGroup(e,n,t,i))}_renderTickGroup(e,t,i,n){const s="position"===e.mode?Array.isArray(e.values)?e.values[t]:e.values:this._valueFromPosition(n);if(null!=s&&!isNaN(s))return c("div",{afterCreate:this._afterTickGroupCreate,afterRemoved:this._afterTickGroupRemoved,bind:this,"data-config":e,"data-position":n,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":s,key:`tick-group-${t}`,onclick:this._onTickGroupClick},this._renderTickLine(e,t,i,s),e.labelsVisible?this._renderTickLabel(e,t,i,s):null)}_renderTickLine(e,t,i,n){return c("div",{afterCreate:this._afterTickLineCreate,"aria-valuenow":n.toString(),bind:this,class:l.tickElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:this._getPositionStyleForElement(n)})}_renderTickLabel(e,t,i,n){const s=e.labelFormatFunction?e.labelFormatFunction(n,"tick",t):this.viewModel.getLabelForValue(n,"tick",t);return c("div",{afterCreate:this._afterTickLabelCreate,"aria-label":s,"aria-valuenow":n.toString(),"aria-valuetext":s,bind:this,class:l.tickLabelElement,"data-config":e,"data-tick-config-index":i,"data-tick-group-index":t,"data-value":n,key:`tick-label-${t}`,style:`transform: translate(-50%); ${this._getPositionStyleForElement(n)}`},s)}_afterContainerCreate(e){this.addHandles(m(e,()=>this.scheduleRender()))}_afterTrackCreate(e){this._set("trackElement",e),e.addEventListener("pointerdown",this._onTrackPointerDown),this.scheduleRender()}_afterTrackRemoved(e){e.removeEventListener("pointerdown",this._onTrackPointerDown),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp)}_afterSegmentCreate(e){this.segmentElements.add(e),e.addEventListener("pointerdown",this._onSegmentPointerDown)}_afterSegmentRemoved(e){this.segmentElements.remove(e),e.removeEventListener("pointerdown",this._onSegmentPointerDown)}_afterEffectiveSegmentCreate(e){this.effectiveSegmentElements.add(e)}_afterEffectiveSegmentRemoved(e){this.effectiveSegmentElements.remove(e)}_afterAnchorCreate(e){if(this._anchorElements.push(e),e.addEventListener("pointerdown",this._onAnchorPointerDown),this.thumbCreatedFunction){const t=g(e),i=y(e),n=this.thumbElements.at(t),s=this.labelElements.at(t)||null;this.thumbCreatedFunction(t,i,n,s)}}_afterAnchorUpdate(e){if(null!=this._focusedAnchorIndex){g(e)===this._focusedAnchorIndex&&(e.focus(),this._focusedAnchorIndex=null)}}_afterAnchorRemoved(e){const t=this._anchorElements.indexOf(e,0);t>-1&&this._anchorElements.splice(t,1),e.removeEventListener("pointerdown",this._onAnchorPointerDown)}_afterThumbCreate(e){this.thumbElements.add(e)}_afterThumbRemoved(e){this.thumbElements.remove(e)}_afterLabelCreate(e){this.labelElements.add(e),e.addEventListener("pointerdown",this._onLabelPointerDown),e.addEventListener("pointerup",this._onLabelPointerUp)}_afterLabelRemoved(e){this.labelElements.remove(e),e.removeEventListener("pointerdown",this._onLabelPointerDown),e.removeEventListener("pointerup",this._onLabelPointerUp)}_afterInputCreate(e){if(e.focus(),e.select(),this.inputCreatedFunction){const t=e.getAttribute("data-input-type"),i="thumb"===t?f(e):null;this.inputCreatedFunction(e,t,i)}}_afterTickLineCreate(e){const t=P(e),i=k(e),n=this.tickElements.at(t),s=n.at(i);s?s.tickElement=e:n.add({groupElement:null,tickElement:e,labelElement:null},i)}_afterTickLabelCreate(e){const t=P(e),i=k(e),n=this.tickElements.at(t),s=n.at(i);s?s.labelElement=e:n.add({groupElement:null,labelElement:e,tickElement:null},i)}_afterTickGroupRemoved(e){const t=P(e),i=this.tickElements.items[t],n=i?.find(t=>t.groupElement===e);n&&i.remove(n)}_afterTickGroupCreate(e){const t=I(e);if(t?.tickCreatedFunction){const i=P(e),n=k(e),s=y(e),o=this.tickElements?.at(i)?.at(n);if(o){o.groupElement=e;const i=o.tickElement||null,n=o.labelElement||null;t.tickCreatedFunction(s,i,n)}}}_afterMaxLabelCreate(e){this._set("maxLabelElement",e)}_afterMinLabelCreate(e){this._set("minLabelElement",e)}_onAnchorKeyDown(e){if(this._isDisabled||"editing"===this.state)return;const{key:t,target:i}=e,n=this.values,s=g(i),o=this._anchorElements[s],r=n[s],a=[_.moveAnchorUp,_.moveAnchorDown,_.moveAnchorLeft,_.moveAnchorRight];if(t===_.showInput&&this.labelInputsEnabled)this._activeLabelInputIndex=s;else if(a.includes(t)){e.preventDefault();const{steps:i}=this,n=t===_.moveAnchorUp||t===_.moveAnchorRight?1:-1;if(null!=i)this._toStep(s,this._isReversedLayout()?-1*n:n);else{const{precision:e}=this,t=this._getPositionOfElement(o),i=this._valueFromPosition(t),r=this._isHorizontalLayout()?n:-1*n;let a;a=0===e?this._positionFromValue(i+r):1===e?this._positionFromValue(i+.1*r):t+r,this._toPosition(s,a)}const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}else if(t===_.moveAnchorToMax||t===_.moveAnchorToMin){e.preventDefault();const{min:i,max:n}=this._getAnchorBoundsInPixels(s),o=this._isPositionInverted()?t===_.moveAnchorToMax?i:n:t===_.moveAnchorToMin?i:n;this._toPosition(s,o);const a=this.values[s];r!==a&&this._emitThumbChangeEvent({index:s,oldValue:r,value:a})}}_onAnchorPointerDown(e){if(this._isDisabled)return;const{target:t,clientX:i,clientY:n}=e,s=g(t);null!=s&&(e.preventDefault(),this._anchorElements[s]&&this._anchorElements[s].focus(),this._storeTrackDimensions(),this._dragStartInfo={clientX:i,clientY:n,index:s,position:this._getPositionOfElement(this._anchorElements[s])},document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onAnchorPointerMove(e){if("editing"===this.state||!this._dragStartInfo)return;e.preventDefault();const{values:t,_anchorElements:i,_dragged:n,_dragStartInfo:s,_dragStartInfo:{index:o,position:r}}=this,{clientX:a,clientY:l}=e,h=n?"drag":"start",u=i[o],d=this._getPositionOfElement(u),c=this._applyPrecisionToPosition(this._isHorizontalLayout()?r+a-s.clientX:r+l-s.clientY);if(d===c)return;const m=t[o];this._dragged=!0,this._toPosition(o,c);const _=this.values[o];n?m!==_&&this._emitThumbDragEvent({index:o,state:h,value:_}):this._emitThumbDragEvent({index:o,state:h,value:m})}_onAnchorPointerUp(e){if(document.removeEventListener("pointerup",this._onAnchorPointerUp),document.removeEventListener("pointermove",this._onAnchorPointerMove),!this._dragStartInfo)return;e.preventDefault();const{index:t}=this._dragStartInfo,i=this._dragged,n=this.values[t];this._dragged=!1,this._dragStartInfo=null,this._lastMovedHandleIndex=t,i?this._emitThumbDragEvent({index:t,state:"stop",value:n}):(this.scheduleRender(),"editing"!==this.state&&this._emitThumbClickEvent({index:t,value:n}))}_onTrackPointerDown(e){const{_dragStartInfo:t,snapOnClickEnabled:i,state:n,values:s}=this;if(this._isDisabled||"editing"===n||t)return;if(document.addEventListener("pointermove",this._onTrackPointerMove),document.addEventListener("pointerup",this._onTrackPointerUp),!i||!s?.length)return;const{steps:o}=this,{clientX:r,clientY:a}=e,l=this._getCursorPositionFromEvent(e),h=this._valueFromPosition(l),u=this._getIndexOfNearestValue(h),d=s[u],c=s.some((e,t)=>e===d&&t!==u)&&h>d?s.lastIndexOf(d):u;if(null==c)return;const m=s[c],_=null!=o?this._calculateNearestStepPosition(l):l;this._toPosition(c,_),this._dragged=!0,this._dragStartInfo={clientX:r,clientY:a,index:c,position:_},this._focusedAnchorIndex=c,this._emitThumbDragEvent({index:c,state:"start",value:m});const p=this.values[c];m!==p&&this._emitThumbDragEvent({index:c,state:"drag",value:p}),document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove)}_onTrackPointerMove(e){e.preventDefault(),this._dragged=!0}_onTrackPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointermove",this._onTrackPointerMove),document.removeEventListener("pointerup",this._onTrackPointerUp),this.snapOnClickEnabled||(this._dragged=!1),!this._dragged){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitTrackClickEvent({value:i})}}_onSegmentPointerDown(e){e.preventDefault();const t=e.target,i=b(t),n=E(t),s=x(t);if(this._isDisabled||null==n||null==s)return;e.stopPropagation(),this._storeTrackDimensions(),document.addEventListener("pointerup",this._onSegmentPointerUp);const o=this._getAnchorDetails(n),r=this._getAnchorDetails(s);this.syncedSegmentsEnabled?(this.segmentElements.forEach(e=>e.classList.add(l.segmentElementActive)),this._anchorElements.forEach(e=>e.classList.add(l.anchorElementActive))):(this.segmentElements.at(i).classList.add(l.segmentElementActive),this._anchorElements[o.index]?.classList.add(l.anchorElementActive),this._anchorElements[r.index]?.classList.add(l.anchorElementActive)),this._segmentDragStartInfo={cursorPosition:this._getCursorPositionFromEvent(e),index:i,details:this._normalizeSegmentDetails({min:o,max:r})},this.draggableSegmentsEnabled&&(document.addEventListener("pointermove",this._onSegmentPointerMove),this._emitSegmentDragEvent({index:i,state:"start",thumbIndices:[n,s]}))}_onSegmentPointerMove(e){if(!this._segmentDragStartInfo)return;e.preventDefault();const{_trackHeight:t,_trackWidth:i,_segmentDragStartInfo:{index:n,cursorPosition:s,details:{min:o,max:r}}}=this,{index:a,position:l,value:h}=o,{index:u,position:d,value:c}=r;this._dragged=!0;const m=this._getCursorPositionFromEvent(e);if(m===s)return;const _=this._positionToPercent(s),p=this._positionToPercent(m)-_,v=this._positionToPercent(l)+p,g=this._positionToPercent(d)+p,{min:f}=this._getAnchorBoundsAsPercents(a),{max:b}=this._getAnchorBoundsAsPercents(u);let E=!1,x=!1;if(v<f?E=!0:g>b&&(x=!0),E){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(a),i=this._isPositionInverted()?t:e,n=i,s=c+(i-h),o=s-this.values[u];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[n,s]))}if(x){const{min:e,max:t}=this.viewModel.getBoundsForValueAtIndex(u),i=this._isPositionInverted()?e:t,n=i,s=h+(i-c),o=s-this.values[a];return void(this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(o):this._updateAnchorValues([a,u],[s,n]))}const y=this._isHorizontalLayout()?i:t,P=g/100*y,k=v/100*y,I=this.values,A=[I[a],I[u]],M=this._getValueForAnchorAtPosition(a,k),L=this._getValueForAnchorAtPosition(u,P);this.syncedSegmentsEnabled?this._updateAnchorValuesByDifference(M-A[0]):this._updateAnchorValues([a,u],[M,L]);[this.values[a],this.values[u]].every((e,t)=>e===A[t])||this._emitSegmentDragEvent({index:n,state:"drag",thumbIndices:[a,u]})}_onSegmentPointerUp(e){if(e.preventDefault(),document.removeEventListener("pointerup",this._onSegmentPointerUp),document.removeEventListener("pointermove",this._onSegmentPointerMove),!this._segmentDragStartInfo)return;const{_dragged:t}=this,i=this.min,n=this.max,s=this.values,{index:o,details:{min:{index:r},max:{index:a}}}=this._segmentDragStartInfo;if(this.segmentElements.forEach(e=>e.classList.remove(l.segmentElementActive)),this._anchorElements.forEach(e=>e.classList.remove(l.anchorElementActive)),this.draggableSegmentsEnabled){const e=n-i,t=s[r],l=s[a];this._lastMovedHandleIndex=t===l?t>e/2?r:a:null,this._dragged=!1,this._segmentDragStartInfo=null,this._emitSegmentDragEvent({index:o,state:"stop",thumbIndices:[r,a]})}if(!t){const t=this._getCursorPositionFromEvent(e),i=this._valueFromPosition(t);this._emitSegmentClickEvent({index:o,value:i,thumbIndices:[r,a]})}}_onTickGroupClick(e){const t=e.target;if(I(t)){const e=P(t),i=k(t),n=y(t);this._emitTickClickEvent({configIndex:e,groupIndex:i,value:n})}}_storeTrackDimensions(){if(this.trackElement){const e=this._getDimensions(this.trackElement);this._trackHeight=this._applyPrecisionToPosition(e.height),this._trackWidth=this._applyPrecisionToPosition(e.width)}}_onLabelPointerDown(){this._isDisabled||(this._dragged=!1,document.addEventListener("pointerup",this._onAnchorPointerUp),document.addEventListener("pointermove",this._onAnchorPointerMove))}_onLabelPointerMove(){this._isDisabled||(this._dragged=!0)}_onLabelPointerUp(e){if(this._isDisabled)return;const t=g(e.target);this.labelInputsEnabled&&!this._dragged&&null!=t&&(this._activeLabelInputIndex=t),this._dragged=!1,document.removeEventListener("pointerup",this._onLabelPointerUp),document.removeEventListener("pointermove",this._onLabelPointerMove)}_onLabelInputBlur(e){const{_activeLabelInputIndex:t,values:i,viewModel:n}=this,s=e.target.value;if(this._activeLabelInputIndex=null,!s||null==t||null==i)return;const o=this._parseInputValue(s,"value",t),r=i[t],{min:a,max:l}=this.viewModel.getBoundsForValueAtIndex(t);if(o<a||o>l)return;n.setValue(t,o);const h=this.values[t];r!==h&&this._emitThumbChangeEvent({index:t,oldValue:r,value:h})}_onInputKeyDown(e){if(this._isDisabled)return;const{key:t,target:i}=e,{hideInput1:n,hideInput2:s,hideInput3:o}=_,{_activeLabelInputIndex:r,_anchorElements:a}=this,l=i;if(t===n||t===s||t===o){e.stopPropagation();const t=r;l.blur(),null!=t?a[t].focus():l.parentElement?.focus()}}_onMaxLabelClick(){this._isDisabled||(this._emitMaxRangeLabelClickEvent({type:"max-click",value:this.max}),this.rangeLabelInputsEnabled&&(this._isMaxInputActive=!0))}_onMaxLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMaxInputActive=!0)}_onMaxInputBlur(e){const t=e.target.value;if(this._isMaxInputActive=!1,!t)return;const i=this.max,n=this._parseInputValue(t,"max");n<=this.min||(this.viewModel.set("max",n),this.max!==i&&this._emitMaxChangeEvent({oldValue:i,value:this.max}))}_onMinLabelClick(){this._isDisabled||(this._emitMinRangeLabelClickEvent({type:"min-click",value:this.min}),this.rangeLabelInputsEnabled&&(this._isMinInputActive=!0))}_onMinLabelKeyDown({key:e}){this._isDisabled||e!==_.showInput||(this._isMinInputActive=!0)}_onMinInputBlur(e){const t=e.target.value;if(this._isMinInputActive=!1,!t)return;const i=this.min,n=this._parseInputValue(t,"min");n>=this.max||(this.viewModel.set("min",n),this.min!==i&&this._emitMinChangeEvent({oldValue:i,value:this.min}))}_positionFromValue(e){const{_trackHeight:t,_trackWidth:i}=this,n=this.min??0,s=this.max??0,o=s-n;if(0===o||null==e)return 0;const r=this._isHorizontalLayout();let a=r?this._applyPrecisionToPosition(i*(e-n)/o):this._applyPrecisionToPosition(t*(s-e)/o);return this._isReversedLayout()&&(a=r?i-a:t-a),a}_valueFromPosition(e){const{_trackHeight:t,_trackWidth:i,precision:n}=this,s=this.min??0,o=this.max??0,r=o-s;let a=this._isHorizontalLayout()?e*r/i+s:r*(1e3-e/t*1e3)/1e3+s;return this._isReversedLayout()&&(a=o+s-a),parseFloat(a.toFixed(n))}_positionToPercent(e){const{_trackHeight:t,_trackWidth:i}=this,n=100*e/(this._isHorizontalLayout()?i:t);return this._applyPrecisionToPosition(n)}_applyPrecisionToPosition(e){return parseFloat(e.toFixed(this._positionPrecision))}_isPositionInverted(){const{layout:e}=this;return"horizontal-reversed"===e||"vertical"===e}_isHorizontalLayout(){return this.layout.includes("horizontal")}_isReversedLayout(){return this.layout.includes("reversed")}_normalizeSegmentDetails(e){if(this._isPositionInverted()){const{min:t,max:i}=e;return{min:i,max:t}}return e}_parseInputValue(e,t,i){return this.inputParseFunction?this.inputParseFunction(e,t,i):this.viewModel.defaultInputParseFunction(e)}_formatInputValue(e,t,i){return this.inputFormatFunction?this.inputFormatFunction(e,t,i):this.viewModel.defaultInputFormatFunction(e)}_getAnchorDetails(e){const t=this.values,i=[...t].sort((e,t)=>e-t)[e],n=t.indexOf(i);return{index:n,position:this._getPositionOfElement(this._anchorElements[n]),value:i}}_updateAnchorStyle(e,t){const i=this._anchorElements[e];i&&(this._isHorizontalLayout()?i.style.left=`${t}`:i.style.top=`${t}`)}_getStyleForAnchor(e,t,i){const n=this._getPositionStyleForElement(e);if(1===this.values?.length)return`${n}`;const s=this._zIndices[t];return`${n}; z-index: ${i?this._zIndexOffset+s:s}`}_getPositionStyleForElement(e){const t=this._positionFromValue(e),i=this._positionToPercent(t);return`${this._isHorizontalLayout()?"left":"top"}: ${i}%`}_getPositionOfElement(e){const t=this._getDimensions(e.offsetParent),i=this._getDimensions(e);return this._isHorizontalLayout()?this._applyPrecisionToPosition(i.left-t.left):this._applyPrecisionToPosition(i.top-t.top)}_updateAnchorValues(e,t){e.forEach((e,i)=>this._toValue(e,t[i]))}_updateAnchorValuesByDifference(e){const{min:t,max:i,values:n}=this;n?.forEach((n,s)=>this._toValue(s,Math.max(Math.min(n+e,i),t)))}_toValue(e,t){if(null!=this.steps){t=this._getStepValues()[this._getIndexOfNearestStepValue(t)]}this._updateAnchorStyle(e,this._getPositionStyleForElement(t)),this.viewModel.setValue(e,t)}_toPosition(e,t){const i=null!=this.steps?this._getStepValueForAnchorAtPosition(e,t):this._getValueForAnchorAtPosition(e,t);this._updateAnchorStyle(e,this._getPositionStyleForElement(i)),this.viewModel.setValue(e,i)}_getValueForAnchorAtPosition(e,t){const{min:i,max:n}=this._getAnchorBoundsInPixels(e),{min:s,max:o}=this.viewModel.getBoundsForValueAtIndex(e);let r,a,l=null;return this._isPositionInverted()?(r=s,a=o):(r=o,a=s),l=t>n?r:t<i?a:this._valueFromPosition(t),l>o?l=o:l<s&&(l=s),l}_getStepValueForAnchorAtPosition(e,t){const i=this._getStepValues(),n=this._calculateNearestStepPosition(t),s=this._getValueForAnchorAtPosition(e,n);return i[this._getIndexOfNearestStepValue(s)]}_getAnchorBoundsAsPercents(e){const{min:t,max:i}=this._getAnchorBoundsInPixels(e);return{min:this._positionToPercent(t),max:this._positionToPercent(i)}}_getAnchorBoundsInPixels(e){const{_anchorElements:t,_trackHeight:i,_trackWidth:n,effectiveMax:s,effectiveMin:o,thumbsConstrained:r}=this,a=t[e-1],l=t[e+1],h=this._isHorizontalLayout()?n:i;let u,d;return this._isPositionInverted()?(u=null!=o?this._positionFromValue(o):h,d=null!=s?this._positionFromValue(s):0):(u=null!=s?this._positionFromValue(s):h,d=null!=o?this._positionFromValue(o):0),r?this._isPositionInverted()?{max:a?this._getPositionOfElement(a):u,min:l?this._getPositionOfElement(l):d}:{max:l?this._getPositionOfElement(l):u,min:a?this._getPositionOfElement(a):d}:{max:u,min:d}}_getIndexOfNearestValue(e){const t=this.values;return t.indexOf(t.reduce((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t))}_getCursorPositionFromEvent(e){const t=this._getDimensions(this.trackElement);return this._isHorizontalLayout()?this._applyPrecisionToPosition(e.clientX-t.left):this._applyPrecisionToPosition(e.clientY-t.top)}_getStepValues(){const{steps:e}=this;if(Array.isArray(e))return e;const{max:t,min:i}=this;if(null==i||null==t||null==e)return[];const n=Math.ceil((t-i)/e),s=[];for(let o=0;o<=n;o++){const n=i+e*o;s.push(n>t?t:n)}return s}_toStep(e,t){const i=this.values[e],n=this._getStepValues(),s=n.indexOf(i);let o=null;if(s>-1){let i=n[s+t];isNaN(i)&&(i=n[s]);const r=this._positionFromValue(i);o=this._getStepValueForAnchorAtPosition(e,r)}else{o=n[this._getIndexOfNearestStepValue(i)+t]}this.viewModel.setValue(e,o)}_getIndexOfNearestStepValue(e){const{steps:t}=this;if(null==t)return null;const i=this._getStepValues(),n=i.reduce((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t);return i.indexOf(n)}_calculateNearestStepPosition(e){const t=this._valueFromPosition(e),i=this._getIndexOfNearestStepValue(t),n=this._getStepValues();return this._positionFromValue(n[i])}_getTickCounts(e,t){const{mode:i}=t;return"count"===i||"position"===i?e||0:"percent"===i&&100/e||0}_calculateTickPositions(e){return e.map(e=>this._positionFromValue(e))}_calculateEquidistantTickPositions(e){const{_trackWidth:t,_trackHeight:i}=this,n=this._isHorizontalLayout()?t:i,s=n/(e-1),o=[];if(1===e)return[n/2];for(let r=0;r<e;r++){const e=r*s;e<=n&&o.push(e)}return o}_getDimensions(e){return n(e),e.getBoundingClientRect()}_emitTrackClickEvent(e){this.emit("track-click",{...e,type:"track-click"})}_emitTickClickEvent(e){this.emit("tick-click",{...e,type:"tick-click"})}_emitMaxChangeEvent(e){this.emit("max-change",{...e,type:"max-change"})}_emitMinChangeEvent(e){this.emit("min-change",{...e,type:"min-change"})}_emitThumbChangeEvent(e){this.emit("thumb-change",{...e,type:"thumb-change"})}_emitThumbClickEvent(e){this.emit("thumb-click",{...e,type:"thumb-click"})}_emitThumbDragEvent(e){this.emit("thumb-drag",{...e,type:"thumb-drag"})}_emitSegmentClickEvent(e){this.emit("segment-click",{...e,type:"segment-click"})}_emitSegmentDragEvent(e){this.emit("segment-drag",{...e,type:"segment-drag"})}_emitMinRangeLabelClickEvent(e){this.emit("min-click",e)}_emitMaxRangeLabelClickEvent(e){this.emit("max-click",e)}};function g(e){return e?.["data-thumb-index"]}function f(e){return e?.["data-input-index"]}function b(e){return e?.["data-segment-index"]}function E(e){return e?.["data-min-thumb-index"]}function x(e){return e?.["data-max-thumb-index"]}function y(e){return e?.["data-value"]}function P(e){return e?.["data-tick-config-index"]}function k(e){return e?.["data-tick-group-index"]}function I(e){return e?.["data-config"]}e([s()],v.prototype,"_activeLabelInputIndex",void 0),e([s()],v.prototype,"_dragStartInfo",void 0),e([s()],v.prototype,"_isMinInputActive",void 0),e([s()],v.prototype,"_isMaxInputActive",void 0),e([s()],v.prototype,"_segmentDragStartInfo",void 0),e([s({readOnly:!0})],v.prototype,"_isDisabled",null),e([s()],v.prototype,"disabled",void 0),e([s()],v.prototype,"draggableSegmentsEnabled",void 0),e([s()],v.prototype,"effectiveMax",null),e([s()],v.prototype,"effectiveMin",null),e([s({readOnly:!0})],v.prototype,"effectiveSegmentElements",void 0),e([s()],v.prototype,"extraNodes",void 0),e([s()],v.prototype,"inputCreatedFunction",void 0),e([s()],v.prototype,"inputFormatFunction",null),e([s()],v.prototype,"inputParseFunction",null),e([s()],v.prototype,"icon",null),e([s()],v.prototype,"label",null),e([s({readOnly:!0})],v.prototype,"labelElements",void 0),e([s()],v.prototype,"labelInputsEnabled",void 0),e([s()],v.prototype,"labelFormatFunction",null),e([s({readOnly:!0})],v.prototype,"labels",null),e([s({value:"horizontal"})],v.prototype,"layout",null),e([s()],v.prototype,"max",null),e([s({readOnly:!0})],v.prototype,"maxLabelElement",void 0),e([s(),d("esri/widgets/Slider/t9n/Slider")],v.prototype,"messages",void 0),e([s()],v.prototype,"min",null),e([s({readOnly:!0})],v.prototype,"minLabelElement",void 0),e([s()],v.prototype,"precision",null),e([s()],v.prototype,"rangeLabelInputsEnabled",void 0),e([s({readOnly:!0})],v.prototype,"segmentElements",void 0),e([s()],v.prototype,"snapOnClickEnabled",void 0),e([s({readOnly:!0})],v.prototype,"state",null),e([s()],v.prototype,"steps",void 0),e([s()],v.prototype,"syncedSegmentsEnabled",void 0),e([s()],v.prototype,"thumbsConstrained",null),e([s()],v.prototype,"thumbCreatedFunction",void 0),e([s({readOnly:!0})],v.prototype,"thumbElements",void 0),e([s()],v.prototype,"tickConfigs",null),e([s({readOnly:!0})],v.prototype,"tickElements",void 0),e([s({readOnly:!0})],v.prototype,"trackElement",void 0),e([s()],v.prototype,"values",null),e([s({type:h})],v.prototype,"viewModel",void 0),e([s()],v.prototype,"visibleElements",void 0),e([o("visibleElements")],v.prototype,"castVisibleElements",null),v=e([r("esri.widgets.Slider")],v);const A=v;export{A as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{id as t}from"../../kernel.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import{EventedAccessor as i}from"../../core/Evented.js";import a from"../../core/Logger.js";import{whenOnce as l,once as o}from"../../core/reactiveUtils.js";import{property as n,subclass as c}from"../../core/accessorSupport/decorators.js";import{isPoint as u,isMultipoint as h}from"../../geometry/support/jsonUtils.js";import{fetchMessageBundle as p}from"../../intl/messages.js";import d from"../../layers/FeatureLayer.js";import g from"../../layers/GraphicsLayer.js";import y from"../../layers/support/CodedValueDomain.js";import{isFeatureLayer as m,isSubtypeSublayer as f,getOwningPortalUrl as w}from"../../layers/support/layerUtils.js";import _ from"../../networks/UtilityNetwork.js";import{getFeaturesFromLayers as b}from"../../networks/support/utils.js";import A from"../../portal/Portal.js";import{hasUserTypeExtension as v}from"../../portal/support/utils.js";import{trace as k}from"../../rest/networks/trace.js";import I from"../../rest/networks/support/TraceLocation.js";import F from"../../rest/networks/support/TraceParameters.js";import{addUniqueLayer as G}from"../../views/draw/support/layerUtils.js";import{GeometryHandler as R}from"./support/GeometryHandler.js";import{GraphicHandler as L,barrierColor as T,startingPointColor as H}from"./support/GraphicHandler.js";import{ResultAreaHandler as S}from"./support/ResultAreaHandler.js";import{UtilityHelper as N}from"./support/UtilityHelper.js";const P=()=>p("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace"),U=()=>p("esri/core/t9n/Units"),B=`utility-network-trace-flags-${Date.now()}`,C=`utility-network-trace-results-${Date.now()}`,E=`utility-network-trace-sketch-${Date.now()}`;function V(e){return e instanceof y}function j(e){return"feature"===e.layer.type||"subtype-group"===e.layer.type}function D(e){return"layer"in e}function O(e){return void 0!==e.layerViews}function M(e){return"graphics"===e.type}function x(e){return"feature"===e.type||"subtype-group"===e.type||"group"===e.type}async function q(e){const t=new d({url:e.networkSystemLayers.dirtyAreasLayerUrl});await t.load();const r=t.version;if(Number(r)<=11.1){const t=await w(e.layerUrl),r=new A({url:t});await r.load();const s=r?.user?.username;return!!s&&v(r,s,"utilityNetwork")}return!0}let $=class extends i{constructor(e){super(e),this._activeProgress=!1,this._clickHandler=null,this._flags=[],this._flagId=0,this._geometryHandler=null,this._highlightHandler=[],this._resultAreaHandler=null,this._sketchViewModel=null,this._traceTimeout=6e5,this._utilityHelper=new N,this._validUNLayers=[],this._watchHandler=null,this.traces=[],this.graphicHandler=null,this.defaultGraphicColor={color:[255,255,0,.6],haloOpacity:.9,fillOpacity:.2,hex:"#FFFF00"},this.enableResultArea=!1,this.flags=[],this.messages=null,this.messagesUnits=null,this.defaultResultAreaProperties={type:"convexhull",distance:10,unit:"meters",areaUnit:"square-meters",color:{color:[255,165,0,.5],haloOpacity:.9,fillOpacity:.2,hex:"#ffa500"},show:!1},this.selectedTraces=[],this.selectOnComplete=!0,this.showGraphicsOnComplete=!0,this.showSelectionAttributes=!0,this.traceResults=[],this.utilityNetwork=null}initialize(){this._geometryHandler=new R,this.graphicHandler=new L,this._resultAreaHandler=new S;(async()=>{const[e,t]=await Promise.all([P(),U()]);this.set({messages:e,messagesUnits:t})})()}destroy(){this.view=null}get resultAreaProperties(){return this.defaultResultAreaProperties}set resultAreaProperties(e){this._set("resultAreaProperties",{...this.defaultResultAreaProperties,...e}),this.graphicHandler.addCustomColor(this.resultAreaProperties.color),this.traceResults.forEach(t=>{const r=t.resultArea?.show;t.resultArea={...this.defaultResultAreaProperties,...e},this.removeResultAreaFromMap(t),this.enableResultArea&&this.createResultAreaGraphic(t).then(s=>{if(s){t.resultAreaGraphic=s;const i=e?.show??r;t.resultArea&&(t.resultArea.show=i),i&&this.addResultAreaToMap(t,s)}})})}get state(){return this.view?.ready?"ready":"loading"}get view(){return this._get("view")}set view(e){e&&"2d"!==e.type&&a.getLogger(this).error(new s("view:invalid-view","SceneView is not supported",{view:e})),this._set("view",e),this.utilityNetwork&&this.reset(),this.utilityNetwork=null,this.loadUtilityNetwork().then(e=>{e&&this.selectTracesOnLoad()})}addFlagByHit(e,t){const r=!!this.view&&this.view.popupEnabled,s=e=>{this.view?.popup&&(this.view.popupEnabled=e)};return new Promise((i,a)=>{r&&s(!1),this._clickHandler?.remove(),this._clickHandler=this._sketchViewModel.on("create",l=>{if("complete"===l.state){const o=this._getGraphicLayer(E);o&&l.graphic&&o.remove(l.graphic),this.queryFlagByHitTest(l,e,t).then(r=>{this.emit("add-flag-complete",{type:e,symbol:t}),i(r)}).catch(r=>{this.emit("add-flag-error",{type:e,symbol:t}),a(r)}).finally(()=>{r&&s(!0),this._clickHandler?.remove()})}}),this._sketchViewModel.create("point"),this.emit("add-flag",{type:e})})}addNonspatialTraceLocation(e,t){const r=this._getDisplayField(e),s=this.utilityNetwork?.getTerminalConfiguration(e),i={terminalId:null,isFilterBarrier:!1,allTerminals:s,selectedTerminals:[s?s.terminals[0].id||null:1],displayValue:r};e.attributes={...e.attributes,...i};const a=e.attributes.hasOwnProperty("GLOBALID")?e.attributes.GLOBALID:e.attributes.globalid;if(!this._flags.some(e=>e.globalId===a&&e.type===t)){const r=this._createFlagProperty(e,t,null);this._flags.push(r),this.emit("add-flag-complete",{type:t})}this.emit("add-flag",{type:t})}async addFlagsOnLoad(){if(this._flags.length>0)return[];await l(()=>null!=this.view&&!this.view.updating);return(await Promise.all(this.flags.map(async e=>{if(!e.mapPoint)return null;const{type:t}=e,r=e.mapPoint.clone(),s="barrier"===t?T:H,i={graphic:this.graphicHandler.makeGraphic(r,s),state:"complete",tool:"point",toolEventInfo:null,type:"create"};try{return await this.queryFlagByHitTest(i,e.type,null),this.emit("add-flag-complete",{type:t}),null}catch(a){return this.emit("add-flag-error",{type:t}),"barrier"===t?"barrier":"starting-point"}}))).filter(e=>!e)}async addResultAreaToMap(e,t){if(this.view)if(e.resultArea.show=!0,t)this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t});else if(e.results){const t=await this.createResultAreaGraphic(e);t&&(e.resultAreaGraphic=t,this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t}))}}async addResultGraphicToView(e,t){const{view:r}=this,{results:s}=e;if(r&&s&&this.utilityNetwork)for(const i in s.aggregatedGeometry)if("line,multipoint,polygon".includes(i)){const a=i,l=s.aggregatedGeometry[a];if(null!=l){l.spatialReference=this.utilityNetwork.spatialReference,e.graphicEnabled=!0;const s=await this._geometryHandler.projectGeometry(l,r.spatialReference),i={globalid:e.trace.globalId};if(null!==s){const e=this.graphicHandler.makeGraphic(s,t.color,i,r.spatialReference);this._getGraphicLayer(C)?.add(e)}}}}addTerminal(e,t){const r=[...this._flags];r.forEach(r=>{r.globalId===t.globalId&&(t.selectedTerminals?.includes(parseInt(e,10))||r.selectedTerminals?.push(parseInt(e,10)))}),this._flags=r}async callTrace(){const e=this.traces.filter(e=>e.selected);return!!e.length&&(this.traceResults.length>0&&this.traceResults.forEach(e=>{this.removeResultGraphicFromView(e)}),this.traceResults=[],this.removeSelection(),await Promise.all(e.map(async(e,t)=>{const r=e,s=new F({gdbVersion:this.utilityNetwork?.gdbVersion,moment:this.utilityNetwork?.historicMoment,namedTraceConfigurationGlobalId:r.globalId,outSpatialReference:null,resultTypes:null,traceType:r.traceType,traceLocations:this._flags,traceConfiguration:null});await this.executeTrace(r,this.utilityNetwork?.networkServiceUrl,s).then(async e=>{if(e.hasOwnProperty("results")){const r={...e};if(null!==r.results){r.resultArea={...this.resultAreaProperties};const e=[...r.results.elements];r.results.elements.length=0;const s=new Map;for(const t of e)s.has(t.globalId)||(s.set(t.globalId,!0),r.results.elements.push(t));const i=[...this.traceResults];if(i.splice(t,0,r),this.traceResults=i,null!==r.results&&(this.selectOnComplete&&this.mergeSelection(!0,r.trace),this.showGraphicsOnComplete&&await this.addResultGraphicToView(r,r.graphicColor),this.enableResultArea)){const e=await this.createResultAreaGraphic(r);e&&(r.resultAreaGraphic=e,r.resultArea?.show&&await this.addResultAreaToMap(r,r.resultAreaGraphic))}}else{const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}this._activeProgress=!1}else{this._activeProgress=!1;const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}}).catch(e=>{throw this._activeProgress=!1,e})})),!0)}cancelAddFlagByHit(){this._sketchViewModel.cancel()}changeResultAreaColor(e,t){if(!e.resultArea)return;e.resultArea.color=t;const r=this._resultAreaHandler?.changeResultAreaColor(e.trace.globalId,t,this.view.map);e.resultAreaGraphic&&(e.resultAreaGraphic.symbol=r)}changeResultGraphicColor(e,t){const r=[...this.traceResults];r.length>0&&r.forEach(r=>{r.trace.globalId===t.trace.globalId&&(r.graphicColor=e,r.graphicEnabled=!0)}),this.traceResults=r,this.removeResultGraphicFromView(t),this.addResultGraphicToView(t,e)}changeFlagSymbol(e,t){this._flags.length>0&&this._flags.forEach(r=>{r.type===e&&t&&r.mapGraphic&&(r.mapGraphic.symbol=t)})}checkCanTrace(){const e={status:!0,issues:[]},t=this.traces.filter(e=>e.selected);t.length||(e.status=!1,e.issues.push("noTracesSelected"));this._flags.some(e=>"starting-point"===e.type)||(e.status=!1,e.issues.push("noStartingPoints"));return this._flags.filter(e=>null!==e.allTerminals).some(e=>!e.selectedTerminals.length)&&(e.status=!1,e.issues.push("noTerminalSelected")),e}checkSelectionExist(){return this._highlightHandler.some(e=>e)}clearResult(e){if(!this.view)return;let t=this.traceResults;if(t.length>0){const r=t.filter(t=>t.trace.globalId===e.globalId);r.length>0&&(this.removeResultGraphicFromView(r[0]),this.removeResultAreaFromMap(r[0])),t=t.filter(t=>t.trace.globalId!==e.globalId)}this.traceResults=t,0===t.length?(this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]})):this.mergeSelection(!1,e)}createResultAreaGeometries(e,t,r){if(!this.view||!this.resultAreaProperties)return;let s;if(s="convexhull"===this.resultAreaProperties?.type?1===t.length&&(u(t[0])||h(t[0])&&1===t[0].points.length)?this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0):this._resultAreaHandler?.createConvexHull(t,e.resultArea?.distance,e.resultArea?.unit):this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0),!s)return;if(Array.isArray(s)){for(const t of s){const r=this.getResultAreaAttributes(e,t),s=this._resultAreaHandler?.createResultAreaGraphic(t,r,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(s)return s}return}const i=this.getResultAreaAttributes(e,s);return this._resultAreaHandler?.createResultAreaGraphic(s,i,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color)}async createResultAreaGraphic(e){if(e.results){const t=await this._createResultAreaInputGeometry(e.results);if(t.length>0){const r=Array(t.length).fill(e.resultArea?.distance),s=this.createResultAreaGeometries(e,t,r);return this.emit("create-result-area",{graphic:s}),s}}}executeTrace(e,t,r){const s=this._processFlags(r.traceLocations);return r.traceLocations=s,k(t,r,{timeout:this._traceTimeout}).then(t=>({trace:e,results:t,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:"success",date:new Date})).catch(t=>({trace:e,results:null,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:t.message,date:new Date}))}async getNonspatialTraceLocationInitialFeature(){return new Promise((e,t)=>{this._clickHandler?.remove(),this._clickHandler=this._sketchViewModel.on("create",async r=>{if("complete"!==r.state)return;const s=this._getGraphicLayer(E);s&&r.graphic&&s.remove(r.graphic);const i=this.view?.toScreen(r.graphic?.geometry);if(!i)return;const a=await(this.view?.hitTest(i));if(a?.results.length){const r=a.results.find(e=>"graphic"===e.type&&this.utilityNetwork?.isUtilityLayer(e.layer));r?e(r):t(null)}}),this._sketchViewModel.create("point")})}getResultAreaAttributes(e,r){const{messages:s}=this,i=[],a=[];this._flags.forEach(e=>{const t=e.displayValue?.field+":"+e.displayValue?.value+";"+s.attributeStrings.globalid+":"+e.globalId+";"+s.attributeStrings.terminalid+":"+e.terminalId+";"+s.attributeStrings.x+":"+e.mapPoint?.x+";"+s.attributeStrings.y+":"+e.mapPoint?.y;"starting-point"===e.type?i.push(t):a.push(t)});const l=this.utilityNetwork?.gdbVersion;return{traceId:e.trace.globalId,traceName:e.trace.title,traceDescription:e.trace.description??"",startingPoints:i.toString(),barriers:a.toString(),version:l??void 0,username:t.credentials[0].userId,date:e.date,elementCount:e.results?.elements.length,functionResult:JSON.stringify(e.results?.globalFunctionResults),areaStatistic:r?this._geometryHandler.calculateArea(r,e.resultArea?.areaUnit):0}}getValidSources(){let e=[];const t=this.utilityNetwork?.dataElement?.domainNetworks??[];for(const r of t)e=e.concat(r.junctionSources),e=e.concat(r.edgeSources);return e}groupResultsByNetworkSource(e){return 0===e.length?[]:this._groupBy(e,"networkSourceId")}async loadUtilityNetwork(){const{view:e}=this;if(!e)return null;if(await e.when(),this.utilityNetwork){if(this.utilityNetwork.loaded||await this.utilityNetwork.load(),this.utilityNetwork instanceof _){try{const t=e.map;await t.loadAll()}catch(i){if("layer:unsupported-layer-type"!==i.name&&"subtype-grouplayer:missing-subtypes"!==i.name)throw i;console.error(i)}finally{this._loadUNSupportItems()}return this.utilityNetwork}return null}const t=e.map,r=t.utilityNetworks?.at(0);if(r){if(await r.load(),this.utilityNetwork=r,!await q(r))throw new s("utility-network:no-user-type-extension","User type extension not found");try{await t.loadAll()}catch(i){if("layer:unsupported-layer-type"!==i.name&&"subtype-grouplayer:missing-subtypes"!==i.name)throw i;console.error(i)}finally{this._loadUNSupportItems()}return r}return null}manageFilterBarrier(e,t){const r=[...this._flags];r.forEach(r=>{r.globalId===t.globalId&&"barrier"===t.type&&r.id===t.id&&(r.isFilterBarrier=e)}),this._flags=r}mergeSelection(e,t){let r=[];const s=[...this.traceResults],i=t.globalId;s.forEach(t=>{i===t.trace.globalId&&(t.selectionEnabled=e),t.selectionEnabled&&null!==t.results?.elements&&(r=[...r,...t.results?.elements??[]])}),this.selectResults([...new Set(r)])}async queryFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return null;const s=this.utilityNetwork.getObjectIdsFromElements(e),i={layerUrl:s[0].layerUrl,objectIds:s[0].objectIds,outFields:["*"]},a=t.map?.allTables.toArray().filter(e=>e?.parsedUrl?.path===s[0].layerUrl).filter(m)??[];this._getUniqueMapLayerViews(t).filter(({layer:e})=>e?.parsedUrl?.path===s[0].layerUrl).forEach(({layer:e})=>{"feature"!==e.type&&"subtype-group"!==e.type||a.push(e)});const l=(await Promise.all(a.map(async e=>{const s={layers:new r([e]),layerInfos:[i],returnGeometry:!0,outSpatialReference:t.spatialReference},[a]=await b(s,!1);return a}))).filter(({featureSet:e})=>e.features.length>0);return l.length>0?l:null}queryFlagByHitTest(e,t,r){return this._lookupFlagByHit(e).then(e=>{const{view:s}=this;if(!s)return!1;if(e.length>0){const s=[...this._flags],i=r;return e.forEach(e=>{const r=e.graphic,a=r.attributes.hasOwnProperty("GLOBALID")?r.attributes.GLOBALID:r.attributes.globalid;if(s.filter(e=>e.globalId===a).length<=0){const e=this.graphicHandler.getFlagGraphic(r.attributes.mapPoint,t,r,i);this._getGraphicLayer(B)?.add(e);const a=this._createFlagProperty(r,t,e);s.push(a)}else if(null!==r.attributes.percentAlong){const e=this.graphicHandler.getFlagGraphic(r.attributes.mapPoint,t,r,i);this._getGraphicLayer(B)?.add(e);const a=this._createFlagProperty(r,t,e);s.push(a)}}),this._flags=s,!0}return!1})}removeResultGraphicFromView(e){const{view:t}=this;if(!t)return;const r=this._getGraphicLayer(C)?.graphics;e.graphicEnabled=!1;const s=r?.filter(t=>t.attributes[t.attributes.hasOwnProperty("GLOBALID")?"GLOBALID":"globalid"]===e.trace.globalId);s?.forEach(e=>{this._getGraphicLayer(C)?.remove(e)})}removeFlag(e){const t=this._flags.filter(t=>{if(t.id!==e.id)return t});this._removeGraphic(e),this._flags=t}removeAllResultAreaGraphics(){this._resultAreaHandler?.removeAllResultAreaGraphics(this.view.map)}removeResultAreaFromMap(e){if(e.resultArea){e.resultArea.show=!1;const t=this._resultAreaHandler?.removeResultArea(e.trace.globalId,this.view?.map);t&&this.emit("remove-result-area",{graphic:t})}}removeSelection(){this._highlightHandler.forEach(e=>{e&&e.remove()}),this._highlightHandler=[]}removeTerminal(e,t){const r=[...this._flags];r.forEach(r=>{if(r.globalId===t.globalId&&t.selectedTerminals?.includes(parseInt(e,10))){const s=t.selectedTerminals.indexOf(parseInt(e,10));r.selectedTerminals?.splice(s,1)}}),this._flags=r}removeFlagsOnLoadWatcher(){this._watchHandler&&null!==this._watchHandler&&this._watchHandler.remove()}removeClickHandler(){this._clickHandler&&(this._sketchViewModel.cancel(),this._clickHandler.remove())}reset(){this._flags=[],this.traceResults=[];const e=[...this.traces];e.forEach(e=>{e.selected=!1}),this.traces=e,this.view&&(this._getGraphicLayer(E)?.removeAll(),this._getGraphicLayer(B)?.removeAll(),this._getGraphicLayer(C)?.removeAll(),this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]}),this.emit("reset"))}selectFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return;const r=this.utilityNetwork.getObjectIdsFromElements(e);this._getUniqueMapLayerViews(t).forEach(e=>{D(e)&&e.layer?.parsedUrl?.path===r[0].layerUrl&&j(e)&&this._highlightHandler.push(e.highlight(r[0].objectIds))})}selectResults(e){if(e.length>0){this.removeSelection();const t=this.groupResultsByNetworkSource(e),r=[];for(const e in t)this.selectFeaturesById(t[e]),r.push(this.queryFeaturesById(t[e]));Promise.all(r).then(e=>{this.emit("select-features",{resultSet:e})})}else this.removeSelection(),this.emit("clear-selection",{resultSet:[]})}selectTraces(e,t){const r=[...this.traces];r.forEach(r=>{t===r.globalId&&(r.selected=e)}),this.traces=r}selectTracesOnLoad(){this.utilityNetwork?.hasOwnProperty("sharedNamedTraceConfigurations")&&(this.traces=[...this.utilityNetwork.sharedNamedTraceConfigurations],this.traces.forEach(e=>{e.selected=!1,this.selectedTraces.includes(e.globalId)&&(e.selected=!0)}))}zoomToAsset(e){this.view?.goTo(e).catch(e=>console.error(e))}async _createResultAreaInputGeometry(e){if(null!=e.aggregatedGeometry)return this._geometryHandler.mergeAggregatedToGeometries(e.aggregatedGeometry);const t=this.groupResultsByNetworkSource(e.elements),r=[];for(const s in t)r.push(this.queryFeaturesById(t[s]));try{const e=await Promise.all(r),t=[];for(const r of e)if(r)for(const e of r)for(const r of e.featureSet.features)r.geometry&&t.push(r.geometry);return t}catch{return[]}}_loadUNSupportItems(){if(!this.utilityNetwork)return;const{map:e}=this.view,{messages:t}=this;this._populateOutfields(),this._createGraphicLayer(E),this._createGraphicLayer(B),this._createGraphicLayer(C),this._resultAreaHandler?.createGraphicLayer(e,t?.alertsStrings.genericResultHeader),this._validUNLayers=this._utilityHelper.getValidUtilityNetworkLayers(e,this.utilityNetwork),this._sketchViewModel=this.graphicHandler.initializeSketch(this.view,this._getGraphicLayer(E),this._validUNLayers)}_getUniqueMapLayerViews(e){const t=[],r=e.layerViews.filter(({layer:{type:e}})=>"feature"===e||"group"===e||"subtype-group"===e).toArray(),s=e=>{for(const r of e.layerViews)O(r)?s(r):t.push(r)};return r.forEach(e=>{switch(e.layer.type){case"group":O(e)&&s(e);break;case"subtype-group":t.push(e);break;default:t.some(t=>t.layer.id===e.layer.id)||t.push(e)}}),t}_processFlags(e){const t=[];return e.forEach(e=>{if(null!==e.selectedTerminals&&e.selectedTerminals.length>0)e.selectedTerminals.forEach(r=>{const s=new I({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:r,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(s)});else{const r=new I({globalId:e.globalId,percentAlong:e.percentAlong,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(r)}}),t}_getDisplayField(e){return f(e?.sourceLayer)?this._getDisplayFieldBySublayer(e):this._getDisplayFieldByFeatureLayer(e)}_getDisplayFieldBySublayer(e){let t="",r="";const s=e.sourceLayer;t=this._checkParentForData(s,"displayField");for(const i in e.attributes){const a=i.toLowerCase();a===t?.toLowerCase()?(r=e.attributes[i],"assetgroup"===a||"assettype"===a?r=this._checkSubtype(s,s.subtypeCode):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))}return{field:t,value:r?.toString()??s.title}}_getDisplayFieldByFeatureLayer(e){const t=e.sourceLayer;let r=t.displayField,s="";for(const i in e.attributes){const a=i.toLowerCase();if(a===r?.toLowerCase())if(s=e.attributes[i],"assetgroup"===a||"assettype"===a){let a=e.attributes[t.typeIdField.toUpperCase()];a||(a=e.attributes[t.typeIdField.toLowerCase()]),r=t.typeIdField,s=this._checkSubtype(t,a),""===r&&(t.templates&&t.templates.length>0?(r=t.templates[0]?.name,s=t.templates[0]?.name):(r=t.displayField,s=e.attributes[i]))}else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t));else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t))}return{field:r,value:s?s.toString():""}}_checkSubtype(e,t){let r=t;if("subtype-sublayer"===e.type){const s=this._checkParentForData(e,"subtypes");s?.length>0&&s.forEach(e=>{e.code===t&&(r=e.name)})}else if(null!=e.types&&e.types.length>0){const s=e.types.filter(e=>e.id===t);s.length>0&&(r=s[0].name)}return r}_checkDomain(e,t,r){let s=r;const i=e.filter(e=>e.name.toLowerCase()===t.toLowerCase());if(i.length>0&&V(i[0].domain)&&i[0].domain?.codedValues){const e=i[0].domain.codedValues.filter(({code:e})=>e===r);e.length>0&&(s=e[0].name)}return s}_checkParentForData(e,t){return e.parent?.[t]??null}_defaultDisplayField(e,t){return e.trim()?e:t.templates&&t.templates?.length>0?t.templates[0].name:t.title}get _uniqueFlagId(){return this._flagId++}_groupBy(e,t){return e.reduce((e,r)=>((e[r[t]]=e[r[t]]||[]).push(r),e),{})}async _lookupFlagByHit(e){const t=[];let r={};const s=e.graphic?.geometry,i=this.view?.toScreen(s),a=await(this.view?.hitTest(i,{include:this._validUNLayers}));if(!a?.results.length)return[];const l=a?.results.find(e=>null!==e.layer),n=l,c=n.graphic.geometry?.type,u=l?.layer,h=u.globalIdField??"globalid",p=u.objectIdField??"objectid";if(h&&!!n.graphic.attributes[h])r=n.graphic.attributes;else{const e=await(this.view?.whenLayerView(u)),t=e.createQuery();t.outFields=["assetgroup","assettype","globalid","objectid"],t.where=`${p} = ${n.graphic.attributes[p]}`,await o(()=>!e?.updating&&!e?.dataUpdating);const s=await(e?.queryFeatures(t)),i=s?.features[0],a=i?.attributes;r=a}const d=this._getDisplayField(n.graphic),g=n.mapPoint;let y={};if("point"===c||"polygon"===c){if(this.utilityNetwork){const e=this.utilityNetwork.getTerminalConfiguration(n.graphic);y={terminalId:e?e.terminals[0].id||null:1,isFilterBarrier:!1,allTerminals:e??null,selectedTerminals:[e?e.terminals[0].id||null:1],percentAlong:null,displayValue:d,mapPoint:g}}}else if("polyline"===c){const t=n.graphic.geometry;y={terminalId:null,isFilterBarrier:!1,allTerminals:null,selectedTerminals:null,percentAlong:this._geometryHandler.getPercentageAlong(t,e.graphic?.geometry,t.spatialReference),displayValue:d,mapPoint:g}}return n.graphic.attributes={...r,...y},t.push(n),t}_createFlagProperty(e,t,r){const s=new I;s.terminalId=e.attributes.terminalId,s.isFilterBarrier=e.attributes.isFilterBarrier,s.percentAlong=e.attributes.percentAlong,s.globalId=e.attributes.globalid||e.attributes.GLOBALID,s.type=t;const i=s;return i.details=e,i.mapGraphic=r,i.id=this._uniqueFlagId,i.allTerminals=e.attributes.allTerminals,i.selectedTerminals=e.attributes.selectedTerminals,i.displayValue=e.attributes.displayValue,i.mapPoint=e.attributes.mapPoint,i}_populateOutfields(){if(!this.view)return;const{map:e}=this.view,t=this.getValidSources(),r=e=>{"group"===e.type?e.layers.forEach(e=>{x(e)&&r(e)}):t.some(t=>t.layerId===e.layerId)&&e.fields.some(e=>"assetgroup"===e.name.toLowerCase())&&(e.outFields=["assetgroup","assettype","globalid","objectid"])};for(const s of e.layers)x(s)&&r(s)}_removeGraphic(e){this._getGraphicLayer(B)?.remove(e.mapGraphic)}_createGraphicLayer(e){const{map:t}=this.view;if(!t.findLayerById(e)){const t=new g({id:e,internal:!0,listMode:"hide",title:e});G(this.view,t)}}_getGraphicLayer(e){const{map:t}=this.view;if(t){const r=t.findLayerById(e);if(r&&M(r))return r}return null}};e([n()],$.prototype,"_activeProgress",void 0),e([n()],$.prototype,"_flags",void 0),e([n()],$.prototype,"traces",void 0),e([n()],$.prototype,"defaultGraphicColor",void 0),e([n()],$.prototype,"enableResultArea",void 0),e([n()],$.prototype,"flags",void 0),e([n()],$.prototype,"messages",void 0),e([n()],$.prototype,"messagesUnits",void 0),e([n()],$.prototype,"resultAreaProperties",null),e([n()],$.prototype,"selectedTraces",void 0),e([n()],$.prototype,"selectOnComplete",void 0),e([n()],$.prototype,"showGraphicsOnComplete",void 0),e([n()],$.prototype,"showSelectionAttributes",void 0),e([n({readOnly:!0})],$.prototype,"state",null),e([n()],$.prototype,"traceResults",void 0),e([n()],$.prototype,"utilityNetwork",void 0),e([n({value:null})],$.prototype,"view",null),$=e([c("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceViewModel")],$);const z=$;export{z as default};
5
+ import{__decorate as e}from"tslib";import{id as t}from"../../kernel.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import{EventedAccessor as i}from"../../core/Evented.js";import a from"../../core/Logger.js";import{whenOnce as l,once as o}from"../../core/reactiveUtils.js";import{property as n,subclass as c}from"../../core/accessorSupport/decorators.js";import{ensureArray as u}from"../../core/accessorSupport/ensureType.js";import{isPoint as h,isMultipoint as p}from"../../geometry/support/jsonUtils.js";import{fetchMessageBundle as d}from"../../intl/messages.js";import g from"../../layers/FeatureLayer.js";import y from"../../layers/GraphicsLayer.js";import m from"../../layers/support/CodedValueDomain.js";import{isFeatureLayer as f,isSubtypeSublayer as w,getOwningPortalUrl as _}from"../../layers/support/layerUtils.js";import b from"../../networks/UtilityNetwork.js";import{getFeaturesFromLayers as A}from"../../networks/support/utils.js";import v from"../../portal/Portal.js";import{hasUserTypeExtension as k}from"../../portal/support/utils.js";import{trace as I}from"../../rest/networks/trace.js";import F from"../../rest/networks/support/TraceLocation.js";import G from"../../rest/networks/support/TraceParameters.js";import{addUniqueLayer as R}from"../../views/draw/support/layerUtils.js";import{GeometryHandler as L}from"./support/GeometryHandler.js";import{GraphicHandler as T,barrierColor as H,startingPointColor as S}from"./support/GraphicHandler.js";import{ResultAreaHandler as N}from"./support/ResultAreaHandler.js";import{UtilityHelper as P}from"./support/UtilityHelper.js";const U=()=>d("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace"),B=()=>d("esri/core/t9n/Units"),C=`utility-network-trace-flags-${Date.now()}`,E=`utility-network-trace-results-${Date.now()}`,V=`utility-network-trace-sketch-${Date.now()}`;function j(e){return e instanceof m}function D(e){return"feature"===e.layer.type||"subtype-group"===e.layer.type}function O(e){return"layer"in e}function M(e){return void 0!==e.layerViews}function x(e){return"graphics"===e.type}function q(e){return"feature"===e.type||"subtype-group"===e.type||"group"===e.type}async function $(e){const t=new g({url:e.networkSystemLayers.dirtyAreasLayerUrl});await t.load();const r=t.version;if(Number(r)<=11.1){const t=await _(e.layerUrl),r=new v({url:t});await r.load();const s=r?.user?.username;return!!s&&k(r,s,"utilityNetwork")}return!0}let z=class extends i{constructor(e){super(e),this._activeProgress=!1,this._clickHandler=null,this._flags=[],this._flagId=0,this._geometryHandler=null,this._highlightHandler=[],this._resultAreaHandler=null,this._sketchViewModel=null,this._traceTimeout=6e5,this._utilityHelper=new P,this._validUNLayers=[],this._watchHandler=null,this.traces=[],this.graphicHandler=null,this.defaultGraphicColor={color:[255,255,0,.6],haloOpacity:.9,fillOpacity:.2,hex:"#FFFF00"},this.enableResultArea=!1,this.flags=[],this.messages=null,this.messagesUnits=null,this.defaultResultAreaProperties={type:"convexhull",distance:10,unit:"meters",areaUnit:"square-meters",color:{color:[255,165,0,.5],haloOpacity:.9,fillOpacity:.2,hex:"#ffa500"},show:!1},this.selectedTraces=[],this.selectOnComplete=!0,this.showGraphicsOnComplete=!0,this.showSelectionAttributes=!0,this.traceResults=[],this.utilityNetwork=null}initialize(){this._geometryHandler=new L,this.graphicHandler=new T,this._resultAreaHandler=new N;(async()=>{const[e,t]=await Promise.all([U(),B()]);this.set({messages:e,messagesUnits:t})})()}destroy(){this.view=null}get resultAreaProperties(){return this.defaultResultAreaProperties}set resultAreaProperties(e){this._set("resultAreaProperties",{...this.defaultResultAreaProperties,...e}),this.graphicHandler.addCustomColor(this.resultAreaProperties.color),this.traceResults.forEach(t=>{const r=t.resultArea?.show;t.resultArea={...this.defaultResultAreaProperties,...e},this.removeResultAreaFromMap(t),this.enableResultArea&&this.createResultAreaGraphic(t).then(s=>{if(s){t.resultAreaGraphic=s;const i=e?.show??r;t.resultArea&&(t.resultArea.show=i),i&&this.addResultAreaToMap(t,s)}})})}get state(){return this.view?.ready?"ready":"loading"}get view(){return this._get("view")}set view(e){e&&"2d"!==e.type&&a.getLogger(this).error(new s("view:invalid-view","SceneView is not supported",{view:e})),this._set("view",e),this.utilityNetwork&&this.reset(),this.utilityNetwork=null,this.loadUtilityNetwork().then(e=>{e&&this.selectTracesOnLoad()})}addFlagByHit(e,t){const r=!!this.view&&this.view.popupEnabled,s=e=>{this.view?.popup&&(this.view.popupEnabled=e)};return new Promise((i,a)=>{r&&s(!1),this._clickHandler?.remove(),this._clickHandler=this._sketchViewModel.on("create",l=>{if("complete"===l.state){const o=this._getGraphicLayer(V);o&&l.graphic&&o.remove(l.graphic),this.queryFlagByHitTest(l,e,t).then(r=>{this.emit("add-flag-complete",{type:e,symbol:t}),i(r)}).catch(r=>{this.emit("add-flag-error",{type:e,symbol:t}),a(r)}).finally(()=>{r&&s(!0),this._clickHandler?.remove()})}}),this._sketchViewModel.create("point"),this.emit("add-flag",{type:e})})}addNonspatialTraceLocation(e,t){const r=this._getDisplayField(e),s=this.utilityNetwork?.getTerminalConfiguration(e),i={terminalId:null,isFilterBarrier:!1,allTerminals:s,selectedTerminals:[s?s.terminals[0].id||null:1],displayValue:r};e.attributes={...e.attributes,...i};const a=e.attributes.hasOwnProperty("GLOBALID")?e.attributes.GLOBALID:e.attributes.globalid;if(!this._flags.some(e=>e.globalId===a&&e.type===t)){const r=this._createFlagProperty(e,t,null);this._flags.push(r),this.emit("add-flag-complete",{type:t})}this.emit("add-flag",{type:t})}async addFlagsOnLoad(){if(this._flags.length>0)return[];await l(()=>null!=this.view&&!this.view.updating);return(await Promise.all(this.flags.map(async e=>{if(!e.mapPoint)return null;const{type:t}=e,r=e.mapPoint.clone(),s="barrier"===t?H:S,i={graphic:this.graphicHandler.makeGraphic(r,s),state:"complete",tool:"point",toolEventInfo:null,type:"create"};try{return await this.queryFlagByHitTest(i,e.type,null),this.emit("add-flag-complete",{type:t}),null}catch(a){return this.emit("add-flag-error",{type:t}),"barrier"===t?"barrier":"starting-point"}}))).filter(e=>!e)}async addResultAreaToMap(e,t){if(this.view)if(e.resultArea.show=!0,t)this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t});else if(e.results){const t=await this.createResultAreaGraphic(e);t&&(e.resultAreaGraphic=t,this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t}))}}async addResultGraphicToView(e,t){const{view:r}=this,{results:s}=e;if(r&&s&&this.utilityNetwork)for(const i in s.aggregatedGeometry)if("line,multipoint,polygon".includes(i)){const a=i,l=s.aggregatedGeometry[a];if(null!=l){l.spatialReference=this.utilityNetwork.spatialReference,e.graphicEnabled=!0;const s=await this._geometryHandler.projectGeometry(l,r.spatialReference),i={globalid:e.trace.globalId};if(null!==s){const e=this.graphicHandler.makeGraphic(s,t.color,i,r.spatialReference);this._getGraphicLayer(E)?.add(e)}}}}addTerminal(e,t){const r=[...this._flags];r.forEach(r=>{r.globalId===t.globalId&&(t.selectedTerminals?.includes(parseInt(e,10))||r.selectedTerminals?.push(parseInt(e,10)))}),this._flags=r}async callTrace(){const e=this.traces.filter(e=>e.selected);return!!e.length&&(this.traceResults.length>0&&this.traceResults.forEach(e=>{this.removeResultGraphicFromView(e)}),this.traceResults=[],this.removeSelection(),await Promise.all(e.map(async(e,t)=>{const r=e,s=new G({gdbVersion:this.utilityNetwork?.gdbVersion,moment:this.utilityNetwork?.historicMoment,namedTraceConfigurationGlobalId:r.globalId,outSpatialReference:null,resultTypes:null,traceType:r.traceType,traceLocations:u(F,this._flags),traceConfiguration:null});await this.executeTrace(r,this.utilityNetwork?.networkServiceUrl,s).then(async e=>{if(e.hasOwnProperty("results")){const r={...e};if(null!==r.results){r.resultArea={...this.resultAreaProperties};const e=[...r.results.elements];r.results.elements.length=0;const s=new Map;for(const t of e)s.has(t.globalId)||(s.set(t.globalId,!0),r.results.elements.push(t));const i=[...this.traceResults];if(i.splice(t,0,r),this.traceResults=i,null!==r.results&&(this.selectOnComplete&&this.mergeSelection(!0,r.trace),this.showGraphicsOnComplete&&await this.addResultGraphicToView(r,r.graphicColor),this.enableResultArea)){const e=await this.createResultAreaGraphic(r);e&&(r.resultAreaGraphic=e,r.resultArea?.show&&await this.addResultAreaToMap(r,r.resultAreaGraphic))}}else{const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}this._activeProgress=!1}else{this._activeProgress=!1;const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}}).catch(e=>{throw this._activeProgress=!1,e})})),!0)}cancelAddFlagByHit(){this._sketchViewModel.cancel()}changeResultAreaColor(e,t){if(!e.resultArea)return;e.resultArea.color=t;const r=this._resultAreaHandler?.changeResultAreaColor(e.trace.globalId,t,this.view.map);e.resultAreaGraphic&&(e.resultAreaGraphic.symbol=r)}changeResultGraphicColor(e,t){const r=[...this.traceResults];r.length>0&&r.forEach(r=>{r.trace.globalId===t.trace.globalId&&(r.graphicColor=e,r.graphicEnabled=!0)}),this.traceResults=r,this.removeResultGraphicFromView(t),this.addResultGraphicToView(t,e)}changeFlagSymbol(e,t){this._flags.length>0&&this._flags.forEach(r=>{r.type===e&&t&&r.mapGraphic&&(r.mapGraphic.symbol=t)})}checkCanTrace(){const e={status:!0,issues:[]},t=this.traces.filter(e=>e.selected);t.length||(e.status=!1,e.issues.push("noTracesSelected"));this._flags.some(e=>"starting-point"===e.type)||(e.status=!1,e.issues.push("noStartingPoints"));return this._flags.filter(e=>null!==e.allTerminals).some(e=>!e.selectedTerminals.length)&&(e.status=!1,e.issues.push("noTerminalSelected")),e}checkSelectionExist(){return this._highlightHandler.some(e=>e)}clearResult(e){if(!this.view)return;let t=this.traceResults;if(t.length>0){const r=t.filter(t=>t.trace.globalId===e.globalId);r.length>0&&(this.removeResultGraphicFromView(r[0]),this.removeResultAreaFromMap(r[0])),t=t.filter(t=>t.trace.globalId!==e.globalId)}this.traceResults=t,0===t.length?(this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]})):this.mergeSelection(!1,e)}createResultAreaGeometries(e,t,r){if(!this.view||!this.resultAreaProperties)return;let s;if(s="convexhull"===this.resultAreaProperties?.type?1===t.length&&(h(t[0])||p(t[0])&&1===t[0].points.length)?this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0):this._resultAreaHandler?.createConvexHull(t,e.resultArea?.distance,e.resultArea?.unit):this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0),!s)return;if(Array.isArray(s)){for(const t of s){const r=this.getResultAreaAttributes(e,t),s=this._resultAreaHandler?.createResultAreaGraphic(t,r,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(s)return s}return}const i=this.getResultAreaAttributes(e,s);return this._resultAreaHandler?.createResultAreaGraphic(s,i,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color)}async createResultAreaGraphic(e){if(e.results){const t=await this._createResultAreaInputGeometry(e.results);if(t.length>0){const r=Array(t.length).fill(e.resultArea?.distance),s=this.createResultAreaGeometries(e,t,r);return this.emit("create-result-area",{graphic:s}),s}}}executeTrace(e,t,r){const s=this._processFlags(r.traceLocations);return r.traceLocations=s,I(t,r,{timeout:this._traceTimeout}).then(t=>({trace:e,results:t,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:"success",date:new Date})).catch(t=>({trace:e,results:null,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:t.message,date:new Date}))}async getNonspatialTraceLocationInitialFeature(){return new Promise((e,t)=>{this._clickHandler?.remove(),this._clickHandler=this._sketchViewModel.on("create",async r=>{if("complete"!==r.state)return;const s=this._getGraphicLayer(V);s&&r.graphic&&s.remove(r.graphic);const i=this.view?.toScreen(r.graphic?.geometry);if(!i)return;const a=await(this.view?.hitTest(i));if(a?.results.length){const r=a.results.find(e=>"graphic"===e.type&&this.utilityNetwork?.isUtilityLayer(e.layer));r?e(r):t(null)}}),this._sketchViewModel.create("point")})}getResultAreaAttributes(e,r){const{messages:s}=this,i=[],a=[];this._flags.forEach(e=>{const t=e.displayValue?.field+":"+e.displayValue?.value+";"+s.attributeStrings.globalid+":"+e.globalId+";"+s.attributeStrings.terminalid+":"+e.terminalId+";"+s.attributeStrings.x+":"+e.mapPoint?.x+";"+s.attributeStrings.y+":"+e.mapPoint?.y;"starting-point"===e.type?i.push(t):a.push(t)});const l=this.utilityNetwork?.gdbVersion;return{traceId:e.trace.globalId,traceName:e.trace.title,traceDescription:e.trace.description??"",startingPoints:i.toString(),barriers:a.toString(),version:l??void 0,username:t.credentials[0].userId,date:e.date,elementCount:e.results?.elements.length,functionResult:JSON.stringify(e.results?.globalFunctionResults),areaStatistic:r?this._geometryHandler.calculateArea(r,e.resultArea?.areaUnit):0}}getValidSources(){let e=[];const t=this.utilityNetwork?.dataElement?.domainNetworks??[];for(const r of t)e=e.concat(r.junctionSources),e=e.concat(r.edgeSources);return e}groupResultsByNetworkSource(e){return 0===e.length?[]:this._groupBy(e,"networkSourceId")}async loadUtilityNetwork(){const{view:e}=this;if(!e)return null;if(await e.when(),this.utilityNetwork){if(this.utilityNetwork.loaded||await this.utilityNetwork.load(),this.utilityNetwork instanceof b){try{const t=e.map;await t.loadAll()}catch(i){if("layer:unsupported-layer-type"!==i.name&&"subtype-grouplayer:missing-subtypes"!==i.name)throw i;console.error(i)}finally{this._loadUNSupportItems()}return this.utilityNetwork}return null}const t=e.map,r=t.utilityNetworks?.at(0);if(r){if(await r.load(),this.utilityNetwork=r,!await $(r))throw new s("utility-network:no-user-type-extension","User type extension not found");try{await t.loadAll()}catch(i){if("layer:unsupported-layer-type"!==i.name&&"subtype-grouplayer:missing-subtypes"!==i.name)throw i;console.error(i)}finally{this._loadUNSupportItems()}return r}return null}manageFilterBarrier(e,t){const r=[...this._flags];r.forEach(r=>{r.globalId===t.globalId&&"barrier"===t.type&&r.id===t.id&&(r.isFilterBarrier=e)}),this._flags=r}mergeSelection(e,t){let r=[];const s=[...this.traceResults],i=t.globalId;s.forEach(t=>{i===t.trace.globalId&&(t.selectionEnabled=e),t.selectionEnabled&&null!==t.results?.elements&&(r=[...r,...t.results?.elements??[]])}),this.selectResults([...new Set(r)])}async queryFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return null;const s=this.utilityNetwork.getObjectIdsFromElements(e),i={layerUrl:s[0].layerUrl,objectIds:s[0].objectIds,outFields:["*"]},a=t.map?.allTables.toArray().filter(e=>e?.parsedUrl?.path===s[0].layerUrl).filter(f)??[];this._getUniqueMapLayerViews(t).filter(({layer:e})=>e?.parsedUrl?.path===s[0].layerUrl).forEach(({layer:e})=>{"feature"!==e.type&&"subtype-group"!==e.type||a.push(e)});const l=(await Promise.all(a.map(async e=>{const s={layers:new r([e]),layerInfos:[i],returnGeometry:!0,outSpatialReference:t.spatialReference},[a]=await A(s,!1);return a}))).filter(({featureSet:e})=>e.features.length>0);return l.length>0?l:null}queryFlagByHitTest(e,t,r){return this._lookupFlagByHit(e).then(e=>{const{view:s}=this;if(!s)return!1;if(e.length>0){const s=[...this._flags],i=r;return e.forEach(e=>{const r=e.graphic,a=r.attributes.hasOwnProperty("GLOBALID")?r.attributes.GLOBALID:r.attributes.globalid;if(s.filter(e=>e.globalId===a).length<=0){const e=this.graphicHandler.getFlagGraphic(r.attributes.mapPoint,t,r,i);this._getGraphicLayer(C)?.add(e);const a=this._createFlagProperty(r,t,e);s.push(a)}else if(null!==r.attributes.percentAlong){const e=this.graphicHandler.getFlagGraphic(r.attributes.mapPoint,t,r,i);this._getGraphicLayer(C)?.add(e);const a=this._createFlagProperty(r,t,e);s.push(a)}}),this._flags=s,!0}return!1})}removeResultGraphicFromView(e){const{view:t}=this;if(!t)return;const r=this._getGraphicLayer(E)?.graphics;e.graphicEnabled=!1;const s=r?.filter(t=>t.attributes[t.attributes.hasOwnProperty("GLOBALID")?"GLOBALID":"globalid"]===e.trace.globalId);s?.forEach(e=>{this._getGraphicLayer(E)?.remove(e)})}removeFlag(e){const t=this._flags.filter(t=>{if(t.id!==e.id)return t});this._removeGraphic(e),this._flags=t}removeAllResultAreaGraphics(){this._resultAreaHandler?.removeAllResultAreaGraphics(this.view.map)}removeResultAreaFromMap(e){if(e.resultArea){e.resultArea.show=!1;const t=this._resultAreaHandler?.removeResultArea(e.trace.globalId,this.view?.map);t&&this.emit("remove-result-area",{graphic:t})}}removeSelection(){this._highlightHandler.forEach(e=>{e&&e.remove()}),this._highlightHandler=[]}removeTerminal(e,t){const r=[...this._flags];r.forEach(r=>{if(r.globalId===t.globalId&&t.selectedTerminals?.includes(parseInt(e,10))){const s=t.selectedTerminals.indexOf(parseInt(e,10));r.selectedTerminals?.splice(s,1)}}),this._flags=r}removeFlagsOnLoadWatcher(){this._watchHandler&&null!==this._watchHandler&&this._watchHandler.remove()}removeClickHandler(){this._clickHandler&&(this._sketchViewModel.cancel(),this._clickHandler.remove())}reset(){this._flags=[],this.traceResults=[];const e=[...this.traces];e.forEach(e=>{e.selected=!1}),this.traces=e,this.view&&(this._getGraphicLayer(V)?.removeAll(),this._getGraphicLayer(C)?.removeAll(),this._getGraphicLayer(E)?.removeAll(),this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]}),this.emit("reset"))}selectFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return;const r=this.utilityNetwork.getObjectIdsFromElements(e);this._getUniqueMapLayerViews(t).forEach(e=>{O(e)&&e.layer?.parsedUrl?.path===r[0].layerUrl&&D(e)&&this._highlightHandler.push(e.highlight(r[0].objectIds))})}selectResults(e){if(e.length>0){this.removeSelection();const t=this.groupResultsByNetworkSource(e),r=[];for(const e in t)this.selectFeaturesById(t[e]),r.push(this.queryFeaturesById(t[e]));Promise.all(r).then(e=>{this.emit("select-features",{resultSet:e})})}else this.removeSelection(),this.emit("clear-selection",{resultSet:[]})}selectTraces(e,t){const r=[...this.traces];r.forEach(r=>{t===r.globalId&&(r.selected=e)}),this.traces=r}selectTracesOnLoad(){this.utilityNetwork?.hasOwnProperty("sharedNamedTraceConfigurations")&&(this.traces=[...this.utilityNetwork.sharedNamedTraceConfigurations],this.traces.forEach(e=>{e.selected=!1,this.selectedTraces.includes(e.globalId)&&(e.selected=!0)}))}zoomToAsset(e){this.view?.goTo(e).catch(e=>console.error(e))}async _createResultAreaInputGeometry(e){if(null!=e.aggregatedGeometry)return this._geometryHandler.mergeAggregatedToGeometries(e.aggregatedGeometry);const t=this.groupResultsByNetworkSource(e.elements),r=[];for(const s in t)r.push(this.queryFeaturesById(t[s]));try{const e=await Promise.all(r),t=[];for(const r of e)if(r)for(const e of r)for(const r of e.featureSet.features)r.geometry&&t.push(r.geometry);return t}catch{return[]}}_loadUNSupportItems(){if(!this.utilityNetwork)return;const{map:e}=this.view,{messages:t}=this;this._populateOutfields(),this._createGraphicLayer(V),this._createGraphicLayer(C),this._createGraphicLayer(E),this._resultAreaHandler?.createGraphicLayer(e,t?.alertsStrings.genericResultHeader),this._validUNLayers=this._utilityHelper.getValidUtilityNetworkLayers(e,this.utilityNetwork),this._sketchViewModel=this.graphicHandler.initializeSketch(this.view,this._getGraphicLayer(V),this._validUNLayers)}_getUniqueMapLayerViews(e){const t=[],r=e.layerViews.filter(({layer:{type:e}})=>"feature"===e||"group"===e||"subtype-group"===e).toArray(),s=e=>{for(const r of e.layerViews)M(r)?s(r):t.push(r)};return r.forEach(e=>{switch(e.layer.type){case"group":M(e)&&s(e);break;case"subtype-group":t.push(e);break;default:t.some(t=>t.layer.id===e.layer.id)||t.push(e)}}),t}_processFlags(e){const t=[];return e.forEach(e=>{if(null!==e.selectedTerminals&&e.selectedTerminals.length>0)e.selectedTerminals.forEach(r=>{const s=new F({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:r,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(s)});else{const r=new F({globalId:e.globalId,percentAlong:e.percentAlong,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(r)}}),t}_getDisplayField(e){return w(e?.sourceLayer)?this._getDisplayFieldBySublayer(e):this._getDisplayFieldByFeatureLayer(e)}_getDisplayFieldBySublayer(e){let t="",r="";const s=e.sourceLayer;t=this._checkParentForData(s,"displayField");for(const i in e.attributes){const a=i.toLowerCase();a===t?.toLowerCase()?(r=e.attributes[i],"assetgroup"===a||"assettype"===a?r=this._checkSubtype(s,s.subtypeCode):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))}return{field:t,value:r?.toString()??s.title}}_getDisplayFieldByFeatureLayer(e){const t=e.sourceLayer;let r=t.displayField,s="";for(const i in e.attributes){const a=i.toLowerCase();if(a===r?.toLowerCase())if(s=e.attributes[i],"assetgroup"===a||"assettype"===a){let a=e.attributes[t.typeIdField.toUpperCase()];a||(a=e.attributes[t.typeIdField.toLowerCase()]),r=t.typeIdField,s=this._checkSubtype(t,a),""===r&&(t.templates&&t.templates.length>0?(r=t.templates[0]?.name,s=t.templates[0]?.name):(r=t.displayField,s=e.attributes[i]))}else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t));else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t))}return{field:r,value:s?s.toString():""}}_checkSubtype(e,t){let r=t;if("subtype-sublayer"===e.type){const s=this._checkParentForData(e,"subtypes");s?.length>0&&s.forEach(e=>{e.code===t&&(r=e.name)})}else if(null!=e.types&&e.types.length>0){const s=e.types.filter(e=>e.id===t);s.length>0&&(r=s[0].name)}return r}_checkDomain(e,t,r){let s=r;const i=e.filter(e=>e.name.toLowerCase()===t.toLowerCase());if(i.length>0&&j(i[0].domain)&&i[0].domain?.codedValues){const e=i[0].domain.codedValues.filter(({code:e})=>e===r);e.length>0&&(s=e[0].name)}return s}_checkParentForData(e,t){return e.parent?.[t]??null}_defaultDisplayField(e,t){return e.trim()?e:t.templates&&t.templates?.length>0?t.templates[0].name:t.title}get _uniqueFlagId(){return this._flagId++}_groupBy(e,t){return e.reduce((e,r)=>((e[r[t]]=e[r[t]]||[]).push(r),e),{})}async _lookupFlagByHit(e){const t=[];let r={};const s=e.graphic?.geometry,i=this.view?.toScreen(s),a=await(this.view?.hitTest(i,{include:this._validUNLayers}));if(!a?.results.length)return[];const l=a?.results.find(e=>null!==e.layer),n=l,c=n.graphic.geometry?.type,u=l?.layer,h=u.globalIdField??"globalid",p=u.objectIdField??"objectid";if(h&&!!n.graphic.attributes[h])r=n.graphic.attributes;else{const e=await(this.view?.whenLayerView(u)),t=e.createQuery();t.outFields=["assetgroup","assettype","globalid","objectid"],t.where=`${p} = ${n.graphic.attributes[p]}`,await o(()=>!e?.updating&&!e?.dataUpdating);const s=await(e?.queryFeatures(t)),i=s?.features[0],a=i?.attributes;r=a}const d=this._getDisplayField(n.graphic),g=n.mapPoint;let y={};if("point"===c||"polygon"===c){if(this.utilityNetwork){const e=this.utilityNetwork.getTerminalConfiguration(n.graphic);y={terminalId:e?e.terminals[0].id||null:1,isFilterBarrier:!1,allTerminals:e??null,selectedTerminals:[e?e.terminals[0].id||null:1],percentAlong:null,displayValue:d,mapPoint:g}}}else if("polyline"===c){const t=n.graphic.geometry;y={terminalId:null,isFilterBarrier:!1,allTerminals:null,selectedTerminals:null,percentAlong:this._geometryHandler.getPercentageAlong(t,e.graphic?.geometry,t.spatialReference),displayValue:d,mapPoint:g}}return n.graphic.attributes={...r,...y},t.push(n),t}_createFlagProperty(e,t,r){const s=new F;s.terminalId=e.attributes.terminalId,s.isFilterBarrier=e.attributes.isFilterBarrier,s.percentAlong=e.attributes.percentAlong,s.globalId=e.attributes.globalid||e.attributes.GLOBALID,s.type=t;const i=s;return i.details=e,i.mapGraphic=r,i.id=this._uniqueFlagId,i.allTerminals=e.attributes.allTerminals,i.selectedTerminals=e.attributes.selectedTerminals,i.displayValue=e.attributes.displayValue,i.mapPoint=e.attributes.mapPoint,i}_populateOutfields(){if(!this.view)return;const{map:e}=this.view,t=this.getValidSources(),r=e=>{"group"===e.type?e.layers.forEach(e=>{q(e)&&r(e)}):t.some(t=>t.layerId===e.layerId)&&e.fields.some(e=>"assetgroup"===e.name.toLowerCase())&&(e.outFields=["assetgroup","assettype","globalid","objectid"])};for(const s of e.layers)q(s)&&r(s)}_removeGraphic(e){this._getGraphicLayer(C)?.remove(e.mapGraphic)}_createGraphicLayer(e){const{map:t}=this.view;if(!t.findLayerById(e)){const t=new y({id:e,internal:!0,listMode:"hide",title:e});R(this.view,t)}}_getGraphicLayer(e){const{map:t}=this.view;if(t){const r=t.findLayerById(e);if(r&&x(r))return r}return null}};e([n()],z.prototype,"_activeProgress",void 0),e([n()],z.prototype,"_flags",void 0),e([n()],z.prototype,"traces",void 0),e([n()],z.prototype,"defaultGraphicColor",void 0),e([n()],z.prototype,"enableResultArea",void 0),e([n()],z.prototype,"flags",void 0),e([n()],z.prototype,"messages",void 0),e([n()],z.prototype,"messagesUnits",void 0),e([n()],z.prototype,"resultAreaProperties",null),e([n()],z.prototype,"selectedTraces",void 0),e([n()],z.prototype,"selectOnComplete",void 0),e([n()],z.prototype,"showGraphicsOnComplete",void 0),e([n()],z.prototype,"showSelectionAttributes",void 0),e([n({readOnly:!0})],z.prototype,"state",null),e([n()],z.prototype,"traceResults",void 0),e([n()],z.prototype,"utilityNetwork",void 0),e([n({value:null})],z.prototype,"view",null),z=e([c("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceViewModel")],z);const J=z;export{J as default};