@arcgis/core 5.1.0-next.32 → 5.1.0-next.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{ad9194335902c687bb96.js → 48968fb9e103ee6c3579.js} +1 -1
  3. package/assets/esri/core/workers/chunks/{965b8fa54d0cfafd4a70.js → 5b22245bf02f839d79e3.js} +1 -1
  4. package/assets/esri/core/workers/chunks/{7948d6f14ae44d346d88.js → 5cb4cd1cc6c21f69b925.js} +1 -1
  5. package/assets/esri/core/workers/chunks/{7411ca5e1876aaa0228e.js → 6ba87ebb1c8c5f1d4798.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{e3fe1db9380633292b27.js → 746b3e98bad32c366a27.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{01e4cc34be6265843258.js → 8109476a7b1039d424ab.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{75cde632887a95ea20f2.js → 91e9337bef87ada2e05c.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{942e4d69b140bc2f97c9.js → 938125c024e1524a57e6.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{17078f4ab1b3e33c80b4.js → ab679e5d76d70a1672af.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{85f309c1888c1c8411b1.js → ba477072b1d1d3b5f78b.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{ca700e9e1bced9f99899.js → bfdfa737f8e7b0bee417.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{af601eb8c938c0720406.js → c2c339b2df1c4466f4d4.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{c24ce19ab8580364c703.js → cc69e61d6a7c220e3dd8.js} +2 -2
  15. package/assets/esri/core/workers/chunks/{19722dfef06028ab399b.js → cf045900f179210f22d2.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{e9dd60d0220036545ebb.js → d22cc7d485c032181bbc.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{ba067547ec094ad13904.js → da60a6df2f7858a2910e.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{7ddb11a127b9458e9eac.js → f104d83b7b31a16908ee.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{29687aae97dc01f33fa6.js → f7e66295401b85e2c91d.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{3ca7f5cedf3cb747c0cf.js → fa62d43ccf5cb991dddd.js} +1 -1
  21. package/config.js +1 -1
  22. package/kernel.js +1 -1
  23. package/package.json +3 -3
  24. package/support/revision.js +1 -1
  25. package/views/2d/engine/flow/dataUtils.js +1 -1
  26. package/views/2d/engine/webgl/TextureManager.js +1 -1
  27. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
  28. package/views/3d/analysis/Slice/SliceTool.js +1 -1
  29. package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementShiftTool.js +1 -1
  30. package/views/3d/interactive/editingTools/transform/extentTransform/ExtentMove.js +1 -1
  31. package/views/3d/interactive/editingTools/transform/extentTransform/ExtentRotate.js +1 -1
  32. package/views/3d/interactive/editingTools/transform/extentTransform/ExtentScale.js +1 -1
  33. package/views/3d/interactive/manipulators/ResizeManipulator.js +2 -0
  34. package/views/3d/interactive/manipulators/RotateManipulator.js +2 -0
  35. package/views/3d/interactive/manipulators/ShiftManipulator.js +2 -0
  36. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  37. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  38. package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
  39. package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
  40. package/views/3d/layers/graphics/GraphicsDeconflictor.js +1 -1
  41. package/views/3d/terrain/TerrainRenderer.js +1 -1
  42. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  43. package/views/draw/Draw.d.ts +37 -16
  44. package/views/interactive/coordinateHelper.js +1 -1
  45. package/views/support/flow/dataUtils.js +1 -1
  46. package/views/webgl/RenderingContext.js +1 -1
  47. package/widgets/Editor/EditorViewModel.js +1 -1
  48. package/views/3d/analysis/Slice/ResizeManipulator.js +0 -2
  49. package/views/3d/analysis/Slice/RotateManipulator.js +0 -2
  50. package/views/3d/analysis/Slice/ShiftManipulator.js +0 -2
  51. /package/assets/esri/core/workers/chunks/{c24ce19ab8580364c703.js.LICENSE.txt → cc69e61d6a7c220e3dd8.js.LICENSE.txt} +0 -0
@@ -1,5 +1,10 @@
1
1
  import type Accessor from "../../core/Accessor.js";
2
2
  import type DrawAction from "./DrawAction.js";
3
+ import type MultipointDrawAction from "./MultipointDrawAction.js";
4
+ import type PointDrawAction from "./PointDrawAction.js";
5
+ import type PolygonDrawAction from "./PolygonDrawAction.js";
6
+ import type PolylineDrawAction from "./PolylineDrawAction.js";
7
+ import type SegmentDrawAction from "./SegmentDrawAction.js";
3
8
  import type { MapViewOrSceneView } from "../MapViewOrSceneView.js";
4
9
  import type { DrawOptions } from "./types.js";
5
10
 
@@ -119,25 +124,41 @@ export default class Draw extends Accessor {
119
124
  */
120
125
  complete(): void;
121
126
  /**
122
- * Creates an instance of the requested draw action.
123
- *
124
127
  * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
125
- * See the table below for a list of possible values and type of draw action it creates.
126
- *
127
- * **Possible Values**
128
- *
129
- * Geometry type | Draw action instance
130
- * ------------- | --------------------
131
- * point | [PointDrawAction](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PointDrawAction/)
132
- * multipoint | [MultipointDrawAction](https://developers.arcgis.com/javascript/latest/references/core/views/draw/MultipointDrawAction/) (only supported in [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/))
133
- * polyline | [PolylineDrawAction](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PolylineDrawAction/)
134
- * polygon | [PolygonDrawAction](https://developers.arcgis.com/javascript/latest/references/core/views/draw/PolygonDrawAction/)
135
- * rectangle, circle, ellipse | [SegmentDrawAction](https://developers.arcgis.com/javascript/latest/references/core/views/draw/SegmentDrawAction/)
136
128
  * @param drawOptions - Object of the drawing options for the geometry to be created.
137
- * @returns Returns an instance of the requested draw action.
138
- * @example let pointAction = draw.create("point");
129
+ * @returns Returns a PointDrawAction instance.
130
+ */
131
+ create(drawAction: "point", drawOptions?: DrawOptions): PointDrawAction;
132
+ /**
133
+ * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
134
+ * @param drawOptions - Object of the drawing options for the geometry to be created.
135
+ * @returns Returns a PolygonDrawAction instance.
136
+ */
137
+ create(drawAction: "polygon", drawOptions?: DrawOptions): PolygonDrawAction;
138
+ /**
139
+ * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
140
+ * @param drawOptions - Object of the drawing options for the geometry to be created.
141
+ * @returns Returns a PolylineDrawAction instance.
142
+ */
143
+ create(drawAction: "polyline", drawOptions?: DrawOptions): PolylineDrawAction;
144
+ /**
145
+ * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
146
+ * @param drawOptions - Object of the drawing options for the geometry to be created.
147
+ * @returns Returns a MultipointDrawAction instance.
148
+ */
149
+ create(drawAction: "multipoint", drawOptions?: DrawOptions): MultipointDrawAction;
150
+ /**
151
+ * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
152
+ * @param drawOptions - Object of the drawing options for the geometry to be created.
153
+ * @returns Returns a SegmentDrawAction instance.
154
+ */
155
+ create(drawAction: "rectangle" | "circle" | "ellipse" | "triangle", drawOptions?: DrawOptions): SegmentDrawAction;
156
+ /**
157
+ * @param drawAction - Name of the [draw action](https://developers.arcgis.com/javascript/latest/references/core/views/draw/DrawAction/) to create.
158
+ * @param drawOptions - Object of the drawing options for the geometry to be created.
159
+ * @returns Returns a DrawAction instance of the correct type.
139
160
  */
140
- create(drawAction: ToolType, drawOptions?: DrawOptions): DrawAction;
161
+ create(drawAction: ToolType, drawOptions?: DrawOptions): SegmentDrawAction | MultipointDrawAction | PolylineDrawAction | PolygonDrawAction | PointDrawAction;
141
162
  /**
142
163
  * Resets the drawing by clearing the active action.
143
164
  *
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{distance as e,lerp as r,copy as t,equals as a}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as i,fromValues as o,fromArray as n}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{distance as s,set as u,lerp as c,copy as l,equals as p}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as h,fromValues as v,fromArray as y}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lerp as d,copy as f,equals as m}from"../../core/libs/gl-matrix-2/math/vec4.js";import{create as T,fromValues as _,fromArray as g}from"../../core/libs/gl-matrix-2/factories/vec4f64.js";import x from"../../geometry/Point.js";class R{constructor(e){this.spatialReference=e}createVector(){return this._tag(i())}pointToVector(e){return this._tag(o(e.x,e.y))}arrayToVector(e){return this._tag(o(e[0],e[1]))}vectorToArray(e){return[e[0],e[1]]}pointToArray(e){return[e.x,e.y]}vectorToPoint(e,r=new x){if(e)return r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(e)return r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"},r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.hasZ=!1,r.hasM=!1,r.spatialReference=this.spatialReference,r}lerp(e,t,a,i){return r(i,e,t,a)}addDelta(e,r,t){e[0]+=r,e[1]+=t}distance(r,t){return e(r,t)}getZ(e,r=void 0){return r}hasZ(){return!1}getM(e,r=void 0){return r}hasM(){return!1}clone(e){return this._tag(n(e))}copy(e,r){return t(r,e)}fromXYZ(e){return this._tag(o(e[0],e[1]))}toXYZ(e,r=h()){return u(r,e[0],e[1],0)}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],0)}pointToXYZ(e,r=h()){return u(r,e.x,e.y,0)}equals(e,r){return a(e,r)}_tag(e){return e}}class Z{constructor(e,r){this._valueType=e,this.spatialReference=r}createVector(){return this._tag(h())}pointToVector(e){return this._tag(v(e.x,e.y,0===this._valueType?e.z:e.m))}arrayToVector(e){return this._tag(v(e[0],e[1],e[2]||0))}vectorToArray(e){return[e[0],e[1],e[2]]}pointToArray(e){return 0===this._valueType?[e.x,e.y,e.z]:[e.x,e.y,e.m]}vectorToPoint(e,r=new x){if(e)return r.x=e[0],r.y=e[1],r.z=0===this._valueType?e[2]:void 0,r.m=1===this._valueType?e[2]:void 0,r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=0===this._valueType?e[2]:void 0,r.m=1===this._valueType?e[2]:void 0,r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(!e)return;r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"};const t=0===this._valueType,a=1===this._valueType;return r.x=e[0],r.y=e[1],r.z=t?e[2]:void 0,r.m=a?e[2]:void 0,r.hasZ=t,r.hasM=a,r.spatialReference=this.spatialReference,r}lerp(e,r,t,a){return c(a,e,r,t)}addDelta(e,r,t,a){e[0]+=r,e[1]+=t,0===this._valueType&&(e[2]+=a)}distance(r,t){return 0===this._valueType?s(r,t):e(X(r),X(t))}getZ(e,r=void 0){return 0===this._valueType?e[2]:r}hasZ(){return 0===this._valueType}getM(e,r=void 0){return 1===this._valueType?e[2]:r}hasM(){return 1===this._valueType}clone(e){return this._tag(y(e))}copy(e,r){return l(r,e)}fromXYZ(e,r=0,t=0){return this._tag(v(e[0],e[1],0===this._valueType?e.length>2?e[2]:r:t))}toXYZ(e,r=h()){return u(r,e[0],e[1],0===this._valueType?e[2]:0)}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],1===this._valueType||e.length<3?0:e[2])}pointToXYZ(e,r=h()){return u(r,e.x,e.y,0===this._valueType?e.z??0:0)}equals(e,r){return p(e,r)}_tag(e){return e}}class z{constructor(e){this.spatialReference=e}createVector(){return this._tag(T())}pointToVector(e){return this._tag(_(e.x,e.y,e.z,e.m))}arrayToVector(e){return this._tag(_(e[0],e[1],e[2]||0,e[3]||0))}vectorToArray(e){return[e[0],e[1],e[2],e[3]]}pointToArray(e){return[e.x,e.y,e.z,e.m]}vectorToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(e)return r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"},r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.hasZ=!0,r.hasM=!0,r.spatialReference=this.spatialReference,r}lerp(e,r,t,a){return d(a,e,r,t)}addDelta(e,r,t,a){e[0]+=r,e[1]+=t,e[2]+=a}distance(e,r){return s(M(e),M(r))}getZ(e){return e[2]}hasZ(){return!0}getM(e){return e[3]}hasM(){return!0}clone(e){return this._tag(g(e))}copy(e,r){return f(r,e)}fromXYZ(e,r=0,t=0){return this._tag(_(e[0],e[1],e.length>2?e[2]:r,t))}toXYZ(e,r=h()){return u(r,e[0],e[1],e[2])}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],e.length<3?0:e[2])}pointToXYZ(e,r=h()){return u(r,e.x,e.y,e.z??0)}equals(e,r){return m(e,r)}_tag(e){return e}}function M(e){return e}function X(e){return e}function Y(e,r,t){return e&&r?new z(t):r?new Z(1,t):e?new Z(0,t):new R(t)}export{R as CoordinateHelper2D,Z as CoordinateHelper3D,z as CoordinateHelper4D,Y as createCoordinateHelper};
2
+ import{distance as e,lerp as r,copy as t,equals as a}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as i,fromValues as o,fromArray as n}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{distance as s,set as u,lerp as c,copy as l,equals as p}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as h,fromValues as y,fromArray as v}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lerp as f,copy as d,equals as m}from"../../core/libs/gl-matrix-2/math/vec4.js";import{create as T,fromValues as _,fromArray as g}from"../../core/libs/gl-matrix-2/factories/vec4f64.js";import x from"../../geometry/Point.js";class R{constructor(e){this.spatialReference=e}createVector(){return this._tag(i())}pointToVector(e){return this._tag(o(e.x,e.y))}arrayToVector(e){return this._tag(o(e[0],e[1]))}vectorToArray(e){return[e[0],e[1]]}pointToArray(e){return[e.x,e.y]}vectorToPoint(e,r=new x){if(e)return r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(e)return r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"},r.x=e[0],r.y=e[1],r.z=void 0,r.m=void 0,r.hasZ=!1,r.hasM=!1,r.spatialReference=this.spatialReference,r}lerp(e,t,a,i){return r(i,e,t,a)}addDelta(e,r,t){e[0]+=r,e[1]+=t}distance(r,t){return e(r,t)}getZ(e,r){return r}hasZ(){return!1}getM(e,r){return r}hasM(){return!1}clone(e){return this._tag(n(e))}copy(e,r){return t(r,e)}fromXYZ(e){return this._tag(o(e[0],e[1]))}toXYZ(e,r=h()){return u(r,e[0],e[1],0)}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],0)}pointToXYZ(e,r=h()){return u(r,e.x,e.y,0)}equals(e,r){return a(e,r)}_tag(e){return e}}class Z{constructor(e,r){this._valueType=e,this.spatialReference=r}createVector(){return this._tag(h())}pointToVector(e){return this._tag(y(e.x,e.y,0===this._valueType?e.z:e.m))}arrayToVector(e){return this._tag(y(e[0],e[1],e[2]||0))}vectorToArray(e){return[e[0],e[1],e[2]]}pointToArray(e){return 0===this._valueType?[e.x,e.y,e.z]:[e.x,e.y,e.m]}vectorToPoint(e,r=new x){if(e)return r.x=e[0],r.y=e[1],r.z=0===this._valueType?e[2]:void 0,r.m=1===this._valueType?e[2]:void 0,r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=0===this._valueType?e[2]:void 0,r.m=1===this._valueType?e[2]:void 0,r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(!e)return;r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"};const t=0===this._valueType,a=1===this._valueType;return r.x=e[0],r.y=e[1],r.z=t?e[2]:void 0,r.m=a?e[2]:void 0,r.hasZ=t,r.hasM=a,r.spatialReference=this.spatialReference,r}lerp(e,r,t,a){return c(a,e,r,t)}addDelta(e,r,t,a){e[0]+=r,e[1]+=t,0===this._valueType&&(e[2]+=a)}distance(r,t){return 0===this._valueType?s(r,t):e(X(r),X(t))}getZ(e,r){return 0===this._valueType?e[2]:r}hasZ(){return 0===this._valueType}getM(e,r){return 1===this._valueType?e[2]:r}hasM(){return 1===this._valueType}clone(e){return this._tag(v(e))}copy(e,r){return l(r,e)}fromXYZ(e,r=0,t=0){return this._tag(y(e[0],e[1],0===this._valueType?e.length>2?e[2]:r:t))}toXYZ(e,r=h()){return u(r,e[0],e[1],0===this._valueType?e[2]:0)}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],1===this._valueType||e.length<3?0:e[2])}pointToXYZ(e,r=h()){return u(r,e.x,e.y,0===this._valueType?e.z??0:0)}equals(e,r){return p(e,r)}_tag(e){return e}}class z{constructor(e){this.spatialReference=e}createVector(){return this._tag(T())}pointToVector(e){return this._tag(_(e.x,e.y,e.z,e.m))}arrayToVector(e){return this._tag(_(e[0],e[1],e[2]||0,e[3]||0))}vectorToArray(e){return[e[0],e[1],e[2],e[3]]}pointToArray(e){return[e.x,e.y,e.z,e.m]}vectorToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.spatialReference=this.spatialReference,r}arrayToPoint(e,r=new x){return r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.spatialReference=this.spatialReference,r}vectorToDehydratedPoint(e,r){if(e)return r??={x:void 0,y:void 0,z:void 0,m:void 0,hasZ:void 0,hasM:void 0,spatialReference:void 0,type:"point"},r.x=e[0],r.y=e[1],r.z=e[2],r.m=e[3],r.hasZ=!0,r.hasM=!0,r.spatialReference=this.spatialReference,r}lerp(e,r,t,a){return f(a,e,r,t)}addDelta(e,r,t,a){e[0]+=r,e[1]+=t,e[2]+=a}distance(e,r){return s(M(e),M(r))}getZ(e){return e[2]}hasZ(){return!0}getM(e){return e[3]}hasM(){return!0}clone(e){return this._tag(g(e))}copy(e,r){return d(r,e)}fromXYZ(e,r=0,t=0){return this._tag(_(e[0],e[1],e.length>2?e[2]:r,t))}toXYZ(e,r=h()){return u(r,e[0],e[1],e[2])}arrayToXYZ(e,r=h()){return u(r,e[0],e[1],e.length<3?0:e[2])}pointToXYZ(e,r=h()){return u(r,e.x,e.y,e.z??0)}equals(e,r){return m(e,r)}_tag(e){return e}}function M(e){return e}function X(e){return e}function Y(e,r,t){return e&&r?new z(t):r?new Z(1,t):e?new Z(0,t):new R(t)}export{R as CoordinateHelper2D,Z as CoordinateHelper3D,z as CoordinateHelper4D,Y as createCoordinateHelper};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{moduloPositive as e,deg2rad as r}from"../../../core/mathUtils.js";import o from"../../../core/RandomLCG.js";import{Seconds as n}from"../../../core/time.js";import i from"../../../geometry/Extent.js";import{getInfo as a}from"../../../geometry/support/spatialReferenceUtils.js";const s=()=>t.getLogger("esri.views.support.flow.dataUtils");function l(t,e,r,n,i){if(t.density<=0)return[];const{positions:a}=i,s=[],l=new o,c=1/Math.max(t.lineCollisionWidth,1),d=Math.round(r*c),u=Math.round(n*c),m=new Int32Array(d*u);for(let o=0;o<m.length;o++)m[o]=-1;const p={raster:m,width:d,height:u,resolutionFactor:c},w={},g=t.lineSpacing/Math.sqrt(t.density),y=Math.floor(n/g),x=Math.floor(r/g);for(let o=0;o<y;o++){const t=o*g;for(let e=0;e<x;e++){const r=e*g;w[`${e}-${o}`]={x:r,y:t,positions:[]}}}for(const{x:o,y:h}of a){const t=w[`${Math.floor(o/g)}-${Math.floor(h/g)}`];t&&t.positions.push([o,h])}const M=[];for(const o in w){const t=w[o];if(0===t.positions.length)M.push({x:t.x+g/2,y:t.y+g/2,sort:.66+.33*l.getFloat(),stage:0});else{const[e]=t.positions.splice(0,1);M.push({x:e[0],y:e[1],sort:.33*l.getFloat(),stage:1});for(const[r,o]of t.positions)M.push({x:r,y:o,sort:.33+.33*l.getFloat(),stage:2})}}M.sort((t,e)=>t.sort-e.sort);for(const{x:o,y:v,stage:A}of M){if(s.length>=t.maxNumberOfStreamlines)break;const i=t.onlyForwardTracing?h(1,t,e,o,v,[r,n],s.length,p):f(t,e,o,v,[r,n],s.length,l,p);i.length<2||s.push({stage:A,vertices:i})}return s}function c(t,e){const r=d(e.data,e.width,e.height,t.smoothing);if(t.interpolate){return(t,o)=>{const n=Math.floor(t),i=Math.floor(o);if(n<0||n>=e.width)return[0,0];if(i<0||i>=e.height)return[0,0];const a=t-n,s=o-i,l=n,c=i,h=n<e.width-1?n+1:n,f=i<e.height-1?i+1:i,d=r[2*(c*e.width+l)],u=r[2*(c*e.width+h)],m=r[2*(f*e.width+l)],p=r[2*(f*e.width+h)],w=r[2*(c*e.width+l)+1],g=r[2*(c*e.width+h)+1];return[(d*(1-s)+m*s)*(1-a)+(u*(1-s)+p*s)*a,(w*(1-s)+r[2*(f*e.width+l)+1]*s)*(1-a)+(g*(1-s)+r[2*(f*e.width+h)+1]*s)*a]}}return(t,o)=>{const n=Math.round(t),i=Math.round(o);return n<0||n>=e.width||i<0||i>=e.height?[0,0]:[r[2*(i*e.width+n)],r[2*(i*e.width+n)+1]]}}function h(t,r,o,i,a,s,l,c){const h=[],{raster:f,width:d,height:u,resolutionFactor:m}=c;let p=i,w=a,g=n(0),[y,x]=o(p,w);y*=r.velocityScale,x*=r.velocityScale;const M=Math.sqrt(y*y+x*x);let v,A;h.push({x:p,y:w,time:g,speed:M});for(let k=0;k<r.verticesPerLine;k++){let[i,a]=o(p,w);i*=r.velocityScale,a*=r.velocityScale;const c=Math.sqrt(i*i+a*a);if(c<r.minSpeedThreshold)return h;const y=t*i/c,x=t*a/c;p+=y*r.segmentLength,w+=x*r.segmentLength,r.wrapAround&&(p=e(p,s[0]));const M=t*r.segmentLength/c;if(g=n(g+M),Math.acos(y*v+x*A)>r.maxTurnAngle)return h;if(r.collisions){let t=Math.round(p*m);const o=Math.round(w*m);if(r.wrapAround&&(t=e(t,d)),t<0||t>d-1||o<0||o>u-1)return h;const n=f[o*d+t];if(-1!==n&&n!==l)return h;f[o*d+t]=l}h.push({x:p,y:w,time:g,speed:c}),v=y,A=x}return h}function f(t,e,r,o,n,i,a,s){const l=Math.round((.2+.6*a.getFloat())*t.verticesPerLine),c=t.verticesPerLine-l,f=h(-1,{...t,verticesPerLine:c},e,r,o,n,i,s),d=h(1,{...t,verticesPerLine:l},e,r,o,n,i,s),u=f.reverse();u.splice(-1,1);return u.concat(d)}function d(t,e,r,o){if(0===o)return t;const n=Math.round(3*o),i=new Array(2*n+1);let a=0;for(let c=-n;c<=n;c++){const t=Math.exp(-c*c/(o*o));i[c+n]=t,a+=t}for(let c=-n;c<=n;c++)i[c+n]/=a;const s=new Float32Array(t.length);for(let c=0;c<r;c++)for(let r=0;r<e;r++){let o=0,a=0;for(let s=-n;s<=n;s++){if(r+s<0||r+s>=e)continue;const l=i[s+n];o+=l*t[2*(c*e+(r+s))],a+=l*t[2*(c*e+(r+s))+1]}s[2*(c*e+r)]=o,s[2*(c*e+r)+1]=a}const l=new Float32Array(t.length);for(let c=0;c<e;c++)for(let t=0;t<r;t++){let o=0,a=0;for(let l=-n;l<=n;l++){if(t+l<0||t+l>=r)continue;const h=i[l+n];o+=h*s[2*((t+l)*e+c)],a+=h*s[2*((t+l)*e+c)+1]}l[2*(t*e+c)]=o,l[2*(t*e+c)+1]=a}return l}async function u(t,e,r,o,n,l){const c=performance.now(),h=a(e.spatialReference);if(!h){const i=await m(t,e,r,o,n,l);return has("esri-2d-profiler")&&s().info("I.7","loadImagery, early exit (ms)",Math.round(performance.now()-c)),has("esri-2d-profiler")&&s().info("I.9","Number of parts",1),i}const[f,d]=h.valid,u=d-f,p=Math.ceil(e.width/u),w=e.width/p,g=Math.round(r/p);let y=e.xmin;const x=[],M=performance.now();for(let a=0;a<p;a++){const r=new i({xmin:y,xmax:y+w,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference});x.push(m(t,r,g,o,n,l)),y+=w}const v=await Promise.all(x);if(has("esri-2d-profiler")&&s().info("I.8","All calls to _fetchPart (ms)",Math.round(performance.now()-M)),has("esri-2d-profiler")&&s().info("I.9","Number of parts",v.length),1===v.length)return has("esri-2d-profiler")&&s().info("I.10","loadImagery, general exit without stitching back (ms)",Math.round(performance.now()-c)),v[0];const A={data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};let k=0;for(const i of v){for(let t=0;t<i.height;t++)for(let e=0;e<i.width;e++)k+e>=r||(A.data[2*(t*r+k+e)]=i.data[2*(t*i.width+e)],A.data[2*(t*r+k+e)+1]=i.data[2*(t*i.width+e)+1],A.mask[t*r+k+e]=i.mask[t*i.width+e]);k+=i.width}return has("esri-2d-profiler")&&s().info("I.10","loadImagery, general exit (ms)",Math.round(performance.now()-c)),A}async function m(t,e,r,o,n,i){const a={requestProjectedLocalDirections:!0,signal:i,interpolation:"bilinear"};if(null!=n&&(a.timeExtent=n),"imagery"===t.type){await t.load({signal:i});const n=await t.internalFetchImage(e,r,o,a);if(null==n?.pixelData?.pixelBlock)return{data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};return p(t.rasterInfo.dataType,n.pixelData.pixelBlock)}await t.load({signal:i});const s=await t.fetchPixels(e,r,o,a);if(null==s?.pixelBlock)return{data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};return p(t.serviceRasterInfo.dataType,s.pixelBlock)}function p(t,e,o=e.width,n=e.height,i=0,a=0){const s=e.pixels,l=o*n,c=2,h=new Float32Array(l*c),f=e.width,d=(t,e)=>t+i+(e+a)*f,u=(t,e)=>t+e*o;let m;if(null!=e.mask)if(o!==e.width||n!==e.height||0!==i||0!==a){m=new Uint8Array(l*c);const t=e.mask;for(let e=0;e<n;++e)for(let r=0;r<o;++r){const o=d(r,e),n=u(r,e);m[c*n]=t[c*o],m[c*n+1]=t[c*o+1]}}else m=e.mask;else m=new Uint8Array(l*c),m.fill(255);if("vector-uv"===t)for(let r=0;r<n;++r)for(let t=0;t<o;++t){const e=d(t,r),o=u(t,r);h[c*o]=s[0][e],h[c*o+1]=-s[1][e]}else if("vector-magdir"===t){const{cos:t,sin:e}=Math;for(let i=0;i<n;++i)for(let n=0;n<o;++n){const o=d(n,i),a=u(n,i),l=s[0][o],f=r(s[1][o]),m=t(f-Math.PI/2),p=e(f-Math.PI/2);h[c*a]=m*l,h[c*a+1]=p*l}}return{data:h,mask:m,width:o,height:n}}export{c as createFlowFieldFromData,u as loadImagery,p as toFlowData,l as traceFlowPaths};
2
+ import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{moduloPositive as e,deg2rad as r}from"../../../core/mathUtils.js";import o from"../../../core/RandomLCG.js";import{Seconds as n}from"../../../core/time.js";import i from"../../../geometry/Extent.js";import{getInfo as a}from"../../../geometry/support/spatialReferenceUtils.js";const s=()=>t.getLogger("esri.views.support.flow.dataUtils");function l(t,e,r,n,i){if(t.density<=0)return[];const{positions:a}=i,s=[],l=new o,c=1/Math.max(t.lineCollisionWidth,1),h=Math.round(r*c),u=Math.round(n*c),m=new Int32Array(h*u);for(let o=0;o<m.length;o++)m[o]=-1;const p={raster:m,width:h,height:u,resolutionFactor:c},w={},g=t.lineSpacing/Math.sqrt(t.density),y=Math.floor(n/g),x=Math.floor(r/g);for(let o=0;o<y;o++){const t=o*g;for(let e=0;e<x;e++){const r=e*g;w[`${e}-${o}`]={x:r,y:t,positions:[]}}}for(const{x:o,y:f}of a){const t=w[`${Math.floor(o/g)}-${Math.floor(f/g)}`];t&&t.positions.push([o,f])}const M=[];for(const o in w){const t=w[o];if(0===t.positions.length)M.push({x:t.x+g/2,y:t.y+g/2,sort:.66+.33*l.getFloat(),stage:0});else{const[e]=t.positions.splice(0,1);M.push({x:e[0],y:e[1],sort:.33*l.getFloat(),stage:1});for(const[r,o]of t.positions)M.push({x:r,y:o,sort:.33+.33*l.getFloat(),stage:2})}}M.sort((t,e)=>t.sort-e.sort);for(const{x:o,y:k,stage:v}of M){if(s.length>=t.maxNumberOfStreamlines)break;const i=t.onlyForwardTracing?f(1,t,e,o,k,[r,n],s.length,p):d(t,e,o,k,[r,n],s.length,l,p);i.length<2||s.push({stage:v,vertices:i})}return s}function c(t){for(let e=0;e<t.mask.length;e++)0===t.mask[e]&&(t.data[2*e]=0,t.data[2*e+1]=0)}function h(t,e){const r=u(e.data,e.width,e.height,t.smoothing);if(t.interpolate){return(t,o)=>{const n=Math.floor(t),i=Math.floor(o);if(n<0||n>=e.width)return[0,0];if(i<0||i>=e.height)return[0,0];const a=t-n,s=o-i,l=n,c=i,h=n<e.width-1?n+1:n,f=i<e.height-1?i+1:i,d=r[2*(c*e.width+l)],u=r[2*(c*e.width+h)],m=r[2*(f*e.width+l)],p=r[2*(f*e.width+h)],w=r[2*(c*e.width+l)+1],g=r[2*(c*e.width+h)+1];return[(d*(1-s)+m*s)*(1-a)+(u*(1-s)+p*s)*a,(w*(1-s)+r[2*(f*e.width+l)+1]*s)*(1-a)+(g*(1-s)+r[2*(f*e.width+h)+1]*s)*a]}}return(t,o)=>{const n=Math.round(t),i=Math.round(o);return n<0||n>=e.width||i<0||i>=e.height?[0,0]:[r[2*(i*e.width+n)],r[2*(i*e.width+n)+1]]}}function f(t,r,o,i,a,s,l,c){const h=[],{raster:f,width:d,height:u,resolutionFactor:m}=c;let p=i,w=a,g=n(0),[y,x]=o(p,w);y*=r.velocityScale,x*=r.velocityScale;const M=Math.sqrt(y*y+x*x);let k,v;h.push({x:p,y:w,time:g,speed:M});for(let A=0;A<r.verticesPerLine;A++){let[i,a]=o(p,w);i*=r.velocityScale,a*=r.velocityScale;const c=Math.sqrt(i*i+a*a);if(c<r.minSpeedThreshold)return h;const y=t*i/c,x=t*a/c;p+=y*r.segmentLength,w+=x*r.segmentLength,r.wrapAround&&(p=e(p,s[0]));const M=t*r.segmentLength/c;if(g=n(g+M),Math.acos(y*k+x*v)>r.maxTurnAngle)return h;if(r.collisions){let t=Math.round(p*m);const o=Math.round(w*m);if(r.wrapAround&&(t=e(t,d)),t<0||t>d-1||o<0||o>u-1)return h;const n=f[o*d+t];if(-1!==n&&n!==l)return h;f[o*d+t]=l}h.push({x:p,y:w,time:g,speed:c}),k=y,v=x}return h}function d(t,e,r,o,n,i,a,s){const l=Math.round((.2+.6*a.getFloat())*t.verticesPerLine),c=t.verticesPerLine-l,h=f(-1,{...t,verticesPerLine:c},e,r,o,n,i,s),d=f(1,{...t,verticesPerLine:l},e,r,o,n,i,s),u=h.reverse();u.splice(-1,1);return u.concat(d)}function u(t,e,r,o){if(0===o)return t;const n=Math.round(3*o),i=new Array(2*n+1);let a=0;for(let c=-n;c<=n;c++){const t=Math.exp(-c*c/(o*o));i[c+n]=t,a+=t}for(let c=-n;c<=n;c++)i[c+n]/=a;const s=new Float32Array(t.length);for(let c=0;c<r;c++)for(let r=0;r<e;r++){let o=0,a=0;for(let s=-n;s<=n;s++){if(r+s<0||r+s>=e)continue;const l=i[s+n];o+=l*t[2*(c*e+(r+s))],a+=l*t[2*(c*e+(r+s))+1]}s[2*(c*e+r)]=o,s[2*(c*e+r)+1]=a}const l=new Float32Array(t.length);for(let c=0;c<e;c++)for(let t=0;t<r;t++){let o=0,a=0;for(let l=-n;l<=n;l++){if(t+l<0||t+l>=r)continue;const h=i[l+n];o+=h*s[2*((t+l)*e+c)],a+=h*s[2*((t+l)*e+c)+1]}l[2*(t*e+c)]=o,l[2*(t*e+c)+1]=a}return l}async function m(t,e,r,o,n,l){const c=performance.now(),h=a(e.spatialReference);if(!h){const i=await p(t,e,r,o,n,l);return has("esri-2d-profiler")&&s().info("I.7","loadImagery, early exit (ms)",Math.round(performance.now()-c)),has("esri-2d-profiler")&&s().info("I.9","Number of parts",1),i}const[f,d]=h.valid,u=d-f,m=Math.ceil(e.width/u),w=e.width/m,g=Math.round(r/m);let y=e.xmin;const x=[],M=performance.now();for(let a=0;a<m;a++){const r=new i({xmin:y,xmax:y+w,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference});x.push(p(t,r,g,o,n,l)),y+=w}const k=await Promise.all(x);if(has("esri-2d-profiler")&&s().info("I.8","All calls to _fetchPart (ms)",Math.round(performance.now()-M)),has("esri-2d-profiler")&&s().info("I.9","Number of parts",k.length),1===k.length)return has("esri-2d-profiler")&&s().info("I.10","loadImagery, general exit without stitching back (ms)",Math.round(performance.now()-c)),k[0];const v={data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};let A=0;for(const i of k){for(let t=0;t<i.height;t++)for(let e=0;e<i.width;e++)A+e>=r||(v.data[2*(t*r+A+e)]=i.data[2*(t*i.width+e)],v.data[2*(t*r+A+e)+1]=i.data[2*(t*i.width+e)+1],v.mask[t*r+A+e]=i.mask[t*i.width+e]);A+=i.width}return has("esri-2d-profiler")&&s().info("I.10","loadImagery, general exit (ms)",Math.round(performance.now()-c)),v}async function p(t,e,r,o,n,i){const a={requestProjectedLocalDirections:!0,signal:i,interpolation:"bilinear"};if(null!=n&&(a.timeExtent=n),"imagery"===t.type){await t.load({signal:i});const n=await t.internalFetchImage(e,r,o,a);if(null==n?.pixelData?.pixelBlock)return{data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};return w(t.rasterInfo.dataType,n.pixelData.pixelBlock)}await t.load({signal:i});const s=await t.fetchPixels(e,r,o,a);if(null==s?.pixelBlock)return{data:new Float32Array(r*o*2),mask:new Uint8Array(r*o),width:r,height:o};return w(t.serviceRasterInfo.dataType,s.pixelBlock)}function w(t,e,o=e.width,n=e.height,i=0,a=0){const s=e.pixels,l=o*n,c=2,h=new Float32Array(l*c),f=e.width,d=(t,e)=>t+i+(e+a)*f,u=(t,e)=>t+e*o;let m;if(null!=e.mask)if(o!==e.width||n!==e.height||0!==i||0!==a){m=new Uint8Array(l*c);const t=e.mask;for(let e=0;e<n;++e)for(let r=0;r<o;++r){const o=d(r,e),n=u(r,e);m[c*n]=t[c*o],m[c*n+1]=t[c*o+1]}}else m=e.mask;else m=new Uint8Array(l*c),m.fill(255);if("vector-uv"===t)for(let r=0;r<n;++r)for(let t=0;t<o;++t){const e=d(t,r),o=u(t,r);h[c*o]=s[0][e],h[c*o+1]=-s[1][e]}else if("vector-magdir"===t){const{cos:t,sin:e}=Math;for(let i=0;i<n;++i)for(let n=0;n<o;++n){const o=d(n,i),a=u(n,i),l=s[0][o],f=r(s[1][o]),m=t(f-Math.PI/2),p=e(f-Math.PI/2);h[c*a]=m*l,h[c*a+1]=p*l}}return{data:h,mask:m,width:o,height:n}}export{c as applyMask,h as createFlowFieldFromData,m as loadImagery,w as toFlowData,l as traceFlowPaths};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import has from"../../core/has.js";import t from"../../core/Logger.js";import{disposeMaybe as e}from"../../core/maybe.js";import{after as s}from"../../core/promiseUtils.js";import{Milliseconds as i}from"../../core/time.js";import{webglDebugEnabled as a,checkWebGLError as r,getErrorMessage as n,webglValidateShadersEnabled as l}from"./checkWebGLError.js";import{ContextState as h}from"./ContextState.js";import{DrawBufferNone as f,DrawBufferBack as o,baseTextureUnit as u,ResourceType as c,ColorAttachment0 as d,PrimitiveType as _}from"./enums.js";import{InstanceCounter as b}from"./InstanceCounter.js";import{Parameters as g}from"./Parameters.js";import{ProgramCache as p}from"./ProgramCache.js";import{StateTracker as m}from"./renderState.js";import B from"./Texture.js";import{WebGLDriverTest as F}from"./WebGLDriverTest.js";import{Capabilities as T}from"./capabilities/Capabilities.js";const x=()=>t.getLogger("esri.views.webgl.RenderingContext");let k=class{constructor(t,e){this.gl=t,this.instanceCounter=new b,this._programCache=new p(this),this._transformFeedbackRequestInfo=null,this._state=new h,this._numOfDrawCalls=0,this._numOfTriangles=0,this._options=e,this.configure(e)}configure(t){this._options=t,this._capabilities=new T(this.gl,t),this._parameters=new g(this.gl,this._capabilities,t),B.TEXTURE_UNIT_FOR_UPDATES=this._parameters.maxTextureImageUnits-1;const s=this.gl.getParameter(this.gl.VIEWPORT);this._state=new h,this._state.viewport={x:s[0],y:s[1],width:s[2],height:s[3]},this._stateTracker=new m({setBlending:t=>{if(t){this.setBlendingEnabled(!0),this.setBlendEquationSeparate(t.opRgb,t.opAlpha),this.setBlendFunctionSeparate(t.srcRgb,t.dstRgb,t.srcAlpha,t.dstAlpha);const e=t.color;this.setBlendColor(e.r,e.g,e.b,e.a)}else this.setBlendingEnabled(!1)},setCulling:t=>{t?(this.setFaceCullingEnabled(!0),this.setCullFace(t.face),this.setFrontFace(t.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:t=>{t?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(t.factor,t.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:t=>{t?(this.setDepthTestEnabled(!0),this.setDepthFunction(t.func)):this.setDepthTestEnabled(!1)},setStencilTest:t=>{if(t){this.setStencilTestEnabled(!0);const e=t.function;this.setStencilFunction(e.func,e.ref,e.mask);const s=t.operation;this.setStencilOp(s.fail,s.zFail,s.zPass)}else this.setStencilTestEnabled(!1)},setDepthWrite:t=>{t?(this.setDepthWriteEnabled(!0),this.setDepthRange(t.zNear,t.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:t=>{t?this.setColorMask(t.r,t.g,t.b,t.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:t=>{t?this.setStencilWriteMask(t.mask):this.setStencilWriteMask(0)}}),this.enforceState(),e(this._driverTest),this._driverTest=new F(this)}updateOptions(t){this._options={...this._options,...t},this._parameters=new g(this.gl,this._capabilities,this._options)}dispose(){this._driverTest=e(this._driverTest),this._programCache=e(this._programCache),this.bindVAO(null),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this._state.uniformBufferBindingPoints.length=0,this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663),this._state.textureUnitMap.length=0,this._state=null,this._capabilities=null,this._stateTracker=null,a()&&this.instanceCounter.resourceInformation&&console.log(this.instanceCounter.resourceInformation)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}get programCache(){return this._programCache}setPipelineState(t){this._stateTracker.setPipeline(t)}getPipelineState(){return this._stateTracker.getPipelineState()}setBlendingEnabled(t){this._state.blend!==t&&(!0===t?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=t,this._stateTracker.invalidateBlending())}externalProgramUpdate(){this._state.program?.stop(),this._state.program=null}externalTextureUnitUpdate(t,e){for(let s=0;s<t.length;++s)this._state.textureUnitMap[t[s]]=null;e>=0&&(this._state.activeTexture=e)}externalVertexArrayObjectUpdate(){this.gl.bindVertexArray(null),this._state.vertexArrayObject=null,this._state.vertexBuffer=null,this._state.indexBuffer=null}externalVertexBufferUpdate(){this._state.vertexBuffer=null}externalIndexBufferUpdate(){this._state.indexBuffer=null}setBlendColor(t,e,s,i){t===this._state.blendColor.r&&e===this._state.blendColor.g&&s===this._state.blendColor.b&&i===this._state.blendColor.a||(this.gl.blendColor(t,e,s,i),this._state.blendColor.r=t,this._state.blendColor.g=e,this._state.blendColor.b=s,this._state.blendColor.a=i,this._stateTracker.invalidateBlending())}setBlendFunction(t,e){t===this._state.blendFunction.srcRGB&&e===this._state.blendFunction.dstRGB||(this.gl.blendFunc(t,e),this._state.blendFunction.srcRGB=t,this._state.blendFunction.srcAlpha=t,this._state.blendFunction.dstRGB=e,this._state.blendFunction.dstAlpha=e,this._stateTracker.invalidateBlending())}setBlendFunctionSeparate(t,e,s,i){this._state.blendFunction.srcRGB===t&&this._state.blendFunction.srcAlpha===s&&this._state.blendFunction.dstRGB===e&&this._state.blendFunction.dstAlpha===i||(this.gl.blendFuncSeparate(t,e,s,i),this._state.blendFunction.srcRGB=t,this._state.blendFunction.srcAlpha=s,this._state.blendFunction.dstRGB=e,this._state.blendFunction.dstAlpha=i,this._stateTracker.invalidateBlending())}setBlendEquation(t){this._state.blendEquation.mode!==t&&(this.gl.blendEquation(t),this._state.blendEquation.mode=t,this._state.blendEquation.modeAlpha=t,this._stateTracker.invalidateBlending())}setBlendEquationSeparate(t,e){this._state.blendEquation.mode===t&&this._state.blendEquation.modeAlpha===e||(this.gl.blendEquationSeparate(t,e),this._state.blendEquation.mode=t,this._state.blendEquation.modeAlpha=e,this._stateTracker.invalidateBlending())}setColorMask(t,e,s,i){this._state.colorMask.r===t&&this._state.colorMask.g===e&&this._state.colorMask.b===s&&this._state.colorMask.a===i||(this.gl.colorMask(t,e,s,i),this._state.colorMask.r=t,this._state.colorMask.g=e,this._state.colorMask.b=s,this._state.colorMask.a=i,this._stateTracker.invalidateColorWrite())}setClearColor(t,e,s,i){this._state.clearColor.r===t&&this._state.clearColor.g===e&&this._state.clearColor.b===s&&this._state.clearColor.a===i||(this.gl.clearColor(t,e,s,i),this._state.clearColor.r=t,this._state.clearColor.g=e,this._state.clearColor.b=s,this._state.clearColor.a=i)}setFaceCullingEnabled(t){this._state.faceCulling!==t&&(!0===t?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this._state.faceCulling=t,this._stateTracker.invalidateCulling())}setPolygonOffsetFillEnabled(t){this._state.polygonOffsetFill!==t&&(!0===t?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL),this._state.polygonOffsetFill=t,this._stateTracker.invalidatePolygonOffset())}setPolygonOffset(t,e){this._state.polygonOffset[0]===t&&this._state.polygonOffset[1]===e||(this._state.polygonOffset[0]=t,this._state.polygonOffset[1]=e,this.gl.polygonOffset(t,e),this._stateTracker.invalidatePolygonOffset())}setCullFace(t){this._state.cullFace!==t&&(this.gl.cullFace(t),this._state.cullFace=t,this._stateTracker.invalidateCulling())}setFrontFace(t){this._state.frontFace!==t&&(this.gl.frontFace(t),this._state.frontFace=t,this._stateTracker.invalidateCulling())}setScissorTestEnabled(t){this._state.scissorTest!==t&&(!0===t?this.gl.enable(this.gl.SCISSOR_TEST):this.gl.disable(this.gl.SCISSOR_TEST),this._state.scissorTest=t)}setScissorRect(t,e,s,i){this._state.scissorRect.x===t&&this._state.scissorRect.y===e&&this._state.scissorRect.width===s&&this._state.scissorRect.height===i||(this.gl.scissor(t,e,s,i),this._state.scissorRect.x=t,this._state.scissorRect.y=e,this._state.scissorRect.width=s,this._state.scissorRect.height=i)}setDepthTestEnabled(t){this._state.depthTest!==t&&(!0===t?this.gl.enable(this.gl.DEPTH_TEST):this.gl.disable(this.gl.DEPTH_TEST),this._state.depthTest=t,this._stateTracker.invalidateDepthTest())}setClearDepth(t){this._state.clearDepth!==t&&(this.gl.clearDepth(t),this._state.clearDepth=t)}setDepthFunction(t){this._state.depthFunction!==t&&(this.gl.depthFunc(t),this._state.depthFunction=t,this._stateTracker.invalidateDepthTest())}setDepthWriteEnabled(t){this._state.depthWrite!==t&&(this.gl.depthMask(t),this._state.depthWrite=t,this._stateTracker.invalidateDepthWrite())}setDepthRange(t,e){this._state.depthRange.zNear===t&&this._state.depthRange.zFar===e||(this.gl.depthRange(t,e),this._state.depthRange.zNear=t,this._state.depthRange.zFar=e,this._stateTracker.invalidateDepthWrite())}setStencilTestEnabled(t){this._state.stencilTest!==t&&(!0===t?this.gl.enable(this.gl.STENCIL_TEST):this.gl.disable(this.gl.STENCIL_TEST),this._state.stencilTest=t,this._stateTracker.invalidateStencilTest())}setClearStencil(t){t!==this._state.clearStencil&&(this.gl.clearStencil(t),this._state.clearStencil=t)}setStencilFunction(t,e,s){this._state.stencilFunction.func===t&&this._state.stencilFunction.ref===e&&this._state.stencilFunction.mask===s||(this.gl.stencilFunc(t,e,s),this._state.stencilFunction.face=1032,this._state.stencilFunction.func=t,this._state.stencilFunction.ref=e,this._state.stencilFunction.mask=s,this._stateTracker.invalidateStencilTest())}setStencilFunctionSeparate(t,e,s,i){this._state.stencilFunction.face===t&&this._state.stencilFunction.func===e&&this._state.stencilFunction.ref===s&&this._state.stencilFunction.mask===i||(this.gl.stencilFuncSeparate(t,e,s,i),this._state.stencilFunction.face=t,this._state.stencilFunction.func=e,this._state.stencilFunction.ref=s,this._state.stencilFunction.mask=i,this._stateTracker.invalidateStencilTest())}setStencilWriteMask(t){this._state.stencilWriteMask!==t&&(this.gl.stencilMask(t),this._state.stencilWriteMask=t,this._stateTracker.invalidateStencilWrite())}setStencilOp(t,e,s){1032===this._state.stencilOperation.face&&this._state.stencilOperation.fail===t&&this._state.stencilOperation.zFail===e&&this._state.stencilOperation.zPass===s||(this.gl.stencilOp(t,e,s),this._state.stencilOperation.face=1032,this._state.stencilOperation.fail=t,this._state.stencilOperation.zFail=e,this._state.stencilOperation.zPass=s,this._stateTracker.invalidateStencilTest())}setStencilOpSeparate(t,e,s,i){this._state.stencilOperation.face===t&&this._state.stencilOperation.fail===e&&this._state.stencilOperation.zFail===s&&this._state.stencilOperation.zPass===i||(this.gl.stencilOpSeparate(t,e,s,i),this._state.stencilOperation.face=t,this._state.stencilOperation.fail=e,this._state.stencilOperation.zFail=s,this._state.stencilOperation.zPass=i,this._stateTracker.invalidateStencilTest())}setActiveTexture(t,e=!1){const s=this._state.activeTexture;return t>=0&&(e||t!==this._state.activeTexture)&&(this.gl.activeTexture(u+t),this._state.activeTexture=t),s}setDrawBuffers(t){const{drawFramebuffer:e}=this._state,s=null===e,i=s?this._state.drawBuffers.defaultFramebuffer:this._state.drawBuffers.fbos.get(e)??[];if(i?.length===t.length&&i.every((e,s)=>e===t[s]))return i;if(t.length>this.parameters.maxDrawBuffers)return x().error(`Setting more active draw buffers (${t.length}) than GL.MAX_DRAW_BUFFERS allows ( ${this.parameters.maxDrawBuffers}).`),i;if(s){if(t.length>1)return x().error(`The default framebuffer can only have 1 active draw buffer but was requested with ${t.length}.`),i;if(t[0]!==o&&t[0]!==f)return x().error(`The default framebuffer can only use the constants GL.BACK or GL.NONE as draw buffers but got ${t[0]}`),i}else if(t.includes(o))return x().error("A framebuffer object can only use the constants GL.COLOR_ATTACHMENTx or GL.NONE as draw buffers."),i;return this.gl.drawBuffers(t),r(this.gl),s?this._state.drawBuffers.defaultFramebuffer=t:this._state.drawBuffers.fbos.set(e,t),i}clear(t,e=255){t&&(16384&t&&this.setColorMask(!0,!0,!0,!0),256&t&&this.setDepthWriteEnabled(!0),1024&t&&this.setStencilWriteMask(e),this.gl.clear(t))}clearFramebuffer(t,e=!1,s=!1){let i=0;if(t){const e=1e-13,s=Math.max(e,t[3]);this.setClearColor(t[0],t[1],t[2],s),i|=16384}e&&(i|=256),!1===s?s=0:(!0===s&&(s=255),i|=1024),i&&this.clear(i,s)}clearBuffer(t,e,s=6144,i=void 0){this.gl.clearBufferfv(s,t,e,i)}clearBufferInteger(t,e,s=6144,i=void 0){this.gl.clearBufferiv(s,t,e,i)}clearBufferUnsignedInteger(t,e,s=6144,i=void 0){this.gl.clearBufferuiv(s,t,e,i)}drawArrays(t,e,s){if(this._transformFeedbackRequestInfo){if(t!==this._transformFeedbackRequestInfo.primitiveType)throw new Error("DrawArrays called during transform feedback, but primitiveType does not match that of the current transform feedback request");if(null==this._state.program?.hasTransformFeedbackVaryings)throw new Error("DrawArrays called during transform feedback, but the shader program was not linked with a transform feedback varying")}if(a()&&(this._numOfDrawCalls++,this._numOfTriangles+=E(t,s),has("enable-feature:webgl-debug:textureReadWrite"))){const t=this._state.textureUnitMap;for(let e=0;e<t.length;e++){const s=t[e];if(null!=s&&s===this._state.drawFramebuffer?.colorTexture)throw new Error(`Detected readWrite. Texture already bound at index ${e}`)}}this.gl.drawArrays(t,e,s),r(this.gl)}drawArraysInstanced(t,e,s,i){this.gl.drawArraysInstanced(t,e,s,i),r(this.gl)}drawElements(t,e,s,i){if(this._transformFeedbackRequestInfo)throw new Error("Cannot called drawElements during a transform feedback request");if(a()&&(this._numOfDrawCalls++,this._numOfTriangles+=E(t,e)),this.gl.drawElements(t,e,s,i),a()){const a=n(this.gl);if(a){const r=this.getBoundVAO(),n=r?.indexBuffer,l=r?.buffers,h={indexBuffer:n,vertexBuffers:l},f={mode:t,count:e,type:s,offset:i},o=n?.size??0,u=i+e,c=o<u?`. Buffer is too small. Attempted to draw index ${u} of ${o}`:"";x().error(`drawElements: ${a}${c}`,{args:f,vao:h})}}}drawElementsInstanced(t,e,s,i,a){this.gl.drawElementsInstanced(t,e,s,i,a),r(this.gl)}logInfo(){a()&&console.log(`DrawCalls: ${this._numOfDrawCalls}, Triangles: ${this._numOfTriangles}`)}resetInfo(){a()&&(this._numOfDrawCalls=0,this._numOfTriangles=0)}get capabilities(){return this._capabilities}setViewport(t,e,s,i){s=Math.max(Math.round(s),1),i=Math.max(Math.round(i),1);const a=this._state.viewport;a.x===t&&a.y===e&&a.width===s&&a.height===i||(a.x=t,a.y=e,a.width=s,a.height=i,this.gl.viewport(t,e,s,i))}setViewport4fv(t){this.setViewport(t[0],t[1],t[2],t[3])}restoreViewport({x:t,y:e,width:s,height:i}){this.setViewport(t,e,s,i)}getViewport(){const t=this._state.viewport;return{x:t.x,y:t.y,width:t.width,height:t.height}}useProgram(t){if(this._state.program!==t){if(t&&null==t.glName&&l())throw new Error("Attempting to use disposed or invalid Program");this._state.program?.stop(),this._state.program=t,this.gl.useProgram(t?.glName??null)}}bindTexture(t,e,s=!1){(e>=this.parameters.maxTextureImageUnits||e<0)&&x().error(`Input texture unit (${e}) is out of range of available units (0...${this.parameters.maxTextureImageUnits})\n `);const i=this._state.textureUnitMap[e];return null==t?.glName?(null!=i&&(this.setActiveTexture(e,s),this.gl.bindTexture(i.descriptor.target,null)),this._state.textureUnitMap[e]=null,i):s||i!==t?(this.setActiveTexture(e,s),this.gl.bindTexture(t.descriptor.target,t.glName),t.applyChanges(),this._state.textureUnitMap[e]=t,i):(t.isDirty&&(this.setActiveTexture(e,s),t.applyChanges()),i)}unbindTexture(t){if(null!=t)for(let e=0;e<this.parameters.maxTextureImageUnits;e++)this._state.textureUnitMap[e]===t&&(this.bindTexture(null,e),this._state.textureUnitMap[e]=null)}bindFramebuffer(t,e=!1){const s=C(t);if(e||this._state.readFramebuffer!==t||this._state.drawFramebuffer!==t){if(null==t)return this.gl.bindFramebuffer(36160,null),this._state.readFramebuffer=this._state.drawFramebuffer=null,void this.setDrawBuffers(s);t.initializeAndBind(36160),this._state.readFramebuffer=t,this._state.drawFramebuffer=t,this.setDrawBuffers(s)}else this.setDrawBuffers(s)}bindFramebufferSeparate(t,e,s=!1){const i=36008===e,a=i?this._state.readFramebuffer:this._state.drawFramebuffer;(s||a!==t)&&(null==t?this.gl.bindFramebuffer(e,null):t.initializeAndBind(e),i?this._state.readFramebuffer=t??null:(this._state.drawFramebuffer=t??null,this.setDrawBuffers(C(t))))}blitFramebuffer(t,e,s=16384,i=9728,a=0,r=0,n=t.width,l=t.height,h=0,f=0,o=e.width,u=e.height){this.bindFramebufferSeparate(t,36008,!0),this.bindFramebufferSeparate(e,36009,!0),this.gl.blitFramebuffer(a,r,n,l,h,f,o,u,s,i)}bindBuffer(t,e){if(t)switch(e??=t.bufferType,e){case 34962:this._state.vertexBuffer=w(this.gl,t,e,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,t,e,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,t,e,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,t,e,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,t,e,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,t,e,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,t,e,this._state.copyWriteBuffer);break;case 35982:this._state.transformFeedbackBuffer=w(this.gl,t,e,this._state.transformFeedbackBuffer)}}bindRenderbuffer(t){const e=this.gl;t||(e.bindRenderbuffer(e.RENDERBUFFER,null),this._state.renderbuffer=null),this._state.renderbuffer!==t&&(e.bindRenderbuffer(e.RENDERBUFFER,t.glName),this._state.renderbuffer=t)}_getBufferBinding(t,e){if(e>=this.parameters.maxUniformBufferBindings||e<0)return x().error(`Uniform buffer binding point (${e}) is out of range (0...${this.parameters.maxUniformBufferBindings})\n `),null;const s=35345===t?this._state.uniformBufferBindingPoints:this._state.transformBufferBindingPoints;let i=s[e];return null==i&&(i={buffer:null,offset:0,size:0},s[e]=i),i}bindBufferBase(t,e,s){const i=this._getBufferBinding(t,e);null!=i&&(i.buffer===s&&0===i.offset&&0===i.size||(this.gl.bindBufferBase(t,e,s?s.glName:null),i.buffer=s,i.offset=0,i.size=0))}bindBufferRange(t,e,s,i,a){const r=this._getBufferBinding(t,e);null!=r&&(r.buffer===s&&r.offset===i&&r.size===a||(i%this._parameters.uniformBufferOffsetAlignment===0?(this.gl.bindBufferRange(t,e,s.glName,i,a),r.buffer=s,r.offset=i,r.size=a):x().error("Uniform buffer binding offset is not a multiple of the context offset alignment")))}bindUBO(t,e,s,i){null!=e?(a()&&(i??e.byteLength)>this._parameters.maxUniformBlockSize&&x().error("Attempting to bind more data than the maximum uniform block size"),e.initialize(),void 0!==s&&void 0!==i?this.bindBufferRange(35345,t,e.buffer,s,i):this.bindBufferBase(35345,t,e.buffer)):this.bindBufferBase(35345,t,null)}unbindUBO(t){for(let e=0,s=this._state.uniformBufferBindingPoints.length;e<s;e++){const s=this._state.uniformBufferBindingPoints[e];null!=s&&s.buffer===t.buffer&&this.bindBufferBase(35345,e,null)}}unbindBuffer(t){switch(t){case 34962:this._state.vertexBuffer=w(this.gl,null,t,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,null,t,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,null,t,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,null,t,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,null,t,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,null,t,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,null,t,this._state.copyWriteBuffer)}}bindVAO(t,e){if(null==t)return this._state.vertexArrayObject?.unbind(),void(this._state.vertexArrayObject=null);this._state.vertexArrayObject!==t&&(t.bind(e),this._state.vertexArrayObject=t)}bindTransformFeedback(t){const{gl:e}=this;e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,t.glName)}beginTransformFeedback(t,e){if(this._transformFeedbackRequestInfo)throw new Error("Already in a transform feedback request");const{gl:s}=this;s.bindTransformFeedback(s.TRANSFORM_FEEDBACK,t.glName),s.beginTransformFeedback(e),this._transformFeedbackRequestInfo={primitiveType:e}}endTransformFeedback(){if(!this._transformFeedbackRequestInfo)throw new Error("Not in a transform feedback request");const{gl:t}=this;t.endTransformFeedback(),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),this._transformFeedbackRequestInfo=null}async clientWaitAsync(t=i(10)){const{gl:e}=this,a=e.fenceSync(37143,0);if(!a)throw new Error("Client wait failed, could not create sync object");let r;this.instanceCounter.increment(c.Sync,a),e.flush();do{await s(t),r=e.clientWaitSync(a,0,0)}while(37147===r);if(this.instanceCounter.decrement(c.Sync,a),e.deleteSync(a),37149===r)throw new Error("Client wait failed")}getBoundFramebufferObject(t=36160){return 36008===t?this._state.readFramebuffer:this._state.drawFramebuffer}temporaryBindFramebufferObject(t,e,s=!1){const i=this.getBoundFramebufferObject();try{this.bindFramebuffer(t,s),e()}finally{this.bindFramebuffer(i,s)}}getBoundVAO(){return this._state.vertexArrayObject}resetState(){this.useProgram(null),this.bindVAO(null),this.bindFramebuffer(null,!0),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this._state.uniformBufferBindingPoints.length=0,this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663);for(let t=0;t<this.parameters.maxTextureImageUnits;++t)this.bindTexture(null,t);this.setBlendingEnabled(!1),this.setBlendFunction(1,0),this.setBlendEquation(32774),this.setBlendColor(0,0,0,0),this.setFaceCullingEnabled(!1),this.setCullFace(1029),this.setFrontFace(2305),this.setPolygonOffsetFillEnabled(!1),this.setPolygonOffset(0,0),this.setScissorTestEnabled(!1),this.setScissorRect(0,0,this.gl.canvas.width,this.gl.canvas.height),this.setDepthTestEnabled(!1),this.setDepthFunction(513),this.setDepthRange(0,1),this.setStencilTestEnabled(!1),this.setStencilFunction(519,0,0),this.setStencilOp(7680,7680,7680),this.setClearColor(0,0,0,0),this.setClearDepth(1),this.setClearStencil(0),this.setColorMask(!0,!0,!0,!0),this.setStencilWriteMask(4294967295),this.setDepthWriteEnabled(!0),this.setViewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}enforceState(){const{gl:t}=this;t.bindVertexArray(null);for(let s=0;s<this.parameters.maxVertexAttributes;s++)t.disableVertexAttribArray(s);this._state.vertexBuffer?t.bindBuffer(this._state.vertexBuffer.bufferType,this._state.vertexBuffer.glName):t.bindBuffer(34962,null),this._state.indexBuffer?t.bindBuffer(this._state.indexBuffer.bufferType,this._state.indexBuffer.glName):t.bindBuffer(34963,null),this._state.uniformBuffer?t.bindBuffer(this._state.uniformBuffer.bufferType,this._state.uniformBuffer.glName):t.bindBuffer(35345,null);for(let s=0;s<this._parameters.maxUniformBufferBindings;s++){const e=this._state.uniformBufferBindingPoints[s];if(null!=e){const{buffer:i,offset:a,size:r}=e;null!==i?0===a&&0===r?t.bindBufferBase(35345,s,i.glName):t.bindBufferRange(35345,s,i.glName,a,r):t.bindBufferBase(35345,s,null)}}if(this._state.pixelPackBuffer?t.bindBuffer(this._state.pixelPackBuffer.bufferType,this._state.pixelPackBuffer.glName):t.bindBuffer(35051,null),this._state.pixelUnpackBuffer?t.bindBuffer(this._state.pixelUnpackBuffer.bufferType,this._state.pixelUnpackBuffer.glName):t.bindBuffer(35052,null),this._state.copyReadBuffer?t.bindBuffer(this._state.copyReadBuffer.bufferType,this._state.copyReadBuffer.glName):t.bindBuffer(36662,null),this._state.copyWriteBuffer?t.bindBuffer(this._state.copyWriteBuffer.bufferType,this._state.copyWriteBuffer.glName):t.bindBuffer(36663,null),t.bindFramebuffer(36008,null),t.readBuffer(t.BACK),this._state.readFramebuffer&&(t.bindFramebuffer(36008,this._state.readFramebuffer.glName),t.readBuffer(d)),t.bindFramebuffer(36009,this._state.drawFramebuffer?.glName??null),null===this._state.drawFramebuffer){const e=this._state.drawBuffers.defaultFramebuffer;t.drawBuffers(e??[o])}else{const e=this._state.drawBuffers.fbos.get(this._state.drawFramebuffer);t.drawBuffers(e??[d])}if(this._state.vertexArrayObject){const t=this._state.vertexArrayObject;this._state.vertexArrayObject&&(this._state.vertexArrayObject.unbind(),this._state.vertexArrayObject=null),this.bindVAO(t)}t.useProgram(this._state.program?.glName??null),t.blendColor(this._state.blendColor.r,this._state.blendColor.g,this._state.blendColor.b,this._state.blendColor.a),t.bindRenderbuffer(t.RENDERBUFFER,this._state.renderbuffer?.glName??null),!0===this._state.blend?t.enable(this.gl.BLEND):t.disable(this.gl.BLEND),t.blendEquationSeparate(this._state.blendEquation.mode,this._state.blendEquation.modeAlpha),t.blendFuncSeparate(this._state.blendFunction.srcRGB,this._state.blendFunction.dstRGB,this._state.blendFunction.srcAlpha,this._state.blendFunction.dstAlpha),t.clearColor(this._state.clearColor.r,this._state.clearColor.g,this._state.clearColor.b,this._state.clearColor.a),t.clearDepth(this._state.clearDepth),t.clearStencil(this._state.clearStencil),t.colorMask(this._state.colorMask.r,this._state.colorMask.g,this._state.colorMask.b,this._state.colorMask.a),t.cullFace(this._state.cullFace),t.depthFunc(this._state.depthFunction),t.depthRange(this._state.depthRange.zNear,this._state.depthRange.zFar),!0===this._state.depthTest?t.enable(t.DEPTH_TEST):t.disable(t.DEPTH_TEST),t.depthMask(this._state.depthWrite),t.frontFace(this._state.frontFace),t.lineWidth(1),!0===this._state.faceCulling?t.enable(t.CULL_FACE):t.disable(t.CULL_FACE),t.polygonOffset(this._state.polygonOffset[0],this._state.polygonOffset[1]),!0===this._state.polygonOffsetFill?t.enable(t.POLYGON_OFFSET_FILL):t.disable(t.POLYGON_OFFSET_FILL),t.scissor(this._state.scissorRect.x,this._state.scissorRect.y,this._state.scissorRect.width,this._state.scissorRect.height),!0===this._state.scissorTest?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST),t.stencilFunc(this._state.stencilFunction.func,this._state.stencilFunction.ref,this._state.stencilFunction.mask),t.stencilOpSeparate(this._state.stencilOperation.face,this._state.stencilOperation.fail,this._state.stencilOperation.zFail,this._state.stencilOperation.zPass),!0===this._state.stencilTest?t.enable(t.STENCIL_TEST):t.disable(t.STENCIL_TEST),t.stencilMask(this._state.stencilWriteMask);for(let s=0;s<this.parameters.maxTextureImageUnits;s++){t.activeTexture(u+s),t.bindTexture(3553,null),t.bindTexture(34067,null),t.bindTexture(32879,null),t.bindTexture(35866,null);const e=this._state.textureUnitMap[s];null!=e&&t.bindTexture(e.descriptor.target,e.glName)}t.activeTexture(u+this._state.activeTexture);const e=this._state.viewport;t.viewport(e.x,e.y,e.width,e.height),this.resetInfo()}};function w(t,e,s,i){return e?i!==e&&t.bindBuffer(s,e.glName):t.bindBuffer(s,null),e}function E(t,e){switch(t){case _.POINTS:return 2*e;case _.TRIANGLES:return e/3;case _.TRIANGLE_STRIP:case _.TRIANGLE_FAN:return e-2;default:return 0}}function C(t){return t?t.colorAttachments.length>0?t.colorAttachments:[f]:[o]}export{k as RenderingContext,C as getFramebufferDrawBuffers};
2
+ import has from"../../core/has.js";import t from"../../core/Logger.js";import{disposeMaybe as e}from"../../core/maybe.js";import{after as s}from"../../core/promiseUtils.js";import{Milliseconds as i}from"../../core/time.js";import{webglDebugEnabled as a,checkWebGLError as r,getErrorMessage as n,webglValidateShadersEnabled as l}from"./checkWebGLError.js";import{ContextState as h}from"./ContextState.js";import{DrawBufferNone as f,DrawBufferBack as o,baseTextureUnit as u,ResourceType as c,ColorAttachment0 as d,PrimitiveType as _}from"./enums.js";import{InstanceCounter as b}from"./InstanceCounter.js";import{Parameters as g}from"./Parameters.js";import{ProgramCache as p}from"./ProgramCache.js";import{StateTracker as m}from"./renderState.js";import B from"./Texture.js";import{WebGLDriverTest as F}from"./WebGLDriverTest.js";import{Capabilities as T}from"./capabilities/Capabilities.js";const x=()=>t.getLogger("esri.views.webgl.RenderingContext");let k=class{constructor(t,e){this.gl=t,this.instanceCounter=new b,this._programCache=new p(this),this._transformFeedbackRequestInfo=null,this._state=new h,this._numOfDrawCalls=0,this._numOfTriangles=0,this._options=e,this.configure(e)}configure(t){this._options=t,this._capabilities=new T(this.gl,t),this._parameters=new g(this.gl,this._capabilities,t),B.TEXTURE_UNIT_FOR_UPDATES=this._parameters.maxTextureImageUnits-1;const s=this.gl.getParameter(this.gl.VIEWPORT);this._state=new h,this._state.viewport={x:s[0],y:s[1],width:s[2],height:s[3]},this._stateTracker=new m({setBlending:t=>{if(t){this.setBlendingEnabled(!0),this.setBlendEquationSeparate(t.opRgb,t.opAlpha),this.setBlendFunctionSeparate(t.srcRgb,t.dstRgb,t.srcAlpha,t.dstAlpha);const e=t.color;this.setBlendColor(e.r,e.g,e.b,e.a)}else this.setBlendingEnabled(!1)},setCulling:t=>{t?(this.setFaceCullingEnabled(!0),this.setCullFace(t.face),this.setFrontFace(t.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:t=>{t?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(t.factor,t.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:t=>{t?(this.setDepthTestEnabled(!0),this.setDepthFunction(t.func)):this.setDepthTestEnabled(!1)},setStencilTest:t=>{if(t){this.setStencilTestEnabled(!0);const e=t.function;this.setStencilFunction(e.func,e.ref,e.mask);const s=t.operation;this.setStencilOp(s.fail,s.zFail,s.zPass)}else this.setStencilTestEnabled(!1)},setDepthWrite:t=>{t?(this.setDepthWriteEnabled(!0),this.setDepthRange(t.zNear,t.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:t=>{t?this.setColorMask(t.r,t.g,t.b,t.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:t=>{t?this.setStencilWriteMask(t.mask):this.setStencilWriteMask(0)}}),this.enforceState(),e(this._driverTest),this._driverTest=new F(this)}updateOptions(t){this._options={...this._options,...t},this._parameters=new g(this.gl,this._capabilities,this._options)}dispose(){this._driverTest=e(this._driverTest),this._programCache=e(this._programCache),this.bindVAO(null),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this._state.uniformBufferBindingPoints.length=0,this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663),this._state.textureUnitMap.length=0,this._state=null,this._capabilities=null,this._stateTracker=null,a()&&this.instanceCounter.resourceInformation&&console.log(this.instanceCounter.resourceInformation)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}get programCache(){return this._programCache}setPipelineState(t){this._stateTracker.setPipeline(t)}getPipelineState(){return this._stateTracker.getPipelineState()}setBlendingEnabled(t){this._state.blend!==t&&(!0===t?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=t,this._stateTracker.invalidateBlending())}externalProgramUpdate(){this._state.program?.stop(),this._state.program=null}externalTextureUnitUpdate(t,e){for(let s=0;s<t.length;++s)this._state.textureUnitMap[t[s]]=null;e>=0&&(this._state.activeTexture=e)}externalVertexArrayObjectUpdate(){this.gl.bindVertexArray(null),this._state.vertexArrayObject=null,this._state.vertexBuffer=null,this._state.indexBuffer=null}externalVertexBufferUpdate(){this._state.vertexBuffer=null}externalIndexBufferUpdate(){this._state.indexBuffer=null}setBlendColor(t,e,s,i){t===this._state.blendColor.r&&e===this._state.blendColor.g&&s===this._state.blendColor.b&&i===this._state.blendColor.a||(this.gl.blendColor(t,e,s,i),this._state.blendColor.r=t,this._state.blendColor.g=e,this._state.blendColor.b=s,this._state.blendColor.a=i,this._stateTracker.invalidateBlending())}setBlendFunction(t,e){t===this._state.blendFunction.srcRGB&&e===this._state.blendFunction.dstRGB||(this.gl.blendFunc(t,e),this._state.blendFunction.srcRGB=t,this._state.blendFunction.srcAlpha=t,this._state.blendFunction.dstRGB=e,this._state.blendFunction.dstAlpha=e,this._stateTracker.invalidateBlending())}setBlendFunctionSeparate(t,e,s,i){this._state.blendFunction.srcRGB===t&&this._state.blendFunction.srcAlpha===s&&this._state.blendFunction.dstRGB===e&&this._state.blendFunction.dstAlpha===i||(this.gl.blendFuncSeparate(t,e,s,i),this._state.blendFunction.srcRGB=t,this._state.blendFunction.srcAlpha=s,this._state.blendFunction.dstRGB=e,this._state.blendFunction.dstAlpha=i,this._stateTracker.invalidateBlending())}setBlendEquation(t){this._state.blendEquation.mode!==t&&(this.gl.blendEquation(t),this._state.blendEquation.mode=t,this._state.blendEquation.modeAlpha=t,this._stateTracker.invalidateBlending())}setBlendEquationSeparate(t,e){this._state.blendEquation.mode===t&&this._state.blendEquation.modeAlpha===e||(this.gl.blendEquationSeparate(t,e),this._state.blendEquation.mode=t,this._state.blendEquation.modeAlpha=e,this._stateTracker.invalidateBlending())}setColorMask(t,e,s,i){this._state.colorMask.r===t&&this._state.colorMask.g===e&&this._state.colorMask.b===s&&this._state.colorMask.a===i||(this.gl.colorMask(t,e,s,i),this._state.colorMask.r=t,this._state.colorMask.g=e,this._state.colorMask.b=s,this._state.colorMask.a=i,this._stateTracker.invalidateColorWrite())}setClearColor(t,e,s,i){this._state.clearColor.r===t&&this._state.clearColor.g===e&&this._state.clearColor.b===s&&this._state.clearColor.a===i||(this.gl.clearColor(t,e,s,i),this._state.clearColor.r=t,this._state.clearColor.g=e,this._state.clearColor.b=s,this._state.clearColor.a=i)}setFaceCullingEnabled(t){this._state.faceCulling!==t&&(!0===t?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this._state.faceCulling=t,this._stateTracker.invalidateCulling())}setPolygonOffsetFillEnabled(t){this._state.polygonOffsetFill!==t&&(!0===t?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL),this._state.polygonOffsetFill=t,this._stateTracker.invalidatePolygonOffset())}setPolygonOffset(t,e){this._state.polygonOffset[0]===t&&this._state.polygonOffset[1]===e||(this._state.polygonOffset[0]=t,this._state.polygonOffset[1]=e,this.gl.polygonOffset(t,e),this._stateTracker.invalidatePolygonOffset())}setCullFace(t){this._state.cullFace!==t&&(this.gl.cullFace(t),this._state.cullFace=t,this._stateTracker.invalidateCulling())}setFrontFace(t){this._state.frontFace!==t&&(this.gl.frontFace(t),this._state.frontFace=t,this._stateTracker.invalidateCulling())}setScissorTestEnabled(t){this._state.scissorTest!==t&&(!0===t?this.gl.enable(this.gl.SCISSOR_TEST):this.gl.disable(this.gl.SCISSOR_TEST),this._state.scissorTest=t)}setScissorRect(t,e,s,i){this._state.scissorRect.x===t&&this._state.scissorRect.y===e&&this._state.scissorRect.width===s&&this._state.scissorRect.height===i||(this.gl.scissor(t,e,s,i),this._state.scissorRect.x=t,this._state.scissorRect.y=e,this._state.scissorRect.width=s,this._state.scissorRect.height=i)}setDepthTestEnabled(t){this._state.depthTest!==t&&(!0===t?this.gl.enable(this.gl.DEPTH_TEST):this.gl.disable(this.gl.DEPTH_TEST),this._state.depthTest=t,this._stateTracker.invalidateDepthTest())}setClearDepth(t){this._state.clearDepth!==t&&(this.gl.clearDepth(t),this._state.clearDepth=t)}setDepthFunction(t){this._state.depthFunction!==t&&(this.gl.depthFunc(t),this._state.depthFunction=t,this._stateTracker.invalidateDepthTest())}setDepthWriteEnabled(t){this._state.depthWrite!==t&&(this.gl.depthMask(t),this._state.depthWrite=t,this._stateTracker.invalidateDepthWrite())}setDepthRange(t,e){this._state.depthRange.zNear===t&&this._state.depthRange.zFar===e||(this.gl.depthRange(t,e),this._state.depthRange.zNear=t,this._state.depthRange.zFar=e,this._stateTracker.invalidateDepthWrite())}setStencilTestEnabled(t){this._state.stencilTest!==t&&(!0===t?this.gl.enable(this.gl.STENCIL_TEST):this.gl.disable(this.gl.STENCIL_TEST),this._state.stencilTest=t,this._stateTracker.invalidateStencilTest())}setClearStencil(t){t!==this._state.clearStencil&&(this.gl.clearStencil(t),this._state.clearStencil=t)}setStencilFunction(t,e,s){this._state.stencilFunction.func===t&&this._state.stencilFunction.ref===e&&this._state.stencilFunction.mask===s||(this.gl.stencilFunc(t,e,s),this._state.stencilFunction.face=1032,this._state.stencilFunction.func=t,this._state.stencilFunction.ref=e,this._state.stencilFunction.mask=s,this._stateTracker.invalidateStencilTest())}setStencilFunctionSeparate(t,e,s,i){this._state.stencilFunction.face===t&&this._state.stencilFunction.func===e&&this._state.stencilFunction.ref===s&&this._state.stencilFunction.mask===i||(this.gl.stencilFuncSeparate(t,e,s,i),this._state.stencilFunction.face=t,this._state.stencilFunction.func=e,this._state.stencilFunction.ref=s,this._state.stencilFunction.mask=i,this._stateTracker.invalidateStencilTest())}setStencilWriteMask(t){this._state.stencilWriteMask!==t&&(this.gl.stencilMask(t),this._state.stencilWriteMask=t,this._stateTracker.invalidateStencilWrite())}setStencilOp(t,e,s){1032===this._state.stencilOperation.face&&this._state.stencilOperation.fail===t&&this._state.stencilOperation.zFail===e&&this._state.stencilOperation.zPass===s||(this.gl.stencilOp(t,e,s),this._state.stencilOperation.face=1032,this._state.stencilOperation.fail=t,this._state.stencilOperation.zFail=e,this._state.stencilOperation.zPass=s,this._stateTracker.invalidateStencilTest())}setStencilOpSeparate(t,e,s,i){this._state.stencilOperation.face===t&&this._state.stencilOperation.fail===e&&this._state.stencilOperation.zFail===s&&this._state.stencilOperation.zPass===i||(this.gl.stencilOpSeparate(t,e,s,i),this._state.stencilOperation.face=t,this._state.stencilOperation.fail=e,this._state.stencilOperation.zFail=s,this._state.stencilOperation.zPass=i,this._stateTracker.invalidateStencilTest())}setActiveTexture(t,e=!1){const s=this._state.activeTexture;return t>=0&&(e||t!==this._state.activeTexture)&&(this.gl.activeTexture(u+t),this._state.activeTexture=t),s}setDrawBuffers(t){const{drawFramebuffer:e}=this._state,s=null===e,i=s?this._state.drawBuffers.defaultFramebuffer:this._state.drawBuffers.fbos.get(e)??[];if(i?.length===t.length&&i.every((e,s)=>e===t[s]))return i;if(t.length>this.parameters.maxDrawBuffers)return x().error(`Setting more active draw buffers (${t.length}) than GL.MAX_DRAW_BUFFERS allows ( ${this.parameters.maxDrawBuffers}).`),i;if(s){if(t.length>1)return x().error(`The default framebuffer can only have 1 active draw buffer but was requested with ${t.length}.`),i;if(t[0]!==o&&t[0]!==f)return x().error(`The default framebuffer can only use the constants GL.BACK or GL.NONE as draw buffers but got ${t[0]}`),i}else if(t.includes(o))return x().error("A framebuffer object can only use the constants GL.COLOR_ATTACHMENTx or GL.NONE as draw buffers."),i;return this.gl.drawBuffers(t),r(this.gl),s?this._state.drawBuffers.defaultFramebuffer=t:this._state.drawBuffers.fbos.set(e,t),i}clear(t,e=255){t&&(16384&t&&this.setColorMask(!0,!0,!0,!0),256&t&&this.setDepthWriteEnabled(!0),1024&t&&this.setStencilWriteMask(e),this.gl.clear(t))}clearFramebuffer(t,e=!1,s=!1){let i=0;if(t){const e=1e-13,s=Math.max(e,t[3]);this.setClearColor(t[0],t[1],t[2],s),i|=16384}e&&(i|=256),!1===s?s=0:(!0===s&&(s=255),i|=1024),i&&this.clear(i,s)}clearBuffer(t,e,s=6144,i){this.gl.clearBufferfv(s,t,e,i)}clearBufferInteger(t,e,s=6144,i){this.gl.clearBufferiv(s,t,e,i)}clearBufferUnsignedInteger(t,e,s=6144,i){this.gl.clearBufferuiv(s,t,e,i)}drawArrays(t,e,s){if(this._transformFeedbackRequestInfo){if(t!==this._transformFeedbackRequestInfo.primitiveType)throw new Error("DrawArrays called during transform feedback, but primitiveType does not match that of the current transform feedback request");if(null==this._state.program?.hasTransformFeedbackVaryings)throw new Error("DrawArrays called during transform feedback, but the shader program was not linked with a transform feedback varying")}if(a()&&(this._numOfDrawCalls++,this._numOfTriangles+=E(t,s),has("enable-feature:webgl-debug:textureReadWrite"))){const t=this._state.textureUnitMap;for(let e=0;e<t.length;e++){const s=t[e];if(null!=s&&s===this._state.drawFramebuffer?.colorTexture)throw new Error(`Detected readWrite. Texture already bound at index ${e}`)}}this.gl.drawArrays(t,e,s),r(this.gl)}drawArraysInstanced(t,e,s,i){this.gl.drawArraysInstanced(t,e,s,i),r(this.gl)}drawElements(t,e,s,i){if(this._transformFeedbackRequestInfo)throw new Error("Cannot called drawElements during a transform feedback request");if(a()&&(this._numOfDrawCalls++,this._numOfTriangles+=E(t,e)),this.gl.drawElements(t,e,s,i),a()){const a=n(this.gl);if(a){const r=this.getBoundVAO(),n=r?.indexBuffer,l=r?.buffers,h={indexBuffer:n,vertexBuffers:l},f={mode:t,count:e,type:s,offset:i},o=n?.size??0,u=i+e,c=o<u?`. Buffer is too small. Attempted to draw index ${u} of ${o}`:"";x().error(`drawElements: ${a}${c}`,{args:f,vao:h})}}}drawElementsInstanced(t,e,s,i,a){this.gl.drawElementsInstanced(t,e,s,i,a),r(this.gl)}logInfo(){a()&&console.log(`DrawCalls: ${this._numOfDrawCalls}, Triangles: ${this._numOfTriangles}`)}resetInfo(){a()&&(this._numOfDrawCalls=0,this._numOfTriangles=0)}get capabilities(){return this._capabilities}setViewport(t,e,s,i){s=Math.max(Math.round(s),1),i=Math.max(Math.round(i),1);const a=this._state.viewport;a.x===t&&a.y===e&&a.width===s&&a.height===i||(a.x=t,a.y=e,a.width=s,a.height=i,this.gl.viewport(t,e,s,i))}setViewport4fv(t){this.setViewport(t[0],t[1],t[2],t[3])}restoreViewport({x:t,y:e,width:s,height:i}){this.setViewport(t,e,s,i)}getViewport(){const t=this._state.viewport;return{x:t.x,y:t.y,width:t.width,height:t.height}}useProgram(t){if(this._state.program!==t){if(t&&null==t.glName&&l())throw new Error("Attempting to use disposed or invalid Program");this._state.program?.stop(),this._state.program=t,this.gl.useProgram(t?.glName??null)}}bindTexture(t,e,s=!1){(e>=this.parameters.maxTextureImageUnits||e<0)&&x().error(`Input texture unit (${e}) is out of range of available units (0...${this.parameters.maxTextureImageUnits})\n `);const i=this._state.textureUnitMap[e];return null==t?.glName?(null!=i&&(this.setActiveTexture(e,s),this.gl.bindTexture(i.descriptor.target,null)),this._state.textureUnitMap[e]=null,i):s||i!==t?(this.setActiveTexture(e,s),this.gl.bindTexture(t.descriptor.target,t.glName),t.applyChanges(),this._state.textureUnitMap[e]=t,i):(t.isDirty&&(this.setActiveTexture(e,s),t.applyChanges()),i)}unbindTexture(t){if(null!=t)for(let e=0;e<this.parameters.maxTextureImageUnits;e++)this._state.textureUnitMap[e]===t&&(this.bindTexture(null,e),this._state.textureUnitMap[e]=null)}bindFramebuffer(t,e=!1){const s=C(t);if(e||this._state.readFramebuffer!==t||this._state.drawFramebuffer!==t){if(null==t)return this.gl.bindFramebuffer(36160,null),this._state.readFramebuffer=this._state.drawFramebuffer=null,void this.setDrawBuffers(s);t.initializeAndBind(36160),this._state.readFramebuffer=t,this._state.drawFramebuffer=t,this.setDrawBuffers(s)}else this.setDrawBuffers(s)}bindFramebufferSeparate(t,e,s=!1){const i=36008===e,a=i?this._state.readFramebuffer:this._state.drawFramebuffer;(s||a!==t)&&(null==t?this.gl.bindFramebuffer(e,null):t.initializeAndBind(e),i?this._state.readFramebuffer=t??null:(this._state.drawFramebuffer=t??null,this.setDrawBuffers(C(t))))}blitFramebuffer(t,e,s=16384,i=9728,a=0,r=0,n=t.width,l=t.height,h=0,f=0,o=e.width,u=e.height){this.bindFramebufferSeparate(t,36008,!0),this.bindFramebufferSeparate(e,36009,!0),this.gl.blitFramebuffer(a,r,n,l,h,f,o,u,s,i)}bindBuffer(t,e){if(t)switch(e??=t.bufferType,e){case 34962:this._state.vertexBuffer=w(this.gl,t,e,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,t,e,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,t,e,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,t,e,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,t,e,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,t,e,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,t,e,this._state.copyWriteBuffer);break;case 35982:this._state.transformFeedbackBuffer=w(this.gl,t,e,this._state.transformFeedbackBuffer)}}bindRenderbuffer(t){const e=this.gl;t||(e.bindRenderbuffer(e.RENDERBUFFER,null),this._state.renderbuffer=null),this._state.renderbuffer!==t&&(e.bindRenderbuffer(e.RENDERBUFFER,t.glName),this._state.renderbuffer=t)}_getBufferBinding(t,e){if(e>=this.parameters.maxUniformBufferBindings||e<0)return x().error(`Uniform buffer binding point (${e}) is out of range (0...${this.parameters.maxUniformBufferBindings})\n `),null;const s=35345===t?this._state.uniformBufferBindingPoints:this._state.transformBufferBindingPoints;let i=s[e];return null==i&&(i={buffer:null,offset:0,size:0},s[e]=i),i}bindBufferBase(t,e,s){const i=this._getBufferBinding(t,e);null!=i&&(i.buffer===s&&0===i.offset&&0===i.size||(this.gl.bindBufferBase(t,e,s?s.glName:null),i.buffer=s,i.offset=0,i.size=0))}bindBufferRange(t,e,s,i,a){const r=this._getBufferBinding(t,e);null!=r&&(r.buffer===s&&r.offset===i&&r.size===a||(i%this._parameters.uniformBufferOffsetAlignment===0?(this.gl.bindBufferRange(t,e,s.glName,i,a),r.buffer=s,r.offset=i,r.size=a):x().error("Uniform buffer binding offset is not a multiple of the context offset alignment")))}bindUBO(t,e,s,i){null!=e?(a()&&(i??e.byteLength)>this._parameters.maxUniformBlockSize&&x().error("Attempting to bind more data than the maximum uniform block size"),e.initialize(),void 0!==s&&void 0!==i?this.bindBufferRange(35345,t,e.buffer,s,i):this.bindBufferBase(35345,t,e.buffer)):this.bindBufferBase(35345,t,null)}unbindUBO(t){for(let e=0,s=this._state.uniformBufferBindingPoints.length;e<s;e++){const s=this._state.uniformBufferBindingPoints[e];null!=s&&s.buffer===t.buffer&&this.bindBufferBase(35345,e,null)}}unbindBuffer(t){switch(t){case 34962:this._state.vertexBuffer=w(this.gl,null,t,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,null,t,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,null,t,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,null,t,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,null,t,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,null,t,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,null,t,this._state.copyWriteBuffer)}}bindVAO(t,e){if(null==t)return this._state.vertexArrayObject?.unbind(),void(this._state.vertexArrayObject=null);this._state.vertexArrayObject!==t&&(t.bind(e),this._state.vertexArrayObject=t)}bindTransformFeedback(t){const{gl:e}=this;e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,t.glName)}beginTransformFeedback(t,e){if(this._transformFeedbackRequestInfo)throw new Error("Already in a transform feedback request");const{gl:s}=this;s.bindTransformFeedback(s.TRANSFORM_FEEDBACK,t.glName),s.beginTransformFeedback(e),this._transformFeedbackRequestInfo={primitiveType:e}}endTransformFeedback(){if(!this._transformFeedbackRequestInfo)throw new Error("Not in a transform feedback request");const{gl:t}=this;t.endTransformFeedback(),t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null),this._transformFeedbackRequestInfo=null}async clientWaitAsync(t=i(10)){const{gl:e}=this,a=e.fenceSync(37143,0);if(!a)throw new Error("Client wait failed, could not create sync object");let r;this.instanceCounter.increment(c.Sync,a),e.flush();do{await s(t),r=e.clientWaitSync(a,0,0)}while(37147===r);if(this.instanceCounter.decrement(c.Sync,a),e.deleteSync(a),37149===r)throw new Error("Client wait failed")}getBoundFramebufferObject(t=36160){return 36008===t?this._state.readFramebuffer:this._state.drawFramebuffer}temporaryBindFramebufferObject(t,e,s=!1){const i=this.getBoundFramebufferObject();try{this.bindFramebuffer(t,s),e()}finally{this.bindFramebuffer(i,s)}}getBoundVAO(){return this._state.vertexArrayObject}resetState(){this.useProgram(null),this.bindVAO(null),this.bindFramebuffer(null,!0),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this._state.uniformBufferBindingPoints.length=0,this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663);for(let t=0;t<this.parameters.maxTextureImageUnits;++t)this.bindTexture(null,t);this.setBlendingEnabled(!1),this.setBlendFunction(1,0),this.setBlendEquation(32774),this.setBlendColor(0,0,0,0),this.setFaceCullingEnabled(!1),this.setCullFace(1029),this.setFrontFace(2305),this.setPolygonOffsetFillEnabled(!1),this.setPolygonOffset(0,0),this.setScissorTestEnabled(!1),this.setScissorRect(0,0,this.gl.canvas.width,this.gl.canvas.height),this.setDepthTestEnabled(!1),this.setDepthFunction(513),this.setDepthRange(0,1),this.setStencilTestEnabled(!1),this.setStencilFunction(519,0,0),this.setStencilOp(7680,7680,7680),this.setClearColor(0,0,0,0),this.setClearDepth(1),this.setClearStencil(0),this.setColorMask(!0,!0,!0,!0),this.setStencilWriteMask(4294967295),this.setDepthWriteEnabled(!0),this.setViewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}enforceState(){const{gl:t}=this;t.bindVertexArray(null);for(let s=0;s<this.parameters.maxVertexAttributes;s++)t.disableVertexAttribArray(s);this._state.vertexBuffer?t.bindBuffer(this._state.vertexBuffer.bufferType,this._state.vertexBuffer.glName):t.bindBuffer(34962,null),this._state.indexBuffer?t.bindBuffer(this._state.indexBuffer.bufferType,this._state.indexBuffer.glName):t.bindBuffer(34963,null),this._state.uniformBuffer?t.bindBuffer(this._state.uniformBuffer.bufferType,this._state.uniformBuffer.glName):t.bindBuffer(35345,null);for(let s=0;s<this._parameters.maxUniformBufferBindings;s++){const e=this._state.uniformBufferBindingPoints[s];if(null!=e){const{buffer:i,offset:a,size:r}=e;null!==i?0===a&&0===r?t.bindBufferBase(35345,s,i.glName):t.bindBufferRange(35345,s,i.glName,a,r):t.bindBufferBase(35345,s,null)}}if(this._state.pixelPackBuffer?t.bindBuffer(this._state.pixelPackBuffer.bufferType,this._state.pixelPackBuffer.glName):t.bindBuffer(35051,null),this._state.pixelUnpackBuffer?t.bindBuffer(this._state.pixelUnpackBuffer.bufferType,this._state.pixelUnpackBuffer.glName):t.bindBuffer(35052,null),this._state.copyReadBuffer?t.bindBuffer(this._state.copyReadBuffer.bufferType,this._state.copyReadBuffer.glName):t.bindBuffer(36662,null),this._state.copyWriteBuffer?t.bindBuffer(this._state.copyWriteBuffer.bufferType,this._state.copyWriteBuffer.glName):t.bindBuffer(36663,null),t.bindFramebuffer(36008,null),t.readBuffer(t.BACK),this._state.readFramebuffer&&(t.bindFramebuffer(36008,this._state.readFramebuffer.glName),t.readBuffer(d)),t.bindFramebuffer(36009,this._state.drawFramebuffer?.glName??null),null===this._state.drawFramebuffer){const e=this._state.drawBuffers.defaultFramebuffer;t.drawBuffers(e??[o])}else{const e=this._state.drawBuffers.fbos.get(this._state.drawFramebuffer);t.drawBuffers(e??[d])}if(this._state.vertexArrayObject){const t=this._state.vertexArrayObject;this._state.vertexArrayObject&&(this._state.vertexArrayObject.unbind(),this._state.vertexArrayObject=null),this.bindVAO(t)}t.useProgram(this._state.program?.glName??null),t.blendColor(this._state.blendColor.r,this._state.blendColor.g,this._state.blendColor.b,this._state.blendColor.a),t.bindRenderbuffer(t.RENDERBUFFER,this._state.renderbuffer?.glName??null),!0===this._state.blend?t.enable(this.gl.BLEND):t.disable(this.gl.BLEND),t.blendEquationSeparate(this._state.blendEquation.mode,this._state.blendEquation.modeAlpha),t.blendFuncSeparate(this._state.blendFunction.srcRGB,this._state.blendFunction.dstRGB,this._state.blendFunction.srcAlpha,this._state.blendFunction.dstAlpha),t.clearColor(this._state.clearColor.r,this._state.clearColor.g,this._state.clearColor.b,this._state.clearColor.a),t.clearDepth(this._state.clearDepth),t.clearStencil(this._state.clearStencil),t.colorMask(this._state.colorMask.r,this._state.colorMask.g,this._state.colorMask.b,this._state.colorMask.a),t.cullFace(this._state.cullFace),t.depthFunc(this._state.depthFunction),t.depthRange(this._state.depthRange.zNear,this._state.depthRange.zFar),!0===this._state.depthTest?t.enable(t.DEPTH_TEST):t.disable(t.DEPTH_TEST),t.depthMask(this._state.depthWrite),t.frontFace(this._state.frontFace),t.lineWidth(1),!0===this._state.faceCulling?t.enable(t.CULL_FACE):t.disable(t.CULL_FACE),t.polygonOffset(this._state.polygonOffset[0],this._state.polygonOffset[1]),!0===this._state.polygonOffsetFill?t.enable(t.POLYGON_OFFSET_FILL):t.disable(t.POLYGON_OFFSET_FILL),t.scissor(this._state.scissorRect.x,this._state.scissorRect.y,this._state.scissorRect.width,this._state.scissorRect.height),!0===this._state.scissorTest?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST),t.stencilFunc(this._state.stencilFunction.func,this._state.stencilFunction.ref,this._state.stencilFunction.mask),t.stencilOpSeparate(this._state.stencilOperation.face,this._state.stencilOperation.fail,this._state.stencilOperation.zFail,this._state.stencilOperation.zPass),!0===this._state.stencilTest?t.enable(t.STENCIL_TEST):t.disable(t.STENCIL_TEST),t.stencilMask(this._state.stencilWriteMask);for(let s=0;s<this.parameters.maxTextureImageUnits;s++){t.activeTexture(u+s),t.bindTexture(3553,null),t.bindTexture(34067,null),t.bindTexture(32879,null),t.bindTexture(35866,null);const e=this._state.textureUnitMap[s];null!=e&&t.bindTexture(e.descriptor.target,e.glName)}t.activeTexture(u+this._state.activeTexture);const e=this._state.viewport;t.viewport(e.x,e.y,e.width,e.height),this.resetInfo()}};function w(t,e,s,i){return e?i!==e&&t.bindBuffer(s,e.glName):t.bindBuffer(s,null),e}function E(t,e){switch(t){case _.POINTS:return 2*e;case _.TRIANGLES:return e/3;case _.TRIANGLE_STRIP:case _.TRIANGLE_FAN:return e-2;default:return 0}}function C(t){return t?t.colorAttachments.length>0?t.colorAttachments:[f]:[o]}export{k as RenderingContext,C as getFramebufferDrawBuffers};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import{createTask as i}from"../../core/asyncUtils.js";import o from"../../core/Collection.js";import{deprecatedFunction as r}from"../../core/deprecate.js";import s from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import{abortHandle as n,makeHandle as l}from"../../core/handleUtils.js";import"../../core/has.js";import c from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as p,removeMaybe as h}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as w}from"../../core/promiseUtils.js";import f from"../../core/ReactiveMap.js";import{watch as m,syncAndInitial as y,initial as g,on as k,when as v,sync as _,whenOnce as W}from"../../core/reactiveUtils.js";import{property as M,subclass as T}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as F}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as b}from"../../editing/templateUtils.js";import{getGraphicLayer as V}from"../../graphic/graphicOriginUtils.js";import S from"../../layers/GraphicsLayer.js";import{isEditableLayer as I}from"../../layers/support/editableLayers.js";import{isFeatureLayer as L,isSubtypeGroupLayer as E,getOwningPortalUrl as C}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as A}from"../../portal/support/urlUtils.js";import U from"../../views/SelectionManager.js";import O from"../../views/interactive/sketch/SketchLabelOptions.js";import j from"../../views/interactive/sketch/SketchOptions.js";import P from"../../views/interactive/sketch/SketchTooltipOptions.js";import R from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as H}from"../../views/interactive/snapping/SnappingManager.js";import q from"../../views/interactive/snapping/SnappingOptions.js";import{isISelectableLayer as x}from"../../views/support/selectionUtils.js";import G from"../Attachments/AttachmentsViewModel.js";import D from"./CreateFeaturesWorkflow.js";import B from"./UpdateWorkflow.js";import{getLayersFromWorkflow as N,isCreateFeaturesWorkflow as Q,isUpdateRecordWorkflow as z,isUpdateFeaturesWorkflow as Z,isMergeFeaturesWorkflow as $,isSplitFeatureWorkflow as J,isUpdateWorkflow as K,isFeatureFormViewModel as X,findEditorItemForLayerOrThrow as Y,toFeatureInfos as ee,fetchFullFeaturesByObjectId as te,fetchFullFeatures as ie,findEditorItemForLayer as oe,whenEditorLayerView as re,isBatchAttributeFormViewModel as se}from"./workflowUtils.js";import ae from"./support/EditorItem.js";import{assertViewNot3D as ne,MultipleSourceLayersError as le,InsufficientFeatureCountError as ce,MissingOriginLayerError as de,assertMergeWorkflowCapabilities as pe,FetchFullFeatureError as he,assertSplitWorkflowCapabilities as ue}from"./support/errors.js";import{makeTemplateGroupInfoForLayer as we}from"../FeatureTemplates/featureTemplatesUtils.js";import fe from"../FeatureTemplates/FeatureTemplatesViewModel.js";import me from"../Sketch/SketchViewModel.js";import ye from"../Spinner/SpinnerViewModel.js";import{goTo as ge}from"../support/goToUtils.js";import{isFeatureItem as ke,isLayerItem as ve}from"../support/SelectionList/selectionListUtils.js";import _e from"../support/SelectionList/SelectionListViewModel.js";import We from"../support/SelectionToolbar/SelectionToolbarViewModel.js";function Me(e,t){return e?.find(e=>e.layer===t)}let Te=class extends a{constructor(e){super(e),this._defaultSelectionManager=new U,this._queuedSelectionTool=null,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new S({listMode:"hide",internal:!0,title:"Editor sketch layer"}),this._snappingManager=null,this._templatesByLayer=new Map,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new F,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new o,this.editorItems=new o,this.editorItemsLayerMap=new f,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new G({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new fe({disabledItemFunction:({layer:e})=>this._itemIsSuspended(e)}),this.layerInfos=null,this.ownSketchViewModel=new me({layer:this._sketchGraphicsLayer,useLegacyCreateTools:this._get("useLegacyCreateTools")??!0}),this.selectionListViewModel=new _e,this.selectionManager=null,this.selectionToolbarViewModel=new We({continuousSelectionEnabled:!0,defaultOperationType:"replace",persistSelection:!1,returnGeometry:!1}),this.sketchOptions=new j,this.snappingOptions=new q({attributeRulesEnabled:!0}),this.spinnerViewModel=new ye,this.syncViewSelection=!1,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this.showConfirmationPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{if("viewing-selection-list"===this.state)return this.selectionListViewModel.filterText=void 0,void this.effectiveSelectionManager.clear();this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>await(this.activeWorkflow?.save(this.showConfirmationPrompt)),this.selectFeature=(e,t=!1)=>{const i=this.activeWorkflow;if(this._candidateCommitted||"update"!==i?.type)return;const{rootFeatures:o}=i.data;o.removeAll(),e&&o.add(e),t&&(i.next(),this._candidateCommitted=!0)}}initialize(){this.addHandles([m(()=>{const e=this.view,t=e?.map?.editableLayers.toArray(),i=e?.allLayerViews,o=i?.filter(e=>!!t?.includes(e.layer));return[t,o,this.layerInfos]},()=>this._updateEditorItems(),y),m(()=>this.hideTemplatesForInactiveLayers,()=>this.syncFeatureTemplates()),m(()=>this._selectionSources,()=>this._syncSelectionSources(),g),k(()=>this.activeWorkflow,"cancel",()=>this.emit("workflow-cancel")),k(()=>this.activeWorkflow,"commit",()=>this.emit("workflow-commit")),k(()=>this.activeWorkflow,"complete",()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)}),v(()=>!this.activeWorkflow&&this._queuedSelectionTool,()=>this._queuedSelectionTool&&this.selectionToolbarViewModel.activateTool(this._queuedSelectionTool)),m(()=>this.activeWorkflow,e=>this._defaultSelectionManager.highlightEnabled=!e),v(()=>this.view?.map,e=>e.add(this._sketchGraphicsLayer),g),k(()=>this.editorItems,"change",()=>this._afterEditorItemsChange()),m(()=>[this.canCreate,this.canUpdateVisible],()=>this._afterEditorItemsChange()),m(()=>this.page,(e,t)=>{const i=[...this.pageStack];if(-1===i.indexOf(e))i.push(e);else for(;i.length&&i.at(-1)!==e;)i.pop();this.pageStack=i},y),v(()=>"awaiting-update-feature-candidate"===this.state,()=>this._candidateCommitted=!1),k(()=>this.featureTemplatesViewModel,"select",async({item:e,oldItem:t})=>{const{activeWorkflow:i}=this;if(i){if("update"===i.type&&"awaiting-feature-creation-info"===i.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(t,{emit:!1})}}if(!e)return;const o={layer:e.layer,template:e.template};if(e.supportsUpload)return this.featureTemplatesViewModel.select(t,{emit:!1}),this.startCreateFeaturesWorkflow(o);await this.startCreateFeaturesWorkflowAtFeatureCreation(o)}),m(()=>[this.view,this.featureTemplatesViewModel],([e,t])=>{t.view=e},y),k(()=>this.view,"key-down",e=>{"Escape"===e.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(e.stopPropagation(),this.back())}),k(()=>this.sketchViewModel,["create","delete","update"],e=>{const{activeWorkflow:t}=this,i=N(t),o=`sketch-${e.type}`;this.emit(o,{type:o,detail:e,layer:i[0],layers:i})},_),m(()=>this.view,e=>{if(this._snappingManager=d(this._snappingManager),!e)return;const t=this.snappingOptions;this._snappingManager=new H({view:e,options:t}),this.ownSketchViewModel.snappingManager=this._snappingManager},y),m(()=>this.snappingOptions,e=>{this._snappingManager&&(this._snappingManager.options=e)},y),k(()=>this.selectionToolbarViewModel,"complete",e=>this._onSelectionComplete(e)),m(()=>({view:this.view,selectionManager:this.effectiveSelectionManager,selectionListViewModel:this.selectionListViewModel,selectionToolbarViewModel:this.selectionToolbarViewModel}),({view:e,selectionManager:t,selectionListViewModel:i,selectionToolbarViewModel:o})=>{t.view=e,i.view=e,o.view=e},y),m(()=>this.effectiveSelectionManager,e=>{this.selectionListViewModel.selectionManager=e,this.selectionToolbarViewModel.selectionManager=e},y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then(()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null}),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=h(this._sketchEventListenerHandle),this.selectionListViewModel?.destroy(),this.selectionToolbarViewModel?.destroy(),this._defaultSelectionManager.destroy()}get _featureTemplatesLayersAndTables(){const e=new o;for(const t of this.editorItems){const i=this.hideTemplatesForInactiveLayers&&!t.visible;t.supportsCreateFeaturesWorkflow&&!i&&e.push(t.layer)}return e}get _selectionSources(){const e=new o;if(this.syncViewSelection||this.selectionManager)return e;for(const t of this.editorItems)x(t.layer)&&t.supportsUpdateWorkflow&&e.push(t.layer);return e}get activeFeatureCount(){const e=this.activeLeafWorkflow;return Q(e)?e.pendingFeatures.length:z(e)&&e.data.edits.feature?1:Z(e)?e.data.fullFeatures.length:$(e)?e.data.features.length:J(e)?2:0}get activeLeafWorkflow(){const e=this.activeWorkflow;return e&&K(e)?e.activeWorkflow??e:e}get canCreate(){return this.editorItems.some(e=>e.supportsCreateFeaturesWorkflow)}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some(e=>e.supportsUpdateWorkflow)}get canUpdateVisible(){return this.editorItems.some(e=>e.supportsUpdateWorkflow&&e.visible)}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter(e=>"scene"===e.type||!e.isTable)}get effectiveSelectionManager(){const e=this.view;return e&&this.syncViewSelection?e.selectionManager:this.selectionManager??this._defaultSelectionManager}get featureFormViewModel(){const e=this.activeWorkflow?.formViewModel;return X(e)?e:null}get formViewModel(){return this.activeWorkflow?.formViewModel}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get useLegacyCreateTools(){return this.ownSketchViewModel.useLegacyCreateTools}set useLegacyCreateTools(e){this.ownSketchViewModel.useLegacyCreateTools=e}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||"2d"!==this.view?.type}get sketchViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeSketchViewModel:"create-features"===e?.type?e.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const e=this.attachmentsViewModel.mode;if("add"===e)return"adding-attachment";if("edit"===e)return"editing-attachment";const{activeWorkflow:t}=this,i=!t?.stepId;return this.effectiveSelectionManager.count&&i?"viewing-selection-list":i?"ready":"update"===t.type&&t.activeWorkflow?.stepId?t.activeWorkflow.stepId:t.stepId}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}set view(e){this.ownSketchViewModel.view=e,this.spinnerViewModel.view=e,this._set("view",e)}get canZoomTo(){return this._getWorkingFeatures().some(e=>e.geometry)}get page(){const{activeWorkflow:e,state:t}=this;if("update"===e?.type&&X(e.formViewModel)){const{associatedLayer:t,associationId:i}=e.formViewModel;if(t||null!=i)return"viewing-associated-features"}if("update"===e?.type&&"awaiting-feature-to-update"===e.stepId)return"ready";if("create-features"===e?.type&&0===e.numPendingFeatures){const t=e.data.upload;if(t)return"default"===t.state?"ready":"creating-features-upload-details"}return t??"disabled"}get featureFormDisabled(){const{activeLeafWorkflow:e}=this;if(z(e))return!1===e.data.editorItem?.capabilities.update.attributes||!0===e.formViewModel.disabled;if(Z(e)){const{formViewModel:t}=e;return t.disabled||t.readOnly}return!1}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeLeafWorkflow:e}=this;if(z(e)){const{data:t}=e;return t.editorItem?.capabilities.delete.enabled&&!t.readOnly}return!!Z(e)&&e.data.editorItems.every(e=>e.capabilities.delete.enabled)}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}activateSelectionTool(e){return this.selectionToolbarViewModel.activateTool(e)}cancelSelectionTool(){this.selectionToolbarViewModel.cancel()}getTemplatesForLayer(e){return this._templatesByLayer.get(e)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(e){return this.startCreateFeaturesWorkflow(e,"creating-features")}async startCreateFeaturesWorkflow(e,t="awaiting-feature-creation-info"){if(await W(()=>!this.updating),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const i=this._createUpdatingResolver();try{await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(e,t);this._set("activeWorkflow",i),await i.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(e){await W(()=>!this.updating);const t=this._createUpdatingResolver();try{const{initialFeature:t}=e,i=t.sourceLayer=t.layer,o=i?Y(this.editorItems,i):void 0;if(!o?.supportsCreateFeaturesWorkflow)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow({initialFeature:t,layer:o.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",r),await r.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startMergeFeaturesWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"merge-features");const i=Array.isArray(e)?ee(e):[e];if(i.length>1)throw new le;if(0===i.length||i[0].objectIds.length<2)throw new ce(2);const r=i[0],s=r.layer;if(!s)throw new de;const a=Y(this.editorItems,s);pe(a);const l=this._createUpdatingResolver(),c=new AbortController;this.addHandles(n(c));try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=await te(r.objectIds,s,this.view?.spatialReference,c.signal);if(e.length!==r.objectIds.length)throw new he;let i;if(t.keyFeature){const o=t.keyFeature.getObjectId();i=e.find(e=>e.getObjectId()===o)??t.keyFeature}const a=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(e),rootWorkflowOptions:{type:"merge",props:{...t,keyFeature:i}}});this._set("activeWorkflow",a),this.addHandles(this._destroyWorkflowOnCommit(a)),await a.start()}catch(d){this._logErrorAndCancelWorkflow(d)}finally{l.resolve()}}async startSplitFeatureWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"split-feature");const i=V(e);if(!i)throw new de;const r=Y(this.editorItems,i);ue(r);const s=this._createUpdatingResolver(),a=new AbortController;this.addHandles(n(a));try{await this._cancelWorkflow(),this.cancelSelectionTool();const r=await ie([e],i,this.view?.spatialReference,a.signal);if(1!==r.length)throw new he;const s=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(r),rootWorkflowOptions:{type:"split",props:t}});this._set("activeWorkflow",s),this.addHandles(this._destroyWorkflowOnCommit(s)),await s.start()}catch(l){this._logErrorAndCancelWorkflow(l)}finally{s.resolve()}}async startUpdateFeaturesWorkflow(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update features workflow is unsupported or disabled.");const t=Array.isArray(e)?ee(e):[e];if(t.length>1)throw new le;const i=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=this._createUpdateWorkflow("editing-existing-feature",{rootFeatureInfos:t,rootWorkflowOptions:{type:"update-multiple"}});e.addHandles(this._destroyWorkflowOnCommit(e)),this._set("activeWorkflow",e),await e.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start()}catch(t){this._logErrorAndCancelWorkflow(t)}finally{e.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow("awaiting-update-feature-candidate");t.data.candidates=e,this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowAtFeatureEdit(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const t=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o([e])});t.addHandles(this._destroyWorkflowOnCommit(t)),this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowWithActiveSelection(){const{selectionListViewModel:e}=this;if(!e.visibleFeatureCount||!e.visibleLayerCount)throw new s("editing:missing-selection","Unable to determine visible selection.");if(e.visibleLayerCount>1)throw new s("editing:features-different-layers","Cannot start workflow with features from different layers.");const t=e.layerItems.find(e=>e.visible);t&&await this._startUpdateWorkflowWithLayerItem(t,"update")}async deleteFeatureFromWorkflow(){r(c.getLogger(this),"EditorViewModel.deleteFeatureFromWorkflow is deprecated. Use EditorViewModel.deleteFeatures instead.",{version:"4.33",replacement:"EditorViewModel.deleteFeatures",warnOnce:!0}),await this.deleteFeatures()}async deleteFeatures(){const e=this.activeWorkflow;if(K(e))return e.deleteActiveFeatures();this._logError("editing:unsupported-workflow","Deleting features requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:e}=this;e&&"update"===e.type?await e.deleteActiveAssociation():this._logError("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(e){return this._cancelWorkflow({warnIfNoWorkflow:!0,...e})}itemHasInvalidFormTemplate(e){return null!=e&&!0===oe(this.editorItems,e.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(e){const{view:i,sketchViewModel:o}=this;if(!i)return;const r=void 0,s=e??o?.createGraphic;if(s)"mesh"===s.geometry?.type?ge(i,s.geometry,r):ge(i,s,r);else{const e=this._getWorkingFeatures();"3d"===i.type&&e?.some(e=>"mesh"===e.geometry?.type)?ge(i,e.map(e=>e.geometry).filter(t),r):e&&ge(i,e,r)}}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}async onSelectionListItemSelect(e){ke(e)&&await this.startUpdateWorkflowAtFeatureEdit(e.graphic)}async onSelectionListMenuItemSelect(e,t){ke(e)?await this.startUpdateWorkflowAtFeatureEdit(e.graphic):ve(e)&&await this._startUpdateWorkflowWithLayerItem(e,t)}restrictFeatureTemplatesViewModelToLayer(e){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([e]),l(()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)})}async _getEditorItemCandidates(e){const{view:t}=this;if(!t?.map)return[];const{map:i}=t,o=i.editableLayers.toArray(),r=i.allTables.toArray().filter(e=>L(e)||E(e));return await Promise.allSettled([...o.flatMap(e=>this._getLayerLoadPromise(e)),...r.flatMap(e=>this._getLayerLoadPromise(e))]),u(e),[...o.reverse(),...r.reverse()].filter(e=>I(e)&&("mesh"!==e.geometryType||"3d"===t.type)).flatMap(e=>"subtype-group"===e.type?e.sublayers.toArray():e)}_getLayerLoadPromise(e){return E(e)?e.loadAll():e.load()}_drainEditorItems(){this.editorItems.drain(e=>e.destroy())}_updateEditorItems(){p(this._updateItemsTask);const{view:e}=this,t=i(async t=>{if(!e?.map||!e?.allLayerViews)return;const i=await this._getEditorItemCandidates(t);if(!i.length)return this._drainEditorItems(),void this.editorItemsLayerMap.clear();const o=[],r=[],s=[],{editorItemsLayerMap:a,layerInfos:n}=this;for(const c of i){const t=Me(n,c),i=await re(e,c).catch(()=>null),l=t?o:i?r:s,d=new ae({layer:c,layerInfo:t,layerView:i});l.push(d),a.set(c,d)}n?.length&&o.sort((e,t)=>n.findIndex(({layer:t})=>t===e.layer)-n.findIndex(({layer:e})=>e===t.layer));const l=[...o,...r,...s];t.aborted||(this._drainEditorItems(),this.editorItems.addMany(l))});this._updatingHandles.consumePromise(t.promise),this._updateItemsTask=t}_updateTemplates(){p(this._updateTemplatesTask);const e=i(async e=>{const t=this._templatesByLayer,i=this._featureTemplatesLayersAndTables.filter(e=>!t.has(e));if(i.length>0){const o=await b({layers:i.toArray(),view:this.view,signal:e,queryOptions:{returnVisibleTemplatesOnly:!0}});for(const{layer:e,templates:i}of o)t.set(e,i)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)});this._updatingHandles.consumePromise(e.promise),this._updateTemplatesTask=e}_setFeatureTemplatesViewModelLayers(e){const t=this._templatesByLayer,i=[];for(const o of e){const e=t.get(o);e&&e.length>0&&i.push(we(o,e))}this.featureTemplatesViewModel.templateInfos=i}_afterEditorItemsChange(){const{activeWorkflow:e}=this;if(this.syncFeatureTemplates(),!e)return;const{stepId:t}=e;"create-features"!==e.type?"update"===e.type&&("awaiting-feature-to-update"===t&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===t&&!e.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==t||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(e){const t=this.activeWorkflow;if(!t)return void(e?.warnIfNoWorkflow&&this._logError("editing:no-active-workflow","There is no active workflow to cancel."));if(!e||!1!==e.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await t.cancel(e)}finally{t.destroy()}}else try{await t.cancel(e),this._set("activeWorkflow",null),t.destroy()}catch(i){}}_createCreateFeaturesWorkflow(e,t){return D.create({viewModel:this,creationInfo:e,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_createUpdateWorkflow(e,t){const i=B.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,...t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)});return i}_addAttachments(e,t){const i=t.map(t=>this._addAttachment(e,t.feature,t.attachment))??[];return Promise.all(i)}async _addAttachment(e,t,i){let o=null;if(!("addAttachment"in e)||null==e.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation(async()=>(o=await(e.addAttachment?.(t,i).catch(e=>{throw e?.error||e}))??null,o)),o}async _applyEdits(e,t,i){let o=null;const r=e.url?await C(e.url):null,s={returnServiceEditsOption:(!r||!A(r))&&!/\/hosted\//i.test(e.url)?"original-and-current-features":void 0,editsRespectTrueCurves:!0,...i};return await this._queueOperation(async()=>{const{view:i}=this;if(!i)return null;const r=await re(i,e).catch(()=>null);return o=await e.applyEdits(t,s),r&&await W(()=>!r.updating),o}),o}async _applyEditsFeatureService(e,t,i){let o=null;return await this._queueOperation(async()=>o=await e.applyEdits(t,i)),o}_destroyWorkflowOnCommit(e){return k(()=>e,"commit",()=>{e.destroy(),this.activeWorkflow===e&&this._set("activeWorkflow",null)})}_queueOperation(e){this._activityQueue.push(e);const t=(e,t)=>{const i=t.indexOf(e);i>-1&&t.splice(i,1)};return e().then(e=>(Array.isArray(e)?e.forEach(e=>this._handleEditsResultError(e)):this._handleEditsResultError(e),e)).catch(i=>{this._logError("editing:operation-error","An error occurred.",{error:i});const o={error:i,retry:()=>(t(o,this.failures),this._queueOperation(e)),cancel:()=>{t(o,this.failures)}};this._set("failures",[...this.failures,o])}).then(()=>{t(e,this._activityQueue)})}_handleEditsResultError(e){if(null!=e&&"error"in e&&null!=e.error)throw e.error;if(null!=e&&"addFeatureResults"in e){const{addFeatureResults:t,deleteFeatureResults:i,updateFeatureResults:o}=e,r=t.find(e=>!!e.error)||o.find(e=>!!e.error)||i.find(e=>!!e.error);if(r)throw r.error}}_createUpdatingResolver(){const e=w();return this._updatingHandles.consumePromise(e.promise),e}_logErrorAndCancelWorkflow(e){const{name:t,message:i,details:o}=e;this._logError(t??"editing:workflow-start-failed",i??void 0,o??e),this._cancelWorkflow({force:!0})}_itemIsSuspended(e){const t=Y(this.editorItems,e);return null!=t&&(!t.visible||t.disabled)}_logError(e,t,i){c.getLogger(this).error(new s(e,t,i))}_syncSelectionSources(){this._defaultSelectionManager.sources.items=this._selectionSources.toArray()}async _onSelectionComplete(e){if(e.aborted)return;const{operationType:t,selection:i}=e,{effectiveSelectionManager:o}=this;this._queuedSelectionTool=void 0;const r=[],s=[];i.forEach(e=>{const t=V(e),i=this.editorItemsLayerMap.get(t);i?.editable&&s.push(e),!1!==i?.visible&&r.push(e)});const a=1===s.length;if("ready"===this.state&&a&&"replace"===t)return this._queuedSelectionTool=e.toolName,this.startUpdateWorkflowAtFeatureEdit(s[0]);switch(t){case"remove":o.updateSelection({current:[],added:[],removed:r});break;case"replace":o.clear(),o.updateSelection({current:r,added:[],removed:[]});break;case"add":o.updateSelection({current:r,added:[],removed:[]})}}async _startUpdateWorkflowWithLayerItem(e,t){if(!e.objectIds?.length)return;const i=e.featureItems.filter(e=>e.visible).map(e=>e.graphic),o=this.selectionListViewModel.filterText;if(1===i.length)return await this.startUpdateWorkflowAtFeatureEdit(i[0]);let r;if(null!=o&&""!==o){const e=ee(i);if(e.length>1)throw new le;if(r=e[0],!r)throw new ce("merge"===t?2:1)}else r={layer:e.layer,objectIds:e.objectIds};"update"===t?await this.startUpdateFeaturesWorkflow(r):"merge"===t&&await this.startMergeFeaturesWorkflow(r)}_getWorkingFeatures(){const{sketchViewModel:e}=this;if(e?.createGraphic)return[e.createGraphic];if(e?.updateGraphics?.length)return e.updateGraphics.toArray();const{formViewModel:t}=this;if(X(t)&&t.feature)return[t.feature];if(se(t)){if(t.activeFeature)return[t.activeFeature];if(t.features.length)return t.features.toArray()}return[]}};e([M()],Te.prototype,"_defaultSelectionManager",void 0),e([M()],Te.prototype,"_featureTemplatesLayersAndTables",null),e([M()],Te.prototype,"_queuedSelectionTool",void 0),e([M()],Te.prototype,"_snappingManager",void 0),e([M()],Te.prototype,"_selectionSources",null),e([M()],Te.prototype,"activeFeatureCount",null),e([M({readOnly:!0})],Te.prototype,"activeWorkflow",void 0),e([M()],Te.prototype,"activeLeafWorkflow",null),e([M({readOnly:!0})],Te.prototype,"_activityQueue",void 0),e([M({readOnly:!0})],Te.prototype,"canCreate",null),e([M()],Te.prototype,"canCreateVisible",null),e([M({readOnly:!0})],Te.prototype,"canUpdate",null),e([M()],Te.prototype,"canUpdateVisible",null),e([M()],Te.prototype,"featureTemplatesLayers",null),e([M()],Te.prototype,"editorItems",void 0),e([M()],Te.prototype,"editorItemsLayerMap",void 0),e([M()],Te.prototype,"effectiveSelectionManager",null),e([M({readOnly:!0})],Te.prototype,"failures",void 0),e([M()],Te.prototype,"hideTemplatesForInactiveLayers",void 0),e([M({type:G})],Te.prototype,"attachmentsViewModel",void 0),e([M()],Te.prototype,"featureFormViewModel",null),e([M()],Te.prototype,"formViewModel",null),e([M()],Te.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),e([M({type:fe})],Te.prototype,"featureTemplatesViewModel",void 0),e([M({type:O})],Te.prototype,"labelOptions",null),e([M()],Te.prototype,"layerInfos",void 0),e([M()],Te.prototype,"useLegacyCreateTools",null),e([M()],Te.prototype,"isUsingLegacyCreateTools",null),e([M()],Te.prototype,"ownSketchViewModel",void 0),e([M()],Te.prototype,"selectionListViewModel",void 0),e([M()],Te.prototype,"selectionManager",void 0),e([M()],Te.prototype,"selectionToolbarViewModel",void 0),e([M()],Te.prototype,"sketchOptions",void 0),e([M()],Te.prototype,"sketchViewModel",null),e([M({type:q,nonNullable:!0})],Te.prototype,"snappingOptions",void 0),e([M()],Te.prototype,"spinnerViewModel",void 0),e([M()],Te.prototype,"state",null),e([M({readOnly:!0})],Te.prototype,"syncing",null),e([M()],Te.prototype,"syncViewSelection",void 0),e([M()],Te.prototype,"updating",null),e([M({type:P})],Te.prototype,"tooltipOptions",null),e([M({type:R})],Te.prototype,"valueOptions",null),e([M()],Te.prototype,"view",null),e([M()],Te.prototype,"canZoomTo",null),e([M()],Te.prototype,"pageStack",void 0),e([M()],Te.prototype,"showDiscardEditsPrompt",void 0),e([M()],Te.prototype,"showConfirmationPrompt",void 0),e([M()],Te.prototype,"_candidateCommitted",void 0),e([M()],Te.prototype,"page",null),e([M()],Te.prototype,"featureFormDisabled",null),e([M()],Te.prototype,"featureFormHasAssociation",null),e([M()],Te.prototype,"canGoBack",null),e([M()],Te.prototype,"shouldShowDeleteButton",null),e([M()],Te.prototype,"hasPendingEdits",null),e([M()],Te.prototype,"snappingManager",null),Te=e([T("esri.widgets.Editor.EditorViewModel")],Te);const Fe=Te;export{Fe as default};
2
+ import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import{createTask as i}from"../../core/asyncUtils.js";import o from"../../core/Collection.js";import{deprecatedFunction as r}from"../../core/deprecate.js";import s from"../../core/Error.js";import{EventedAccessor as a}from"../../core/Evented.js";import{abortHandle as n,makeHandle as l}from"../../core/handleUtils.js";import"../../core/has.js";import c from"../../core/Logger.js";import{destroyMaybe as d,abortMaybe as p,removeMaybe as h}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as w}from"../../core/promiseUtils.js";import f from"../../core/ReactiveMap.js";import{watch as m,syncAndInitial as y,initial as g,on as k,when as v,sync as _,whenOnce as W}from"../../core/reactiveUtils.js";import{property as M,subclass as T}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as F}from"../../core/support/UpdatingHandles.js";import{getTemplatesForLayers as b}from"../../editing/templateUtils.js";import{getGraphicLayer as V}from"../../graphic/graphicOriginUtils.js";import S from"../../layers/GraphicsLayer.js";import{isEditableLayer as I}from"../../layers/support/editableLayers.js";import{isFeatureLayer as L,isSubtypeGroupLayer as E,getOwningPortalUrl as C}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as A}from"../../portal/support/urlUtils.js";import U from"../../views/SelectionManager.js";import O from"../../views/interactive/sketch/SketchLabelOptions.js";import j from"../../views/interactive/sketch/SketchOptions.js";import P from"../../views/interactive/sketch/SketchTooltipOptions.js";import R from"../../views/interactive/sketch/SketchValueOptions.js";import{SnappingManager as H}from"../../views/interactive/snapping/SnappingManager.js";import q from"../../views/interactive/snapping/SnappingOptions.js";import{isISelectableLayer as x}from"../../views/support/selectionUtils.js";import G from"../Attachments/AttachmentsViewModel.js";import D from"./CreateFeaturesWorkflow.js";import B from"./UpdateWorkflow.js";import{getLayersFromWorkflow as N,isCreateFeaturesWorkflow as Q,isUpdateRecordWorkflow as z,isUpdateFeaturesWorkflow as Z,isMergeFeaturesWorkflow as $,isSplitFeatureWorkflow as J,isUpdateWorkflow as K,isFeatureFormViewModel as X,findEditorItemForLayerOrThrow as Y,toFeatureInfos as ee,fetchFullFeaturesByObjectId as te,fetchFullFeatures as ie,findEditorItemForLayer as oe,whenEditorLayerView as re,isBatchAttributeFormViewModel as se}from"./workflowUtils.js";import ae from"./support/EditorItem.js";import{assertViewNot3D as ne,MultipleSourceLayersError as le,InsufficientFeatureCountError as ce,MissingOriginLayerError as de,assertMergeWorkflowCapabilities as pe,FetchFullFeatureError as he,assertSplitWorkflowCapabilities as ue}from"./support/errors.js";import{makeTemplateGroupInfoForLayer as we}from"../FeatureTemplates/featureTemplatesUtils.js";import fe from"../FeatureTemplates/FeatureTemplatesViewModel.js";import me from"../Sketch/SketchViewModel.js";import ye from"../Spinner/SpinnerViewModel.js";import{goTo as ge}from"../support/goToUtils.js";import{isFeatureItem as ke,isLayerItem as ve}from"../support/SelectionList/selectionListUtils.js";import _e from"../support/SelectionList/SelectionListViewModel.js";import We from"../support/SelectionToolbar/SelectionToolbarViewModel.js";function Me(e,t){return e?.find(e=>e.layer===t)}let Te=class extends a{constructor(e){super(e),this._defaultSelectionManager=new U,this._queuedSelectionTool=null,this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new S({listMode:"hide",internal:!0,title:"Editor sketch layer"}),this._snappingManager=null,this._templatesByLayer=new Map,this._updateItemsTask=null,this._updateTemplatesTask=null,this._updatingHandles=new F,this._featureTemplatesViewModelIsRestricted=!1,this.activeWorkflow=null,this._activityQueue=new o,this.editorItems=new o,this.editorItemsLayerMap=new f,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new G({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new fe({disabledItemFunction:({layer:e})=>this._itemIsSuspended(e)}),this.layerInfos=null,this.ownSketchViewModel=new me({layer:this._sketchGraphicsLayer,useLegacyCreateTools:this._get("useLegacyCreateTools")??!0}),this.selectionListViewModel=new _e,this.selectionManager=null,this.selectionToolbarViewModel=new We({continuousSelectionEnabled:!0,defaultOperationType:"replace",persistSelection:!1,returnGeometry:!1}),this.sketchOptions=new j,this.snappingOptions=new q({attributeRulesEnabled:!0}),this.spinnerViewModel=new ye,this.syncViewSelection=!1,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this.showConfirmationPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{if("viewing-selection-list"===this.state)return this.selectionListViewModel.filterText=void 0,void this.effectiveSelectionManager.clear();this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>await(this.activeWorkflow?.save(this.showConfirmationPrompt)),this.selectFeature=(e,t=!1)=>{const i=this.activeWorkflow;if(this._candidateCommitted||"update"!==i?.type)return;const{rootFeatures:o}=i.data;o.removeAll(),e&&o.add(e),t&&(i.next(),this._candidateCommitted=!0)}}initialize(){this.addHandles([m(()=>{const e=this.view,t=e?.map?.editableLayers.toArray(),i=e?.allLayerViews,o=i?.filter(e=>!!t?.includes(e.layer));return[t,o,this.layerInfos]},()=>this._updateEditorItems(),y),m(()=>this.hideTemplatesForInactiveLayers,()=>this.syncFeatureTemplates()),m(()=>this._selectionSources,()=>this._syncSelectionSources(),g),k(()=>this.activeWorkflow,"cancel",()=>this.emit("workflow-cancel")),k(()=>this.activeWorkflow,"commit",()=>this.emit("workflow-commit")),k(()=>this.activeWorkflow,"complete",()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)}),v(()=>!this.activeWorkflow&&this._queuedSelectionTool,()=>this._queuedSelectionTool&&this.selectionToolbarViewModel.activateTool(this._queuedSelectionTool)),m(()=>this.activeWorkflow,e=>this._defaultSelectionManager.highlightEnabled=!e),v(()=>this.view?.map,e=>e.add(this._sketchGraphicsLayer),g),k(()=>this.editorItems,"change",()=>this._afterEditorItemsChange()),m(()=>[this.canCreate,this.canUpdateVisible],()=>this._afterEditorItemsChange()),m(()=>this.page,(e,t)=>{const i=[...this.pageStack];if(-1===i.indexOf(e))i.push(e);else for(;i.length&&i.at(-1)!==e;)i.pop();this.pageStack=i},y),v(()=>"awaiting-update-feature-candidate"===this.state,()=>this._candidateCommitted=!1),k(()=>this.featureTemplatesViewModel,"select",async({item:e,oldItem:t})=>{const{activeWorkflow:i}=this;if(i){if("update"===i.type&&"awaiting-feature-creation-info"===i.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(t,{emit:!1})}}if(!e)return;const o={layer:e.layer,template:e.template};if(e.supportsUpload)return this.featureTemplatesViewModel.select(t,{emit:!1}),this.startCreateFeaturesWorkflow(o);await this.startCreateFeaturesWorkflowAtFeatureCreation(o)}),m(()=>[this.view,this.featureTemplatesViewModel],([e,t])=>{t.view=e},y),k(()=>this.view,"key-down",e=>{"Escape"===e.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(e.stopPropagation(),this.back())}),k(()=>this.sketchViewModel,["create","delete","update"],e=>{const{activeWorkflow:t}=this,i=N(t),o=`sketch-${e.type}`;this.emit(o,{type:o,detail:e,layer:i[0],layers:i})},_),m(()=>this.view,e=>{if(this._snappingManager=d(this._snappingManager),!e)return;const t=this.snappingOptions;this._snappingManager=new H({view:e,options:t}),this.ownSketchViewModel.snappingManager=this._snappingManager},y),m(()=>this.snappingOptions,e=>{this._snappingManager&&(this._snappingManager.options=e)},y),k(()=>this.selectionToolbarViewModel,"complete",e=>this._onSelectionComplete(e)),m(()=>({view:this.view,selectionManager:this.effectiveSelectionManager,selectionListViewModel:this.selectionListViewModel,selectionToolbarViewModel:this.selectionToolbarViewModel}),({view:e,selectionManager:t,selectionListViewModel:i,selectionToolbarViewModel:o})=>{t.view=e,i.view=e,o.view=e},y),m(()=>this.effectiveSelectionManager,e=>{this.selectionListViewModel.selectionManager=e,this.selectionToolbarViewModel.selectionManager=e},y)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then(()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null}),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=h(this._sketchEventListenerHandle),this.selectionListViewModel?.destroy(),this.selectionToolbarViewModel?.destroy(),this._defaultSelectionManager.destroy()}get _featureTemplatesLayersAndTables(){const e=new o;for(const t of this.editorItems){const i=this.hideTemplatesForInactiveLayers&&!t.visible;t.supportsCreateFeaturesWorkflow&&!i&&e.push(t.layer)}return e}get _selectionSources(){const e=new o;if(this.syncViewSelection||this.selectionManager)return e;for(const t of this.editorItems)x(t.layer)&&t.supportsUpdateWorkflow&&e.push(t.layer);return e}get activeFeatureCount(){const e=this.activeLeafWorkflow;return Q(e)?e.pendingFeatures.length:z(e)&&e.data.edits.feature?1:Z(e)?e.data.fullFeatures.length:$(e)?e.data.features.length:J(e)?2:0}get activeLeafWorkflow(){const e=this.activeWorkflow;return e&&K(e)?e.activeWorkflow??e:e}get canCreate(){return this.editorItems.some(e=>e.supportsCreateFeaturesWorkflow)}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some(e=>e.supportsUpdateWorkflow)}get canUpdateVisible(){return this.editorItems.some(e=>e.supportsUpdateWorkflow&&e.visible)}get featureTemplatesLayers(){return this._featureTemplatesLayersAndTables.filter(e=>"scene"===e.type||!e.isTable)}get effectiveSelectionManager(){const e=this.view;return e&&this.syncViewSelection?e.selectionManager:this.selectionManager??this._defaultSelectionManager}get featureFormViewModel(){const e=this.activeWorkflow?.formViewModel;return X(e)?e:null}get formViewModel(){return this.activeWorkflow?.formViewModel}get utilityNetworkAssociationAddAssociationViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeUtilityNetworkAssociationAddAssociationViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(e){this.sketchOptions.labels=e}get useLegacyCreateTools(){return this.ownSketchViewModel.useLegacyCreateTools}set useLegacyCreateTools(e){this.ownSketchViewModel.useLegacyCreateTools=e}get isUsingLegacyCreateTools(){return this.useLegacyCreateTools||"2d"!==this.view?.type}get sketchViewModel(){const{activeWorkflow:e}=this;return"update"===e?.type?e.activeSketchViewModel:"create-features"===e?.type?e.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const e=this.attachmentsViewModel.mode;if("add"===e)return"adding-attachment";if("edit"===e)return"editing-attachment";const{activeWorkflow:t}=this,i=!t?.stepId;return this.effectiveSelectionManager.count&&i?"viewing-selection-list":i?"ready":"update"===t.type&&t.activeWorkflow?.stepId?t.activeWorkflow.stepId:t.stepId}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(e){this.sketchOptions.tooltips=e}get valueOptions(){return this.sketchOptions.values}set valueOptions(e){this.sketchOptions.values=e}set view(e){this.ownSketchViewModel.view=e,this.spinnerViewModel.view=e,this._set("view",e)}get canZoomTo(){return this._getWorkingFeatures().some(e=>e.geometry)}get page(){const{activeWorkflow:e,state:t}=this;if("update"===e?.type&&X(e.formViewModel)){const{associatedLayer:t,associationId:i}=e.formViewModel;if(t||null!=i)return"viewing-associated-features"}if("update"===e?.type&&"awaiting-feature-to-update"===e.stepId)return"ready";if("create-features"===e?.type&&0===e.numPendingFeatures){const t=e.data.upload;if(t)return"default"===t.state?"ready":"creating-features-upload-details"}return t??"disabled"}get featureFormDisabled(){const{activeLeafWorkflow:e}=this;if(z(e))return!1===e.data.editorItem?.capabilities.update.attributes||!0===e.formViewModel.disabled;if(Z(e)){const{formViewModel:t}=e;return t.disabled||t.readOnly}return!1}get featureFormHasAssociation(){return!!this.featureFormViewModel?.activeAssociation}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeLeafWorkflow:e}=this;if(z(e)){const{data:t}=e;return t.editorItem?.capabilities.delete.enabled&&!t.readOnly}return!!Z(e)&&e.data.editorItems.every(e=>e.capabilities.delete.enabled)}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}get snappingManager(){return this._snappingManager}activateSelectionTool(e){return this.selectionToolbarViewModel.activateTool(e)}cancelSelectionTool(){this.selectionToolbarViewModel.cancel()}getTemplatesForLayer(e){return this._templatesByLayer.get(e)??[]}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(e){return this.startCreateFeaturesWorkflow(e,"creating-features")}async startCreateFeaturesWorkflow(e,t="awaiting-feature-creation-info"){if(await W(()=>!this.updating),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const i=this._createUpdatingResolver();try{await this._cancelWorkflow();const i=this._createCreateFeaturesWorkflow(e,t);this._set("activeWorkflow",i),await i.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startCreateFeaturesWorkflowAtFeatureEdit(e){await W(()=>!this.updating);const t=this._createUpdatingResolver();try{const{initialFeature:t}=e,i=t.sourceLayer=t.layer,o=i?Y(this.editorItems,i):void 0;if(!o?.supportsCreateFeaturesWorkflow)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow({initialFeature:t,layer:o.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",r),await r.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startMergeFeaturesWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"merge-features");const i=Array.isArray(e)?ee(e):[e];if(i.length>1)throw new le;if(0===i.length||i[0].objectIds.length<2)throw new ce(2);const r=i[0],s=r.layer;if(!s)throw new de;const a=Y(this.editorItems,s);pe(a);const l=this._createUpdatingResolver(),c=new AbortController;this.addHandles(n(c));try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=await te(r.objectIds,s,this.view?.spatialReference,c.signal);if(e.length!==r.objectIds.length)throw new he;let i;if(t.keyFeature){const o=t.keyFeature.getObjectId();i=e.find(e=>e.getObjectId()===o)??t.keyFeature}const a=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(e),rootWorkflowOptions:{type:"merge",props:{...t,keyFeature:i}}});this._set("activeWorkflow",a),this.addHandles(this._destroyWorkflowOnCommit(a)),await a.start()}catch(d){this._logErrorAndCancelWorkflow(d)}finally{l.resolve()}}async startSplitFeatureWorkflow(e,t={}){await W(()=>!this.updating),ne(this,"split-feature");const i=V(e);if(!i)throw new de;const r=Y(this.editorItems,i);ue(r);const s=this._createUpdatingResolver(),a=new AbortController;this.addHandles(n(a));try{await this._cancelWorkflow(),this.cancelSelectionTool();const r=await ie([e],i,this.view?.spatialReference,a.signal);if(1!==r.length)throw new he;const s=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o(r),rootWorkflowOptions:{type:"split",props:t}});this._set("activeWorkflow",s),this.addHandles(this._destroyWorkflowOnCommit(s)),await s.start()}catch(l){this._logErrorAndCancelWorkflow(l)}finally{s.resolve()}}async startUpdateFeaturesWorkflow(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update features workflow is unsupported or disabled.");const t=Array.isArray(e)?ee(e):[e];if(t.length>1)throw new le;const i=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const e=this._createUpdateWorkflow("editing-existing-feature",{rootFeatureInfos:t,rootWorkflowOptions:{type:"update-multiple"}});e.addHandles(this._destroyWorkflowOnCommit(e)),this._set("activeWorkflow",e),await e.start()}catch(o){this._logErrorAndCancelWorkflow(o)}finally{i.resolve()}}async startUpdateWorkflowAtFeatureSelection(){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();try{await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start()}catch(t){this._logErrorAndCancelWorkflow(t)}finally{e.resolve()}}async startUpdateWorkflowAtMultipleFeatureSelection(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow();const t=this._createUpdateWorkflow("awaiting-update-feature-candidate");t.data.candidates=e,this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowAtFeatureEdit(e){if(await W(()=>!this.updating),!this.canUpdate)return void this._logError("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();try{await this._cancelWorkflow(),this.cancelSelectionTool();const t=this._createUpdateWorkflow("editing-existing-feature",{rootFeatures:new o([e])});t.addHandles(this._destroyWorkflowOnCommit(t)),this._set("activeWorkflow",t),await t.start()}catch(i){this._logErrorAndCancelWorkflow(i)}finally{t.resolve()}}async startUpdateWorkflowWithActiveSelection(){const{selectionListViewModel:e}=this;if(!e.visibleFeatureCount||!e.visibleLayerCount)throw new s("editing:missing-selection","Unable to determine visible selection.");if(e.visibleLayerCount>1)throw new s("editing:features-different-layers","Cannot start workflow with features from different layers.");const t=e.layerItems.find(e=>e.visible);t&&await this._startUpdateWorkflowWithLayerItem(t,"update")}async deleteFeatureFromWorkflow(){r(c.getLogger(this),"EditorViewModel.deleteFeatureFromWorkflow is deprecated. Use EditorViewModel.deleteFeatures instead.",{version:"4.33",replacement:"EditorViewModel.deleteFeatures",warnOnce:!0}),await this.deleteFeatures()}async deleteFeatures(){const e=this.activeWorkflow;if(K(e))return e.deleteActiveFeatures();this._logError("editing:unsupported-workflow","Deleting features requires an active update workflow.")}async deleteAssociationFromWorkflow(){const{activeWorkflow:e}=this;e&&"update"===e.type?await e.deleteActiveAssociation():this._logError("editing:unsupported-workflow","Deleting an association requires an active update workflow.")}async cancelWorkflow(e){return this._cancelWorkflow({warnIfNoWorkflow:!0,...e})}itemHasInvalidFormTemplate(e){return null!=e&&!0===oe(this.editorItems,e.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelIsRestricted||this._updateTemplates()}zoomTo(e){const{view:i,sketchViewModel:o}=this;if(!i)return;const r=void 0,s=e??o?.createGraphic;if(s)"mesh"===s.geometry?.type?ge(i,s.geometry,r):ge(i,s,r);else{const e=this._getWorkingFeatures();"3d"===i.type&&e?.some(e=>"mesh"===e.geometry?.type)?ge(i,e.map(e=>e.geometry).filter(t),r):e&&ge(i,e,r)}}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}async onSelectionListItemSelect(e){ke(e)&&await this.startUpdateWorkflowAtFeatureEdit(e.graphic)}async onSelectionListMenuItemSelect(e,t){ke(e)?await this.startUpdateWorkflowAtFeatureEdit(e.graphic):ve(e)&&await this._startUpdateWorkflowWithLayerItem(e,t)}restrictFeatureTemplatesViewModelToLayer(e){return this._featureTemplatesViewModelIsRestricted=!0,this._setFeatureTemplatesViewModelLayers([e]),l(()=>{this._featureTemplatesViewModelIsRestricted=!1,this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)})}async _getEditorItemCandidates(e){const{view:t}=this;if(!t?.map)return[];const{map:i}=t,o=i.editableLayers.toArray(),r=i.allTables.toArray().filter(e=>L(e)||E(e));return await Promise.allSettled([...o.flatMap(e=>this._getLayerLoadPromise(e)),...r.flatMap(e=>this._getLayerLoadPromise(e))]),u(e),[...o.reverse(),...r.reverse()].filter(e=>I(e)&&("mesh"!==e.geometryType||"3d"===t.type)).flatMap(e=>"subtype-group"===e.type?e.sublayers.toArray():e)}_getLayerLoadPromise(e){return E(e)?e.loadAll():e.load()}_drainEditorItems(){this.editorItems.drain(e=>e.destroy())}_updateEditorItems(){p(this._updateItemsTask);const{view:e}=this,t=i(async t=>{if(!e?.map||!e?.allLayerViews)return;const i=await this._getEditorItemCandidates(t);if(!i.length)return this._drainEditorItems(),void this.editorItemsLayerMap.clear();const o=[],r=[],s=[],{editorItemsLayerMap:a,layerInfos:n}=this;for(const c of i){const t=Me(n,c),i=await re(e,c).catch(()=>null),l=t?o:i?r:s,d=new ae({layer:c,layerInfo:t,layerView:i});l.push(d),a.set(c,d)}n?.length&&o.sort((e,t)=>n.findIndex(({layer:t})=>t===e.layer)-n.findIndex(({layer:e})=>e===t.layer));const l=[...o,...r,...s];t.aborted||(this._drainEditorItems(),this.editorItems.addMany(l))});this._updatingHandles.consumePromise(t.promise),this._updateItemsTask=t}_updateTemplates(){p(this._updateTemplatesTask);const e=i(async e=>{const t=this._templatesByLayer,i=this._featureTemplatesLayersAndTables.filter(e=>!t.has(e));if(i.length>0){const o=await b({layers:i.toArray(),view:this.view,signal:e,queryOptions:{returnVisibleTemplatesOnly:!0}});for(const{layer:e,templates:i}of o)t.set(e,i)}this._setFeatureTemplatesViewModelLayers(this.featureTemplatesLayers)});this._updatingHandles.consumePromise(e.promise),this._updateTemplatesTask=e}_setFeatureTemplatesViewModelLayers(e){const t=this._templatesByLayer,i=[];for(const o of e){const e=t.get(o);e&&e.length>0&&i.push(we(o,e))}this.featureTemplatesViewModel.templateInfos=i}_afterEditorItemsChange(){const{activeWorkflow:e}=this;if(this.syncFeatureTemplates(),!e)return;const{stepId:t}=e;"create-features"!==e.type?"update"===e.type&&("awaiting-feature-to-update"===t&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===t&&!e.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==t||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(e){const t=this.activeWorkflow;if(!t)return void(e?.warnIfNoWorkflow&&this._logError("editing:no-active-workflow","There is no active workflow to cancel."));if(!e||!1!==e.force){this.emit("workflow-cancel"),this._set("activeWorkflow",null);try{await t.cancel(e)}finally{t.destroy()}}else try{await t.cancel(e),this._set("activeWorkflow",null),t.destroy()}catch(i){}}_createCreateFeaturesWorkflow(e,t){return D.create({viewModel:this,creationInfo:e,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)})}_createUpdateWorkflow(e,t){const i=B.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,...t,applyEdits:(e,t,i)=>this._applyEdits(e,t,i),applyEditsFeatureService:(e,t,i)=>this._applyEditsFeatureService(e,t,i),addAttachmentsCallback:(e,t)=>this._addAttachments(e,t)});return i}_addAttachments(e,t){const i=t.map(t=>this._addAttachment(e,t.feature,t.attachment))??[];return Promise.all(i)}async _addAttachment(e,t,i){let o=null;if(!("addAttachment"in e)||null==e.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation(async()=>(o=await(e.addAttachment?.(t,i).catch(e=>{throw e?.error||e}))??null,o)),o}async _applyEdits(e,t,i){let o=null;const r=e.url?await C(e.url):null,s={returnServiceEditsOption:(!r||!A(r))&&!/\/hosted\//i.test(e.url)?"original-and-current-features":void 0,editsRespectTrueCurves:!0,...i};return await this._queueOperation(async()=>{const{view:i}=this;if(!i)return null;const r=await re(i,e).catch(()=>null);return o=await e.applyEdits(t,s),r&&await W(()=>!r.updating),o}),o}async _applyEditsFeatureService(e,t,i){let o=null;return await this._queueOperation(async()=>o=await e.applyEdits(t,i)),o}_destroyWorkflowOnCommit(e){return k(()=>e,"commit",()=>{e.destroy(),this.activeWorkflow===e&&this._set("activeWorkflow",null)})}_queueOperation(e){this._activityQueue.push(e);const t=(e,t)=>{const i=t.indexOf(e);i>-1&&t.splice(i,1)};return e().then(e=>(Array.isArray(e)?e.forEach(e=>this._handleEditsResultError(e)):this._handleEditsResultError(e),e)).catch(i=>{this._logError("editing:operation-error","An error occurred.",{error:i});const o={error:i,retry:()=>(t(o,this.failures),this._queueOperation(e)),cancel:()=>{t(o,this.failures)}};this._set("failures",[...this.failures,o])}).then(()=>{t(e,this._activityQueue)})}_handleEditsResultError(e){if(null!=e&&"error"in e&&null!=e.error)throw e.error;if(null!=e&&"addFeatureResults"in e){const{addFeatureResults:t,deleteFeatureResults:i,updateFeatureResults:o}=e,r=t.find(e=>!!e.error)||o.find(e=>!!e.error)||i.find(e=>!!e.error);if(r)throw r.error}}_createUpdatingResolver(){const e=w();return this._updatingHandles.consumePromise(e.promise),e}_logErrorAndCancelWorkflow(e){const{name:t,message:i,details:o}=e;this._logError(t??"editing:workflow-start-failed",i??void 0,o??e),this._cancelWorkflow({force:!0})}_itemIsSuspended(e){const t=Y(this.editorItems,e);return null!=t&&(!t.visible||t.disabled)}_logError(e,t,i){c.getLogger(this).error(new s(e,t,i))}_syncSelectionSources(){this._defaultSelectionManager.sources.items=this._selectionSources.toArray()}async _onSelectionComplete(e){if(e.aborted)return;const{operationType:t,selection:i}=e,{effectiveSelectionManager:o}=this;this._queuedSelectionTool=void 0;const r=[],s=[];i.forEach(e=>{const t=V(e),i=this.editorItemsLayerMap.get(t);i?.editable&&s.push(e),!1!==i?.visible&&r.push(e)});const a=1===r.length&&s.includes(r[0]);if("ready"===this.state&&a&&"replace"===t)return this._queuedSelectionTool=e.toolName,this.startUpdateWorkflowAtFeatureEdit(r[0]);switch(t){case"remove":o.updateSelection({current:[],added:[],removed:r});break;case"replace":o.clear(),o.updateSelection({current:r,added:[],removed:[]});break;case"add":o.updateSelection({current:r,added:[],removed:[]})}}async _startUpdateWorkflowWithLayerItem(e,t){if(!e.objectIds?.length)return;const i=e.featureItems.filter(e=>e.visible).map(e=>e.graphic),o=this.selectionListViewModel.filterText;if(1===i.length)return await this.startUpdateWorkflowAtFeatureEdit(i[0]);let r;if(null!=o&&""!==o){const e=ee(i);if(e.length>1)throw new le;if(r=e[0],!r)throw new ce("merge"===t?2:1)}else r={layer:e.layer,objectIds:e.objectIds};"update"===t?await this.startUpdateFeaturesWorkflow(r):"merge"===t&&await this.startMergeFeaturesWorkflow(r)}_getWorkingFeatures(){const{sketchViewModel:e}=this;if(e?.createGraphic)return[e.createGraphic];if(e?.updateGraphics?.length)return e.updateGraphics.toArray();const{formViewModel:t}=this;if(X(t)&&t.feature)return[t.feature];if(se(t)){if(t.activeFeature)return[t.activeFeature];if(t.features.length)return t.features.toArray()}return[]}};e([M()],Te.prototype,"_defaultSelectionManager",void 0),e([M()],Te.prototype,"_featureTemplatesLayersAndTables",null),e([M()],Te.prototype,"_queuedSelectionTool",void 0),e([M()],Te.prototype,"_snappingManager",void 0),e([M()],Te.prototype,"_selectionSources",null),e([M()],Te.prototype,"activeFeatureCount",null),e([M({readOnly:!0})],Te.prototype,"activeWorkflow",void 0),e([M()],Te.prototype,"activeLeafWorkflow",null),e([M({readOnly:!0})],Te.prototype,"_activityQueue",void 0),e([M({readOnly:!0})],Te.prototype,"canCreate",null),e([M()],Te.prototype,"canCreateVisible",null),e([M({readOnly:!0})],Te.prototype,"canUpdate",null),e([M()],Te.prototype,"canUpdateVisible",null),e([M()],Te.prototype,"featureTemplatesLayers",null),e([M()],Te.prototype,"editorItems",void 0),e([M()],Te.prototype,"editorItemsLayerMap",void 0),e([M()],Te.prototype,"effectiveSelectionManager",null),e([M({readOnly:!0})],Te.prototype,"failures",void 0),e([M()],Te.prototype,"hideTemplatesForInactiveLayers",void 0),e([M({type:G})],Te.prototype,"attachmentsViewModel",void 0),e([M()],Te.prototype,"featureFormViewModel",null),e([M()],Te.prototype,"formViewModel",null),e([M()],Te.prototype,"utilityNetworkAssociationAddAssociationViewModel",null),e([M({type:fe})],Te.prototype,"featureTemplatesViewModel",void 0),e([M({type:O})],Te.prototype,"labelOptions",null),e([M()],Te.prototype,"layerInfos",void 0),e([M()],Te.prototype,"useLegacyCreateTools",null),e([M()],Te.prototype,"isUsingLegacyCreateTools",null),e([M()],Te.prototype,"ownSketchViewModel",void 0),e([M()],Te.prototype,"selectionListViewModel",void 0),e([M()],Te.prototype,"selectionManager",void 0),e([M()],Te.prototype,"selectionToolbarViewModel",void 0),e([M()],Te.prototype,"sketchOptions",void 0),e([M()],Te.prototype,"sketchViewModel",null),e([M({type:q,nonNullable:!0})],Te.prototype,"snappingOptions",void 0),e([M()],Te.prototype,"spinnerViewModel",void 0),e([M()],Te.prototype,"state",null),e([M({readOnly:!0})],Te.prototype,"syncing",null),e([M()],Te.prototype,"syncViewSelection",void 0),e([M()],Te.prototype,"updating",null),e([M({type:P})],Te.prototype,"tooltipOptions",null),e([M({type:R})],Te.prototype,"valueOptions",null),e([M()],Te.prototype,"view",null),e([M()],Te.prototype,"canZoomTo",null),e([M()],Te.prototype,"pageStack",void 0),e([M()],Te.prototype,"showDiscardEditsPrompt",void 0),e([M()],Te.prototype,"showConfirmationPrompt",void 0),e([M()],Te.prototype,"_candidateCommitted",void 0),e([M()],Te.prototype,"page",null),e([M()],Te.prototype,"featureFormDisabled",null),e([M()],Te.prototype,"featureFormHasAssociation",null),e([M()],Te.prototype,"canGoBack",null),e([M()],Te.prototype,"shouldShowDeleteButton",null),e([M()],Te.prototype,"hasPendingEdits",null),e([M()],Te.prototype,"snappingManager",null),Te=e([T("esri.widgets.Editor.EditorViewModel")],Te);const Fe=Te;export{Fe as default};
@@ -1,2 +0,0 @@
1
- /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{watch as e,initial as t}from"../../../../core/reactiveUtils.js";import{fromValues as r}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{resizeHandleCornerWidth as o,resizeHandleEdgeWidth as i,displayFocusMultiplier as s,resizeHandleCornerInputRadius as a,resizeHandleEdgeInputRadius as l}from"./sliceToolConfig.js";import{isDiagonalResizeHandle as n,resizeNormal as c,resizeOutlineOnly as m}from"./sliceToolUtils.js";import{Manipulator3D as f}from"../../interactive/Manipulator3D.js";import{worldScaledManipulatorSettings as d}from"../../interactive/manipulatorUtils.js";import{RenderObject as p}from"../../interactive/RenderObject.js";import{createPolylineGeometry as u}from"../../webgl-engine/lib/GeometryUtil.js";import{RibbonLineMaterial as w}from"../../webgl-engine/materials/RibbonLineMaterial.js";class b extends f{constructor(r,a){const l=n(a),c=l?o:i,m=c*s,f=i,p={renderOccluded:4,isDecoration:!0},u=new w({...p,width:c},r.state.isGlobal),b=new w({...p,width:m},r.state.isGlobal),h=new w({...p,width:f},r.state.isGlobal);super({view:r,...d,...j({isCorner:l,unfocusedMaterial:u,focusedMaterial:b,outlineMaterial:h})}),this._themeHandle=e(()=>r.effectiveTheme.accentColor,e=>{const t=e.toUnitRGBA();u.setParameters({color:t}),b.setParameters({color:t}),h.setParameters({color:t})},t)}destroy(){this._themeHandle.remove(),super.destroy()}}function j({isCorner:e,unfocusedMaterial:t,focusedMaterial:o,outlineMaterial:i}){const s=e?[r(1,0,0),r(0,0,0),r(0,1,0)]:[r(1,0,0),r(-1,0,0)];return{renderObjects:[new p(u(t,s),1|c),new p(u(o,s),2|c),new p(u(i,s),m)],collisionType:{type:"line",paths:[s]},radius:e?a:l,state:c}}export{b as ResizeManipulator};
@@ -1,2 +0,0 @@
1
- /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{multiplyOpacity as e,getContrast as t}from"../../../../core/colorUtils.js";import{releaseMaybe as r}from"../../../../core/maybe.js";import{watch as i,initial as o}from"../../../../core/reactiveUtils.js";import{DidPointerMoveRecentlyFlag as a}from"./sliceToolUtils.js";import{Manipulator3D as s}from"../../interactive/Manipulator3D.js";import{rotateManipulatorDefaults as n}from"../../interactive/manipulatorUtils.js";import{RenderObject as l}from"../../interactive/RenderObject.js";import{Attribute as c}from"../../webgl-engine/lib/Attribute.js";import{Geometry as m}from"../../webgl-engine/lib/Geometry.js";import{createPolylineGeometry as u}from"../../webgl-engine/lib/GeometryUtil.js";import{Parameters as d,ImageMaterial as p}from"../../webgl-engine/materials/ImageMaterial.js";import{RibbonLineMaterial as f}from"../../webgl-engine/materials/RibbonLineMaterial.js";class h extends s{constructor(r,a){const s=e(r.effectiveTheme.accentColor,.5),l=t(r.effectiveTheme.accentColor),c=a(s,l),m=new d(c.managedTexture,!1);m.writeDepth=!1,m.renderOccluded=16,m.isDecoration=!0;const u=new p(m),h=n.calloutWidth,g=new f({width:h,renderOccluded:4,isDecoration:!0},r.state.isGlobal);super({view:r,...w({imageMaterial:u,calloutMaterial:g})}),this._material=u,this._textureHandle=c,this._themeHandle=i(()=>r.effectiveTheme.accentColor,r=>{const i=e(r,.5),o=t(r),s=this._textureHandle;this._textureHandle=a(i,o),u.setParameters({managedTexture:this._textureHandle.managedTexture}),s?.release(),g.setParameters({color:r.toUnitRGBA()})},o)}destroy(){this._textureHandle=r(this._textureHandle),this._themeHandle.remove(),this._material.dispose(),super.destroy()}}function w({imageMaterial:e,calloutMaterial:t}){const{focusMultiplier:r,calloutLength:i,discRadius:o}=n,s=o*r,d=(e,t)=>{const r=[0,1,2,2,3,0];return new m(t,[["position",new c([i-e,-e,0,i+e,-e,0,i+e,e,0,i-e,e,0],r,3,!0)],["uv0",new c([0,0,1,0,1,1,0,1],r,2,!0)]])},p=u(t,[[0,0,0],[i-o,0,0]]),f=u(t,[[0,0,0],[i-s,0,0]]),h=a;return{autoScaleRenderObjects:!1,collisionPriority:1,collisionType:{type:"disc",direction:[0,0,1],offset:[i,0,0]},focusMultiplier:r,radius:o,renderObjects:[new l(d(o,e),1|h),new l(p,1|h),new l(d(s,e),2|h),new l(f,2|h)],state:h}}export{h as RotateManipulator};
@@ -1,2 +0,0 @@
1
- /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import t from"../../../../Color.js";import{getContrast as e}from"../../../../core/colorUtils.js";import{watch as r,initial as o}from"../../../../core/reactiveUtils.js";import{identity as i,translate as a,scale as s,fromQuat as n,multiply as c}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{rotationTo as m}from"../../../../core/libs/gl-matrix-2/math/quat.js";import{subtract as p,normalize as u,scale as f,add as d,set as g}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as h,fromValues as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as j,sm4d as M,sq4d as w}from"../../../../geometry/support/vectorStacks.js";import{shiftRestartOffsetDistance as v,shiftRestartTipRadius as O,shiftRestartTipLength as U,shiftRestartArrowOutlineWidth as x,shiftRestartArrowLength as y,shiftRestartTubeRadius as D,shiftRestartTubeFocusMultiplier as P,shiftRestartTipFocusMultiplier as R}from"./sliceToolConfig.js";import{DidPointerMoveRecentlyFlag as C,IsShiftEdgeOnScreenFlag as G}from"./sliceToolUtils.js";import{Manipulator3D as A}from"../../interactive/Manipulator3D.js";import{RenderObject as B}from"../../interactive/RenderObject.js";import{createPolylineGeometry as F,createConeGeometry as T,createPathExtrusionGeometry as H}from"../../webgl-engine/lib/GeometryUtil.js";import{ColorMaterial as S}from"../../webgl-engine/materials/ColorMaterial.js";import{RibbonLineMaterial as _}from"../../webgl-engine/materials/RibbonLineMaterial.js";class k extends A{constructor(i,a){const s=new _({width:1,renderOccluded:4,isDecoration:!0},i.state.isGlobal),n=new S({cullFace:2,renderOccluded:16,isDecoration:!0}),c=new S({cullFace:2,renderOccluded:16,isDecoration:!0}),l=new S({cullFace:2,renderOccluded:16,isDecoration:!0}),m=new S({writeDepth:!1,cullFace:1,renderOccluded:2,isDecoration:!0});super({view:i,...q({offsetMode:a,tubeMaterial:n,tipMaterial:c,capMaterial:l,outlineMaterial:m,calloutMaterial:s})}),this._themeHandle=r(()=>i.effectiveTheme.accentColor,r=>{const o=e(r),i=r.toUnitRGBA(),a=o.toUnitRGBA(),p=t.blendColors(o,r,.4).toUnitRGBA(),u=t.blendColors(o,r,.14).toUnitRGBA();s.setParameters({color:i}),n.setParameters({color:u}),c.setParameters({color:a}),l.setParameters({color:p}),m.setParameters({color:i})},o)}destroy(){this._themeHandle.remove(),super.destroy()}}function q({offsetMode:t,tubeMaterial:e,tipMaterial:r,capMaterial:o,outlineMaterial:i,calloutMaterial:a}){const s=0===t?v:0,n=[b(s,0,-y/2),b(s,0,y/2)],c=z(n),l=I({vertices:n,padding:0,materials:{tube:e,tip:r,cap:o}}),m=I({vertices:n,padding:x,materials:{tube:i,tip:i,cap:i}}),p=F(a,[[s,0,0],[s-v,0,0]]),u=F(a,[[s,0,0],[s-v,0,0]]);return{renderObjects:[...l.normal.map(t=>new B(t,1|C)),...m.normal.map(t=>new B(t,1|C)),new B(p,1|C|G),...l.focused.map(t=>new B(t,2|C)),...m.focused.map(t=>new B(t,2|C)),new B(u,2|C|G)],autoScaleRenderObjects:!1,collisionType:{type:"line",paths:[c]},collisionPriority:1,radius:O,state:C}}function I({vertices:t,padding:e,materials:r}){const o=o=>{const v=t.slice(),x=p(j.get(),v[0],v[1]);u(x,x);const y=p(j.get(),v[v.length-1],v[v.length-2]);if(u(y,y),e>0){const t=f(h(),y,-e);v[v.length-1]=d(t,t,v[v.length-1]);const r=f(h(),x,-e);v[0]=d(r,r,v[0])}const C=o?R:1,G=U*C,A=O*C,B=i(M.get());if(e>0){const t=G/4,r=g(j.get(),0,t,0),o=1+e/t;a(B,B,r),s(B,B,g(j.get(),o,o,o)),a(B,B,f(r,r,-1/o))}const F=i(l()),H=b(0,1,0),S=n(l(),m(w.get(),H,y));S[12]=v[v.length-1][0],S[13]=v[v.length-1][1],S[14]=v[v.length-1][2],c(S,S,B);const _=r.tube,k=L(D*(o?P:1)+e,v,_);k.transformation=F;const q=[k],I=r.tip,z=T(I,G,A,24,!1,!1,!0);z.transformation=S,q.push(z);const E=r.cap,J=T(E,G,A,24,!1,!0,!1);J.transformation=S,q.push(J);const K=n(l(),m(w.get(),H,x));return K[12]=v[0][0],K[13]=v[0][1],K[14]=v[0][2],c(K,K,B),q.push(z.instantiate({transformation:K})),q.push(J.instantiate({transformation:K})),q};return{normal:o(!1),focused:o(!0)}}function L(t,e,r){const o=[],i=12;for(let a=0;a<i;a++){const e=a/i*2*Math.PI;o.push([Math.cos(e)*t,Math.sin(e)*t])}return H(r,o,e,[],[],!1)}function z(t,e){const r=p(h(),t[t.length-1],t[t.length-2]);u(r,r),f(r,r,U),d(r,r,t[t.length-1]);{const e=p(h(),t[0],t[1]);return u(e,e),f(e,e,U),d(e,e,t[0]),[e,...t,r]}}export{k as ShiftManipulator};