web-annotation-renderer 0.6.0 → 0.6.2
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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -51
- package/dist/index.js.map +1 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.cjs.map +1 -1
- package/dist/index10.js +13 -210
- package/dist/index10.js.map +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.cjs.map +1 -1
- package/dist/index11.js +50 -13
- package/dist/index11.js.map +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.cjs.map +1 -1
- package/dist/index12.js +155 -48
- package/dist/index12.js.map +1 -1
- package/dist/index13.cjs +1 -1
- package/dist/index13.cjs.map +1 -1
- package/dist/index13.js +34 -169
- package/dist/index13.js.map +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.cjs.map +1 -1
- package/dist/index14.js +65 -28
- package/dist/index14.js.map +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.cjs.map +1 -1
- package/dist/index15.js +33 -71
- package/dist/index15.js.map +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.cjs.map +1 -1
- package/dist/index16.js +77 -22
- package/dist/index16.js.map +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.cjs.map +1 -1
- package/dist/index17.js +31 -52
- package/dist/index17.js.map +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.cjs.map +1 -1
- package/dist/index18.js +22 -23
- package/dist/index18.js.map +1 -1
- package/dist/index2.cjs +1 -1
- package/dist/index2.cjs.map +1 -1
- package/dist/index2.js +5 -6
- package/dist/index2.js.map +1 -1
- package/dist/index21.cjs +1 -1
- package/dist/index21.cjs.map +1 -1
- package/dist/index21.js +48 -27
- package/dist/index21.js.map +1 -1
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +1 -1
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +1 -1
- package/dist/index29.cjs +1 -1
- package/dist/index29.cjs.map +1 -1
- package/dist/index29.js +70 -4
- package/dist/index29.js.map +1 -1
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +1 -1
- package/dist/index30.cjs +2 -0
- package/dist/index30.cjs.map +1 -0
- package/dist/index30.js +8 -0
- package/dist/index30.js.map +1 -0
- package/dist/index31.cjs +2 -0
- package/dist/index31.cjs.map +1 -0
- package/dist/index31.js +995 -0
- package/dist/index31.js.map +1 -0
- package/dist/index5.cjs +1 -1
- package/dist/index5.cjs.map +1 -1
- package/dist/index5.js +189 -80
- package/dist/index5.js.map +1 -1
- package/dist/index6.cjs +1 -1
- package/dist/index6.cjs.map +1 -1
- package/dist/index6.js +18 -60
- package/dist/index6.js.map +1 -1
- package/dist/index7.cjs +1 -1
- package/dist/index7.cjs.map +1 -1
- package/dist/index7.js +17 -17
- package/dist/index7.js.map +1 -1
- package/dist/index8.cjs +1 -1
- package/dist/index8.cjs.map +1 -1
- package/dist/index8.js +125 -16
- package/dist/index8.js.map +1 -1
- package/dist/index9.cjs +1 -1
- package/dist/index9.cjs.map +1 -1
- package/dist/index9.js +201 -118
- package/dist/index9.js.map +1 -1
- package/package.json +4 -2
package/dist/index6.js
CHANGED
|
@@ -1,65 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const i = (h, t) => ({
|
|
2
|
+
left: h.x * t.width,
|
|
3
|
+
top: h.y * t.height,
|
|
4
|
+
width: (h.w ?? 0) * t.width,
|
|
5
|
+
height: (h.h ?? 0) * t.height
|
|
6
|
+
}), e = (h, t) => ({
|
|
7
|
+
left: h.x * t.width,
|
|
8
|
+
top: h.y * t.height,
|
|
9
|
+
width: (h.w ?? 0) * t.width,
|
|
10
|
+
height: (h.h ?? 0) * t.height
|
|
11
|
+
});
|
|
12
|
+
function o(h, t) {
|
|
13
|
+
return {
|
|
14
|
+
x: h.x * t.width,
|
|
15
|
+
y: h.y * t.height
|
|
9
16
|
};
|
|
10
17
|
}
|
|
11
|
-
function M(t, n, e = null) {
|
|
12
|
-
const { amplitude: r = 0 } = n || {};
|
|
13
|
-
if (r === 0 || !t || t.length === 0)
|
|
14
|
-
return t;
|
|
15
|
-
const u = s(e);
|
|
16
|
-
return t.map(([l, f]) => [
|
|
17
|
-
l + (u() - 0.5) * r,
|
|
18
|
-
f + (u() - 0.5) * r
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
function b(t, n) {
|
|
22
|
-
const { taperIn: e = 0, taperOut: r = 0 } = n || {};
|
|
23
|
-
if (!t || t.length === 0)
|
|
24
|
-
return [];
|
|
25
|
-
if (e === 0 && r === 0)
|
|
26
|
-
return t.map(() => 1);
|
|
27
|
-
const u = t.length;
|
|
28
|
-
return t.map((l, f) => {
|
|
29
|
-
const c = u > 1 ? f / (u - 1) : 0;
|
|
30
|
-
return e > 0 && c < e ? c / e : r > 0 && c > 1 - r ? (1 - c) / r : 1;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function A(t, n) {
|
|
34
|
-
const { amplitude: e = 0, frequency: r = 0.05 } = n || {};
|
|
35
|
-
return e === 0 || !t || t.length < 2 ? t : t.map(([u, l], f) => {
|
|
36
|
-
const c = f / (t.length - 1), h = Math.sin(c * Math.PI * 2 * r * t.length) * e;
|
|
37
|
-
let y = 0, d = 1;
|
|
38
|
-
if (f < t.length - 1) {
|
|
39
|
-
const [m, p] = t[f + 1], a = m - u, o = p - l, i = Math.sqrt(a * a + o * o);
|
|
40
|
-
i > 1e-4 && (y = -o / i, d = a / i);
|
|
41
|
-
}
|
|
42
|
-
return [
|
|
43
|
-
u + y * h,
|
|
44
|
-
l + d * h
|
|
45
|
-
];
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function g(t, n) {
|
|
49
|
-
if (!n) return { ...t };
|
|
50
|
-
if (!t) return { ...n };
|
|
51
|
-
const e = { ...t };
|
|
52
|
-
for (const r of Object.keys(n)) {
|
|
53
|
-
const u = n[r], l = t[r];
|
|
54
|
-
u !== null && typeof u == "object" && !Array.isArray(u) && l !== null && typeof l == "object" && !Array.isArray(l) ? e[r] = g(l, u) : u !== void 0 && (e[r] = u);
|
|
55
|
-
}
|
|
56
|
-
return e;
|
|
57
|
-
}
|
|
58
18
|
export {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
g as deepMerge,
|
|
63
|
-
s as seededRandom
|
|
19
|
+
e as NormSizeToPixel,
|
|
20
|
+
o as pointNormToAbs,
|
|
21
|
+
i as rectNormToAbs
|
|
64
22
|
};
|
|
65
23
|
//# sourceMappingURL=index6.js.map
|
package/dist/index6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index6.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index6.js","sources":["../src/utils/coordinateUtils.js"],"sourcesContent":["/**\n * Coordinate Utility Functions\n *\n * This module provides utility functions for coordinate transformations\n * between normalized (0-1) coordinates and absolute pixel coordinates.\n * Used by annotation layers to position elements on the PDF canvas.\n */\n\n/**\n * Convert normalized rectangle to absolute pixel coordinates\n *\n * Transforms a rectangle with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number, w: number, h: number}} rect - Normalized rectangle (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{left: number, top: number, width: number, height: number}} Absolute coordinates in pixels\n *\n * @example\n * const rect = { x: 0.1, y: 0.2, w: 0.5, h: 0.3 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = rectNormToAbs(rect, viewport);\n * // Returns: { left: 100, top: 280, width: 500, height: 420 }\n */\nexport const rectNormToAbs = (r, vp) => ({\n left: r.x * vp.width,\n top: r.y * vp.height,\n width: (r.w ?? 0) * vp.width,\n height: (r.h ?? 0) * vp.height,\n});\n\n/**\n * Convert normalized size to pixel dimensions (Legacy)\n *\n * @deprecated Use rectNormToAbs instead. This function is kept for backward compatibility.\n *\n * Transforms normalized rectangle coordinates to absolute pixel coordinates.\n * This is an alias for rectNormToAbs maintained for backward compatibility.\n *\n * @param {{x: number, y: number, w: number, h: number}} r - Normalized rectangle (0-1)\n * @param {{width: number, height: number}} vp - Viewport dimensions in pixels\n * @returns {{left: number, top: number, width: number, height: number}} Absolute coordinates in pixels\n */\nexport const NormSizeToPixel = (r, vp) => ({\n left: r.x * vp.width,\n top: r.y * vp.height,\n width: (r.w ?? 0) * vp.width,\n height: (r.h ?? 0) * vp.height,\n});\n\n/**\n * Convert normalized point to absolute pixel coordinates\n *\n * Transforms a point with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number}} point - Normalized point (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{x: number, y: number}} Absolute coordinates in pixels\n *\n * @example\n * const point = { x: 0.5, y: 0.5 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = pointNormToAbs(point, viewport);\n * // Returns: { x: 500, y: 700 }\n */\nexport function pointNormToAbs(point, viewport) {\n return {\n x: point.x * viewport.width,\n y: point.y * viewport.height\n };\n}\n"],"names":["rectNormToAbs","r","vp","NormSizeToPixel","pointNormToAbs","point","viewport"],"mappings":"AAwBY,MAACA,IAAgB,CAACC,GAAGC,OAAQ;AAAA,EACvC,MAAMD,EAAE,IAAIC,EAAG;AAAA,EACf,KAAKD,EAAE,IAAIC,EAAG;AAAA,EACd,QAAQD,EAAE,KAAK,KAAKC,EAAG;AAAA,EACvB,SAASD,EAAE,KAAK,KAAKC,EAAG;AAC1B,IAcaC,IAAkB,CAACF,GAAGC,OAAQ;AAAA,EACzC,MAAMD,EAAE,IAAIC,EAAG;AAAA,EACf,KAAKD,EAAE,IAAIC,EAAG;AAAA,EACd,QAAQD,EAAE,KAAK,KAAKC,EAAG;AAAA,EACvB,SAASD,EAAE,KAAK,KAAKC,EAAG;AAC1B;AAkBO,SAASE,EAAeC,GAAOC,GAAU;AAC9C,SAAO;AAAA,IACL,GAAGD,EAAM,IAAIC,EAAS;AAAA,IACtB,GAAGD,EAAM,IAAIC,EAAS;AAAA,EAC1B;AACA;"}
|
package/dist/index7.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(e,t){if(!e)throw new Error("Page object is required");return e.getViewport({scale:t})}function r(e){return e?{width:e.width,height:e.height}:{width:0,height:0}}function o(e,t,i){return{width:e*i,height:t*i}}exports.calculateScaledDimensions=o;exports.calculateViewport=n;exports.getViewportDimensions=r;
|
|
2
2
|
//# sourceMappingURL=index7.cjs.map
|
package/dist/index7.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.cjs","sources":["../src/utils/
|
|
1
|
+
{"version":3,"file":"index7.cjs","sources":["../src/utils/viewportUtils.js"],"sourcesContent":["/**\n * Viewport Utility Functions\n *\n * This module provides utility functions for PDF viewport calculations\n * and transformations. These functions are used by the PDF viewer to\n * calculate viewport dimensions and manage scaling.\n */\n\n/**\n * Calculate viewport from PDF page\n *\n * Creates a viewport object from a PDF.js page with the specified scale.\n * The viewport contains dimensions and transformation matrix for rendering.\n *\n * @param {Object} page - PDF.js page object\n * @param {number} scale - Scale factor for rendering\n * @returns {Object} Viewport object with width, height, and transform matrix\n *\n * @example\n * const viewport = calculateViewport(pdfPage, 1.5);\n * // Returns: { width: 1200, height: 1600, scale: 1.5, ... }\n */\nexport function calculateViewport(page, scale) {\n if (!page) {\n throw new Error('Page object is required');\n }\n\n return page.getViewport({ scale });\n}\n\n/**\n * Get viewport dimensions\n *\n * Extracts width and height from a viewport object.\n * Useful for coordinate transformations and layout calculations.\n *\n * @param {Object} viewport - Viewport object from PDF.js\n * @returns {{width: number, height: number}} Dimensions object\n *\n * @example\n * const { width, height } = getViewportDimensions(viewport);\n * // Returns: { width: 1200, height: 1600 }\n */\nexport function getViewportDimensions(viewport) {\n if (!viewport) {\n return { width: 0, height: 0 };\n }\n\n return {\n width: viewport.width,\n height: viewport.height\n };\n}\n\n/**\n * Calculate scaled dimensions\n *\n * Calculates dimensions for a given scale factor.\n * Used when zoom level changes to determine new canvas size.\n *\n * @param {number} baseWidth - Original width\n * @param {number} baseHeight - Original height\n * @param {number} scale - Scale factor\n * @returns {{width: number, height: number}} Scaled dimensions\n *\n * @example\n * const scaled = calculateScaledDimensions(800, 1000, 1.5);\n * // Returns: { width: 1200, height: 1500 }\n */\nexport function calculateScaledDimensions(baseWidth, baseHeight, scale) {\n return {\n width: baseWidth * scale,\n height: baseHeight * scale\n };\n}\n"],"names":["calculateViewport","page","scale","getViewportDimensions","viewport","calculateScaledDimensions","baseWidth","baseHeight"],"mappings":"gFAsBO,SAASA,EAAkBC,EAAMC,EAAO,CAC7C,GAAI,CAACD,EACH,MAAM,IAAI,MAAM,yBAAyB,EAG3C,OAAOA,EAAK,YAAY,CAAE,MAAAC,EAAO,CACnC,CAeO,SAASC,EAAsBC,EAAU,CAC9C,OAAKA,EAIE,CACL,MAAOA,EAAS,MAChB,OAAQA,EAAS,MACrB,EANW,CAAE,MAAO,EAAG,OAAQ,CAAC,CAOhC,CAiBO,SAASC,EAA0BC,EAAWC,EAAYL,EAAO,CACtE,MAAO,CACL,MAAOI,EAAYJ,EACnB,OAAQK,EAAaL,CACzB,CACA"}
|
package/dist/index7.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function
|
|
1
|
+
function r(t, e) {
|
|
2
|
+
if (!t)
|
|
3
|
+
throw new Error("Page object is required");
|
|
4
|
+
return t.getViewport({ scale: e });
|
|
5
|
+
}
|
|
6
|
+
function n(t) {
|
|
7
|
+
return t ? {
|
|
8
|
+
width: t.width,
|
|
9
|
+
height: t.height
|
|
10
|
+
} : { width: 0, height: 0 };
|
|
11
|
+
}
|
|
12
|
+
function h(t, e, i) {
|
|
13
13
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
width: t * i,
|
|
15
|
+
height: e * i
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
h as calculateScaledDimensions,
|
|
20
|
+
r as calculateViewport,
|
|
21
|
+
n as getViewportDimensions
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=index7.js.map
|
package/dist/index7.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.js","sources":["../src/utils/
|
|
1
|
+
{"version":3,"file":"index7.js","sources":["../src/utils/viewportUtils.js"],"sourcesContent":["/**\n * Viewport Utility Functions\n *\n * This module provides utility functions for PDF viewport calculations\n * and transformations. These functions are used by the PDF viewer to\n * calculate viewport dimensions and manage scaling.\n */\n\n/**\n * Calculate viewport from PDF page\n *\n * Creates a viewport object from a PDF.js page with the specified scale.\n * The viewport contains dimensions and transformation matrix for rendering.\n *\n * @param {Object} page - PDF.js page object\n * @param {number} scale - Scale factor for rendering\n * @returns {Object} Viewport object with width, height, and transform matrix\n *\n * @example\n * const viewport = calculateViewport(pdfPage, 1.5);\n * // Returns: { width: 1200, height: 1600, scale: 1.5, ... }\n */\nexport function calculateViewport(page, scale) {\n if (!page) {\n throw new Error('Page object is required');\n }\n\n return page.getViewport({ scale });\n}\n\n/**\n * Get viewport dimensions\n *\n * Extracts width and height from a viewport object.\n * Useful for coordinate transformations and layout calculations.\n *\n * @param {Object} viewport - Viewport object from PDF.js\n * @returns {{width: number, height: number}} Dimensions object\n *\n * @example\n * const { width, height } = getViewportDimensions(viewport);\n * // Returns: { width: 1200, height: 1600 }\n */\nexport function getViewportDimensions(viewport) {\n if (!viewport) {\n return { width: 0, height: 0 };\n }\n\n return {\n width: viewport.width,\n height: viewport.height\n };\n}\n\n/**\n * Calculate scaled dimensions\n *\n * Calculates dimensions for a given scale factor.\n * Used when zoom level changes to determine new canvas size.\n *\n * @param {number} baseWidth - Original width\n * @param {number} baseHeight - Original height\n * @param {number} scale - Scale factor\n * @returns {{width: number, height: number}} Scaled dimensions\n *\n * @example\n * const scaled = calculateScaledDimensions(800, 1000, 1.5);\n * // Returns: { width: 1200, height: 1500 }\n */\nexport function calculateScaledDimensions(baseWidth, baseHeight, scale) {\n return {\n width: baseWidth * scale,\n height: baseHeight * scale\n };\n}\n"],"names":["calculateViewport","page","scale","getViewportDimensions","viewport","calculateScaledDimensions","baseWidth","baseHeight"],"mappings":"AAsBO,SAASA,EAAkBC,GAAMC,GAAO;AAC7C,MAAI,CAACD;AACH,UAAM,IAAI,MAAM,yBAAyB;AAG3C,SAAOA,EAAK,YAAY,EAAE,OAAAC,GAAO;AACnC;AAeO,SAASC,EAAsBC,GAAU;AAC9C,SAAKA,IAIE;AAAA,IACL,OAAOA,EAAS;AAAA,IAChB,QAAQA,EAAS;AAAA,EACrB,IANW,EAAE,OAAO,GAAG,QAAQ,EAAC;AAOhC;AAiBO,SAASC,EAA0BC,GAAWC,GAAYL,GAAO;AACtE,SAAO;AAAA,IACL,OAAOI,IAAYJ;AAAA,IACnB,QAAQK,IAAaL;AAAA,EACzB;AACA;"}
|
package/dist/index8.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("pdfjs-dist");function O(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const M=O(j);async function I(e){try{const t=await e.getTextContent(),n=e.getViewport({scale:1}),o=n.width,a=n.height,i=[];for(const s of t.items){if(!s.str||!s.str.trim())continue;const r=s.transform,g=Math.sqrt(r[2]*r[2]+r[3]*r[3]),h=r[4],c=n.height-r[5],u=s.width,l=s.height||g,p=h,x=c-l,f=h+u,m=c,b=[Math.max(0,Math.min(1,p/o)),Math.max(0,Math.min(1,x/a)),Math.max(0,Math.min(1,f/o)),Math.max(0,Math.min(1,m/a))];i.push({type:"text",text:s.str,bbox_norm:b,font:s.fontName||"unknown",fontSize:g,source:"pdfjs"})}return i}catch(t){return console.error("Error extracting text blocks:",t),[]}}function X(e,t,n){const o=e[4],a=e[5],i=e[0],s=e[3],r=Math.abs(i),g=Math.abs(s),h=n-a-g,c=n-a,u=o,l=o+r;return[Math.max(0,Math.min(1,u/t)),Math.max(0,Math.min(1,h/n)),Math.max(0,Math.min(1,l/t)),Math.max(0,Math.min(1,c/n))]}function B(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function P(e,t){return{[t.paintImageXObject]:"paintImageXObject",[t.paintInlineImageXObject]:"paintInlineImageXObject",[t.paintImageMaskXObject]:"paintImageMaskXObject",[t.paintJpegXObject]:"paintJpegXObject"}[e]||"unknown"}async function T(e){try{const t=await e.getOperatorList(),n=e.getViewport({scale:1}),o=n.width,a=n.height,i=[],s=[];let r=[1,0,0,1,0,0];const g=t.fnArray,h=t.argsArray,c=M.OPS,u=[c.paintImageXObject,c.paintInlineImageXObject,c.paintImageMaskXObject,c.paintJpegXObject];for(let l=0;l<g.length;l++){const p=g[l],x=h[l];if(p===c.save)s.push([...r]);else if(p===c.restore)s.length>0&&(r=s.pop());else if(p===c.transform){const[f,m,b,w,y,k]=x;r=B(r,[f,m,b,w,y,k])}else if(u.includes(p)){const f=X(r,o,a);i.push({type:"image",bbox_norm:f,source:"pdfjs",operator:P(p,c)})}}return i}catch(t){return console.error("Error extracting image blocks:",t),[]}}async function d(e,t){try{const o=await M.getDocument(e).promise;if(t<1||t>o.numPages)throw new Error(`Invalid page number: ${t}. Document has ${o.numPages} pages.`);const a=await o.getPage(t),i=a.getViewport({scale:1}),[s,r]=await Promise.all([I(a),T(a)]);return{textBlocks:s,imageBlocks:r,pageDimensions:{width:i.width,height:i.height},pageNumber:t}}catch(n){throw console.error(`Error extracting blocks from page ${t}:`,n),n}}async function D(e,t){const n=[];for(const o of t)try{const a=await d(e,o);n.push(a)}catch(a){console.error(`Failed to extract page ${o}:`,a),n.push({textBlocks:[],imageBlocks:[],pageDimensions:null,pageNumber:o,error:a.message})}return n}exports.extractAllBlocks=d;exports.extractMultiplePages=D;
|
|
2
2
|
//# sourceMappingURL=index8.cjs.map
|
package/dist/index8.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index8.cjs","sources":["../src/utils/viewportUtils.js"],"sourcesContent":["/**\n * Viewport Utility Functions\n *\n * This module provides utility functions for PDF viewport calculations\n * and transformations. These functions are used by the PDF viewer to\n * calculate viewport dimensions and manage scaling.\n */\n\n/**\n * Calculate viewport from PDF page\n *\n * Creates a viewport object from a PDF.js page with the specified scale.\n * The viewport contains dimensions and transformation matrix for rendering.\n *\n * @param {Object} page - PDF.js page object\n * @param {number} scale - Scale factor for rendering\n * @returns {Object} Viewport object with width, height, and transform matrix\n *\n * @example\n * const viewport = calculateViewport(pdfPage, 1.5);\n * // Returns: { width: 1200, height: 1600, scale: 1.5, ... }\n */\nexport function calculateViewport(page, scale) {\n if (!page) {\n throw new Error('Page object is required');\n }\n\n return page.getViewport({ scale });\n}\n\n/**\n * Get viewport dimensions\n *\n * Extracts width and height from a viewport object.\n * Useful for coordinate transformations and layout calculations.\n *\n * @param {Object} viewport - Viewport object from PDF.js\n * @returns {{width: number, height: number}} Dimensions object\n *\n * @example\n * const { width, height } = getViewportDimensions(viewport);\n * // Returns: { width: 1200, height: 1600 }\n */\nexport function getViewportDimensions(viewport) {\n if (!viewport) {\n return { width: 0, height: 0 };\n }\n\n return {\n width: viewport.width,\n height: viewport.height\n };\n}\n\n/**\n * Calculate scaled dimensions\n *\n * Calculates dimensions for a given scale factor.\n * Used when zoom level changes to determine new canvas size.\n *\n * @param {number} baseWidth - Original width\n * @param {number} baseHeight - Original height\n * @param {number} scale - Scale factor\n * @returns {{width: number, height: number}} Scaled dimensions\n *\n * @example\n * const scaled = calculateScaledDimensions(800, 1000, 1.5);\n * // Returns: { width: 1200, height: 1500 }\n */\nexport function calculateScaledDimensions(baseWidth, baseHeight, scale) {\n return {\n width: baseWidth * scale,\n height: baseHeight * scale\n };\n}\n"],"names":["calculateViewport","page","scale","getViewportDimensions","viewport","calculateScaledDimensions","baseWidth","baseHeight"],"mappings":"gFAsBO,SAASA,EAAkBC,EAAMC,EAAO,CAC7C,GAAI,CAACD,EACH,MAAM,IAAI,MAAM,yBAAyB,EAG3C,OAAOA,EAAK,YAAY,CAAE,MAAAC,EAAO,CACnC,CAeO,SAASC,EAAsBC,EAAU,CAC9C,OAAKA,EAIE,CACL,MAAOA,EAAS,MAChB,OAAQA,EAAS,MACrB,EANW,CAAE,MAAO,EAAG,OAAQ,CAAC,CAOhC,CAiBO,SAASC,EAA0BC,EAAWC,EAAYL,EAAO,CACtE,MAAO,CACL,MAAOI,EAAYJ,EACnB,OAAQK,EAAaL,CACzB,CACA"}
|
|
1
|
+
{"version":3,"file":"index8.cjs","sources":["../src/utils/pdfExtractor.js"],"sourcesContent":["/**\n * PDF Data Extractor - Extract text and image blocks from PDF\n *\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering.\n *\n * @module utils/pdfExtractor\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\n\n/**\n * Extract text blocks from a PDF page with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of text blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractTextBlocks(page) {\n try {\n const textContent = await page.getTextContent();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const textBlocks = [];\n\n for (const item of textContent.items) {\n // Skip empty text\n if (!item.str || !item.str.trim()) {\n continue;\n }\n\n // Get transform matrix [a, b, c, d, e, f]\n const transform = item.transform;\n const fontSize = Math.sqrt(transform[2] * transform[2] + transform[3] * transform[3]);\n\n // Calculate bounding box (absolute coordinates)\n const x = transform[4];\n const y = viewport.height - transform[5]; // Convert to top-left origin\n const width = item.width;\n const height = item.height || fontSize;\n\n const x1 = x;\n const y1 = y - height;\n const x2 = x + width;\n const y2 = y;\n\n // Normalize coordinates to 0-1 range\n const bbox_norm = [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n\n textBlocks.push({\n type: \"text\",\n text: item.str,\n bbox_norm: bbox_norm,\n font: item.fontName || \"unknown\",\n fontSize: fontSize,\n source: \"pdfjs\"\n });\n }\n\n return textBlocks;\n } catch (error) {\n console.error(\"Error extracting text blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract normalized bounding box from PDF transformation matrix\n *\n * @param {Array} transform - PDF transformation matrix [a, b, c, d, e, f]\n * @param {number} pageWidth - Page width for normalization\n * @param {number} pageHeight - Page height for coordinate conversion and normalization\n * @returns {Array} Normalized bounding box [x1, y1, x2, y2] in 0-1 range\n */\nfunction extractBBoxFromTransform(transform, pageWidth, pageHeight) {\n const x = transform[4];\n const y = transform[5];\n const scaleX = transform[0];\n const scaleY = transform[3];\n\n // Scale factors represent image dimensions\n const width = Math.abs(scaleX);\n const height = Math.abs(scaleY);\n\n // Convert from PDF bottom-left to image top-left origin\n const y1 = pageHeight - y - height;\n const y2 = pageHeight - y;\n const x1 = x;\n const x2 = x + width;\n\n // Normalize to 0-1 range\n return [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n}\n\n/**\n * Multiply two transformation matrices\n *\n * @param {Array} m1 - First matrix [a, b, c, d, e, f]\n * @param {Array} m2 - Second matrix [a, b, c, d, e, f]\n * @returns {Array} Result matrix [a, b, c, d, e, f]\n */\nfunction multiplyTransforms(m1, m2) {\n return [\n m1[0] * m2[0] + m1[2] * m2[1],\n m1[1] * m2[0] + m1[3] * m2[1],\n m1[0] * m2[2] + m1[2] * m2[3],\n m1[1] * m2[2] + m1[3] * m2[3],\n m1[0] * m2[4] + m1[2] * m2[5] + m1[4],\n m1[1] * m2[4] + m1[3] * m2[5] + m1[5]\n ];\n}\n\n/**\n * Get human-readable operator name\n *\n * @param {number} op - Operator code\n * @param {Object} OPS - PDF.js OPS constants\n * @returns {string} Operator name\n */\nfunction getOperatorName(op, OPS) {\n const opNames = {\n [OPS.paintImageXObject]: \"paintImageXObject\",\n [OPS.paintInlineImageXObject]: \"paintInlineImageXObject\",\n [OPS.paintImageMaskXObject]: \"paintImageMaskXObject\",\n [OPS.paintJpegXObject]: \"paintJpegXObject\"\n };\n return opNames[op] || \"unknown\";\n}\n\n/**\n * Extract image blocks from a PDF page using getOperatorList with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of image blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractImageBlocks(page) {\n try {\n const operatorList = await page.getOperatorList();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const imageBlocks = [];\n const graphicsStateStack = []; // Track graphics state transformations\n let currentTransform = [1, 0, 0, 1, 0, 0]; // Identity matrix\n\n const ops = operatorList.fnArray;\n const args = operatorList.argsArray;\n\n // Image paint operator constants from PDF.js\n const OPS = pdfjsLib.OPS;\n const IMAGE_OPS = [\n OPS.paintImageXObject,\n OPS.paintInlineImageXObject,\n OPS.paintImageMaskXObject,\n OPS.paintJpegXObject\n ];\n\n for (let i = 0; i < ops.length; i++) {\n const op = ops[i];\n const arg = args[i];\n\n // Track graphics state stack\n if (op === OPS.save) {\n graphicsStateStack.push([...currentTransform]);\n } else if (op === OPS.restore) {\n if (graphicsStateStack.length > 0) {\n currentTransform = graphicsStateStack.pop();\n }\n } else if (op === OPS.transform) {\n // Update current transformation matrix\n const [a, b, c, d, e, f] = arg;\n currentTransform = multiplyTransforms(currentTransform, [a, b, c, d, e, f]);\n } else if (IMAGE_OPS.includes(op)) {\n // Extract image bounding box (normalized)\n const bbox_norm = extractBBoxFromTransform(currentTransform, pageWidth, pageHeight);\n\n imageBlocks.push({\n type: \"image\",\n bbox_norm: bbox_norm,\n source: \"pdfjs\",\n operator: getOperatorName(op, OPS)\n });\n }\n }\n\n return imageBlocks;\n } catch (error) {\n console.error(\"Error extracting image blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract all blocks (text and images) from a PDF page\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {number} pageNumber - Page number (1-indexed)\n * @returns {Promise<Object>} Object with textBlocks and imageBlocks arrays\n */\nexport async function extractAllBlocks(pdfPath, pageNumber) {\n try {\n // Load PDF document\n const loadingTask = pdfjsLib.getDocument(pdfPath);\n const pdfDoc = await loadingTask.promise;\n\n // Validate page number\n if (pageNumber < 1 || pageNumber > pdfDoc.numPages) {\n throw new Error(`Invalid page number: ${pageNumber}. Document has ${pdfDoc.numPages} pages.`);\n }\n\n // Get page\n const page = await pdfDoc.getPage(pageNumber);\n const viewport = page.getViewport({ scale: 1.0 });\n\n // Extract text and image blocks in parallel\n const [textBlocks, imageBlocks] = await Promise.all([\n extractTextBlocks(page),\n extractImageBlocks(page)\n ]);\n\n return {\n textBlocks,\n imageBlocks,\n pageDimensions: {\n width: viewport.width,\n height: viewport.height\n },\n pageNumber: pageNumber\n };\n } catch (error) {\n console.error(`Error extracting blocks from page ${pageNumber}:`, error);\n throw error;\n }\n}\n\n/**\n * Extract blocks from multiple pages\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {Array<number>} pageNumbers - Array of page numbers (1-indexed)\n * @returns {Promise<Array>} Array of extraction results, one per page\n */\nexport async function extractMultiplePages(pdfPath, pageNumbers) {\n const results = [];\n\n for (const pageNum of pageNumbers) {\n try {\n const pageData = await extractAllBlocks(pdfPath, pageNum);\n results.push(pageData);\n } catch (error) {\n console.error(`Failed to extract page ${pageNum}:`, error);\n results.push({\n textBlocks: [],\n imageBlocks: [],\n pageDimensions: null,\n pageNumber: pageNum,\n error: error.message\n });\n }\n }\n\n return results;\n}\n"],"names":["extractTextBlocks","page","textContent","viewport","pageWidth","pageHeight","textBlocks","item","transform","fontSize","x","y","width","height","x1","y1","x2","y2","bbox_norm","error","extractBBoxFromTransform","scaleX","scaleY","multiplyTransforms","m1","m2","getOperatorName","op","OPS","extractImageBlocks","operatorList","imageBlocks","graphicsStateStack","currentTransform","ops","args","pdfjsLib","IMAGE_OPS","i","arg","a","b","c","d","e","f","extractAllBlocks","pdfPath","pageNumber","pdfDoc","extractMultiplePages","pageNumbers","results","pageNum","pageData"],"mappings":"wYAgBA,eAAeA,EAAkBC,EAAM,CACrC,GAAI,CACF,MAAMC,EAAc,MAAMD,EAAK,eAAc,EACvCE,EAAWF,EAAK,YAAY,CAAE,MAAO,CAAG,CAAE,EAE1CG,EAAYD,EAAS,MACrBE,EAAaF,EAAS,OAEtBG,EAAa,CAAA,EAEnB,UAAWC,KAAQL,EAAY,MAAO,CAEpC,GAAI,CAACK,EAAK,KAAO,CAACA,EAAK,IAAI,OACzB,SAIF,MAAMC,EAAYD,EAAK,UACjBE,EAAW,KAAK,KAAKD,EAAU,CAAC,EAAIA,EAAU,CAAC,EAAIA,EAAU,C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,OAAQA,EAAS,MACzB,EACM,WAAY6C,CAClB,CACE,OAAS7B,EAAO,CACd,cAAQ,MAAM,qCAAqC6B,CAAU,IAAK7B,CAAK,EACjEA,CACR,CACF,CASO,eAAe+B,EAAqBH,EAASI,EAAa,CAC/D,MAAMC,EAAU,CAAA,EAEhB,UAAWC,KAAWF,EACpB,GAAI,CACF,MAAMG,EAAW,MAAMR,EAAiBC,EAASM,CAAO,EACxDD,EAAQ,KAAKE,CAAQ,CACvB,OAASnC,EAAO,CACd,QAAQ,MAAM,0BAA0BkC,CAAO,IAAKlC,CAAK,EACzDiC,EAAQ,KAAK,CACX,WAAY,CAAA,EACZ,YAAa,CAAA,EACb,eAAgB,KAChB,WAAYC,EACZ,MAAOlC,EAAM,OACrB,CAAO,CACH,CAGF,OAAOiC,CACT"}
|
package/dist/index8.js
CHANGED
|
@@ -1,23 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as w from "pdfjs-dist";
|
|
2
|
+
async function d(e) {
|
|
3
|
+
try {
|
|
4
|
+
const t = await e.getTextContent(), o = e.getViewport({ scale: 1 }), s = o.width, n = o.height, i = [];
|
|
5
|
+
for (const r of t.items) {
|
|
6
|
+
if (!r.str || !r.str.trim())
|
|
7
|
+
continue;
|
|
8
|
+
const a = r.transform, g = Math.sqrt(a[2] * a[2] + a[3] * a[3]), l = a[4], c = o.height - a[5], x = r.width, h = r.height || g, p = l, f = c - h, u = l + x, m = c, b = [
|
|
9
|
+
Math.max(0, Math.min(1, p / s)),
|
|
10
|
+
Math.max(0, Math.min(1, f / n)),
|
|
11
|
+
Math.max(0, Math.min(1, u / s)),
|
|
12
|
+
Math.max(0, Math.min(1, m / n))
|
|
13
|
+
];
|
|
14
|
+
i.push({
|
|
15
|
+
type: "text",
|
|
16
|
+
text: r.str,
|
|
17
|
+
bbox_norm: b,
|
|
18
|
+
font: r.fontName || "unknown",
|
|
19
|
+
fontSize: g,
|
|
20
|
+
source: "pdfjs"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return i;
|
|
24
|
+
} catch (t) {
|
|
25
|
+
return console.error("Error extracting text blocks:", t), [];
|
|
26
|
+
}
|
|
5
27
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
28
|
+
function j(e, t, o) {
|
|
29
|
+
const s = e[4], n = e[5], i = e[0], r = e[3], a = Math.abs(i), g = Math.abs(r), l = o - n - g, c = o - n, x = s, h = s + a;
|
|
30
|
+
return [
|
|
31
|
+
Math.max(0, Math.min(1, x / t)),
|
|
32
|
+
Math.max(0, Math.min(1, l / o)),
|
|
33
|
+
Math.max(0, Math.min(1, h / t)),
|
|
34
|
+
Math.max(0, Math.min(1, c / o))
|
|
35
|
+
];
|
|
11
36
|
}
|
|
12
|
-
function
|
|
37
|
+
function I(e, t) {
|
|
38
|
+
return [
|
|
39
|
+
e[0] * t[0] + e[2] * t[1],
|
|
40
|
+
e[1] * t[0] + e[3] * t[1],
|
|
41
|
+
e[0] * t[2] + e[2] * t[3],
|
|
42
|
+
e[1] * t[2] + e[3] * t[3],
|
|
43
|
+
e[0] * t[4] + e[2] * t[5] + e[4],
|
|
44
|
+
e[1] * t[4] + e[3] * t[5] + e[5]
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
function O(e, t) {
|
|
13
48
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
49
|
+
[t.paintImageXObject]: "paintImageXObject",
|
|
50
|
+
[t.paintInlineImageXObject]: "paintInlineImageXObject",
|
|
51
|
+
[t.paintImageMaskXObject]: "paintImageMaskXObject",
|
|
52
|
+
[t.paintJpegXObject]: "paintJpegXObject"
|
|
53
|
+
}[e] || "unknown";
|
|
54
|
+
}
|
|
55
|
+
async function X(e) {
|
|
56
|
+
try {
|
|
57
|
+
const t = await e.getOperatorList(), o = e.getViewport({ scale: 1 }), s = o.width, n = o.height, i = [], r = [];
|
|
58
|
+
let a = [1, 0, 0, 1, 0, 0];
|
|
59
|
+
const g = t.fnArray, l = t.argsArray, c = w.OPS, x = [
|
|
60
|
+
c.paintImageXObject,
|
|
61
|
+
c.paintInlineImageXObject,
|
|
62
|
+
c.paintImageMaskXObject,
|
|
63
|
+
c.paintJpegXObject
|
|
64
|
+
];
|
|
65
|
+
for (let h = 0; h < g.length; h++) {
|
|
66
|
+
const p = g[h], f = l[h];
|
|
67
|
+
if (p === c.save)
|
|
68
|
+
r.push([...a]);
|
|
69
|
+
else if (p === c.restore)
|
|
70
|
+
r.length > 0 && (a = r.pop());
|
|
71
|
+
else if (p === c.transform) {
|
|
72
|
+
const [u, m, b, M, k, y] = f;
|
|
73
|
+
a = I(a, [u, m, b, M, k, y]);
|
|
74
|
+
} else if (x.includes(p)) {
|
|
75
|
+
const u = j(a, s, n);
|
|
76
|
+
i.push({
|
|
77
|
+
type: "image",
|
|
78
|
+
bbox_norm: u,
|
|
79
|
+
source: "pdfjs",
|
|
80
|
+
operator: O(p, c)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return i;
|
|
85
|
+
} catch (t) {
|
|
86
|
+
return console.error("Error extracting image blocks:", t), [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function B(e, t) {
|
|
90
|
+
try {
|
|
91
|
+
const s = await w.getDocument(e).promise;
|
|
92
|
+
if (t < 1 || t > s.numPages)
|
|
93
|
+
throw new Error(`Invalid page number: ${t}. Document has ${s.numPages} pages.`);
|
|
94
|
+
const n = await s.getPage(t), i = n.getViewport({ scale: 1 }), [r, a] = await Promise.all([
|
|
95
|
+
d(n),
|
|
96
|
+
X(n)
|
|
97
|
+
]);
|
|
98
|
+
return {
|
|
99
|
+
textBlocks: r,
|
|
100
|
+
imageBlocks: a,
|
|
101
|
+
pageDimensions: {
|
|
102
|
+
width: i.width,
|
|
103
|
+
height: i.height
|
|
104
|
+
},
|
|
105
|
+
pageNumber: t
|
|
106
|
+
};
|
|
107
|
+
} catch (o) {
|
|
108
|
+
throw console.error(`Error extracting blocks from page ${t}:`, o), o;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function T(e, t) {
|
|
112
|
+
const o = [];
|
|
113
|
+
for (const s of t)
|
|
114
|
+
try {
|
|
115
|
+
const n = await B(e, s);
|
|
116
|
+
o.push(n);
|
|
117
|
+
} catch (n) {
|
|
118
|
+
console.error(`Failed to extract page ${s}:`, n), o.push({
|
|
119
|
+
textBlocks: [],
|
|
120
|
+
imageBlocks: [],
|
|
121
|
+
pageDimensions: null,
|
|
122
|
+
pageNumber: s,
|
|
123
|
+
error: n.message
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return o;
|
|
17
127
|
}
|
|
18
128
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
n as getViewportDimensions
|
|
129
|
+
B as extractAllBlocks,
|
|
130
|
+
T as extractMultiplePages
|
|
22
131
|
};
|
|
23
132
|
//# sourceMappingURL=index8.js.map
|
package/dist/index8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index8.js","sources":["../src/utils/viewportUtils.js"],"sourcesContent":["/**\n * Viewport Utility Functions\n *\n * This module provides utility functions for PDF viewport calculations\n * and transformations. These functions are used by the PDF viewer to\n * calculate viewport dimensions and manage scaling.\n */\n\n/**\n * Calculate viewport from PDF page\n *\n * Creates a viewport object from a PDF.js page with the specified scale.\n * The viewport contains dimensions and transformation matrix for rendering.\n *\n * @param {Object} page - PDF.js page object\n * @param {number} scale - Scale factor for rendering\n * @returns {Object} Viewport object with width, height, and transform matrix\n *\n * @example\n * const viewport = calculateViewport(pdfPage, 1.5);\n * // Returns: { width: 1200, height: 1600, scale: 1.5, ... }\n */\nexport function calculateViewport(page, scale) {\n if (!page) {\n throw new Error('Page object is required');\n }\n\n return page.getViewport({ scale });\n}\n\n/**\n * Get viewport dimensions\n *\n * Extracts width and height from a viewport object.\n * Useful for coordinate transformations and layout calculations.\n *\n * @param {Object} viewport - Viewport object from PDF.js\n * @returns {{width: number, height: number}} Dimensions object\n *\n * @example\n * const { width, height } = getViewportDimensions(viewport);\n * // Returns: { width: 1200, height: 1600 }\n */\nexport function getViewportDimensions(viewport) {\n if (!viewport) {\n return { width: 0, height: 0 };\n }\n\n return {\n width: viewport.width,\n height: viewport.height\n };\n}\n\n/**\n * Calculate scaled dimensions\n *\n * Calculates dimensions for a given scale factor.\n * Used when zoom level changes to determine new canvas size.\n *\n * @param {number} baseWidth - Original width\n * @param {number} baseHeight - Original height\n * @param {number} scale - Scale factor\n * @returns {{width: number, height: number}} Scaled dimensions\n *\n * @example\n * const scaled = calculateScaledDimensions(800, 1000, 1.5);\n * // Returns: { width: 1200, height: 1500 }\n */\nexport function calculateScaledDimensions(baseWidth, baseHeight, scale) {\n return {\n width: baseWidth * scale,\n height: baseHeight * scale\n };\n}\n"],"names":["calculateViewport","page","scale","getViewportDimensions","viewport","calculateScaledDimensions","baseWidth","baseHeight"],"mappings":"AAsBO,SAASA,EAAkBC,GAAMC,GAAO;AAC7C,MAAI,CAACD;AACH,UAAM,IAAI,MAAM,yBAAyB;AAG3C,SAAOA,EAAK,YAAY,EAAE,OAAAC,GAAO;AACnC;AAeO,SAASC,EAAsBC,GAAU;AAC9C,SAAKA,IAIE;AAAA,IACL,OAAOA,EAAS;AAAA,IAChB,QAAQA,EAAS;AAAA,EACrB,IANW,EAAE,OAAO,GAAG,QAAQ,EAAC;AAOhC;AAiBO,SAASC,EAA0BC,GAAWC,GAAYL,GAAO;AACtE,SAAO;AAAA,IACL,OAAOI,IAAYJ;AAAA,IACnB,QAAQK,IAAaL;AAAA,EACzB;AACA;"}
|
|
1
|
+
{"version":3,"file":"index8.js","sources":["../src/utils/pdfExtractor.js"],"sourcesContent":["/**\n * PDF Data Extractor - Extract text and image blocks from PDF\n *\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering.\n *\n * @module utils/pdfExtractor\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\n\n/**\n * Extract text blocks from a PDF page with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of text blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractTextBlocks(page) {\n try {\n const textContent = await page.getTextContent();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const textBlocks = [];\n\n for (const item of textContent.items) {\n // Skip empty text\n if (!item.str || !item.str.trim()) {\n continue;\n }\n\n // Get transform matrix [a, b, c, d, e, f]\n const transform = item.transform;\n const fontSize = Math.sqrt(transform[2] * transform[2] + transform[3] * transform[3]);\n\n // Calculate bounding box (absolute coordinates)\n const x = transform[4];\n const y = viewport.height - transform[5]; // Convert to top-left origin\n const width = item.width;\n const height = item.height || fontSize;\n\n const x1 = x;\n const y1 = y - height;\n const x2 = x + width;\n const y2 = y;\n\n // Normalize coordinates to 0-1 range\n const bbox_norm = [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n\n textBlocks.push({\n type: \"text\",\n text: item.str,\n bbox_norm: bbox_norm,\n font: item.fontName || \"unknown\",\n fontSize: fontSize,\n source: \"pdfjs\"\n });\n }\n\n return textBlocks;\n } catch (error) {\n console.error(\"Error extracting text blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract normalized bounding box from PDF transformation matrix\n *\n * @param {Array} transform - PDF transformation matrix [a, b, c, d, e, f]\n * @param {number} pageWidth - Page width for normalization\n * @param {number} pageHeight - Page height for coordinate conversion and normalization\n * @returns {Array} Normalized bounding box [x1, y1, x2, y2] in 0-1 range\n */\nfunction extractBBoxFromTransform(transform, pageWidth, pageHeight) {\n const x = transform[4];\n const y = transform[5];\n const scaleX = transform[0];\n const scaleY = transform[3];\n\n // Scale factors represent image dimensions\n const width = Math.abs(scaleX);\n const height = Math.abs(scaleY);\n\n // Convert from PDF bottom-left to image top-left origin\n const y1 = pageHeight - y - height;\n const y2 = pageHeight - y;\n const x1 = x;\n const x2 = x + width;\n\n // Normalize to 0-1 range\n return [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n}\n\n/**\n * Multiply two transformation matrices\n *\n * @param {Array} m1 - First matrix [a, b, c, d, e, f]\n * @param {Array} m2 - Second matrix [a, b, c, d, e, f]\n * @returns {Array} Result matrix [a, b, c, d, e, f]\n */\nfunction multiplyTransforms(m1, m2) {\n return [\n m1[0] * m2[0] + m1[2] * m2[1],\n m1[1] * m2[0] + m1[3] * m2[1],\n m1[0] * m2[2] + m1[2] * m2[3],\n m1[1] * m2[2] + m1[3] * m2[3],\n m1[0] * m2[4] + m1[2] * m2[5] + m1[4],\n m1[1] * m2[4] + m1[3] * m2[5] + m1[5]\n ];\n}\n\n/**\n * Get human-readable operator name\n *\n * @param {number} op - Operator code\n * @param {Object} OPS - PDF.js OPS constants\n * @returns {string} Operator name\n */\nfunction getOperatorName(op, OPS) {\n const opNames = {\n [OPS.paintImageXObject]: \"paintImageXObject\",\n [OPS.paintInlineImageXObject]: \"paintInlineImageXObject\",\n [OPS.paintImageMaskXObject]: \"paintImageMaskXObject\",\n [OPS.paintJpegXObject]: \"paintJpegXObject\"\n };\n return opNames[op] || \"unknown\";\n}\n\n/**\n * Extract image blocks from a PDF page using getOperatorList with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of image blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractImageBlocks(page) {\n try {\n const operatorList = await page.getOperatorList();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const imageBlocks = [];\n const graphicsStateStack = []; // Track graphics state transformations\n let currentTransform = [1, 0, 0, 1, 0, 0]; // Identity matrix\n\n const ops = operatorList.fnArray;\n const args = operatorList.argsArray;\n\n // Image paint operator constants from PDF.js\n const OPS = pdfjsLib.OPS;\n const IMAGE_OPS = [\n OPS.paintImageXObject,\n OPS.paintInlineImageXObject,\n OPS.paintImageMaskXObject,\n OPS.paintJpegXObject\n ];\n\n for (let i = 0; i < ops.length; i++) {\n const op = ops[i];\n const arg = args[i];\n\n // Track graphics state stack\n if (op === OPS.save) {\n graphicsStateStack.push([...currentTransform]);\n } else if (op === OPS.restore) {\n if (graphicsStateStack.length > 0) {\n currentTransform = graphicsStateStack.pop();\n }\n } else if (op === OPS.transform) {\n // Update current transformation matrix\n const [a, b, c, d, e, f] = arg;\n currentTransform = multiplyTransforms(currentTransform, [a, b, c, d, e, f]);\n } else if (IMAGE_OPS.includes(op)) {\n // Extract image bounding box (normalized)\n const bbox_norm = extractBBoxFromTransform(currentTransform, pageWidth, pageHeight);\n\n imageBlocks.push({\n type: \"image\",\n bbox_norm: bbox_norm,\n source: \"pdfjs\",\n operator: getOperatorName(op, OPS)\n });\n }\n }\n\n return imageBlocks;\n } catch (error) {\n console.error(\"Error extracting image blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract all blocks (text and images) from a PDF page\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {number} pageNumber - Page number (1-indexed)\n * @returns {Promise<Object>} Object with textBlocks and imageBlocks arrays\n */\nexport async function extractAllBlocks(pdfPath, pageNumber) {\n try {\n // Load PDF document\n const loadingTask = pdfjsLib.getDocument(pdfPath);\n const pdfDoc = await loadingTask.promise;\n\n // Validate page number\n if (pageNumber < 1 || pageNumber > pdfDoc.numPages) {\n throw new Error(`Invalid page number: ${pageNumber}. Document has ${pdfDoc.numPages} pages.`);\n }\n\n // Get page\n const page = await pdfDoc.getPage(pageNumber);\n const viewport = page.getViewport({ scale: 1.0 });\n\n // Extract text and image blocks in parallel\n const [textBlocks, imageBlocks] = await Promise.all([\n extractTextBlocks(page),\n extractImageBlocks(page)\n ]);\n\n return {\n textBlocks,\n imageBlocks,\n pageDimensions: {\n width: viewport.width,\n height: viewport.height\n },\n pageNumber: pageNumber\n };\n } catch (error) {\n console.error(`Error extracting blocks from page ${pageNumber}:`, error);\n throw error;\n }\n}\n\n/**\n * Extract blocks from multiple pages\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {Array<number>} pageNumbers - Array of page numbers (1-indexed)\n * @returns {Promise<Array>} Array of extraction results, one per page\n */\nexport async function extractMultiplePages(pdfPath, pageNumbers) {\n const results = [];\n\n for (const pageNum of pageNumbers) {\n try {\n const pageData = await extractAllBlocks(pdfPath, pageNum);\n results.push(pageData);\n } catch (error) {\n console.error(`Failed to extract page ${pageNum}:`, error);\n results.push({\n textBlocks: [],\n imageBlocks: [],\n pageDimensions: null,\n pageNumber: pageNum,\n error: error.message\n });\n }\n }\n\n return results;\n}\n"],"names":["extractTextBlocks","page","textContent","viewport","pageWidth","pageHeight","textBlocks","item","transform","fontSize","x","y","width","height","x1","y1","x2","y2","bbox_norm","error","extractBBoxFromTransform","scaleX","scaleY","multiplyTransforms","m1","m2","getOperatorName","op","OPS","extractImageBlocks","operatorList","imageBlocks","graphicsStateStack","currentTransform","ops","args","pdfjsLib","IMAGE_OPS","i","arg","a","b","c","d","e","f","extractAllBlocks","pdfPath","pageNumber","pdfDoc","extractMultiplePages","pageNumbers","results","pageNum","pageData"],"mappings":";AAgBA,eAAeA,EAAkBC,GAAM;AACrC,MAAI;AACF,UAAMC,IAAc,MAAMD,EAAK,eAAc,GACvCE,IAAWF,EAAK,YAAY,EAAE,OAAO,EAAG,CAAE,GAE1CG,IAAYD,EAAS,OACrBE,IAAaF,EAAS,QAEtBG,IAAa,CAAA;AAEnB,eAAWC,KAAQL,EAAY,OAAO;AAEpC,UAAI,CAACK,EAAK,OAAO,CAACA,EAAK,IAAI;AACzB;AAIF,YAAMC,IAAYD,EAAK,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QAAIC,IAAa,KAAKA,IAAaC,EAAO;AACxC,YAAM,IAAI,MAAM,wBAAwBD,CAAU,kBAAkBC,EAAO,QAAQ,SAAS;AAI9F,UAAMhD,IAAO,MAAMgD,EAAO,QAAQD,CAAU,GACtC7C,IAAWF,EAAK,YAAY,EAAE,OAAO,EAAG,CAAE,GAG1C,CAACK,GAAYyB,CAAW,IAAI,MAAM,QAAQ,IAAI;AAAA,MAClD/B,EAAkBC,CAAI;AAAA,MACtB4B,EAAmB5B,CAAI;AAAA,IAC7B,CAAK;AAED,WAAO;AAAA,MACL,YAAAK;AAAA,MACA,aAAAyB;AAAA,MACA,gBAAgB;AAAA,QACd,OAAO5B,EAAS;AAAA,QAChB,QAAQA,EAAS;AAAA,MACzB;AAAA,MACM,YAAY6C;AAAA,IAClB;AAAA,EACE,SAAS7B,GAAO;AACd,kBAAQ,MAAM,qCAAqC6B,CAAU,KAAK7B,CAAK,GACjEA;AAAA,EACR;AACF;AASO,eAAe+B,EAAqBH,GAASI,GAAa;AAC/D,QAAMC,IAAU,CAAA;AAEhB,aAAWC,KAAWF;AACpB,QAAI;AACF,YAAMG,IAAW,MAAMR,EAAiBC,GAASM,CAAO;AACxD,MAAAD,EAAQ,KAAKE,CAAQ;AAAA,IACvB,SAASnC,GAAO;AACd,cAAQ,MAAM,0BAA0BkC,CAAO,KAAKlC,CAAK,GACzDiC,EAAQ,KAAK;AAAA,QACX,YAAY,CAAA;AAAA,QACZ,aAAa,CAAA;AAAA,QACb,gBAAgB;AAAA,QAChB,YAAYC;AAAA,QACZ,OAAOlC,EAAM;AAAA,MACrB,CAAO;AAAA,IACH;AAGF,SAAOiC;AACT;"}
|
package/dist/index9.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index26.cjs");function d(t,n,e,l,o){let i=t;return typeof t=="string"&&(i=parseFloat(t)),typeof i!="number"||isNaN(i)?(o.push(`[${e}]: Field "${l}" invalid value "${t}", using default ${n}`),n):i<0?(o.push(`[${e}]: Field "${l}" value ${i} below range [0,1], clamping to 0`),0):i>1?(o.push(`[${e}]: Field "${l}" value ${i} exceeds range [0,1], clamping to 1`),1):i}function c(t,n,e,l){if(typeof t!="string"||t.trim().length===0)return l.push(`[${e}]: Invalid color format "${t}", using default ${n}`),n;const o=t.trim(),i=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/,r=/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/,u=["red","blue","green","yellow","black","white","gray","grey","orange","purple","pink","brown","transparent"],$=i.test(o),E=r.test(o),T=u.includes(o.toLowerCase());return $||E||T?o:(l.push(`[${e}]: Invalid color format "${t}", using default ${n}`),n)}function F(t,n,e,l,o){let i=t;return typeof t=="string"&&(i=parseFloat(t)),typeof i!="number"||isNaN(i)||i<=0?(o.push(`[${e}]: Field "${l}" invalid value "${t}", using default ${n}`),n):i}function f(t,n,e){const l={};if(typeof t.id!="string"||t.id.trim().length===0){const o=Date.now(),i=Math.random().toString(36).substr(2,9);l.id=`anno-${o}-${i}`,e.push(`[${l.id}]: Auto-generated ID (original was missing or invalid)`)}else l.id=t.id.trim();return l.type=t.type,typeof t.page!="number"||t.page<1?(n.push(`[${l.id}]: Field "page" invalid value "${t.page}", using default ${s.BASE_DEFAULTS.page}`),l.page=s.BASE_DEFAULTS.page):l.page=Math.floor(t.page),typeof t.start!="number"||t.start<0?(n.push(`[${l.id}]: Field "start" invalid value "${t.start}", using default ${s.BASE_DEFAULTS.start}`),l.start=s.BASE_DEFAULTS.start):l.start=t.start,typeof t.end!="number"||t.end<0?(n.push(`[${l.id}]: Field "end" invalid value "${t.end}", using start value ${l.start}`),l.end=l.start):t.end<l.start?(n.push(`[${l.id}]: Field "end" (${t.end}) less than start (${l.start}), clamping to start`),l.end=l.start):l.end=t.end,l}function a(t,n,e){return!t||typeof t!="object"?(e.push(`[${n}]: Invalid quad object, using default`),{x:.1,y:.1,w:.8,h:.05}):{x:d(t.x,.1,n,"quad.x",e),y:d(t.y,.1,n,"quad.y",e),w:d(t.w,.8,n,"quad.w",e),h:d(t.h,.05,n,"quad.h",e)}}function y(t,n,e,l){const o={...t};n.mode!=="quads"?(e.push(`[${t.id}]: Field "mode" invalid value "${n.mode}", using default "${s.HIGHLIGHT_DEFAULTS.mode}"`),o.mode=s.HIGHLIGHT_DEFAULTS.mode):o.mode=n.mode,!Array.isArray(n.quads)||n.quads.length===0?(e.push(`[${t.id}]: Field "quads" missing or empty, using default`),o.quads=s.HIGHLIGHT_DEFAULTS.quads):o.quads=n.quads.map((r,u)=>a(r,t.id,e));const i=s.HIGHLIGHT_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?(e.push(`[${t.id}]: Field "style" missing or invalid, using default`),o.style={color:i}):o.style={color:c(n.style.color,i,t.id,e)},o}function p(t,n,e,l){const o={...t};typeof n.content!="string"||n.content.trim().length===0?(e.push(`[${t.id}]: Field "content" missing or empty, using default "${s.TEXT_DEFAULTS.content}"`),o.content=s.TEXT_DEFAULTS.content):o.content=n.content,o.x=d(n.x,s.TEXT_DEFAULTS.x,t.id,"x",e),o.y=d(n.y,s.TEXT_DEFAULTS.y,t.id,"y",e),o.w=d(n.w,s.TEXT_DEFAULTS.w,t.id,"w",e),o.h=d(n.h,s.TEXT_DEFAULTS.h,t.id,"h",e);const i=s.TEXT_DEFAULTS.style.bg,r=s.TEXT_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?(e.push(`[${t.id}]: Field "style" missing or invalid, using defaults`),o.style={bg:i,color:r}):o.style={bg:c(n.style.bg,i,t.id,e),color:c(n.style.color,r,t.id,e)},o}function m(t,n,e,l){const o={...t};!Array.isArray(n.quads)||n.quads.length===0?(e.push(`[${t.id}]: Field "quads" missing or empty, using default`),o.quads=s.UNDERLINE_DEFAULTS.quads):o.quads=n.quads.map(r=>a(r,t.id,e));const i=s.UNDERLINE_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?o.style={color:i}:o.style={color:c(n.style.color,i,t.id,e)},o}function g(t,n,e,l){const o={...t};o.from_x=d(n.from_x,s.ARROW_DEFAULTS.from_x,t.id,"from_x",e),o.from_y=d(n.from_y,s.ARROW_DEFAULTS.from_y,t.id,"from_y",e),o.to_x=d(n.to_x,s.ARROW_DEFAULTS.to_x,t.id,"to_x",e),o.to_y=d(n.to_y,s.ARROW_DEFAULTS.to_y,t.id,"to_y",e);const i=s.ARROW_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?o.style={color:i}:o.style={color:c(n.style.color,i,t.id,e)},o}function h(t,n,e,l){const o={...t};o.cx=d(n.cx,s.CIRCLE_DEFAULTS.cx,t.id,"cx",e),o.cy=d(n.cy,s.CIRCLE_DEFAULTS.cy,t.id,"cy",e),o.rx=d(n.rx,s.CIRCLE_DEFAULTS.rx,t.id,"rx",e),o.ry=d(n.ry,s.CIRCLE_DEFAULTS.ry,t.id,"ry",e);const i=s.CIRCLE_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?o.style={color:i}:o.style={color:c(n.style.color,i,t.id,e)},o}function A(t,n){const e=[],l=[];if(!t||typeof t!="object")return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Not a valid object`};if(typeof t.type!="string"||t.type.trim().length===0)return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Missing or invalid type field`};const o=t.type.trim(),i=f(t,e,l);let r;if(o==="highlight")r=y(i,t,e);else if(o==="text")r=p(i,t,e);else if(o==="underline")r=m(i,t,e);else if(o==="arrow")r=g(i,t,e);else if(o==="circle")r=h(i,t,e);else if(o==="ink")r={...i,strokes:t.strokes||[]},t.style&&(r.style=t.style);else return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Unsupported type "${o}"`};return{annotation:r,warnings:e,info:l,critical:null}}function _(t,n={}){n.skipInvalid;const e=n.warnInConsole!==!1,l=n.onWarning||null,o={normalized:[],warnings:[],info:[],skipped:[]};if(!Array.isArray(t)){const i="normalizeAnnotationArray: Input is not an array, returning empty result";return o.warnings.push(i),e&&console.warn(`[Annotation Normalizer] ${i}`),o}return t.forEach((i,r)=>{if(i==null){o.skipped.push({index:r,annotation:i,reason:"Annotation is null or undefined"});return}const u=A(i,r);if(u.critical){o.skipped.push({index:r,annotation:i,reason:u.critical}),e&&console.error(`[Annotation Normalizer] ${u.critical}`);return}o.normalized.push(u.annotation),o.warnings.push(...u.warnings),o.info.push(...u.info)}),e&&(o.warnings.length>0||o.info.length>0||o.skipped.length>0)&&(console.group("[Annotation Normalizer] Validation Summary"),o.normalized.length>0&&console.info(`✓ Normalized ${o.normalized.length} annotation(s)`),o.skipped.length>0&&(console.error(`✗ Skipped ${o.skipped.length} annotation(s)`),o.skipped.forEach(i=>{console.error(` Index ${i.index}: ${i.reason}`)})),o.warnings.length>0&&(console.warn(`⚠ ${o.warnings.length} warning(s):`),o.warnings.forEach(i=>console.warn(` ${i}`))),o.info.length>0&&(console.info(`ℹ ${o.info.length} info message(s):`),o.info.forEach(i=>console.info(` ${i}`))),console.groupEnd()),l&&typeof l=="function"&&l(o),o}exports.normalizeAnnotation=A;exports.normalizeAnnotationArray=_;exports.normalizeArrow=g;exports.normalizeBaseFields=f;exports.normalizeCircle=h;exports.normalizeColor=c;exports.normalizeCoordinate=d;exports.normalizeHighlight=y;exports.normalizePositiveNumber=F;exports.normalizeText=p;exports.normalizeUnderline=m;
|
|
2
2
|
//# sourceMappingURL=index9.cjs.map
|