@chialab/pdfjs-lib 1.0.0-alpha.32 → 1.0.0-alpha.34

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.
@@ -27502,6 +27502,86 @@ var AnnotationOperatorsList = class {
27502
27502
  }
27503
27503
  };
27504
27504
 
27505
+ // src/lib/utils.ts
27506
+ async function canvasToData(canvas) {
27507
+ if ("toBlob" in canvas) {
27508
+ const blob = await new Promise(
27509
+ (resolve) => canvas.toBlob((data) => resolve(data))
27510
+ );
27511
+ if (!blob) {
27512
+ throw new Error("Failed to generate graphics");
27513
+ }
27514
+ return new Uint8Array(await blob.arrayBuffer());
27515
+ }
27516
+ const buffer = await canvas.toBuffer("png");
27517
+ return new Uint8Array(buffer);
27518
+ }
27519
+ async function toDataUrl(data, type = "image/png") {
27520
+ if (typeof FileReader !== "undefined") {
27521
+ return new Promise((resolve) => {
27522
+ const reader = new FileReader();
27523
+ reader.onload = () => {
27524
+ resolve(reader.result);
27525
+ };
27526
+ reader.readAsDataURL(new Blob([data], { type }));
27527
+ });
27528
+ }
27529
+ return `data:${type};base64,${Buffer.from(data).toString("base64")}`;
27530
+ }
27531
+ function colorToRgb(color) {
27532
+ if (color.startsWith("#")) {
27533
+ const hex = color.slice(1);
27534
+ if (hex.length === 3) {
27535
+ return [
27536
+ Number.parseInt(hex[0] + hex[0], 16),
27537
+ Number.parseInt(hex[1] + hex[1], 16),
27538
+ Number.parseInt(hex[2] + hex[2], 16)
27539
+ ];
27540
+ }
27541
+ if (hex.length === 6) {
27542
+ return [
27543
+ Number.parseInt(hex.slice(0, 2), 16),
27544
+ Number.parseInt(hex.slice(2, 4), 16),
27545
+ Number.parseInt(hex.slice(4, 6), 16)
27546
+ ];
27547
+ }
27548
+ }
27549
+ throw new Error(`Invalid color format: ${color}`);
27550
+ }
27551
+ function rgbToHex(r, g, b) {
27552
+ const toHex = (value) => value.toString(16).padStart(2, "0");
27553
+ if (Array.isArray(r)) {
27554
+ return `#${toHex(r[0])}${toHex(r[1])}${toHex(r[2])}`;
27555
+ }
27556
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
27557
+ }
27558
+ function parseRgbaColor(color) {
27559
+ const match = color.match(
27560
+ /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/
27561
+ );
27562
+ if (!match) {
27563
+ return { r: 0, g: 0, b: 0, a: 1 };
27564
+ }
27565
+ return {
27566
+ r: Number.parseInt(match[1], 10),
27567
+ g: Number.parseInt(match[2], 10),
27568
+ b: Number.parseInt(match[3], 10),
27569
+ a: match[4] ? Number.parseFloat(match[4]) : 1
27570
+ };
27571
+ }
27572
+ function randomUUID() {
27573
+ if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
27574
+ return crypto.randomUUID();
27575
+ }
27576
+ const hex = [...Array(36)].map(
27577
+ () => Math.floor(Math.random() * 16).toString(16)
27578
+ );
27579
+ hex[14] = "4";
27580
+ hex[19] = (Number.parseInt(hex[19], 16) & 3 | 8).toString(16);
27581
+ hex[8] = hex[13] = hex[18] = hex[23] = "-";
27582
+ return hex.join("");
27583
+ }
27584
+
27505
27585
  // src/lib/Svg.ts
