web-annotation-renderer 0.6.1 → 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 +26 -24
- package/dist/index.js.map +1 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +2 -2
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.cjs.map +1 -1
- package/dist/index18.js +22 -117
- package/dist/index18.js.map +1 -1
- package/dist/index19.cjs +1 -1
- package/dist/index19.cjs.map +1 -1
- package/dist/index19.js +83 -69
- package/dist/index19.js.map +1 -1
- package/dist/index20.cjs +1 -1
- package/dist/index20.cjs.map +1 -1
- package/dist/index20.js +100 -76
- package/dist/index20.js.map +1 -1
- package/dist/index21.cjs +1 -1
- package/dist/index21.cjs.map +1 -1
- package/dist/index21.js +77 -138
- package/dist/index21.js.map +1 -1
- package/dist/index22.cjs +1 -1
- package/dist/index22.cjs.map +1 -1
- package/dist/index22.js +139 -36
- package/dist/index22.js.map +1 -1
- package/dist/index23.cjs +1 -1
- package/dist/index23.cjs.map +1 -1
- package/dist/index23.js +35 -34
- package/dist/index23.js.map +1 -1
- package/dist/index24.cjs +1 -1
- package/dist/index24.cjs.map +1 -1
- package/dist/index24.js +27 -28
- package/dist/index24.js.map +1 -1
- package/dist/index25.cjs +1 -1
- package/dist/index25.cjs.map +1 -1
- package/dist/index25.js +38 -40
- package/dist/index25.js.map +1 -1
- package/dist/index26.cjs +1 -1
- package/dist/index26.cjs.map +1 -1
- package/dist/index26.js +39 -4
- package/dist/index26.js.map +1 -1
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +4 -4
- package/dist/index28.cjs +1 -1
- package/dist/index28.cjs.map +1 -1
- package/dist/index28.js +5 -71
- package/dist/index28.js.map +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/index30.cjs +1 -1
- package/dist/index30.cjs.map +1 -1
- package/dist/index30.js +4 -991
- package/dist/index30.js.map +1 -1
- 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 +63 -56
- package/dist/index5.js.map +1 -1
- package/dist/index9.cjs +1 -1
- package/dist/index9.cjs.map +1 -1
- package/dist/index9.js +17 -15
- package/dist/index9.js.map +1 -1
- package/package.json +1 -1
package/dist/index19.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index19.cjs","sources":["../src/pen/
|
|
1
|
+
{"version":3,"file":"index19.cjs","sources":["../src/pen/GradualRenderer.js"],"sourcesContent":["import StrokeDrawer from './StrokeDrawer.js';\n\n/**\n * GradualRenderer - Progressive stroke rendering synced to timeline\n *\n * Renders stroke commands with progressive reveal based on current\n * audio/video timeline position.\n *\n * Features:\n * - Progressive stroke reveal synced to audio timeline\n * - High-DPI canvas support for crisp rendering\n * - Efficient single-pass render per timeline update\n * - Accepts timing in seconds (start/end fields)\n *\n * @example\n * const renderer = new GradualRenderer(canvas, { width: 800, height: 600 });\n * renderer.setStrokeCommands(commands);\n * renderer.setTime(1.5); // seconds\n * renderer.render();\n */\nclass GradualRenderer {\n /**\n * Creates a new GradualRenderer instance\n *\n * @param {HTMLCanvasElement} canvas - Canvas element for rendering\n * @param {Object} pdfDimensions - PDF page dimensions\n * @param {number} pdfDimensions.width - Page width in pixels\n * @param {number} pdfDimensions.height - Page height in pixels\n */\n constructor(canvas, pdfDimensions) {\n this.canvas = canvas;\n this.dimensions = { ...pdfDimensions };\n this.ctx = null;\n this.strokeDrawer = null;\n this.strokeCommands = [];\n this.currentTime = 0; // seconds\n this.isDestroyed = false;\n\n this._setupCanvas();\n }\n\n /**\n * Configures canvas for high-DPI rendering\n *\n * @private\n */\n _setupCanvas() {\n const dpr = window.devicePixelRatio || 1;\n const { width, height } = this.dimensions;\n\n // Set canvas buffer resolution (high-res)\n this.canvas.width = Math.round(width * dpr);\n this.canvas.height = Math.round(height * dpr);\n\n // Set canvas display size (CSS)\n this.canvas.style.width = `${width}px`;\n this.canvas.style.height = `${height}px`;\n\n // Get context and scale for DPR\n this.ctx = this.canvas.getContext('2d');\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n // Create stroke drawer\n this.strokeDrawer = new StrokeDrawer(this.ctx, this.dimensions);\n }\n\n /**\n * Sets the stroke commands to render\n *\n * @param {Array} commands - Array of stroke command objects\n * @param {string} commands[].id - Unique stroke identifier\n * @param {Array} commands[].points - [[x, y], ...] normalized coordinates\n * @param {string} commands[].color - Stroke color\n * @param {number} commands[].width - Stroke width in pixels\n * @param {number} commands[].start - Start time in seconds\n * @param {number} commands[].end - End time in seconds\n */\n setStrokeCommands(commands) {\n if (this.isDestroyed) return;\n\n this.strokeCommands = commands || [];\n\n // Sort by start time for efficient rendering\n this.strokeCommands.sort((a, b) => {\n const startA = a.start ?? 0;\n const startB = b.start ?? 0;\n return startA - startB;\n });\n }\n\n /**\n * Sets the current timeline position\n *\n * @param {number} time - Current time in seconds\n */\n setTime(time) {\n if (this.isDestroyed) return;\n this.currentTime = time;\n }\n\n /**\n * Updates dimensions when viewport changes\n *\n * @param {Object} dimensions - New dimensions\n * @param {number} dimensions.width - Width in pixels\n * @param {number} dimensions.height - Height in pixels\n */\n setDimensions(dimensions) {\n if (this.isDestroyed) return;\n\n this.dimensions = { ...dimensions };\n this._setupCanvas();\n }\n\n /**\n * Renders all visible strokes at current timeline position\n *\n * Called once per timeline update. Clears canvas and redraws\n * all strokes with appropriate progress.\n */\n render() {\n if (this.isDestroyed || !this.ctx) return;\n\n // Clear canvas\n this.strokeDrawer.clear();\n\n // Draw each stroke based on timing\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n const end = stroke.end ?? start + 1;\n\n // Skip strokes that haven't started\n if (this.currentTime < start) {\n continue;\n }\n\n // Calculate progress\n const progress = this._calculateProgress(start, end);\n\n // Draw stroke with progress\n this.strokeDrawer.drawStroke(stroke, progress);\n }\n }\n\n /**\n * Calculates stroke progress based on timing\n *\n * @private\n * @param {number} start - Stroke start time in seconds\n * @param {number} end - Stroke end time in seconds\n * @returns {number} Progress from 0 to 1\n */\n _calculateProgress(start, end) {\n if (this.currentTime >= end) {\n return 1.0; // Fully visible\n }\n\n const duration = end - start;\n if (duration <= 0) return 1.0;\n\n const elapsed = this.currentTime - start;\n return Math.max(0, Math.min(1, elapsed / duration));\n }\n\n /**\n * Clears the canvas\n */\n clear() {\n if (this.isDestroyed || !this.strokeDrawer) return;\n this.strokeDrawer.clear();\n }\n\n /**\n * Gets visible stroke count at current time\n *\n * @returns {number} Number of visible strokes\n */\n getVisibleStrokeCount() {\n let count = 0;\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n if (this.currentTime >= start) {\n count++;\n }\n }\n return count;\n }\n\n /**\n * Destroys the renderer and releases resources\n */\n destroy() {\n if (this.isDestroyed) return;\n\n this.strokeCommands = [];\n this.strokeDrawer = null;\n this.ctx = null;\n this.canvas = null;\n this.isDestroyed = true;\n }\n}\n\nexport default GradualRenderer;\n"],"names":["GradualRenderer","canvas","pdfDimensions","dpr","width","height","StrokeDrawer","commands","a","b","startA","startB","time","dimensions","stroke","start","end","progress","duration","elapsed","count"],"mappings":"6IAoBA,MAAMA,CAAgB,CASpB,YAAYC,EAAQC,EAAe,CACjC,KAAK,OAASD,EACd,KAAK,WAAa,CAAE,GAAGC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CAC/C,EACF,CAUA,mBAAmBF,EAAOC,EAAK,CAC7B,GAAI,KAAK,aAAeA,EACtB,MAAO,GAGT,MAAME,EAAWF,EAAMD,EACvB,GAAIG,GAAY,EAAG,MAAO,GAE1B,MAAMC,EAAU,KAAK,YAAcJ,EACnC,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAGI,EAAUD,CAAQ,CAAC,CACpD,CAKA,OAAQ,CACF,KAAK,aAAe,CAAC,KAAK,cAC9B,KAAK,aAAa,MAAK,CACzB,CAOA,uBAAwB,CACtB,IAAIE,EAAQ,EACZ,UAAWN,KAAU,KAAK,eAAgB,CACxC,MAAMC,EAAQD,EAAO,OAAS,EAC1B,KAAK,aAAeC,GACtBK,GAEJ,CACA,OAAOA,CACT,CAKA,SAAU,CACJ,KAAK,cAET,KAAK,eAAiB,CAAA,EACtB,KAAK,aAAe,KACpB,KAAK,IAAM,KACX,KAAK,OAAS,KACd,KAAK,YAAc,GACrB,CACF"}
|
package/dist/index19.js
CHANGED
|
@@ -1,107 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
import n from "./index20.js";
|
|
2
|
+
class h {
|
|
2
3
|
/**
|
|
3
|
-
* Creates a new
|
|
4
|
+
* Creates a new GradualRenderer instance
|
|
4
5
|
*
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {Object}
|
|
7
|
-
* @param {number}
|
|
8
|
-
* @param {number}
|
|
6
|
+
* @param {HTMLCanvasElement} canvas - Canvas element for rendering
|
|
7
|
+
* @param {Object} pdfDimensions - PDF page dimensions
|
|
8
|
+
* @param {number} pdfDimensions.width - Page width in pixels
|
|
9
|
+
* @param {number} pdfDimensions.height - Page height in pixels
|
|
9
10
|
*/
|
|
10
|
-
constructor(t,
|
|
11
|
-
this.
|
|
11
|
+
constructor(t, s) {
|
|
12
|
+
this.canvas = t, this.dimensions = { ...s }, this.ctx = null, this.strokeDrawer = null, this.strokeCommands = [], this.currentTime = 0, this.isDestroyed = !1, this._setupCanvas();
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* Configures canvas for high-DPI rendering
|
|
15
16
|
*
|
|
16
|
-
* @
|
|
17
|
+
* @private
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
_setupCanvas() {
|
|
20
|
+
const t = window.devicePixelRatio || 1, { width: s, height: e } = this.dimensions;
|
|
21
|
+
this.canvas.width = Math.round(s * t), this.canvas.height = Math.round(e * t), this.canvas.style.width = `${s}px`, this.canvas.style.height = `${e}px`, this.ctx = this.canvas.getContext("2d"), this.ctx.setTransform(t, 0, 0, t, 0, 0), this.strokeDrawer = new n(this.ctx, this.dimensions);
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Sets the stroke commands to render
|
|
23
25
|
*
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {number} [
|
|
26
|
+
* @param {Array} commands - Array of stroke command objects
|
|
27
|
+
* @param {string} commands[].id - Unique stroke identifier
|
|
28
|
+
* @param {Array} commands[].points - [[x, y], ...] normalized coordinates
|
|
29
|
+
* @param {string} commands[].color - Stroke color
|
|
30
|
+
* @param {number} commands[].width - Stroke width in pixels
|
|
31
|
+
* @param {number} commands[].start - Start time in seconds
|
|
32
|
+
* @param {number} commands[].end - End time in seconds
|
|
30
33
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
setStrokeCommands(t) {
|
|
35
|
+
this.isDestroyed || (this.strokeCommands = t || [], this.strokeCommands.sort((s, e) => {
|
|
36
|
+
const r = s.start ?? 0, i = e.start ?? 0;
|
|
37
|
+
return r - i;
|
|
38
|
+
}));
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
|
-
*
|
|
41
|
+
* Sets the current timeline position
|
|
39
42
|
*
|
|
40
|
-
* @
|
|
41
|
-
* @param {Array} points - Array of [x, y] normalized coordinates
|
|
42
|
-
* @param {number} width - Stroke width in pixels
|
|
43
|
+
* @param {number} time - Current time in seconds
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
for (let i = 0; i < t.length; i++) {
|
|
47
|
-
const [e, s] = this._normalizedToPixel(t[i]);
|
|
48
|
-
i === 0 ? this.ctx.moveTo(e, s) : this.ctx.lineTo(e, s);
|
|
49
|
-
}
|
|
50
|
-
this.ctx.stroke();
|
|
45
|
+
setTime(t) {
|
|
46
|
+
this.isDestroyed || (this.currentTime = t);
|
|
51
47
|
}
|
|
52
48
|
/**
|
|
53
|
-
*
|
|
49
|
+
* Updates dimensions when viewport changes
|
|
54
50
|
*
|
|
55
|
-
*
|
|
51
|
+
* @param {Object} dimensions - New dimensions
|
|
52
|
+
* @param {number} dimensions.width - Width in pixels
|
|
53
|
+
* @param {number} dimensions.height - Height in pixels
|
|
54
|
+
*/
|
|
55
|
+
setDimensions(t) {
|
|
56
|
+
this.isDestroyed || (this.dimensions = { ...t }, this._setupCanvas());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Renders all visible strokes at current timeline position
|
|
56
60
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param {number} baseWidth - Base stroke width in pixels
|
|
60
|
-
* @param {Array} pressures - Pressure values (0-1) for each point
|
|
61
|
+
* Called once per timeline update. Clears canvas and redraws
|
|
62
|
+
* all strokes with appropriate progress.
|
|
61
63
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
render() {
|
|
65
|
+
if (!(this.isDestroyed || !this.ctx)) {
|
|
66
|
+
this.strokeDrawer.clear();
|
|
67
|
+
for (const t of this.strokeCommands) {
|
|
68
|
+
const s = t.start ?? 0, e = t.end ?? s + 1;
|
|
69
|
+
if (this.currentTime < s)
|
|
70
|
+
continue;
|
|
71
|
+
const r = this._calculateProgress(s, e);
|
|
72
|
+
this.strokeDrawer.drawStroke(t, r);
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
/**
|
|
69
|
-
*
|
|
77
|
+
* Calculates stroke progress based on timing
|
|
70
78
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @param {number}
|
|
74
|
-
* @
|
|
75
|
-
* @param {number} radius - Dot radius in pixels
|
|
76
|
-
* @param {string} color - Fill color
|
|
79
|
+
* @private
|
|
80
|
+
* @param {number} start - Stroke start time in seconds
|
|
81
|
+
* @param {number} end - Stroke end time in seconds
|
|
82
|
+
* @returns {number} Progress from 0 to 1
|
|
77
83
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
_calculateProgress(t, s) {
|
|
85
|
+
if (this.currentTime >= s)
|
|
86
|
+
return 1;
|
|
87
|
+
const e = s - t;
|
|
88
|
+
if (e <= 0) return 1;
|
|
89
|
+
const r = this.currentTime - t;
|
|
90
|
+
return Math.max(0, Math.min(1, r / e));
|
|
81
91
|
}
|
|
82
92
|
/**
|
|
83
|
-
* Clears the
|
|
93
|
+
* Clears the canvas
|
|
84
94
|
*/
|
|
85
95
|
clear() {
|
|
86
|
-
|
|
87
|
-
this.ctx.clearRect(0, 0, this.viewport.width * t, this.viewport.height * t);
|
|
96
|
+
this.isDestroyed || !this.strokeDrawer || this.strokeDrawer.clear();
|
|
88
97
|
}
|
|
89
98
|
/**
|
|
90
|
-
*
|
|
99
|
+
* Gets visible stroke count at current time
|
|
91
100
|
*
|
|
92
|
-
* @
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
* @returns {number} Number of visible strokes
|
|
102
|
+
*/
|
|
103
|
+
getVisibleStrokeCount() {
|
|
104
|
+
let t = 0;
|
|
105
|
+
for (const s of this.strokeCommands) {
|
|
106
|
+
const e = s.start ?? 0;
|
|
107
|
+
this.currentTime >= e && t++;
|
|
108
|
+
}
|
|
109
|
+
return t;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Destroys the renderer and releases resources
|
|
95
113
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return [
|
|
99
|
-
o * this.viewport.width,
|
|
100
|
-
i * this.viewport.height
|
|
101
|
-
];
|
|
114
|
+
destroy() {
|
|
115
|
+
this.isDestroyed || (this.strokeCommands = [], this.strokeDrawer = null, this.ctx = null, this.canvas = null, this.isDestroyed = !0);
|
|
102
116
|
}
|
|
103
117
|
}
|
|
104
118
|
export {
|
|
105
|
-
|
|
119
|
+
h as default
|
|
106
120
|
};
|
|
107
121
|
//# sourceMappingURL=index19.js.map
|
package/dist/index19.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index19.js","sources":["../src/pen/
|
|
1
|
+
{"version":3,"file":"index19.js","sources":["../src/pen/GradualRenderer.js"],"sourcesContent":["import StrokeDrawer from './StrokeDrawer.js';\n\n/**\n * GradualRenderer - Progressive stroke rendering synced to timeline\n *\n * Renders stroke commands with progressive reveal based on current\n * audio/video timeline position.\n *\n * Features:\n * - Progressive stroke reveal synced to audio timeline\n * - High-DPI canvas support for crisp rendering\n * - Efficient single-pass render per timeline update\n * - Accepts timing in seconds (start/end fields)\n *\n * @example\n * const renderer = new GradualRenderer(canvas, { width: 800, height: 600 });\n * renderer.setStrokeCommands(commands);\n * renderer.setTime(1.5); // seconds\n * renderer.render();\n */\nclass GradualRenderer {\n /**\n * Creates a new GradualRenderer instance\n *\n * @param {HTMLCanvasElement} canvas - Canvas element for rendering\n * @param {Object} pdfDimensions - PDF page dimensions\n * @param {number} pdfDimensions.width - Page width in pixels\n * @param {number} pdfDimensions.height - Page height in pixels\n */\n constructor(canvas, pdfDimensions) {\n this.canvas = canvas;\n this.dimensions = { ...pdfDimensions };\n this.ctx = null;\n this.strokeDrawer = null;\n this.strokeCommands = [];\n this.currentTime = 0; // seconds\n this.isDestroyed = false;\n\n this._setupCanvas();\n }\n\n /**\n * Configures canvas for high-DPI rendering\n *\n * @private\n */\n _setupCanvas() {\n const dpr = window.devicePixelRatio || 1;\n const { width, height } = this.dimensions;\n\n // Set canvas buffer resolution (high-res)\n this.canvas.width = Math.round(width * dpr);\n this.canvas.height = Math.round(height * dpr);\n\n // Set canvas display size (CSS)\n this.canvas.style.width = `${width}px`;\n this.canvas.style.height = `${height}px`;\n\n // Get context and scale for DPR\n this.ctx = this.canvas.getContext('2d');\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n // Create stroke drawer\n this.strokeDrawer = new StrokeDrawer(this.ctx, this.dimensions);\n }\n\n /**\n * Sets the stroke commands to render\n *\n * @param {Array} commands - Array of stroke command objects\n * @param {string} commands[].id - Unique stroke identifier\n * @param {Array} commands[].points - [[x, y], ...] normalized coordinates\n * @param {string} commands[].color - Stroke color\n * @param {number} commands[].width - Stroke width in pixels\n * @param {number} commands[].start - Start time in seconds\n * @param {number} commands[].end - End time in seconds\n */\n setStrokeCommands(commands) {\n if (this.isDestroyed) return;\n\n this.strokeCommands = commands || [];\n\n // Sort by start time for efficient rendering\n this.strokeCommands.sort((a, b) => {\n const startA = a.start ?? 0;\n const startB = b.start ?? 0;\n return startA - startB;\n });\n }\n\n /**\n * Sets the current timeline position\n *\n * @param {number} time - Current time in seconds\n */\n setTime(time) {\n if (this.isDestroyed) return;\n this.currentTime = time;\n }\n\n /**\n * Updates dimensions when viewport changes\n *\n * @param {Object} dimensions - New dimensions\n * @param {number} dimensions.width - Width in pixels\n * @param {number} dimensions.height - Height in pixels\n */\n setDimensions(dimensions) {\n if (this.isDestroyed) return;\n\n this.dimensions = { ...dimensions };\n this._setupCanvas();\n }\n\n /**\n * Renders all visible strokes at current timeline position\n *\n * Called once per timeline update. Clears canvas and redraws\n * all strokes with appropriate progress.\n */\n render() {\n if (this.isDestroyed || !this.ctx) return;\n\n // Clear canvas\n this.strokeDrawer.clear();\n\n // Draw each stroke based on timing\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n const end = stroke.end ?? start + 1;\n\n // Skip strokes that haven't started\n if (this.currentTime < start) {\n continue;\n }\n\n // Calculate progress\n const progress = this._calculateProgress(start, end);\n\n // Draw stroke with progress\n this.strokeDrawer.drawStroke(stroke, progress);\n }\n }\n\n /**\n * Calculates stroke progress based on timing\n *\n * @private\n * @param {number} start - Stroke start time in seconds\n * @param {number} end - Stroke end time in seconds\n * @returns {number} Progress from 0 to 1\n */\n _calculateProgress(start, end) {\n if (this.currentTime >= end) {\n return 1.0; // Fully visible\n }\n\n const duration = end - start;\n if (duration <= 0) return 1.0;\n\n const elapsed = this.currentTime - start;\n return Math.max(0, Math.min(1, elapsed / duration));\n }\n\n /**\n * Clears the canvas\n */\n clear() {\n if (this.isDestroyed || !this.strokeDrawer) return;\n this.strokeDrawer.clear();\n }\n\n /**\n * Gets visible stroke count at current time\n *\n * @returns {number} Number of visible strokes\n */\n getVisibleStrokeCount() {\n let count = 0;\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n if (this.currentTime >= start) {\n count++;\n }\n }\n return count;\n }\n\n /**\n * Destroys the renderer and releases resources\n */\n destroy() {\n if (this.isDestroyed) return;\n\n this.strokeCommands = [];\n this.strokeDrawer = null;\n this.ctx = null;\n this.canvas = null;\n this.isDestroyed = true;\n }\n}\n\nexport default GradualRenderer;\n"],"names":["GradualRenderer","canvas","pdfDimensions","dpr","width","height","StrokeDrawer","commands","a","b","startA","startB","time","dimensions","stroke","start","end","progress","duration","elapsed","count"],"mappings":";AAoBA,MAAMA,EAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASpB,YAAYC,GAAQC,GAAe;AACjC,SAAK,SAASD,GACd,KAAK,aAAa,EAAE,GAAGC,EAAa,GACpC,KAAK,MAAM,MACX,KAAK,eAAe,MACpB,KAAK,iBAAiB,CAAA,GACtB,KAAK,cAAc,GACnB,KAAK,cAAc,IAEnB,KAAK,aAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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IAAQ;AAGlC,YAAI,KAAK,cAAcA;AACrB;AAIF,cAAME,IAAW,KAAK,mBAAmBF,GAAOC,CAAG;AAGnD,aAAK,aAAa,WAAWF,GAAQG,CAAQ;AAAA,MAC/C;AAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,mBAAmBF,GAAOC,GAAK;AAC7B,QAAI,KAAK,eAAeA;AACtB,aAAO;AAGT,UAAME,IAAWF,IAAMD;AACvB,QAAIG,KAAY,EAAG,QAAO;AAE1B,UAAMC,IAAU,KAAK,cAAcJ;AACnC,WAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAGI,IAAUD,CAAQ,CAAC;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AACN,IAAI,KAAK,eAAe,CAAC,KAAK,gBAC9B,KAAK,aAAa,MAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,wBAAwB;AACtB,QAAIE,IAAQ;AACZ,eAAWN,KAAU,KAAK,gBAAgB;AACxC,YAAMC,IAAQD,EAAO,SAAS;AAC9B,MAAI,KAAK,eAAeC,KACtBK;AAAA,IAEJ;AACA,WAAOA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU;AACR,IAAI,KAAK,gBAET,KAAK,iBAAiB,CAAA,GACtB,KAAK,eAAe,MACpB,KAAK,MAAM,MACX,KAAK,SAAS,MACd,KAAK,cAAc;AAAA,EACrB;AACF;"}
|
package/dist/index20.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class d{constructor(t,o){this.ctx=t,this.viewport=o}setViewport(t){this.viewport=t}drawStroke(t,o=1){const{points:i,color:e,width:s,pressures:h}=t;if(!i||i.length<2)return;const n=Math.max(2,Math.floor(i.length*o)),r=i.slice(0,n);this.ctx.strokeStyle=e||"rgba(0, 0, 0, 0.5)",this.ctx.lineCap="round",this.ctx.lineJoin="round",h&&h.length>=r.length?this._drawVariableWidthStroke(r,s,h.slice(0,n)):this._drawConstantWidthStroke(r,s)}_drawConstantWidthStroke(t,o){this.ctx.lineWidth=o||2,this.ctx.beginPath();for(let i=0;i<t.length;i++){const[e,s]=this._normalizedToPixel(t[i]);i===0?this.ctx.moveTo(e,s):this.ctx.lineTo(e,s)}this.ctx.stroke()}_drawVariableWidthStroke(t,o,i){for(let e=1;e<t.length;e++){const[s,h]=this._normalizedToPixel(t[e-1]),[n,r]=this._normalizedToPixel(t[e]),l=i[e-1]||1,c=i[e]||1,a=(l+c)/2,x=Math.max(.5,o*a);this.ctx.lineWidth=x,this.ctx.beginPath(),this.ctx.moveTo(s,h),this.ctx.lineTo(n,r),this.ctx.stroke()}}drawPoint(t,o,i,e){const[s,h]=this._normalizedToPixel([t,o]);this.ctx.fillStyle=e||"rgba(0, 0, 0, 0.5)",this.ctx.beginPath(),this.ctx.arc(s,h,i,0,Math.PI*2),this.ctx.fill()}clear(){const t=window.devicePixelRatio||1;this.ctx.clearRect(0,0,this.viewport.width*t,this.viewport.height*t)}_normalizedToPixel(t){const[o,i]=t;return[o*this.viewport.width,i*this.viewport.height]}}exports.default=d;
|
|
2
2
|
//# sourceMappingURL=index20.cjs.map
|
package/dist/index20.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index20.cjs","sources":["../src/pen/
|
|
1
|
+
{"version":3,"file":"index20.cjs","sources":["../src/pen/StrokeDrawer.js"],"sourcesContent":["/**\n * StrokeDrawer - Low-level canvas stroke drawing utilities\n *\n * Handles the actual drawing of strokes on canvas with support for:\n * - Progressive stroke reveal (partial drawing based on progress)\n * - Normalized to pixel coordinate conversion\n * - Variable width based on pressure data\n * - Smooth line rendering with round caps/joins\n */\nclass StrokeDrawer {\n /**\n * Creates a new StrokeDrawer instance\n *\n * @param {CanvasRenderingContext2D} ctx - Canvas 2D rendering context\n * @param {Object} viewport - Viewport dimensions for coordinate conversion\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n */\n constructor(ctx, viewport) {\n this.ctx = ctx;\n this.viewport = viewport;\n }\n\n /**\n * Updates the viewport dimensions\n *\n * @param {Object} viewport - New viewport dimensions\n */\n setViewport(viewport) {\n this.viewport = viewport;\n }\n\n /**\n * Draws a stroke with optional progress for progressive reveal\n *\n * @param {Object} stroke - Stroke command object\n * @param {Array} stroke.points - Array of [x, y] normalized coordinates\n * @param {string} stroke.color - Stroke color (CSS color string)\n * @param {number} stroke.width - Base stroke width in pixels\n * @param {Array} [stroke.pressures] - Optional pressure values for variable width\n * @param {number} [progress=1.0] - Progress from 0 to 1 (for progressive reveal)\n */\n drawStroke(stroke, progress = 1.0) {\n const { points, color, width, pressures } = stroke;\n\n if (!points || points.length < 2) return;\n\n // Calculate how many points to draw based on progress\n const pointCount = Math.max(2, Math.floor(points.length * progress));\n const visiblePoints = points.slice(0, pointCount);\n\n // Configure stroke style\n this.ctx.strokeStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.lineCap = 'round';\n this.ctx.lineJoin = 'round';\n\n // Draw with variable width if pressures provided\n if (pressures && pressures.length >= visiblePoints.length) {\n this._drawVariableWidthStroke(visiblePoints, width, pressures.slice(0, pointCount));\n } else {\n this._drawConstantWidthStroke(visiblePoints, width);\n }\n }\n\n /**\n * Draws a stroke with constant width\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} width - Stroke width in pixels\n */\n _drawConstantWidthStroke(points, width) {\n this.ctx.lineWidth = width || 2;\n this.ctx.beginPath();\n\n for (let i = 0; i < points.length; i++) {\n const [px, py] = this._normalizedToPixel(points[i]);\n\n if (i === 0) {\n this.ctx.moveTo(px, py);\n } else {\n this.ctx.lineTo(px, py);\n }\n }\n\n this.ctx.stroke();\n }\n\n /**\n * Draws a stroke with variable width based on pressure\n *\n * Uses multiple line segments with varying widths for natural pen feel.\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} baseWidth - Base stroke width in pixels\n * @param {Array} pressures - Pressure values (0-1) for each point\n */\n _drawVariableWidthStroke(points, baseWidth, pressures) {\n for (let i = 1; i < points.length; i++) {\n const [x1, y1] = this._normalizedToPixel(points[i - 1]);\n const [x2, y2] = this._normalizedToPixel(points[i]);\n\n // Average pressure between two points\n const p1 = pressures[i - 1] || 1;\n const p2 = pressures[i] || 1;\n const avgPressure = (p1 + p2) / 2;\n\n // Apply pressure to width (min 0.5, max 2x base width)\n const width = Math.max(0.5, baseWidth * avgPressure);\n\n this.ctx.lineWidth = width;\n this.ctx.beginPath();\n this.ctx.moveTo(x1, y1);\n this.ctx.lineTo(x2, y2);\n this.ctx.stroke();\n }\n }\n\n /**\n * Draws a single point (dot)\n *\n * Useful for single-point strokes or debugging.\n *\n * @param {number} x - Normalized x coordinate (0-1)\n * @param {number} y - Normalized y coordinate (0-1)\n * @param {number} radius - Dot radius in pixels\n * @param {string} color - Fill color\n */\n drawPoint(x, y, radius, color) {\n const [px, py] = this._normalizedToPixel([x, y]);\n\n this.ctx.fillStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.beginPath();\n this.ctx.arc(px, py, radius, 0, Math.PI * 2);\n this.ctx.fill();\n }\n\n /**\n * Clears the entire canvas\n */\n clear() {\n const dpr = window.devicePixelRatio || 1;\n this.ctx.clearRect(0, 0, this.viewport.width * dpr, this.viewport.height * dpr);\n }\n\n /**\n * Converts normalized coordinates (0-1) to pixel coordinates\n *\n * @private\n * @param {Array} point - [x, y] normalized coordinates\n * @returns {Array} [x, y] pixel coordinates\n */\n _normalizedToPixel(point) {\n const [normX, normY] = point;\n return [\n normX * this.viewport.width,\n normY * this.viewport.height\n ];\n }\n}\n\nexport default StrokeDrawer;\n"],"names":["StrokeDrawer","ctx","viewport","stroke","progress","points","color","width","pressures","pointCount","visiblePoints","px","py","baseWidth","i","x1","y1","x2","y2","p1","p2","avgPressure","x","y","radius","dpr","point","normX","normY"],"mappings":"4GASA,MAAMA,CAAa,CASjB,YAAYC,EAAKC,EAAU,CACzB,KAAK,IAAMD,EACX,KAAK,SAAWC,CAClB,CAOA,YAAYA,EAAU,CACpB,KAAK,SAAWA,CAClB,CAYA,WAAWC,EAAQC,EAAW,EAAK,CACjC,KAAM,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAAC,EAAO,UAAAC,CAAS,EAAKL,EAE5C,GAAI,CAACE,GAAUA,EAAO,OAAS,EAAG,OAGlC,MAAMI,EAAa,KAAK,IAAI,EAAG,KAAK,MAAMJ,EAAO,OAASD,CAAQ,CAAC,EAC7DM,EAAgBL,EAAO,MAAM,EAAGI,CAAU,EAGhD,KAAK,IAAI,YAAcH,GAAS,qBAChC,KAAK,IAAI,QAAU,QACnB,KAAK,IAAI,SAAW,QAGhBE,GAAaA,EAAU,QAAUE,EAAc,OACjD,KAAK,yBAAyBA,EAAeH,EAAOC,EAAU,MAAM,EAAGC,CAAU,CAAC,EAElF,KAAK,yBAAyBC,EAAeH,CAAK,CAEtD,CASA,yBAAyBF,EAAQE,EAAO,CACtC,KAAK,IAAI,UAAYA,GAAS,EAC9B,KAAK,IAAI,UAAS,EAElB,QAAS,EAAI,EAAG,EAAIF,EAAO,OAAQ,IAAK,CACtC,KAAM,CAACM,EAAIC,CAAE,EAAI,KAAK,mBAAmBP,EAAO,CAAC,CAAC,EAE9C,IAAM,EACR,KAAK,IAAI,OAAOM,EAAIC,CAAE,EAEtB,KAAK,IAAI,OAAOD,EAAIC,CAAE,CAE1B,CAEA,KAAK,IAAI,OAAM,CACjB,CAYA,yBAAyBP,EAAQQ,EAAWL,EAAW,CACrD,QAASM,EAAI,EAAGA,EAAIT,EAAO,OAAQS,IAAK,CACtC,KAAM,CAACC,EAAIC,CAAE,EAAI,KAAK,mBAAmBX,EAAOS,EAAI,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|
-
width: 2
|
|
17
|
-
},
|
|
18
|
-
circle: {
|
|
19
|
-
color: "rgba(255, 140, 0, 1.0)",
|
|
20
|
-
width: 3
|
|
1
|
+
class w {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new StrokeDrawer instance
|
|
4
|
+
*
|
|
5
|
+
* @param {CanvasRenderingContext2D} ctx - Canvas 2D rendering context
|
|
6
|
+
* @param {Object} viewport - Viewport dimensions for coordinate conversion
|
|
7
|
+
* @param {number} viewport.width - Viewport width in pixels
|
|
8
|
+
* @param {number} viewport.height - Viewport height in pixels
|
|
9
|
+
*/
|
|
10
|
+
constructor(t, o) {
|
|
11
|
+
this.ctx = t, this.viewport = o;
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
width: 2
|
|
30
|
-
},
|
|
31
|
-
underline: {
|
|
32
|
-
color: "rgba(30, 64, 175, 1.0)",
|
|
33
|
-
width: 2
|
|
34
|
-
},
|
|
35
|
-
arrow: {
|
|
36
|
-
color: "rgba(30, 64, 175, 1.0)",
|
|
37
|
-
width: 2
|
|
38
|
-
},
|
|
39
|
-
circle: {
|
|
40
|
-
color: "rgba(30, 64, 175, 1.0)",
|
|
41
|
-
width: 3
|
|
13
|
+
/**
|
|
14
|
+
* Updates the viewport dimensions
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} viewport - New viewport dimensions
|
|
17
|
+
*/
|
|
18
|
+
setViewport(t) {
|
|
19
|
+
this.viewport = t;
|
|
42
20
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
width:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Draws a stroke with optional progress for progressive reveal
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} stroke - Stroke command object
|
|
25
|
+
* @param {Array} stroke.points - Array of [x, y] normalized coordinates
|
|
26
|
+
* @param {string} stroke.color - Stroke color (CSS color string)
|
|
27
|
+
* @param {number} stroke.width - Base stroke width in pixels
|
|
28
|
+
* @param {Array} [stroke.pressures] - Optional pressure values for variable width
|
|
29
|
+
* @param {number} [progress=1.0] - Progress from 0 to 1 (for progressive reveal)
|
|
30
|
+
*/
|
|
31
|
+
drawStroke(t, o = 1) {
|
|
32
|
+
const { points: i, color: e, width: s, pressures: h } = t;
|
|
33
|
+
if (!i || i.length < 2) return;
|
|
34
|
+
const n = Math.max(2, Math.floor(i.length * o)), r = i.slice(0, n);
|
|
35
|
+
this.ctx.strokeStyle = e || "rgba(0, 0, 0, 0.5)", this.ctx.lineCap = "round", this.ctx.lineJoin = "round", h && h.length >= r.length ? this._drawVariableWidthStroke(r, s, h.slice(0, n)) : this._drawConstantWidthStroke(r, s);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Draws a stroke with constant width
|
|
39
|
+
*
|
|
40
|
+
* @private
|
|
41
|
+
* @param {Array} points - Array of [x, y] normalized coordinates
|
|
42
|
+
* @param {number} width - Stroke width in pixels
|
|
43
|
+
*/
|
|
44
|
+
_drawConstantWidthStroke(t, o) {
|
|
45
|
+
this.ctx.lineWidth = o || 2, this.ctx.beginPath();
|
|
46
|
+
for (let i = 0; i < t.length; i++) {
|
|
47
|
+
const [e, s] = this._normalizedToPixel(t[i]);
|
|
48
|
+
i === 0 ? this.ctx.moveTo(e, s) : this.ctx.lineTo(e, s);
|
|
49
|
+
}
|
|
50
|
+
this.ctx.stroke();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Draws a stroke with variable width based on pressure
|
|
54
|
+
*
|
|
55
|
+
* Uses multiple line segments with varying widths for natural pen feel.
|
|
56
|
+
*
|
|
57
|
+
* @private
|
|
58
|
+
* @param {Array} points - Array of [x, y] normalized coordinates
|
|
59
|
+
* @param {number} baseWidth - Base stroke width in pixels
|
|
60
|
+
* @param {Array} pressures - Pressure values (0-1) for each point
|
|
61
|
+
*/
|
|
62
|
+
_drawVariableWidthStroke(t, o, i) {
|
|
63
|
+
for (let e = 1; e < t.length; e++) {
|
|
64
|
+
const [s, h] = this._normalizedToPixel(t[e - 1]), [n, r] = this._normalizedToPixel(t[e]), l = i[e - 1] || 1, c = i[e] || 1, a = (l + c) / 2, x = Math.max(0.5, o * a);
|
|
65
|
+
this.ctx.lineWidth = x, this.ctx.beginPath(), this.ctx.moveTo(s, h), this.ctx.lineTo(n, r), this.ctx.stroke();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Draws a single point (dot)
|
|
70
|
+
*
|
|
71
|
+
* Useful for single-point strokes or debugging.
|
|
72
|
+
*
|
|
73
|
+
* @param {number} x - Normalized x coordinate (0-1)
|
|
74
|
+
* @param {number} y - Normalized y coordinate (0-1)
|
|
75
|
+
* @param {number} radius - Dot radius in pixels
|
|
76
|
+
* @param {string} color - Fill color
|
|
77
|
+
*/
|
|
78
|
+
drawPoint(t, o, i, e) {
|
|
79
|
+
const [s, h] = this._normalizedToPixel([t, o]);
|
|
80
|
+
this.ctx.fillStyle = e || "rgba(0, 0, 0, 0.5)", this.ctx.beginPath(), this.ctx.arc(s, h, i, 0, Math.PI * 2), this.ctx.fill();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Clears the entire canvas
|
|
84
|
+
*/
|
|
85
|
+
clear() {
|
|
86
|
+
const t = window.devicePixelRatio || 1;
|
|
87
|
+
this.ctx.clearRect(0, 0, this.viewport.width * t, this.viewport.height * t);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Converts normalized coordinates (0-1) to pixel coordinates
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
* @param {Array} point - [x, y] normalized coordinates
|
|
94
|
+
* @returns {Array} [x, y] pixel coordinates
|
|
95
|
+
*/
|
|
96
|
+
_normalizedToPixel(t) {
|
|
97
|
+
const [o, i] = t;
|
|
98
|
+
return [
|
|
99
|
+
o * this.viewport.width,
|
|
100
|
+
i * this.viewport.height
|
|
101
|
+
];
|
|
63
102
|
}
|
|
64
|
-
}, r = {
|
|
65
|
-
default: o,
|
|
66
|
-
blue: i,
|
|
67
|
-
minimal: l
|
|
68
|
-
};
|
|
69
|
-
function c(t) {
|
|
70
|
-
return r[t] || r.default;
|
|
71
|
-
}
|
|
72
|
-
function e() {
|
|
73
|
-
return Object.keys(r);
|
|
74
103
|
}
|
|
75
104
|
export {
|
|
76
|
-
|
|
77
|
-
o as DEFAULT_PRESET,
|
|
78
|
-
l as MINIMAL_PRESET,
|
|
79
|
-
r as default,
|
|
80
|
-
c as getPreset,
|
|
81
|
-
e as getPresetNames
|
|
105
|
+
w as default
|
|
82
106
|
};
|
|
83
107
|
//# sourceMappingURL=index20.js.map
|