@arcgis/core 4.24.5 → 4.24.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/core",
3
- "version": "4.24.5",
3
+ "version": "4.24.6",
4
4
  "homepage": "https://js.arcgis.com",
5
5
  "description": "ArcGIS API for JavaScript: A complete 2D and 3D mapping and data visualization API",
6
6
  "keywords": [
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- const c="20220630",e="5a46844c5ac1b721521da79fb0304de9e8457e2c";export{c as buildDate,e as commitHash};
5
+ const d="20220707",f="7fd01dbc0e83d753fcf101c8ff2a8d215430252d";export{d as buildDate,f as commitHash};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import i from"../../../Graphic.js";import s from"../../../core/Collection.js";import{isSome as t,isNone as r}from"../../../core/maybe.js";import{watch as h,on as a,initial as o}from"../../../core/reactiveUtils.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/set.js";import{subclass as p}from"../../../core/accessorSupport/decorators/subclass.js";import{LayerView2DMixin as c}from"./LayerView2D.js";import n from"./graphics/GraphicContainer.js";import l from"./graphics/GraphicsView2D.js";import g from"../../layers/LayerView.js";const d="sublayers",u="layerView",f=Object.freeze({remove(){},pause(){},resume(){}});let m=class extends(c(g)){constructor(){super(...arguments),this._highlightIds=new Map}async fetchPopupFeatures(e){return Array.from(this.graphicsViews(),(i=>i.hitTest(e).filter((e=>!!e.popupTemplate)))).flat()}*graphicsViews(){t(this._graphicsViewsFeatureCollectionMap)?yield*this._graphicsViewsFeatureCollectionMap.keys():t(this._graphicsViews)?yield*this._graphicsViews:yield*[]}async hitTest(e,i){return Array.from(this.graphicsViews(),(i=>{const s=i.hitTest(e);if(t(this._graphicsViewsFeatureCollectionMap)){const e=this._graphicsViewsFeatureCollectionMap.get(i);for(const i of s)!i.popupTemplate&&e.popupTemplate&&(i.popupTemplate=e.popupTemplate)}return s})).flat().map((i=>({type:"graphic",graphic:i,layer:this.layer,mapPoint:e})))}highlight(e){let t;return"number"==typeof e?t=[e]:e instanceof i?t=[e.uid]:Array.isArray(e)&&e.length>0?t="number"==typeof e[0]?e:e.map((e=>e&&e.uid)):s.isCollection(e)&&(t=e.map((e=>e&&e.uid)).toArray()),t=t.filter((e=>null!=e)),t.length?(this._addHighlight(t),{remove:()=>{this._removeHighlight(t)}}):f}update(e){for(const i of this.graphicsViews())i.processUpdate(e)}attach(){const e=this.view,i=()=>this.requestUpdate(),s=this.layer.featureCollections;if(t(s)&&s.length){this._graphicsViewsFeatureCollectionMap=new Map;for(const t of s){const s=new n(this.view.featuresTilingScheme);s.fadeTransitionEnabled=!0;const r=new l({view:e,graphics:t.source,renderer:t.renderer,requestUpdateCallback:i,container:s});this._graphicsViewsFeatureCollectionMap.set(r,t),this.container.addChild(r.container),this.handles.add([h((()=>t.visible),(e=>r.container.visible=e),o),h((()=>r.updating),(()=>this.notifyChange("updating")),o)],u)}this._updateHighlight()}else t(this.layer.sublayers)&&this.handles.add(a((()=>this.layer.sublayers),"change",(()=>this._createGraphicsViews()),{onListenerAdd:()=>this._createGraphicsViews(),onListenerRemove:()=>this._destroyGraphicsViews()}),d)}detach(){this._destroyGraphicsViews(),this.handles.remove(d)}moveStart(){}moveEnd(){}viewChange(){for(const e of this.graphicsViews())e.viewChange()}isUpdating(){for(const e of this.graphicsViews())if(e.updating)return!0;return!1}_destroyGraphicsViews(){this.container.removeAllChildren(),this.handles.remove(u);for(const e of this.graphicsViews())e.destroy();this._graphicsViews=null,this._graphicsViewsFeatureCollectionMap=null}_createGraphicsViews(){if(this._destroyGraphicsViews(),r(this.layer.sublayers))return;const e=[],i=this.view,s=()=>this.requestUpdate();for(const t of this.layer.sublayers){const r=new n(this.view.featuresTilingScheme);r.fadeTransitionEnabled=!0;const a=new l({view:i,graphics:t.graphics,requestUpdateCallback:s,container:r});this.handles.add([t.on("graphic-update",a.graphicUpdateHandler),h((()=>t.visible),(e=>a.container.visible=e),o),h((()=>a.updating),(()=>this.notifyChange("updating")),o)],u),this.container.addChild(a.container),e.push(a)}this._graphicsViews=e,this._updateHighlight()}_addHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i);this._highlightIds.set(i,e+1)}else this._highlightIds.set(i,1);this._updateHighlight()}_removeHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i)-1;0===e?this._highlightIds.delete(i):this._highlightIds.set(i,e)}this._updateHighlight()}_updateHighlight(){const e=Array.from(this._highlightIds.keys());for(const i of this.graphicsViews())i.setHighlight(e)}};m=e([p("esri.views.2d.layers.MapNotesLayerView2D")],m);const w=m;export{w as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import i from"../../../Graphic.js";import s from"../../../core/Collection.js";import{isSome as t,isNone as r}from"../../../core/maybe.js";import{watch as h,on as a,initial as o}from"../../../core/reactiveUtils.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/set.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import{Container as p}from"../engine/Container.js";import{GroupContainer as c}from"../engine/webgl/GroupContainer.js";import{LayerView2DMixin as l}from"./LayerView2D.js";import g from"./graphics/GraphicContainer.js";import d from"./graphics/GraphicsView2D.js";import u from"../../layers/LayerView.js";const f="sublayers",m="layerView",w=Object.freeze({remove(){},pause(){},resume(){}});let y=class extends(l(u)){constructor(){super(...arguments),this._highlightIds=new Map,this.container=new c}async fetchPopupFeatures(e){return Array.from(this.graphicsViews(),(i=>i.hitTest(e).filter((e=>!!e.popupTemplate)))).flat()}*graphicsViews(){t(this._graphicsViewsFeatureCollectionMap)?yield*this._graphicsViewsFeatureCollectionMap.keys():t(this._graphicsViews)?yield*this._graphicsViews:yield*[]}async hitTest(e,i){return Array.from(this.graphicsViews(),(i=>{const s=i.hitTest(e);if(t(this._graphicsViewsFeatureCollectionMap)){const e=this._graphicsViewsFeatureCollectionMap.get(i);for(const i of s)!i.popupTemplate&&e.popupTemplate&&(i.popupTemplate=e.popupTemplate)}return s})).flat().map((i=>({type:"graphic",graphic:i,layer:this.layer,mapPoint:e})))}highlight(e){let t;return"number"==typeof e?t=[e]:e instanceof i?t=[e.uid]:Array.isArray(e)&&e.length>0?t="number"==typeof e[0]?e:e.map((e=>e&&e.uid)):s.isCollection(e)&&(t=e.map((e=>e&&e.uid)).toArray()),t=t.filter((e=>null!=e)),t.length?(this._addHighlight(t),{remove:()=>{this._removeHighlight(t)}}):w}update(e){for(const i of this.graphicsViews())i.processUpdate(e)}attach(){const e=this.view,i=()=>this.requestUpdate(),s=this.layer.featureCollections;if(t(s)&&s.length){this._graphicsViewsFeatureCollectionMap=new Map;for(const t of s){const s=new g(this.view.featuresTilingScheme);s.fadeTransitionEnabled=!0;const r=new d({view:e,graphics:t.source,renderer:t.renderer,requestUpdateCallback:i,container:s});this._graphicsViewsFeatureCollectionMap.set(r,t),this.container.addChild(r.container),this.handles.add([h((()=>t.visible),(e=>r.container.visible=e),o),h((()=>r.updating),(()=>this.notifyChange("updating")),o)],m)}this._updateHighlight()}else t(this.layer.sublayers)&&this.handles.add(a((()=>this.layer.sublayers),"change",(()=>this._createGraphicsViews()),{onListenerAdd:()=>this._createGraphicsViews(),onListenerRemove:()=>this._destroyGraphicsViews()}),f)}detach(){this._destroyGraphicsViews(),this.handles.remove(f)}moveStart(){}moveEnd(){}viewChange(){for(const e of this.graphicsViews())e.viewChange()}isUpdating(){for(const e of this.graphicsViews())if(e.updating)return!0;return!1}_destroyGraphicsViews(){this.container.removeAllChildren(),this.handles.remove(m);for(const e of this.graphicsViews())e.destroy();this._graphicsViews=null,this._graphicsViewsFeatureCollectionMap=null}_createGraphicsViews(){if(this._destroyGraphicsViews(),r(this.layer.sublayers))return;const e=[],i=this.view,s=()=>this.requestUpdate();for(const t of this.layer.sublayers){const r=new p,a=new g(this.view.featuresTilingScheme);a.fadeTransitionEnabled=!0;const n=new d({view:i,graphics:t.graphics,requestUpdateCallback:s,container:a});this.handles.add([t.on("graphic-update",n.graphicUpdateHandler),h((()=>t.visible),(e=>n.container.visible=e),o),h((()=>n.updating),(()=>this.notifyChange("updating")),o)],m),r.addChild(n.container),this.container.addChild(r),e.push(n)}this._graphicsViews=e,this._updateHighlight()}_addHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i);this._highlightIds.set(i,e+1)}else this._highlightIds.set(i,1);this._updateHighlight()}_removeHighlight(e){for(const i of e)if(this._highlightIds.has(i)){const e=this._highlightIds.get(i)-1;0===e?this._highlightIds.delete(i):this._highlightIds.set(i,e)}this._updateHighlight()}_updateHighlight(){const e=Array.from(this._highlightIds.keys());for(const i of this.graphicsViews())i.setHighlight(e)}};y=e([n("esri.views.2d.layers.MapNotesLayerView2D")],y);const _=y;export{_ as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../Graphic.js";import i from"../../../core/Collection.js";import s from"../../../core/Error.js";import r from"../../../core/Evented.js";import o from"../../../core/Handles.js";import n from"../../../core/Logger.js";import{destroyMaybe as a,isNone as h,isSome as c,abortMaybe as p,get as l}from"../../../core/maybe.js";import{createTask as d}from"../../../core/promiseUtils.js";import{when as m,pausable as v}from"../../../core/reactiveUtils.js";import{property as y}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{closeRingsAndFixWinding as g,geometryToCoordinates as u,getMidpoint as x}from"../../../geometry/support/coordsUtils.js";import f from"../../../layers/GraphicsLayer.js";import G from"../../../symbols/SimpleMarkerSymbol.js";import{ViewingMode as b}from"../../ViewingMode.js";import{SnappingVisualizer2D as V}from"../../2d/interactive/SnappingVisualizer2D.js";import{cloneMove as M}from"./drawUtils.js";import w from"./GraphicMover.js";import S from"./HighlightHelper.js";import{addUniqueLayer as k}from"./layerUtils.js";import{settings as E}from"./settings.js";import{ViewEventPriorities as I}from"../../input/InputManager.js";import{SKETCH_KEYS as O}from"../../interactive/keybindings.js";import{EditGeometryOperations as C}from"../../interactive/editGeometry/EditGeometryOperations.js";import{SnappingContext as R}from"../../interactive/snapping/SnappingContext.js";import j from"../../../geometry/Polyline.js";import H from"../../../geometry/Point.js";class A{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape-start"}}class U{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape"}}class T{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape-stop"}}class D{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move-start"}}class F{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move"}}class z{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move-stop"}}class L{constructor(e){this.added=e,this.type="vertex-select"}}class P{constructor(e){this.removed=e,this.type="vertex-deselect"}}class K{constructor(e,t,i,s){this.added=e,this.graphic=t,this.oldGraphic=i,this.vertices=s,this.type="vertex-add"}}class N{constructor(e,t,i,s){this.removed=e,this.graphic=t,this.oldGraphic=i,this.vertices=s,this.type="vertex-remove"}}const q=E.reshapeGraphics,B={vertices:{default:new G({style:"circle",size:q.vertex.size,color:q.vertex.color,outline:{color:q.vertex.outlineColor,width:1}}),hover:new G({style:"circle",size:q.vertex.hoverSize,color:q.vertex.hoverColor,outline:{color:q.vertex.hoverOutlineColor,width:1}}),selected:new G({style:"circle",size:q.selected.size,color:q.selected.color,outline:{color:q.selected.outlineColor,width:1}})},midpoints:{default:new G({style:"circle",size:q.midpoint.size,color:q.midpoint.color,outline:{color:q.midpoint.outlineColor,width:1}}),hover:new G({style:"circle",size:q.midpoint.size,color:q.midpoint.color,outline:{color:q.midpoint.outlineColor,width:1}})}},J="esri.views.draw.support.Reshape",Q=n.getLogger(J);let W=class extends r.EventedAccessor{constructor(e){super(e),this._activeOperationInfo=null,this._editGeometryOperations=null,this._handles=new o,this._graphicAttributes={esriSketchTool:"box"},this._mover=null,this._snappingTask=null,this._stagedVertex=null,this._viewHandles=new o,this.callbacks={onReshapeStart(){},onReshape(){},onReshapeStop(){},onMoveStart(){},onMove(){},onMoveStop(){},onGraphicClick(){}},this.enableMidpoints=!0,this.enableMovement=!0,this.enableVertices=!0,this.graphic=null,this.layer=null,this.midpointGraphics=new i,this.midpointSymbol=new G({style:"circle",size:6,color:[200,200,200],outline:{color:[100,100,100],width:1}}),this.selectedVertices=[],this.snappingManager=null,this.type="reshape",this.vertexGraphics=new i,this.view=null}initialize(){this._highlightHelper=new S({view:this.view}),this._setup(),this._handles.add([m((()=>this.view?.ready),(()=>{const{layer:e,view:t}=this;k(t,e),this._viewHandles.add(t.on("key-down",(e=>this._keyDownHandler(e)),I.TOOL))}),{once:!0,initial:!0}),v((()=>this.graphic),(()=>this.refresh())),v((()=>this.layer),((e,t)=>{t&&(this._clearSelection(),this._resetGraphics(t)),this.refresh()})),v((()=>this.enableMidpoints),(()=>this.refresh()))])}destroy(){this._reset(),this._mover?.destroy(),this._mover=null,this._handles=a(this._handles),this._viewHandles=a(this._viewHandles)}set highlightsEnabled(e){this._highlightHelper?.removeAll(),this._set("highlightsEnabled",e),this._setUpHighlights()}get state(){const e=!!this.get("view.ready"),t=!(!this.get("graphic")||!this.get("layer"));return e&&t?"active":e?"ready":"disabled"}set symbols(e){const{midpoints:t=B.midpoints,vertices:i=B.vertices}=e||{};this._set("symbols",{midpoints:t,vertices:i})}isUIGraphic(e){const t=[];return this.graphic&&t.push(this.graphic),t.concat(this.vertexGraphics.items,this.midpointGraphics.items),t.length&&t.includes(e)}refresh(){this._reset(),this._setup()}reset(){this.graphic=null}clearSelection(){this._clearSelection()}removeSelectedVertices(){this.selectedVertices.length&&this._removeVertices(this.selectedVertices)}_setup(){const{graphic:e,layer:t}=this;if(!t||!e||h(e.geometry))return;const i=e.geometry;"mesh"!==i.type&&"extent"!==i.type?("polygon"===i.type&&g(i),this._setUpHighlights(),this._setupGraphics(),this._setupMover()):this._logGeometryTypeError()}_setUpHighlights(){this.highlightsEnabled&&this.graphic&&this._highlightHelper.add(this.graphic)}_setUpGeometryHelper(){const e=this.graphic.geometry;if(h(e)||"mesh"===e.type||"extent"===e.type)return void this._logGeometryTypeError();const t="multipoint"===e.type?new j({paths:e.points,spatialReference:e.spatialReference}):e;this._editGeometryOperations=C.fromGeometry(t,b.Local)}_saveSnappingContextForHandle(e,t){this._snappingGraphicsLayer=new f({listMode:"hide",internal:!0,title:"Reshape snapping layer"}),this.view.map.layers.add(this._snappingGraphicsLayer),this._snappingContext=new R({editGeometryOperations:this._editGeometryOperations,elevationInfo:{mode:"on-the-ground",offset:0},pointer:t.viewEvent?.pointerType||"mouse",excludeFeature:this.graphic,visualizer:new V(this._snappingGraphicsLayer),vertexHandle:this._getVertexFromEditGeometry(e)})}_reset(){this._clearSelection(),this._highlightHelper.removeAll(),this._resetGraphics(),this._resetSnappingStateVars(),this._activeOperationInfo=null,this._mover&&this._mover.destroy(),this._mover=null,this.view.cursor="default"}_resetSnappingStateVars(){c(this.snappingManager)&&this.snappingManager.doneSnapping(),c(this._snappingGraphicsLayer)&&(this.view.map.layers.remove(this._snappingGraphicsLayer),this._snappingGraphicsLayer.destroy()),this._editGeometryOperations=a(this._editGeometryOperations),this._snappingTask=p(this._snappingTask),this._snappingTask=null,this._snappingContext=null,this._stagedVertex=null}_resetGraphics(e){this._removeMidpointGraphics(e),this._removeVertexGraphics(e),this._set("selectedVertices",[])}_removeMidpointGraphics(e){const t=e||this.layer;t&&t.removeMany(this.midpointGraphics.items),this.midpointGraphics.items.forEach((e=>e.destroy())),this.midpointGraphics.removeAll()}_removeVertexGraphics(e){const t=e||this.layer;t&&t.removeMany(this.vertexGraphics.items),this.vertexGraphics.items.forEach((e=>e.destroy())),this.vertexGraphics.removeAll()}_getCoordinatesForUI(e){const t=u(e.clone());if("polygon"===e.type)for(const i of t){const e=i[i.length-1];i[0][0]===e[0]&&i[0][1]===e[1]&&i.length>2&&i.pop()}return t}_setupGraphics(){const e=this.graphic.geometry;if(c(e)&&("polyline"===e.type||"polygon"===e.type)){const t=this._getCoordinatesForUI(e);this.enableMidpoints&&this._setUpMidpointGraphics(t),this.enableVertices&&this._setUpVertexGraphics(t)}}_setUpMidpointGraphics(e){this._removeMidpointGraphics();const t=this._createMidpointGraphics(e);this.midpointGraphics.addMany(t),this.layer.addMany(t)}_setUpVertexGraphics(e){this._removeVertexGraphics();const t=this._createVertexGraphics(e);this.vertexGraphics.addMany(t),this._storeRelatedVertexIndices(),this.layer.addMany(t)}_createVertexGraphics(e){const{_graphicAttributes:i,symbols:s,view:{spatialReference:r}}=this,o=[];return e?.forEach(((e,n)=>{e.forEach(((e,a)=>{const[h,c]=e;o.push(new t({geometry:new H({x:h,y:c,spatialReference:r}),symbol:s?.vertices?.default,attributes:{...i,pathIndex:n,pointIndex:a}}))}))})),o}_createMidpointGraphics(e){const{_graphicAttributes:i,symbols:s,view:{spatialReference:r}}=this,o=[];return e?.forEach(((e,n)=>{e.forEach(((a,h)=>{const[c,p]=a,d=e[h+1]?h+1:0;if("polygon"===l(this.graphic.geometry,"type")||0!==d){const[a,l]=e[d],[m,v]=x([c,p],[a,l]);o.push(new t({geometry:new H({x:m,y:v,spatialReference:r}),symbol:s.midpoints.default,attributes:{...i,pathIndex:n,pointIndexStart:h,pointIndexEnd:d}}))}}))})),o}_storeRelatedVertexIndices(){const e=this.vertexGraphics.items;if(!e)return;const t=e.map((({geometry:e})=>({x:e.x,y:e.y})));for(let i=0;i<t.length;i++){const s=[];for(let e=0;e<t.length;e++){if(i===e)continue;const r=t[i],o=t[e];r.x===o.x&&r.y===o.y&&s.push(e)}e[i].attributes.relatedGraphicIndices=s}}_setupMover(){const{enableMovement:e,graphic:t,midpointGraphics:i,vertexGraphics:s,view:r}=this,o=s.concat(i).items;e&&o.push(t),this._mover=new w({enableMoveAllGraphics:!1,highlightsEnabled:!1,indicatorsEnabled:!1,graphics:o,view:r,callbacks:{onGraphicClick:e=>this._onGraphicClickCallback(e),onGraphicMoveStart:e=>this._onGraphicMoveStartCallback(e),onGraphicMove:e=>this._onGraphicMoveCallback(e),onGraphicMoveStop:e=>this._onGraphicMoveStopCallback(e),onGraphicPointerOver:e=>this._onGraphicPointerOverCallback(e),onGraphicPointerOut:e=>this._onGraphicPointerOutCallback(e)}})}_onGraphicClickCallback(e){e.viewEvent.stopPropagation();const t=e.graphic;if(t===this.graphic)this.clearSelection(),this.emit("graphic-click",e),this.callbacks.onGraphicClick&&this.callbacks.onGraphicClick(e);else if(this._isMidpoint(t)){if(2===e.viewEvent.button)return;const i=this.graphic.clone(),s=this._createVertexFromMidpoint(t);this.refresh(),this._emitVertexAddEvent([t],i,s)}else if(this._isVertex(t))if(e.viewEvent.stopPropagation(),2===e.viewEvent.button)this._removeVertices(t);else{e.viewEvent.native.shiftKey||this._clearSelection(),this.selectedVertices.includes(t)?this._removeFromSelection(t,!0):this._addToSelection(t)}}_setUpOperation(e){const{graphic:t,dx:i,dy:s}=e,r=t===this.graphic;this._resetSnappingStateVars(),this._setUpGeometryHelper(),this._saveSnappingContextForHandle(t,e),this._activeOperationInfo={target:this.graphic,mover:t,operationType:r?"move":"reshape",totalDx:i,totalDy:s}}_onGraphicMoveStartCallback(e){const t=e.graphic,{dx:i,dy:s}=e;if(t===this.graphic)return this._clearSelection(),this._resetGraphics(),this._setUpOperation(e),this._emitMoveStartEvent(i,s),void("point"===this._editGeometryOperations.data.type&&this._onHandleMove(t,i,s,e,(()=>this._emitMoveEvent(i,s))));if(!this.selectedVertices.includes(t)){if(this._clearSelection(),this._isMidpoint(t)){const e=this.graphic.clone(),i=this._createVertexFromMidpoint(t);this._emitVertexAddEvent([t],e,i)}this._addToSelection(t)}this._setUpOperation(e),this._emitReshapeStartEvent(t),this._onHandleMove(t,i,s,e,(()=>this._emitReshapeEvent(t)))}_onGraphicMoveCallback(e){const{graphic:t,dx:i,dy:s}=e;this._activeOperationInfo.totalDx+=i,this._activeOperationInfo.totalDy+=s;const{operationType:r}=this._activeOperationInfo;"move"===r?"point"===this._editGeometryOperations.data.type?this._onHandleMove(t,i,s,e,(()=>this._emitMoveEvent(i,s))):this._emitMoveEvent(i,s):this._onHandleMove(t,i,s,e,(()=>this._emitReshapeEvent(t)))}_onGraphicMoveStopCallback(e){const{graphic:t,dx:i,dy:s}=e;this._activeOperationInfo.totalDx+=i,this._activeOperationInfo.totalDy+=s,this._onHandleMove(t,i,s,e,(()=>t===this.graphic?this._emitMoveStopEvent():this._emitReshapeStopEvent(t))),this._resetSnappingStateVars(),this._activeOperationInfo=null,this._isMidpoint(t)&&this.refresh()}_updateMidpointGraphicLocations(e){for(const t of this.midpointGraphics){const{pathIndex:i,pointIndexStart:s,pointIndexEnd:r}=t.attributes,[o,n]=e[i][s],[a,h]=e[i][r],[c,p]=x([o,n],[a,h]);t.geometry=new H({x:c,y:p,spatialReference:this.view.spatialReference})}}_getIndicesForVertexGraphic({attributes:e}){return[e?.pathIndex||0,e?.pointIndex||0]}_getVertexFromEditGeometry(e){const[t,i]=this._getIndicesForVertexGraphic(e);return this._editGeometryOperations.data.components[t].vertices[i]}_onHandleMove(e,t,i,s,r){if(p(this._snappingTask),!this._snappingContext)return;const o=e.geometry,n="graphic-move-stop"===s.type;if(c(this.snappingManager)&&this.selectedVertices.length<2&&!n){const s=this.snappingManager;this._stagedVertex=s.update(o,this._snappingContext),this._syncGeometryAfterVertexMove(e,new H(this._stagedVertex),t,i,n),r(),this._snappingTask=d((async a=>{const h=await s.snap(o,this._snappingContext,a);h.valid&&(this._stagedVertex=h.apply(),this._syncGeometryAfterVertexMove(e,new H(this._stagedVertex),t,i,n),r())}))}else{const s=c(this._stagedVertex)?new H(this._stagedVertex):o;this._syncGeometryAfterVertexMove(e,s,t,i,n),r()}}async _syncGeometryAfterVertexMove(e,t,i,s,r=!1){const o=this._editGeometryOperations.data.geometry;if("point"===o.type)e.geometry=t;else{const{x:n,y:a}=t,[h,c]=this._getIndicesForVertexGraphic(e);let p=u(o);const l=p[h].length-1;p[h][c]=[n,a],"polygon"===o.type&&(0===c?p[h][l]=[n,a]:c===l&&(p[h][0]=[n,a])),this._isVertex(e)&&(p=this._moveRelatedCoordinates(p,e,n,a),p=this._moveSelectedHandleCoordinates(p,e,i,s,"polygon"===o.type),this._updateMidpointGraphicLocations(p)),this.graphic.geometry=o.clone();const d=this._getVertexFromEditGeometry(e),m=n-d.pos[0],v=a-d.pos[1];this._editGeometryOperations.moveVertices([d],m,v,0),r&&(this._mover?this._mover.updateGeometry(this._mover.graphics.indexOf(e),t):e.geometry=t)}}_moveRelatedCoordinates(e,t,i,s){const{relatedGraphicIndices:r}=t.attributes;for(const o of r){const r=this.vertexGraphics.getItemAt(o),{pathIndex:n,pointIndex:a}=r.attributes;e[n][a]=[i,s],r.geometry=t.geometry}return e}_moveSelectedHandleCoordinates(e,t,i,s,r){for(const o of this.selectedVertices)if(o!==t){const{pathIndex:t,pointIndex:n,relatedGraphicIndices:a}=o.attributes,h=M(o.geometry,i,s,this.view),c=e[t].length-1;e[t][n]=[h.x,h.y],o.geometry=h,r&&(0===n?e[t][c]=[h.x,h.y]:n===c&&(e[t][0]=[h.x,h.y]));for(const i of a){const t=this.vertexGraphics.getItemAt(i),{pathIndex:s,pointIndex:r}=t.attributes;e[s][r]=[h.x,h.y],t.geometry=h}}return e}_onGraphicPointerOverCallback(e){const t=e.graphic;this._isVertex(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.vertices.hover),this._updateHoverCursor(t)}_onGraphicPointerOutCallback(e){const t=e.graphic;this._isVertex(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.vertices.default),this.view.cursor="default"}_createVertexFromMidpoint(e){const{_graphicAttributes:t,graphic:i}=this,s=i.geometry;if(h(s)||"polygon"!==s.type&&"polyline"!==s.type)return[];const r=s.clone(),o=[],{pathIndex:n,pointIndexStart:a,pointIndexEnd:c}=e.attributes,{x:p,y:l}=e.geometry,d=0===c?a+1:c,m=u(r);return m[n].splice(d,0,[p,l]),e.attributes={...t,pathIndex:n,pointIndex:d,relatedGraphicIndices:[]},o.push({coordinates:m[n][d],componentIndex:n,vertexIndex:d}),this.graphic.geometry=r,o}_addToSelection(e){e instanceof t&&(e=[e]);for(const t of e)t.symbol=this.symbols.vertices.selected;this._set("selectedVertices",this.selectedVertices.concat(e)),this._emitSelectEvent(e)}_removeFromSelection(e,i){const{vertices:s}=this.symbols,r=i?s.hover:s.default;e instanceof t&&(e=[e]);for(const t of e)this.selectedVertices.splice(this.selectedVertices.indexOf(t),1),this._set("selectedVertices",this.selectedVertices),t.set("symbol",r);this._emitDeselectEvent(e)}_clearSelection(){if(this.selectedVertices.length){const e=this.selectedVertices;for(const t of this.selectedVertices)t.set("symbol",this.symbols.vertices.default);this._set("selectedVertices",[]),this._emitDeselectEvent(e)}}_keyDownHandler(e){O.delete.includes(e.key)&&!e.repeat&&this.selectedVertices.length&&this._removeVertices(this.selectedVertices)}_removeVertices(e){const i=this.graphic.geometry;if(h(i)||"polygon"!==i.type&&"polyline"!==i.type)return;if("polygon"===i.type&&this.vertexGraphics.length<4||this.vertexGraphics.length<3)return;e instanceof t&&(e=[e]);const s=this.graphic.clone(),r=i.clone();let o=u(r);const n=[];e instanceof t&&(e=[e]);for(const t of e){const{x:e,y:i}=t.geometry;for(let t=0;t<o.length;t++){const s=o[t];for(let r=0;r<s.length;r++){const[a,h]=s[r];e===a&&i===h&&(n.push({coordinates:o[t][r],componentIndex:t,vertexIndex:r}),o[t].splice(Number(r),1))}}}if("polygon"===r.type)o=o.filter((e=>{if(e.length<2)return!1;const[t,i]=e[0],[s,r]=e[e.length-1];return(2!==e.length||t!==s||i!==r)&&(t===s&&i===r||e.push(e[0]),!0)})),r.rings=o;else{for(const e of o)1===e.length&&o.splice(o.indexOf(e),1);r.paths=o}this.graphic.geometry=r,this.refresh(),this._emitVertexRemoveEvent(e,s,n)}_isVertex(e){return this.vertexGraphics.includes(e)}_isSelected(e){return this._isVertex(e)&&this.selectedVertices.includes(e)}_isMidpoint(e){return this.midpointGraphics.includes(e)}_updateHoverCursor(e){this.view.cursor=this._isMidpoint(e)?"copy":"move"}_emitMoveStartEvent(e,t){const i=new D(this.graphic,e,t);this.emit("move-start",i),this.callbacks.onMoveStart&&this.callbacks.onMoveStart(i)}_emitMoveEvent(e,t){const i=new F(this.graphic,e,t);this.emit("move",i),this.callbacks.onMove&&this.callbacks.onMove(i)}_emitMoveStopEvent(){const{totalDx:e,totalDy:t}=this._activeOperationInfo,i=new z(this.graphic,e,t);this.emit("move-stop",i),this.callbacks.onMoveStop&&this.callbacks.onMoveStop(i)}_emitReshapeStartEvent(e){const t=new A(this.graphic,e,this.selectedVertices);this.emit("reshape-start",t),this.callbacks.onReshapeStart&&this.callbacks.onReshapeStart(t)}_emitReshapeEvent(e){const t=new U(this.graphic,e,this.selectedVertices);this.emit("reshape",t),this.callbacks.onReshape&&this.callbacks.onReshape(t)}_emitReshapeStopEvent(e){const t=new T(this.graphic,e,this.selectedVertices);this.emit("reshape-stop",t),this.callbacks.onReshapeStop&&this.callbacks.onReshapeStop(t)}_emitSelectEvent(e){const t=new L(e);this.emit("select",t),this.callbacks.onVertexSelect&&this.callbacks.onVertexSelect(t)}_emitDeselectEvent(e){const t=new P(e);this.emit("deselect",t),this.callbacks.onVertexDeselect&&this.callbacks.onVertexDeselect(t)}_emitVertexAddEvent(e,t,i){const s=new K(e,this.graphic,t,i);this.emit("vertex-add",s),this.callbacks.onVertexAdd&&this.callbacks.onVertexAdd(s)}_emitVertexRemoveEvent(e,t,i){const s=new N(e,this.graphic,t,i);this.emit("vertex-remove",s),this.callbacks.onVertexRemove&&this.callbacks.onVertexRemove(s)}_logGeometryTypeError(){Q.error(new s("reshape:invalid-geometry","Reshape operation not supported for the provided graphic. The geometry type is not supported."))}};e([y()],W.prototype,"callbacks",void 0),e([y()],W.prototype,"enableMidpoints",void 0),e([y()],W.prototype,"enableMovement",void 0),e([y()],W.prototype,"enableVertices",void 0),e([y()],W.prototype,"graphic",void 0),e([y({value:!0})],W.prototype,"highlightsEnabled",null),e([y()],W.prototype,"layer",void 0),e([y({readOnly:!0})],W.prototype,"midpointGraphics",void 0),e([y()],W.prototype,"midpointSymbol",void 0),e([y({readOnly:!0})],W.prototype,"selectedVertices",void 0),e([y()],W.prototype,"snappingManager",void 0),e([y({readOnly:!0})],W.prototype,"state",null),e([y({value:B})],W.prototype,"symbols",null),e([y({readOnly:!0})],W.prototype,"type",void 0),e([y({readOnly:!0})],W.prototype,"vertexGraphics",void 0),e([y()],W.prototype,"view",void 0),W=e([_(J)],W);const X=W;export{X as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../Graphic.js";import i from"../../../core/Collection.js";import s from"../../../core/Error.js";import r from"../../../core/Evented.js";import o from"../../../core/Handles.js";import n from"../../../core/Logger.js";import{destroyMaybe as a,isNone as h,isSome as c,abortMaybe as p,get as l}from"../../../core/maybe.js";import{createTask as d}from"../../../core/promiseUtils.js";import{when as m,pausable as v}from"../../../core/reactiveUtils.js";import{property as y}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{closeRingsAndFixWinding as g,geometryToCoordinates as u,getMidpoint as x}from"../../../geometry/support/coordsUtils.js";import f from"../../../layers/GraphicsLayer.js";import G from"../../../symbols/SimpleMarkerSymbol.js";import{ViewingMode as b}from"../../ViewingMode.js";import{SnappingVisualizer2D as V}from"../../2d/interactive/SnappingVisualizer2D.js";import{cloneMove as M}from"./drawUtils.js";import w from"./GraphicMover.js";import S from"./HighlightHelper.js";import{addUniqueLayer as k}from"./layerUtils.js";import{settings as E}from"./settings.js";import{ViewEventPriorities as I}from"../../input/InputManager.js";import{SKETCH_KEYS as O}from"../../interactive/keybindings.js";import{EditGeometryOperations as C}from"../../interactive/editGeometry/EditGeometryOperations.js";import{SnappingContext as R}from"../../interactive/snapping/SnappingContext.js";import j from"../../../geometry/Polyline.js";import H from"../../../geometry/Point.js";class A{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape-start"}}class U{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape"}}class T{constructor(e,t,i){this.graphic=e,this.mover=t,this.selected=i,this.type="reshape-stop"}}class D{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move-start"}}class F{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move"}}class z{constructor(e,t,i){this.mover=e,this.dx=t,this.dy=i,this.type="move-stop"}}class L{constructor(e){this.added=e,this.type="vertex-select"}}class P{constructor(e){this.removed=e,this.type="vertex-deselect"}}class K{constructor(e,t,i,s){this.added=e,this.graphic=t,this.oldGraphic=i,this.vertices=s,this.type="vertex-add"}}class N{constructor(e,t,i,s){this.removed=e,this.graphic=t,this.oldGraphic=i,this.vertices=s,this.type="vertex-remove"}}const q=E.reshapeGraphics,B={vertices:{default:new G({style:"circle",size:q.vertex.size,color:q.vertex.color,outline:{color:q.vertex.outlineColor,width:1}}),hover:new G({style:"circle",size:q.vertex.hoverSize,color:q.vertex.hoverColor,outline:{color:q.vertex.hoverOutlineColor,width:1}}),selected:new G({style:"circle",size:q.selected.size,color:q.selected.color,outline:{color:q.selected.outlineColor,width:1}})},midpoints:{default:new G({style:"circle",size:q.midpoint.size,color:q.midpoint.color,outline:{color:q.midpoint.outlineColor,width:1}}),hover:new G({style:"circle",size:q.midpoint.size,color:q.midpoint.color,outline:{color:q.midpoint.outlineColor,width:1}})}},J="esri.views.draw.support.Reshape",Q=n.getLogger(J);let W=class extends r.EventedAccessor{constructor(e){super(e),this._activeOperationInfo=null,this._editGeometryOperations=null,this._handles=new o,this._graphicAttributes={esriSketchTool:"box"},this._mover=null,this._snappingTask=null,this._stagedVertex=null,this._viewHandles=new o,this.callbacks={onReshapeStart(){},onReshape(){},onReshapeStop(){},onMoveStart(){},onMove(){},onMoveStop(){},onGraphicClick(){}},this.enableMidpoints=!0,this.enableMovement=!0,this.enableVertices=!0,this.graphic=null,this.layer=null,this.midpointGraphics=new i,this.midpointSymbol=new G({style:"circle",size:6,color:[200,200,200],outline:{color:[100,100,100],width:1}}),this.selectedVertices=[],this.snappingManager=null,this.type="reshape",this.vertexGraphics=new i,this.view=null}initialize(){this._highlightHelper=new S({view:this.view}),this._setup(),this._handles.add([m((()=>this.view?.ready),(()=>{const{layer:e,view:t}=this;k(t,e),this._viewHandles.add(t.on("key-down",(e=>this._keyDownHandler(e)),I.TOOL))}),{once:!0,initial:!0}),v((()=>this.graphic),(()=>this.refresh())),v((()=>this.layer),((e,t)=>{t&&(this._clearSelection(),this._resetGraphics(t)),this.refresh()})),v((()=>this.enableMidpoints),(()=>this.refresh()))])}destroy(){this._reset(),this._mover?.destroy(),this._mover=null,this._handles=a(this._handles),this._viewHandles=a(this._viewHandles)}set highlightsEnabled(e){this._highlightHelper?.removeAll(),this._set("highlightsEnabled",e),this._setUpHighlights()}get state(){const e=!!this.get("view.ready"),t=!(!this.get("graphic")||!this.get("layer"));return e&&t?"active":e?"ready":"disabled"}set symbols(e){const{midpoints:t=B.midpoints,vertices:i=B.vertices}=e||{};this._set("symbols",{midpoints:t,vertices:i})}isUIGraphic(e){const t=[];return this.graphic&&t.push(this.graphic),t.concat(this.vertexGraphics.items,this.midpointGraphics.items),t.length&&t.includes(e)}refresh(){this._reset(),this._setup()}reset(){this.graphic=null}clearSelection(){this._clearSelection()}removeSelectedVertices(){this.selectedVertices.length&&this._removeVertices(this.selectedVertices)}_setup(){const{graphic:e,layer:t}=this;if(!t||!e||h(e.geometry))return;const i=e.geometry;"mesh"!==i.type&&"extent"!==i.type?("polygon"===i.type&&g(i),this._setUpHighlights(),this._setupGraphics(),this._setupMover()):this._logGeometryTypeError()}_setUpHighlights(){this.highlightsEnabled&&this.graphic&&this._highlightHelper.add(this.graphic)}_setUpGeometryHelper(){const e=this.graphic.geometry;if(h(e)||"mesh"===e.type||"extent"===e.type)return void this._logGeometryTypeError();const t="multipoint"===e.type?new j({paths:e.points,spatialReference:e.spatialReference}):e;this._editGeometryOperations=C.fromGeometry(t,b.Local)}_saveSnappingContextForHandle(e,t){this._snappingGraphicsLayer=new f({listMode:"hide",internal:!0,title:"Reshape snapping layer"}),this.view.map.layers.add(this._snappingGraphicsLayer),this._snappingContext=new R({editGeometryOperations:this._editGeometryOperations,elevationInfo:{mode:"on-the-ground",offset:0},pointer:t.viewEvent?.pointerType||"mouse",excludeFeature:this.graphic,visualizer:new V(this._snappingGraphicsLayer),vertexHandle:this._getVertexFromEditGeometry(e)})}_reset(){this._clearSelection(),this._highlightHelper.removeAll(),this._resetGraphics(),this._resetSnappingStateVars(),this._activeOperationInfo=null,this._mover&&this._mover.destroy(),this._mover=null,this.view.cursor="default"}_resetSnappingStateVars(){c(this.snappingManager)&&this.snappingManager.doneSnapping(),c(this._snappingGraphicsLayer)&&(this.view.map.layers.remove(this._snappingGraphicsLayer),this._snappingGraphicsLayer.destroy()),this._editGeometryOperations=a(this._editGeometryOperations),this._snappingTask=p(this._snappingTask),this._snappingTask=null,this._snappingContext=null,this._stagedVertex=null}_resetGraphics(e){this._removeMidpointGraphics(e),this._removeVertexGraphics(e),this._set("selectedVertices",[])}_removeMidpointGraphics(e){const t=e||this.layer;t&&t.removeMany(this.midpointGraphics.items),this.midpointGraphics.items.forEach((e=>e.destroy())),this.midpointGraphics.removeAll()}_removeVertexGraphics(e){const t=e||this.layer;t&&t.removeMany(this.vertexGraphics.items),this.vertexGraphics.items.forEach((e=>e.destroy())),this.vertexGraphics.removeAll()}_getCoordinatesForUI(e){const t=u(e.clone());if("polygon"===e.type)for(const i of t){const e=i[i.length-1];i[0][0]===e[0]&&i[0][1]===e[1]&&i.length>2&&i.pop()}return t}_setupGraphics(){const e=this.graphic.geometry;if(c(e)&&("polyline"===e.type||"polygon"===e.type)){const t=this._getCoordinatesForUI(e);this.enableMidpoints&&this._setUpMidpointGraphics(t),this.enableVertices&&this._setUpVertexGraphics(t)}}_setUpMidpointGraphics(e){this._removeMidpointGraphics();const t=this._createMidpointGraphics(e);this.midpointGraphics.addMany(t),this.layer.addMany(t)}_setUpVertexGraphics(e){this._removeVertexGraphics();const t=this._createVertexGraphics(e);this.vertexGraphics.addMany(t),this._storeRelatedVertexIndices(),this.layer.addMany(t)}_createVertexGraphics(e){const{_graphicAttributes:i,symbols:s,view:{spatialReference:r}}=this,o=[];return e?.forEach(((e,n)=>{e.forEach(((e,a)=>{const[h,c]=e;o.push(new t({geometry:new H({x:h,y:c,spatialReference:r}),symbol:s?.vertices?.default,attributes:{...i,pathIndex:n,pointIndex:a}}))}))})),o}_createMidpointGraphics(e){const{_graphicAttributes:i,symbols:s,view:{spatialReference:r}}=this,o=[];return e?.forEach(((e,n)=>{e.forEach(((a,h)=>{const[c,p]=a,d=e[h+1]?h+1:0;if("polygon"===l(this.graphic.geometry,"type")||0!==d){const[a,l]=e[d],[m,v]=x([c,p],[a,l]);o.push(new t({geometry:new H({x:m,y:v,spatialReference:r}),symbol:s.midpoints.default,attributes:{...i,pathIndex:n,pointIndexStart:h,pointIndexEnd:d}}))}}))})),o}_storeRelatedVertexIndices(){const e=this.vertexGraphics.items;if(!e)return;const t=e.map((({geometry:e})=>({x:e.x,y:e.y})));for(let i=0;i<t.length;i++){const s=[];for(let e=0;e<t.length;e++){if(i===e)continue;const r=t[i],o=t[e];r.x===o.x&&r.y===o.y&&s.push(e)}e[i].attributes.relatedGraphicIndices=s}}_setupMover(){const{enableMovement:e,graphic:t,midpointGraphics:i,vertexGraphics:s,view:r}=this,o=s.concat(i).items;e&&o.push(t),this._mover=new w({enableMoveAllGraphics:!1,highlightsEnabled:!1,indicatorsEnabled:!1,graphics:o,view:r,callbacks:{onGraphicClick:e=>this._onGraphicClickCallback(e),onGraphicMoveStart:e=>this._onGraphicMoveStartCallback(e),onGraphicMove:e=>this._onGraphicMoveCallback(e),onGraphicMoveStop:e=>this._onGraphicMoveStopCallback(e),onGraphicPointerOver:e=>this._onGraphicPointerOverCallback(e),onGraphicPointerOut:e=>this._onGraphicPointerOutCallback(e)}})}_onGraphicClickCallback(e){e.viewEvent.stopPropagation();const t=e.graphic;if(t===this.graphic)this.clearSelection(),this.emit("graphic-click",e),this.callbacks.onGraphicClick&&this.callbacks.onGraphicClick(e);else if(this._isMidpoint(t)){if(2===e.viewEvent.button)return;const i=this.graphic.clone(),s=this._createVertexFromMidpoint(t);this.refresh(),this._emitVertexAddEvent([t],i,s)}else if(this._isVertex(t))if(e.viewEvent.stopPropagation(),2===e.viewEvent.button)this._removeVertices(t);else{e.viewEvent.native.shiftKey||this._clearSelection(),this.selectedVertices.includes(t)?this._removeFromSelection(t,!0):this._addToSelection(t)}}_setUpOperation(e){const{graphic:t,dx:i,dy:s}=e,r=t===this.graphic;this._resetSnappingStateVars(),this._setUpGeometryHelper(),this._saveSnappingContextForHandle(t,e),this._activeOperationInfo={target:this.graphic,mover:t,operationType:r?"move":"reshape",totalDx:i,totalDy:s}}_onGraphicMoveStartCallback(e){const t=e.graphic,{dx:i,dy:s}=e;if(t===this.graphic)return this._clearSelection(),this._resetGraphics(),this._setUpOperation(e),this._emitMoveStartEvent(i,s),void("point"===this._editGeometryOperations.data.type&&this._onHandleMove(t,i,s,e,(()=>this._emitMoveEvent(i,s))));if(!this.selectedVertices.includes(t)){if(this._clearSelection(),this._isMidpoint(t)){const e=this.graphic.clone(),i=this._createVertexFromMidpoint(t);this._emitVertexAddEvent([t],e,i)}this._addToSelection(t)}this._setUpOperation(e),this._emitReshapeStartEvent(t),this._onHandleMove(t,i,s,e,(()=>this._emitReshapeEvent(t)))}_onGraphicMoveCallback(e){const{graphic:t,dx:i,dy:s}=e;this._activeOperationInfo.totalDx+=i,this._activeOperationInfo.totalDy+=s;const{operationType:r}=this._activeOperationInfo;"move"===r?"point"===this._editGeometryOperations.data.type?this._onHandleMove(t,i,s,e,(()=>this._emitMoveEvent(i,s))):this._emitMoveEvent(i,s):this._onHandleMove(t,i,s,e,(()=>this._emitReshapeEvent(t)))}_onGraphicMoveStopCallback(e){const{graphic:t,dx:i,dy:s}=e,r=t===this.graphic,o="point"!==this._editGeometryOperations.data.type;this._activeOperationInfo.totalDx+=i,this._activeOperationInfo.totalDy+=s,this._onHandleMove(t,i,s,e,(()=>r?this._emitMoveStopEvent():this._emitReshapeStopEvent(t))),r&&o||this._isMidpoint(t)?this.refresh():(this._resetSnappingStateVars(),this._activeOperationInfo=null)}_updateMidpointGraphicLocations(e){for(const t of this.midpointGraphics){const{pathIndex:i,pointIndexStart:s,pointIndexEnd:r}=t.attributes,[o,n]=e[i][s],[a,h]=e[i][r],[c,p]=x([o,n],[a,h]);t.geometry=new H({x:c,y:p,spatialReference:this.view.spatialReference})}}_getIndicesForVertexGraphic({attributes:e}){return[e?.pathIndex||0,e?.pointIndex||0]}_getVertexFromEditGeometry(e){const[t,i]=this._getIndicesForVertexGraphic(e);return this._editGeometryOperations.data.components[t].vertices[i]}_onHandleMove(e,t,i,s,r){if(p(this._snappingTask),!this._snappingContext)return;const o=e.geometry,n="graphic-move-stop"===s.type;if(c(this.snappingManager)&&this.selectedVertices.length<2&&!n){const s=this.snappingManager;this._stagedVertex=s.update(o,this._snappingContext),this._syncGeometryAfterVertexMove(e,new H(this._stagedVertex),t,i,n),r(),this._snappingTask=d((async a=>{const h=await s.snap(o,this._snappingContext,a);h.valid&&(this._stagedVertex=h.apply(),this._syncGeometryAfterVertexMove(e,new H(this._stagedVertex),t,i,n),r())}))}else{const s=c(this._stagedVertex)?new H(this._stagedVertex):o;this._syncGeometryAfterVertexMove(e,s,t,i,n),r()}}async _syncGeometryAfterVertexMove(e,t,i,s,r=!1){const o=this._editGeometryOperations.data.geometry;if("point"===o.type)e.geometry=t;else{const{x:n,y:a}=t,[h,c]=this._getIndicesForVertexGraphic(e);let p=u(o);const l=p[h].length-1;p[h][c]=[n,a],"polygon"===o.type&&(0===c?p[h][l]=[n,a]:c===l&&(p[h][0]=[n,a])),this._isVertex(e)&&(p=this._moveRelatedCoordinates(p,e,n,a),p=this._moveSelectedHandleCoordinates(p,e,i,s,"polygon"===o.type),this._updateMidpointGraphicLocations(p)),this.graphic.geometry=o.clone();const d=this._getVertexFromEditGeometry(e),m=n-d.pos[0],v=a-d.pos[1];this._editGeometryOperations.moveVertices([d],m,v,0),r&&(this._mover?this._mover.updateGeometry(this._mover.graphics.indexOf(e),t):e.geometry=t)}}_moveRelatedCoordinates(e,t,i,s){const{relatedGraphicIndices:r}=t.attributes;for(const o of r){const r=this.vertexGraphics.getItemAt(o),{pathIndex:n,pointIndex:a}=r.attributes;e[n][a]=[i,s],r.geometry=t.geometry}return e}_moveSelectedHandleCoordinates(e,t,i,s,r){for(const o of this.selectedVertices)if(o!==t){const{pathIndex:t,pointIndex:n,relatedGraphicIndices:a}=o.attributes,h=M(o.geometry,i,s,this.view),c=e[t].length-1;e[t][n]=[h.x,h.y],o.geometry=h,r&&(0===n?e[t][c]=[h.x,h.y]:n===c&&(e[t][0]=[h.x,h.y]));for(const i of a){const t=this.vertexGraphics.getItemAt(i),{pathIndex:s,pointIndex:r}=t.attributes;e[s][r]=[h.x,h.y],t.geometry=h}}return e}_onGraphicPointerOverCallback(e){const t=e.graphic;this._isVertex(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.vertices.hover),this._updateHoverCursor(t)}_onGraphicPointerOutCallback(e){const t=e.graphic;this._isVertex(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.vertices.default),this.view.cursor="default"}_createVertexFromMidpoint(e){const{_graphicAttributes:t,graphic:i}=this,s=i.geometry;if(h(s)||"polygon"!==s.type&&"polyline"!==s.type)return[];const r=s.clone(),o=[],{pathIndex:n,pointIndexStart:a,pointIndexEnd:c}=e.attributes,{x:p,y:l}=e.geometry,d=0===c?a+1:c,m=u(r);return m[n].splice(d,0,[p,l]),e.attributes={...t,pathIndex:n,pointIndex:d,relatedGraphicIndices:[]},o.push({coordinates:m[n][d],componentIndex:n,vertexIndex:d}),this.graphic.geometry=r,o}_addToSelection(e){e instanceof t&&(e=[e]);for(const t of e)t.symbol=this.symbols.vertices.selected;this._set("selectedVertices",this.selectedVertices.concat(e)),this._emitSelectEvent(e)}_removeFromSelection(e,i){const{vertices:s}=this.symbols,r=i?s.hover:s.default;e instanceof t&&(e=[e]);for(const t of e)this.selectedVertices.splice(this.selectedVertices.indexOf(t),1),this._set("selectedVertices",this.selectedVertices),t.set("symbol",r);this._emitDeselectEvent(e)}_clearSelection(){if(this.selectedVertices.length){const e=this.selectedVertices;for(const t of this.selectedVertices)t.set("symbol",this.symbols.vertices.default);this._set("selectedVertices",[]),this._emitDeselectEvent(e)}}_keyDownHandler(e){O.delete.includes(e.key)&&!e.repeat&&this.selectedVertices.length&&this._removeVertices(this.selectedVertices)}_removeVertices(e){const i=this.graphic.geometry;if(h(i)||"polygon"!==i.type&&"polyline"!==i.type)return;if("polygon"===i.type&&this.vertexGraphics.length<4||this.vertexGraphics.length<3)return;e instanceof t&&(e=[e]);const s=this.graphic.clone(),r=i.clone();let o=u(r);const n=[];e instanceof t&&(e=[e]);for(const t of e){const{x:e,y:i}=t.geometry;for(let t=0;t<o.length;t++){const s=o[t];for(let r=0;r<s.length;r++){const[a,h]=s[r];e===a&&i===h&&(n.push({coordinates:o[t][r],componentIndex:t,vertexIndex:r}),o[t].splice(Number(r),1))}}}if("polygon"===r.type)o=o.filter((e=>{if(e.length<2)return!1;const[t,i]=e[0],[s,r]=e[e.length-1];return(2!==e.length||t!==s||i!==r)&&(t===s&&i===r||e.push(e[0]),!0)})),r.rings=o;else{for(const e of o)1===e.length&&o.splice(o.indexOf(e),1);r.paths=o}this.graphic.geometry=r,this.refresh(),this._emitVertexRemoveEvent(e,s,n)}_isVertex(e){return this.vertexGraphics.includes(e)}_isSelected(e){return this._isVertex(e)&&this.selectedVertices.includes(e)}_isMidpoint(e){return this.midpointGraphics.includes(e)}_updateHoverCursor(e){this.view.cursor=this._isMidpoint(e)?"copy":"move"}_emitMoveStartEvent(e,t){const i=new D(this.graphic,e,t);this.emit("move-start",i),this.callbacks.onMoveStart&&this.callbacks.onMoveStart(i)}_emitMoveEvent(e,t){const i=new F(this.graphic,e,t);this.emit("move",i),this.callbacks.onMove&&this.callbacks.onMove(i)}_emitMoveStopEvent(){const{totalDx:e,totalDy:t}=this._activeOperationInfo,i=new z(this.graphic,e,t);this.emit("move-stop",i),this.callbacks.onMoveStop&&this.callbacks.onMoveStop(i)}_emitReshapeStartEvent(e){const t=new A(this.graphic,e,this.selectedVertices);this.emit("reshape-start",t),this.callbacks.onReshapeStart&&this.callbacks.onReshapeStart(t)}_emitReshapeEvent(e){const t=new U(this.graphic,e,this.selectedVertices);this.emit("reshape",t),this.callbacks.onReshape&&this.callbacks.onReshape(t)}_emitReshapeStopEvent(e){const t=new T(this.graphic,e,this.selectedVertices);this.emit("reshape-stop",t),this.callbacks.onReshapeStop&&this.callbacks.onReshapeStop(t)}_emitSelectEvent(e){const t=new L(e);this.emit("select",t),this.callbacks.onVertexSelect&&this.callbacks.onVertexSelect(t)}_emitDeselectEvent(e){const t=new P(e);this.emit("deselect",t),this.callbacks.onVertexDeselect&&this.callbacks.onVertexDeselect(t)}_emitVertexAddEvent(e,t,i){const s=new K(e,this.graphic,t,i);this.emit("vertex-add",s),this.callbacks.onVertexAdd&&this.callbacks.onVertexAdd(s)}_emitVertexRemoveEvent(e,t,i){const s=new N(e,this.graphic,t,i);this.emit("vertex-remove",s),this.callbacks.onVertexRemove&&this.callbacks.onVertexRemove(s)}_logGeometryTypeError(){Q.error(new s("reshape:invalid-geometry","Reshape operation not supported for the provided graphic. The geometry type is not supported."))}};e([y()],W.prototype,"callbacks",void 0),e([y()],W.prototype,"enableMidpoints",void 0),e([y()],W.prototype,"enableMovement",void 0),e([y()],W.prototype,"enableVertices",void 0),e([y()],W.prototype,"graphic",void 0),e([y({value:!0})],W.prototype,"highlightsEnabled",null),e([y()],W.prototype,"layer",void 0),e([y({readOnly:!0})],W.prototype,"midpointGraphics",void 0),e([y()],W.prototype,"midpointSymbol",void 0),e([y({readOnly:!0})],W.prototype,"selectedVertices",void 0),e([y()],W.prototype,"snappingManager",void 0),e([y({readOnly:!0})],W.prototype,"state",null),e([y({value:B})],W.prototype,"symbols",null),e([y({readOnly:!0})],W.prototype,"type",void 0),e([y({readOnly:!0})],W.prototype,"vertexGraphics",void 0),e([y()],W.prototype,"view",void 0),W=e([_(J)],W);const X=W;export{X as default};