@chialab/pdfjs-lib 1.0.0-alpha.33 → 1.0.0-alpha.35

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;
@@ -42418,6 +42430,7 @@ async function createTextLayerV2(page, {
42418
42430
  }
42419
42431
  chunks.push({
42420
42432
  text,
42433
+ width: textWidth,
42421
42434
  margin: margin * finalFontSize,
42422
42435
  scale: graphicWidth / textWidth
42423
42436
  });
@@ -42760,6 +42773,7 @@ export {
42760
42773
  noContextMenu,
42761
42774
  normalizeUnicode,
42762
42775
  parseRgbaColor,
42776
+ randomUUID,
42763
42777
  renderRichText,
42764
42778
  renderSvgNode,
42765
42779
  renderTextLayer,
@@ -22,6 +22,7 @@ export interface TextLayerAnchor extends TextLayerElement {
22
22
  }
23
23
  export interface TextLayerChunk {
24
24
  text: string;
25
+ width: number;
25
26
  margin: number;
26
27
  scale?: number;
27
28
  }
@@ -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;
@@ -41071,6 +41072,7 @@ async function createTextLayerV2(page, {
41071
41072
  }
41072
41073
  chunks.push({
41073
41074
  text,
41075
+ width: textWidth,
41074
41076
  margin: margin * finalFontSize,
41075
41077
  scale: graphicWidth / textWidth
41076
41078
  });
@@ -41413,6 +41415,7 @@ export {
41413
41415
  noContextMenu,
41414
41416
  normalizeUnicode,
41415
41417
  parseRgbaColor,
41418
+ randomUUID,
41416
41419
  renderRichText,
41417
41420
  renderSvgNode,
41418
41421
  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.33",
4
+ "version": "1.0.0-alpha.35",
5
5
  "type": "module",
6
6
  "author": "Chialab <dev@chialab.it>",
7
7
  "license": "MIT",