@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 46.5 kB
JavaScript
import{_ as t}from"../../chunks/tslib.es6.js";import{symbolTypes as e}from"../../symbols.js";import o from"../../core/Collection.js";import i from"../../core/Error.js";import a from"../../core/Evented.js";import r from"../../core/Handles.js";import s from"../../core/Logger.js";import{destroyMaybe as n,isSome as p,unwrap as l,abortMaybe as h,isNone as c,unwrapOr as d,get as u}from"../../core/maybe.js";import{createAbortError as y,whenOrAbort as m}from"../../core/promiseUtils.js";import{on as v,watch as g,when as f,whenOnce as _,syncAndInitial as w}from"../../core/reactiveUtils.js";import{property as G}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import{subclass as b}from"../../core/accessorSupport/decorators/subclass.js";import{getReferenceEllipsoid as T}from"../../geometry/ellipsoidUtils.js";import{canProjectWithoutEngine as O,isLoaded as E,load as S,project as A}from"../../geometry/projection.js";import{geometryToCoordinates as C}from"../../geometry/support/coordsUtils.js";import{equals as k}from"../../geometry/support/spatialReferenceUtils.js";import M from"../../layers/GraphicsLayer.js";import{SupportedGraphicResult as H,isSupportedGraphicResultMessage as R}from"../../views/3d/interactive/editingTools/isSupportedGraphicUtils.js";import{isSupportedGraphic as I}from"../../views/3d/interactive/editingTools/moveGraphic/isSupportedGraphic.js";import{isSupportedGraphic as D}from"../../views/3d/interactive/editingTools/reshapeGraphic/isSupportedGraphic.js";import{isSupportedGraphic as U}from"../../views/3d/interactive/editingTools/transformGraphic/isSupportedGraphic.js";import{addUniqueLayer as x}from"../../views/draw/support/layerUtils.js";import{ViewEventPriorities as P}from"../../views/input/InputManager.js";import{SKETCH_KEYS as j}from"../../views/interactive/keybindings.js";import L from"../../views/interactive/sketch/SketchLabelOptions.js";import F from"../../views/interactive/sketch/SketchTooltipOptions.js";import{SnappingManager as V}from"../../views/interactive/snapping/SnappingManager.js";import W from"../../views/interactive/snapping/SnappingOptions.js";import{setupSnappingToggleHandles as K}from"../../views/interactive/snapping/snappingUtils.js";import{findFirstGraphicHit as q}from"../../views/support/hitTestSelectUtils.js";import{createScreenPointFromEvent as Z}from"../../views/support/screenUtils.js";import{CreateOperationHandle as z,UpdateOperationHandle as N}from"./support/OperationHandle.js";import B from"../../symbols/SimpleMarkerSymbol.js";import $ from"../../symbols/SimpleFillSymbol.js";import Y from"../../symbols/SimpleLineSymbol.js";const J={defaultZ:0},Q={reshapeOptions:{edgeOperation:"split",shapeOperation:"move",vertexOperation:"move"},enableMoveAllGraphics:!0,enableRotation:!0,enableScaling:!0,multipleSelectionEnabled:!0,preserveAspectRatio:!1,toggleToolOnClick:!0,enableZ:!0,tool:"transform"};let X=class extends a.EventedAccessor{constructor(t){super(t),this._numUpdating=0,this._handles=new r,this._internalGraphicsLayer=new M({listMode:"hide",internal:!0,title:"SVM Internal"}),this._operationHandle=null,this._viewHandles=new r,this.activeFillSymbol=null,this.activeLineSymbol=null,this.activeVertexSymbol=null,this.allowDeleteKey=!0,this.labelOptions=new L,this.layer=null,this.pointSymbol=new B({style:"circle",size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this.polygonSymbol=new $({color:[150,150,150,.2],outline:{color:[50,50,50],width:2}}),this.polylineSymbol=new Y({color:[130,130,130,1],width:2}),this._snappingManager=null,this.tooltipOptions=new F,this.updateGraphics=new o,this.updateOnGraphicClick=!0,this.updatePointSymbol=new B({size:10,color:[0,200,255,.5],outline:{color:"black",width:1}}),this.updatePolygonSymbol=new $({color:[12,207,255,.2],outline:{join:"round",color:[12,207,255],width:2}}),this.updatePolylineSymbol=new Y({color:[12,207,255],width:2}),this.vertexSymbol=new B({style:"circle",size:6,color:[255,255,255],outline:{color:[50,50,50],width:1}}),this._moduleLoaderAbortController=null,this._viewReadyAbortController=null,this._originalAutoOpenEnabled=null,this.defaultCreateOptions=J,this.defaultUpdateOptions=Q,this.snappingOptions=new W}initialize(){this._handles.add([v((()=>this.view?.map?.layers),"change",(t=>{t.removed.includes(this.layer)&&this.cancel()})),v((()=>this.layer?.graphics),"change",(t=>{if(p(this._operationHandle))for(const e of t.removed)this.updateGraphics.includes(e)&&(this.updateGraphics.length>1?this._operationHandle.removeFromSelection(e):this._operationHandle.cancel())})),g((()=>this.layer?.elevationInfo??null),(t=>{t!==this._internalGraphicsLayer.elevationInfo&&(this.cancel(),this._internalGraphicsLayer.elevationInfo=t)}),w),g((()=>this.view),(t=>{n(this._snappingManager),t&&(this._snappingManager=new V({view:t,options:this.snappingOptions}),"2d"===t.type?import("../../views/2d/interactive/editingTools.js"):"3d"===t.type&&(import("../../views/3d/interactive/editingTools.js"),import("../../views/3d/layers/GraphicsLayerView3D.js")))}),w),g((()=>this.view?.spatialReference),((t,e)=>{t&&e&&!t.equals(e)&&this.cancel()}))]),K(this)}destroy(){this.cancel(),this._handles=n(this._handles),this._viewHandles=n(this._viewHandles),this._removeDefaultLayer(),this._snappingManager=n(this._snappingManager),this._set("view",null),this.emit("destroy")}get _defaultUpdateTool(){return"3d"===this.view?.type?"move":"transform"}get updating(){return this._numUpdating>0||p(this._snappingManager)&&this._snappingManager.updating}get activeTool(){return this._operationHandle?.tool??null}get activeComponent(){return this._operationHandle?.activeComponent??null}get createGraphic(){return!p(this.activeComponent)||"draw-3d"!==this.activeComponent.type&&"draw-2d"!==this.activeComponent.type?this._get("createGraphic"):l(this.activeComponent.graphic)}get defaultCreateOptions(){return this._get("defaultCreateOptions")}set defaultCreateOptions(t){this._set("defaultCreateOptions",{...J,...t})}get defaultUpdateOptions(){return this._get("defaultUpdateOptions")}set defaultUpdateOptions(t){this._set("defaultUpdateOptions",{...Q,...t,reshapeOptions:{...Q.reshapeOptions,...t?.reshapeOptions}})}set snappingOptions(t){p(this._snappingManager)&&(this._snappingManager.options=t),this._set("snappingOptions",t)}get state(){const t=!(!this.view?.ready||!this.layer),e=this._operationHandle;return t&&e?"active":t?"ready":"disabled"}get view(){return this._get("view")}set view(t){const e=this._get("view");if(e){const{container:t,map:o}=e;t&&(e.cursor=null),o&&o.remove(this._internalGraphicsLayer),this._viewHandles.removeAll(),this.cancel()}const o="view-ready";this._handles.remove(o),t&&this._handles.add(f((()=>t.ready),(e=>{this._viewHandles.removeAll(),e&&this._viewHandles.add(this._generateViewHandles(t))}),w),o),this._set("view",t)}cancel(){this._moduleLoaderAbortController=h(this._moduleLoaderAbortController),this._viewReadyAbortController=h(this._viewReadyAbortController),this._operationHandle&&this._operationHandle.cancel()}complete(){this._operationHandle&&this._operationHandle.complete()}delete(){const{state:t,updateGraphics:e}=this;if("active"===t&&e.length){const{activeTool:t,layer:o}=this,i=e.toArray();o.removeMany(i),this.cancel(),this._emitDeleteEvent({graphics:i,tool:t})}}duplicate(){if("active"===this.state&&this.updateGraphics.length){const t=this.updateGraphics.map((t=>t.clone())).toArray();return this.layer.addMany(t),this.emit("duplicate",{graphics:t,type:"duplicate"}),t}return[]}async create(t,e){this.cancel(),await this._waitViewReady();const{view:o,layer:i}=this;if(!o||"disabled"===this.state)throw i||this._logMissingLayer(),y();if(p(o.activeTool)&&(o.activeTool=null),!t)return void this._logError("sketch:missing-parameter","Missing parameter 'tool'.");x(o,this._internalGraphicsLayer);const a=await this._setupCreateOperation(t,e);if(c(a)||this.destroyed)return void o.map.remove(this._internalGraphicsLayer);const r=()=>{if(a===this._operationHandle){const e=this.createGraphic,o=this._operationHandle.cancelled;this._operationHandle.destroy(),this._operationHandle=null,this._set("createGraphic",null),this.view&&this.view.map&&this.view.map.remove(this._internalGraphicsLayer),a.cancelled||null==e||i.add(e),this.emit("create",{graphic:e,state:o?"cancel":"complete",tool:t,toolEventInfo:null,type:"create"})}};a.on("complete",r),this._operationHandle=a,o.ready&&o.focus()}async update(t,e){this.cancel(),await this._waitViewReady();const{layer:o,view:i,state:a}=this;if(!i||"disabled"===a)throw o||this._logMissingLayer(),y();p(i.activeTool)&&(i.activeTool=null);const r=Array.isArray(t)?t:[t];if(null==t||!r||!r.length)return void this._logError("sketch:missing-parameter","Missing parameter 'graphics'.");if(r.some((t=>t.layer!==o?(this._logError("sketch:invalid-parameter","Parameter 'graphics' contains one or more graphics missing from the supplied GraphicsLayer."),!0):!!c(t.geometry)&&(this._logError("sketch:invalid-parameter","Parameter 'graphics' contains one or more graphics with an unsupported geometry."),!0))))return;const s=await this._setupUpdateOperation(r,e);this.destroyed||c(s)||nt(s)||(x(i,this._internalGraphicsLayer),this._setUpdateOperationHandle(s,e),this.emit("update",{graphics:r,state:"start",aborted:!1,tool:s.tool,toolEventInfo:null,type:"update"}))}async _updateSpatialReference(t){const e=this.view;if(e){this._beginAsyncOperation(),t=Array.isArray(t)?t:[t];for(const o of t)p(o.geometry)&&"mesh"!==o.geometry.type&&!k(o.geometry.spatialReference,e.spatialReference)&&(O(o.geometry.spatialReference,e.spatialReference)||E()||await S(),o.geometry=A(o.geometry,e.spatialReference));this._endAsyncOperation()}else this._logMissingView()}undo(){this.canUndo()&&this._operationHandle?.undo()}redo(){this.canRedo()&&this._operationHandle?.redo()}canUndo(){return!(!this._operationHandle||!this._operationHandle.canUndo())}canRedo(){return!(!this._operationHandle||!this._operationHandle.canRedo())}toggleUpdateTool(){this._operationHandle&&this._operationHandle.toggleTool&&this._operationHandle.toggleTool()}async _getFirstHit(t){const e=this.view;if(!e)return this._logMissingView(),null;if("2d"===e.type){const o=[];e.map.allLayers.forEach((t=>{"vector-tile"!==t.type&&"imagery"!==t.type||o.push(t)}));const i=await e.hitTest(t,{exclude:o});return q(i.results)}const o=[e.map.ground];e.map.allLayers.forEach((t=>{"integrated-mesh"===t.type&&o.push(t)}));const i=await e.hitTest(t,{exclude:o});if(i.results.length>0){const t=i.results[0];if(p(t)&&"graphic"===t.type&&t.graphic&&(!i.ground.mapPoint||e.map.ground.opacity<1||i.ground.distance-d(t.distance,0)>-Math.min(3*i.ground.distance,"global"===e.viewingMode?T(e.renderCoordsHelper.spatialReference).radius/e.renderCoordsHelper.unitInMeters:Number.POSITIVE_INFINITY)))return t}return null}_generateViewHandles(t){return[t.on("immediate-click",(async e=>{const o="active"===this.state&&"create"===this._operationHandle?.type;if("disabled"===this.state||o||!this.updateOnGraphicClick)return;this._beginAsyncOperation();const i=await e.async((()=>this._getFirstHit(Z(e))));let a=null;if(p(i)){const o=i.graphic;this.updateGraphics.includes(o)||o.layer===this.layer?(e.stopPropagation(),a=o):"2d"!==t.type||this._isComponentGraphic(o)||"active"!==this.state||this.cancel()}else"active"===this.state&&this.cancel();p(a)&&!this.updateGraphics.includes(a)&&await this.update([a],{...this.defaultUpdateOptions,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions}}),this._endAsyncOperation()}),P.WIDGET)]}async _setupCreateOperation(t,e){const o=this.view;if(!o)return this._logMissingView(),null;const i={hasZ:"3d"===o.type,...this.defaultCreateOptions,...e},a=await this._setupDrawGraphicTool(t,o,i);return c(a)?null:(o.tools.add(a),o.activeTool=a,this._setupCreateOperationHandle(a))}async _setupDrawGraphicTool(t,e,o){if("multipoint"===t&&"3d"===e.type)return this._logError("sketch:create","Multipoint geometries are not supported in SceneView."),null;if(!e)return this._logMissingView(),null;const i="rectangle"!==t,a="rectangle"!==t,r={view:e,mode:"rectangle"===t||"circle"===t?"hybrid":"click",...o,snapToScene:!1,geometryType:t,graphicSymbol:this._getGraphicSymbolFromTool(t),snappingManager:this._snappingManager,forceUniformSize:a,centered:i};return"2d"===e.type?this._makeDrawGraphicTool2D(r):this._makeDrawGraphicTool3D(r)}async _makeDrawGraphicTool2D(t){const e=await this._requireModule(import("../../views/2d/interactive/editingTools.js"));return nt(e)||this.destroyed?null:new e.module.DrawGraphicTool2D({...t,activeVertexSymbol:this.activeVertexSymbol,regularVerticesSymbol:this.vertexSymbol,activeLineSymbol:this.activeLineSymbol,activeFillSymbol:ot(t.geometryType)?this.activeFillSymbol:null,tooltipOptions:this.tooltipOptions})}async _makeDrawGraphicTool3D(t){const e=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(nt(e)||this.destroyed)return null;const{elevationInfo:o}=this.layer;return new e.module.DrawGraphicTool3D({...t,elevationInfo:o,snapToScene:!p(o)||"absolute-height"===o.mode,labelOptions:this.labelOptions,tooltipOptions:this.tooltipOptions})}_setupCreateOperationHandle(t){const e=this.view;if(!e)return this._logMissingView(),null;let o=null;const i=t.forceUniformSize,a=t.centered,r=[e.on("key-down",(e=>{if(e.key===j.pan)e.stopPropagation(),e.repeat||(t.enabled=!1);else if(e.key===j.complete)e.stopPropagation(),t.completeCreateOperation();else if(e.key!==j.vertexAdd||e.repeat)e.key===j.undo?(e.stopPropagation(),s.undo()):e.key===j.redo?(e.stopPropagation(),s.redo()):e.key!==j.constraint||"rectangle"!==t.geometryType&&"circle"!==t.geometryType||e.repeat?e.key===j.center&&(e.repeat||(t.centered=!a,e.stopPropagation())):(t.forceUniformSize=!i,e.stopPropagation());else{const o=t.drawOperation.geometryType;"polyline"!==o&&"polygon"!==o&&"multipoint"!==o||(e.stopPropagation(),t.drawOperation.commitStagedVertex())}}),P.WIDGET),e.on("key-up",(e=>{e.key===j.pan?t.enabled=!0:e.key!==j.constraint||"rectangle"!==t.geometryType&&"circle"!==t.geometryType?e.key===j.center&&(t.centered=a,e.stopPropagation()):(t.forceUniformSize=i,e.stopPropagation())}),P.WIDGET),t.on("vertex-add",(e=>{switch(o=c(o)?"start":"active",e.operation){case"apply":this.emit("create",{graphic:l(t.graphic),state:o,tool:this.activeTool,toolEventInfo:e,type:"create"});break;case"undo":this._emitUndoEvent({graphics:[l(t.graphic)],tool:t.geometryType});break;case"redo":this._emitRedoEvent({graphics:[l(t.graphic)],tool:t.geometryType})}})),t.on("cursor-update",(e=>{t.drawOperation.numCommittedVertices>0&&this.emit("create",{graphic:l(t.graphic),state:"active",tool:this.activeTool,toolEventInfo:{coordinates:e.vertices[0].coordinates,type:"cursor-update"},type:"create"})})),t.on("vertex-remove",(e=>{switch(e.operation){case"apply":this.emit("create",{graphic:l(t.graphic),state:"active",tool:this.activeTool,toolEventInfo:e,type:"create"});break;case"undo":this._emitUndoEvent({graphics:[l(t.graphic)],tool:t.geometryType});break;case"redo":this._emitRedoEvent({graphics:[l(t.graphic)],tool:t.geometryType})}})),t.on("complete",(t=>{this._set("createGraphic",l(t.graphic)),o="complete",t.aborted?s&&s.cancel():s&&s.complete()})),g((()=>this._getGraphicSymbolFromTool(t.geometryType)),(e=>{t.graphicSymbol=e}))],s=new z({activeComponent:t,tool:t.geometryType,type:"create",onEnd:()=>{r.forEach((t=>t.remove())),r.length=0,e.tools?.remove(t)},undo:()=>{t.canUndo&&t.undo()},redo:()=>{t.canRedo&&t.redo()},canUndo:()=>t.canUndo,canRedo:()=>t.canRedo});return s}_getGraphicSymbolFromTool(t){switch(t){case"point":case"multipoint":return this.pointSymbol;case"polyline":return this.polylineSymbol;case"circle":case"rectangle":case"polygon":return this.polygonSymbol}}async _setupUpdateOperation(t,e){const{layer:o,view:i}=this;if(!i)return this._logMissingView(),null;const a={tool:this._defaultUpdateTool,...this.defaultUpdateOptions,...e,reshapeOptions:{...this.defaultUpdateOptions.reshapeOptions,...e?.reshapeOptions}};let r=a.tool;for(const s of t)o.remove(s),o.add(s);if("3d"===i.type){if(0===t.length)return null;switch(r){case"move":return this._setupMove3DOperation(t,a,i,r);case"reshape":{if(t.length>1)return this._logError("sketch:reshape-multiple","Reshape operation does not support multiple graphics."),null;const e=D(t[0]);return e===H.SUPPORTED?this._setupReshape3DOperation(t[0],a,i):(this._logError("sketch:reshape",`Reshape operation not supported for provided graphic(s) (${R(e)}).`),null)}case"transform":return this._setupGraphicTransform3DOperation(t,a,i)}}switch(r){case"move":return this._setupMove2DOperation(t,a,i);case"reshape":{if(t.length>1)return this._logError("sketch:reshape-multiple","Reshape operation does not support multiple graphics."),null;const e=D(t[0]);return e===H.SUPPORTED?this._setupTransformOrReshape2DOperation(t,r,a,i):(this._logError("sketch:reshape",`Reshape operation not supported for provided graphic(s) (${R(e)}).`),null)}case"transform":if(1===t.length){const e=u(t[0].geometry,"type");"point"!==e&&"multipoint"!==e||(r="reshape")}return this._setupTransformOrReshape2DOperation(t,r,a,i)}}async _setupMove3DOperation(t,e,o,i,a=!1){for(const l of t){const t=I(l);if(t!==H.SUPPORTED)return this._logError("sketch:move",`Move operation not supported for provided graphic(s) (${R(t)}).`),null}const r=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(nt(r))return r;const s=new r.module.GraphicMoveTool({view:o,enableZ:e.enableZ,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions});o.tools.add(s),s.graphics.addMany(t),a||this.updateGraphics.addMany(t);const n=[],p=new N({activeComponent:s,tool:i,type:"update",onEnd:()=>{n.forEach((t=>t.remove())),n.length=0,o.tools?.remove(s),s.destroyed||s.destroy()},undo:()=>{it(p,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i})},redo:()=>{at(p,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i})},addToSelection:t=>{this.updateGraphics.push(t),s.graphics.push(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:t=>{const e=this.updateGraphics.indexOf(t);p.history.undo.forEach((t=>t.updates.splice(e,1))),p.history.redo.forEach((t=>t.updates.splice(e,1))),this.updateGraphics.remove(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"}),0!==this.updateGraphics.length?s.graphics.remove(t):p.complete()},toggleTool:async()=>{if(1!==this.updateGraphics.length||!1===e.toggleToolOnClick)return;if("transform"!==i)return;const t=this.updateGraphics.getItemAt(0);if(D(t)!==H.SUPPORTED)return;const a=await this._setupReshape3DOperation(t,e,o,!0);nt(a)||(p.onEnd(),p.destroy(),this._setUpdateOperationHandle(a,e))}});return n.push(...this._getHandlesForComponent(p,e),o.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(p,t,e)),P.WIDGET),o.on("key-down",(t=>{this._getCommonUpdateOperationKeyDownHandlers(p,t)}),P.WIDGET)),p}_setupGraphicTransform3DOperation(t,e,o,i=!1){if(1===t.length&&U(t[0])===H.SUPPORTED){const a=t[0],r=a.geometry;if(p(r)&&("point"===r.type||"mesh"===r.type))return this._setupPointTransform3DOperation(a,e,o);if(p(r)&&("polygon"===r.type||"polyline"===r.type))return this._setupPolyTransform3DOperation(a,e,o,i)}return this._setupMove3DOperation(t,e,o,"transform",i)}async _setupPointTransform3DOperation(t,e,o){const i="transform",{enableRotation:a,enableScaling:r,enableZ:s}=e,n=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(nt(n))return n;const p=new n.module.GraphicTransformTool({graphic:t,view:o,enableRotation:a,enableScaling:r,enableZ:s,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions});o.tools.add(p),this.updateGraphics.add(t);const l=[],h=new N({activeComponent:p,tool:i,type:"update",onEnd:()=>{l.forEach((t=>t.remove())),l.length=0,o.tools?.remove(p),p.destroyed||p.destroy()},undo:()=>{it(h,this.updateGraphics.toArray()),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:i})},redo:()=>{at(h,this.updateGraphics.toArray()),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:i})},addToSelection:async t=>{this.updateGraphics.add(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),e,o,"transform",!0);nt(i)||(h.onEnd(),h.destroy(),this._setUpdateOperationHandle(i,e))},removeFromSelection:t=>{this.updateGraphics.remove(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"}),h.complete()},toggleTool:()=>{}});return l.push(...this._getHandlesForComponent(h,e),o.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(h,t,e)),P.WIDGET),o.on("key-down",(t=>{this._getCommonUpdateOperationKeyDownHandlers(h,t)}),P.WIDGET)),h}async _setupPolyTransform3DOperation(t,e,o,i=!1){const a="transform",{enableRotation:r,enableScaling:s,enableZ:n,preserveAspectRatio:p}=e,l=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(nt(l))return l;const h=new l.module.ExtentTransformTool({graphic:t,view:o,enableRotation:r,enableScaling:s,enableZ:n,preserveAspectRatio:p,tooltipOptions:this.tooltipOptions});o.tools.add(h),i||this.updateGraphics.add(t);const c=[],d=new N({activeComponent:h,tool:a,type:"update",onEnd:()=>{c.forEach((t=>t.remove())),c.length=0,o.tools?.remove(h),h.destroyed||h.destroy()},canUndo:()=>h.canUndo,undo:()=>{h.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a})},canRedo:()=>h.canRedo,redo:()=>{h.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a})},addToSelection:async t=>{this.updateGraphics.add(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),e,o,"transform",!0);nt(i)||(d.onEnd(),d.destroy(),this._setUpdateOperationHandle(i,e))},removeFromSelection:t=>{this.updateGraphics.remove(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"}),d.complete()},toggleTool:async()=>{if(1!==this.updateGraphics.length||!1===e.toggleToolOnClick)return;const t=this.updateGraphics.getItemAt(0);if(D(t)!==H.SUPPORTED)return;const i=await this._setupReshape3DOperation(t,e,o,!0);nt(i)||(d.onEnd(),d.destroy(),this._setUpdateOperationHandle(i,e))}});return c.push(...this._getHandlesForComponent(d,e),o.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(d,t,e)),P.WIDGET),o.on("key-down",(t=>this._getCommonUpdateOperationKeyDownHandlers(d,t)),P.WIDGET),o.on("key-down",(t=>{t.key!==j.constraint||t.repeat||(h.preserveAspectRatio=!h.preserveAspectRatio,t.stopPropagation())}),P.WIDGET),o.on("key-up",(t=>{t.key===j.constraint&&(h.preserveAspectRatio=!h.preserveAspectRatio,t.stopPropagation())}),P.WIDGET)),d}async _setupMove2DOperation(t,e,o){const i="move";this.updateGraphics.addMany(t),await this._updateSpatialReference(t);const a=await this._getGraphicMover(t,e,o);if(nt(a))return a;const r=new N({activeComponent:a,tool:i,type:"update",onEnd:()=>{this._displayDefaultCursor(),p.forEach((t=>t.remove())),n.forEach((t=>t.remove())),p=[],n=[],a.destroy(),this._internalGraphicsLayer?.removeMany([...this.updateGraphics.toArray()])},undo:()=>{const t=this.updateGraphics.toArray();it(r,t),r.refreshComponent(),this._emitUndoEvent({graphics:t,tool:i})},redo:()=>{const t=this.updateGraphics.toArray();at(r,t),r.refreshComponent(),this._emitRedoEvent({graphics:t,tool:i})},addToSelection:async t=>{await this._updateSpatialReference(t),this.updateGraphics.push(t),a.graphics=this.updateGraphics.toArray(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:t=>{const e=this.updateGraphics.indexOf(t);r.history.undo.forEach((t=>t.updates.splice(e,1))),r.history.redo.forEach((t=>t.updates.splice(e,1))),this.updateGraphics.remove(t);const o=this.updateGraphics.toArray();this.emit("update",{graphics:o,state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"}),0!==this.updateGraphics.length?a.graphics=o:r.complete()}});let s=!1,n=[o.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(r,t,e)),P.WIDGET),o.on("key-down",(t=>{this._getCommonUpdateOperationKeyDownHandlers(r,t),t.key!==j.constraint||t.repeat||(s=!0,a.enableMoveAllGraphics=!a.enableMoveAllGraphics)}),P.WIDGET),o.on("key-up",(t=>{t.key===j.constraint&&s&&(s=!1,a.enableMoveAllGraphics=!a.enableMoveAllGraphics)}),P.WIDGET)],p=this._getHandlesForComponent(r,e);return r}async _setupReshape3DOperation(t,e,o,i=!1){const a="reshape",r=await this._requireModule(import("../../views/3d/interactive/editingTools.js"));if(nt(r))return r;const s=e.reshapeOptions,n=new r.module.GraphicReshapeTool({view:o,graphic:t,enableZVertex:e.enableZ&&"move"===s?.vertexOperation,enableZShape:e.enableZ&&"move"===s?.shapeOperation,enableMoveGraphic:"move"===s?.shapeOperation||"move-xy"===s?.shapeOperation,enableMidpoints:"split"===s?.edgeOperation,enableEdgeOffset:"offset"===s?.edgeOperation,snappingManager:this._snappingManager,labelOptions:this.labelOptions,tooltipOptions:this.tooltipOptions});o.tools.add(n),i||this.updateGraphics.add(t);const p=[],l=new N({activeComponent:n,tool:a,type:"update",onEnd:()=>{p.forEach((t=>t.remove())),p.length=0,o.tools?.remove(n),n.destroyed||n.destroy()},canUndo:()=>n.canUndo,undo:()=>{n.undo(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:a})},canRedo:()=>n.canRedo,redo:()=>{n.redo(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:a})},addToSelection:async t=>{this.updateGraphics.add(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"});const i=await this._setupMove3DOperation(this.updateGraphics.toArray(),e,o,"transform",!0);nt(i)||(l.onEnd(),l.destroy(),this._setUpdateOperationHandle(i,e))},removeFromSelection:t=>{this.updateGraphics.remove(t),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"}),l.complete()},toggleTool:async()=>{if(!1===e.toggleToolOnClick)return;const t=await this._setupGraphicTransform3DOperation(this.updateGraphics.toArray(),e,o,!0);nt(t)||(l.onEnd(),l.destroy(),this._setUpdateOperationHandle(t,e))}});return p.push(...this._getHandlesForComponent(l,e),o.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(l,t,e)),P.WIDGET),o.on("key-down",(t=>{this._getCommonUpdateOperationKeyDownHandlers(l,t)}),P.WIDGET)),l}async _setupTransformOrReshape2DOperation(t,e,o,i){this.updateGraphics.addMany(t),await this._updateSpatialReference(t);const a="transform"===e?await this._getBox(t,o,i):await this._getReshape(t,o,i);if(nt(a))return a;const r=new N({activeComponent:a,type:"update",onEnd:()=>{n.forEach((t=>t.remove())),s.forEach((t=>t.remove())),n=[],s=[],r.activeComponent&&!r.activeComponent.destroyed&&r.activeComponent.destroy(),this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray())},undo:()=>{it(r,this.updateGraphics.toArray()),r.refreshComponent(),this._emitUndoEvent({graphics:this.updateGraphics.toArray(),tool:r.tool})},redo:()=>{at(r,this.updateGraphics.toArray()),r.refreshComponent(),this._emitRedoEvent({graphics:this.updateGraphics.toArray(),tool:r.tool})},addToSelection:async t=>{let e=r.activeComponent;if("reshape"===e?.type){const e=[...this.updateGraphics,t];this.updateGraphics.removeAll();const a=await this._setupMove2DOperation(e,o,i);if(nt(a))return;r.onEnd(),r.destroy(),this._setUpdateOperationHandle(a,o)}else this.updateGraphics.add(t),e.graphics=this.updateGraphics.toArray(),e.refresh(),r.resetHistory();this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[t],removed:[],type:"selection-change"},type:"update"})},removeFromSelection:async t=>{const e=this.updateGraphics.indexOf(t);r.history.undo.forEach((t=>t.updates.splice(e,1))),r.history.redo.forEach((t=>t.updates.splice(e,1))),this.updateGraphics.remove(t);const o=this.updateGraphics.toArray();if(0===o.length)r.complete();else{const t=o[0].geometry;1!==o.length||!p(t)||"point"!==t.type&&"multipoint"!==t.type?r.activeComponent.graphics=o:r.toggleTool()}this.emit("update",{graphics:o,state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:[],removed:[t],type:"selection-change"},type:"update"})},toggleTool:async()=>{if(this.updateGraphics.length>1)return;const t=this.updateGraphics.getItemAt(0),e=t.geometry;if(p(e)&&("reshape"===r.tool&&("point"===e.type||"multipoint"===e.type)||"transform"===r.tool&&"extent"===e.type))return;let a=null;"transform"===r.tool?a=await this._getReshape([t],o,i):"reshape"===r.tool&&(a=await this._getBox([t],o,i)),nt(a)||(r.activeComponent?.destroy(),r.activeComponent=a,r.activeComponent&&(n.forEach((t=>t.remove())),n=this._getHandlesForComponent(r,o)))}});let s=[i.on("immediate-click",(t=>this._getCommonUpdateOperationClickHandlers(r,t,o)),P.WIDGET),i.on("key-down",(t=>{if(this._getCommonUpdateOperationKeyDownHandlers(r,t),t.key===j.constraint&&!t.repeat&&r){const t=r.activeComponent;t&&"box"===t.type&&(t.preserveAspectRatio=!t.preserveAspectRatio)}}),P.WIDGET),i.on("key-up",(t=>{if(t.key===j.constraint&&r){const t=r.activeComponent;t&&"box"===t.type&&(t.preserveAspectRatio=!t.preserveAspectRatio)}}),P.WIDGET)],n=this._getHandlesForComponent(r,o);return r}async _getGraphicMover(t,e,o){const{enableMoveAllGraphics:i}=e,a=await this._requireModule(import("../../views/draw/support/GraphicMover.js"));return nt(a)?a:new a.module.default({enableMoveAllGraphics:i,highlightsEnabled:!0,indicatorsEnabled:!1,graphics:t,view:o,callbacks:{onGraphicMoveStart:({dx:t,dy:e,graphic:o})=>{this._displayGrabbingCursor(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:"move-start"},type:"update"})},onGraphicMove:({dx:t,dy:e,graphic:o})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:"move"},type:"update"}),onGraphicMoveStop:({dx:t,dy:e,graphic:o})=>{this._displayPointerCursor(),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:"move-stop"},type:"update"})},onGraphicPointerOver:()=>this._displayPointerCursor(),onGraphicPointerOut:()=>this._displayDefaultCursor()}})}async _getBox(t,e,o){const{enableRotation:i,enableScaling:a,preserveAspectRatio:r}=e,s=await this._requireModule(import("../../views/draw/support/Box.js"));return nt(s)?s:new s.module.default({graphics:t,enableRotation:i,enableScaling:a,preserveAspectRatio:r,layer:this._internalGraphicsLayer,view:o,tooltipOptions:this.tooltipOptions,callbacks:{onMoveStart:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onMove:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onMoveStop:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onScaleStart:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onScale:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onScaleStop:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onRotateStart:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onRotate:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onRotateStop:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"})}})}async _getReshape(t,e,o){const i="split"===e.reshapeOptions?.edgeOperation,a="move"===e.reshapeOptions?.shapeOperation,r=await this._requireModule(import("../../views/draw/support/Reshape.js"));return nt(r)?r:new r.module.default({enableMidpoints:i,enableMovement:a,graphic:t[0],layer:this._internalGraphicsLayer,snappingManager:this._snappingManager,tooltipOptions:this.tooltipOptions,view:o,callbacks:{onReshapeStart:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onReshape:t=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{...t},type:"update"}),onReshapeStop:({mover:t,type:e})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t,type:e},type:"update"}),onMoveStart:({dx:t,dy:e,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:i},type:"update"}),onMove:({dx:t,dy:e,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:i},type:"update"}),onMoveStop:({dx:t,dy:e,mover:o,type:i})=>this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t,dy:e,mover:o,type:i},type:"update"}),onVertexAdd:({added:t,type:e,vertices:o})=>{const i=t.map((t=>C(t.geometry)));this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{added:i,vertices:o,type:e},type:"update"})},onVertexRemove:({removed:t,type:e,vertices:o})=>{const i=t.map((t=>C(t.geometry)));this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{removed:i,vertices:o,type:e},type:"update"})}}})}_getHandlesForComponent(t,e){const o=t.activeComponent;if(!o)return[];switch(o.type){case"graphic-mover":return[o.on("graphic-click",(({graphic:e,viewEvent:o})=>{o.native?.shiftKey&&(o.stopPropagation(),t.removeFromSelection(e))})),o.on("graphic-move-start",(e=>t.addToHistory(st(e.allGraphics))))];case"box":return[o.on("graphic-click",(o=>this._onTransformOrReshape2DGraphicClick(t,e,o))),o.on("move-start",(e=>t.addToHistory(st(e.graphics)))),o.on("rotate-start",(e=>t.addToHistory(st(e.graphics)))),o.on("scale-start",(e=>t.addToHistory(st(e.graphics))))];case"reshape":return[o.on("graphic-click",(o=>this._onTransformOrReshape2DGraphicClick(t,e,o))),o.on("move-start",(e=>t.addToHistory(st([e.mover])))),o.on("reshape-start",(e=>t.addToHistory(st([e.graphic])))),o.on("vertex-add",(e=>t.addToHistory(st([e.oldGraphic])))),o.on("vertex-remove",(e=>t.addToHistory(st([e.oldGraphic]))))];case"move-3d":return[o.on("graphic-move-start",(e=>{t.addToHistory(st(e.allGraphics)),this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:e.allGraphics.length>0?e.allGraphics[0]:null,type:"move-start"},type:"update"})})),o.on("graphic-move",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:t.dx,dy:t.dy,mover:t.allGraphics.length>0?t.allGraphics[0]:null,type:"move"},type:"update"})})),o.on("graphic-move-stop",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{dx:0,dy:0,mover:t.allGraphics.length>0?t.allGraphics[0]:null,type:"move-stop"},type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],t,e):t.toggleTool()}))];case"transform-3d":return[o.on("record-undo",(({record:e})=>{t.addToHistory({updates:[e]})})),o.on("graphic-translate-start",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,dx:t.dxScreen,dy:t.dyScreen,type:"move-start"},type:"update"})})),o.on("graphic-translate-stop",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,dx:t.dxScreen,dy:t.dyScreen,type:"move-stop"},type:"update"})})),o.on("graphic-rotate-start",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,angle:t.angle,type:"rotate-start"},type:"update"})})),o.on("graphic-rotate-stop",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,angle:t.angle,type:"rotate-stop"},type:"update"})})),o.on("graphic-scale-start",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,xScale:t.xScale,yScale:t.yScale,type:"scale-start"},type:"update"})})),o.on("graphic-scale-stop",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,xScale:t.xScale,yScale:t.yScale,type:"scale-stop"},type:"update"})})),o.on("graphic-translate",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,dx:t.dxScreen,dy:t.dyScreen,type:"move"},type:"update"})})),o.on("graphic-rotate",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,angle:t.angle,type:"rotate"},type:"update"})})),o.on("graphic-scale",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:{mover:t.graphic,xScale:t.xScale,yScale:t.yScale,type:"scale"},type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],t,e):t.toggleTool()}))];case"reshape-3d":return[o.on("reshape",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:t,type:"update"})})),o.on("move",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:t,type:"update"})})),o.on("vertex-add",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:t,type:"update"})})),o.on("vertex-remove",(t=>{this.emit("update",{graphics:this.updateGraphics.toArray(),state:"active",aborted:!1,tool:this.activeTool,toolEventInfo:t,type:"update"})})),o.on("immediate-click",(o=>{o.shiftKey?this._toggleSelection([o.graphic],t,e):t.toggleTool()}))]}}_onTransformOrReshape2DGraphicClick(t,e,o){const{graphic:i,viewEvent:a}=o;return a.native?.shiftKey&&i.layer===this.layer?(a.stopPropagation(),t.removeFromSelection(i)):e.toggleToolOnClick?(a.stopPropagation(),t.toggleTool()):void 0}_setUpdateOperationHandle(t,e){this._operationHandle=t;const o=this.view?.map;this._disablePopup(e);const i=()=>{if(t===this._operationHandle){const i=this.updateGraphics.toArray(),a=this._operationHandle.tool;this._operationHandle.destroy(),this._operationHandle=null,this._internalGraphicsLayer.removeMany(this.updateGraphics.toArray()),this.updateGraphics.removeAll(),o&&o.remove(this._internalGraphicsLayer),this._restorePopup(e),this.emit("update",{graphics:i,state:"complete",aborted:t.cancelled,tool:a,toolEventInfo:null,type:"update"})}};t.on("complete",i)}async _getCommonUpdateOperationClickHandlers(t,e,o){const i=Z(e),a=await e.async((()=>this._getFirstHit(i)));if(c(a))return void t.complete();if(e.native.shiftKey&&this._toggleSelection([a.graphic],t,o))return void e.stopPropagation();this.updateGraphics.includes(a.graphic)?e.stopPropagation():t.complete()}_toggleSelection(t,e,o){const i=!!o.multipleSelectionEnabled;return t.some((t=>null!=t&&(!(!i||t.layer!==this.layer)&&(this.updateGraphics.includes(t)?e.removeFromSelection(t):e.addToSelection(t),!0))))}_getCommonUpdateOperationKeyDownHandlers(t,e){if(!t)return;const o=e.key;o===j.undo&&t.canUndo()?(e.stopPropagation(),t.undo()):o===j.redo&&t.canRedo()?(e.stopPropagation(),t.redo()):o===j.cancel?(e.stopPropagation(),t.cancel()):this.allowDeleteKey&&j.delete.includes(o)&&this._onDeleteKey(e)}_onDeleteKey(t){if(!this._operationHandle||"update"!==this._operationHandle.type)return;const e=this.activeComponent,o=this.updateGraphics.toArray();c(e)||"reshape-3d"===e.type||("reshape"!==e.type||1===o.length&&"point"===u(o[0].geometry,"type"))&&(t.stopPropagation(),this.delete())}_removeDefaultLayer(){this._internalGraphicsLayer&&(this.view?.map?.remove(this._internalGraphicsLayer),this._internalGraphicsLayer=n(this._internalGraphicsLayer))}_isComponentGraphic(t){const{activeComponent:e}=this;return!(!t||c(e))&&(t.attributes&&t.attributes.esriSketchTool||"draw-2d"===e.type&&e.graphic===t||("box"===e.type||"reshape"===e.type)&&e.isUIGraphic(t))}_displayPointerCursor(){this.view&&this.view.container&&"pointer"!==this.view.cursor&&(this.view.cursor="pointer")}_displayGrabbingCursor(){this.view&&this.view.container&&"grabbing"!==this.view.cursor&&(this.view.cursor="grabbing")}_displayDefaultCursor(){this.view&&this.view.container&&null!==this.view.cursor&&(this.view.cursor=null)}_logError(t,e,o){s.getLogger(this.declaredClass).error(new i(t,e,o))}async _requireModule(t){const e=new AbortController;this._moduleLoaderAbortController=e;const o=await t;return this._moduleLoaderAbortController!==e||e.signal.aborted?{requireError:"aborted"}:{module:o}}_emitUndoEvent(t){this.emit("undo",{...t,type:"undo"})}_emitRedoEvent(t){this.emit("redo",{...t,type:"redo"})}_emitDeleteEvent(t){this.emit("delete",{...t,type:"delete"})}get test(){return{operationHandle:this._operationHandle,defaultUpdateOptions:Q}}wait(){return _((()=>!this.updating))}_beginAsyncOperation(){this._numUpdating+=1,this.notifyChange("updating")}_endAsyncOperation(){this._numUpdating-=1,this.notifyChange("updating")}_disablePopupEnabled(t){return"3d"!==this.view?.type||this.updateOnGraphicClick||(l(t)?.toggleToolOnClick??!1)}_disablePopup(t){if(!this._disablePopupEnabled(t))return;const e=this.view?.popup;e&&c(this._originalAutoOpenEnabled)&&(this._originalAutoOpenEnabled=e.autoOpenEnabled,e.autoOpenEnabled=!1)}_restorePopup(t){if(!this._disablePopupEnabled(t))return;const e=this.view?.popup;e&&p(this._originalAutoOpenEnabled)&&(e.autoOpenEnabled=this._originalAutoOpenEnabled,this._originalAutoOpenEnabled=null)}async _waitViewReady(){const t=this.view;t?(h(this._viewReadyAbortController),this._viewReadyAbortController=new AbortController,await m(_((()=>t?.ready)),this._viewReadyAbortController.signal)):this._logMissingView()}_logMissingView(){this._logError("sketch:missing-property",et("view"))}_logMissingLayer(){this._logError(tt,et("layer"))}};t([G()],X.prototype,"updating",null),t([G()],X.prototype,"_operationHandle",void 0),t([G({readOnly:!0})],X.prototype,"activeTool",null),t([G()],X.prototype,"activeFillSymbol",void 0),t([G()],X.prototype,"activeLineSymbol",void 0),t([G()],X.prototype,"activeVertexSymbol",void 0),t([G()],X.prototype,"allowDeleteKey",void 0),t([G({readOnly:!0})],X.prototype,"createGraphic",null),t([G()],X.prototype,"defaultCreateOptions",null),t([G()],X.prototype,"defaultUpdateOptions",null),t([G({type:L,nonNullable:!0})],X.prototype,"labelOptions",void 0),t([G()],X.prototype,"layer",void 0),t([G({types:e})],X.prototype,"pointSymbol",void 0),t([G({types:e})],X.prototype,"polygonSymbol",void 0),t([G({types:e})],X.prototype,"polylineSymbol",void 0),t([G({type:W,nonNullable:!0})],X.prototype,"snappingOptions",null),t([G()],X.prototype,"_snappingManager",void 0),t([G({readOnly:!0})],X.prototype,"state",null),t([G({type:F,nonNullable:!0})],X.prototype,"tooltipOptions",void 0),t([G({readOnly:!0})],X.prototype,"updateGraphics",void 0),t([G()],X.prototype,"updateOnGraphicClick",void 0),t([G({types:e})],X.prototype,"updatePointSymbol",void 0),t([G({types:e})],X.prototype,"updatePolygonSymbol",void 0),t([G({types:e})],X.prototype,"updatePolylineSymbol",void 0),t([G({types:e})],X.prototype,"vertexSymbol",void 0),t([G({value:null})],X.prototype,"view",null),X=t([b("esri.widgets.Sketch.SketchViewModel")],X);const tt="sketch:missing-property",et=t=>`Property '${t}' is missing on SketchViewModel.`;function ot(t){return"polygon"===t||"rectangle"===t||"circle"===t}function it(t,e){rt("undo",t.history.undo,t.history.redo,e)}function at(t,e){rt("redo",t.history.redo,t.history.undo,e)}function rt(t,e,o,i){const a=e.pop();if(!a)return;const r=a.updates,s=[];i.forEach(((e,o)=>{const i=r[o];null!=i&&("geometry"in i&&p(i.geometry)&&(s.push({geometry:e.geometry}),e.geometry=i.geometry),"symbol"in i&&p(i.symbol)&&(s.push({symbol:e.symbol}),e.symbol=i.symbol),"undo"in i&&(s.push(i),i[t](e)))})),o.push({updates:s})}function st(t){return{updates:t.map((t=>({geometry:t.geometry})))}}function nt(t){return"requireError"in t&&"aborted"===t.requireError}const pt=X;export{pt as default};