web-annotation-renderer 0.3.0 → 0.4.0
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 +49 -42
- package/dist/index.js.map +1 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.cjs.map +1 -1
- package/dist/index10.js +172 -17
- package/dist/index10.js.map +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.cjs.map +1 -1
- package/dist/index11.js +13 -20
- package/dist/index11.js.map +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.cjs.map +1 -1
- package/dist/index12.js +148 -123
- package/dist/index12.js.map +1 -1
- package/dist/index13.cjs +1 -1
- package/dist/index13.cjs.map +1 -1
- package/dist/index13.js +29 -198
- package/dist/index13.js.map +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.cjs.map +1 -1
- package/dist/index14.js +56 -15
- package/dist/index14.js.map +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.cjs.map +1 -1
- package/dist/index15.js +115 -120
- package/dist/index15.js.map +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.cjs.map +1 -1
- package/dist/index16.js +100 -212
- package/dist/index16.js.map +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.cjs.map +1 -1
- package/dist/index17.js +55 -37
- package/dist/index17.js.map +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.cjs.map +1 -1
- package/dist/index18.js +139 -35
- package/dist/index18.js.map +1 -1
- package/dist/index19.cjs +1 -1
- package/dist/index19.cjs.map +1 -1
- package/dist/index19.js +37 -37
- package/dist/index19.js.map +1 -1
- package/dist/index2.cjs +1 -1
- package/dist/index2.cjs.map +1 -1
- package/dist/index2.js +65 -73
- package/dist/index2.js.map +1 -1
- package/dist/index20.cjs +1 -1
- package/dist/index20.cjs.map +1 -1
- package/dist/index20.js +29 -39
- package/dist/index20.js.map +1 -1
- package/dist/index21.cjs +1 -1
- package/dist/index21.cjs.map +1 -1
- package/dist/index21.js +38 -32
- package/dist/index21.js.map +1 -1
- package/dist/index22.cjs +1 -1
- package/dist/index22.cjs.map +1 -1
- package/dist/index22.js +22 -5
- package/dist/index22.js.map +1 -1
- package/dist/index23.cjs +2 -0
- package/dist/index23.cjs.map +1 -0
- package/dist/index23.js +8 -0
- package/dist/index23.js.map +1 -0
- package/dist/index24.cjs +2 -0
- package/dist/index24.cjs.map +1 -0
- package/dist/index24.js +8 -0
- package/dist/index24.js.map +1 -0
- package/dist/index3.cjs +1 -1
- package/dist/index3.cjs.map +1 -1
- package/dist/index3.js +1 -1
- package/dist/index4.cjs +1 -1
- package/dist/index4.cjs.map +1 -1
- package/dist/index4.js +72 -71
- package/dist/index4.js.map +1 -1
- package/dist/index5.cjs +1 -1
- package/dist/index5.cjs.map +1 -1
- package/dist/index5.js +153 -65
- package/dist/index5.js.map +1 -1
- package/dist/index6.cjs +1 -1
- package/dist/index6.cjs.map +1 -1
- package/dist/index6.js +60 -114
- package/dist/index6.js.map +1 -1
- package/dist/index7.cjs +1 -1
- package/dist/index7.cjs.map +1 -1
- package/dist/index7.js +19 -91
- package/dist/index7.js.map +1 -1
- package/dist/index8.cjs +1 -1
- package/dist/index8.cjs.map +1 -1
- package/dist/index8.js +19 -105
- package/dist/index8.js.map +1 -1
- package/dist/index9.cjs +1 -1
- package/dist/index9.cjs.map +1 -1
- package/dist/index9.js +123 -98
- package/dist/index9.js.map +1 -1
- package/package.json +4 -3
package/dist/index8.js
CHANGED
|
@@ -1,109 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Renders text box elements for all annotations
|
|
18
|
-
*
|
|
19
|
-
* Creates DOM structure for each text annotation. Creates text box divs
|
|
20
|
-
* with proper positioning and styling. Initially hidden (visibility
|
|
21
|
-
* controlled by updateTime).
|
|
22
|
-
*
|
|
23
|
-
* This method is idempotent - safe to call multiple times.
|
|
24
|
-
*/
|
|
25
|
-
render() {
|
|
26
|
-
this.layerElement.innerHTML = "", this.textElements.clear(), this.annotations.forEach((t) => {
|
|
27
|
-
const s = p(t, this.viewport), e = document.createElement("div");
|
|
28
|
-
e.style.position = "absolute", e.style.left = `${s.left}px`, e.style.top = `${s.top}px`, e.style.width = `${s.width}px`, e.style.height = `${s.height}px`, e.style.backgroundColor = t.style?.bg || "rgba(255,255,255,0.9)", e.style.borderRadius = "4px", e.style.padding = "8px", e.style.fontSize = "14px", e.style.lineHeight = "1.4", e.style.color = t.style?.color || "#1f2937", e.style.fontFamily = "system-ui, -apple-system, sans-serif", e.style.display = "flex", e.style.alignItems = "center", e.style.justifyContent = "flex-start", e.style.overflow = "hidden", e.style.wordWrap = "break-word", e.style.display = "none", this.layerElement.appendChild(e), this.textElements.set(t.id, {
|
|
29
|
-
element: e,
|
|
30
|
-
annotation: t
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Updates text box visibility and content based on timeline position
|
|
36
|
-
*
|
|
37
|
-
* Shows/hides text boxes based on start time. Calculates visible text
|
|
38
|
-
* for progressive reveal (typing effect). Text appears immediately when
|
|
39
|
-
* start time is reached and types in progressively.
|
|
40
|
-
*
|
|
41
|
-
* @param {number} nowSec - Current timeline position in seconds
|
|
42
|
-
*/
|
|
43
|
-
updateTime(t) {
|
|
44
|
-
super.updateTime(t), this.textElements.forEach(({ element: s, annotation: e }) => {
|
|
45
|
-
if (t < e.start)
|
|
46
|
-
s.style.display = "none";
|
|
47
|
-
else {
|
|
48
|
-
s.style.display = "flex";
|
|
49
|
-
const l = this._getVisibleText(
|
|
50
|
-
e.content,
|
|
51
|
-
e.start,
|
|
52
|
-
e.end,
|
|
53
|
-
t
|
|
54
|
-
);
|
|
55
|
-
s.textContent = l;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Calculates visible text based on progress between start and end times
|
|
61
|
-
*
|
|
62
|
-
* Implements word-by-word reveal with partial character reveal for
|
|
63
|
-
* the current word being typed.
|
|
64
|
-
*
|
|
65
|
-
* @private
|
|
66
|
-
* @param {string} content - Full text content
|
|
67
|
-
* @param {number} start - Start time in seconds
|
|
68
|
-
* @param {number} end - End time in seconds
|
|
69
|
-
* @param {number} currentTime - Current timeline position in seconds
|
|
70
|
-
* @returns {string} Visible portion of text
|
|
71
|
-
*/
|
|
72
|
-
_getVisibleText(t, s, e, l) {
|
|
73
|
-
if (l < s)
|
|
74
|
-
return "";
|
|
75
|
-
if (l >= e)
|
|
76
|
-
return t;
|
|
77
|
-
const n = (l - s) / (e - s), r = t.split(" "), i = Math.floor(n * r.length);
|
|
78
|
-
if (i === 0)
|
|
79
|
-
return "";
|
|
80
|
-
const o = r.slice(0, i);
|
|
81
|
-
if (i < r.length) {
|
|
82
|
-
const h = n * r.length - i, y = r[i], a = Math.floor(
|
|
83
|
-
h * y.length
|
|
84
|
-
);
|
|
85
|
-
a > 0 && o.push(y.slice(0, a));
|
|
86
|
-
}
|
|
87
|
-
return o.join(" ");
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Updates the visual state of the layer
|
|
91
|
-
*
|
|
92
|
-
* Not used by TextLayer - updateTime handles all updates directly.
|
|
93
|
-
* Implemented to satisfy BaseLayer contract.
|
|
94
|
-
*/
|
|
95
|
-
update() {
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Destroys the layer and releases all resources
|
|
99
|
-
*
|
|
100
|
-
* Clears element storage, removes DOM elements, and calls parent cleanup.
|
|
101
|
-
*/
|
|
102
|
-
destroy() {
|
|
103
|
-
this.textElements.clear(), this.textElements = null, this.layerElement && this.layerElement.parentNode && this.layerElement.parentNode.removeChild(this.layerElement), this.layerElement = null, super.destroy();
|
|
104
|
-
}
|
|
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
|
+
return {
|
|
14
|
+
width: t * i,
|
|
15
|
+
height: e * i
|
|
16
|
+
};
|
|
105
17
|
}
|
|
106
18
|
export {
|
|
107
|
-
|
|
19
|
+
h as calculateScaledDimensions,
|
|
20
|
+
r as calculateViewport,
|
|
21
|
+
n as getViewportDimensions
|
|
108
22
|
};
|
|
109
23
|
//# sourceMappingURL=index8.js.map
|
package/dist/index8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index8.js","sources":["../src/layers/TextLayer.js"],"sourcesContent":["import BaseLayer from \"./BaseLayer.js\";\nimport { rectNormToAbs } from \"../utils/coordinateUtils.js\";\n\n/**\n * TextLayer - Renders text annotations with progressive reveal\n *\n * Extends BaseLayer to render text box annotations with progressive\n * word-by-word text reveal animation (typing effect). Text appears\n * immediately and types in character by character, simulating real-time typing.\n *\n * @extends BaseLayer\n */\nclass TextLayer extends BaseLayer {\n /**\n * Creates a new TextLayer instance\n *\n * @param {HTMLElement} container - Parent DOM element for layer content\n * @param {Object} viewport - Initial viewport dimensions\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n * @param {number} viewport.scale - PDF scale/zoom level\n */\n constructor(container, viewport) {\n // Call parent constructor first\n super(container, viewport);\n\n // Create layer container element\n this.layerElement = document.createElement(\"div\");\n this.layerElement.style.position = \"absolute\";\n this.layerElement.style.inset = \"0\";\n this.layerElement.style.pointerEvents = \"none\";\n this.layerElement.style.zIndex = \"30\";\n\n // Append to parent container\n this.container.appendChild(this.layerElement);\n\n // Initialize element storage (Map of id -> element)\n this.textElements = new Map();\n }\n\n /**\n * Renders text box elements for all annotations\n *\n * Creates DOM structure for each text annotation. Creates text box divs\n * with proper positioning and styling. Initially hidden (visibility\n * controlled by updateTime).\n *\n * This method is idempotent - safe to call multiple times.\n */\n render() {\n // Clear existing elements\n this.layerElement.innerHTML = \"\";\n this.textElements.clear();\n\n // Process each annotation\n this.annotations.forEach((annotation) => {\n // Convert normalized coordinates to absolute pixels\n const abs = rectNormToAbs(annotation, this.viewport);\n\n // Create text box div\n const textBox = document.createElement(\"div\");\n\n // Set positioning\n textBox.style.position = \"absolute\";\n textBox.style.left = `${abs.left}px`;\n textBox.style.top = `${abs.top}px`;\n textBox.style.width = `${abs.width}px`;\n textBox.style.height = `${abs.height}px`;\n\n // Set background and border\n textBox.style.backgroundColor =\n annotation.style?.bg || \"rgba(255,255,255,0.9)\";\n textBox.style.borderRadius = \"4px\";\n textBox.style.padding = \"8px\";\n\n // Set text styling\n textBox.style.fontSize = \"14px\";\n textBox.style.lineHeight = \"1.4\";\n textBox.style.color = annotation.style?.color || \"#1f2937\";\n textBox.style.fontFamily = \"system-ui, -apple-system, sans-serif\";\n\n // Set layout\n textBox.style.display = \"flex\";\n textBox.style.alignItems = \"center\";\n textBox.style.justifyContent = \"flex-start\";\n textBox.style.overflow = \"hidden\";\n textBox.style.wordWrap = \"break-word\";\n\n // Initially hidden (will be shown/updated in updateTime)\n textBox.style.display = \"none\";\n\n // Append to layer\n this.layerElement.appendChild(textBox);\n\n // Store reference\n this.textElements.set(annotation.id, {\n element: textBox,\n annotation: annotation,\n });\n });\n }\n\n /**\n * Updates text box visibility and content based on timeline position\n *\n * Shows/hides text boxes based on start time. Calculates visible text\n * for progressive reveal (typing effect). Text appears immediately when\n * start time is reached and types in progressively.\n *\n * @param {number} nowSec - Current timeline position in seconds\n */\n updateTime(nowSec) {\n // Call parent implementation\n super.updateTime(nowSec);\n\n // Update each text element\n this.textElements.forEach(({ element, annotation }) => {\n // Check if annotation should be visible\n if (nowSec < annotation.start) {\n // Before start time - hide\n element.style.display = \"none\";\n } else {\n // After start time - show\n element.style.display = \"flex\";\n\n // Calculate visible text\n const visibleText = this._getVisibleText(\n annotation.content,\n annotation.start,\n annotation.end,\n nowSec\n );\n\n // Update text content (typing effect)\n element.textContent = visibleText;\n }\n });\n }\n\n /**\n * Calculates visible text based on progress between start and end times\n *\n * Implements word-by-word reveal with partial character reveal for\n * the current word being typed.\n *\n * @private\n * @param {string} content - Full text content\n * @param {number} start - Start time in seconds\n * @param {number} end - End time in seconds\n * @param {number} currentTime - Current timeline position in seconds\n * @returns {string} Visible portion of text\n */\n _getVisibleText(content, start, end, currentTime) {\n // Before start - no text visible\n if (currentTime < start) {\n return \"\";\n }\n\n // After end - full text visible\n if (currentTime >= end) {\n return content;\n }\n\n // During animation - calculate progress\n const progress = (currentTime - start) / (end - start);\n\n // Split into words\n const words = content.split(\" \");\n\n // Calculate visible word count\n const visibleWordCount = Math.floor(progress * words.length);\n\n // No words visible yet\n if (visibleWordCount === 0) {\n return \"\";\n }\n\n // Get complete visible words\n const visibleWords = words.slice(0, visibleWordCount);\n\n // Add partial of the next word if not at the end\n if (visibleWordCount < words.length) {\n // Calculate progress within current word\n const currentWordProgress = progress * words.length - visibleWordCount;\n\n // Get current word being typed\n const currentWord = words[visibleWordCount];\n\n // Calculate visible character count\n const visibleCharCount = Math.floor(\n currentWordProgress * currentWord.length\n );\n\n // Add partial word if any characters are visible\n if (visibleCharCount > 0) {\n visibleWords.push(currentWord.slice(0, visibleCharCount));\n }\n }\n\n // Join words with spaces\n return visibleWords.join(\" \");\n }\n\n /**\n * Updates the visual state of the layer\n *\n * Not used by TextLayer - updateTime handles all updates directly.\n * Implemented to satisfy BaseLayer contract.\n */\n update() {\n // Not used - updateTime handles updates directly\n }\n\n /**\n * Destroys the layer and releases all resources\n *\n * Clears element storage, removes DOM elements, and calls parent cleanup.\n */\n destroy() {\n // Clear element storage\n this.textElements.clear();\n this.textElements = null;\n\n // Remove layer element from DOM\n if (this.layerElement && this.layerElement.parentNode) {\n this.layerElement.parentNode.removeChild(this.layerElement);\n }\n this.layerElement = null;\n\n // Call parent destroy\n super.destroy();\n }\n}\n\nexport default TextLayer;\n"],"names":["TextLayer","BaseLayer","container","viewport","annotation","abs","rectNormToAbs","textBox","nowSec","element","visibleText","content","start","end","currentTime","progress","words","visibleWordCount","visibleWords","currentWordProgress","currentWord","visibleCharCount"],"mappings":";;AAYA,MAAMA,UAAkBC,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUhC,YAAYC,GAAWC,GAAU;AAE/B,UAAMD,GAAWC,CAAQ,GAGzB,KAAK,eAAe,SAAS,cAAc,KAAK,GAChD,KAAK,aAAa,MAAM,WAAW,YACnC,KAAK,aAAa,MAAM,QAAQ,KAChC,KAAK,aAAa,MAAM,gBAAgB,QACxC,KAAK,aAAa,MAAM,SAAS,MAGjC,KAAK,UAAU,YAAY,KAAK,YAAY,GAG5C,KAAK,eAAe,oBAAI,IAAG;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,SAAS;AAEP,SAAK,aAAa,YAAY,IAC9B,KAAK,aAAa,MAAK,GAGvB,KAAK,YAAY,QAAQ,CAACC,MAAe;AAEvC,YAAMC,IAAMC,EAAcF,GAAY,KAAK,QAAQ,GAG7CG,IAAU,SAAS,cAAc,KAAK;AAG5C,MAAAA,EAAQ,MAAM,WAAW,YACzBA,EAAQ,MAAM,OAAO,GAAGF,EAAI,IAAI,MAChCE,EAAQ,MAAM,MAAM,GAAGF,EAAI,GAAG,MAC9BE,EAAQ,MAAM,QAAQ,GAAGF,EAAI,KAAK,MAClCE,EAAQ,MAAM,SAAS,GAAGF,EAAI,MAAM,MAGpCE,EAAQ,MAAM,kBACZH,EAAW,OAAO,MAAM,y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zBM,IAAmB,KAAK,MAAMF,IAAWC,EAAM,MAAM;AAG3D,QAAIC,MAAqB;AACvB,aAAO;AAIT,UAAMC,IAAeF,EAAM,MAAM,GAAGC,CAAgB;AAGpD,QAAIA,IAAmBD,EAAM,QAAQ;AAEnC,YAAMG,IAAsBJ,IAAWC,EAAM,SAASC,GAGhDG,IAAcJ,EAAMC,CAAgB,GAGpCI,IAAmB,KAAK;AAAA,QAC5BF,IAAsBC,EAAY;AAAA,MAC1C;AAGM,MAAIC,IAAmB,KACrBH,EAAa,KAAKE,EAAY,MAAM,GAAGC,CAAgB,CAAC;AAAA,IAE5D;AAGA,WAAOH,EAAa,KAAK,GAAG;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAS;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,UAAU;AAER,SAAK,aAAa,MAAK,GACvB,KAAK,eAAe,MAGhB,KAAK,gBAAgB,KAAK,aAAa,cACzC,KAAK,aAAa,WAAW,YAAY,KAAK,YAAY,GAE5D,KAAK,eAAe,MAGpB,MAAM,QAAO;AAAA,EACf;AACF;"}
|
|
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;"}
|
package/dist/index9.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.
|
|
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=index9.cjs.map
|
package/dist/index9.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index9.cjs","sources":["../src/layers/DrawingLayer.js"],"sourcesContent":["import BaseLayer from './BaseLayer.js';\n\n/**\n * DrawingLayer - Renders ink/drawing annotations on HTML canvas\n *\n * Extends BaseLayer to provide progressive stroke animation for ink annotations.\n * Draws stroke points incrementally based on timeline position using requestAnimationFrame.\n * Handles device pixel ratio scaling for crisp rendering on high-DPI displays.\n *\n * Features:\n * - Progressive stroke drawing point-by-point\n * - Multiple strokes per annotation with custom colors/sizes\n * - Device pixel ratio handling for Retina displays\n * - Smooth 60fps animation with RAF\n * - Efficient canvas clear/redraw cycle\n *\n * @extends BaseLayer\n */\nclass DrawingLayer extends BaseLayer {\n /**\n * Creates a new DrawingLayer instance\n *\n * @param {HTMLElement} container - Parent DOM element for layer content\n * @param {Object} viewport - Initial viewport dimensions\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n * @param {number} viewport.scale - PDF scale/zoom level\n */\n constructor(container, viewport) {\n super(container, viewport);\n\n // Create canvas element\n this.canvasElement = document.createElement('canvas');\n this.canvasElement.style.position = 'absolute';\n this.canvasElement.style.inset = '0';\n this.canvasElement.style.pointerEvents = 'none';\n this.canvasElement.style.zIndex = '40';\n\n // Append to container\n this.container.appendChild(this.canvasElement);\n\n // Get 2D context\n this.ctx = this.canvasElement.getContext('2d');\n\n // Setup canvas with device pixel ratio\n this._setupCanvas();\n }\n\n /**\n * Configures canvas dimensions with device pixel ratio scaling\n *\n * Sets canvas buffer size for high-resolution rendering on Retina displays\n * while maintaining correct display size in CSS pixels. Scales context\n * transform to allow drawing with CSS pixel coordinates.\n *\n * @private\n */\n _setupCanvas() {\n const dpr = window.devicePixelRatio || 1;\n\n // Set canvas buffer resolution (high-res for crisp rendering)\n this.canvasElement.width = Math.round(this.viewport.width * dpr);\n this.canvasElement.height = Math.round(this.viewport.height * dpr);\n\n // Set canvas display size (CSS pixels)\n this.canvasElement.style.width = `${this.viewport.width}px`;\n this.canvasElement.style.height = `${this.viewport.height}px`;\n\n // Scale context to account for device pixel ratio\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n }\n\n /**\n * Updates viewport dimensions and resizes canvas\n *\n * Reconfigures canvas buffer and display size when viewport changes\n * due to page navigation or zoom operations.\n *\n * @param {Object} viewport - New viewport dimensions\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n * @param {number} viewport.scale - PDF scale/zoom level\n * @override\n */\n setViewport(viewport) {\n super.setViewport(viewport);\n this._setupCanvas();\n }\n\n /**\n * Updates timeline position and draws progressive strokes\n *\n * Redraws the canvas with strokes progressively drawn based on elapsed time.\n * Clears the canvas and redraws all visible strokes.\n * Renders once per call - no continuous loop.\n *\n * @param {number} nowSec - Current timeline position in seconds\n * @throws {Error} If called after layer is destroyed\n * @override\n */\n updateTime(nowSec) {\n super.updateTime(nowSec);\n\n // Check destroyed state\n if (this.isDestroyed) return;\n\n // Clear canvas\n this.ctx.clearRect(0, 0, this.canvasElement.width, this.canvasElement.height);\n\n // Draw each annotation\n for (const a of this.annotations) {\n // Skip annotations that haven't started yet\n if (nowSec < a.start) continue;\n\n // Calculate elapsed time (capped at duration for persistence)\n const duration = a.end - a.start;\n const elapsed = Math.min(nowSec - a.start, duration);\n\n // Draw each stroke\n for (const stroke of (a.strokes || [])) {\n // Configure stroke style\n this.ctx.lineCap = 'round';\n this.ctx.lineJoin = 'round';\n this.ctx.strokeStyle = stroke.color || '#1f2937';\n this.ctx.lineWidth = stroke.size || 3;\n this.ctx.beginPath();\n\n let started = false;\n\n // Draw points up to current time\n for (const point of stroke.points) {\n // Skip points that haven't been drawn yet\n if (point.t > elapsed) break;\n\n // Convert normalized coordinates to canvas pixels\n const x = point.x * this.viewport.width;\n const y = point.y * this.viewport.height;\n\n if (!started) {\n this.ctx.moveTo(x, y);\n started = true;\n } else {\n this.ctx.lineTo(x, y);\n }\n }\n\n // Render the stroke\n if (started) {\n this.ctx.stroke();\n }\n }\n }\n }\n\n /**\n * Renders the layer content\n *\n * No-op for DrawingLayer - canvas rendering happens in updateTime().\n * Canvas element is created once in constructor.\n *\n * @override\n */\n render() {\n // No-op: Canvas rendering happens in updateTime()\n // Canvas element is created once in constructor\n }\n\n /**\n * Updates the visual state of the layer\n *\n * Not used for DrawingLayer - updateTime() handles drawing directly.\n *\n * @override\n */\n update() {\n // Not used - updateTime handles drawing directly\n }\n\n /**\n * Destroys the layer and releases resources\n *\n * Clears references and removes canvas from DOM.\n * Safe to call multiple times (idempotent).\n *\n * @override\n */\n destroy() {\n // Clear context reference\n this.ctx = null;\n\n // Remove canvas from DOM\n if (this.canvasElement && this.canvasElement.parentNode) {\n this.canvasElement.parentNode.removeChild(this.canvasElement);\n }\n this.canvasElement = null;\n\n // Call parent cleanup (always last)\n super.destroy();\n }\n}\n\nexport default DrawingLayer;\n"],"names":["DrawingLayer","BaseLayer","container","viewport","dpr","nowSec","a","duration","elapsed","stroke","started","point","x","y"],"mappings":"4IAkBA,MAAMA,UAAqBC,EAAAA,OAAU,CAUnC,YAAYC,EAAWC,EAAU,CAC/B,MAAMD,EAAWC,CAAQ,EAGzB,KAAK,cAAgB,SAAS,cAAc,QAAQ,EACpD,KAAK,cAAc,MAAM,SAAW,WACpC,KAAK,cAAc,MAAM,MAAQ,IACjC,KAAK,cAAc,MAAM,cAAgB,OACzC,KAAK,cAAc,MAAM,OAAS,KAGlC,KAAK,UAAU,YAAY,KAAK,aAAa,EAG7C,KAAK,IAAM,KAAK,cAAc,WAAW,IAAI,EAG7C,KAAK,aAAY,CACnB,CAWA,cAAe,CACb,MAAMC,EAAM,OAAO,kBAAoB,EAGvC,KAAK,cAAc,MAAQ,KAAK,MAAM,KAAK,SAAS,MAAQA,CAAG,EAC/D,KAAK,cAAc,OAAS,KAAK,MAAM,KAAK,SAAS,OAASA,CAAG,EAGjE,KAAK,cAAc,MAAM,MAAQ,GAAG,KAAK,SAAS,KAAK,KACvD,KAAK,cAAc,MAAM,OAAS,GAAG,KAAK,SAAS,MAAM,KAGzD,KAAK,IAAI,aAAaA,EAAK,EAAG,EAAGA,EAAK,EAAG,CAAC,CAC5C,CAcA,YAAYD,EAAU,CACpB,MAAM,YAAYA,CAAQ,EAC1B,KAAK,aAAY,CACnB,CAaA,WAAWE,EAAQ,CAIjB,GAHA,MAAM,WAAWA,CAAM,EAGnB,MAAK,YAGT,MAAK,IAAI,UAAU,EAAG,EAAG,KAAK,cAAc,MAAO,KAAK,cAAc,MAAM,EAG5E,UAAWC,KAAK,KAAK,YAAa,CAEhC,GAAID,EAASC,EAAE,MAAO,SAGtB,MAAMC,EAAWD,EAAE,IAAMA,EAAE,MACrBE,EAAU,KAAK,IAAIH,EAASC,EAAE,MAAOC,CAAQ,EAGnD,UAAWE,KAAWH,EAAE,SAAW,CAAA,EAAK,CAEtC,KAAK,IAAI,QAAU,QACnB,KAAK,IAAI,SAAW,QACpB,KAAK,IAAI,YAAcG,EAAO,OAAS,UACvC,KAAK,IAAI,UAAYA,EAAO,MAAQ,EACpC,KAAK,IAAI,UAAS,EAElB,IAAIC,EAAU,GAGd,UAAWC,KAASF,EAAO,OAAQ,CAEjC,GAAIE,EAAM,EAAIH,EAAS,MAGvB,MAAMI,EAAID,EAAM,EAAI,KAAK,SAAS,MAC5BE,EAAIF,EAAM,EAAI,KAAK,SAAS,OAE7BD,EAIH,KAAK,IAAI,OAAOE,EAAGC,CAAC,GAHpB,KAAK,IAAI,OAAOD,EAAGC,CAAC,EACpBH,EAAU,GAId,CAGIA,GACF,KAAK,IAAI,OAAM,CAEnB,CACF,EACF,CAUA,QAAS,CAGT,CASA,QAAS,CAET,CAUA,SAAU,CAER,KAAK,IAAM,KAGP,KAAK,eAAiB,KAAK,cAAc,YAC3C,KAAK,cAAc,WAAW,YAAY,KAAK,aAAa,EAE9D,KAAK,cAAgB,KAGrB,MAAM,QAAO,CACf,CACF"}
|
|
1
|
+
{"version":3,"file":"index9.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,CAAC,EAAIA,EAAU,CAAC,CAAC,EAG9EE,EAAIF,EAAU,CAAC,EACfG,EAAIR,EAAS,OAASK,EAAU,CAAC,EACjCI,EAAQL,EAAK,MACbM,EAASN,EAAK,QAAUE,EAExBK,EAAKJ,EACLK,EAAKJ,EAAIE,EACTG,EAAKN,EAAIE,EACTK,EAAKN,EAGLO,EAAY,CAChB,KAAK,IAAI,EAAK,KAAK,IAAI,EAAKJ,EA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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/index9.js
CHANGED
|
@@ -1,107 +1,132 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.canvasElement.width = Math.round(this.viewport.width * t), this.canvasElement.height = Math.round(this.viewport.height * t), this.canvasElement.style.width = `${this.viewport.width}px`, this.canvasElement.style.height = `${this.viewport.height}px`, this.ctx.setTransform(t, 0, 0, t, 0, 0);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Updates viewport dimensions and resizes canvas
|
|
30
|
-
*
|
|
31
|
-
* Reconfigures canvas buffer and display size when viewport changes
|
|
32
|
-
* due to page navigation or zoom operations.
|
|
33
|
-
*
|
|
34
|
-
* @param {Object} viewport - New viewport dimensions
|
|
35
|
-
* @param {number} viewport.width - Viewport width in pixels
|
|
36
|
-
* @param {number} viewport.height - Viewport height in pixels
|
|
37
|
-
* @param {number} viewport.scale - PDF scale/zoom level
|
|
38
|
-
* @override
|
|
39
|
-
*/
|
|
40
|
-
setViewport(t) {
|
|
41
|
-
super.setViewport(t), this._setupCanvas();
|
|
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), [];
|
|
42
26
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
27
|
+
}
|
|
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
|
+
];
|
|
36
|
+
}
|
|
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) {
|
|
48
|
+
return {
|
|
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
|
+
});
|
|
70
82
|
}
|
|
71
83
|
}
|
|
84
|
+
return i;
|
|
85
|
+
} catch (t) {
|
|
86
|
+
return console.error("Error extracting image blocks:", t), [];
|
|
72
87
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
* Clears references and removes canvas from DOM.
|
|
96
|
-
* Safe to call multiple times (idempotent).
|
|
97
|
-
*
|
|
98
|
-
* @override
|
|
99
|
-
*/
|
|
100
|
-
destroy() {
|
|
101
|
-
this.ctx = null, this.canvasElement && this.canvasElement.parentNode && this.canvasElement.parentNode.removeChild(this.canvasElement), this.canvasElement = null, super.destroy();
|
|
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;
|
|
102
109
|
}
|
|
103
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;
|
|
127
|
+
}
|
|
104
128
|
export {
|
|
105
|
-
|
|
129
|
+
B as extractAllBlocks,
|
|
130
|
+
T as extractMultiplePages
|
|
106
131
|
};
|
|
107
132
|
//# sourceMappingURL=index9.js.map
|
package/dist/index9.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index9.js","sources":["../src/layers/DrawingLayer.js"],"sourcesContent":["import BaseLayer from './BaseLayer.js';\n\n/**\n * DrawingLayer - Renders ink/drawing annotations on HTML canvas\n *\n * Extends BaseLayer to provide progressive stroke animation for ink annotations.\n * Draws stroke points incrementally based on timeline position using requestAnimationFrame.\n * Handles device pixel ratio scaling for crisp rendering on high-DPI displays.\n *\n * Features:\n * - Progressive stroke drawing point-by-point\n * - Multiple strokes per annotation with custom colors/sizes\n * - Device pixel ratio handling for Retina displays\n * - Smooth 60fps animation with RAF\n * - Efficient canvas clear/redraw cycle\n *\n * @extends BaseLayer\n */\nclass DrawingLayer extends BaseLayer {\n /**\n * Creates a new DrawingLayer instance\n *\n * @param {HTMLElement} container - Parent DOM element for layer content\n * @param {Object} viewport - Initial viewport dimensions\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n * @param {number} viewport.scale - PDF scale/zoom level\n */\n constructor(container, viewport) {\n super(container, viewport);\n\n // Create canvas element\n this.canvasElement = document.createElement('canvas');\n this.canvasElement.style.position = 'absolute';\n this.canvasElement.style.inset = '0';\n this.canvasElement.style.pointerEvents = 'none';\n this.canvasElement.style.zIndex = '40';\n\n // Append to container\n this.container.appendChild(this.canvasElement);\n\n // Get 2D context\n this.ctx = this.canvasElement.getContext('2d');\n\n // Setup canvas with device pixel ratio\n this._setupCanvas();\n }\n\n /**\n * Configures canvas dimensions with device pixel ratio scaling\n *\n * Sets canvas buffer size for high-resolution rendering on Retina displays\n * while maintaining correct display size in CSS pixels. Scales context\n * transform to allow drawing with CSS pixel coordinates.\n *\n * @private\n */\n _setupCanvas() {\n const dpr = window.devicePixelRatio || 1;\n\n // Set canvas buffer resolution (high-res for crisp rendering)\n this.canvasElement.width = Math.round(this.viewport.width * dpr);\n this.canvasElement.height = Math.round(this.viewport.height * dpr);\n\n // Set canvas display size (CSS pixels)\n this.canvasElement.style.width = `${this.viewport.width}px`;\n this.canvasElement.style.height = `${this.viewport.height}px`;\n\n // Scale context to account for device pixel ratio\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n }\n\n /**\n * Updates viewport dimensions and resizes canvas\n *\n * Reconfigures canvas buffer and display size when viewport changes\n * due to page navigation or zoom operations.\n *\n * @param {Object} viewport - New viewport dimensions\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n * @param {number} viewport.scale - PDF scale/zoom level\n * @override\n */\n setViewport(viewport) {\n super.setViewport(viewport);\n this._setupCanvas();\n }\n\n /**\n * Updates timeline position and draws progressive strokes\n *\n * Redraws the canvas with strokes progressively drawn based on elapsed time.\n * Clears the canvas and redraws all visible strokes.\n * Renders once per call - no continuous loop.\n *\n * @param {number} nowSec - Current timeline position in seconds\n * @throws {Error} If called after layer is destroyed\n * @override\n */\n updateTime(nowSec) {\n super.updateTime(nowSec);\n\n // Check destroyed state\n if (this.isDestroyed) return;\n\n // Clear canvas\n this.ctx.clearRect(0, 0, this.canvasElement.width, this.canvasElement.height);\n\n // Draw each annotation\n for (const a of this.annotations) {\n // Skip annotations that haven't started yet\n if (nowSec < a.start) continue;\n\n // Calculate elapsed time (capped at duration for persistence)\n const duration = a.end - a.start;\n const elapsed = Math.min(nowSec - a.start, duration);\n\n // Draw each stroke\n for (const stroke of (a.strokes || [])) {\n // Configure stroke style\n this.ctx.lineCap = 'round';\n this.ctx.lineJoin = 'round';\n this.ctx.strokeStyle = stroke.color || '#1f2937';\n this.ctx.lineWidth = stroke.size || 3;\n this.ctx.beginPath();\n\n let started = false;\n\n // Draw points up to current time\n for (const point of stroke.points) {\n // Skip points that haven't been drawn yet\n if (point.t > elapsed) break;\n\n // Convert normalized coordinates to canvas pixels\n const x = point.x * this.viewport.width;\n const y = point.y * this.viewport.height;\n\n if (!started) {\n this.ctx.moveTo(x, y);\n started = true;\n } else {\n this.ctx.lineTo(x, y);\n }\n }\n\n // Render the stroke\n if (started) {\n this.ctx.stroke();\n }\n }\n }\n }\n\n /**\n * Renders the layer content\n *\n * No-op for DrawingLayer - canvas rendering happens in updateTime().\n * Canvas element is created once in constructor.\n *\n * @override\n */\n render() {\n // No-op: Canvas rendering happens in updateTime()\n // Canvas element is created once in constructor\n }\n\n /**\n * Updates the visual state of the layer\n *\n * Not used for DrawingLayer - updateTime() handles drawing directly.\n *\n * @override\n */\n update() {\n // Not used - updateTime handles drawing directly\n }\n\n /**\n * Destroys the layer and releases resources\n *\n * Clears references and removes canvas from DOM.\n * Safe to call multiple times (idempotent).\n *\n * @override\n */\n destroy() {\n // Clear context reference\n this.ctx = null;\n\n // Remove canvas from DOM\n if (this.canvasElement && this.canvasElement.parentNode) {\n this.canvasElement.parentNode.removeChild(this.canvasElement);\n }\n this.canvasElement = null;\n\n // Call parent cleanup (always last)\n super.destroy();\n }\n}\n\nexport default DrawingLayer;\n"],"names":["DrawingLayer","BaseLayer","container","viewport","dp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AAO,KAAK,cAAc,MAAM;AAG5E,iBAAWC,KAAK,KAAK,aAAa;AAEhC,YAAID,IAASC,EAAE,MAAO;AAGtB,cAAMC,IAAWD,EAAE,MAAMA,EAAE,OACrBE,IAAU,KAAK,IAAIH,IAASC,EAAE,OAAOC,CAAQ;AAGnD,mBAAWE,KAAWH,EAAE,WAAW,CAAA,GAAK;AAEtC,eAAK,IAAI,UAAU,SACnB,KAAK,IAAI,WAAW,SACpB,KAAK,IAAI,cAAcG,EAAO,SAAS,WACvC,KAAK,IAAI,YAAYA,EAAO,QAAQ,GACpC,KAAK,IAAI,UAAS;AAElB,cAAIC,IAAU;AAGd,qBAAWC,KAASF,EAAO,QAAQ;AAEjC,gBAAIE,EAAM,IAAIH,EAAS;AAGvB,kBAAMI,IAAID,EAAM,IAAI,KAAK,SAAS,OAC5BE,IAAIF,EAAM,IAAI,KAAK,SAAS;AAElC,YAAKD,IAIH,KAAK,IAAI,OAAOE,GAAGC,CAAC,KAHpB,KAAK,IAAI,OAAOD,GAAGC,CAAC,GACpBH,IAAU;AAAA,UAId;AAGA,UAAIA,KACF,KAAK,IAAI,OAAM;AAAA,QAEnB;AAAA,MACF;AAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,SAAS;AAAA,EAGT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,SAAS;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UAAU;AAER,SAAK,MAAM,MAGP,KAAK,iBAAiB,KAAK,cAAc,cAC3C,KAAK,cAAc,WAAW,YAAY,KAAK,aAAa,GAE9D,KAAK,gBAAgB,MAGrB,MAAM,QAAO;AAAA,EACf;AACF;"}
|
|
1
|
+
{"version":3,"file":"index9.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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
|
"type": "module",
|
|
5
5
|
"description": "Framework-agnostic PDF annotation renderer with timeline synchronization for educational content and interactive documents",
|
|
6
6
|
"keywords": [
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"lint": "eslint ."
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
+
"canvas": "^3.2.0",
|
|
65
66
|
"pdfjs-dist": "^5.4.149"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
@@ -86,8 +87,8 @@
|
|
|
86
87
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
87
88
|
"globals": "^16.4.0",
|
|
88
89
|
"puppeteer": "^24.22.0",
|
|
89
|
-
"react": "^
|
|
90
|
-
"react-dom": "^
|
|
90
|
+
"react": "^18.2.0",
|
|
91
|
+
"react-dom": "^18.2.0",
|
|
91
92
|
"vite": "^7.1.7"
|
|
92
93
|
}
|
|
93
94
|
}
|