27506
27586
  function isSvgElement(node) {
27507
27587
  return "children" in node;
@@ -27519,7 +27599,7 @@ function isSvgRoot(node) {
27519
27599
  return node.tag === "svg";
27520
27600
  }
27521
27601
  function id(type, id2 = null, scope) {
27522
- return [type, scope, id2 ?? crypto.randomUUID()].filter(Boolean).join("_");
27602
+ return [type, scope, id2 ?? randomUUID()].filter(Boolean).join("_");
27523
27603
  }
27524
27604
  function findSvgNode(root, matcher) {
27525
27605
  for (const child of root.children) {
@@ -27832,74 +27912,6 @@ function renderSvgNode(node) {
27832
27912
  return `<${node.tag}${renderAttributes(node.attrs)} />`;
27833
27913
  }
27834
27914
 
27835
- // src/lib/utils.ts
27836
- async function canvasToData(canvas) {
27837
- if ("toBlob" in canvas) {
27838
- const blob = await new Promise(
27839
- (resolve) => canvas.toBlob((data) => resolve(data))
27840
- );
27841
- if (!blob) {
27842
- throw new Error("Failed to generate graphics");
27843
- }
27844
- return new Uint8Array(await blob.arrayBuffer());
27845
- }
27846
- const buffer = await canvas.toBuffer("png");
27847
- return new Uint8Array(buffer);
27848
- }
27849
- async function toDataUrl(data, type = "image/png") {
27850
- if (typeof FileReader !== "undefined") {
27851
- return new Promise((resolve) => {
27852
- const reader = new FileReader();
27853
- reader.onload = () => {
27854
- resolve(reader.result);
27855
- };
27856
- reader.readAsDataURL(new Blob([data], { type }));
27857
- });
27858
- }
27859
- return `data:${type};base64,${Buffer.from(data).toString("base64")}`;
27860
- }
27861
- function colorToRgb(color) {
27862
- if (color.startsWith("#")) {
27863
- const hex = color.slice(1);
27864
- if (hex.length === 3) {
27865
- return [
27866
- Number.parseInt(hex[0] + hex[0], 16),
27867
- Number.parseInt(hex[1] + hex[1], 16),
27868
- Number.parseInt(hex[2] + hex[2], 16)
27869
- ];
27870
- }
27871
- if (hex.length === 6) {
27872
- return [
27873
- Number.parseInt(hex.slice(0, 2), 16),
27874
- Number.parseInt(hex.slice(2, 4), 16),
27875
- Number.parseInt(hex.slice(4, 6), 16)
27876
- ];
27877
- }
27878
- }
27879
- throw new Error(`Invalid color format: ${color}`);
27880
- }
27881
- function rgbToHex(r, g, b) {
27882
- const toHex = (value) => value.toString(16).padStart(2, "0");
27883
- if (Array.isArray(r)) {
27884
- return `#${toHex(r[0])}${toHex(r[1])}${toHex(r[2])}`;
27885
- }
27886
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
27887
- }
27888
- function parseRgbaColor(color) {
27889
- const match = color.match(
27890
- /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/
27891
- );
27892
- if (!match) {
27893
- return { r: 0, g: 0, b: 0, a: 1 };
27894
- }
27895
- return {
27896
- r: Number.parseInt(match[1], 10),
27897
- g: Number.parseInt(match[2], 10),
27898
- b: Number.parseInt(match[3], 10),
27899
- a: match[4] ? Number.parseFloat(match[4]) : 1
27900
- };
27901
- }
27902
-
27903
27915
  // src/lib/SvgCanvasContext.ts
27904
27916
  function isCanvas(img) {
27905
27917
  return "toDataURL" in img;
@@ -42638,12 +42650,14 @@ async function createTextLayerV2(page, {
42638
42650
  }
42639
42651
  }
42640
42652
  closeTextItem();
42641
- decorateStructTree(
42642
- structTree,
42643
- rootContainer,
42644
- graphics,
42645
- annotations
42646
- );
42653
+ if (structTree) {
42654
+ decorateStructTree(
42655
+ structTree,
42656
+ rootContainer,
42657
+ graphics,
42658
+ annotations
42659
+ );
42660
+ }
42647
42661
  return rootContainer;
42648
42662
  }
42649
42663
 
@@ -42758,6 +42772,7 @@ export {
42758
42772
  noContextMenu,
42759
42773
  normalizeUnicode,
42760
42774
  parseRgbaColor,
42775
+ randomUUID,
42761
42776
  renderRichText,
42762
42777
  renderSvgNode,
42763
42778
  renderTextLayer,
@@ -30,3 +30,4 @@ export declare function parseRgbaColor(color: string): {
30
30
  b: number;
31
31
  a: number;
32
32
  };
33
+ export declare function randomUUID(): string;
@@ -6,7 +6,7 @@ import {
6
6
  NodeWasmFactory,
7
7
  fetchData2 as fetchData,
8
8
  filtersRegistry
9
- } from "./chunk-R66TN6BM.js";
9
+ } from "./chunk-FUWEGVHM.js";
10
10
  import "./chunk-T2JWSGAF.js";
11
11
  import "./chunk-ZFIGV5OT.js";
12
12
  export {
@@ -1676,6 +1676,18 @@ function parseRgbaColor(color) {
1676
1676
  a: match[4] ? Number.parseFloat(match[4]) : 1
1677
1677
  };
1678
1678
  }
1679
+ function randomUUID() {
1680
+ if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
1681
+ return crypto.randomUUID();
1682
+ }
1683
+ const hex = [...Array(36)].map(
1684
+ () => Math.floor(Math.random() * 16).toString(16)
1685
+ );
1686
+ hex[14] = "4";
1687
+ hex[19] = (Number.parseInt(hex[19], 16) & 3 | 8).toString(16);
1688
+ hex[8] = hex[13] = hex[18] = hex[23] = "-";
1689
+ return hex.join("");
1690
+ }
1679
1691
 
1680
1692
  // src/lib/NodeFilterFactory.ts
1681
1693
  var filtersRegistry = /* @__PURE__ */ new Map();
@@ -2062,6 +2074,7 @@ export {
2062
2074
  colorToRgb,
2063
2075
  rgbToHex,
2064
2076
  parseRgbaColor,
2077
+ randomUUID,
2065
2078
  filtersRegistry,
2066
2079
  NodeFilterFactory,
2067
2080
  NodeCanvasFactory,
@@ -48,12 +48,13 @@ import {
48
48
  isValidFetchUrl,
49
49
  noContextMenu,
50
50
  parseRgbaColor,
51
+ randomUUID,
51
52
  renderRichText,
52
53
  rgbToHex,
53
54
  setLayerDimensions,
54
55
  stopEvent,
55
56
  toDataUrl
56
- } from "./chunk-R66TN6BM.js";
57
+ } from "./chunk-FUWEGVHM.js";
57
58
  import {
58
59
  AbortException,
59
60
  AnnotationBorderStyleType,
@@ -38486,7 +38487,7 @@ function isSvgRoot(node) {
38486
38487
  return node.tag === "svg";
38487
38488
  }
38488
38489
  function id(type, id2 = null, scope) {
38489
- return [type, scope, id2 ?? crypto.randomUUID()].filter(Boolean).join("_");
38490
+ return [type, scope, id2 ?? randomUUID()].filter(Boolean).join("_");
38490
38491
  }
38491
38492
  function findSvgNode(root, matcher) {
38492
38493
  for (const child of root.children) {
@@ -39833,7 +39834,7 @@ function destroySvgContext(ctx) {
39833
39834
 
39834
39835
  // src/lib/PDFPageProxy.ts
39835
39836
  async function loadNodeCanvasFactory() {
39836
- const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtils-SRP3N4DX.js");
39837
+ const { NodeCanvasFactory: NodeCanvasFactory2 } = await import("./NodeUtils-WMSRRHQR.js");
39837
39838
  return new NodeCanvasFactory2({});
39838
39839
  }
39839
39840
  var getAnnotations = PDFPageProxy.prototype.getAnnotations;
@@ -41291,12 +41292,14 @@ async function createTextLayerV2(page, {
41291
41292
  }
41292
41293
  }
41293
41294
  closeTextItem();
41294
- decorateStructTree(
41295
- structTree,
41296
- rootContainer,
41297
- graphics,
41298
- annotations
41299
- );
41295
+ if (structTree) {
41296
+ decorateStructTree(
41297
+ structTree,
41298
+ rootContainer,
41299
+ graphics,
41300
+ annotations
41301
+ );
41302
+ }
41300
41303
  return rootContainer;
41301
41304
  }
41302
41305
 
@@ -41411,6 +41414,7 @@ export {
41411
41414
  noContextMenu,
41412
41415
  normalizeUnicode,
41413
41416
  parseRgbaColor,
41417
+ randomUUID,
41414
41418
  renderRichText,
41415
41419
  renderSvgNode,
41416
41420
  renderTextLayer,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chialab/pdfjs-lib",
3
3
  "description": "A custom Mozilla's PDF.js build with better Node support and extras.",
4
- "version": "1.0.0-alpha.32",
4
+ "version": "1.0.0-alpha.34",
5
5
  "type": "module",
6
6
  "author": "Chialab <dev@chialab.it>",
7
7
  "license": "MIT",