web-annotation-renderer 0.1.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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +156 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/index10.cjs +2 -0
- package/dist/index10.cjs.map +1 -0
- package/dist/index10.js +23 -0
- package/dist/index10.js.map +1 -0
- package/dist/index11.cjs +2 -0
- package/dist/index11.cjs.map +1 -0
- package/dist/index11.js +23 -0
- package/dist/index11.js.map +1 -0
- package/dist/index12.cjs +2 -0
- package/dist/index12.cjs.map +1 -0
- package/dist/index12.js +203 -0
- package/dist/index12.js.map +1 -0
- package/dist/index13.cjs +2 -0
- package/dist/index13.cjs.map +1 -0
- package/dist/index13.js +18 -0
- package/dist/index13.js.map +1 -0
- package/dist/index14.cjs +2 -0
- package/dist/index14.cjs.map +1 -0
- package/dist/index14.js +116 -0
- package/dist/index14.js.map +1 -0
- package/dist/index15.cjs +2 -0
- package/dist/index15.cjs.map +1 -0
- package/dist/index15.js +35 -0
- package/dist/index15.js.map +1 -0
- package/dist/index2.cjs +2 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +182 -0
- package/dist/index2.js.map +1 -0
- package/dist/index3.cjs +2 -0
- package/dist/index3.cjs.map +1 -0
- package/dist/index3.js +121 -0
- package/dist/index3.js.map +1 -0
- package/dist/index4.cjs +2 -0
- package/dist/index4.cjs.map +1 -0
- package/dist/index4.js +104 -0
- package/dist/index4.js.map +1 -0
- package/dist/index5.cjs +2 -0
- package/dist/index5.cjs.map +1 -0
- package/dist/index5.js +105 -0
- package/dist/index5.js.map +1 -0
- package/dist/index6.cjs +2 -0
- package/dist/index6.cjs.map +1 -0
- package/dist/index6.js +119 -0
- package/dist/index6.js.map +1 -0
- package/dist/index7.cjs +2 -0
- package/dist/index7.cjs.map +1 -0
- package/dist/index7.js +100 -0
- package/dist/index7.js.map +1 -0
- package/dist/index8.cjs +2 -0
- package/dist/index8.cjs.map +1 -0
- package/dist/index8.js +109 -0
- package/dist/index8.js.map +1 -0
- package/dist/index9.cjs +2 -0
- package/dist/index9.cjs.map +1 -0
- package/dist/index9.js +112 -0
- package/dist/index9.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +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 // Initialize animation frame ID\n this.rafId = null;\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 starts progressive stroke drawing\n *\n * Cancels any existing animation loop and starts a new requestAnimationFrame\n * loop to redraw the canvas with strokes progressively drawn based on elapsed time.\n * Each frame clears the canvas and redraws all visible strokes.\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 // Cancel existing RAF to prevent multiple loops\n if (this.rafId) {\n cancelAnimationFrame(this.rafId);\n }\n\n // Start drawing loop\n const draw = () => {\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 // Schedule next frame\n this.rafId = requestAnimationFrame(draw);\n };\n\n // Start the loop\n draw();\n }\n\n /**\n * Renders the layer content\n *\n * No-op for DrawingLayer - canvas rendering happens in updateTime() RAF loop.\n * Canvas element is created once in constructor and drawn to continuously.\n *\n * @override\n */\n render() {\n // No-op: Canvas rendering happens in updateTime() RAF loop\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 updates via RAF loop.\n *\n * @override\n */\n update() {\n // Not used - updateTime handles drawing via RAF loop\n }\n\n /**\n * Destroys the layer and releases resources\n *\n * Cancels animation loop, clears references, and removes canvas from DOM.\n * Safe to call multiple times (idempotent).\n *\n * @override\n */\n destroy() {\n // Cancel animation loop first\n if (this.rafId) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n\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","draw","a","duration","elapsed","stroke","started","point","x","y"],"mappings":"4IAkBA,MAAMA,UAAqBC,EAAAA,OAAU,CAUnC,YAAYC,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G,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,CAGA,KAAK,MAAQ,sBAAsBL,CAAI,EACzC,EAGAA,EAAI,CACN,CAUA,QAAS,CAGT,CASA,QAAS,CAET,CAUA,SAAU,CAEJ,KAAK,QACP,qBAAqB,KAAK,KAAK,EAC/B,KAAK,MAAQ,MAIf,KAAK,IAAM,KAGP,KAAK,eAAiB,KAAK,cAAc,YAC3C,KAAK,cAAc,WAAW,YAAY,KAAK,aAAa,EAE9D,KAAK,cAAgB,KAGrB,MAAM,QAAO,CACf,CACF"}
|
package/dist/index9.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import l from "./index6.js";
|
|
2
|
+
class p extends l {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new DrawingLayer instance
|
|
5
|
+
*
|
|
6
|
+
* @param {HTMLElement} container - Parent DOM element for layer content
|
|
7
|
+
* @param {Object} viewport - Initial viewport dimensions
|
|
8
|
+
* @param {number} viewport.width - Viewport width in pixels
|
|
9
|
+
* @param {number} viewport.height - Viewport height in pixels
|
|
10
|
+
* @param {number} viewport.scale - PDF scale/zoom level
|
|
11
|
+
*/
|
|
12
|
+
constructor(t, s) {
|
|
13
|
+
super(t, s), this.canvasElement = document.createElement("canvas"), this.canvasElement.style.position = "absolute", this.canvasElement.style.inset = "0", this.canvasElement.style.pointerEvents = "none", this.canvasElement.style.zIndex = "40", this.container.appendChild(this.canvasElement), this.ctx = this.canvasElement.getContext("2d"), this.rafId = null, this._setupCanvas();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Configures canvas dimensions with device pixel ratio scaling
|
|
17
|
+
*
|
|
18
|
+
* Sets canvas buffer size for high-resolution rendering on Retina displays
|
|
19
|
+
* while maintaining correct display size in CSS pixels. Scales context
|
|
20
|
+
* transform to allow drawing with CSS pixel coordinates.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
_setupCanvas() {
|
|
25
|
+
const t = window.devicePixelRatio || 1;
|
|
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();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Updates timeline position and starts progressive stroke drawing
|
|
45
|
+
*
|
|
46
|
+
* Cancels any existing animation loop and starts a new requestAnimationFrame
|
|
47
|
+
* loop to redraw the canvas with strokes progressively drawn based on elapsed time.
|
|
48
|
+
* Each frame clears the canvas and redraws all visible strokes.
|
|
49
|
+
*
|
|
50
|
+
* @param {number} nowSec - Current timeline position in seconds
|
|
51
|
+
* @throws {Error} If called after layer is destroyed
|
|
52
|
+
* @override
|
|
53
|
+
*/
|
|
54
|
+
updateTime(t) {
|
|
55
|
+
super.updateTime(t), this.rafId && cancelAnimationFrame(this.rafId);
|
|
56
|
+
const s = () => {
|
|
57
|
+
if (!this.isDestroyed) {
|
|
58
|
+
this.ctx.clearRect(0, 0, this.canvasElement.width, this.canvasElement.height);
|
|
59
|
+
for (const e of this.annotations) {
|
|
60
|
+
if (t < e.start) continue;
|
|
61
|
+
const o = e.end - e.start, c = Math.min(t - e.start, o);
|
|
62
|
+
for (const i of e.strokes || []) {
|
|
63
|
+
this.ctx.lineCap = "round", this.ctx.lineJoin = "round", this.ctx.strokeStyle = i.color || "#1f2937", this.ctx.lineWidth = i.size || 3, this.ctx.beginPath();
|
|
64
|
+
let n = !1;
|
|
65
|
+
for (const a of i.points) {
|
|
66
|
+
if (a.t > c) break;
|
|
67
|
+
const h = a.x * this.viewport.width, r = a.y * this.viewport.height;
|
|
68
|
+
n ? this.ctx.lineTo(h, r) : (this.ctx.moveTo(h, r), n = !0);
|
|
69
|
+
}
|
|
70
|
+
n && this.ctx.stroke();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.rafId = requestAnimationFrame(s);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
s();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Renders the layer content
|
|
80
|
+
*
|
|
81
|
+
* No-op for DrawingLayer - canvas rendering happens in updateTime() RAF loop.
|
|
82
|
+
* Canvas element is created once in constructor and drawn to continuously.
|
|
83
|
+
*
|
|
84
|
+
* @override
|
|
85
|
+
*/
|
|
86
|
+
render() {
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Updates the visual state of the layer
|
|
90
|
+
*
|
|
91
|
+
* Not used for DrawingLayer - updateTime() handles updates via RAF loop.
|
|
92
|
+
*
|
|
93
|
+
* @override
|
|
94
|
+
*/
|
|
95
|
+
update() {
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Destroys the layer and releases resources
|
|
99
|
+
*
|
|
100
|
+
* Cancels animation loop, clears references, and removes canvas from DOM.
|
|
101
|
+
* Safe to call multiple times (idempotent).
|
|
102
|
+
*
|
|
103
|
+
* @override
|
|
104
|
+
*/
|
|
105
|
+
destroy() {
|
|
106
|
+
this.rafId && (cancelAnimationFrame(this.rafId), this.rafId = null), this.ctx = null, this.canvasElement && this.canvasElement.parentNode && this.canvasElement.parentNode.removeChild(this.canvasElement), this.canvasElement = null, super.destroy();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
p as default
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=index9.js.map
|
|
@@ -0,0 +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 // Initialize animation frame ID\n this.rafId = null;\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 starts progressive stroke drawing\n *\n * Cancels any existing animation loop and starts a new requestAnimationFrame\n * loop to redraw the canvas with strokes progressively drawn based on elapsed time.\n * Each frame clears the canvas and redraws all visible strokes.\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 // Cancel existing RAF to prevent multiple loops\n if (this.rafId) {\n cancelAnimationFrame(this.rafId);\n }\n\n // Start drawing loop\n const draw = () => {\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 // Schedule next frame\n this.rafId = requestAnimationFrame(draw);\n };\n\n // Start the loop\n draw();\n }\n\n /**\n * Renders the layer content\n *\n * No-op for DrawingLayer - canvas rendering happens in updateTime() RAF loop.\n * Canvas element is created once in constructor and drawn to continuously.\n *\n * @override\n */\n render() {\n // No-op: Canvas rendering happens in updateTime() RAF loop\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 updates via RAF loop.\n *\n * @override\n */\n update() {\n // Not used - updateTime handles drawing via RAF loop\n }\n\n /**\n * Destroys the layer and releases resources\n *\n * Cancels animation loop, clears references, and removes canvas from DOM.\n * Safe to call multiple times (idempotent).\n *\n * @override\n */\n destroy() {\n // Cancel animation loop first\n if (this.rafId) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n\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","draw","a","duration","elapsed","stroke","started","point","x","y"],"mappings":";AAkBA,MAAMA,UAAqBC,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUnC,YAAYC,GAAWC,GAAU;AAC/B,UAAMD,GAAWC,CAAQ,GAGzB,KAAK,gBAAgB,SAAS,cAAc,QAAQ,GACpD,KAAK,cAAc,MAAM,WAAW,YACpC,KAAK,cAAc,MAAM,QAAQ,KACjC,KAAK,cAAc,MAAM,gBAAgB,QACzC,KAAK,cAAc,MAAM,SAAS,MAGlC,KAAK,UAAU,YAAY,KAAK,aAAa,GAG7C,KAAK,MAAM,KAAK,cAAc,WAAW,IAAI,GAG7C,KAAK,QAAQ,MAGb,KAAK,aAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,eAAe;AACb,UAAMC,IAAM,OAAO,oBAAoB;AAGvC,SAAK,cAAc,QAAQ,KAAK,MAAM,KAAK,SAAS,QAAQA,CAAG,GAC/D,KAAK,cAAc,SAAS,KAAK,MAAM,KAAK,SAAS,SAASA,CAAG,GAGjE,KAAK,cAAc,MAAM,QAAQ,GAAG,KAAK,SAAS,KAAK,MACvD,KAAK,cAAc,MAAM,SAAS,GAAG,KAAK,SAAS,MAAM,MAGzD,KAAK,IAAI,aAAaA,GAAK,GAAG,GAAGA,GAAK,GAAG,CAAC;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,YAAYD,GAAU;AACpB,UAAM,YAAYA,CAAQ,GAC1B,KAAK,aAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AAK,UACP,qBAAqB,KAAK,KAAK,GAC/B,KAAK,QAAQ,OAIf,KAAK,MAAM,MAGP,KAAK,iBAAiB,KAAK,cAAc,cAC3C,KAAK,cAAc,WAAW,YAAY,KAAK,aAAa,GAE9D,KAAK,gBAAgB,MAGrB,MAAM,QAAO;AAAA,EACf;AACF;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "web-annotation-renderer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Framework-agnostic PDF annotation renderer with timeline synchronization for educational content and interactive documents",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pdf",
|
|
8
|
+
"annotations",
|
|
9
|
+
"renderer",
|
|
10
|
+
"timeline",
|
|
11
|
+
"pdfjs",
|
|
12
|
+
"education",
|
|
13
|
+
"react",
|
|
14
|
+
"canvas",
|
|
15
|
+
"highlights",
|
|
16
|
+
"interactive",
|
|
17
|
+
"viewer",
|
|
18
|
+
"timeline-sync"
|
|
19
|
+
],
|
|
20
|
+
"author": "jhl72e <jhl72e@gmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/jhl72e/pdfAutoAnnotator.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/jhl72e/pdfAutoAnnotator/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/jhl72e/pdfAutoAnnotator#readme",
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist/",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"sideEffects": false,
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "vite build",
|
|
51
|
+
"test": "echo \"Tests not yet implemented\" && exit 0",
|
|
52
|
+
"prepublishOnly": "npm run build",
|
|
53
|
+
"lint": "eslint ."
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"pdfjs-dist": "^5.4.149"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
60
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"react": {
|
|
64
|
+
"optional": false
|
|
65
|
+
},
|
|
66
|
+
"react-dom": {
|
|
67
|
+
"optional": false
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@eslint/js": "^9.36.0",
|
|
72
|
+
"@types/react": "^19.1.13",
|
|
73
|
+
"@types/react-dom": "^19.1.9",
|
|
74
|
+
"@vitejs/plugin-react": "^5.0.3",
|
|
75
|
+
"eslint": "^9.36.0",
|
|
76
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
77
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
78
|
+
"globals": "^16.4.0",
|
|
79
|
+
"puppeteer": "^24.22.0",
|
|
80
|
+
"react": "^19.1.1",
|
|
81
|
+
"react-dom": "^19.1.1",
|
|
82
|
+
"vite": "^7.1.7"
|
|
83
|
+
}
|
|
84
|
+
}
|