@chialab/pdfjs-lib 1.0.0-alpha.19 → 1.0.0-alpha.20

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.
@@ -34,11 +34,12 @@ import {
34
34
  isValidFetchUrl,
35
35
  makeSerializable,
36
36
  noContextMenu,
37
+ parseRgbaColor,
37
38
  rgbToHex,
38
39
  setLayerDimensions,
39
40
  stopEvent,
40
41
  toDataUrl
41
- } from "./chunk-QCIN557M.js";
42
+ } from "./chunk-3XZOTLLE.js";
42
43
  import {
43
44
  AbortException,
44
45
  AnnotationBorderStyleType,
@@ -377,13 +378,13 @@ var _ImageManager = class _ImageManager {
377
378
  async getFromUrl(url) {
378
379
  return __privateMethod(this, _ImageManager_instances, get_fn).call(this, url, url);
379
380
  }
380
- async getFromBlob(id, blobPromise) {
381
+ async getFromBlob(id2, blobPromise) {
381
382
  const blob = await blobPromise;
382
- return __privateMethod(this, _ImageManager_instances, get_fn).call(this, id, blob);
383
+ return __privateMethod(this, _ImageManager_instances, get_fn).call(this, id2, blob);
383
384
  }
384
- async getFromId(id) {
385
+ async getFromId(id2) {
385
386
  __privateGet(this, _cache) || __privateSet(this, _cache, /* @__PURE__ */ new Map());
386
- const data = __privateGet(this, _cache).get(id);
387
+ const data = __privateGet(this, _cache).get(id2);
387
388
  if (!data) {
388
389
  return null;
389
390
  }
@@ -401,9 +402,9 @@ var _ImageManager = class _ImageManager {
401
402
  }
402
403
  return this.getFromUrl(data.url);
403
404
  }
404
- getFromCanvas(id, canvas) {
405
+ getFromCanvas(id2, canvas) {
405
406
  __privateGet(this, _cache) || __privateSet(this, _cache, /* @__PURE__ */ new Map());
406
- let data = __privateGet(this, _cache).get(id);
407
+ let data = __privateGet(this, _cache).get(id2);
407
408
  if (data?.bitmap) {
408
409
  data.refCounter += 1;
409
410
  return data;
@@ -417,20 +418,20 @@ var _ImageManager = class _ImageManager {
417
418
  refCounter: 1,
418
419
  isSvg: false
419
420
  };
420
- __privateGet(this, _cache).set(id, data);
421
+ __privateGet(this, _cache).set(id2, data);
421
422
  __privateGet(this, _cache).set(data.id, data);
422
423
  return data;
423
424
  }
424
- getSvgUrl(id) {
425
- const data = __privateGet(this, _cache).get(id);
425
+ getSvgUrl(id2) {
426
+ const data = __privateGet(this, _cache).get(id2);
426
427
  if (!data?.isSvg) {
427
428
  return null;
428
429
  }
429
430
  return data.svgUrl;
430
431
  }
431
- deleteId(id) {
432
+ deleteId(id2) {
432
433
  __privateGet(this, _cache) || __privateSet(this, _cache, /* @__PURE__ */ new Map());
433
- const data = __privateGet(this, _cache).get(id);
434
+ const data = __privateGet(this, _cache).get(id2);
434
435
  if (!data) {
435
436
  return;
436
437
  }
@@ -452,8 +453,8 @@ var _ImageManager = class _ImageManager {
452
453
  // We must take care of having the right manager because we can copy/paste
453
454
  // some images from other documents, hence it'd be a pity to use an id from an
454
455
  // other manager.
455
- isValidId(id) {
456
- return id.startsWith(`image_${__privateGet(this, _baseId)}_`);
456
+ isValidId(id2) {
457
+ return id2.startsWith(`image_${__privateGet(this, _baseId)}_`);
457
458
  }
458
459
  };
459
460
  _baseId = new WeakMap();
@@ -1662,8 +1663,8 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
1662
1663
  * @param {string} id
1663
1664
  * @returns {AnnotationEditor}
1664
1665
  */
1665
- getEditor(id) {
1666
- return __privateGet(this, _allEditors).get(id);
1666
+ getEditor(id2) {
1667
+ return __privateGet(this, _allEditors).get(id2);
1667
1668
  }
1668
1669
  /**
1669
1670
  * Add a new editor.
@@ -2160,10 +2161,10 @@ var _AnnotationEditorUIManager = class _AnnotationEditorUIManager {
2160
2161
  }
2161
2162
  return boxes.length === 0 ? null : boxes;
2162
2163
  }
2163
- addChangedExistingAnnotation({ annotationElementId, id }) {
2164
+ addChangedExistingAnnotation({ annotationElementId, id: id2 }) {
2164
2165
  (__privateGet(this, _changedExistingAnnotations) || __privateSet(this, _changedExistingAnnotations, /* @__PURE__ */ new Map())).set(
2165
2166
  annotationElementId,
2166
- id
2167
+ id2
2167
2168
  );
2168
2169
  }
2169
2170
  removeChangedExistingAnnotation({ annotationElementId }) {
@@ -5194,7 +5195,7 @@ function transformPath(commands, transform) {
5194
5195
  }
5195
5196
  });
5196
5197
  }
5197
- function calculateBoundingBox(commands) {
5198
+ function getBBox(commands) {
5198
5199
  let minX = Number.POSITIVE_INFINITY;
5199
5200
  let minY = Number.POSITIVE_INFINITY;
5200
5201
  let maxX = Number.NEGATIVE_INFINITY;
@@ -6690,25 +6691,25 @@ var CachedCanvases = class {
6690
6691
  this.canvasFactory = canvasFactory;
6691
6692
  this.cache = /* @__PURE__ */ Object.create(null);
6692
6693
  }
6693
- getCanvas(id, width, height) {
6694
+ getCanvas(id2, width, height) {
6694
6695
  let canvasEntry;
6695
- if (this.cache[id] !== void 0) {
6696
- canvasEntry = this.cache[id];
6696
+ if (this.cache[id2] !== void 0) {
6697
+ canvasEntry = this.cache[id2];
6697
6698
  this.canvasFactory.reset(canvasEntry, width, height);
6698
6699
  } else {
6699
6700
  canvasEntry = this.canvasFactory.create(width, height);
6700
- this.cache[id] = canvasEntry;
6701
+ this.cache[id2] = canvasEntry;
6701
6702
  }
6702
6703
  return canvasEntry;
6703
6704
  }
6704
- delete(id) {
6705
- delete this.cache[id];
6705
+ delete(id2) {
6706
+ delete this.cache[id2];
6706
6707
  }
6707
6708
  clear() {
6708
- for (const id in this.cache) {
6709
- const canvasEntry = this.cache[id];
6709
+ for (const id2 in this.cache) {
6710
+ const canvasEntry = this.cache[id2];
6710
6711
  this.canvasFactory.destroy(canvasEntry);
6711
- delete this.cache[id];
6712
+ delete this.cache[id2];
6712
6713
  }
6713
6714
  }
6714
6715
  };
@@ -8385,7 +8386,7 @@ var _CanvasGraphics = class _CanvasGraphics {
8385
8386
  this.compose(dirtyBox);
8386
8387
  }
8387
8388
  }
8388
- beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
8389
+ beginAnnotation(id2, rect, transform, matrix, hasOwnCanvas) {
8389
8390
  __privateMethod(this, _CanvasGraphics_instances, restoreInitialState_fn).call(this);
8390
8391
  resetCtxToDefault(this.ctx);
8391
8392
  this.ctx.save();
@@ -8417,7 +8418,7 @@ var _CanvasGraphics = class _CanvasGraphics {
8417
8418
  canvasHeight
8418
8419
  );
8419
8420
  const { canvas, context } = this.annotationCanvas;
8420
- this.annotationCanvasMap.set(id, canvas);
8421
+ this.annotationCanvasMap.set(id2, canvas);
8421
8422
  this.annotationCanvas.savedCtx = this.ctx;
8422
8423
  this.ctx = context;
8423
8424
  this.ctx.save();
@@ -9059,45 +9060,45 @@ var OptionalContentConfig = class {
9059
9060
  return __privateMethod(this, _OptionalContentConfig_instances, evaluateVisibilityExpression_fn).call(this, group.expression);
9060
9061
  }
9061
9062
  if (!group.policy || group.policy === "AnyOn") {
9062
- for (const id of group.ids) {
9063
- if (!__privateGet(this, _groups).has(id)) {
9064
- warn(`Optional content group not found: ${id}`);
9063
+ for (const id2 of group.ids) {
9064
+ if (!__privateGet(this, _groups).has(id2)) {
9065
+ warn(`Optional content group not found: ${id2}`);
9065
9066
  return true;
9066
9067
  }
9067
- if (__privateGet(this, _groups).get(id).visible) {
9068
+ if (__privateGet(this, _groups).get(id2).visible) {
9068
9069
  return true;
9069
9070
  }
9070
9071
  }
9071
9072
  return false;
9072
9073
  } else if (group.policy === "AllOn") {
9073
- for (const id of group.ids) {
9074
- if (!__privateGet(this, _groups).has(id)) {
9075
- warn(`Optional content group not found: ${id}`);
9074
+ for (const id2 of group.ids) {
9075
+ if (!__privateGet(this, _groups).has(id2)) {
9076
+ warn(`Optional content group not found: ${id2}`);
9076
9077
  return true;
9077
9078
  }
9078
- if (!__privateGet(this, _groups).get(id).visible) {
9079
+ if (!__privateGet(this, _groups).get(id2).visible) {
9079
9080
  return false;
9080
9081
  }
9081
9082
  }
9082
9083
  return true;
9083
9084
  } else if (group.policy === "AnyOff") {
9084
- for (const id of group.ids) {
9085
- if (!__privateGet(this, _groups).has(id)) {
9086
- warn(`Optional content group not found: ${id}`);
9085
+ for (const id2 of group.ids) {
9086
+ if (!__privateGet(this, _groups).has(id2)) {
9087
+ warn(`Optional content group not found: ${id2}`);
9087
9088
  return true;
9088
9089
  }
9089
- if (!__privateGet(this, _groups).get(id).visible) {
9090
+ if (!__privateGet(this, _groups).get(id2).visible) {
9090
9091
  return true;
9091
9092
  }
9092
9093
  }
9093
9094
  return false;
9094
9095
  } else if (group.policy === "AllOff") {
9095
- for (const id of group.ids) {
9096
- if (!__privateGet(this, _groups).has(id)) {
9097
- warn(`Optional content group not found: ${id}`);
9096
+ for (const id2 of group.ids) {
9097
+ if (!__privateGet(this, _groups).has(id2)) {
9098
+ warn(`Optional content group not found: ${id2}`);
9098
9099
  return true;
9099
9100
  }
9100
- if (__privateGet(this, _groups).get(id).visible) {
9101
+ if (__privateGet(this, _groups).get(id2).visible) {
9101
9102
  return false;
9102
9103
  }
9103
9104
  }
@@ -9109,16 +9110,16 @@ var OptionalContentConfig = class {
9109
9110
  warn(`Unknown group type ${group.type}.`);
9110
9111
  return true;
9111
9112
  }
9112
- setVisibility(id, visible = true, preserveRB = true) {
9113
- const group = __privateGet(this, _groups).get(id);
9113
+ setVisibility(id2, visible = true, preserveRB = true) {
9114
+ const group = __privateGet(this, _groups).get(id2);
9114
9115
  if (!group) {
9115
- warn(`Optional content group not found: ${id}`);
9116
+ warn(`Optional content group not found: ${id2}`);
9116
9117
  return;
9117
9118
  }
9118
9119
  if (preserveRB && visible && group.rbGroups.length) {
9119
9120
  for (const rbGroup of group.rbGroups) {
9120
9121
  for (const otherId of rbGroup) {
9121
- if (otherId !== id) {
9122
+ if (otherId !== id2) {
9122
9123
  __privateGet(this, _groups).get(otherId)?._setVisible(INTERNAL, false, true);
9123
9124
  }
9124
9125
  }
@@ -9172,16 +9173,16 @@ var OptionalContentConfig = class {
9172
9173
  }
9173
9174
  return [...__privateGet(this, _groups).keys()];
9174
9175
  }
9175
- getGroup(id) {
9176
- return __privateGet(this, _groups).get(id) || null;
9176
+ getGroup(id2) {
9177
+ return __privateGet(this, _groups).get(id2) || null;
9177
9178
  }
9178
9179
  getHash() {
9179
9180
  if (__privateGet(this, _cachedGetHash) !== null) {
9180
9181
  return __privateGet(this, _cachedGetHash);
9181
9182
  }
9182
9183
  const hash = new MurmurHash3_64();
9183
- for (const [id, group] of __privateGet(this, _groups)) {
9184
- hash.update(`${id}:${group.visible}`);
9184
+ for (const [id2, group] of __privateGet(this, _groups)) {
9185
+ hash.update(`${id2}:${group.visible}`);
9185
9186
  }
9186
9187
  return __privateSet(this, _cachedGetHash, hash.hexdigest());
9187
9188
  }
@@ -11506,8 +11507,8 @@ var PDFDocumentProxy = class {
11506
11507
  * information of the given named destination, or `null` when the named
11507
11508
  * destination is not present in the PDF file.
11508
11509
  */
11509
- getDestination(id) {
11510
- return this._transport.getDestination(id);
11510
+ getDestination(id2) {
11511
+ return this._transport.getDestination(id2);
11511
11512
  }
11512
11513
  /**
11513
11514
  * @returns {Promise<Array<string> | null>} A promise that is resolved with
@@ -12484,10 +12485,10 @@ setupFakeWorker_fn = function() {
12484
12485
  }
12485
12486
  const port = new LoopbackPort();
12486
12487
  __privateSet(this, _port2, port);
12487
- const id = `fake${__privateWrapper(_PDFWorker, _fakeWorkerId)._++}`;
12488
- const workerHandler = new MessageHandler(id + "_worker", id, port);
12488
+ const id2 = `fake${__privateWrapper(_PDFWorker, _fakeWorkerId)._++}`;
12489
+ const workerHandler = new MessageHandler(id2 + "_worker", id2, port);
12489
12490
  WorkerMessageHandler.setup(workerHandler, port);
12490
- __privateSet(this, _messageHandler, new MessageHandler(id, id + "_worker", port));
12491
+ __privateSet(this, _messageHandler, new MessageHandler(id2, id2 + "_worker", port));
12491
12492
  __privateMethod(this, _PDFWorker_instances, resolve_fn).call(this);
12492
12493
  }).catch((reason) => {
12493
12494
  __privateGet(this, _capability3).reject(
@@ -12818,11 +12819,11 @@ var WorkerTransport = class {
12818
12819
  const page = __privateGet(this, _pageCache).get(data.pageIndex);
12819
12820
  page._startRenderPage(data.transparency, data.cacheKey);
12820
12821
  });
12821
- messageHandler.on("commonobj", ([id, type, exportedData]) => {
12822
+ messageHandler.on("commonobj", ([id2, type, exportedData]) => {
12822
12823
  if (this.destroyed) {
12823
12824
  return null;
12824
12825
  }
12825
- if (this.commonObjs.has(id)) {
12826
+ if (this.commonObjs.has(id2)) {
12826
12827
  return null;
12827
12828
  }
12828
12829
  switch (type) {
@@ -12830,16 +12831,16 @@ var WorkerTransport = class {
12830
12831
  if ("error" in exportedData) {
12831
12832
  const exportedError = exportedData.error;
12832
12833
  warn(`Error during font loading: ${exportedError}`);
12833
- this.commonObjs.resolve(id, exportedError);
12834
+ this.commonObjs.resolve(id2, exportedError);
12834
12835
  break;
12835
12836
  }
12836
12837
  const inspectFont = this._params.pdfBug && globalThis.FontInspector?.enabled ? (font2, url) => globalThis.FontInspector.fontAdded(font2, url) : null;
12837
12838
  const font = new FontFaceObject(exportedData, inspectFont);
12838
- this.fontLoader.bind(font).catch(() => messageHandler.sendWithPromise("FontFallback", { id })).finally(() => {
12839
+ this.fontLoader.bind(font).catch(() => messageHandler.sendWithPromise("FontFallback", { id: id2 })).finally(() => {
12839
12840
  if (!font.fontExtraProperties && font.data) {
12840
12841
  font.data = null;
12841
12842
  }
12842
- this.commonObjs.resolve(id, font);
12843
+ this.commonObjs.resolve(id2, font);
12843
12844
  });
12844
12845
  break;
12845
12846
  case "CopyLocalImage":
@@ -12853,7 +12854,7 @@ var WorkerTransport = class {
12853
12854
  if (!data.dataLen) {
12854
12855
  return null;
12855
12856
  }
12856
- this.commonObjs.resolve(id, structuredClone(data));
12857
+ this.commonObjs.resolve(id2, structuredClone(data));
12857
12858
  return data.dataLen;
12858
12859
  }
12859
12860
  }
@@ -12861,19 +12862,19 @@ var WorkerTransport = class {
12861
12862
  case "FontPath":
12862
12863
  case "Image":
12863
12864
  case "Pattern":
12864
- this.commonObjs.resolve(id, exportedData);
12865
+ this.commonObjs.resolve(id2, exportedData);
12865
12866
  break;
12866
12867
  default:
12867
12868
  throw new Error(`Got unknown common object type ${type}`);
12868
12869
  }
12869
12870
  return null;
12870
12871
  });
12871
- messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
12872
+ messageHandler.on("obj", ([id2, pageIndex, type, imageData]) => {
12872
12873
  if (this.destroyed) {
12873
12874
  return;
12874
12875
  }
12875
12876
  const pageProxy = __privateGet(this, _pageCache).get(pageIndex);
12876
- if (pageProxy.objs.has(id)) {
12877
+ if (pageProxy.objs.has(id2)) {
12877
12878
  return;
12878
12879
  }
12879
12880
  if (pageProxy._intentStates.size === 0) {
@@ -12883,7 +12884,7 @@ var WorkerTransport = class {
12883
12884
  switch (type) {
12884
12885
  case "Image":
12885
12886
  case "Pattern":
12886
- pageProxy.objs.resolve(id, imageData);
12887
+ pageProxy.objs.resolve(id2, imageData);
12887
12888
  break;
12888
12889
  default:
12889
12890
  throw new Error(`Got unknown object type ${type}`);
@@ -12993,12 +12994,12 @@ var WorkerTransport = class {
12993
12994
  getDestinations() {
12994
12995
  return this.messageHandler.sendWithPromise("GetDestinations", null);
12995
12996
  }
12996
- getDestination(id) {
12997
- if (typeof id !== "string") {
12997
+ getDestination(id2) {
12998
+ if (typeof id2 !== "string") {
12998
12999
  return Promise.reject(new Error("Invalid destination request."));
12999
13000
  }
13000
13001
  return this.messageHandler.sendWithPromise("GetDestination", {
13001
- id
13002
+ id: id2
13002
13003
  });
13003
13004
  }
13004
13005
  getPageLabels() {
@@ -13373,8 +13374,8 @@ var DOMSVGFactory = class extends BaseSVGFactory {
13373
13374
 
13374
13375
  // src/pdf.js/src/display/xfa_layer.js
13375
13376
  var XfaLayer = class {
13376
- static setupStorage(html, id, element, storage, intent) {
13377
- const storedData = storage.getValue(id, { value: null });
13377
+ static setupStorage(html, id2, element, storage, intent) {
13378
+ const storedData = storage.getValue(id2, { value: null });
13378
13379
  switch (element.name) {
13379
13380
  case "textarea":
13380
13381
  if (storedData.value !== null) {
@@ -13384,7 +13385,7 @@ var XfaLayer = class {
13384
13385
  break;
13385
13386
  }
13386
13387
  html.addEventListener("input", (event) => {
13387
- storage.setValue(id, { value: event.target.value });
13388
+ storage.setValue(id2, { value: event.target.value });
13388
13389
  });
13389
13390
  break;
13390
13391
  case "input":
@@ -13398,7 +13399,7 @@ var XfaLayer = class {
13398
13399
  break;
13399
13400
  }
13400
13401
  html.addEventListener("change", (event) => {
13401
- storage.setValue(id, {
13402
+ storage.setValue(id2, {
13402
13403
  value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
13403
13404
  });
13404
13405
  });
@@ -13410,7 +13411,7 @@ var XfaLayer = class {
13410
13411
  break;
13411
13412
  }
13412
13413
  html.addEventListener("input", (event) => {
13413
- storage.setValue(id, { value: event.target.value });
13414
+ storage.setValue(id2, { value: event.target.value });
13414
13415
  });
13415
13416
  }
13416
13417
  break;
@@ -13428,7 +13429,7 @@ var XfaLayer = class {
13428
13429
  html.addEventListener("input", (event) => {
13429
13430
  const options = event.target.options;
13430
13431
  const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
13431
- storage.setValue(id, { value });
13432
+ storage.setValue(id2, { value });
13432
13433
  });
13433
13434
  break;
13434
13435
  }
@@ -13965,8 +13966,8 @@ var _AnnotationElement = class _AnnotationElement {
13965
13966
  const defs = svgFactory.createElement("defs");
13966
13967
  svg.append(defs);
13967
13968
  const clipPath = svgFactory.createElement("clipPath");
13968
- const id = `clippath_${this.data.id}`;
13969
- clipPath.setAttribute("id", id);
13969
+ const id2 = `clippath_${this.data.id}`;
13970
+ clipPath.setAttribute("id", id2);
13970
13971
  clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
13971
13972
  defs.append(clipPath);
13972
13973
  for (let i = 2, ii = quadPoints.length; i < ii; i += 8) {
@@ -13993,7 +13994,7 @@ var _AnnotationElement = class _AnnotationElement {
13993
13994
  style.backgroundImage = svgBuffer.join("");
13994
13995
  }
13995
13996
  this.container.append(svg);
13996
- this.container.style.clipPath = `url(#${id})`;
13997
+ this.container.style.clipPath = `url(#${id2})`;
13997
13998
  }
13998
13999
  /**
13999
14000
  * Create a popup for the annotation's HTML element. This is used for
@@ -14041,36 +14042,36 @@ var _AnnotationElement = class _AnnotationElement {
14041
14042
  if (this._fieldObjects) {
14042
14043
  const fieldObj = this._fieldObjects[name];
14043
14044
  if (fieldObj) {
14044
- for (const { page, id, exportValues } of fieldObj) {
14045
+ for (const { page, id: id2, exportValues } of fieldObj) {
14045
14046
  if (page === -1) {
14046
14047
  continue;
14047
14048
  }
14048
- if (id === skipId) {
14049
+ if (id2 === skipId) {
14049
14050
  continue;
14050
14051
  }
14051
14052
  const exportValue = typeof exportValues === "string" ? exportValues : null;
14052
14053
  const domElement = document.querySelector(
14053
- `[data-element-id="${id}"]`
14054
+ `[data-element-id="${id2}"]`
14054
14055
  );
14055
14056
  if (domElement && !GetElementsByNameSet.has(domElement)) {
14056
- warn(`_getElementsByName - element not allowed: ${id}`);
14057
+ warn(`_getElementsByName - element not allowed: ${id2}`);
14057
14058
  continue;
14058
14059
  }
14059
- fields.push({ id, exportValue, domElement });
14060
+ fields.push({ id: id2, exportValue, domElement });
14060
14061
  }
14061
14062
  }
14062
14063
  return fields;
14063
14064
  }
14064
14065
  for (const domElement of document.getElementsByName(name)) {
14065
14066
  const { exportValue } = domElement;
14066
- const id = domElement.getAttribute("data-element-id");
14067
- if (id === skipId) {
14067
+ const id2 = domElement.getAttribute("data-element-id");
14068
+ if (id2 === skipId) {
14068
14069
  continue;
14069
14070
  }
14070
14071
  if (!GetElementsByNameSet.has(domElement)) {
14071
14072
  continue;
14072
14073
  }
14073
- fields.push({ id, exportValue, domElement });
14074
+ fields.push({ id: id2, exportValue, domElement });
14074
14075
  }
14075
14076
  return fields;
14076
14077
  }
@@ -14308,8 +14309,8 @@ var LinkAnnotationElement = class extends AnnotationElement {
14308
14309
  const fieldIds = new Set(resetFormRefs);
14309
14310
  for (const fieldName of resetFormFields) {
14310
14311
  const fields = this._fieldObjects[fieldName] || [];
14311
- for (const { id } of fields) {
14312
- fieldIds.add(id);
14312
+ for (const { id: id2 } of fields) {
14313
+ fieldIds.add(id2);
14313
14314
  }
14314
14315
  }
14315
14316
  for (const fields of Object.values(this._fieldObjects)) {
@@ -14327,34 +14328,34 @@ var LinkAnnotationElement = class extends AnnotationElement {
14327
14328
  const storage = this.annotationStorage;
14328
14329
  const allIds = [];
14329
14330
  for (const field of allFields) {
14330
- const { id } = field;
14331
- allIds.push(id);
14331
+ const { id: id2 } = field;
14332
+ allIds.push(id2);
14332
14333
  switch (field.type) {
14333
14334
  case "text": {
14334
14335
  const value = field.defaultValue || "";
14335
- storage.setValue(id, { value });
14336
+ storage.setValue(id2, { value });
14336
14337
  break;
14337
14338
  }
14338
14339
  case "checkbox":
14339
14340
  case "radiobutton": {
14340
14341
  const value = field.defaultValue === field.exportValues;
14341
- storage.setValue(id, { value });
14342
+ storage.setValue(id2, { value });
14342
14343
  break;
14343
14344
  }
14344
14345
  case "combobox":
14345
14346
  case "listbox": {
14346
14347
  const value = field.defaultValue || "";
14347
- storage.setValue(id, { value });
14348
+ storage.setValue(id2, { value });
14348
14349
  break;
14349
14350
  }
14350
14351
  default:
14351
14352
  continue;
14352
14353
  }
14353
- const domElement = document.querySelector(`[data-element-id="${id}"]`);
14354
+ const domElement = document.querySelector(`[data-element-id="${id2}"]`);
14354
14355
  if (!domElement) {
14355
14356
  continue;
14356
14357
  } else if (!GetElementsByNameSet.has(domElement)) {
14357
- warn(`_bindResetFormAction - element not allowed: ${id}`);
14358
+ warn(`_bindResetFormAction - element not allowed: ${id2}`);
14358
14359
  continue;
14359
14360
  }
14360
14361
  domElement.dispatchEvent(new Event("resetform"));
@@ -14581,15 +14582,15 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14581
14582
  }
14582
14583
  render() {
14583
14584
  const storage = this.annotationStorage;
14584
- const id = this.data.id;
14585
+ const id2 = this.data.id;
14585
14586
  this.container.classList.add("textWidgetAnnotation");
14586
14587
  let element = null;
14587
14588
  if (this.renderForms) {
14588
- const storedData = storage.getValue(id, {
14589
+ const storedData = storage.getValue(id2, {
14589
14590
  value: this.data.fieldValue
14590
14591
  });
14591
14592
  let textContent = storedData.value || "";
14592
- const maxLen = storage.getValue(id, {
14593
+ const maxLen = storage.getValue(id2, {
14593
14594
  charLimit: this.data.maxLen
14594
14595
  }).charLimit;
14595
14596
  if (maxLen && textContent.length > maxLen) {
@@ -14624,7 +14625,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14624
14625
  element.hidden = true;
14625
14626
  }
14626
14627
  GetElementsByNameSet.add(element);
14627
- element.setAttribute("data-element-id", id);
14628
+ element.setAttribute("data-element-id", id2);
14628
14629
  element.disabled = this.data.readOnly;
14629
14630
  element.name = this.data.fieldName;
14630
14631
  element.tabIndex = 0;
@@ -14637,7 +14638,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14637
14638
  element.maxLength = maxLen;
14638
14639
  }
14639
14640
  element.addEventListener("input", (event) => {
14640
- storage.setValue(id, { value: event.target.value });
14641
+ storage.setValue(id2, { value: event.target.value });
14641
14642
  this.setPropertyOnSiblings(
14642
14643
  element,
14643
14644
  "value",
@@ -14678,7 +14679,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14678
14679
  const actions = {
14679
14680
  value(event) {
14680
14681
  elementData.userValue = event.detail.value ?? "";
14681
- storage.setValue(id, { value: elementData.userValue.toString() });
14682
+ storage.setValue(id2, { value: elementData.userValue.toString() });
14682
14683
  event.target.value = elementData.userValue;
14683
14684
  },
14684
14685
  formattedValue(event) {
@@ -14687,7 +14688,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14687
14688
  if (formattedValue !== null && formattedValue !== void 0 && event.target !== document.activeElement) {
14688
14689
  event.target.value = formattedValue;
14689
14690
  }
14690
- storage.setValue(id, {
14691
+ storage.setValue(id2, {
14691
14692
  formattedValue
14692
14693
  });
14693
14694
  },
@@ -14708,11 +14709,11 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14708
14709
  }
14709
14710
  value = value.slice(0, charLimit);
14710
14711
  target.value = elementData.userValue = value;
14711
- storage.setValue(id, { value });
14712
+ storage.setValue(id2, { value });
14712
14713
  this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
14713
14714
  source: this,
14714
14715
  detail: {
14715
- id,
14716
+ id: id2,
14716
14717
  name: "Keystroke",
14717
14718
  value,
14718
14719
  willCommit: true,
@@ -14747,7 +14748,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14747
14748
  this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
14748
14749
  source: this,
14749
14750
  detail: {
14750
- id,
14751
+ id: id2,
14751
14752
  name: "Keystroke",
14752
14753
  value,
14753
14754
  willCommit: true,
@@ -14772,7 +14773,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14772
14773
  this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
14773
14774
  source: this,
14774
14775
  detail: {
14775
- id,
14776
+ id: id2,
14776
14777
  name: "Keystroke",
14777
14778
  value,
14778
14779
  willCommit: true,
@@ -14821,7 +14822,7 @@ var TextWidgetAnnotationElement = class extends WidgetAnnotationElement {
14821
14822
  this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
14822
14823
  source: this,
14823
14824
  detail: {
14824
- id,
14825
+ id: id2,
14825
14826
  name: "Keystroke",
14826
14827
  value,
14827
14828
  change: data || "",
@@ -14883,18 +14884,18 @@ var CheckboxWidgetAnnotationElement = class extends WidgetAnnotationElement {
14883
14884
  render() {
14884
14885
  const storage = this.annotationStorage;
14885
14886
  const data = this.data;
14886
- const id = data.id;
14887
- let value = storage.getValue(id, {
14887
+ const id2 = data.id;
14888
+ let value = storage.getValue(id2, {
14888
14889
  value: data.exportValue === data.fieldValue
14889
14890
  }).value;
14890
14891
  if (typeof value === "string") {
14891
14892
  value = value !== "Off";
14892
- storage.setValue(id, { value });
14893
+ storage.setValue(id2, { value });
14893
14894
  }
14894
14895
  this.container.classList.add("buttonWidgetAnnotation", "checkBox");
14895
14896
  const element = document.createElement("input");
14896
14897
  GetElementsByNameSet.add(element);
14897
- element.setAttribute("data-element-id", id);
14898
+ element.setAttribute("data-element-id", id2);
14898
14899
  element.disabled = data.readOnly;
14899
14900
  this._setRequired(element, this.data.required);
14900
14901
  element.type = "checkbox";
@@ -14909,7 +14910,7 @@ var CheckboxWidgetAnnotationElement = class extends WidgetAnnotationElement {
14909
14910
  for (const checkbox of this._getElementsByName(
14910
14911
  name,
14911
14912
  /* skipId = */
14912
- id
14913
+ id2
14913
14914
  )) {
14914
14915
  const curChecked = checked && checkbox.exportValue === data.exportValue;
14915
14916
  if (checkbox.domElement) {
@@ -14917,7 +14918,7 @@ var CheckboxWidgetAnnotationElement = class extends WidgetAnnotationElement {
14917
14918
  }
14918
14919
  storage.setValue(checkbox.id, { value: curChecked });
14919
14920
  }
14920
- storage.setValue(id, { value: checked });
14921
+ storage.setValue(id2, { value: checked });
14921
14922
  });
14922
14923
  element.addEventListener("resetform", (event) => {
14923
14924
  const defaultValue = data.defaultFieldValue || "Off";
@@ -14928,7 +14929,7 @@ var CheckboxWidgetAnnotationElement = class extends WidgetAnnotationElement {
14928
14929
  const actions = {
14929
14930
  value(event) {
14930
14931
  event.target.checked = event.detail.value !== "Off";
14931
- storage.setValue(id, { value: event.target.checked });
14932
+ storage.setValue(id2, { value: event.target.checked });
14932
14933
  }
14933
14934
  };
14934
14935
  this._dispatchEventFromSandbox(actions, jsEvent);
@@ -14963,26 +14964,26 @@ var RadioButtonWidgetAnnotationElement = class extends WidgetAnnotationElement {
14963
14964
  this.container.classList.add("buttonWidgetAnnotation", "radioButton");
14964
14965
  const storage = this.annotationStorage;
14965
14966
  const data = this.data;
14966
- const id = data.id;
14967
- let value = storage.getValue(id, {
14967
+ const id2 = data.id;
14968
+ let value = storage.getValue(id2, {
14968
14969
  value: data.fieldValue === data.buttonValue
14969
14970
  }).value;
14970
14971
  if (typeof value === "string") {
14971
14972
  value = value !== data.buttonValue;
14972
- storage.setValue(id, { value });
14973
+ storage.setValue(id2, { value });
14973
14974
  }
14974
14975
  if (value) {
14975
14976
  for (const radio of this._getElementsByName(
14976
14977
  data.fieldName,
14977
14978
  /* skipId = */
14978
- id
14979
+ id2
14979
14980
  )) {
14980
14981
  storage.setValue(radio.id, { value: false });
14981
14982
  }
14982
14983
  }
14983
14984
  const element = document.createElement("input");
14984
14985
  GetElementsByNameSet.add(element);
14985
- element.setAttribute("data-element-id", id);
14986
+ element.setAttribute("data-element-id", id2);
14986
14987
  element.disabled = data.readOnly;
14987
14988
  this._setRequired(element, this.data.required);
14988
14989
  element.type = "radio";
@@ -14996,11 +14997,11 @@ var RadioButtonWidgetAnnotationElement = class extends WidgetAnnotationElement {
14996
14997
  for (const radio of this._getElementsByName(
14997
14998
  name,
14998
14999
  /* skipId = */
14999
- id
15000
+ id2
15000
15001
  )) {
15001
15002
  storage.setValue(radio.id, { value: false });
15002
15003
  }
15003
- storage.setValue(id, { value: checked });
15004
+ storage.setValue(id2, { value: checked });
15004
15005
  });
15005
15006
  element.addEventListener("resetform", (event) => {
15006
15007
  const defaultValue = data.defaultFieldValue;
@@ -15013,7 +15014,7 @@ var RadioButtonWidgetAnnotationElement = class extends WidgetAnnotationElement {
15013
15014
  value: (event) => {
15014
15015
  const checked = pdfButtonValue === event.detail.value;
15015
15016
  for (const radio of this._getElementsByName(event.target.name)) {
15016
- const curChecked = checked && radio.id === id;
15017
+ const curChecked = checked && radio.id === id2;
15017
15018
  if (radio.domElement) {
15018
15019
  radio.domElement.checked = curChecked;
15019
15020
  }
@@ -15069,13 +15070,13 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15069
15070
  render() {
15070
15071
  this.container.classList.add("choiceWidgetAnnotation");
15071
15072
  const storage = this.annotationStorage;
15072
- const id = this.data.id;
15073
- const storedData = storage.getValue(id, {
15073
+ const id2 = this.data.id;
15074
+ const storedData = storage.getValue(id2, {
15074
15075
  value: this.data.fieldValue
15075
15076
  });
15076
15077
  const selectElement = document.createElement("select");
15077
15078
  GetElementsByNameSet.add(selectElement);
15078
- selectElement.setAttribute("data-element-id", id);
15079
+ selectElement.setAttribute("data-element-id", id2);
15079
15080
  selectElement.disabled = this.data.readOnly;
15080
15081
  this._setRequired(selectElement, this.data.required);
15081
15082
  selectElement.name = this.data.fieldName;
@@ -15146,7 +15147,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15146
15147
  for (const option of selectElement.options) {
15147
15148
  option.selected = values.has(option.value);
15148
15149
  }
15149
- storage.setValue(id, {
15150
+ storage.setValue(id2, {
15150
15151
  value: getValue(
15151
15152
  /* isExport */
15152
15153
  true
@@ -15174,7 +15175,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15174
15175
  options[0].selected = true;
15175
15176
  }
15176
15177
  }
15177
- storage.setValue(id, {
15178
+ storage.setValue(id2, {
15178
15179
  value: getValue(
15179
15180
  /* isExport */
15180
15181
  true
@@ -15190,7 +15191,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15190
15191
  while (selectElement.length !== 0) {
15191
15192
  selectElement.remove(0);
15192
15193
  }
15193
- storage.setValue(id, { value: null, items: [] });
15194
+ storage.setValue(id2, { value: null, items: [] });
15194
15195
  selectedValues = getValue(
15195
15196
  /* isExport */
15196
15197
  false
@@ -15207,7 +15208,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15207
15208
  } else {
15208
15209
  selectElement.append(optionElement);
15209
15210
  }
15210
- storage.setValue(id, {
15211
+ storage.setValue(id2, {
15211
15212
  value: getValue(
15212
15213
  /* isExport */
15213
15214
  true
@@ -15234,7 +15235,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15234
15235
  if (selectElement.options.length > 0) {
15235
15236
  selectElement.options[0].selected = true;
15236
15237
  }
15237
- storage.setValue(id, {
15238
+ storage.setValue(id2, {
15238
15239
  value: getValue(
15239
15240
  /* isExport */
15240
15241
  true
@@ -15251,7 +15252,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15251
15252
  for (const option of event.target.options) {
15252
15253
  option.selected = indices.has(option.index);
15253
15254
  }
15254
- storage.setValue(id, {
15255
+ storage.setValue(id2, {
15255
15256
  value: getValue(
15256
15257
  /* isExport */
15257
15258
  true
@@ -15277,12 +15278,12 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15277
15278
  /* isExport */
15278
15279
  false
15279
15280
  );
15280
- storage.setValue(id, { value: exportValue });
15281
+ storage.setValue(id2, { value: exportValue });
15281
15282
  event.preventDefault();
15282
15283
  this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
15283
15284
  source: this,
15284
15285
  detail: {
15285
- id,
15286
+ id: id2,
15286
15287
  name: "Keystroke",
15287
15288
  value: selectedValues,
15288
15289
  change,
@@ -15310,7 +15311,7 @@ var ChoiceWidgetAnnotationElement = class extends WidgetAnnotationElement {
15310
15311
  );
15311
15312
  } else {
15312
15313
  selectElement.addEventListener("input", function(event) {
15313
- storage.setValue(id, { value: getValue(
15314
+ storage.setValue(id2, { value: getValue(
15314
15315
  /* isExport */
15315
15316
  true
15316
15317
  ) });
@@ -15359,7 +15360,7 @@ var PopupAnnotationElement = class extends AnnotationElement {
15359
15360
  }
15360
15361
  this.container.setAttribute(
15361
15362
  "aria-controls",
15362
- elementIds.map((id) => `${AnnotationPrefix}${id}`).join(",")
15363
+ elementIds.map((id2) => `${AnnotationPrefix}${id2}`).join(",")
15363
15364
  );
15364
15365
  return this.container;
15365
15366
  }
@@ -16341,8 +16342,8 @@ var _AnnotationLayer = class _AnnotationLayer {
16341
16342
  getEditableAnnotations() {
16342
16343
  return Array.from(__privateGet(this, _editableAnnotations).values());
16343
16344
  }
16344
- getEditableAnnotation(id) {
16345
- return __privateGet(this, _editableAnnotations).get(id);
16345
+ getEditableAnnotation(id2) {
16346
+ return __privateGet(this, _editableAnnotations).get(id2);
16346
16347
  }
16347
16348
  /**
16348
16349
  * @private
@@ -16367,9 +16368,9 @@ _annotationCanvasMap = new WeakMap();
16367
16368
  _editableAnnotations = new WeakMap();
16368
16369
  _structTreeLayer = new WeakMap();
16369
16370
  _AnnotationLayer_instances = new WeakSet();
16370
- appendElement_fn = async function(element, id, popupElements) {
16371
+ appendElement_fn = async function(element, id2, popupElements) {
16371
16372
  const contentElement = element.firstChild || element;
16372
- const annotationId = contentElement.id = `${AnnotationPrefix}${id}`;
16373
+ const annotationId = contentElement.id = `${AnnotationPrefix}${id2}`;
16373
16374
  const ariaAttributes = await __privateGet(this, _structTreeLayer)?.getAriaAttributes(annotationId);
16374
16375
  if (ariaAttributes) {
16375
16376
  for (const [key, value] of ariaAttributes) {
@@ -16394,8 +16395,8 @@ setAnnotationCanvasMap_fn = function() {
16394
16395
  return;
16395
16396
  }
16396
16397
  const layer = this.div;
16397
- for (const [id, canvas] of __privateGet(this, _annotationCanvasMap)) {
16398
- const element = layer.querySelector(`[data-annotation-id="${id}"]`);
16398
+ for (const [id2, canvas] of __privateGet(this, _annotationCanvasMap)) {
16399
+ const element = layer.querySelector(`[data-annotation-id="${id2}"]`);
16399
16400
  if (!element) {
16400
16401
  continue;
16401
16402
  }
@@ -16410,13 +16411,13 @@ setAnnotationCanvasMap_fn = function() {
16410
16411
  } else {
16411
16412
  firstChild.after(canvas);
16412
16413
  }
16413
- const editableAnnotation = __privateGet(this, _editableAnnotations).get(id);
16414
+ const editableAnnotation = __privateGet(this, _editableAnnotations).get(id2);
16414
16415
  if (!editableAnnotation) {
16415
16416
  continue;
16416
16417
  }
16417
16418
  if (editableAnnotation._hasNoCanvas) {
16418
16419
  this._annotationEditorUIManager?.setMissingCanvas(
16419
- id,
16420
+ id2,
16420
16421
  element.id,
16421
16422
  canvas
16422
16423
  );
@@ -16932,7 +16933,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
16932
16933
  defaultAppearanceData: { fontSize, fontColor },
16933
16934
  rect,
16934
16935
  rotation,
16935
- id,
16936
+ id: id2,
16936
16937
  popupRef
16937
16938
  },
16938
16939
  textContent,
@@ -16953,8 +16954,8 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
16953
16954
  pageIndex: pageNumber - 1,
16954
16955
  rect: rect.slice(0),
16955
16956
  rotation,
16956
- annotationElementId: id,
16957
- id,
16957
+ annotationElementId: id2,
16958
+ id: id2,
16958
16959
  deleted: false,
16959
16960
  popupRef
16960
16961
  };
@@ -18761,7 +18762,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18761
18762
  let initialData = null;
18762
18763
  if (data instanceof HighlightAnnotationElement) {
18763
18764
  const {
18764
- data: { quadPoints: quadPoints2, rect, rotation, id, color: color2, opacity: opacity2, popupRef },
18765
+ data: { quadPoints: quadPoints2, rect, rotation, id: id2, color: color2, opacity: opacity2, popupRef },
18765
18766
  parent: {
18766
18767
  page: { pageNumber }
18767
18768
  }
@@ -18775,8 +18776,8 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18775
18776
  pageIndex: pageNumber - 1,
18776
18777
  rect: rect.slice(0),
18777
18778
  rotation,
18778
- annotationElementId: id,
18779
- id,
18779
+ annotationElementId: id2,
18780
+ id: id2,
18780
18781
  deleted: false,
18781
18782
  popupRef
18782
18783
  };
@@ -18786,7 +18787,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18786
18787
  inkLists: inkLists2,
18787
18788
  rect,
18788
18789
  rotation,
18789
- id,
18790
+ id: id2,
18790
18791
  color: color2,
18791
18792
  borderStyle: { rawWidth: thickness },
18792
18793
  popupRef
@@ -18804,8 +18805,8 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18804
18805
  pageIndex: pageNumber - 1,
18805
18806
  rect: rect.slice(0),
18806
18807
  rotation,
18807
- annotationElementId: id,
18808
- id,
18808
+ annotationElementId: id2,
18809
+ id: id2,
18809
18810
  deleted: false,
18810
18811
  popupRef
18811
18812
  };
@@ -18853,7 +18854,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18853
18854
  point.y = pageHeight - (points[i + 1] - pageY);
18854
18855
  outliner.add(point);
18855
18856
  }
18856
- const { id, clipPathId } = parent.drawLayer.draw(
18857
+ const { id: id2, clipPathId } = parent.drawLayer.draw(
18857
18858
  {
18858
18859
  bbox: [0, 0, 1, 1],
18859
18860
  root: {
@@ -18876,7 +18877,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
18876
18877
  );
18877
18878
  __privateMethod(_c = editor, _HighlightEditor_instances, createFreeOutlines_fn).call(_c, {
18878
18879
  highlightOutlines: outliner.getOutlines(),
18879
- highlightId: id,
18880
+ highlightId: id2,
18880
18881
  clipPathId
18881
18882
  });
18882
18883
  __privateMethod(_d = editor, _HighlightEditor_instances, addToDrawLayer_fn).call(_d);
@@ -19931,7 +19932,7 @@ createDrawOutlines_fn = function({ drawOutlines, drawId, drawingOptions }) {
19931
19932
  __privateMethod(this, _DrawingEditor_instances, updateBbox_fn).call(this, drawOutlines.box);
19932
19933
  };
19933
19934
  createDrawing_fn = function(drawOutlines, parent) {
19934
- const { id } = parent.drawLayer.draw(
19935
+ const { id: id2 } = parent.drawLayer.draw(
19935
19936
  _DrawingEditor._mergeSVGProperties(
19936
19937
  this._drawingOptions.toSVGProperties(),
19937
19938
  drawOutlines.defaultSVGProperties
@@ -19941,7 +19942,7 @@ createDrawing_fn = function(drawOutlines, parent) {
19941
19942
  /* hasClip = */
19942
19943
  false
19943
19944
  );
19944
- return id;
19945
+ return id2;
19945
19946
  };
19946
19947
  cleanDrawLayer_fn2 = function() {
19947
19948
  if (this._drawId === null || !this.parent) {
@@ -20925,7 +20926,7 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
20925
20926
  inkLists,
20926
20927
  rect,
20927
20928
  rotation,
20928
- id,
20929
+ id: id2,
20929
20930
  color,
20930
20931
  opacity,
20931
20932
  borderStyle: { rawWidth: thickness },
@@ -20945,8 +20946,8 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
20945
20946
  pageIndex: pageNumber - 1,
20946
20947
  rect: rect.slice(0),
20947
20948
  rotation,
20948
- annotationElementId: id,
20949
- id,
20949
+ annotationElementId: id2,
20950
+ id: id2,
20950
20951
  deleted: false,
20951
20952
  popupRef
20952
20953
  };
@@ -21343,9 +21344,9 @@ neighborIndexToId_fn = function(i0, j0, i, j) {
21343
21344
  };
21344
21345
  _neighborIdToIndex = new WeakMap();
21345
21346
  clockwiseNonZero_fn = function(buf, width, i0, j0, i, j, offset) {
21346
- const id = __privateMethod(this, _SignatureExtractor_static, neighborIndexToId_fn).call(this, i0, j0, i, j);
21347
+ const id2 = __privateMethod(this, _SignatureExtractor_static, neighborIndexToId_fn).call(this, i0, j0, i, j);
21347
21348
  for (let k = 0; k < 8; k++) {
21348
- const kk = (-k + id - offset + 16) % 8;
21349
+ const kk = (-k + id2 - offset + 16) % 8;
21349
21350
  const shiftI = __privateGet(this, _neighborIdToIndex)[2 * kk];
21350
21351
  const shiftJ = __privateGet(this, _neighborIdToIndex)[2 * kk + 1];
21351
21352
  if (buf[(i0 + shiftI) * width + (j0 + shiftJ)] !== 0) {
@@ -21355,9 +21356,9 @@ clockwiseNonZero_fn = function(buf, width, i0, j0, i, j, offset) {
21355
21356
  return -1;
21356
21357
  };
21357
21358
  counterClockwiseNonZero_fn = function(buf, width, i0, j0, i, j, offset) {
21358
- const id = __privateMethod(this, _SignatureExtractor_static, neighborIndexToId_fn).call(this, i0, j0, i, j);
21359
+ const id2 = __privateMethod(this, _SignatureExtractor_static, neighborIndexToId_fn).call(this, i0, j0, i, j);
21359
21360
  for (let k = 0; k < 8; k++) {
21360
- const kk = (k + id + offset + 16) % 8;
21361
+ const kk = (k + id2 + offset + 16) % 8;
21361
21362
  const shiftI = __privateGet(this, _neighborIdToIndex)[2 * kk];
21362
21363
  const shiftJ = __privateGet(this, _neighborIdToIndex)[2 * kk + 1];
21363
21364
  if (buf[(i0 + shiftI) * width + (j0 + shiftJ)] !== 0) {
@@ -22381,7 +22382,7 @@ var StampEditor = class extends AnnotationEditor {
22381
22382
  let missingCanvas = false;
22382
22383
  if (data instanceof StampAnnotationElement) {
22383
22384
  const {
22384
- data: { rect: rect2, rotation, id, structParent, popupRef },
22385
+ data: { rect: rect2, rotation, id: id2, structParent, popupRef },
22385
22386
  container,
22386
22387
  parent: {
22387
22388
  page: { pageNumber }
@@ -22400,7 +22401,7 @@ var StampEditor = class extends AnnotationEditor {
22400
22401
  missingCanvas = true;
22401
22402
  data._hasNoCanvas = true;
22402
22403
  }
22403
- const altText = (await parent._structTree.getAriaAttributes(`${AnnotationPrefix}${id}`))?.get("aria-label") || "";
22404
+ const altText = (await parent._structTree.getAriaAttributes(`${AnnotationPrefix}${id2}`))?.get("aria-label") || "";
22404
22405
  initialData = data = {
22405
22406
  annotationType: AnnotationEditorType.STAMP,
22406
22407
  bitmapId: bitmapId2,
@@ -22408,8 +22409,8 @@ var StampEditor = class extends AnnotationEditor {
22408
22409
  pageIndex: pageNumber - 1,
22409
22410
  rect: rect2.slice(0),
22410
22411
  rotation,
22411
- annotationElementId: id,
22412
- id,
22412
+ annotationElementId: id2,
22413
+ id: id2,
22413
22414
  deleted: false,
22414
22415
  accessibilityData: {
22415
22416
  decorative: false,
@@ -23014,18 +23015,18 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
23014
23015
  if (!this.div.contains(elements[0])) {
23015
23016
  return;
23016
23017
  }
23017
- let id;
23018
+ let id2;
23018
23019
  const regex = new RegExp(`^${AnnotationEditorPrefix}[0-9]+$`);
23019
23020
  for (const element of elements) {
23020
23021
  if (regex.test(element.id)) {
23021
- id = element.id;
23022
+ id2 = element.id;
23022
23023
  break;
23023
23024
  }
23024
23025
  }
23025
- if (!id) {
23026
+ if (!id2) {
23026
23027
  return;
23027
23028
  }
23028
- const editor = __privateGet(this, _editors).get(id);
23029
+ const editor = __privateGet(this, _editors).get(id2);
23029
23030
  if (editor?.annotationElementId === null) {
23030
23031
  e.stopPropagation();
23031
23032
  e.preventDefault();
@@ -23054,18 +23055,18 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
23054
23055
  if (__privateGet(this, _annotationLayer)) {
23055
23056
  const editables = __privateGet(this, _annotationLayer).getEditableAnnotations();
23056
23057
  for (const editable of editables) {
23057
- const { id } = editable.data;
23058
- if (__privateGet(this, _uiManager3).isDeletedAnnotationElement(id)) {
23058
+ const { id: id2 } = editable.data;
23059
+ if (__privateGet(this, _uiManager3).isDeletedAnnotationElement(id2)) {
23059
23060
  continue;
23060
23061
  }
23061
- let editor = resetAnnotations.get(id);
23062
+ let editor = resetAnnotations.get(id2);
23062
23063
  if (editor) {
23063
23064
  editor.resetAnnotationElement(editable);
23064
23065
  editor.show(false);
23065
23066
  editable.show();
23066
23067
  continue;
23067
23068
  }
23068
- editor = changedAnnotations.get(id);
23069
+ editor = changedAnnotations.get(id2);
23069
23070
  if (editor) {
23070
23071
  __privateGet(this, _uiManager3).addChangedExistingAnnotation(editor);
23071
23072
  if (editor.renderAnnotationElement(editable)) {
@@ -23087,8 +23088,8 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
23087
23088
  this.toggleAnnotationLayerPointerEvents(true);
23088
23089
  __privateSet(this, _isDisabling, false);
23089
23090
  }
23090
- getEditableAnnotation(id) {
23091
- return __privateGet(this, _annotationLayer)?.getEditableAnnotation(id) || null;
23091
+ getEditableAnnotation(id2) {
23092
+ return __privateGet(this, _annotationLayer)?.getEditableAnnotation(id2) || null;
23092
23093
  }
23093
23094
  /**
23094
23095
  * Set the current editor.
@@ -23286,10 +23287,10 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
23286
23287
  this.updateToolbar(options);
23287
23288
  await __privateGet(this, _uiManager3).updateMode(options.mode);
23288
23289
  const { offsetX, offsetY } = __privateMethod(this, _AnnotationEditorLayer_instances, getCenterPoint_fn).call(this);
23289
- const id = this.getNextId();
23290
+ const id2 = this.getNextId();
23290
23291
  const editor = __privateMethod(this, _AnnotationEditorLayer_instances, createNewEditor_fn).call(this, {
23291
23292
  parent: this,
23292
- id,
23293
+ id: id2,
23293
23294
  x: offsetX,
23294
23295
  y: offsetY,
23295
23296
  uiManager: __privateGet(this, _uiManager3),
@@ -23316,10 +23317,10 @@ var _AnnotationEditorLayer = class _AnnotationEditorLayer {
23316
23317
  * @returns {AnnotationEditor}
23317
23318
  */
23318
23319
  createAndAddNewEditor(event, isCentered, data = {}) {
23319
- const id = this.getNextId();
23320
+ const id2 = this.getNextId();
23320
23321
  const editor = __privateMethod(this, _AnnotationEditorLayer_instances, createNewEditor_fn).call(this, {
23321
23322
  parent: this,
23322
- id,
23323
+ id: id2,
23323
23324
  x: event.offsetX,
23324
23325
  y: event.offsetY,
23325
23326
  uiManager: __privateGet(this, _uiManager3),
@@ -23686,41 +23687,41 @@ var _DrawLayer = class _DrawLayer {
23686
23687
  return shadow(this, "_svgFactory", new DOMSVGFactory());
23687
23688
  }
23688
23689
  draw(properties, isPathUpdatable = false, hasClip = false) {
23689
- const id = __privateWrapper(_DrawLayer, _id4)._++;
23690
+ const id2 = __privateWrapper(_DrawLayer, _id4)._++;
23690
23691
  const root = __privateMethod(this, _DrawLayer_instances, createSVG_fn).call(this);
23691
23692
  const defs = _DrawLayer._svgFactory.createElement("defs");
23692
23693
  root.append(defs);
23693
23694
  const path = _DrawLayer._svgFactory.createElement("path");
23694
23695
  defs.append(path);
23695
- const pathId = `path_p${this.pageIndex}_${id}`;
23696
+ const pathId = `path_p${this.pageIndex}_${id2}`;
23696
23697
  path.setAttribute("id", pathId);
23697
23698
  path.setAttribute("vector-effect", "non-scaling-stroke");
23698
23699
  if (isPathUpdatable) {
23699
- __privateGet(this, _toUpdate).set(id, path);
23700
+ __privateGet(this, _toUpdate).set(id2, path);
23700
23701
  }
23701
23702
  const clipPathId = hasClip ? __privateMethod(this, _DrawLayer_instances, createClipPath_fn).call(this, defs, pathId) : null;
23702
23703
  const use = _DrawLayer._svgFactory.createElement("use");
23703
23704
  root.append(use);
23704
23705
  use.setAttribute("href", `#${pathId}`);
23705
23706
  this.updateProperties(root, properties);
23706
- __privateGet(this, _mapping).set(id, root);
23707
- return { id, clipPathId: `url(#${clipPathId})` };
23707
+ __privateGet(this, _mapping).set(id2, root);
23708
+ return { id: id2, clipPathId: `url(#${clipPathId})` };
23708
23709
  }
23709
23710
  drawOutline(properties, mustRemoveSelfIntersections) {
23710
- const id = __privateWrapper(_DrawLayer, _id4)._++;
23711
+ const id2 = __privateWrapper(_DrawLayer, _id4)._++;
23711
23712
  const root = __privateMethod(this, _DrawLayer_instances, createSVG_fn).call(this);
23712
23713
  const defs = _DrawLayer._svgFactory.createElement("defs");
23713
23714
  root.append(defs);
23714
23715
  const path = _DrawLayer._svgFactory.createElement("path");
23715
23716
  defs.append(path);
23716
- const pathId = `path_p${this.pageIndex}_${id}`;
23717
+ const pathId = `path_p${this.pageIndex}_${id2}`;
23717
23718
  path.setAttribute("id", pathId);
23718
23719
  path.setAttribute("vector-effect", "non-scaling-stroke");
23719
23720
  let maskId;
23720
23721
  if (mustRemoveSelfIntersections) {
23721
23722
  const mask = _DrawLayer._svgFactory.createElement("mask");
23722
23723
  defs.append(mask);
23723
- maskId = `mask_p${this.pageIndex}_${id}`;
23724
+ maskId = `mask_p${this.pageIndex}_${id2}`;
23724
23725
  mask.setAttribute("id", maskId);
23725
23726
  mask.setAttribute("maskUnits", "objectBoundingBox");
23726
23727
  const rect = _DrawLayer._svgFactory.createElement("rect");
@@ -23747,12 +23748,12 @@ var _DrawLayer = class _DrawLayer {
23747
23748
  use1.classList.add("mainOutline");
23748
23749
  use2.classList.add("secondaryOutline");
23749
23750
  this.updateProperties(root, properties);
23750
- __privateGet(this, _mapping).set(id, root);
23751
- return id;
23751
+ __privateGet(this, _mapping).set(id2, root);
23752
+ return id2;
23752
23753
  }
23753
- finalizeDraw(id, properties) {
23754
- __privateGet(this, _toUpdate).delete(id);
23755
- this.updateProperties(id, properties);
23754
+ finalizeDraw(id2, properties) {
23755
+ __privateGet(this, _toUpdate).delete(id2);
23756
+ this.updateProperties(id2, properties);
23756
23757
  }
23757
23758
  updateProperties(elementOrId, properties) {
23758
23759
  var _a2;
@@ -23782,25 +23783,25 @@ var _DrawLayer = class _DrawLayer {
23782
23783
  __privateMethod(this, _DrawLayer_instances, updateProperties_fn).call(this, pathElement, path);
23783
23784
  }
23784
23785
  }
23785
- updateParent(id, layer) {
23786
+ updateParent(id2, layer) {
23786
23787
  if (layer === this) {
23787
23788
  return;
23788
23789
  }
23789
- const root = __privateGet(this, _mapping).get(id);
23790
+ const root = __privateGet(this, _mapping).get(id2);
23790
23791
  if (!root) {
23791
23792
  return;
23792
23793
  }
23793
23794
  __privateGet(layer, _parent2).append(root);
23794
- __privateGet(this, _mapping).delete(id);
23795
- __privateGet(layer, _mapping).set(id, root);
23795
+ __privateGet(this, _mapping).delete(id2);
23796
+ __privateGet(layer, _mapping).set(id2, root);
23796
23797
  }
23797
- remove(id) {
23798
- __privateGet(this, _toUpdate).delete(id);
23798
+ remove(id2) {
23799
+ __privateGet(this, _toUpdate).delete(id2);
23799
23800
  if (__privateGet(this, _parent2) === null) {
23800
23801
  return;
23801
23802
  }
23802
- __privateGet(this, _mapping).get(id).remove();
23803
- __privateGet(this, _mapping).delete(id);
23803
+ __privateGet(this, _mapping).get(id2).remove();
23804
+ __privateGet(this, _mapping).delete(id2);
23804
23805
  }
23805
23806
  destroy() {
23806
23807
  __privateSet(this, _parent2, null);
@@ -23949,15 +23950,93 @@ var AnnotationOperatorsList = class {
23949
23950
  * @param id The id of the annotation.
23950
23951
  * @return The list of operators for the given annotation id.
23951
23952
  */
23952
- get(id) {
23953
- return this.map.get(id) ?? [];
23953
+ get(id2) {
23954
+ return this.map.get(id2) ?? [];
23954
23955
  }
23955
23956
  };
23956
23957
 
23957
- // src/lib/SvgCanvasContext.ts
23958
- function parseTransformMatrix(transformString) {
23959
- const values = transformString.match(/matrix\(([^)]+)\)/)?.[1].split(",").map(Number);
23960
- return new DOMMatrix(values);
23958
+ // src/lib/Svg.ts
23959
+ function isSvgElement(node) {
23960
+ return "children" in node;
23961
+ }
23962
+ function isSvgPath(node) {
23963
+ return node.tag === "path";
23964
+ }
23965
+ function isSvgImage(node) {
23966
+ return node.tag === "image";
23967
+ }
23968
+ function isSvgMarkedContent(node) {
23969
+ return node.tag === "use" && "type" in node.attrs;
23970
+ }
23971
+ function isSvgRoot(node) {
23972
+ return node.tag === "svg";
23973
+ }
23974
+ function id(type, id2 = null, scope) {
23975
+ return [type, scope, id2 ?? crypto.randomUUID()].filter(Boolean).join("_");
23976
+ }
23977
+ function findSvgNode(root, matcher) {
23978
+ for (const child of root.children) {
23979
+ if (typeof child === "string") {
23980
+ continue;
23981
+ }
23982
+ if (matcher(child)) {
23983
+ return child;
23984
+ }
23985
+ if (isSvgElement(child)) {
23986
+ const result = findSvgNode(child, matcher);
23987
+ if (result) {
23988
+ return result;
23989
+ }
23990
+ }
23991
+ }
23992
+ return null;
23993
+ }
23994
+ function parseNumberList(input) {
23995
+ return input.trim().replace(/[\s,]+/g, " ").split(" ").filter(Boolean).map(Number);
23996
+ }
23997
+ function parseTransform(input) {
23998
+ if (!input) {
23999
+ return new DOMMatrix();
24000
+ }
24001
+ const result = new DOMMatrix();
24002
+ const regex = /([a-zA-Z]+)\s*\(([^)]*)\)/g;
24003
+ let match = regex.exec(input);
24004
+ while (match) {
24005
+ const k = match[1];
24006
+ const nums = parseNumberList(match[2]);
24007
+ let t = new DOMMatrix();
24008
+ switch (k) {
24009
+ case "matrix":
24010
+ if (nums.length >= 6) {
24011
+ t = new DOMMatrix(nums);
24012
+ }
24013
+ break;
24014
+ case "translate":
24015
+ t = new DOMMatrix().translate(nums[0] || 0, nums[1] || 0);
24016
+ break;
24017
+ case "scale":
24018
+ t = new DOMMatrix().scale(nums[0] ?? 1, nums[1] ?? nums[0] ?? 1);
24019
+ break;
24020
+ case "rotate": {
24021
+ const angle = (nums[0] || 0) * Math.PI / 180;
24022
+ if (nums.length >= 3) {
24023
+ t = new DOMMatrix().translate(nums[1], nums[2]).rotate(angle).translate(-nums[1], -nums[2]);
24024
+ } else {
24025
+ t = new DOMMatrix().rotate(angle);
24026
+ }
24027
+ break;
24028
+ }
24029
+ case "skewX":
24030
+ t = new DOMMatrix().skewX((nums[0] || 0) * Math.PI / 180);
24031
+ break;
24032
+ case "skewY":
24033
+ t = new DOMMatrix().skewY((nums[0] || 0) * Math.PI / 180);
24034
+ break;
24035
+ }
24036
+ result.multiplySelf(t);
24037
+ match = regex.exec(input);
24038
+ }
24039
+ return result;
23961
24040
  }
23962
24041
  function matrixToTransform(matrix) {
23963
24042
  return `matrix(${matrix.a}, ${matrix.b}, ${matrix.c}, ${matrix.d}, ${matrix.e}, ${matrix.f})`;
@@ -23984,20 +24063,6 @@ function parseFontStyle(fontString) {
23984
24063
  fontFamilies: match.groups?.family ? match.groups.family.split(",").map((entry) => entry.trim().replace(/^"/, "").replace(/"$/, "")) : ["serif"]
23985
24064
  };
23986
24065
  }
23987
- function parseRGBAColor(color) {
23988
- const match = color.match(
23989
- /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/
23990
- );
23991
- if (!match) {
23992
- return { r: 0, g: 0, b: 0, a: 1 };
23993
- }
23994
- return {
23995
- r: Number.parseInt(match[1], 10),
23996
- g: Number.parseInt(match[2], 10),
23997
- b: Number.parseInt(match[3], 10),
23998
- a: match[4] ? Number.parseFloat(match[4]) : 1
23999
- };
24000
- }
24001
24066
  function getTextAnchor(textAlign) {
24002
24067
  switch (textAlign) {
24003
24068
  case "left":
@@ -24032,6 +24097,195 @@ function getAngle(vector) {
24032
24097
  }
24033
24098
  return -Math.acos(vector[0]);
24034
24099
  }
24100
+ function sampleEllipse(cx, cy, rx, ry, steps) {
24101
+ const pts = [];
24102
+ for (let i = 0; i < steps; i++) {
24103
+ const t = i / steps * 2 * Math.PI;
24104
+ pts.push({ x: cx + rx * Math.cos(t), y: cy + ry * Math.sin(t) });
24105
+ }
24106
+ pts.push({ x: cx + rx, y: cy });
24107
+ return pts;
24108
+ }
24109
+ function outlinePoints(node, defs = [], inheritedMatrix = new DOMMatrix()) {
24110
+ const transformMatrix = node.attrs.transform ? inheritedMatrix.multiply(parseTransform(node.attrs.transform)) : inheritedMatrix;
24111
+ const points = [];
24112
+ const addPoint = (p) => {
24113
+ const tp = transformMatrix.transformPoint(new DOMPoint(p.x, p.y));
24114
+ points.push({
24115
+ x: tp.x,
24116
+ y: tp.y
24117
+ });
24118
+ };
24119
+ switch (node.tag) {
24120
+ case "image":
24121
+ case "rect": {
24122
+ const x = node.attrs.x || 0;
24123
+ const y = node.attrs.y || 0;
24124
+ const w = node.attrs.width || 0;
24125
+ const h = node.attrs.height || 0;
24126
+ addPoint({ x, y });
24127
+ addPoint({ x: x + w, y });
24128
+ addPoint({ x: x + w, y: y + h });
24129
+ addPoint({ x, y: y + h });
24130
+ break;
24131
+ }
24132
+ case "line": {
24133
+ addPoint({
24134
+ x: node.attrs.x1 || 0,
24135
+ y: node.attrs.y1 || 0
24136
+ });
24137
+ addPoint({
24138
+ x: node.attrs.x2 || 0,
24139
+ y: node.attrs.y2 || 0
24140
+ });
24141
+ break;
24142
+ }
24143
+ case "polyline":
24144
+ case "polygon": {
24145
+ const raw = parseNumberList(node.attrs.points || "");
24146
+ for (let i = 0; i + 1 < raw.length; i += 2) {
24147
+ addPoint({ x: raw[i], y: raw[i + 1] });
24148
+ }
24149
+ break;
24150
+ }
24151
+ case "circle": {
24152
+ const cx = node.attrs.cx || 0;
24153
+ const cy = node.attrs.cy || 0;
24154
+ const r = node.attrs.r || 0;
24155
+ for (const p of sampleEllipse(
24156
+ cx,
24157
+ cy,
24158
+ r,
24159
+ r,
24160
+ Math.max(12, Math.ceil(r / 2))
24161
+ )) {
24162
+ addPoint(p);
24163
+ }
24164
+ break;
24165
+ }
24166
+ case "ellipse": {
24167
+ const cx = node.attrs.cx || 0;
24168
+ const cy = node.attrs.cy || 0;
24169
+ const rx = node.attrs.rx || 0;
24170
+ const ry = node.attrs.ry || 0;
24171
+ for (const p of sampleEllipse(
24172
+ cx,
24173
+ cy,
24174
+ rx,
24175
+ ry,
24176
+ Math.max(12, Math.ceil(Math.max(rx, ry) / 2))
24177
+ )) {
24178
+ addPoint(p);
24179
+ }
24180
+ break;
24181
+ }
24182
+ case "path": {
24183
+ const bbox = getBBox(parseCommands(node.attrs.d || ""));
24184
+ addPoint({ x: bbox.x, y: bbox.y });
24185
+ addPoint({ x: bbox.x, y: bbox.y + bbox.height });
24186
+ addPoint({ x: bbox.x + bbox.width, y: bbox.y });
24187
+ addPoint({ x: bbox.x + bbox.width, y: bbox.y + bbox.height });
24188
+ break;
24189
+ }
24190
+ case "g": {
24191
+ const boxes = (node.children || []).filter((child) => typeof child === "object").map((child) => getBBox2(child, defs, transformMatrix)).filter(Boolean);
24192
+ if (!boxes.length) {
24193
+ return [];
24194
+ }
24195
+ const x1 = Math.min(...boxes.map((b) => b.x));
24196
+ const y1 = Math.min(...boxes.map((b) => b.y));
24197
+ const x2 = Math.max(...boxes.map((b) => b.x + b.width));
24198
+ const y2 = Math.max(...boxes.map((b) => b.y + b.height));
24199
+ addPoint({ x: x1, y: y1 });
24200
+ addPoint({ x: x2, y: y1 });
24201
+ addPoint({ x: x2, y: y2 });
24202
+ addPoint({ x: x1, y: y2 });
24203
+ break;
24204
+ }
24205
+ case "use": {
24206
+ const href = node.attrs.href;
24207
+ if (!href) {
24208
+ break;
24209
+ }
24210
+ const id2 = href.substring(1);
24211
+ const def = defs.find(
24212
+ (d) => typeof d.attrs.id === "string" && d.attrs.id === id2
24213
+ );
24214
+ if (!def) {
24215
+ break;
24216
+ }
24217
+ points.push(...outlinePoints(def, defs, transformMatrix));
24218
+ break;
24219
+ }
24220
+ }
24221
+ return points;
24222
+ }
24223
+ function getBBox2(node, defs = [], inheritedMatrix = new DOMMatrix()) {
24224
+ const points = outlinePoints(node, defs, inheritedMatrix);
24225
+ if (!points || !points.length) {
24226
+ return null;
24227
+ }
24228
+ let minX = Number.POSITIVE_INFINITY;
24229
+ let minY = Number.POSITIVE_INFINITY;
24230
+ let maxX = Number.NEGATIVE_INFINITY;
24231
+ let maxY = Number.NEGATIVE_INFINITY;
24232
+ for (const p of points) {
24233
+ minX = Math.min(minX, p.x);
24234
+ minY = Math.min(minY, p.y);
24235
+ maxX = Math.max(maxX, p.x);
24236
+ maxY = Math.max(maxY, p.y);
24237
+ }
24238
+ if (minX === Number.POSITIVE_INFINITY) {
24239
+ return null;
24240
+ }
24241
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
24242
+ }
24243
+ function renderAttributes(attrs) {
24244
+ const result = Object.entries(attrs).filter(([, value]) => value != null).map(([key, value]) => `${key}="${value}"`).join(" ");
24245
+ if (result.length) {
24246
+ return ` ${result}`;
24247
+ }
24248
+ return "";
24249
+ }
24250
+ function renderChildren(children) {
24251
+ return children.map((child) => renderSvgNode(child)).join("");
24252
+ }
24253
+ function renderSvgNode(node) {
24254
+ if (typeof node === "string") {
24255
+ return node;
24256
+ }
24257
+ if (isSvgRoot(node)) {
24258
+ return `<svg${renderAttributes({
24259
+ xmlns: "http://www.w3.org/2000/svg",
24260
+ version: "1.1",
24261
+ width: `${node.attrs.width}`,
24262
+ height: `${node.attrs.height}`,
24263
+ viewBox: `0 0 ${node.attrs.width} ${node.attrs.height}`,
24264
+ preserveAspectRatio: "none",
24265
+ xmlSpace: "preserve"
24266
+ })}>${renderChildren(node.children)}</svg>`;
24267
+ }
24268
+ if (isSvgImage(node)) {
24269
+ return `<image${renderAttributes({
24270
+ href: node.attrs.href,
24271
+ width: `${node.attrs.width}`,
24272
+ height: `${node.attrs.height}`,
24273
+ transform: node.attrs.transform,
24274
+ preserveAspectRatio: "none"
24275
+ })} />`;
24276
+ }
24277
+ if (isSvgMarkedContent(node)) {
24278
+ return `<use${renderAttributes({
24279
+ href: node.attrs.href
24280
+ })} />`;
24281
+ }
24282
+ if (isSvgElement(node)) {
24283
+ return `<${node.tag}${renderAttributes(node.attrs)}>${renderChildren(node.children)}</${node.tag}>`;
24284
+ }
24285
+ return `<${node.tag}${renderAttributes(node.attrs)} />`;
24286
+ }
24287
+
24288
+ // src/lib/SvgCanvasContext.ts
24035
24289
  function isCanvas(img) {
24036
24290
  return "toDataURL" in img;
24037
24291
  }
@@ -24088,12 +24342,6 @@ var SvgRadialGradient = class {
24088
24342
  this.stops.push({ offset, color });
24089
24343
  }
24090
24344
  };
24091
- function isSvgElement(node) {
24092
- return "children" in node;
24093
- }
24094
- function isSvgText(node) {
24095
- return "text" in node;
24096
- }
24097
24345
  var SvgCanvasContext = class {
24098
24346
  constructor(width, height, canvas) {
24099
24347
  __publicField(this, "_width");
@@ -24123,13 +24371,16 @@ var SvgCanvasContext = class {
24123
24371
  });
24124
24372
  __publicField(this, "_styleStack", []);
24125
24373
  __publicField(this, "_groupStack", []);
24374
+ __publicField(this, "_markedStack", []);
24126
24375
  __publicField(this, "_transformMatrixStack", []);
24127
24376
  __publicField(this, "_root");
24128
24377
  __publicField(this, "_defs");
24129
24378
  __publicField(this, "_currentGroup");
24130
24379
  __publicField(this, "_currentElement", null);
24380
+ __publicField(this, "_currentMarked", null);
24131
24381
  __publicField(this, "_transformMatrix", new DOMMatrix([1, 0, 0, 1, 0, 0]));
24132
24382
  __publicField(this, "_currentPosition", {});
24383
+ __publicField(this, "_parents", /* @__PURE__ */ new Map());
24133
24384
  this._width = width;
24134
24385
  this._height = height;
24135
24386
  this._canvas = canvas;
@@ -24138,13 +24389,9 @@ var SvgCanvasContext = class {
24138
24389
  this._root = {
24139
24390
  tag: "svg",
24140
24391
  attrs: {
24141
- version: "1.1",
24142
- xmlns: "http://www.w3.org/2000/svg",
24143
- width: `${width}`,
24144
- height: `${height}`,
24145
- viewBox: `0 0 ${width} ${height}`,
24146
- preserveAspectRatio: "none",
24147
- "xml:space": "preserve"
24392
+ id: id("svg" /* Root */),
24393
+ width,
24394
+ height
24148
24395
  },
24149
24396
  children: []
24150
24397
  };
@@ -24154,7 +24401,7 @@ var SvgCanvasContext = class {
24154
24401
  children: []
24155
24402
  };
24156
24403
  this._currentGroup = this._root;
24157
- this._root.children.push(this._defs);
24404
+ this._addNode(this._defs, this._root);
24158
24405
  this.resetTransform();
24159
24406
  }
24160
24407
  get canvas() {
@@ -24258,8 +24505,8 @@ var SvgCanvasContext = class {
24258
24505
  this._height = height;
24259
24506
  this._canvas.width = width;
24260
24507
  this._canvas.height = height;
24261
- this._root.attrs.width = `${width}`;
24262
- this._root.attrs.height = `${height}`;
24508
+ this._root.attrs.width = width;
24509
+ this._root.attrs.height = height;
24263
24510
  }
24264
24511
  save() {
24265
24512
  this._groupStack.push(this._currentGroup);
@@ -24267,34 +24514,22 @@ var SvgCanvasContext = class {
24267
24514
  this._styleStack.push(this._getStyleState());
24268
24515
  this._transformMatrixStack.push(this.getTransform());
24269
24516
  }
24270
- clearRect(x, y, width, height) {
24271
- if (x !== 0 || y !== 0 || this._width !== width || this._height !== height) {
24272
- throw new Error("clearRect is not supported in SVG");
24273
- }
24274
- this._clearCanvas();
24275
- }
24276
24517
  restore() {
24277
- if (this._groupStack.length) {
24278
- const group = this._groupStack.pop();
24279
- if (!this._isTransformationGroup(this._currentGroup)) {
24280
- group.children = group.children.filter(
24281
- (child) => child !== this._currentGroup
24282
- );
24283
- group.children.push(...this._currentGroup.children);
24284
- }
24285
- this._currentGroup = group;
24286
- } else {
24287
- this._currentGroup = this._root;
24288
- }
24518
+ this._currentGroup = this._groupStack.pop() ?? this._root;
24289
24519
  if (this._styleStack.length) {
24290
- const state = this._styleStack.pop();
24291
- this._applyStyleState(state);
24520
+ this._applyStyleState(this._styleStack.pop());
24292
24521
  }
24293
24522
  if (this._transformMatrixStack.length) {
24294
24523
  const { a, b, c, d, e, f } = this._transformMatrixStack.pop();
24295
24524
  this.setTransform(a, b, c, d, e, f);
24296
24525
  }
24297
24526
  }
24527
+ clearRect(x, y, width, height) {
24528
+ if (x !== 0 || y !== 0 || this._width !== width || this._height !== height) {
24529
+ throw new Error("clearRect is not supported in SVG");
24530
+ }
24531
+ this._clearCanvas();
24532
+ }
24298
24533
  beginPath() {
24299
24534
  this._currentPosition = {};
24300
24535
  this._currentElement = {
@@ -24468,19 +24703,18 @@ var SvgCanvasContext = class {
24468
24703
  if (path instanceof SvgPath2D) {
24469
24704
  const d = toCommands(path);
24470
24705
  if (d && d !== "Z") {
24471
- const parent = this._currentGroup;
24472
24706
  const pathElement = {
24473
24707
  tag: "path",
24474
24708
  attrs: {
24475
24709
  d,
24476
24710
  fill: "none",
24477
24711
  stroke: "none",
24478
- "stroke-width": "0"
24712
+ "stroke-width": "1"
24479
24713
  }
24480
24714
  };
24481
24715
  this._applyTransformation(pathElement);
24482
24716
  this._applyStyle(pathElement, "stroke");
24483
- parent.children.push(pathElement);
24717
+ this._addNode(pathElement);
24484
24718
  }
24485
24719
  } else if (this._currentElement) {
24486
24720
  this._applyStyle(this._currentElement, "stroke");
@@ -24503,7 +24737,6 @@ var SvgCanvasContext = class {
24503
24737
  if (path instanceof SvgPath2D) {
24504
24738
  const d = toCommands(path);
24505
24739
  if (d && d !== "Z") {
24506
- const parent = this._currentGroup;
24507
24740
  const pathElement = {
24508
24741
  tag: "path",
24509
24742
  attrs: {
@@ -24515,7 +24748,7 @@ var SvgCanvasContext = class {
24515
24748
  };
24516
24749
  this._applyTransformation(pathElement);
24517
24750
  this._applyStyle(pathElement, "fill");
24518
- parent.children.push(pathElement);
24751
+ this._addNode(pathElement);
24519
24752
  }
24520
24753
  } else if (this._currentElement) {
24521
24754
  this._applyStyle(this._currentElement, "fill");
@@ -24529,19 +24762,18 @@ var SvgCanvasContext = class {
24529
24762
  if (a === 1 && b === 0 && c === 0 && d === 1 && e === 0 && f === 0 && x === 0 && y === 0 && width === this._width && height === this._height) {
24530
24763
  this._clearCanvas();
24531
24764
  }
24532
- const parent = this._currentGroup;
24533
24765
  const rect = {
24534
24766
  tag: "rect",
24535
24767
  attrs: {
24536
- x: `${x}`,
24537
- y: `${y}`,
24538
- width: `${width}`,
24539
- height: `${height}`
24768
+ x,
24769
+ y,
24770
+ width,
24771
+ height
24540
24772
  }
24541
24773
  };
24542
- parent.children.push(rect);
24543
- this._applyTransformation(rect);
24544
24774
  this._applyStyle(rect, "fill");
24775
+ this._applyTransformation(rect);
24776
+ this._addNode(rect);
24545
24777
  }
24546
24778
  getLineDash() {
24547
24779
  return this._currentStyle.lineDash;
@@ -24586,25 +24818,18 @@ var SvgCanvasContext = class {
24586
24818
  } else {
24587
24819
  throw new Error("Invalid number of arguments");
24588
24820
  }
24589
- const parent = this._currentGroup;
24590
24821
  const matrix = this._transformMatrix.translate(dx, dy);
24822
+ const href = isCanvas(image) ? image.toDataURL() : isImage(image) ? image.src : "";
24591
24823
  const svgImage = {
24592
24824
  tag: "image",
24593
24825
  attrs: {
24594
- width: `${dw}`,
24595
- height: `${dh}`,
24596
- preserveAspectRatio: "none"
24826
+ href,
24827
+ width: dw,
24828
+ height: dh
24597
24829
  }
24598
24830
  };
24599
- if (isCanvas(image)) {
24600
- svgImage.attrs.href = image.toDataURL();
24601
- } else if (isImage(image)) {
24602
- svgImage.attrs.href = image.src;
24603
- } else {
24604
- throw new Error("Unknown image source");
24605
- }
24606
24831
  this._applyTransformation(svgImage, matrix);
24607
- parent.children.push(svgImage);
24832
+ this._addNode(svgImage);
24608
24833
  }
24609
24834
  createPattern(image, repetition) {
24610
24835
  let src;
@@ -24637,19 +24862,17 @@ var SvgCanvasContext = class {
24637
24862
  if (path instanceof SvgPath2D && path.commands.length === 0) {
24638
24863
  return;
24639
24864
  }
24640
- const id = `clip_${crypto.randomUUID()}`;
24865
+ const clipId = id("clip" /* Clip */, null, this._root.attrs.id);
24641
24866
  const clipPath = {
24642
24867
  tag: "clipPath",
24643
24868
  attrs: {
24644
- id
24869
+ id: clipId
24645
24870
  },
24646
24871
  children: []
24647
24872
  };
24648
- this._defs.children.push(clipPath);
24649
- const group = this._currentGroup;
24650
- const clipGroup = this._isTransformationGroup(group) ? this._ensureTransformationGroup() : group;
24651
- clipGroup.attrs["clip-path"] = `url(#${id})`;
24652
- this._currentGroup = clipGroup;
24873
+ this._addNode(clipPath, this._defs);
24874
+ const clipGroup = this._ensureTransformationGroup();
24875
+ clipGroup.attrs["clip-path"] = `url(#${clipId})`;
24653
24876
  if (path instanceof SvgPath2D) {
24654
24877
  const pathElement = {
24655
24878
  tag: "path",
@@ -24658,13 +24881,11 @@ var SvgCanvasContext = class {
24658
24881
  }
24659
24882
  };
24660
24883
  this._applyTransformation(pathElement);
24661
- clipPath.children.push(pathElement);
24884
+ this._addNode(pathElement, clipPath);
24662
24885
  } else if (this._currentElement) {
24663
- clipPath.children.push(this._currentElement);
24664
- group.children = group.children.filter(
24665
- (node) => node !== this._currentElement
24666
- );
24886
+ this._addNode(this._currentElement, clipPath);
24667
24887
  }
24888
+ this._currentGroup = clipGroup;
24668
24889
  }
24669
24890
  measureText(text) {
24670
24891
  if (!this._ctx) {
@@ -24681,18 +24902,115 @@ var SvgCanvasContext = class {
24681
24902
  setTransform(a, b, c, d, e, f) {
24682
24903
  this._transformMatrix = new DOMMatrix([a, b, c, d, e, f]);
24683
24904
  }
24684
- _isTransformationGroup(node) {
24685
- return node.tag === "g" && Object.keys(node.attrs).length > 0;
24905
+ beginMarkedContent(type, props) {
24906
+ if (this._currentMarked) {
24907
+ this._markedStack.push(this._currentMarked);
24908
+ }
24909
+ let markedId = null;
24910
+ if (props != null) {
24911
+ if (typeof props === "number") {
24912
+ markedId = `${props}`;
24913
+ } else if (typeof props === "object" && typeof props.id === "number") {
24914
+ markedId = `${props.id}`;
24915
+ }
24916
+ }
24917
+ const computedId = id(
24918
+ "marked_content" /* MarkedContent */,
24919
+ markedId,
24920
+ this._root.attrs.id
24921
+ );
24922
+ const markedNode = {
24923
+ tag: "use",
24924
+ attrs: {
24925
+ href: `#${computedId}`,
24926
+ type,
24927
+ x: 0,
24928
+ y: 0,
24929
+ width: 0,
24930
+ height: 0
24931
+ }
24932
+ };
24933
+ const groupNode = {
24934
+ tag: "g",
24935
+ attrs: {
24936
+ id: computedId
24937
+ },
24938
+ children: []
24939
+ };
24940
+ this._addNode(groupNode, this._defs);
24941
+ this._currentMarked = {
24942
+ node: markedNode,
24943
+ group: groupNode,
24944
+ elements: []
24945
+ };
24946
+ }
24947
+ endMarkedContent() {
24948
+ if (!this._currentMarked) {
24949
+ return;
24950
+ }
24951
+ const bbox = getBBox2(
24952
+ this._currentMarked.group,
24953
+ this._defs.children
24954
+ );
24955
+ this._currentMarked.node.attrs = {
24956
+ ...this._currentMarked.node.attrs,
24957
+ x: bbox?.x ?? 0,
24958
+ y: bbox?.y ?? 0,
24959
+ width: bbox?.width ?? 0,
24960
+ height: bbox?.height ?? 0
24961
+ };
24962
+ this._currentMarked = this._markedStack.pop() ?? null;
24686
24963
  }
24687
24964
  _ensureTransformationGroup() {
24688
- const group = this._currentGroup;
24689
- const newGroup = {
24965
+ const group = {
24690
24966
  tag: "g",
24691
24967
  attrs: {},
24692
24968
  children: []
24693
24969
  };
24694
- group.children.push(newGroup);
24695
- return newGroup;
24970
+ this._addNode(group);
24971
+ return group;
24972
+ }
24973
+ _addNode(node, parent) {
24974
+ const oldParent = this._parents.get(node);
24975
+ if (oldParent) {
24976
+ oldParent.children = oldParent.children.filter((child) => child !== node);
24977
+ }
24978
+ if (parent) {
24979
+ parent.children.push(node);
24980
+ this._parents.set(node, parent);
24981
+ return;
24982
+ }
24983
+ if (!this._currentMarked) {
24984
+ this._addNode(node, this._currentGroup);
24985
+ return;
24986
+ }
24987
+ let group = this._currentGroup;
24988
+ if (this._currentMarked.elements.length === 0) {
24989
+ const markedStackToAdd = [this._currentMarked];
24990
+ let i;
24991
+ for (i = this._markedStack.length - 1; i >= 0; i--) {
24992
+ if (this._markedStack[i].elements.length !== 0) {
24993
+ break;
24994
+ }
24995
+ markedStackToAdd.unshift(this._markedStack[i]);
24996
+ }
24997
+ for (const marked of markedStackToAdd) {
24998
+ const parentMarked = this._markedStack[++i - 1];
24999
+ if (!parentMarked || parentMarked.elements.includes(group)) {
25000
+ this._addNode(marked.node, group);
25001
+ } else {
25002
+ this._addNode(marked.node, parentMarked.group);
25003
+ }
25004
+ parentMarked?.elements.push(marked.node);
25005
+ group = marked.group;
25006
+ }
25007
+ }
25008
+ if (this._currentMarked.elements.includes(group)) {
25009
+ this._addNode(node, group);
25010
+ } else {
25011
+ this._addNode(node, this._currentMarked.group);
25012
+ }
25013
+ this._currentMarked.elements.push(node);
24696
25014
  }
24697
25015
  _applyStyleState(styleState) {
24698
25016
  Object.assign(this._currentStyle, styleState);
@@ -24719,11 +25037,10 @@ var SvgCanvasContext = class {
24719
25037
  node.attrs.transform = matrixToTransform(matrix);
24720
25038
  }
24721
25039
  _createPatternNode(pattern, transform) {
24722
- const id = `pattern_${crypto.randomUUID()}`;
24723
25040
  return {
24724
25041
  tag: "pattern",
24725
25042
  attrs: {
24726
- id,
25043
+ id: id("pattern" /* Pattern */, null, this._root.attrs.id),
24727
25044
  width: `${pattern.width}`,
24728
25045
  height: `${pattern.height}`,
24729
25046
  patternTransform: transform ? matrixToTransform(transform) : void 0,
@@ -24742,12 +25059,11 @@ var SvgCanvasContext = class {
24742
25059
  };
24743
25060
  }
24744
25061
  _createGradientNode(gradient) {
24745
- const id = `pattern_${crypto.randomUUID()}`;
24746
25062
  if (gradient instanceof SvgRadialGradient) {
24747
25063
  return {
24748
25064
  tag: "radialGradient",
24749
25065
  attrs: {
24750
- id,
25066
+ id: id("pattern" /* Pattern */, null, this._root.attrs.id),
24751
25067
  cx: `${gradient.x1}`,
24752
25068
  cy: `${gradient.y1}`,
24753
25069
  r: `${gradient.r1}`,
@@ -24764,7 +25080,7 @@ var SvgCanvasContext = class {
24764
25080
  }
24765
25081
  };
24766
25082
  if (color.startsWith("rgba(")) {
24767
- const parsed = parseRGBAColor(color);
25083
+ const parsed = parseRgbaColor(color);
24768
25084
  stopElement.attrs["stop-color"] = `rgb(${parsed.r}, ${parsed.g}, ${parsed.b})`;
24769
25085
  stopElement.attrs["stop-opacity"] = `${parsed.a ?? 1}`;
24770
25086
  } else {
@@ -24777,7 +25093,7 @@ var SvgCanvasContext = class {
24777
25093
  return {
24778
25094
  tag: "linearGradient",
24779
25095
  attrs: {
24780
- id,
25096
+ id: id("pattern" /* Pattern */, null, this._root.attrs.id),
24781
25097
  x1: `${gradient.x1}`,
24782
25098
  x2: `${gradient.x2}`,
24783
25099
  y1: `${gradient.y1}`,
@@ -24793,7 +25109,7 @@ var SvgCanvasContext = class {
24793
25109
  }
24794
25110
  };
24795
25111
  if (color.startsWith("rgba(")) {
24796
- const parsed = parseRGBAColor(color);
25112
+ const parsed = parseRgbaColor(color);
24797
25113
  stopElement.attrs["stop-color"] = `rgb(${parsed.r}, ${parsed.g}, ${parsed.b})`;
24798
25114
  stopElement.attrs["stop-opacity"] = `${parsed.a ?? 1}`;
24799
25115
  } else {
@@ -24809,24 +25125,24 @@ var SvgCanvasContext = class {
24809
25125
  currentElement.attrs.opacity = `${globalAlpha}`;
24810
25126
  }
24811
25127
  const scale = this._getTransformScale();
24812
- const commands = currentElement.attrs.d ? parseCommands(currentElement.attrs.d) : [];
24813
- const transform = currentElement.attrs.transform ? parseTransformMatrix(currentElement.attrs.transform) : new DOMMatrix();
25128
+ const commands = isSvgPath(currentElement) ? parseCommands(currentElement.attrs.d) : [];
25129
+ const transform = currentElement.attrs.transform ? parseTransform(currentElement.attrs.transform) : new DOMMatrix();
24814
25130
  if (type === "fill") {
24815
25131
  const fillStyle = this._currentStyle.fillStyle;
24816
25132
  if (fillStyle instanceof SvgPattern) {
24817
25133
  const pattern = this._createPatternNode(fillStyle, fillStyle.transform);
24818
- this._defs.children.push(pattern);
25134
+ this._addNode(pattern, this._defs);
24819
25135
  currentElement.attrs.fill = `url(#${pattern.attrs.id})`;
24820
25136
  } else if (fillStyle instanceof SvgLinearGradient) {
24821
25137
  const gradient = this._createGradientNode(fillStyle);
24822
- this._defs.children.push(gradient);
25138
+ this._addNode(gradient, this._defs);
24823
25139
  currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
24824
25140
  } else if (fillStyle instanceof SvgRadialGradient) {
24825
25141
  const gradient = this._createGradientNode(fillStyle);
24826
- this._defs.children.push(gradient);
25142
+ this._addNode(gradient, this._defs);
24827
25143
  currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
24828
25144
  } else if (fillStyle.startsWith("rgba")) {
24829
- const color = parseRGBAColor(fillStyle);
25145
+ const color = parseRgbaColor(fillStyle);
24830
25146
  currentElement.attrs.fill = `rgb(${color.r}, ${color.g}, ${color.b})`;
24831
25147
  currentElement.attrs["fill-opacity"] = `${(color.a ?? 1) * globalAlpha}`;
24832
25148
  } else {
@@ -24836,19 +25152,19 @@ var SvgCanvasContext = class {
24836
25152
  const strokeStyle = this._currentStyle.strokeStyle;
24837
25153
  if (strokeStyle instanceof SvgPattern) {
24838
25154
  const path = transformPath(commands, transform);
24839
- const bbox = calculateBoundingBox(path);
25155
+ const bbox = getBBox(path);
24840
25156
  const pattern = this._createPatternNode(
24841
25157
  strokeStyle,
24842
25158
  new DOMMatrix([1, 0, 0, 1, Math.max(bbox.x, 0), 0])
24843
25159
  );
24844
- this._defs.children.push(pattern);
25160
+ this._addNode(pattern, this._defs);
24845
25161
  currentElement.attrs.stroke = `url(#${pattern.attrs.id})`;
24846
25162
  } else if (strokeStyle instanceof SvgLinearGradient) {
24847
25163
  const gradient = this._createGradientNode(strokeStyle);
24848
- this._defs.children.push(gradient);
25164
+ this._addNode(gradient, this._defs);
24849
25165
  currentElement.attrs.fill = `url(#${gradient.attrs.id})`;
24850
25166
  } else if (strokeStyle.startsWith("rgba")) {
24851
- const color = parseRGBAColor(strokeStyle);
25167
+ const color = parseRgbaColor(strokeStyle);
24852
25168
  currentElement.attrs.stroke = `rgb(${color.r}, ${color.g}, ${color.b})`;
24853
25169
  currentElement.attrs["stroke-opacity"] = `${(color.a ?? 1) * globalAlpha}`;
24854
25170
  } else {
@@ -24872,26 +25188,26 @@ var SvgCanvasContext = class {
24872
25188
  }
24873
25189
  }
24874
25190
  _addPathCommand(command) {
24875
- if (this._currentElement) {
24876
- if (this._currentElement.attrs.d) {
24877
- if (command === "Z" && this._currentElement.attrs.d.endsWith("Z")) {
24878
- return;
24879
- }
24880
- this._currentElement.attrs.d += ` ${command}`;
24881
- } else {
24882
- this._currentElement.attrs.d = command;
24883
- this._currentGroup.children.push(this._currentElement);
25191
+ if (!this._currentElement || !isSvgPath(this._currentElement)) {
25192
+ throw new Error("Current element is not a valid SVG path");
25193
+ }
25194
+ if (this._currentElement.attrs.d) {
25195
+ if (command === "Z" && this._currentElement.attrs.d.endsWith("Z")) {
25196
+ return;
24884
25197
  }
25198
+ this._currentElement.attrs.d += ` ${command}`;
25199
+ } else {
25200
+ this._currentElement.attrs.d = command;
25201
+ this._addNode(this._currentElement);
24885
25202
  }
24886
25203
  }
24887
25204
  _applyText(text, x, y, action) {
24888
- const parent = this._currentGroup;
24889
25205
  const style = parseFontStyle(this._currentStyle.font);
24890
25206
  const textElement = {
24891
25207
  tag: "text",
24892
25208
  attrs: {
24893
- x: `${x}`,
24894
- y: `${y}`,
25209
+ x,
25210
+ y,
24895
25211
  "font-family": style.fontFamilies.join(", "),
24896
25212
  "font-size": style.fontSize,
24897
25213
  "font-style": style.fontStyle,
@@ -24901,17 +25217,18 @@ var SvgCanvasContext = class {
24901
25217
  this._currentStyle.textBaseline
24902
25218
  )
24903
25219
  },
24904
- text
25220
+ children: [text]
24905
25221
  };
24906
25222
  this._applyTransformation(textElement);
24907
25223
  this._applyStyle(textElement, action);
24908
- parent.children.push(textElement);
25224
+ this._addNode(textElement);
24909
25225
  }
24910
25226
  _clearCanvas() {
24911
25227
  this._defs.children = [];
24912
25228
  this._root.children = [this._defs];
24913
25229
  this._currentGroup = this._root;
24914
25230
  this._groupStack = [];
25231
+ this._parents.clear();
24915
25232
  }
24916
25233
  };
24917
25234
  async function createSvgContext(width, height) {
@@ -24928,10 +25245,13 @@ async function toSvgNode(ctx) {
24928
25245
  }
24929
25246
  return ctx.getNode();
24930
25247
  }
25248
+ async function toSvgString(ctx) {
25249
+ return renderSvgNode(await toSvgNode(ctx));
25250
+ }
24931
25251
 
24932
25252
  // src/lib/PDFPageProxy.ts
24933
25253
  async function loadNodeCanvasFactory() {
24934
- const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeCanvasFactory-N32SOXPQ.js");
25254
+ const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeCanvasFactory-YRBSQ5MH.js");
24935
25255
  return new NodeCanvasFactory2({});
24936
25256
  }
24937
25257
  var getAnnotations = PDFPageProxy.prototype.getAnnotations;
@@ -24975,13 +25295,8 @@ PDFPageProxy.prototype.getAnnotations = async function(params) {
24975
25295
  annotation.graphics = {
24976
25296
  tag: "svg",
24977
25297
  attrs: {
24978
- version: "1.1",
24979
- xmlns: "http://www.w3.org/2000/svg",
24980
- width: `${width}`,
24981
- height: `${height}`,
24982
- viewBox: `0 0 ${width * scale} ${height * scale}`,
24983
- preserveAspectRatio: "none",
24984
- "xml:space": "preserve"
25298
+ width,
25299
+ height
24985
25300
  },
24986
25301
  children: [
24987
25302
  {
@@ -25268,6 +25583,43 @@ function isRedactAnnotation(annotation) {
25268
25583
  return annotation.subtype === "Redact";
25269
25584
  }
25270
25585
 
25586
+ // src/lib/CanvasGraphics.ts
25587
+ var {
25588
+ beginDrawing,
25589
+ beginMarkedContent,
25590
+ beginMarkedContentProps,
25591
+ endMarkedContent
25592
+ } = CanvasGraphics.prototype;
25593
+ CanvasGraphics.prototype.beginDrawing = function(options) {
25594
+ if (this.ctx instanceof SvgCanvasContext) {
25595
+ options.transparency = false;
25596
+ }
25597
+ return beginDrawing.call(this, options);
25598
+ };
25599
+ CanvasGraphics.prototype.beginMarkedContent = function(type) {
25600
+ beginMarkedContent.call(this, this.ctx);
25601
+ if (this.ctx instanceof SvgCanvasContext) {
25602
+ this.ctx.beginMarkedContent(type);
25603
+ }
25604
+ };
25605
+ CanvasGraphics.prototype.beginMarkedContentProps = function(type, props) {
25606
+ beginMarkedContentProps.call(this, type, props);
25607
+ if (this.ctx instanceof SvgCanvasContext) {
25608
+ this.ctx.beginMarkedContent(type, props);
25609
+ }
25610
+ };
25611
+ CanvasGraphics.prototype.endMarkedContent = function() {
25612
+ if (this.ctx instanceof SvgCanvasContext) {
25613
+ this.ctx.endMarkedContent();
25614
+ }
25615
+ endMarkedContent.call(this);
25616
+ };
25617
+ Object.assign(CanvasGraphics.prototype, {
25618
+ [OPS.beginMarkedContent]: CanvasGraphics.prototype.beginMarkedContent,
25619
+ [OPS.beginMarkedContentProps]: CanvasGraphics.prototype.beginMarkedContentProps,
25620
+ [OPS.endMarkedContent]: CanvasGraphics.prototype.endMarkedContent
25621
+ });
25622
+
25271
25623
  // src/lib/TextLayer.ts
25272
25624
  function isTextNode(node) {
25273
25625
  return node.role === "text";
@@ -25275,8 +25627,8 @@ function isTextNode(node) {
25275
25627
  function isAnchorNode(node) {
25276
25628
  return node.role === "a";
25277
25629
  }
25278
- function isImageNode(node) {
25279
- return node.role === "img";
25630
+ function isFigureNode(node) {
25631
+ return node.role === "figure";
25280
25632
  }
25281
25633
  var MAX_TEXT_DIVS_TO_RENDER2 = 1e5;
25282
25634
  var DEFAULT_FONT_SIZE3 = 30;
@@ -25286,17 +25638,15 @@ async function createTextLayer(page, {
25286
25638
  canvasFactory,
25287
25639
  viewport = page.getViewport({ scale: 1 }),
25288
25640
  outputScale = 1,
25289
- annotations
25641
+ annotations,
25642
+ graphics
25290
25643
  }) {
25291
- const objs = page.objs;
25292
- const commonObjs = page.commonObjs;
25293
25644
  const styleCache = {};
25294
25645
  const ascentCache = /* @__PURE__ */ new Map();
25295
25646
  const canvasCache = /* @__PURE__ */ new Map();
25296
25647
  const textDivs = [];
25297
25648
  const markedContent = /* @__PURE__ */ new Map();
25298
- const [operatorList, tree, contentSource] = await Promise.all([
25299
- page.getOperatorList(),
25649
+ const [tree, contentSource] = await Promise.all([
25300
25650
  page.getStructTree(),
25301
25651
  page.getTextContent({ includeMarkedContent: true })
25302
25652
  ]);
@@ -25317,13 +25667,6 @@ async function createTextLayer(page, {
25317
25667
  let disableProcessItems = false;
25318
25668
  let canvasContext = null;
25319
25669
  let container = rootContainer;
25320
- const getObject = (data) => {
25321
- try {
25322
- return data.startsWith("g_") ? commonObjs.get(data) : objs.get(data);
25323
- } catch {
25324
- return null;
25325
- }
25326
- };
25327
25670
  const processItems = async (items, lang) => {
25328
25671
  if (disableProcessItems) {
25329
25672
  return;
@@ -25508,7 +25851,7 @@ async function createTextLayer(page, {
25508
25851
  ascentCache.set(fontFamily, ratio);
25509
25852
  return ratio;
25510
25853
  };
25511
- const renderStructTreeNode = async (node, parent) => {
25854
+ const renderStructTreeNode = (node, parent) => {
25512
25855
  if ("role" in node) {
25513
25856
  const role = node.role.toLowerCase();
25514
25857
  switch (role) {
@@ -25518,17 +25861,17 @@ async function createTextLayer(page, {
25518
25861
  children: []
25519
25862
  };
25520
25863
  parent.children.push(section);
25521
- await Promise.all(
25522
- node.children.map((child) => renderStructTreeNode(child, section))
25523
- );
25864
+ for (const child of [...node.children]) {
25865
+ renderStructTreeNode(child, section);
25866
+ }
25524
25867
  break;
25525
25868
  }
25526
25869
  case "lbl":
25527
25870
  case "lbody":
25528
25871
  case "span": {
25529
- await Promise.all(
25530
- node.children.map((child) => renderStructTreeNode(child, parent))
25531
- );
25872
+ for (const child of [...node.children]) {
25873
+ renderStructTreeNode(child, parent);
25874
+ }
25532
25875
  break;
25533
25876
  }
25534
25877
  case "link": {
@@ -25537,9 +25880,9 @@ async function createTextLayer(page, {
25537
25880
  console.warn(
25538
25881
  `Unsupported link type: ${ref.type}`
25539
25882
  );
25540
- await Promise.all(
25541
- node.children.map((child) => renderStructTreeNode(child, parent))
25542
- );
25883
+ for (const child of children) {
25884
+ renderStructTreeNode(child, parent);
25885
+ }
25543
25886
  return;
25544
25887
  }
25545
25888
  const annotation = annotations?.find(
@@ -25547,9 +25890,9 @@ async function createTextLayer(page, {
25547
25890
  );
25548
25891
  if (!annotation) {
25549
25892
  console.warn("Link not found", ref);
25550
- await Promise.all(
25551
- children.map((child) => renderStructTreeNode(child, parent))
25552
- );
25893
+ for (const child of children) {
25894
+ renderStructTreeNode(child, parent);
25895
+ }
25553
25896
  return;
25554
25897
  }
25555
25898
  if (isLinkAnnotation(annotation)) {
@@ -25559,16 +25902,16 @@ async function createTextLayer(page, {
25559
25902
  children: []
25560
25903
  };
25561
25904
  parent.children.push(anchor);
25562
- await Promise.all(
25563
- children.map((child) => renderStructTreeNode(child, anchor))
25564
- );
25905
+ for (const child of children) {
25906
+ renderStructTreeNode(child, anchor);
25907
+ }
25565
25908
  } else {
25566
25909
  console.warn(
25567
25910
  `Unsupported annotation subtype: ${annotation.subtype}`
25568
25911
  );
25569
- await Promise.all(
25570
- children.map((child) => renderStructTreeNode(child, parent))
25571
- );
25912
+ for (const child of children) {
25913
+ renderStructTreeNode(child, parent);
25914
+ }
25572
25915
  }
25573
25916
  break;
25574
25917
  }
@@ -25577,7 +25920,7 @@ async function createTextLayer(page, {
25577
25920
  break;
25578
25921
  }
25579
25922
  if (node.children.length === 1 && node.children[0].role === "Table") {
25580
- await renderStructTreeNode(node.children[0], parent);
25923
+ renderStructTreeNode(node.children[0], parent);
25581
25924
  break;
25582
25925
  }
25583
25926
  const paragraph = {
@@ -25585,11 +25928,9 @@ async function createTextLayer(page, {
25585
25928
  children: []
25586
25929
  };
25587
25930
  parent.children.push(paragraph);
25588
- await Promise.all(
25589
- node.children.map(
25590
- (child) => renderStructTreeNode(child, paragraph)
25591
- )
25592
- );
25931
+ for (const child of [...node.children]) {
25932
+ renderStructTreeNode(child, paragraph);
25933
+ }
25593
25934
  break;
25594
25935
  }
25595
25936
  case "l": {
@@ -25598,9 +25939,9 @@ async function createTextLayer(page, {
25598
25939
  children: []
25599
25940
  };
25600
25941
  parent.children.push(list);
25601
- await Promise.all(
25602
- node.children.map((child) => renderStructTreeNode(child, list))
25603
- );
25942
+ for (const child of [...node.children]) {
25943
+ renderStructTreeNode(child, list);
25944
+ }
25604
25945
  break;
25605
25946
  }
25606
25947
  case "table":
@@ -25619,71 +25960,50 @@ async function createTextLayer(page, {
25619
25960
  children: []
25620
25961
  };
25621
25962
  parent.children.push(block);
25622
- await Promise.all(
25623
- node.children.map((child) => renderStructTreeNode(child, block))
25624
- );
25963
+ for (const child of [...node.children]) {
25964
+ renderStructTreeNode(child, block);
25965
+ }
25625
25966
  break;
25626
25967
  }
25627
25968
  case "figure": {
25628
- await Promise.all(
25629
- node.children.map(async (child) => {
25630
- if (child.type === "content" && child.id) {
25631
- const [, id] = child.id.split("_mc");
25632
- if (!id) {
25633
- return;
25634
- }
25635
- await Promise.all(
25636
- getMarkedObjects(id).map(async (imageId) => {
25637
- const imgData = getObject(imageId);
25638
- if (!imgData?.bitmap && !imgData?.data) {
25639
- return;
25640
- }
25641
- const canvasAndContext = await canvasFactory.create(
25642
- imgData.width,
25643
- imgData.height
25644
- );
25645
- if (imgData.bitmap) {
25646
- canvasAndContext.context.drawImage(imgData.bitmap, 0, 0);
25647
- } else if (imgData.data) {
25648
- if (imgData.kind === ImageKind.RGB_24BPP) {
25649
- const rgbaArray = new Uint8ClampedArray(
25650
- imgData.width * imgData.height * 4
25651
- );
25652
- for (let i = 0, j = 0; i < imgData.data.length; i += 3, j += 4) {
25653
- rgbaArray[j] = imgData.data[i];
25654
- rgbaArray[j + 1] = imgData.data[i + 1];
25655
- rgbaArray[j + 2] = imgData.data[i + 2];
25656
- rgbaArray[j + 3] = 255;
25657
- }
25658
- const imageData = new ImageData(
25659
- rgbaArray,
25660
- imgData.width,
25661
- imgData.height
25662
- );
25663
- canvasAndContext.context.putImageData(imageData, 0, 0);
25664
- } else {
25665
- const imageData = new ImageData(
25666
- imgData.data,
25667
- imgData.width,
25668
- imgData.height
25669
- );
25670
- canvasAndContext.context.putImageData(imageData, 0, 0);
25671
- }
25672
- }
25673
- const imgSrc = await toDataUrl(
25674
- await canvasToData(canvasAndContext.canvas)
25675
- );
25676
- canvasFactory.destroy(canvasAndContext);
25677
- const img = {
25678
- role: "img",
25679
- src: imgSrc
25680
- };
25681
- parent.children.push(img);
25682
- })
25683
- );
25969
+ const ids = [...node.children].filter((child) => "id" in child).map((child) => {
25970
+ const span = markedContent.get(child.id);
25971
+ if (!span) {
25972
+ return child.id;
25973
+ }
25974
+ if (span.parent) {
25975
+ span.parent.children = span.parent.children.filter(
25976
+ (child2) => child2 !== span.node
25977
+ );
25978
+ }
25979
+ return child.id;
25980
+ });
25981
+ if (graphics) {
25982
+ for (const markedId of ids) {
25983
+ const [, figureId] = markedId.split("_mc");
25984
+ if (!figureId) {
25985
+ continue;
25684
25986
  }
25685
- })
25686
- );
25987
+ const useId = `#${id("marked_content" /* MarkedContent */, figureId, graphics.attrs.id)}`;
25988
+ const graphic = findSvgNode(
25989
+ graphics,
25990
+ (node2) => isSvgMarkedContent(node2) && node2.attrs.href === useId
25991
+ );
25992
+ if (!graphic) {
25993
+ continue;
25994
+ }
25995
+ const figure = {
25996
+ role: "figure",
25997
+ href: graphic.attrs.href,
25998
+ x: graphic.attrs.x || 0,
25999
+ y: graphic.attrs.y || 0,
26000
+ width: graphic.attrs.width || 0,
26001
+ height: graphic.attrs.height || 0,
26002
+ alt: node.alt
26003
+ };
26004
+ parent.children.push(figure);
26005
+ }
26006
+ }
25687
26007
  break;
25688
26008
  }
25689
26009
  default: {
@@ -25692,9 +26012,9 @@ async function createTextLayer(page, {
25692
26012
  children: []
25693
26013
  };
25694
26014
  parent.children.push(block);
25695
- await Promise.all(
25696
- node.children.map((child) => renderStructTreeNode(child, block))
25697
- );
26015
+ for (const child of [...node.children]) {
26016
+ renderStructTreeNode(child, block);
26017
+ }
25698
26018
  break;
25699
26019
  }
25700
26020
  }
@@ -25711,32 +26031,6 @@ async function createTextLayer(page, {
25711
26031
  parent.children.push(span.node);
25712
26032
  }
25713
26033
  };
25714
- const getMarkedObjects = (markedContentId) => {
25715
- const results = [];
25716
- let currentMarkedContent = null;
25717
- for (let i = 0; i < operatorList.fnArray.length; i++) {
25718
- const fnId = operatorList.fnArray[i];
25719
- const args = operatorList.argsArray[i];
25720
- if (fnId === OPS.endMarkedContent) {
25721
- if (currentMarkedContent === markedContentId) {
25722
- return results;
25723
- }
25724
- currentMarkedContent = null;
25725
- continue;
25726
- }
25727
- if (fnId === OPS.beginMarkedContentProps && args?.[0] === "Figure") {
25728
- currentMarkedContent = `${args[1]}`;
25729
- continue;
25730
- }
25731
- if (currentMarkedContent !== markedContentId) {
25732
- continue;
25733
- }
25734
- if (fnId === OPS.paintImageXObject) {
25735
- results.push(args[0]);
25736
- }
25737
- }
25738
- return results;
25739
- };
25740
26034
  await loadDefaultFonts();
25741
26035
  const reader = textContentSource.getReader();
25742
26036
  while (true) {
@@ -25748,9 +26042,11 @@ async function createTextLayer(page, {
25748
26042
  await processItems(value.items, value.lang);
25749
26043
  }
25750
26044
  const root = tree?.children[0]?.children[0];
25751
- await Promise.all(
25752
- root?.children.map((child) => renderStructTreeNode(child, rootContainer)) ?? []
25753
- );
26045
+ if (root?.children) {
26046
+ for (const child of root.children) {
26047
+ renderStructTreeNode(child, rootContainer);
26048
+ }
26049
+ }
25754
26050
  ascentCache.clear();
25755
26051
  for (const canvasAndContext of canvasCache.values()) {
25756
26052
  canvasFactory.destroy(canvasAndContext);
@@ -25815,10 +26111,10 @@ export {
25815
26111
  isChoiceWidgetAnnotation,
25816
26112
  isCircleAnnotation,
25817
26113
  isDataScheme,
26114
+ isFigureNode,
25818
26115
  isFileAttachmentAnnotation,
25819
26116
  isFreeTextAnnotation,
25820
26117
  isHighlightAnnotation,
25821
- isImageNode,
25822
26118
  isInkAnnotation,
25823
26119
  isLineAnnotation,
25824
26120
  isLinkAnnotation,
@@ -25836,7 +26132,10 @@ export {
25836
26132
  isStampAnnotation,
25837
26133
  isStrikeOutAnnotation,
25838
26134
  isSvgElement,
25839
- isSvgText,
26135
+ isSvgImage,
26136
+ isSvgMarkedContent,
26137
+ isSvgPath,
26138
+ isSvgRoot,
25840
26139
  isTextAnnotation,
25841
26140
  isTextNode,
25842
26141
  isTextWidgetAnnotation,
@@ -25850,12 +26149,14 @@ export {
25850
26149
  makeSerializable,
25851
26150
  noContextMenu,
25852
26151
  normalizeUnicode,
26152
+ parseRgbaColor,
25853
26153
  rgbToHex,
25854
26154
  setLayerDimensions,
25855
26155
  shadow,
25856
26156
  stopEvent,
25857
26157
  toDataUrl,
25858
26158
  toSvgNode,
26159
+ toSvgString,
25859
26160
  updateUrlHash,
25860
26161
  version
25861
26162
  };