@arcgis/core 5.2.0-next.153 → 5.2.0-next.155

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 (150) hide show
  1. package/arcade/containerUtils.js +1 -1
  2. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  3. package/arcade/functions/feature.js +1 -1
  4. package/arcade/functions/featuresetstring.js +1 -1
  5. package/arcade/functions/geomasync.js +1 -1
  6. package/arcade/functions/portal.js +1 -1
  7. package/arcade/functions/string.js +1 -1
  8. package/arcgisGlobal.d.ts +1 -1
  9. package/assets/esri/core/workers/RemoteClient.js +1 -1
  10. package/assets/esri/core/workers/chunks/05b34302da58e8244da3.js +1 -0
  11. package/assets/esri/core/workers/chunks/28b74bc77f7c13080074.js +1 -0
  12. package/assets/esri/core/workers/chunks/2a226b69d38c72a47a08.js +1 -0
  13. package/assets/esri/core/workers/chunks/47e250d471d0e55fa6be.js +1 -0
  14. package/assets/esri/core/workers/chunks/{a07cb6a2f5b66d4e9f15.js → 49ff0985fb307ac193ab.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{dc486a3595b6d57018bb.js → 5bfea0c55aca826de536.js} +1 -1
  16. package/assets/esri/core/workers/chunks/5f4feca26102088ea565.js +1 -0
  17. package/assets/esri/core/workers/chunks/{407f1e8176f3b0af73b4.js → 66867e523cc82f8fe35b.js} +1 -1
  18. package/assets/esri/core/workers/chunks/67ebc5a3d46b254b725c.js +1 -0
  19. package/assets/esri/core/workers/chunks/6c469b43089767176ced.js +1 -0
  20. package/assets/esri/core/workers/chunks/{6e62581d933e7298d1f6.js → 6f4e6022a52de0c54aab.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{693873b3eb99fba58fa9.js → 78c4e43cfa1eda06b4d9.js} +1 -1
  22. package/assets/esri/core/workers/chunks/81cad8d2f62a5f671c55.js +1 -0
  23. package/assets/esri/core/workers/chunks/{588e677f33df86a595bf.js → 820c8aaf3632edb0150c.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{5924ec3167a2941ebb1f.js → 88c74f3316f1fc253207.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{a4162a8660bf763d542d.js → 967b4992b400517ee712.js} +1 -1
  26. package/assets/esri/core/workers/chunks/96b6ea199ad949fef17c.js +1 -0
  27. package/assets/esri/core/workers/chunks/{adf25e5ed99615b83c68.js → a62c12925303ff802c3d.js} +1 -1
  28. package/assets/esri/core/workers/chunks/acdfd275dbf8533a67f3.js +1 -0
  29. package/assets/esri/core/workers/chunks/b3007aedbf731dacaff1.js +1 -0
  30. package/assets/esri/core/workers/chunks/{9232f57623e1fa3ccabc.js → be5f92e98d09d6e6e38e.js} +1 -1
  31. package/assets/esri/core/workers/chunks/c1254cd131a62750ff6f.js +1 -0
  32. package/assets/esri/core/workers/chunks/{a7f3576208f295b670d6.js → c19cd5a03b6d480fe53b.js} +1 -1
  33. package/assets/esri/core/workers/chunks/c19f238b55ff2893f7c2.js +1 -0
  34. package/assets/esri/core/workers/chunks/c72a904e01dc8c17d992.js +1 -0
  35. package/assets/esri/core/workers/chunks/d33360c4f85203edafff.js +1 -0
  36. package/assets/esri/core/workers/chunks/de6081df29183bf80787.js +1 -0
  37. package/assets/esri/core/workers/chunks/e653c81ffb3d818645dd.js +1 -0
  38. package/assets/esri/core/workers/chunks/eb815148ae65388dd733.js +1 -0
  39. package/assets/esri/core/workers/chunks/ee6679ef9efa1504e7eb.js +1 -0
  40. package/assets/esri/core/workers/chunks/fda83bcb8e40e8044c24.js +1 -0
  41. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  42. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  43. package/assets/esri/libs/pdfjs/wasm/openjpeg_nowasm_fallback.js +1 -0
  44. package/assets/esri/widgets/support/uriUtils/t9n/messages.fr.json +1 -1
  45. package/chunks/lyr3DMain.js +1 -1
  46. package/chunks/lyr3DWorker.js +2 -2
  47. package/chunks/portal.js +1 -1
  48. package/config.js +1 -1
  49. package/form/elements/inputs/DynamicChoiceInput.d.ts +4 -2
  50. package/geometry/support/curves/ellipticArc7Utils.js +1 -1
  51. package/geometry/support/curves/mathUtils.js +1 -1
  52. package/geometry/support/meshUtils.d.ts +5 -6
  53. package/interfaces.d.ts +19 -10
  54. package/kernel.js +1 -1
  55. package/layers/FeatureLayer.d.ts +2 -2
  56. package/layers/GeospatialPDFLayer.d.ts +154 -4
  57. package/layers/Layer.d.ts +2 -0
  58. package/layers/SketchLayer.d.ts +4 -2
  59. package/layers/geospatialPDF/GeospatialPDFLayerWorker.js +1 -1
  60. package/layers/geospatialPDF/ViewportMeasureFrame.js +1 -1
  61. package/layers/geospatialPDF/geospatialPDFParserUtils.js +1 -1
  62. package/layers/geospatialPDF/projectionToWKTUtils.js +2 -2
  63. package/layers/graphics/sources/GeoJSONSource.js +1 -1
  64. package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
  65. package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
  66. package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
  67. package/layers/graphics/sources/support/sourceUtils.js +1 -1
  68. package/layers/support/LabelClass.d.ts +3 -2
  69. package/layers/support/PortalItemData.d.ts +31 -8
  70. package/layers/support/{TimeSeriesCalculation.d.ts → TimeSeriesCalculationMethod.d.ts} +6 -6
  71. package/layers/support/{TimeSeriesCalculation.js → TimeSeriesCalculationMethod.js} +1 -1
  72. package/layers/support/TimeSeriesInfo.d.ts +5 -5
  73. package/layers/support/TimeSeriesInfo.js +1 -1
  74. package/layers/support/fieldUtils.js +1 -1
  75. package/layers/support/timeSeriesUtils.d.ts +6 -2
  76. package/layers/support/timeSeriesUtils.js +1 -1
  77. package/layers/support/types.d.ts +4 -1
  78. package/layers/support/vectorTileLayerLoader.js +1 -1
  79. package/package.json +2 -2
  80. package/portal/schemas/definitions.js +1 -1
  81. package/smartMapping/renderers/support/timeSeriesUtils.js +1 -1
  82. package/smartMapping/statistics/support/timeSeriesUtils.js +1 -1
  83. package/symbols/cim/cimAnalyzer.js +1 -1
  84. package/views/2d/engine/vectorTiles/TileHandler.js +1 -1
  85. package/views/2d/engine/vectorTiles/style/GeoJSONVectorTileSource.js +1 -1
  86. package/views/2d/engine/vectorTiles/style/GeoJSONVectorTileSourceWorker.js +1 -1
  87. package/views/2d/engine/vectorTiles/style/geoJSONVectorTileUtils.js +2 -0
  88. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  89. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/raster/projection.js +1 -1
  90. package/views/2d/layers/VectorTileLayerView2D.js +1 -1
  91. package/views/2d/layers/features/schema/processor/symbols/ComplexSymbolSchema.js +1 -1
  92. package/views/3d/analysis/LineOfSight/LineOfSightObserverPlugin.js +1 -1
  93. package/views/3d/analysis/LineOfSight/LineOfSightTargetPlugin.js +1 -1
  94. package/views/3d/analysis/Viewshed/ViewshedPlacementPointPlugin.js +1 -1
  95. package/views/3d/webgl-engine/core/shaderLibrary/raster/Projection.glsl.js +2 -2
  96. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.js +1 -1
  97. package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
  98. package/views/3d/webgl-engine/lib/MainFramebuffer.js +1 -1
  99. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  100. package/views/3d/webgl-engine/lib/PathCapBuilder.js +1 -1
  101. package/views/3d/webgl-engine/lib/PathEvaluator.js +1 -1
  102. package/views/3d/webgl-engine/lib/PathExtruder.js +1 -1
  103. package/views/3d/webgl-engine/lib/PathProfile.js +1 -1
  104. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  105. package/views/3d/webgl-engine/lib/pathGeometryUtils.js +1 -1
  106. package/views/3d/webgl-engine/parts/ScreenshotManager.js +1 -1
  107. package/views/draw/DrawTool.js +1 -1
  108. package/views/draw/plugins/MultipointPlugin.js +1 -1
  109. package/views/draw/support/PluginContext.js +1 -1
  110. package/views/draw/support/managers/TooltipManager.js +1 -1
  111. package/views/draw/support/types.d.ts +5 -2
  112. package/webdoc/applicationProperties/SearchLayerField.d.ts +7 -1
  113. package/webdoc/applicationProperties/SearchLayerField.js +1 -1
  114. package/webdoc/applicationProperties/SearchTableField.d.ts +7 -1
  115. package/webdoc/applicationProperties/SearchTableField.js +1 -1
  116. package/webdoc/applicationProperties/searchMode.js +2 -0
  117. package/widgets/BatchAttributeForm/batchAttributeFormUtils.js +1 -1
  118. package/widgets/BatchAttributeForm/inputs/support/DynamicChoiceController.js +1 -1
  119. package/widgets/BatchAttributeForm/inputs/support/inputUtils.js +1 -1
  120. package/widgets/BatchAttributeForm.js +1 -1
  121. package/widgets/Editor/EditorViewModel.d.ts +10 -1
  122. package/widgets/Editor.d.ts +10 -1
  123. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  124. package/widgets/FeatureTable/support/FeatureStore.js +1 -1
  125. package/widgets/Legend.d.ts +1 -0
  126. package/widgets/Search/LayerSearchSource.d.ts +23 -1
  127. package/widgets/Search/LayerSearchSource.js +1 -1
  128. package/widgets/Search/support/layerSearchUtils.js +1 -1
  129. package/widgets/Search/types.d.ts +7 -0
  130. package/widgets/support/forms/formUtils.js +1 -1
  131. package/widgets/support/forms/types.d.ts +1 -1
  132. package/assets/esri/core/workers/chunks/03afeefb9d16b6f1d844.js +0 -1
  133. package/assets/esri/core/workers/chunks/09b9a886363bc1197785.js +0 -1
  134. package/assets/esri/core/workers/chunks/21f45a47708e6e43147f.js +0 -1
  135. package/assets/esri/core/workers/chunks/2ecfaa715863216f0faf.js +0 -1
  136. package/assets/esri/core/workers/chunks/3cc43ae56779a9f97f77.js +0 -1
  137. package/assets/esri/core/workers/chunks/3e8eb158320f0e4ce1b6.js +0 -1
  138. package/assets/esri/core/workers/chunks/4fc337240e7cddd0e988.js +0 -1
  139. package/assets/esri/core/workers/chunks/5732fdf6d8b87739aeea.js +0 -1
  140. package/assets/esri/core/workers/chunks/5fa1ec357c3ad1f91bc7.js +0 -1
  141. package/assets/esri/core/workers/chunks/7320a4913b6cad7cc5d7.js +0 -1
  142. package/assets/esri/core/workers/chunks/7d1fd2df579a4b535e0e.js +0 -1
  143. package/assets/esri/core/workers/chunks/879b2de825c1dfc8849d.js +0 -1
  144. package/assets/esri/core/workers/chunks/8c4e0a7384e40979cb42.js +0 -1
  145. package/assets/esri/core/workers/chunks/937824bc7948f7bc7845.js +0 -1
  146. package/assets/esri/core/workers/chunks/9e142551163acf752618.js +0 -1
  147. package/assets/esri/core/workers/chunks/b132ffa7e8bb461b6786.js +0 -1
  148. package/assets/esri/core/workers/chunks/b19b6102ed2d6f67b43b.js +0 -1
  149. package/assets/esri/core/workers/chunks/dca35dbe427605ef6fcc.js +0 -1
  150. package/assets/esri/core/workers/chunks/f095cf98940e3f95d51e.js +0 -1
@@ -54,4 +54,4 @@ this.workerSrc)).WorkerMessageHandler})())}}class er{downloadInfoCapability=Prom
54
54
  `)}`;this.#l();let u=new Range,d=Math.sumPrecise(c.map(e=>e.length));for(let{firstChild:e}of this.editorDiv.childNodes)if(e.nodeType===Node.TEXT_NODE){let t=e.nodeValue.length;if(d<=t){u.setStart(e,d);u.setEnd(e,d);break}d-=t}i.removeAllRanges();i.addRange(u)}#l(){this.editorDiv.replaceChildren();if(this.#e)for(let e of this.#e.split(`
55
55
  `)){let t=document.createElement(`div`);t.append(e?document.createTextNode(e):document.createElement(`br`));this.editorDiv.append(t)}}#u(){return this.#e.replaceAll(`\xA0`,` `)}static#d(e){return e.replaceAll(` `,`\xA0`)}get contentDiv(){return this.editorDiv}getPDFRect(){let e=X._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,n){let r=null;if(e instanceof pr){let{data:{defaultAppearanceData:{fontSize:t,fontColor:n},rect:i,rotation:a,id:o,popupRef:s,richText:c,contentsObj:l,creationDate:u,modificationDate:d},textContent:f,textPosition:p,parent:{page:{pageNumber:m}}}=e;if(!f||f.length===0)return null;r=e={annotationType:y.FREETEXT,color:Array.from(n),fontSize:t,value:f.join(`
56
56
  `),position:p,pageIndex:m-1,rect:i.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let i=await super.deserialize(e,t,n);i.#r=e.fontSize;i.color=P.makeHexColor(...e.color);i.#e=X.#d(e.value);i._initialData=r;e.comment&&i.setCommentData(e);return i}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#r,value:this.#u()});this.addComment(n);if(e){n.isCopy=!0;return n}if(this.annotationElementId&&!this.#f(n))return null;n.id=this.annotationElementId;return n}#f(e){let{value:t,fontSize:n,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((e,t)=>e!==r[t])||e.pageIndex!==i}renderAnnotationElement(e){let t=super.renderAnnotationElement(e);if(!t)return null;let{style:n}=t;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`;n.color=this.color;t.replaceChildren();for(let e of this.#e.split(`
57
- `)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){k("Abstract method `toSVGPath` must be implemented.")}get box(){k("Abstract getter `box` must be implemented.")}serialize(e,t){k("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class vr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=vr.#p+vr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=vr.#p*r;this.#c=vr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new yr(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class yr extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(d,p,i);if(o>p){a=d;o=p}else o===p&&(a=l(a,d));if(c<p){s=d;c=p}else c===p&&(s=l(s,d))}else{u.set(f,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),u);P.rectBoundingBox(...u,i);if(o>u[1]){a=u[0];o=u[1]}else o===u[1]&&(a=l(a,u[0]));if(c<u[3]){s=u[2];c=u[3]}else c===u[3]&&(s=l(s,u[2]))}n=d;r=p}let d=this.#t;d[0]=i[0]-this.#n;d[1]=i[1]-this.#n;d[2]=i[2]-i[0]+2*this.#n;d[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new vr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class br{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=f.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<d){d=n;u=t}else n===d&&(u=Math.max(u,t))}else if(a&&!r){if(n<d){d=n;u=t}else n===d&&(u=Math.min(u,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[u,d];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new xr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class xr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class Sr extends vr{newFreeDrawOutline(e,t,n,r,i,a){return new Cr(e,t,n,r,i,a)}}class Cr extends yr{newOutliner(e,t,n,r,i,a=0){return new Sr(e,t,n,r,i,a)}}class Q extends V{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=y.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new br(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new br(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){V.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case b.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:this.#b(t);break;case b.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,Q._defaultColor],[b.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[b.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[b.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new J({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Fe(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new Sr({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof hr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Sr(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class wr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){k(`Not implemented`)}}class $ extends V{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){k(`Not implemented`)}static get typesMap(){k(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){k(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(B.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);B.setPointer(c,s);window.addEventListener(`pointerup`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(B.isSamePointerType(e.pointerType)){B.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{B.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){B.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(B.isSamePointerId(r)){if(B.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));B.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;B.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;B.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:b.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(b.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){k(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Tr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Er;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Er extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=p.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Dr extends wr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:V._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Dr(this._viewParameters);e.updateAll(this);return e}}class Or extends ${static _type=`ink`;static _editorType=y.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new Dr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[b.INK_THICKNESS,`stroke-width`],[b.INK_COLOR,`stroke`],[b.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Tr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:y.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.INK_COLOR}get colorAndOpacityType(){return b.INK_COLOR_AND_OPACITY}get opacityType(){return b.INK_OPACITY}updateParams(e,t){e===b.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==b.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(b.INK_COLOR,t.color);super.updateDefaultParams(b.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Or.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:V._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class kr extends Er{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Ar{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new kr:new Er;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){O(`decompressSignature: ${e}`);return null}}}class jr extends wr{constructor(){super();super.updateProperties({fill:V._defaultLineColor,"stroke-width":0})}clone(){let e=new jr;e.updateAll(this);return e}}class Mr extends Dr{constructor(e){super(e);super.updateProperties({stroke:V._defaultLineColor,"stroke-width":1})}clone(){let e=new Mr(this._viewParameters);e.updateAll(this);return e}}class Nr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=y.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new jr;this._defaultDrawnSignatureOptions=new Mr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Ar.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:Nr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}else{this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``}));this.div.hidden=!0;this._uiManager.getSignature(this)}}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Ar.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof kr;this.description=n;let s;if(this.#e)s=Nr.getDefaultDrawingOptions();else{s=Nr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.process(e,t,n,r,Nr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ar.extractContoursFromText(e,t,n,r,i,Nr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:Nr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=Nr.getDefaultDrawingOptions();else{this._drawingOptions=Nr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?kr.deserialize(e,t,n,r,i,a):Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Pr extends V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=y.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){V.initialize(e,t)}static isHandlingMimeForPasting(e){return ke.includes(e)}static paste(e,t){t.pasteEditor({mode:y.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=ke.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Oe,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(Ae.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Oe,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*he.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*he.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof gr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,v,b;if(g){delete e.canvas;({id:v,bitmap:b}=n.imageManager.getFromCanvas(m.id,g));g.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${_}${s}`))?.get(`aria-label`)||``;r=e={annotationType:y.STAMP,bitmapId:v,bitmap:b,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Fr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Or,Pr,Q,Nr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Fr.#g.values()];if(!Fr._initialized){Fr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===y.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case y.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case y.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case y.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===y.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Fr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${v}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Fr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);V.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Fr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Fr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==y.STAMP&&n!==y.POPUP&&n!==y.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===y.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;De(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;De(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:br};const Ir={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Lr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){c()||await l();r(s);let[{data:u},d]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),f=Yn({data:u,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Ir,enableHWA:!0,useWorkerFetch:!0,worker:d});this._pdfDocument=await f.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:c,ctm:l}=e,d=s.fromJSON(o),f=await u(d,i,a,l,this._page,this._baseViewport,this._inverseBaseViewport,c,t);r(t);return Rr(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new q({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Rr(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Lr as default};
57
+ `)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){k("Abstract method `toSVGPath` must be implemented.")}get box(){k("Abstract getter `box` must be implemented.")}serialize(e,t){k("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class vr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=vr.#p+vr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=vr.#p*r;this.#c=vr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new yr(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class yr extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(d,p,i);if(o>p){a=d;o=p}else o===p&&(a=l(a,d));if(c<p){s=d;c=p}else c===p&&(s=l(s,d))}else{u.set(f,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),u);P.rectBoundingBox(...u,i);if(o>u[1]){a=u[0];o=u[1]}else o===u[1]&&(a=l(a,u[0]));if(c<u[3]){s=u[2];c=u[3]}else c===u[3]&&(s=l(s,u[2]))}n=d;r=p}let d=this.#t;d[0]=i[0]-this.#n;d[1]=i[1]-this.#n;d[2]=i[2]-i[0]+2*this.#n;d[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new vr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class br{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=f.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<d){d=n;u=t}else n===d&&(u=Math.max(u,t))}else if(a&&!r){if(n<d){d=n;u=t}else n===d&&(u=Math.min(u,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[u,d];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new xr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class xr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class Sr extends vr{newFreeDrawOutline(e,t,n,r,i,a){return new Cr(e,t,n,r,i,a)}}class Cr extends yr{newOutliner(e,t,n,r,i,a=0){return new Sr(e,t,n,r,i,a)}}class Q extends V{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=y.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new br(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new br(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){V.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case b.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:this.#b(t);break;case b.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,Q._defaultColor],[b.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[b.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[b.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new J({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Fe(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new Sr({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof hr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Sr(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class wr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){k(`Not implemented`)}}class $ extends V{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){k(`Not implemented`)}static get typesMap(){k(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){k(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(B.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);B.setPointer(c,s);window.addEventListener(`pointerup`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(B.isSamePointerType(e.pointerType)){B.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{B.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){B.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(B.isSamePointerId(r)){if(B.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));B.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;B.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;B.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:b.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(b.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){k(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Tr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Er;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Er extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=p.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Dr extends wr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:V._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Dr(this._viewParameters);e.updateAll(this);return e}}class Or extends ${static _type=`ink`;static _editorType=y.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new Dr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[b.INK_THICKNESS,`stroke-width`],[b.INK_COLOR,`stroke`],[b.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Tr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:y.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.INK_COLOR}get colorAndOpacityType(){return b.INK_COLOR_AND_OPACITY}get opacityType(){return b.INK_OPACITY}updateParams(e,t){e===b.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==b.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(b.INK_COLOR,t.color);super.updateDefaultParams(b.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Or.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:V._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class kr extends Er{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Ar{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new kr:new Er;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){O(`decompressSignature: ${e}`);return null}}}class jr extends wr{constructor(){super();super.updateProperties({fill:V._defaultLineColor,"stroke-width":0})}clone(){let e=new jr;e.updateAll(this);return e}}class Mr extends Dr{constructor(e){super(e);super.updateProperties({stroke:V._defaultLineColor,"stroke-width":1})}clone(){let e=new Mr(this._viewParameters);e.updateAll(this);return e}}class Nr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=y.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new jr;this._defaultDrawnSignatureOptions=new Mr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Ar.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:Nr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}else{this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``}));this.div.hidden=!0;this._uiManager.getSignature(this)}}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Ar.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof kr;this.description=n;let s;if(this.#e)s=Nr.getDefaultDrawingOptions();else{s=Nr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.process(e,t,n,r,Nr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ar.extractContoursFromText(e,t,n,r,i,Nr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:Nr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=Nr.getDefaultDrawingOptions();else{this._drawingOptions=Nr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?kr.deserialize(e,t,n,r,i,a):Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Pr extends V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=y.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){V.initialize(e,t)}static isHandlingMimeForPasting(e){return ke.includes(e)}static paste(e,t){t.pasteEditor({mode:y.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=ke.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Oe,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(Ae.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Oe,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*he.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*he.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof gr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,v,b;if(g){delete e.canvas;({id:v,bitmap:b}=n.imageManager.getFromCanvas(m.id,g));g.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${_}${s}`))?.get(`aria-label`)||``;r=e={annotationType:y.STAMP,bitmapId:v,bitmap:b,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Fr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Or,Pr,Q,Nr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Fr.#g.values()];if(!Fr._initialized){Fr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===y.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case y.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case y.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case y.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===y.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Fr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${v}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Fr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);V.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Fr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Fr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==y.STAMP&&n!==y.POPUP&&n!==y.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===y.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;De(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;De(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:br};const Ir={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Lr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){c()||await l();r(s);let[{data:u},d]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),f=Yn({data:u,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Ir,enableHWA:!0,useWorkerFetch:!0,worker:d,useWasm:!0});this._pdfDocument=await f.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:c,ctm:l}=e,d=s.fromJSON(o),f=await u(d,i,a,l,this._page,this._baseViewport,this._inverseBaseViewport,c,t);r(t);return Rr(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new q({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Rr(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Lr as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../core/Error.js";import{fromValues as t}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import n from"../../geometry/Point.js";import r from"../../geometry/SpatialReference.js";import{projectExecute as i}from"../../geometry/operators/projectOperator.js";import{expandMediaBox as a,validateTransform as o,affineTransformationFromGeoreference as s,createGeoreferencer as c}from"./sharedUtils.js";class l{constructor(e){let{bbox:t,bounds:n,gpts:r,lpts:i,gcs:c,mediaBox:l}=this.inputValidation(e);this._bbox=t,this._bounds=n,this._gpts=r,this._lpts=i,this._gcs=c,this.outerExtentMediaBox=a(l),this.geoControlPoints=this._getProjectedGeoControlPoints().map(e=>[e[0],e[1]]);let u=this._getBoundsPolygonPage()??this._getPageControlPoints();this.pairedNeatline=u.map(e=>[e[0],e[1]]),this.neatLine=this.pairedNeatline.flat(),this._georeference=this._createControlPointsGeoreference();let d=o(this._georeference);this.ctm=s(d),this.outputValidation()}toSpatialReference(){return new r({wkt:this._gcs.WKT})}inputValidation(t){let{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}=t;if(!n||n.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid BBox.`);if(!s||s.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid MediaBox.`);if(!i||i.length<6||i.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid GPTS.`);if(!a||a.length<6||a.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid LPTS.`);if(a.length!==i.length)throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame LPTS and GPTS must be same length`);if(!o?.WKT)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid WKT.`);return{bbox:n,bounds:r,gpts:i,lpts:a,gcs:{WKT:o.WKT},mediaBox:s}}outputValidation(){if(this.outerExtentMediaBox.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Failed to generate outer extent from mediaBox.`);if(this.geoControlPoints.length<2)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 2 geoControlPoints.`);if(this.pairedNeatline.length<4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 4 neatline points.`);if(!this.ctm||this.ctm.length!==6)throw new e(`geospatial-pdf-layer:invalid-frame`,`Missing or invalid Map Frame CTM`)}_createControlPointsGeoreference(){let e=this._getPageControlPoints(),t=this._getProjectedGeoControlPoints(),n=this._getViewportRect();return c(e,t,this.toSpatialReference(),n)}_getBoundsPolygonLocal(){if(!this._bounds||this._bounds.length<8||this._bounds.length%2!=0)return null;let e=[];for(let t=0;t<this._bounds.length;t+=2)e.push({u:this._bounds[t],v:this._bounds[t+1]});return e}_getBoundsPolygonPage(){return this._getBoundsPolygonLocal()?.map(e=>this._localToPage(e.u,e.v))??null}_getPageControlPoints(){let e=[];for(let t=0;t<this._lpts.length;t+=2){let n=this._lpts[t],r=this._lpts[t+1];e.push(this._localToPage(n,r))}return e}_getProjectedGeoControlPoints(){let e=this.toSpatialReference(),r=[];for(let a=0;a<this._gpts.length;a+=2){let o=this._gpts[a],s=this._gpts[a+1],c=new n({x:s,y:o}),l=i(c,e);r.push(t(l.x,l.y))}return r}_getViewportRect(){let[e,t,n,r]=this._bbox;return{xmin:Math.min(e,n),ymin:Math.min(t,r),xmax:Math.max(e,n),ymax:Math.max(t,r)}}_localToPage(e,n){let[r,i,a,o]=this._bbox;return t(r+e*(a-r),i+n*(o-i))}}export{l as ViewportMeasureFrame};
2
+ import e from"../../core/Error.js";import{fromValues as t}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import n from"../../geometry/Point.js";import r from"../../geometry/SpatialReference.js";import{projectExecute as i}from"../../geometry/operators/projectOperator.js";import{expandMediaBox as a,validateTransform as o,affineTransformationFromGeoreference as s,createGeoreferencer as c}from"./sharedUtils.js";class l{constructor(e){let{bbox:t,bounds:n,gpts:r,lpts:i,gcs:c,mediaBox:l}=this.inputValidation(e);this._bbox=t,this._bounds=n,this._gpts=r,this._lpts=i,this._gcs=c,this.outerExtentMediaBox=a(l),this.geoControlPoints=this._getProjectedGeoControlPoints().map(e=>[e[0],e[1]]);let u=this._getBoundsPolygonPage()??this._getPageControlPoints();this.pairedNeatline=u.map(e=>[e[0],e[1]]),this.neatLine=this.pairedNeatline.flat(),this._georeference=this._createControlPointsGeoreference();let d=o(this._georeference);this.ctm=s(d),this.outputValidation()}toSpatialReference(){let t=this._gcs;if(t?.WKT)return new r({wkt:t.WKT});if(t?.EPSG!=null)return new r({wkid:t.EPSG});throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame missing WKT or EPSG.`)}inputValidation(t){let{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}=t;if(!n||n.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid BBox.`);if(!s||s.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid MediaBox.`);if(!i||i.length<6||i.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid GPTS.`);if(!a||a.length<6||a.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid LPTS.`);if(a.length!==i.length)throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame LPTS and GPTS must be same length`);if(!o?.WKT&&!o?.EPSG)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing a WKT or EPSG code.`);return{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}}outputValidation(){if(this.outerExtentMediaBox.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Failed to generate outer extent from mediaBox.`);if(this.geoControlPoints.length<2)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 2 geoControlPoints.`);if(this.pairedNeatline.length<4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 4 neatline points.`);if(!this.ctm||this.ctm.length!==6)throw new e(`geospatial-pdf-layer:invalid-frame`,`Missing or invalid Map Frame CTM`)}_createControlPointsGeoreference(){let e=this._getPageControlPoints(),t=this._getProjectedGeoControlPoints(),n=this._getViewportRect();return c(e,t,this.toSpatialReference(),n)}_getBoundsPolygonLocal(){if(!this._bounds||this._bounds.length<8||this._bounds.length%2!=0)return null;let e=[];for(let t=0;t<this._bounds.length;t+=2)e.push({u:this._bounds[t],v:this._bounds[t+1]});return e}_getBoundsPolygonPage(){return this._getBoundsPolygonLocal()?.map(e=>this._localToPage(e.u,e.v))??null}_getPageControlPoints(){let e=[];for(let t=0;t<this._lpts.length;t+=2){let n=this._lpts[t],r=this._lpts[t+1];e.push(this._localToPage(n,r))}return e}_getProjectedGeoControlPoints(){let e=this.toSpatialReference(),r=[];for(let a=0;a<this._gpts.length;a+=2){let o=this._gpts[a],s=this._gpts[a+1],c=new n({x:s,y:o}),l=i(c,e);r.push(t(l.x,l.y))}return r}_getViewportRect(){let[e,t,n,r]=this._bbox;return{xmin:Math.min(e,n),ymin:Math.min(t,r),xmax:Math.max(e,n),ymax:Math.max(t,r)}}_localToPage(e,n){let[r,i,a,o]=this._bbox;return t(r+e*(a-r),i+n*(o-i))}}export{l as ViewportMeasureFrame};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../core/Error.js";import"../../core/has.js";import{LGIDictMapFrame as t}from"./LGIDictMapFrame.js";import{projectionToSpatialReference as n}from"./projectionToWKTUtils.js";import{ViewportMeasureFrame as r}from"./ViewportMeasureFrame.js";function i(i,s=0){let c={mediaBox:_(i.MediaBox),rotate:x(i.Rotate),hasLGIDict:i.LGIDict!=null,hasVP:i.VP!=null},l=a(i.LGIDict,s);if(l){if(!l.Projection)throw new e(`geospatial-pdf-layer:parse`,`LGIDict map frame missing Projection.`);let r=n(l.Projection),a;try{a=l.Display?n(l.Display):void 0}catch{a=r}return{result:c,lgiDictFrame:new t({ctm:l.CTM,registration:l.Registration,projection:r,display:a,neatline:l.Neatline,mediaBox:_(i.MediaBox)})}}let u=o(i.VP,s);return u?{result:c,vpFrame:new r({bbox:u.BBox,bounds:u.Measure?.Bounds,gpts:u.Measure?.GPTS,lpts:u.Measure?.LPTS,gcs:u.Measure?.GCS,mediaBox:_(i.MediaBox)})}:{result:c}}function a(e,t){return s(e)[t]}function o(e,t){return c(e)[t]}function s(e){return e==null?[]:Array.isArray(e)?e.map(e=>l(e)):[l(e)]}function c(e){return e==null?[]:Array.isArray(e)?e.map(e=>u(e)):[u(e)]}function l(e){let t=C(e,`LGIDict map frame must be an object.`);return{CTM:_(t.CTM),Registration:v(t.Registration),Neatline:_(t.Neatline),Projection:p(t.Projection),Display:p(t.Display)}}function u(e){let t=C(e,`Viewport frame must be an object.`),n=d(t.Measure);return{BBox:_(t.BBox),Measure_Raw:t.Measure,Measure:n,Raw:t}}function d(e){if(S(e))return{Bounds:_(e.Bounds),GPTS:_(e.GPTS),LPTS:_(e.LPTS),GCS:f(e.GCS)}}function f(e){if(S(e))return{WKT:y(e.WKT)}}function p(e){if(S(e))return{Type:b(e.Type),Units:b(e.Units),Datum:m(e.Datum),Projection_Type:b(e.ProjectionType),Central_Meridian:x(e.CentralMeridian),False_Easting:x(e.FalseEasting),False_Northing:x(e.FalseNorthing),Height:x(e.Height),Hemisphere:b(e.Hemisphere),Latitude_One:x(e.LatitudeOne),Latitude_Two:x(e.LatitudeTwo),Latitude_Of_True_Scale:x(e.LatitudeOfTrueScale),Longitude_One:x(e.LongitudeOne),Longitude_Two:x(e.LongitudeTwo),Longitude_Down_From_Pole:x(e.LongitudeDownFromPole),Orientation:b(e.Orientation),Origin_Height:x(e.OriginHeight),Origin_Latitude:x(e.OriginLatitude),Origin_Longitude:x(e.OriginLongitude),Scale_Factor:x(e.ScaleFactor),Standard_Parallel:x(e.StandardParallel),Standard_Parallel_One:x(e.StandardParallelOne),Standard_Parallel_Two:x(e.StandardParallelTwo),Zone:x(e.Zone),Description:b(e.Description),raw:e}}function m(e){return e==null?null:typeof e==`string`?{kind:`name`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}:S(e)?{kind:`definition`,name:b(e.Description),ellipsoid:h(e.Ellipsoid),to_WGS84:g(e.ToWGS84),raw:e}:{kind:`unknown`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}}function h(e){if(S(e))return{semi_Major_Axis:x(e.SemiMajorAxis),inverse_Flattening:x(e.InvFlattening),semi_Minor_Axis:x(e.SemiMinorAxis),description:b(e.Description)}}function g(e){if(S(e))return{dx:x(e.dx)??0,dy:x(e.dy)??0,dz:x(e.dz)??0,rx:x(e.rx)??0,ry:x(e.ry)??0,rz:x(e.rz)??0,sf:x(e.sf)??0}}function _(e){if(!Array.isArray(e))return;let t=[];for(let n of e){let e=x(n);if(e===void 0)return;t.push(e)}return t}function v(e){if(Array.isArray(e))return e.filter(e=>Array.isArray(e)).map(e=>e.map(e=>x(e)).filter(e=>e!==void 0))}function y(e){if(e!=null)return typeof e==`string`?e:String(e)}function b(e){let t=y(e);if(t!==void 0)return t.trim()}function x(e){if(e==null)return;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=e.trim();if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(t,n){if(!S(t))throw new e(`geospatial-pdf-layer:parse`,n);return t}export{i as parse};
2
+ import e from"../../core/Error.js";import"../../core/has.js";import{LGIDictMapFrame as t}from"./LGIDictMapFrame.js";import{projectionToSpatialReference as n}from"./projectionToWKTUtils.js";import{ViewportMeasureFrame as r}from"./ViewportMeasureFrame.js";function i(i,s=0){let c={mediaBox:_(i.MediaBox),rotate:x(i.Rotate),hasLGIDict:i.LGIDict!=null,hasVP:i.VP!=null};if(c.hasVP){let t=o(i.VP,s);if(!t)throw new e(`geospatial-pdf-layer:invalid frame`,`Failed to parse VP frame at index ${s}`);return{result:c,vpFrame:new r({bbox:t.BBox,bounds:t.Measure?.Bounds,gpts:t.Measure?.GPTS,lpts:t.Measure?.LPTS,gcs:t.Measure?.GCS,mediaBox:_(i.MediaBox)})}}if(c.hasLGIDict){let r=a(i.LGIDict,s);if(!r)throw new e(`geospatial-pdf-layer:invalid frame`,`Failed to parse LGI Dict frame at index ${s}`);if(!r.Projection)throw new e(`geospatial-pdf-layer:parse`,`LGIDict map frame missing Projection.`);let o=n(r.Projection),l;try{l=r.Display?n(r.Display):void 0}catch{l=o}return{result:c,lgiDictFrame:new t({ctm:r.CTM,registration:r.Registration,projection:o,display:l,neatline:r.Neatline,mediaBox:_(i.MediaBox)})}}return{result:c}}function a(e,t){return s(e)[t]}function o(e,t){return c(e)[t]}function s(e){return e==null?[]:Array.isArray(e)?e.map(e=>l(e)):[l(e)]}function c(e){return e==null?[]:Array.isArray(e)?e.map(e=>u(e)):[u(e)]}function l(e){let t=C(e,`LGIDict map frame must be an object.`);return{CTM:_(t.CTM),Registration:v(t.Registration),Neatline:_(t.Neatline),Projection:p(t.Projection),Display:p(t.Display)}}function u(e){let t=C(e,`Viewport frame must be an object.`),n=d(t.Measure);return{BBox:_(t.BBox),Measure_Raw:t.Measure,Measure:n,Raw:t}}function d(e){if(S(e))return{Bounds:_(e.Bounds),GPTS:_(e.GPTS),LPTS:_(e.LPTS),GCS:f(e.GCS)}}function f(e){if(S(e))return{WKT:y(e.WKT),EPSG:x(e.EPSG)}}function p(e){if(S(e))return{Type:b(e.Type),Units:b(e.Units),Datum:m(e.Datum),Projection_Type:b(e.ProjectionType),Central_Meridian:x(e.CentralMeridian),False_Easting:x(e.FalseEasting),False_Northing:x(e.FalseNorthing),Height:x(e.Height),Hemisphere:b(e.Hemisphere),Latitude_One:x(e.LatitudeOne),Latitude_Two:x(e.LatitudeTwo),Latitude_Of_True_Scale:x(e.LatitudeOfTrueScale),Longitude_One:x(e.LongitudeOne),Longitude_Two:x(e.LongitudeTwo),Longitude_Down_From_Pole:x(e.LongitudeDownFromPole),Orientation:b(e.Orientation),Origin_Height:x(e.OriginHeight),Origin_Latitude:x(e.OriginLatitude),Origin_Longitude:x(e.OriginLongitude),Scale_Factor:x(e.ScaleFactor),Standard_Parallel:x(e.StandardParallel),Standard_Parallel_One:x(e.StandardParallelOne),Standard_Parallel_Two:x(e.StandardParallelTwo),Zone:x(e.Zone),Description:b(e.Description),raw:e}}function m(e){return e==null?null:typeof e==`string`?{kind:`name`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}:S(e)?{kind:`definition`,name:b(e.Description),ellipsoid:h(e.Ellipsoid),to_WGS84:g(e.ToWGS84),raw:e}:{kind:`unknown`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}}function h(e){if(S(e))return{semi_Major_Axis:x(e.SemiMajorAxis),inverse_Flattening:x(e.InvFlattening),semi_Minor_Axis:x(e.SemiMinorAxis),description:b(e.Description)}}function g(e){if(S(e))return{dx:x(e.dx)??0,dy:x(e.dy)??0,dz:x(e.dz)??0,rx:x(e.rx)??0,ry:x(e.ry)??0,rz:x(e.rz)??0,sf:x(e.sf)??0}}function _(e){if(!Array.isArray(e))return;let t=[];for(let n of e){let e=x(n);if(e===void 0)return;t.push(e)}return t}function v(e){if(Array.isArray(e))return e.filter(e=>Array.isArray(e)).map(e=>e.map(e=>x(e)).filter(e=>e!==void 0))}function y(e){if(e!=null)return typeof e==`string`?e:String(e)}function b(e){let t=y(e);if(t!==void 0)return t.trim()}function x(e){if(e==null)return;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=e.trim();if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(t,n){if(!S(t))throw new e(`geospatial-pdf-layer:parse`,n);return t}export{i as parse};
@@ -1,3 +1,3 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../core/Error.js";import t from"../../geometry/SpatialReference.js";const n={OriginLatitude:`Origin_Latitude`,CentralMeridian:`Central_Meridian`,ScaleFactor:`Scale_Factor`,FalseEasting:`False_Easting`,FalseNorthing:`False_Northing`,Zone:`Zone`,Hemisphere:`Hemisphere`,StandardParallelOne:`Standard_Parallel_One`,StandardParallelTwo:`Standard_Parallel_Two`},r=/^(?:NAD83|NORTH AMERICAN 1983|NAR(?:-[A-Z])?)$/i,i=/^(?:NAD27|NORTH AMERICAN 1927|NAS(?:-[A-Z])?)$/i,a=/^(?:WGS84|WGS 84|WGE)$/i;function o(e){let n=s(e);if(n.kind===`projected`){let{projectionType:r,datum:i}=n;return r===`SPCS`?O(e,i):new t({wkt:p(e,r,i)})}}function s(e){return c(e)}function c(t){let n=l(t.Type),r=u(t.Projection_Type),i;if(r||(i=`Projection is missing or has unsupported ProjectionType`),n||(i=`Projection dictionary is missing or has invalid Type. Expected Projection or Display.`),t.Datum||(i=`Projection is missing a Datum`),i)throw new e(`geospatial-pdf-layer:invalid-projection`,i);return d(t,r),{kind:`projected`,dictionaryType:n,projectionType:r,datum:t.Datum}}function l(e){switch(e){case`Projection`:case`Display`:return e;default:return}}function u(e){switch(e){case`TC`:case`PH`:case`UT`:case`AC`:case`LE`:case`SPCS`:return e;default:return}}function d(t,r){let i=f(r);for(let a of i){let i=t[n[a]];if(i===void 0||i===``)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection ${r} missing required parameter ${a}.`)}}function f(e){switch(e){case`TC`:return[`OriginLatitude`,`CentralMeridian`,`ScaleFactor`,`FalseEasting`,`FalseNorthing`];case`PH`:return[`OriginLatitude`,`CentralMeridian`,`FalseEasting`,`FalseNorthing`];case`UT`:return[`Zone`,`Hemisphere`];case`AC`:case`LE`:return[`OriginLatitude`,`CentralMeridian`,`StandardParallelOne`,`StandardParallelTwo`,`FalseEasting`,`FalseNorthing`];case`SPCS`:return[`Zone`]}}function p(e,t,n){let r=h(e,t,n),i=m(t),a=_(n),o=v(e.Units??`M`),s=y(e,t);return`PROJCS["${r}",GEOGCS["${S(n)}",${a},PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["${i}"],${s.join(`,
3
- `)},${o}]`}function m(e){switch(e){case`TC`:case`UT`:return`Transverse_Mercator`;case`PH`:return`Polyconic`;case`AC`:return`Albers`;case`LE`:return`Lambert_Conformal_Conic`}}function h(e,t,n){let r=g(n);switch(t){case`TC`:return`${r}_GeospatialPDF_Transverse_Mercator`;case`PH`:return`${r}_GeospatialPDF_Polyconic`;case`UT`:return`${r}_GeospatialPDF_UTM_Zone_${e.Zone}_${e.Hemisphere}`;case`AC`:return`${r}_GeospatialPDF_Albers_Equal_Area`;case`LE`:return`${r}_GeospatialPDF_Lambert_Conformal_Conic`}}function g(e){let t=C(e);return t?T(t)?`NAD_1983`:E(t)?`NAD_1927`:D(t)?`WGS_1984`:`geospatialPDF`:`geospatialPDF`}function _(t){if(t.kind===`definition`){let n=t.ellipsoid;if(!n?.semi_Major_Axis)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Datum definition requires semi-major axis`);let r=x(n),i=t.name??`GeospatialPDF_Datum`,a=`SPHEROID["${n.description??`GeospatialPDF_Spheroid`}",${n.semi_Major_Axis},${r}]`,o=t.to_WGS84;return`DATUM["${i}",${a}${o?`,TOWGS84[${o.dx??0},${o.dy??0},${o.dz??0},${o.rx??0},${o.ry??0},${o.rz??0},${o.sf??0}]`:``}]`}if(t.name){let e=t.name.toUpperCase();if(T(e))return`DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]]`;if(E(e))return`DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]]`;if(D(e))return`DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]]`}throw new e(`geospatial-pdf-layer:invalid-Datum`,`Unsupported datum `+t.name)}function v(e){let t=e.toLowerCase();return[`m`,`meter`,`meters`,`metre`,`metres`].includes(t)?`UNIT["Meter",1.0]`:[`ft`,`foot`,`feet`].includes(t)?`UNIT["Foot",0.3048]`:`UNIT["${e}",1.0]`}function y(e,t){switch(t){case`TC`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Scale_Factor",${e.Scale_Factor}]`];case`PH`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`];case`AC`:case`LE`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Standard_Parallel_1",${e.Standard_Parallel_One}]`,`PARAMETER["Standard_Parallel_2",${e.Standard_Parallel_Two}]`];case`UT`:return b(e)}}function b(t){if(!t.Zone)throw new e(`geospatial-pdf-layer:invalid-projection`,`No zone found for projection code UT`);let n=t.Zone*6-183;return[`PARAMETER["False_Easting",500000]`,`PARAMETER["False_Northing",${/^s/i.test(t.Hemisphere??``)?1e7:0}]`,`PARAMETER["Central_Meridian",${n}]`,`PARAMETER["Latitude_Of_Origin",0]`,`PARAMETER["Scale_Factor",0.9996]`]}function x(t){if(t.inverse_Flattening!=null)return t.inverse_Flattening;let n=t.semi_Major_Axis,r=t.semi_Minor_Axis;if(n==null||r==null)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Ellipsoid definition missing InvFlattening or SemiMinorAxis.`);return n===r?0:n/(n-r)}function S(e){let t=C(e);return t?T(t)?`GCS_North_American_1983`:E(t)?`GCS_North_American_1927`:D(t)?`GCS_WGS_1984`:`GCS_GeospatialPDF`:`GCS_GeospatialPDF`}function C(e){return e.name?w(e.name):null}function w(e){return e.trim().toUpperCase().replace(/_/g,` `).replace(/\s+/g,` `)}function T(e){return r.test(e)}function E(e){return i.test(e)}function D(e){return a.test(e)}function O(n,r){let i=C(r);if(n.Zone===2800&&i&&T(i))return new t({wkid:32110});throw new e(`geospatial-pdf-layer:invalid-projection`,`Unsupported State Plane projection: datum ${r.name}, zone ${n.Zone}`)}export{o as projectionToSpatialReference,s as validateProjection};
2
+ import e from"../../core/Error.js";import t from"../../geometry/SpatialReference.js";const n={OriginLatitude:`Origin_Latitude`,CentralMeridian:`Central_Meridian`,ScaleFactor:`Scale_Factor`,FalseEasting:`False_Easting`,FalseNorthing:`False_Northing`,Zone:`Zone`,Hemisphere:`Hemisphere`,StandardParallelOne:`Standard_Parallel_One`,StandardParallelTwo:`Standard_Parallel_Two`},r=/^(?:NAD83|NORTH AMERICAN 1983|NAR(?:-[A-Z])?)$/i,i=/^(?:NAD27|NORTH AMERICAN 1927|NAS(?:-[A-Z])?)$/i,a=/^(?:WGS84|WGS 84|WGE)$/i;function o(e){let n=s(e);if(n.kind===`projected`){let{projectionType:r,datum:i}=n;return r===`SPCS`?O(e,i):new t({wkt:p(e,r,i)})}}function s(e){return c(e)}function c(t){let n=l(t.Type);if(!n)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection dictionary is missing or has invalid Type`,`Expected Projection or Display`);let r=t.Projection_Type;if(!r)throw new e(`geospatial-pdf-layer:invalid-projection`,`Missing projection code`);let i=u(t.Projection_Type);if(!i)throw new e(`geospatial-pdf-layer:unsupported-projection`,`Unsupported projection code: ${r}`);let a=t.Datum;if(!a)throw new e(`geospatial-pdf-layer:invalid-datum`,`Missing datum definition or code in LGI Dict frame`);if(a.kind===`unknown`)throw new e(`geospatial-pdf-layer:invalid-datum`,`Invalid datum: ${a.name??`unknown`}`);return d(t,i),{kind:`projected`,dictionaryType:n,projectionType:i,datum:t.Datum}}function l(e){switch(e){case`Projection`:case`Display`:return e;default:return}}function u(e){switch(e){case`TC`:case`PH`:case`UT`:case`AC`:case`LE`:case`SPCS`:return e;default:return}}function d(t,r){let i=f(r);for(let a of i){let i=t[n[a]];if(i===void 0||i===``)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection ${r} missing required parameter ${a}`)}}function f(e){switch(e){case`TC`:return[`OriginLatitude`,`CentralMeridian`,`ScaleFactor`,`FalseEasting`,`FalseNorthing`];case`PH`:return[`OriginLatitude`,`CentralMeridian`,`FalseEasting`,`FalseNorthing`];case`UT`:return[`Zone`,`Hemisphere`];case`AC`:case`LE`:return[`OriginLatitude`,`CentralMeridian`,`StandardParallelOne`,`StandardParallelTwo`,`FalseEasting`,`FalseNorthing`];case`SPCS`:return[`Zone`]}}function p(e,t,n){let r=h(e,t,n),i=m(t),a=_(n),o=v(e.Units??`M`),s=y(e,t);return`PROJCS["${r}",GEOGCS["${S(n)}",${a},PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["${i}"],${s.join(`,
3
+ `)},${o}]`}function m(e){switch(e){case`TC`:case`UT`:return`Transverse_Mercator`;case`PH`:return`Polyconic`;case`AC`:return`Albers`;case`LE`:return`Lambert_Conformal_Conic`}}function h(e,t,n){let r=g(n);switch(t){case`TC`:return`${r}_GeospatialPDF_Transverse_Mercator`;case`PH`:return`${r}_GeospatialPDF_Polyconic`;case`UT`:return`${r}_GeospatialPDF_UTM_Zone_${e.Zone}_${e.Hemisphere}`;case`AC`:return`${r}_GeospatialPDF_Albers_Equal_Area`;case`LE`:return`${r}_GeospatialPDF_Lambert_Conformal_Conic`}}function g(e){let t=C(e);return t?T(t)?`NAD_1983`:E(t)?`NAD_1927`:D(t)?`WGS_1984`:`geospatialPDF`:`geospatialPDF`}function _(t){if(t.kind===`definition`){let n=t.raw.Ellipsoid;if(typeof n==`string`)throw new e(`geospatial-pdf-layer:unsupported-ellipsoid`,`Only ellipsoid definitions are supported but found predefined code`,{code:n});let r=t.raw.ToWGS84;if(typeof r==`string`)throw new e(`geospatial-pdf-layer:unsupported-datum-shift`,`Only shift definitions are supported but found predefined code`,{code:r});let i=t.ellipsoid;if(!i?.semi_Major_Axis)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Datum definition requires semi-major axis`);let a=x(i),o=t.name??`GeospatialPDF_Datum`,s=`SPHEROID["${i.description??`GeospatialPDF_Spheroid`}",${i.semi_Major_Axis},${a}]`,c=t.to_WGS84;return`DATUM["${o}",${s}${c?`,TOWGS84[${c.dx??0},${c.dy??0},${c.dz??0},${c.rx??0},${c.ry??0},${c.rz??0},${c.sf??0}]`:``}]`}if(t.name){let e=t.name.toUpperCase();if(T(e))return`DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]]`;if(E(e))return`DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]]`;if(D(e))return`DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]]`}throw new e(`geospatial-pdf-layer:unsupported-datum`,`Unsupported datum code: ${t.name??`unknown`}`)}function v(e){let t=e.toLowerCase();return[`m`,`meter`,`meters`,`metre`,`metres`].includes(t)?`UNIT["Meter",1.0]`:[`ft`,`foot`,`feet`].includes(t)?`UNIT["Foot",0.3048]`:`UNIT["${e}",1.0]`}function y(e,t){switch(t){case`TC`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Scale_Factor",${e.Scale_Factor}]`];case`PH`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`];case`AC`:case`LE`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Standard_Parallel_1",${e.Standard_Parallel_One}]`,`PARAMETER["Standard_Parallel_2",${e.Standard_Parallel_Two}]`];case`UT`:return b(e)}}function b(t){if(!t.Zone)throw new e(`geospatial-pdf-layer:invalid-projection`,`No zone found for projection code UT`);let n=t.Zone*6-183;return[`PARAMETER["False_Easting",500000]`,`PARAMETER["False_Northing",${/^s/i.test(t.Hemisphere??``)?1e7:0}]`,`PARAMETER["Central_Meridian",${n}]`,`PARAMETER["Latitude_Of_Origin",0]`,`PARAMETER["Scale_Factor",0.9996]`]}function x(t){if(t.inverse_Flattening!=null)return t.inverse_Flattening;let n=t.semi_Major_Axis,r=t.semi_Minor_Axis;if(n==null||r==null)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Ellipsoid definition missing InvFlattening or SemiMinorAxis`);return n===r?0:n/(n-r)}function S(e){let t=C(e);return t?T(t)?`GCS_North_American_1983`:E(t)?`GCS_North_American_1927`:D(t)?`GCS_WGS_1984`:`GCS_GeospatialPDF`:`GCS_GeospatialPDF`}function C(e){return e.name?w(e.name):null}function w(e){return e.trim().toUpperCase().replace(/_/g,` `).replace(/\s+/g,` `)}function T(e){return r.test(e)}function E(e){return i.test(e)}function D(e){return a.test(e)}function O(n,r){let i=C(r);if(n.Zone===2800&&i&&T(i))return new t({wkid:32110});throw new e(`geospatial-pdf-layer:invalid-projection`,`Unsupported State Plane projection: datum ${r.name}, zone ${n.Zone}`)}export{o as projectionToSpatialReference};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import has from"../../../core/has.js";import{Loadable as n}from"../../../core/Loadable.js";import r from"../../../core/Logger.js";import{debounce as i}from"../../../core/promiseUtils.js";import{open as a}from"../../../core/workers.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import c from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import f from"../../../rest/support/FeatureSet.js";let p=class extends n{constructor(){super(...arguments),this.type=`geojson`,this.refresh=i(async e=>{await this.load();let{extent:t,timeExtent:n}=await this._connection.invoke(`refresh`,e);return this.sourceJSON.extent=t,n&&(this.sourceJSON.timeInfo.timeExtent=[n.start,n.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}})}load(e){let t=e==null?null:e.signal;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then(()=>this._applyEdits(e))}openPorts(){return this.load().then(()=>this._connection.openPorts())}queryFeatures(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t)).then(e=>f.fromJSON(e))}queryFeaturesJSON(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t))}queryFeatureCount(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatureCount`,e?e.toJSON():null,t))}queryObjectIds(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryObjectIds`,e?e.toJSON():null,t))}queryExtent(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryExtent`,e?e.toJSON():null,t)).then(e=>({count:e.count,extent:c.fromJSON(e.extent)}))}querySnapping(e,t={}){return this.load(t).then(()=>this._connection.invoke(`querySnapping`,e,t))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke(`queryAttributeBins`,e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t(`geojson-layer-source:edit-failure`,`Memory source not loaded`);let n=this.layer.objectIdField,r=[],i=[],a=[];if(e.addFeatures)for(let t of e.addFeatures)r.push(this._serializeFeature(t));if(e.deleteFeatures)for(let t of e.deleteFeatures)`objectId`in t&&t.objectId!=null?i.push(t.objectId):`attributes`in t&&t.attributes[n]!=null&&i.push(t.attributes[n]);if(e.updateFeatures)for(let t of e.updateFeatures)a.push(this._serializeFeature(t));return this._connection.invoke(`applyEdits`,{adds:r,updates:a,deletes:i}).then(({extent:e,timeExtent:t,featureEditResults:n})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(n)))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){let n=e.success===!0?null:e.error||{code:void 0,description:``};return{objectId:e.objectId,globalId:e.globalId,error:n?new t(`geojson-layer-source:edit-failure`,n.description,{code:n.code}):null}}_serializeFeature(e){let{attributes:t}=e,n=this._geometryForSerialization(e);return n?{geometry:n.toJSON(),attributes:t}:{attributes:t}}_geometryForSerialization(e){let{geometry:t}=e;return t==null?null:t.type===`mesh`||t.type===`extent`?l.fromExtent(t.extent):t}async _startWorker(e){this._connection=await a(`GeoJSONSourceWorker`,{strategy:has(`feature-layers-workers`)?`dedicated`:`local`,signal:e,registryTarget:this});let{fields:t,spatialReference:n,hasZ:i,geometryType:o,objectIdField:s,url:c,timeInfo:l,customParameters:f}=this.layer,p=this.layer.originOf(`spatialReference`)===`defaults`,m={url:c,customParameters:f,fields:t&&t.map(e=>e.toJSON()),geometryType:u.toJSON(o),hasZ:i,objectIdField:s,timeInfo:l?l.toJSON():null,spatialReference:p?null:n&&n.toJSON()},h=await this._connection.invoke(`load`,m,{signal:e});for(let e of h.warnings)r.getLogger(this.layer).warn(`#load()`,`${e.message} (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{warning:e});h.featureErrors.length&&r.getLogger(this.layer).warn(`#load()`,`Encountered ${h.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{errors:h.featureErrors}),this.sourceJSON=h.layerDefinition,this.capabilities=d(this.sourceJSON.hasZ,!0)}};e([o()],p.prototype,`capabilities`,void 0),e([o()],p.prototype,`type`,void 0),e([o({constructOnly:!0})],p.prototype,`layer`,void 0),e([o()],p.prototype,`sourceJSON`,void 0),p=e([s(`esri.layers.graphics.sources.GeoJSONSource`)],p);export{p as GeoJSONSource};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import has from"../../../core/has.js";import{Loadable as n}from"../../../core/Loadable.js";import r from"../../../core/Logger.js";import{debounce as i}from"../../../core/promiseUtils.js";import{open as a}from"../../../core/workers.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import c from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import f from"../../../rest/support/FeatureSet.js";let p=class extends n{constructor(){super(...arguments),this.type=`geojson`,this.refresh=i(async e=>{await this.load();let{extent:t,timeExtent:n}=await this._connection.invoke(`refresh`,e);return this.sourceJSON.extent=t,n&&(this.sourceJSON.timeInfo.timeExtent=[n.start,n.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}})}load(e){let t=e==null?null:e.signal;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then(()=>this._applyEdits(e))}openPorts(){return this.load().then(()=>this._connection.openPorts())}queryFeatures(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t)).then(e=>f.fromJSON(e))}queryFeaturesJSON(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t))}queryFeatureCount(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatureCount`,e?e.toJSON():null,t))}queryObjectIds(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryObjectIds`,e?e.toJSON():null,t))}queryExtent(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryExtent`,e?e.toJSON():null,t)).then(e=>({count:e.count,extent:c.fromJSON(e.extent)}))}querySnapping(e,t={}){return this.load(t).then(()=>this._connection.invoke(`querySnapping`,e,t))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke(`queryAttributeBins`,e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t(`geojson-layer-source:edit-failure`,`Memory source not loaded`);let n=this.layer.objectIdField,r=[],i=[],a=[];if(e.addFeatures)for(let t of e.addFeatures)r.push(this._serializeFeature(t));if(e.deleteFeatures)for(let t of e.deleteFeatures)`objectId`in t&&t.objectId!=null?i.push(t.objectId):`attributes`in t&&t.attributes[n]!=null&&i.push(t.attributes[n]);if(e.updateFeatures)for(let t of e.updateFeatures)a.push(this._serializeFeature(t));return this._connection.invoke(`applyEdits`,{adds:r,updates:a,deletes:i}).then(({extent:e,timeExtent:t,featureEditResults:n})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(n)))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){let n=e.success===!0?null:e.error||{code:void 0,description:``};return{objectId:e.objectId,globalId:e.globalId,error:n?new t(`geojson-layer-source:edit-failure`,n.description,{code:n.code}):null}}_serializeFeature(e){let{attributes:t}=e,n=this._geometryForSerialization(e);return n?{geometry:n.toJSON(),attributes:t}:{attributes:t}}_geometryForSerialization(e){let{geometry:t}=e;return t==null?null:t.type===`mesh`||t.type===`extent`?l.fromExtent(t.extent):t}async _startWorker(e){this._connection=await a(`GeoJSONSourceWorker`,{strategy:has(`feature-layers-workers`)?`dedicated`:`local`,signal:e,registryTarget:this});let{fields:t,spatialReference:n,hasZ:i,geometryType:o,objectIdField:s,url:c,timeInfo:l,customParameters:f}=this.layer,p=this.layer.originOf(`spatialReference`)===`defaults`,m={url:c,customParameters:f,fields:t&&t.map(e=>e.toJSON()),geometryType:u.toJSON(o),hasZ:i,objectIdField:s,timeInfo:l?l.toJSON():null,spatialReference:p?null:n&&n.toJSON()},h=await this._connection.invoke(`load`,m,{signal:e});for(let e of h.warnings)r.getLogger(this.layer).warn(`#load()`,`${e.message} (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{warning:e});h.featureErrors.length&&r.getLogger(this.layer).warn(`#load()`,`Encountered ${h.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{errors:h.featureErrors}),this.sourceJSON=h.layerDefinition,this.capabilities=d(this.sourceJSON.hasZ,!0,!this.sourceJSON.geometryType)}};e([o()],p.prototype,`capabilities`,void 0),e([o()],p.prototype,`type`,void 0),e([o({constructOnly:!0})],p.prototype,`layer`,void 0),e([o()],p.prototype,`sourceJSON`,void 0),p=e([s(`esri.layers.graphics.sources.GeoJSONSource`)],p);export{p as GeoJSONSource};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../../../request.js";import{createTask as t}from"../../../../core/asyncUtils.js";import n from"../../../../core/Error.js";import r from"../../../../core/Logger.js";import{isAbortError as i}from"../../../../core/promiseUtils.js";import{getJsonType as a}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as o,equals as s}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromGeometry as c,convertToGeometry as l,convertFromFeatures as u,convertToFeature as d,convertFromFeature as f}from"../../featureConversionUtils.js";import p from"../../data/FeatureStore.js";import{checkProjectionSupport as m,project as h}from"../../data/projectionSupport.js";import{QueryEngine as g}from"../../data/QueryEngine.js";import{inferLayerProperties as _,createOptimizedFeatures as v,validateGeoJSON as y}from"./geojson.js";import{createDefaultTemplate as b,createDefaultAttributesFunction as x,createDrawingInfo as S}from"../support/clientSideDefaults.js";import{queryBinsCapabilities as C,loadGeometryEngineForSimplify as w,mixAttributes as T,createFeatureEditSuccessResult as E,createFeatureEditErrorResult as D,simplify as O}from"../support/sourceUtils.js";import k from"../../../support/FieldsIndex.js";import{kebabDict as A}from"../../../support/fieldType.js";import{getFieldDefaultValue as j,getFieldDefaultLength as M}from"../../../support/fieldUtils.js";import{utc as N}from"../../../../time/constants.js";const P={hasAttachments:!1,capabilities:`query, editing, create, delete, update`,useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsQueryAttachmentsCountOnly:!1,supportsQueryAttachmentOrderByFields:!1,supportsQueryAttachmentWithTypeWildcard:!1,supportsQueryBins:!0,supportsQueryPivot:!1,supportsQueryWithCacheHint:!0,supportsQueryWithDistance:!0,supportsOutDistance:!1,supportsQueryWithResultType:!0,supportsSpatialAggregationStatistics:!0,supportedSpatialAggregationStatistics:[`EnvelopeAggregate`,`CentroidAggregate`,`ConvexHullAggregate`],supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0},queryBinsCapabilities:C};class F{constructor(){this._featureIdInfo=null,this._queryEngine=null,this._snapshotFeatures=async e=>{let t=await this._fetch(e);return this._createFeatures(t)}}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};let r=[],[i]=await Promise.all([e.url?this._fetch(t?.signal):null,this._checkProjection(e.spatialReference)]),a=_(i,{geometryType:e.geometryType}),s=e.fields||a.fields||[],c=e.hasZ==null?a.hasZ:e.hasZ,l=a.geometryType,u=e.objectIdField||a.objectIdFieldName||`__OBJECTID`,d=e.spatialReference||o,f=e.timeInfo;s===a.fields&&a.unknownFields.length>0&&r.push({name:`geojson-layer:unknown-field-types`,message:`Some fields types couldn't be inferred from the features and were dropped`,details:{unknownFields:a.unknownFields}});let m=new k(s),h=m.dateFields.length>0,v=m.get(u);v?(v.type!==`esriFieldTypeString`&&(v.type=`esriFieldTypeOID`),v.editable=!1,v.nullable=!1,u=v.name):(v={alias:u,name:u,type:a.objectIdFieldType===`string`?`esriFieldTypeString`:`esriFieldTypeOID`,editable:!1,nullable:!1},s.unshift(v));let y={};for(let e of s){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new n(`geojson-layer:invalid-field-name`,`field name is missing`,{field:e});if(!A.jsonValues.includes(e.type))throw new n(`geojson-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});if(e.name!==v.name){let t=j(e);t!==void 0&&(y[e.name]=t)}e.length??=M(e)}if(f){if(f.startTimeField){let e=m.get(f.startTimeField);e?(f.startTimeField=e.name,e.type=`esriFieldTypeDate`,h=!0):f.startTimeField=null}if(f.endTimeField){let e=m.get(f.endTimeField);e?(f.endTimeField=e.name,e.type=`esriFieldTypeDate`,h=!0):f.endTimeField=null}if(f.trackIdField){let e=m.get(f.trackIdField);e?f.trackIdField=e.name:(f.trackIdField=null,r.push({name:`geojson-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:f}}))}!f.startTimeField&&!f.endTimeField&&(r.push({name:`geojson-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing`,details:{timeInfo:f}}),f=null)}let C=l?S(l):void 0,w=h?{timeZoneIANA:N}:null,T={warnings:r,featureErrors:[],layerDefinition:{...P,drawingInfo:C??void 0,templates:b(y),extent:void 0,geometryType:l,objectIdField:u,fields:s,hasZ:!!c,timeInfo:f,dateFieldsTimeReference:w}};this._featureIdInfo={type:`object-id`,fieldName:u},this._queryEngine=new g({fieldsIndex:k.fromLayerJSON({fields:s,timeInfo:f,dateFieldsTimeReference:w}),geometryType:l,hasM:!1,hasZ:c,featureIdInfo:this._featureIdInfo,spatialReference:d,timeInfo:f,featureStore:new p({geometryType:l,hasM:!1,hasZ:c})});let E=this._queryEngine.fieldsIndex.requiredFields.indexOf(v);E>-1&&this._queryEngine.fieldsIndex.requiredFields.splice(E,1),this._createDefaultAttributes=x(y,u);let D=this._createFeatures(i);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,D);let O=this._normalizeFeatures(D,T.featureErrors);this._queryEngine.featureStore.addMany(O);let{fullExtent:F,timeExtent:I}=await this._queryEngine.fetchRecomputedExtents();if(T.layerDefinition.extent=F,I){let{start:e,end:t}=I;T.layerDefinition.timeInfo.timeExtent=[e,t]}return T}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([w(t,n),m(e.adds,t),m(e.updates,t)]),await this._waitSnapshotComplete(),this._applyEdits(e)}async queryFeatures(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQuery(e,t.signal)}async queryFeatureCount(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForCount(e,t.signal)}async queryObjectIds(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForIds(e,t.signal)}async queryExtent(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForExtent(e,t.signal)}async querySnapping(e,t={}){return await this._waitSnapshotComplete(),await this._queryEngine.executeQueryForSnapping(e,t.signal)}async queryAttributeBins(e,t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeAttributeBinsQuery(e,t.signal)}async refresh(e){this._loadOptions.customParameters=e,this._snapshotTask?.abort(),this._snapshotTask=t(this._snapshotFeatures),this._snapshotTask.promise.then(e=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,e);let t=this._normalizeFeatures(e);t&&this._queryEngine.featureStore.addMany(t)},e=>{this._queryEngine.featureStore.clear(),i(e)||r.getLogger(`esri.layers.GeoJSONLayer`).error(new n(`geojson-layer:refresh`,`An error occurred during refresh`,{error:e}))}),await this._waitSnapshotComplete();let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o}}_createFeatures(e){if(e==null)return[];let{geometryType:t,hasZ:n}=this._queryEngine,r=this._featureIdInfo.fieldName,i=v(e,{geometryType:t,hasZ:n,objectIdField:r});if(!s(this._queryEngine.spatialReference,o))for(let e of i)e.geometry!=null&&(e.geometry=c(h(l(e.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),o,this._queryEngine.spatialReference)));return i}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(t){let{url:n,customParameters:r}=this._loadOptions,i=(await e(n??``,{responseType:`json`,query:{...r},signal:t})).data;return y(i),i}_normalizeFeatures(e,t){let{fieldsIndex:n}=this._queryEngine,r=[],i=this._featureIdInfo.fieldName;for(let a of e){let e=this._createDefaultAttributes(),o=T(n,e,a.attributes,!0);o?t?.push(o):(this._assignObjectId(e,a.attributes,!0),a.attributes=e,a.objectId=e[i],r.push(a))}return r}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(E(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(e,t){let{addResults:n}=e,{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l}=this._queryEngine,d=this._featureIdInfo.fieldName,f=[];for(let i of t){if(i.geometry&&r!==a(i.geometry)){n.push(D(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),o=T(l,t,i.attributes);if(o){n.push(o);continue}if(this._assignObjectId(t,i.attributes),i.attributes=t,i.uid!=null){let t=i.attributes[d];e.uidToObjectId[i.uid]=t}if(i.geometry!=null){let e=i.geometry.spatialReference??s;i.geometry=h(O(i.geometry,e),e,s)}f.push(i),n.push(E(i.attributes[d]))}c.addMany(u([],f,r,o,i,this._featureIdInfo))}_applyUpdateEdits({updateResults:e},t){let{geometryType:n,hasM:r,hasZ:i,spatialReference:o,featureStore:s,fieldsIndex:c}=this._queryEngine,l=this._featureIdInfo.fieldName;for(let u of t){let{attributes:t,geometry:p}=u,m=t?.[l];if(m==null){e.push(D(`Identifier field ${l} missing`));continue}if(!s.has(m)){e.push(D(`Feature with object id ${m} missing`));continue}let g=d(s.getFeature(m),n,i,r);if(p!=null){if(n!==a(p)){e.push(D(`Incorrect geometry type.`));continue}let t=p.spatialReference??o;g.geometry=h(O(p,t),t,o)}if(t){let n=T(c,g.attributes,t);if(n){e.push(n);continue}}s.add(f(g,n,i,r,this._featureIdInfo)),e.push(E(m))}}_createObjectIdGenerator(e,t){let n=this._featureIdInfo.fieldName,r=e.fieldsIndex.get(n);if(r.type===`esriFieldTypeString`)return()=>r.name+`-`+Date.now().toString(16);let i=-1/0;for(let e of t)e.objectId&&(i=Math.max(i,e.objectId));return i=Math.max(0,i)+1,()=>i++}_assignObjectId(e,t,n=!1){let r=this._featureIdInfo.fieldName;e[r]=!n||!(r in t)?this._objectIdGenerator():t[r]}async _checkProjection(e){try{await m(o,e)}catch{throw new n(`geojson-layer`,`Projection not supported`)}}}export{F as default};
2
+ import e from"../../../../request.js";import{createTask as t}from"../../../../core/asyncUtils.js";import n from"../../../../core/Error.js";import r from"../../../../core/Logger.js";import{isAbortError as i}from"../../../../core/promiseUtils.js";import{getJsonType as a}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as o,equals as s}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromGeometry as c,convertToGeometry as l,convertFromFeatures as u,convertToFeature as d,convertFromFeature as f}from"../../featureConversionUtils.js";import p from"../../data/FeatureStore.js";import{checkProjectionSupport as m,project as h}from"../../data/projectionSupport.js";import{QueryEngine as g}from"../../data/QueryEngine.js";import{inferLayerProperties as _,createOptimizedFeatures as v,validateGeoJSON as y}from"./geojson.js";import{createDefaultTemplate as b,createDefaultAttributesFunction as x,createDrawingInfo as S}from"../support/clientSideDefaults.js";import{tableCapabilities as C,layerCapabilities as w,loadGeometryEngineForSimplify as T,mixAttributes as E,createFeatureEditSuccessResult as D,createFeatureEditErrorResult as O,simplify as k}from"../support/sourceUtils.js";import A from"../../../support/FieldsIndex.js";import{kebabDict as j}from"../../../support/fieldType.js";import{getFieldDefaultValue as M,getFieldDefaultLength as N}from"../../../support/fieldUtils.js";import{utc as P}from"../../../../time/constants.js";class F{constructor(){this._featureIdInfo=null,this._queryEngine=null,this._snapshotFeatures=async e=>{let t=await this._fetch(e);return this._createFeatures(t)}}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};let r=[],[i]=await Promise.all([e.url?this._fetch(t?.signal):null,this._checkProjection(e.spatialReference)]),a=_(i,{geometryType:e.geometryType}),s=e.fields||a.fields||[],c=e.hasZ==null?a.hasZ:e.hasZ,l=a.geometryType,u=!l,d=e.objectIdField||a.objectIdFieldName||`__OBJECTID`,f=e.spatialReference||o,m=e.timeInfo;s===a.fields&&a.unknownFields.length>0&&r.push({name:`geojson-layer:unknown-field-types`,message:`Some fields types couldn't be inferred from the features and were dropped`,details:{unknownFields:a.unknownFields}});let h=new A(s),v=h.dateFields.length>0,y=h.get(d);y?(y.type!==`esriFieldTypeString`&&(y.type=`esriFieldTypeOID`),y.editable=!1,y.nullable=!1,d=y.name):(y={alias:d,name:d,type:a.objectIdFieldType===`string`?`esriFieldTypeString`:`esriFieldTypeOID`,editable:!1,nullable:!1},s.unshift(y));let T={};for(let e of s){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new n(`geojson-layer:invalid-field-name`,`field name is missing`,{field:e});if(!j.jsonValues.includes(e.type))throw new n(`geojson-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});if(e.name!==y.name){let t=M(e);t!==void 0&&(T[e.name]=t)}e.length??=N(e)}if(m){if(m.startTimeField){let e=h.get(m.startTimeField);e?(m.startTimeField=e.name,e.type=`esriFieldTypeDate`,v=!0):m.startTimeField=null}if(m.endTimeField){let e=h.get(m.endTimeField);e?(m.endTimeField=e.name,e.type=`esriFieldTypeDate`,v=!0):m.endTimeField=null}if(m.trackIdField){let e=h.get(m.trackIdField);e?m.trackIdField=e.name:(m.trackIdField=null,r.push({name:`geojson-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:m}}))}!m.startTimeField&&!m.endTimeField&&(r.push({name:`geojson-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing`,details:{timeInfo:m}}),m=null)}let E=l?S(l):void 0,D=v?{timeZoneIANA:P}:null,O={warnings:r,featureErrors:[],layerDefinition:{...u?C:w,drawingInfo:E??void 0,templates:b(T),extent:void 0,geometryType:l,objectIdField:d,fields:s,hasZ:!!c,timeInfo:m,dateFieldsTimeReference:D}};this._featureIdInfo={type:`object-id`,fieldName:d},this._queryEngine=new g({fieldsIndex:A.fromLayerJSON({fields:s,timeInfo:m,dateFieldsTimeReference:D}),geometryType:l,hasM:!1,hasZ:c,featureIdInfo:this._featureIdInfo,spatialReference:f,timeInfo:m,featureStore:new p({geometryType:l,hasM:!1,hasZ:c})});let k=this._queryEngine.fieldsIndex.requiredFields.indexOf(y);k>-1&&this._queryEngine.fieldsIndex.requiredFields.splice(k,1),this._createDefaultAttributes=x(T,d);let F=this._createFeatures(i);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,F);let I=this._normalizeFeatures(F,O.featureErrors);this._queryEngine.featureStore.addMany(I);let{fullExtent:L,timeExtent:R}=await this._queryEngine.fetchRecomputedExtents();if(O.layerDefinition.extent=L,R){let{start:e,end:t}=R;O.layerDefinition.timeInfo.timeExtent=[e,t]}return O}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([T(t,n),m(e.adds,t),m(e.updates,t)]),await this._waitSnapshotComplete(),this._applyEdits(e)}async queryFeatures(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQuery(e,t.signal)}async queryFeatureCount(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForCount(e,t.signal)}async queryObjectIds(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForIds(e,t.signal)}async queryExtent(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForExtent(e,t.signal)}async querySnapping(e,t={}){return await this._waitSnapshotComplete(),await this._queryEngine.executeQueryForSnapping(e,t.signal)}async queryAttributeBins(e,t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeAttributeBinsQuery(e,t.signal)}async refresh(e){this._loadOptions.customParameters=e,this._snapshotTask?.abort(),this._snapshotTask=t(this._snapshotFeatures),this._snapshotTask.promise.then(e=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,e);let t=this._normalizeFeatures(e);t&&this._queryEngine.featureStore.addMany(t)},e=>{this._queryEngine.featureStore.clear(),i(e)||r.getLogger(`esri.layers.GeoJSONLayer`).error(new n(`geojson-layer:refresh`,`An error occurred during refresh`,{error:e}))}),await this._waitSnapshotComplete();let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o}}_createFeatures(e){if(e==null)return[];let{geometryType:t,hasZ:n}=this._queryEngine,r=this._featureIdInfo.fieldName,i=v(e,{geometryType:t,hasZ:n,objectIdField:r});if(!s(this._queryEngine.spatialReference,o))for(let e of i)e.geometry!=null&&(e.geometry=c(h(l(e.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),o,this._queryEngine.spatialReference)));return i}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(t){let{url:n,customParameters:r}=this._loadOptions,i=(await e(n??``,{responseType:`json`,query:{...r},signal:t})).data;return y(i),i}_normalizeFeatures(e,t){let{fieldsIndex:n}=this._queryEngine,r=[],i=this._featureIdInfo.fieldName;for(let a of e){let e=this._createDefaultAttributes(),o=E(n,e,a.attributes,!0);o?t?.push(o):(this._assignObjectId(e,a.attributes,!0),a.attributes=e,a.objectId=e[i],r.push(a))}return r}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(D(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(e,t){let{addResults:n}=e,{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l}=this._queryEngine,d=this._featureIdInfo.fieldName,f=[];for(let i of t){if(i.geometry&&r!==a(i.geometry)){n.push(O(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),o=E(l,t,i.attributes);if(o){n.push(o);continue}if(this._assignObjectId(t,i.attributes),i.attributes=t,i.uid!=null){let t=i.attributes[d];e.uidToObjectId[i.uid]=t}if(i.geometry!=null){let e=i.geometry.spatialReference??s;i.geometry=h(k(i.geometry,e),e,s)}f.push(i),n.push(D(i.attributes[d]))}c.addMany(u([],f,r,o,i,this._featureIdInfo))}_applyUpdateEdits({updateResults:e},t){let{geometryType:n,hasM:r,hasZ:i,spatialReference:o,featureStore:s,fieldsIndex:c}=this._queryEngine,l=this._featureIdInfo.fieldName;for(let u of t){let{attributes:t,geometry:p}=u,m=t?.[l];if(m==null){e.push(O(`Identifier field ${l} missing`));continue}if(!s.has(m)){e.push(O(`Feature with object id ${m} missing`));continue}let g=d(s.getFeature(m),n,i,r);if(p!=null){if(n!==a(p)){e.push(O(`Incorrect geometry type.`));continue}let t=p.spatialReference??o;g.geometry=h(k(p,t),t,o)}if(t){let n=E(c,g.attributes,t);if(n){e.push(n);continue}}s.add(f(g,n,i,r,this._featureIdInfo)),e.push(D(m))}}_createObjectIdGenerator(e,t){let n=this._featureIdInfo.fieldName,r=e.fieldsIndex.get(n);if(r.type===`esriFieldTypeString`)return()=>r.name+`-`+Date.now().toString(16);let i=-1/0;for(let e of t)e.objectId&&(i=Math.max(i,e.objectId));return i=Math.max(0,i)+1,()=>i++}_assignObjectId(e,t,n=!1){let r=this._featureIdInfo.fieldName;e[r]=!n||!(r in t)?this._objectIdGenerator():t[r]}async _checkProjection(e){try{await m(o,e)}catch{throw new n(`geojson-layer`,`Projection not supported`)}}}export{F as default};