web-annotation-renderer 0.5.1 → 0.5.3
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 +39 -33
- package/dist/index.js.map +1 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.cjs.map +1 -1
- package/dist/index10.js +154 -119
- package/dist/index10.js.map +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.cjs.map +1 -1
- package/dist/index15.js +23 -117
- package/dist/index15.js.map +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.cjs.map +1 -1
- package/dist/index16.js +53 -103
- package/dist/index16.js.map +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.cjs.map +1 -1
- package/dist/index17.js +22 -57
- package/dist/index17.js.map +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.cjs.map +1 -1
- package/dist/index18.js +113 -136
- package/dist/index18.js.map +1 -1
- package/dist/index19.cjs +1 -1
- package/dist/index19.cjs.map +1 -1
- package/dist/index19.js +101 -35
- package/dist/index19.js.map +1 -1
- package/dist/index20.cjs +1 -1
- package/dist/index20.cjs.map +1 -1
- package/dist/index20.js +58 -36
- package/dist/index20.js.map +1 -1
- package/dist/index21.cjs +1 -1
- package/dist/index21.cjs.map +1 -1
- package/dist/index21.js +140 -37
- package/dist/index21.js.map +1 -1
- package/dist/index22.cjs +1 -1
- package/dist/index22.cjs.map +1 -1
- package/dist/index22.js +37 -21
- package/dist/index22.js.map +1 -1
- package/dist/index23.cjs +1 -1
- package/dist/index23.cjs.map +1 -1
- package/dist/index23.js +37 -5
- package/dist/index23.js.map +1 -1
- package/dist/index24.cjs +1 -1
- package/dist/index24.cjs.map +1 -1
- package/dist/index24.js +37 -4
- package/dist/index24.js.map +1 -1
- package/dist/index25.cjs +2 -0
- package/dist/index25.cjs.map +1 -0
- package/dist/index25.js +43 -0
- package/dist/index25.js.map +1 -0
- package/dist/index26.cjs +2 -0
- package/dist/index26.cjs.map +1 -0
- package/dist/index26.js +8 -0
- package/dist/index26.js.map +1 -0
- package/dist/index27.cjs +2 -0
- package/dist/index27.cjs.map +1 -0
- package/dist/index27.js +8 -0
- package/dist/index27.js.map +1 -0
- package/dist/index5.cjs +1 -1
- package/dist/index5.cjs.map +1 -1
- package/dist/index5.js +57 -36
- package/dist/index5.js.map +1 -1
- package/package.json +1 -1
package/dist/index15.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index15.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index15.cjs","sources":["../src/converters/underline.js"],"sourcesContent":["/**\n * Underline Converter - Converts underline annotations to stroke commands\n *\n * Transforms quads into horizontal stroke paths at the bottom edge\n * that can be rendered progressively on canvas.\n *\n * @module converters/underline\n */\n\n/**\n * Converts an underline annotation to stroke commands\n *\n * Each quad in the annotation becomes a horizontal stroke at the\n * bottom edge of the quad. Multiple quads are staggered in timing.\n *\n * @param {Object} annotation - Underline annotation object\n * @param {string} annotation.id - Unique identifier\n * @param {number} annotation.start - Start time in seconds\n * @param {number} annotation.end - End time in seconds\n * @param {Array<{x: number, y: number, w: number, h: number}>} annotation.quads - Array of quads\n * @param {Object} [annotation.style] - Optional style overrides\n * @param {Object} style - Resolved style configuration\n * @param {string} style.color - Stroke color\n * @param {number} style.width - Stroke width in pixels\n * @param {string} [style.lineCap='round'] - Line cap style\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function underlineToStrokes(annotation, style) {\n const { id, start, end, quads } = annotation;\n\n if (!quads || quads.length === 0) {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const quadCount = quads.length;\n const quadDuration = totalDuration / quadCount;\n\n for (let i = 0; i < quads.length; i++) {\n const quad = quads[i];\n const { x, y, w, h } = quad;\n\n // Line at bottom edge of quad\n const lineY = y + h;\n const points = [\n [x, lineY],\n [x + w, lineY]\n ];\n\n // Calculate timing for this quad\n const quadStart = start + i * quadDuration;\n const quadEnd = quadStart + quadDuration;\n\n strokes.push({\n id: `${id}-${i}`,\n points,\n start: quadStart,\n end: quadEnd,\n color: style.color || 'rgba(0, 0, 255, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n }\n\n return strokes;\n}\n\nexport default underlineToStrokes;\n"],"names":["underlineToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","i","quad","x","y","w","h","lineY","points","quadStart","quadEnd"],"mappings":"4GA2BO,SAASA,EAAmBC,EAAYC,EAAO,CACpD,KAAM,CAAE,GAAAC,EAAI,MAAAC,EAAO,IAAAC,EAAK,MAAAC,CAAK,EAAKL,EAElC,GAAI,CAACK,GAASA,EAAM,SAAW,EAC7B,MAAO,CAAA,EAGT,MAAMC,EAAU,CAAA,EACVC,EAAgBH,EAAMD,EACtBK,EAAYH,EAAM,OAClBI,EAAeF,EAAgBC,EAErC,QAASE,EAAI,EAAGA,EAAIL,EAAM,OAAQK,IAAK,CACrC,MAAMC,EAAON,EAAMK,CAAC,EACd,CAAE,EAAAE,EAAG,EAAAC,EAAG,EAAAC,EAAG,EAAAC,CAAC,EAAKJ,EAGjBK,EAAQH,EAAIE,EACZE,EAAS,CACb,CAACL,EAAGI,CAAK,EACT,CAACJ,EAAIE,EAAGE,CAAK,CACnB,EAGUE,EAAYf,EAAQO,EAAID,EACxBU,EAAUD,EAAYT,EAE5BH,EAAQ,KAAK,CACX,GAAI,GAAGJ,CAAE,IAAIQ,CAAC,GACd,OAAAO,EACA,MAAOC,EACP,IAAKC,EACL,MAAOlB,EAAM,OAAS,uBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,OAChC,CAAK,CACH,CAEA,OAAOK,CACT"}
|
package/dist/index15.js
CHANGED
|
@@ -1,121 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Sets the stroke commands to render
|
|
25
|
-
*
|
|
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
|
|
33
|
-
*/
|
|
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
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Sets the current timeline position
|
|
42
|
-
*
|
|
43
|
-
* @param {number} time - Current time in seconds
|
|
44
|
-
*/
|
|
45
|
-
setTime(t) {
|
|
46
|
-
this.isDestroyed || (this.currentTime = t);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Updates dimensions when viewport changes
|
|
50
|
-
*
|
|
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
|
|
60
|
-
*
|
|
61
|
-
* Called once per timeline update. Clears canvas and redraws
|
|
62
|
-
* all strokes with appropriate progress.
|
|
63
|
-
*/
|
|
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
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Calculates stroke progress based on timing
|
|
78
|
-
*
|
|
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
|
|
83
|
-
*/
|
|
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));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Clears the canvas
|
|
94
|
-
*/
|
|
95
|
-
clear() {
|
|
96
|
-
this.isDestroyed || !this.strokeDrawer || this.strokeDrawer.clear();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Gets visible stroke count at current time
|
|
100
|
-
*
|
|
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
|
|
113
|
-
*/
|
|
114
|
-
destroy() {
|
|
115
|
-
this.isDestroyed || (this.strokeCommands = [], this.strokeDrawer = null, this.ctx = null, this.canvas = null, this.isDestroyed = !0);
|
|
116
|
-
}
|
|
1
|
+
function x(c, o) {
|
|
2
|
+
const { id: i, start: r, end: l, quads: t } = c;
|
|
3
|
+
if (!t || t.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const s = [], h = l - r, q = t.length, a = h / q;
|
|
6
|
+
for (let n = 0; n < t.length; n++) {
|
|
7
|
+
const p = t[n], { x: d, y: f, w: g, h: w } = p, u = f + w, C = [
|
|
8
|
+
[d, u],
|
|
9
|
+
[d + g, u]
|
|
10
|
+
], e = r + n * a, k = e + a;
|
|
11
|
+
s.push({
|
|
12
|
+
id: `${i}-${n}`,
|
|
13
|
+
points: C,
|
|
14
|
+
start: e,
|
|
15
|
+
end: k,
|
|
16
|
+
color: o.color || "rgba(0, 0, 255, 0.8)",
|
|
17
|
+
width: o.width || 2,
|
|
18
|
+
lineCap: o.lineCap || "round"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return s;
|
|
117
22
|
}
|
|
118
23
|
export {
|
|
119
|
-
|
|
24
|
+
x as default,
|
|
25
|
+
x as underlineToStrokes
|
|
120
26
|
};
|
|
121
27
|
//# sourceMappingURL=index15.js.map
|
package/dist/index15.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index15.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index15.js","sources":["../src/converters/underline.js"],"sourcesContent":["/**\n * Underline Converter - Converts underline annotations to stroke commands\n *\n * Transforms quads into horizontal stroke paths at the bottom edge\n * that can be rendered progressively on canvas.\n *\n * @module converters/underline\n */\n\n/**\n * Converts an underline annotation to stroke commands\n *\n * Each quad in the annotation becomes a horizontal stroke at the\n * bottom edge of the quad. Multiple quads are staggered in timing.\n *\n * @param {Object} annotation - Underline annotation object\n * @param {string} annotation.id - Unique identifier\n * @param {number} annotation.start - Start time in seconds\n * @param {number} annotation.end - End time in seconds\n * @param {Array<{x: number, y: number, w: number, h: number}>} annotation.quads - Array of quads\n * @param {Object} [annotation.style] - Optional style overrides\n * @param {Object} style - Resolved style configuration\n * @param {string} style.color - Stroke color\n * @param {number} style.width - Stroke width in pixels\n * @param {string} [style.lineCap='round'] - Line cap style\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function underlineToStrokes(annotation, style) {\n const { id, start, end, quads } = annotation;\n\n if (!quads || quads.length === 0) {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const quadCount = quads.length;\n const quadDuration = totalDuration / quadCount;\n\n for (let i = 0; i < quads.length; i++) {\n const quad = quads[i];\n const { x, y, w, h } = quad;\n\n // Line at bottom edge of quad\n const lineY = y + h;\n const points = [\n [x, lineY],\n [x + w, lineY]\n ];\n\n // Calculate timing for this quad\n const quadStart = start + i * quadDuration;\n const quadEnd = quadStart + quadDuration;\n\n strokes.push({\n id: `${id}-${i}`,\n points,\n start: quadStart,\n end: quadEnd,\n color: style.color || 'rgba(0, 0, 255, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n }\n\n return strokes;\n}\n\nexport default underlineToStrokes;\n"],"names":["underlineToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","i","quad","x","y","w","h","lineY","points","quadStart","quadEnd"],"mappings":"AA2BO,SAASA,EAAmBC,GAAYC,GAAO;AACpD,QAAM,EAAE,IAAAC,GAAI,OAAAC,GAAO,KAAAC,GAAK,OAAAC,EAAK,IAAKL;AAElC,MAAI,CAACK,KAASA,EAAM,WAAW;AAC7B,WAAO,CAAA;AAGT,QAAMC,IAAU,CAAA,GACVC,IAAgBH,IAAMD,GACtBK,IAAYH,EAAM,QAClBI,IAAeF,IAAgBC;AAErC,WAASE,IAAI,GAAGA,IAAIL,EAAM,QAAQK,KAAK;AACrC,UAAMC,IAAON,EAAMK,CAAC,GACd,EAAE,GAAAE,GAAG,GAAAC,GAAG,GAAAC,GAAG,GAAAC,EAAC,IAAKJ,GAGjBK,IAAQH,IAAIE,GACZE,IAAS;AAAA,MACb,CAACL,GAAGI,CAAK;AAAA,MACT,CAACJ,IAAIE,GAAGE,CAAK;AAAA,IACnB,GAGUE,IAAYf,IAAQO,IAAID,GACxBU,IAAUD,IAAYT;AAE5B,IAAAH,EAAQ,KAAK;AAAA,MACX,IAAI,GAAGJ,CAAE,IAAIQ,CAAC;AAAA,MACd,QAAAO;AAAA,MACA,OAAOC;AAAA,MACP,KAAKC;AAAA,MACL,OAAOlB,EAAM,SAAS;AAAA,MACtB,OAAOA,EAAM,SAAS;AAAA,MACtB,SAASA,EAAM,WAAW;AAAA,IAChC,CAAK;AAAA,EACH;AAEA,SAAOK;AACT;"}
|
package/dist/index16.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"}});function w(C,t){const{id:h,start:e,end:S,from_x:r,from_y:i,to_x:o,to_y:n}=C;if(typeof r!="number"||typeof i!="number"||typeof o!="number"||typeof n!="number")return[];const a=[],p=S-e,f=p*.7,_=p*.3,g=20,M=[];for(let l=0;l<=g;l++){const m=l/g;M.push([r+(o-r)*m,i+(n-i)*m])}a.push({id:`${h}-0`,points:M,start:e,end:e+f,color:t.color||"rgba(255, 0, 0, 0.8)",width:t.width||2,lineCap:t.lineCap||"round"});const D=Math.sqrt((o-r)**2+(n-i)**2),s=Math.min(D*.2,.03),c=Math.atan2(n-i,o-r),u=Math.PI/6,P=[[o,n],[o-s*Math.cos(c-u),n-s*Math.sin(c-u)]],k=[[o,n],[o-s*Math.cos(c+u),n-s*Math.sin(c+u)]],d=e+f,b=_/2;return a.push({id:`${h}-1`,points:P,start:d,end:d+b,color:t.color||"rgba(255, 0, 0, 0.8)",width:t.width||2,lineCap:t.lineCap||"round"}),a.push({id:`${h}-2`,points:k,start:d,end:d+b,color:t.color||"rgba(255, 0, 0, 0.8)",width:t.width||2,lineCap:t.lineCap||"round"}),a}exports.arrowToStrokes=w;exports.default=w;
|
|
2
2
|
//# sourceMappingURL=index16.cjs.map
|
package/dist/index16.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index16.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index16.cjs","sources":["../src/converters/arrow.js"],"sourcesContent":["/**\n * Arrow Converter - Converts arrow annotations to stroke commands\n *\n * Transforms arrow data into a line stroke with arrowhead strokes\n * that can be rendered progressively on canvas.\n *\n * @module converters/arrow\n */\n\n/**\n * Converts an arrow annotation to stroke commands\n *\n * Creates a main line stroke from source to target, followed by\n * two wing strokes forming the arrowhead. Line draws first (70%),\n * then arrowhead (30%).\n *\n * @param {Object} annotation - Arrow annotation object\n * @param {string} annotation.id - Unique identifier\n * @param {number} annotation.start - Start time in seconds\n * @param {number} annotation.end - End time in seconds\n * @param {number} annotation.from_x - Source x position (0-1 normalized)\n * @param {number} annotation.from_y - Source y position (0-1 normalized)\n * @param {number} annotation.to_x - Target x position (0-1 normalized)\n * @param {number} annotation.to_y - Target y position (0-1 normalized)\n * @param {Object} [annotation.style] - Optional style overrides\n * @param {Object} style - Resolved style configuration\n * @param {string} style.color - Stroke color\n * @param {number} style.width - Stroke width in pixels\n * @param {string} [style.lineCap='round'] - Line cap style\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function arrowToStrokes(annotation, style) {\n const { id, start, end, from_x, from_y, to_x, to_y } = annotation;\n\n if (typeof from_x !== 'number' || typeof from_y !== 'number' ||\n typeof to_x !== 'number' || typeof to_y !== 'number') {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const lineDuration = totalDuration * 0.7;\n const headDuration = totalDuration * 0.3;\n\n // Subdivide line for smooth progressive reveal\n const numPoints = 20;\n const linePoints = [];\n for (let i = 0; i <= numPoints; i++) {\n const t = i / numPoints;\n linePoints.push([\n from_x + (to_x - from_x) * t,\n from_y + (to_y - from_y) * t\n ]);\n }\n\n // Main line stroke\n strokes.push({\n id: `${id}-0`,\n points: linePoints,\n start: start,\n end: start + lineDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n // Arrow head calculation\n const lineLength = Math.sqrt((to_x - from_x) ** 2 + (to_y - from_y) ** 2);\n const headSize = Math.min(lineLength * 0.2, 0.03);\n const angle = Math.atan2(to_y - from_y, to_x - from_x);\n const headAngle = Math.PI / 6; // 30 degrees\n\n // Left wing\n const leftWing = [\n [to_x, to_y],\n [\n to_x - headSize * Math.cos(angle - headAngle),\n to_y - headSize * Math.sin(angle - headAngle)\n ]\n ];\n\n // Right wing\n const rightWing = [\n [to_x, to_y],\n [\n to_x - headSize * Math.cos(angle + headAngle),\n to_y - headSize * Math.sin(angle + headAngle)\n ]\n ];\n\n const headStart = start + lineDuration;\n const wingDuration = headDuration / 2;\n\n strokes.push({\n id: `${id}-1`,\n points: leftWing,\n start: headStart,\n end: headStart + wingDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n strokes.push({\n id: `${id}-2`,\n points: rightWing,\n start: headStart,\n end: headStart + wingDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n return strokes;\n}\n\nexport default arrowToStrokes;\n"],"names":["arrowToStrokes","annotation","style","id","start","end","from_x","from_y","to_x","to_y","strokes","totalDuration","lineDuration","headDuration","numPoints","linePoints","i","t","lineLength","headSize","angle","headAngle","leftWing","rightWing","headStart","wingDuration"],"mappings":"4GA+BO,SAASA,EAAeC,EAAYC,EAAO,CAChD,KAAM,CAAE,GAAAC,EAAI,MAAAC,EAAO,IAAAC,EAAK,OAAAC,EAAQ,OAAAC,EAAQ,KAAAC,EAAM,KAAAC,CAAI,EAAKR,EAEvD,GAAI,OAAOK,GAAW,UAAY,OAAOC,GAAW,UAChD,OAAOC,GAAS,UAAY,OAAOC,GAAS,SAC9C,MAAO,CAAA,EAGT,MAAMC,EAAU,CAAA,EACVC,EAAgBN,EAAMD,EACtBQ,EAAeD,EAAgB,GAC/BE,EAAeF,EAAgB,GAG/BG,EAAY,GACZC,EAAa,CAAA,EACnB,QAASC,EAAI,EAAGA,GAAKF,EAAWE,IAAK,CACnC,MAAMC,EAAID,EAAIF,EACdC,EAAW,KAAK,CACdT,GAAUE,EAAOF,GAAUW,EAC3BV,GAAUE,EAAOF,GAAUU,CACjC,CAAK,CACH,CAGAP,EAAQ,KAAK,CACX,GAAI,GAAGP,CAAE,KACT,OAAQY,EACR,MAAOX,EACP,IAAKA,EAAQQ,EACb,MAAOV,EAAM,OAAS,uBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,OAC9B,CAAG,EAGD,MAAMgB,EAAa,KAAK,MAAMV,EAAOF,IAAW,GAAKG,EAAOF,IAAW,CAAC,EAClEY,EAAW,KAAK,IAAID,EAAa,GAAK,GAAI,EAC1CE,EAAQ,KAAK,MAAMX,EAAOF,EAAQC,EAAOF,CAAM,EAC/Ce,EAAY,KAAK,GAAK,EAGtBC,EAAW,CACf,CAACd,EAAMC,CAAI,EACX,CACED,EAAOW,EAAW,KAAK,IAAIC,EAAQC,CAAS,EAC5CZ,EAAOU,EAAW,KAAK,IAAIC,EAAQC,CAAS,CAClD,CACA,EAGQE,EAAY,CAChB,CAACf,EAAMC,CAAI,EACX,CACED,EAAOW,EAAW,KAAK,IAAIC,EAAQC,CAAS,EAC5CZ,EAAOU,EAAW,KAAK,IAAIC,EAAQC,CAAS,CAClD,CACA,EAEQG,EAAYpB,EAAQQ,EACpBa,EAAeZ,EAAe,EAEpC,OAAAH,EAAQ,KAAK,CACX,GAAI,GAAGP,CAAE,KACT,OAAQmB,EACR,MAAOE,EACP,IAAKA,EAAYC,EACjB,MAAOvB,EAAM,OAAS,uBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,OAC9B,CAAG,EAEDQ,EAAQ,KAAK,CACX,GAAI,GAAGP,CAAE,KACT,OAAQoB,EACR,MAAOC,EACP,IAAKA,EAAYC,EACjB,MAAOvB,EAAM,OAAS,uBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,OAC9B,CAAG,EAEMQ,CACT"}
|
package/dist/index16.js
CHANGED
|
@@ -1,107 +1,57 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
];
|
|
102
|
-
}
|
|
1
|
+
function S(b, t) {
|
|
2
|
+
const { id: u, start: a, end: C, from_x: i, from_y: r, to_x: n, to_y: o } = b;
|
|
3
|
+
if (typeof i != "number" || typeof r != "number" || typeof n != "number" || typeof o != "number")
|
|
4
|
+
return [];
|
|
5
|
+
const s = [], l = C - a, f = l * 0.7, D = l * 0.3, g = 20, m = [];
|
|
6
|
+
for (let p = 0; p <= g; p++) {
|
|
7
|
+
const M = p / g;
|
|
8
|
+
m.push([
|
|
9
|
+
i + (n - i) * M,
|
|
10
|
+
r + (o - r) * M
|
|
11
|
+
]);
|
|
12
|
+
}
|
|
13
|
+
s.push({
|
|
14
|
+
id: `${u}-0`,
|
|
15
|
+
points: m,
|
|
16
|
+
start: a,
|
|
17
|
+
end: a + f,
|
|
18
|
+
color: t.color || "rgba(255, 0, 0, 0.8)",
|
|
19
|
+
width: t.width || 2,
|
|
20
|
+
lineCap: t.lineCap || "round"
|
|
21
|
+
});
|
|
22
|
+
const _ = Math.sqrt((n - i) ** 2 + (o - r) ** 2), e = Math.min(_ * 0.2, 0.03), c = Math.atan2(o - r, n - i), h = Math.PI / 6, x = [
|
|
23
|
+
[n, o],
|
|
24
|
+
[
|
|
25
|
+
n - e * Math.cos(c - h),
|
|
26
|
+
o - e * Math.sin(c - h)
|
|
27
|
+
]
|
|
28
|
+
], P = [
|
|
29
|
+
[n, o],
|
|
30
|
+
[
|
|
31
|
+
n - e * Math.cos(c + h),
|
|
32
|
+
o - e * Math.sin(c + h)
|
|
33
|
+
]
|
|
34
|
+
], d = a + f, w = D / 2;
|
|
35
|
+
return s.push({
|
|
36
|
+
id: `${u}-1`,
|
|
37
|
+
points: x,
|
|
38
|
+
start: d,
|
|
39
|
+
end: d + w,
|
|
40
|
+
color: t.color || "rgba(255, 0, 0, 0.8)",
|
|
41
|
+
width: t.width || 2,
|
|
42
|
+
lineCap: t.lineCap || "round"
|
|
43
|
+
}), s.push({
|
|
44
|
+
id: `${u}-2`,
|
|
45
|
+
points: P,
|
|
46
|
+
start: d,
|
|
47
|
+
end: d + w,
|
|
48
|
+
color: t.color || "rgba(255, 0, 0, 0.8)",
|
|
49
|
+
width: t.width || 2,
|
|
50
|
+
lineCap: t.lineCap || "round"
|
|
51
|
+
}), s;
|
|
103
52
|
}
|
|
104
53
|
export {
|
|
105
|
-
|
|
54
|
+
S as arrowToStrokes,
|
|
55
|
+
S as default
|
|
106
56
|
};
|
|
107
57
|
//# sourceMappingURL=index16.js.map
|
package/dist/index16.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index16.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index16.js","sources":["../src/converters/arrow.js"],"sourcesContent":["/**\n * Arrow Converter - Converts arrow annotations to stroke commands\n *\n * Transforms arrow data into a line stroke with arrowhead strokes\n * that can be rendered progressively on canvas.\n *\n * @module converters/arrow\n */\n\n/**\n * Converts an arrow annotation to stroke commands\n *\n * Creates a main line stroke from source to target, followed by\n * two wing strokes forming the arrowhead. Line draws first (70%),\n * then arrowhead (30%).\n *\n * @param {Object} annotation - Arrow annotation object\n * @param {string} annotation.id - Unique identifier\n * @param {number} annotation.start - Start time in seconds\n * @param {number} annotation.end - End time in seconds\n * @param {number} annotation.from_x - Source x position (0-1 normalized)\n * @param {number} annotation.from_y - Source y position (0-1 normalized)\n * @param {number} annotation.to_x - Target x position (0-1 normalized)\n * @param {number} annotation.to_y - Target y position (0-1 normalized)\n * @param {Object} [annotation.style] - Optional style overrides\n * @param {Object} style - Resolved style configuration\n * @param {string} style.color - Stroke color\n * @param {number} style.width - Stroke width in pixels\n * @param {string} [style.lineCap='round'] - Line cap style\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function arrowToStrokes(annotation, style) {\n const { id, start, end, from_x, from_y, to_x, to_y } = annotation;\n\n if (typeof from_x !== 'number' || typeof from_y !== 'number' ||\n typeof to_x !== 'number' || typeof to_y !== 'number') {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const lineDuration = totalDuration * 0.7;\n const headDuration = totalDuration * 0.3;\n\n // Subdivide line for smooth progressive reveal\n const numPoints = 20;\n const linePoints = [];\n for (let i = 0; i <= numPoints; i++) {\n const t = i / numPoints;\n linePoints.push([\n from_x + (to_x - from_x) * t,\n from_y + (to_y - from_y) * t\n ]);\n }\n\n // Main line stroke\n strokes.push({\n id: `${id}-0`,\n points: linePoints,\n start: start,\n end: start + lineDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n // Arrow head calculation\n const lineLength = Math.sqrt((to_x - from_x) ** 2 + (to_y - from_y) ** 2);\n const headSize = Math.min(lineLength * 0.2, 0.03);\n const angle = Math.atan2(to_y - from_y, to_x - from_x);\n const headAngle = Math.PI / 6; // 30 degrees\n\n // Left wing\n const leftWing = [\n [to_x, to_y],\n [\n to_x - headSize * Math.cos(angle - headAngle),\n to_y - headSize * Math.sin(angle - headAngle)\n ]\n ];\n\n // Right wing\n const rightWing = [\n [to_x, to_y],\n [\n to_x - headSize * Math.cos(angle + headAngle),\n to_y - headSize * Math.sin(angle + headAngle)\n ]\n ];\n\n const headStart = start + lineDuration;\n const wingDuration = headDuration / 2;\n\n strokes.push({\n id: `${id}-1`,\n points: leftWing,\n start: headStart,\n end: headStart + wingDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n strokes.push({\n id: `${id}-2`,\n points: rightWing,\n start: headStart,\n end: headStart + wingDuration,\n color: style.color || 'rgba(255, 0, 0, 0.8)',\n width: style.width || 2,\n lineCap: style.lineCap || 'round'\n });\n\n return strokes;\n}\n\nexport default arrowToStrokes;\n"],"names":["arrowToStrokes","annotation","style","id","start","end","from_x","from_y","to_x","to_y","strokes","totalDuration","lineDuration","headDuration","numPoints","linePoints","i","t","lineLength","headSize","angle","headAngle","leftWing","rightWing","headStart","wingDuration"],"mappings":"AA+BO,SAASA,EAAeC,GAAYC,GAAO;AAChD,QAAM,EAAE,IAAAC,GAAI,OAAAC,GAAO,KAAAC,GAAK,QAAAC,GAAQ,QAAAC,GAAQ,MAAAC,GAAM,MAAAC,EAAI,IAAKR;AAEvD,MAAI,OAAOK,KAAW,YAAY,OAAOC,KAAW,YAChD,OAAOC,KAAS,YAAY,OAAOC,KAAS;AAC9C,WAAO,CAAA;AAGT,QAAMC,IAAU,CAAA,GACVC,IAAgBN,IAAMD,GACtBQ,IAAeD,IAAgB,KAC/BE,IAAeF,IAAgB,KAG/BG,IAAY,IACZC,IAAa,CAAA;AACnB,WAASC,IAAI,GAAGA,KAAKF,GAAWE,KAAK;AACnC,UAAMC,IAAID,IAAIF;AACd,IAAAC,EAAW,KAAK;AAAA,MACdT,KAAUE,IAAOF,KAAUW;AAAA,MAC3BV,KAAUE,IAAOF,KAAUU;AAAA,IACjC,CAAK;AAAA,EACH;AAGA,EAAAP,EAAQ,KAAK;AAAA,IACX,IAAI,GAAGP,CAAE;AAAA,IACT,QAAQY;AAAA,IACR,OAAOX;AAAA,IACP,KAAKA,IAAQQ;AAAA,IACb,OAAOV,EAAM,SAAS;AAAA,IACtB,OAAOA,EAAM,SAAS;AAAA,IACtB,SAASA,EAAM,WAAW;AAAA,EAC9B,CAAG;AAGD,QAAMgB,IAAa,KAAK,MAAMV,IAAOF,MAAW,KAAKG,IAAOF,MAAW,CAAC,GAClEY,IAAW,KAAK,IAAID,IAAa,KAAK,IAAI,GAC1CE,IAAQ,KAAK,MAAMX,IAAOF,GAAQC,IAAOF,CAAM,GAC/Ce,IAAY,KAAK,KAAK,GAGtBC,IAAW;AAAA,IACf,CAACd,GAAMC,CAAI;AAAA,IACX;AAAA,MACED,IAAOW,IAAW,KAAK,IAAIC,IAAQC,CAAS;AAAA,MAC5CZ,IAAOU,IAAW,KAAK,IAAIC,IAAQC,CAAS;AAAA,IAClD;AAAA,EACA,GAGQE,IAAY;AAAA,IAChB,CAACf,GAAMC,CAAI;AAAA,IACX;AAAA,MACED,IAAOW,IAAW,KAAK,IAAIC,IAAQC,CAAS;AAAA,MAC5CZ,IAAOU,IAAW,KAAK,IAAIC,IAAQC,CAAS;AAAA,IAClD;AAAA,EACA,GAEQG,IAAYpB,IAAQQ,GACpBa,IAAeZ,IAAe;AAEpC,SAAAH,EAAQ,KAAK;AAAA,IACX,IAAI,GAAGP,CAAE;AAAA,IACT,QAAQmB;AAAA,IACR,OAAOE;AAAA,IACP,KAAKA,IAAYC;AAAA,IACjB,OAAOvB,EAAM,SAAS;AAAA,IACtB,OAAOA,EAAM,SAAS;AAAA,IACtB,SAASA,EAAM,WAAW;AAAA,EAC9B,CAAG,GAEDQ,EAAQ,KAAK;AAAA,IACX,IAAI,GAAGP,CAAE;AAAA,IACT,QAAQoB;AAAA,IACR,OAAOC;AAAA,IACP,KAAKA,IAAYC;AAAA,IACjB,OAAOvB,EAAM,SAAS;AAAA,IACtB,OAAOA,EAAM,SAAS;AAAA,IACtB,SAASA,EAAM,WAAW;AAAA,EAC9B,CAAG,GAEMQ;AACT;"}
|
package/dist/index17.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"}});function a(l,e){const{id:d,start:f,end:p,cx:o,cy:r,rx:n,ry:i}=l;if(typeof o!="number"||typeof r!="number"||typeof n!="number"||typeof i!="number")return[];const u=36,c=[];for(let t=0;t<=u;t++){const s=t/u*Math.PI*2;c.push([o+n*Math.cos(s),r+i*Math.sin(s)])}return[{id:d,points:c,start:f,end:p,color:e.color||"rgba(255, 165, 0, 0.8)",width:e.width||3,lineCap:e.lineCap||"round"}]}exports.circleToStrokes=a;exports.default=a;
|
|
2
2
|
//# sourceMappingURL=index17.cjs.map
|
package/dist/index17.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index17.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index17.cjs","sources":["../src/converters/circle.js"],"sourcesContent":["/**\n * Circle Converter - Converts circle annotations to stroke commands\n *\n * Transforms circle/ellipse data into stroke paths that can be\n * rendered progressively on canvas.\n *\n * @module converters/circle\n */\n\n/**\n * Converts a circle annotation to stroke commands\n *\n * Generates an ellipse path from 0° to 360° that renders\n * progressively around the perimeter.\n *\n * @param {Object} annotation - Circle annotation object\n * @param {string} annotation.id - Unique identifier\n * @param {number} annotation.start - Start time in seconds\n * @param {number} annotation.end - End time in seconds\n * @param {number} annotation.cx - Center x position (0-1 normalized)\n * @param {number} annotation.cy - Center y position (0-1 normalized)\n * @param {number} annotation.rx - Horizontal radius (0-1 normalized)\n * @param {number} annotation.ry - Vertical radius (0-1 normalized)\n * @param {Object} [annotation.style] - Optional style overrides\n * @param {Object} style - Resolved style configuration\n * @param {string} style.color - Stroke color\n * @param {number} style.width - Stroke width in pixels\n * @param {string} [style.lineCap='round'] - Line cap style\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function circleToStrokes(annotation, style) {\n const { id, start, end, cx, cy, rx, ry } = annotation;\n\n if (typeof cx !== 'number' || typeof cy !== 'number' ||\n typeof rx !== 'number' || typeof ry !== 'number') {\n return [];\n }\n\n // Generate ellipse points (36 segments + closing point)\n const numPoints = 36;\n const points = [];\n\n for (let i = 0; i <= numPoints; i++) {\n const angle = (i / numPoints) * Math.PI * 2;\n points.push([\n cx + rx * Math.cos(angle),\n cy + ry * Math.sin(angle)\n ]);\n }\n\n return [{\n id,\n points,\n start,\n end,\n color: style.color || 'rgba(255, 165, 0, 0.8)',\n width: style.width || 3,\n lineCap: style.lineCap || 'round'\n }];\n}\n\nexport default circleToStrokes;\n"],"names":["circleToStrokes","annotation","style","id","start","end","cx","cy","rx","ry","numPoints","points","i","angle"],"mappings":"4GA8BO,SAASA,EAAgBC,EAAYC,EAAO,CACjD,KAAM,CAAE,GAAAC,EAAI,MAAAC,EAAO,IAAAC,EAAK,GAAAC,EAAI,GAAAC,EAAI,GAAAC,EAAI,GAAAC,CAAE,EAAKR,EAE3C,GAAI,OAAOK,GAAO,UAAY,OAAOC,GAAO,UACxC,OAAOC,GAAO,UAAY,OAAOC,GAAO,SAC1C,MAAO,CAAA,EAIT,MAAMC,EAAY,GACZC,EAAS,CAAA,EAEf,QAASC,EAAI,EAAGA,GAAKF,EAAWE,IAAK,CACnC,MAAMC,EAASD,EAAIF,EAAa,KAAK,GAAK,EAC1CC,EAAO,KAAK,CACVL,EAAKE,EAAK,KAAK,IAAIK,CAAK,EACxBN,EAAKE,EAAK,KAAK,IAAII,CAAK,CAC9B,CAAK,CACH,CAEA,MAAO,CAAC,CACN,GAAAV,EACA,OAAAQ,EACA,MAAAP,EACA,IAAAC,EACA,MAAOH,EAAM,OAAS,yBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,OAC9B,CAAG,CACH"}
|