web-annotation-renderer 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +52 -51
  4. package/dist/index.js.map +1 -1
  5. package/dist/index10.cjs +1 -1
  6. package/dist/index10.cjs.map +1 -1
  7. package/dist/index10.js +13 -210
  8. package/dist/index10.js.map +1 -1
  9. package/dist/index11.cjs +1 -1
  10. package/dist/index11.cjs.map +1 -1
  11. package/dist/index11.js +50 -13
  12. package/dist/index11.js.map +1 -1
  13. package/dist/index12.cjs +1 -1
  14. package/dist/index12.cjs.map +1 -1
  15. package/dist/index12.js +155 -48
  16. package/dist/index12.js.map +1 -1
  17. package/dist/index13.cjs +1 -1
  18. package/dist/index13.cjs.map +1 -1
  19. package/dist/index13.js +34 -169
  20. package/dist/index13.js.map +1 -1
  21. package/dist/index14.cjs +1 -1
  22. package/dist/index14.cjs.map +1 -1
  23. package/dist/index14.js +65 -28
  24. package/dist/index14.js.map +1 -1
  25. package/dist/index15.cjs +1 -1
  26. package/dist/index15.cjs.map +1 -1
  27. package/dist/index15.js +33 -71
  28. package/dist/index15.js.map +1 -1
  29. package/dist/index16.cjs +1 -1
  30. package/dist/index16.cjs.map +1 -1
  31. package/dist/index16.js +77 -22
  32. package/dist/index16.js.map +1 -1
  33. package/dist/index17.cjs +1 -1
  34. package/dist/index17.cjs.map +1 -1
  35. package/dist/index17.js +31 -52
  36. package/dist/index17.js.map +1 -1
  37. package/dist/index18.cjs +1 -1
  38. package/dist/index18.cjs.map +1 -1
  39. package/dist/index18.js +22 -23
  40. package/dist/index18.js.map +1 -1
  41. package/dist/index2.cjs +1 -1
  42. package/dist/index2.cjs.map +1 -1
  43. package/dist/index2.js +5 -6
  44. package/dist/index2.js.map +1 -1
  45. package/dist/index21.cjs +1 -1
  46. package/dist/index21.cjs.map +1 -1
  47. package/dist/index21.js +48 -27
  48. package/dist/index21.js.map +1 -1
  49. package/dist/index24.cjs +1 -1
  50. package/dist/index24.js +1 -1
  51. package/dist/index25.cjs +1 -1
  52. package/dist/index25.js +1 -1
  53. package/dist/index29.cjs +1 -1
  54. package/dist/index29.cjs.map +1 -1
  55. package/dist/index29.js +70 -4
  56. package/dist/index29.js.map +1 -1
  57. package/dist/index3.cjs +1 -1
  58. package/dist/index3.js +1 -1
  59. package/dist/index30.cjs +2 -0
  60. package/dist/index30.cjs.map +1 -0
  61. package/dist/index30.js +8 -0
  62. package/dist/index30.js.map +1 -0
  63. package/dist/index31.cjs +2 -0
  64. package/dist/index31.cjs.map +1 -0
  65. package/dist/index31.js +995 -0
  66. package/dist/index31.js.map +1 -0
  67. package/dist/index5.cjs +1 -1
  68. package/dist/index5.cjs.map +1 -1
  69. package/dist/index5.js +189 -80
  70. package/dist/index5.js.map +1 -1
  71. package/dist/index6.cjs +1 -1
  72. package/dist/index6.cjs.map +1 -1
  73. package/dist/index6.js +18 -60
  74. package/dist/index6.js.map +1 -1
  75. package/dist/index7.cjs +1 -1
  76. package/dist/index7.cjs.map +1 -1
  77. package/dist/index7.js +17 -17
  78. package/dist/index7.js.map +1 -1
  79. package/dist/index8.cjs +1 -1
  80. package/dist/index8.cjs.map +1 -1
  81. package/dist/index8.js +125 -16
  82. package/dist/index8.js.map +1 -1
  83. package/dist/index9.cjs +1 -1
  84. package/dist/index9.cjs.map +1 -1
  85. package/dist/index9.js +201 -118
  86. package/dist/index9.js.map +1 -1
  87. package/package.json +4 -2
package/dist/index13.js CHANGED
@@ -1,175 +1,40 @@
1
- import { jsxs as j, jsx as L } from "react/jsx-runtime";
2
- import { useRef as d, useState as Q, useCallback as q, useMemo as z, useEffect as c } from "react";
3
- import { AnnotationRenderer as H } from "./index2.js";
4
- import { getPreset as M } from "./index21.js";
5
- function I({
6
- // Required props
7
- pdfUrl: p,
8
- // Optional props with defaults
9
- page: u = 1,
10
- scale: f = 1.5,
11
- annotations: P = [],
12
- currentTime: h = 0,
13
- // Continuous sync mode (use instead of currentTime for smoother animation)
14
- audioRef: l,
15
- // Stroke configuration
16
- strokeConfig: a,
17
- // Callbacks
18
- onLoad: g,
19
- onError: r,
20
- onPageChange: w,
21
- // Styling
22
- className: x,
23
- style: b,
24
- canvasStyle: k
25
- }) {
26
- const v = d(null), m = d(null), t = d(null), A = d(Promise.resolve()), [i, F] = Q(!1), s = q((e) => {
27
- A.current = A.current.then(e).catch((o) => {
28
- console.error("AnnotPdf: Queued operation failed:", o);
29
- });
30
- }, []), y = z(() => {
31
- if (!a)
32
- return;
33
- const e = a.preset || "default", o = M(e);
34
- return {
35
- highlight: {
36
- color: o.highlight.color,
37
- width: a.highlight?.width ?? o.highlight.width
38
- },
39
- text: {
40
- color: o.handText.color,
41
- width: a.text?.width ?? o.handText.width
42
- }
43
- };
44
- }, [a]);
45
- c(() => {
46
- if (!(!v.current || !m.current)) {
47
- try {
48
- t.current = new H({
49
- canvasElement: v.current,
50
- container: m.current,
51
- strokeConfig: y
52
- }), F(!0);
53
- } catch (e) {
54
- console.error("AnnotPdf: Failed to initialize renderer:", e), r && r(e);
1
+ import { roughLine as L, hashSeed as M } from "./index29.js";
2
+ const o = 1e3;
3
+ function R(h, t) {
4
+ const { id: e, start: r, end: g, quads: s } = h;
5
+ if (!s || s.length === 0)
6
+ return [];
7
+ const i = [], f = g - r, p = s.length, u = f / p, l = t.roughness ?? 0.5, S = t.bowing ?? 0.5, m = t.curveFitting ?? 0.95, C = t.curveStepCount ?? 9, b = t.maxRandomnessOffset ?? 2, q = t.disableMultiStroke ?? !1;
8
+ for (let n = 0; n < s.length; n++) {
9
+ const w = s[n], { x: a, y: k, w: v, h: x } = w, c = k + x / 2, $ = L(
10
+ a * o,
11
+ c * o,
12
+ (a + v) * o,
13
+ c * o,
14
+ {
15
+ roughness: l,
16
+ bowing: S,
17
+ seed: M(`${e}-${n}`),
18
+ curveFitting: m,
19
+ curveStepCount: C,
20
+ maxRandomnessOffset: b,
21
+ disableMultiStroke: q
55
22
  }
56
- return () => {
57
- F(!1), t.current && (t.current.destroy(), t.current = null);
58
- };
59
- }
60
- }, []), c(() => {
61
- if (!i || !p)
62
- return;
63
- let e = !1;
64
- return s(async () => {
65
- if (t.current)
66
- try {
67
- const n = await t.current.loadPDF(p);
68
- if (e) return;
69
- if (!n.success) {
70
- console.error("AnnotPdf: Failed to load PDF:", n.error), r && r(new Error(n.error));
71
- return;
72
- }
73
- g && g({ pageCount: n.pageCount });
74
- } catch (n) {
75
- if (e) return;
76
- console.error("AnnotPdf: Failed to load PDF:", n), r && r(n);
77
- }
78
- }), () => {
79
- e = !0;
80
- };
81
- }, [p, i, s]), c(() => {
82
- !i || !u || typeof u != "number" || s(async () => {
83
- if (t.current)
84
- try {
85
- const e = await t.current.setPage(u);
86
- if (!e.success) {
87
- console.error("AnnotPdf: Failed to set page:", e.error), r && r(new Error(e.error));
88
- return;
89
- }
90
- w && w(u);
91
- } catch (e) {
92
- console.error("AnnotPdf: Failed to set page:", e), r && r(e);
93
- }
94
- });
95
- }, [u, i, s]), c(() => {
96
- !i || !f || typeof f != "number" || s(async () => {
97
- if (t.current)
98
- try {
99
- const e = await t.current.setScale(f);
100
- e.success || (console.error("AnnotPdf: Failed to set scale:", e.error), r && r(new Error(e.error)));
101
- } catch (e) {
102
- console.error("AnnotPdf: Failed to set scale:", e), r && r(e);
103
- }
23
+ ).map(([E, F]) => [E / o, F / o]), d = r + n * u, D = d + u;
24
+ i.push({
25
+ id: `${e}-${n}`,
26
+ points: $,
27
+ start: d,
28
+ end: D,
29
+ color: t.color || "rgba(255, 255, 0, 0.3)",
30
+ width: t.width || 24,
31
+ lineCap: t.lineCap || "butt"
104
32
  });
105
- }, [f, i, s]), c(() => {
106
- if (!(!i || !t.current))
107
- try {
108
- t.current.setAnnotations(P || []);
109
- } catch (e) {
110
- console.error("AnnotPdf: Failed to set annotations:", e), r && r(e);
111
- }
112
- }, [P, i]), c(() => {
113
- if (!l && !(!i || !t.current || h === void 0 || h === null))
114
- try {
115
- t.current.setTime(h);
116
- } catch (e) {
117
- console.error("AnnotPdf: Failed to set time:", e), r && r(e);
118
- }
119
- }, [h, l, i]), c(() => {
120
- if (!l?.current || !i || !t.current)
121
- return;
122
- const e = l.current, o = () => {
123
- t.current && t.current.startContinuousSync(() => e.currentTime);
124
- }, n = () => {
125
- t.current && (t.current.stopContinuousSync(), t.current.setTime(e.currentTime));
126
- }, C = () => {
127
- t.current && t.current.setTime(e.currentTime);
128
- };
129
- return e.addEventListener("play", o), e.addEventListener("pause", n), e.addEventListener("ended", n), e.addEventListener("seeked", C), e.paused || o(), () => {
130
- e.removeEventListener("play", o), e.removeEventListener("pause", n), e.removeEventListener("ended", n), e.removeEventListener("seeked", C), t.current && t.current.stopContinuousSync();
131
- };
132
- }, [l, i]);
133
- const S = d(!0);
134
- c(() => {
135
- if (S.current) {
136
- S.current = !1;
137
- return;
138
- }
139
- if (t.current && y)
140
- try {
141
- t.current.updateStrokeConfig(y);
142
- } catch (e) {
143
- console.error("AnnotPdf: Failed to update stroke config:", e), r && r(e);
144
- }
145
- }, [y]);
146
- const T = {
147
- position: "relative",
148
- display: "inline-block",
149
- lineHeight: 0,
150
- // Remove extra space below canvas
151
- ...b
152
- // User styles override defaults
153
- }, R = {
154
- position: "absolute",
155
- top: 0,
156
- left: 0,
157
- width: "100%",
158
- height: "100%",
159
- pointerEvents: "none",
160
- // Allow clicks to pass through to canvas
161
- overflow: "hidden"
162
- }, D = {
163
- display: "block",
164
- ...k
165
- // User styles override defaults
166
- };
167
- return /* @__PURE__ */ j("div", { className: x, style: T, children: [
168
- /* @__PURE__ */ L("canvas", { ref: v, style: D }),
169
- /* @__PURE__ */ L("div", { ref: m, style: R })
170
- ] });
33
+ }
34
+ return i;
171
35
  }
172
36
  export {
173
- I as default
37
+ R as default,
38
+ R as highlightToStrokes
174
39
  };
175
40
  //# sourceMappingURL=index13.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index13.js","sources":["../src/adapters/AnnotPdf.jsx"],"sourcesContent":["// ============================================================================\n// SECTION 1: IMPORTS\n// ============================================================================\n\nimport { useRef, useEffect, useCallback, useMemo, useState } from 'react';\nimport { AnnotationRenderer } from '../core/AnnotationRenderer.js';\nimport { getPreset } from '../pen/presets.js';\n\n// ============================================================================\n// SECTION 2: JSDOC DOCUMENTATION\n// ============================================================================\n\n/**\n * AnnotPdf - Declarative React component for PDF annotation rendering\n *\n * A React wrapper around the AnnotationRenderer core engine that provides\n * a declarative, props-based API for rendering PDF documents with\n * timeline-synchronized annotations.\n *\n * Features:\n * - Automatic lifecycle management (initialization and cleanup)\n * - Declarative prop-to-method synchronization\n * - PDF rendering with pdf.js\n * - Timeline-synchronized annotation display\n * - Support for highlight, text, and ink annotations\n * - Page navigation and zoom control\n *\n * @component\n * @example\n * // Basic usage\n * <AnnotPdf\n * pdfUrl=\"/document.pdf\"\n * page={1}\n * scale={1.5}\n * annotations={[]}\n * currentTime={0}\n * />\n *\n * @example\n * // With audio synchronization (discrete mode - ~4fps)\n * const [currentTime, setCurrentTime] = useState(0);\n *\n * <div>\n * <AnnotPdf\n * pdfUrl=\"/lecture.pdf\"\n * page={1}\n * scale={1.5}\n * annotations={annotations}\n * currentTime={currentTime}\n * onLoad={({ pageCount }) => console.log('Loaded:', pageCount)}\n * />\n * <audio\n * src=\"/lecture.mp3\"\n * onTimeUpdate={(e) => setCurrentTime(e.target.currentTime)}\n * controls\n * />\n * </div>\n *\n * @example\n * // With audio synchronization (continuous mode - 60fps, smoother)\n * const audioRef = useRef(null);\n *\n * <div>\n * <AnnotPdf\n * pdfUrl=\"/lecture.pdf\"\n * page={1}\n * scale={1.5}\n * annotations={annotations}\n * audioRef={audioRef}\n * onLoad={({ pageCount }) => console.log('Loaded:', pageCount)}\n * />\n * <audio ref={audioRef} src=\"/lecture.mp3\" controls />\n * </div>\n *\n * @param {Object} props - Component props\n * @param {string} props.pdfUrl - PDF document URL (required)\n * @param {number} [props.page=1] - Current page number (1-indexed)\n * @param {number} [props.scale=1.5] - Zoom scale factor\n * @param {Array} [props.annotations=[]] - Array of annotation objects\n * @param {number} [props.currentTime=0] - Timeline position in seconds (discrete mode)\n * @param {React.RefObject<HTMLAudioElement>} [props.audioRef] - Audio element ref for continuous sync (60fps)\n * @param {Function} [props.onLoad] - Callback when PDF loads: ({pageCount}) => void\n * @param {Function} [props.onError] - Callback on error: (error) => void\n * @param {Function} [props.onPageChange] - Callback when page changes: (page) => void\n * @param {Object} [props.strokeConfig] - Stroke rendering configuration\n * @param {string} [props.strokeConfig.preset] - Preset name: 'default', 'blue', 'minimal'\n * @param {Object} [props.strokeConfig.highlight] - Highlight style overrides\n * @param {number} [props.strokeConfig.highlight.width] - Highlight stroke width (16-32)\n * @param {Object} [props.strokeConfig.text] - Text style overrides\n * @param {number} [props.strokeConfig.text.width] - Text stroke width (1-4)\n * @param {string} [props.className] - CSS class for container div\n * @param {Object} [props.style] - Inline styles for container div\n * @param {Object} [props.canvasStyle] - Inline styles for canvas element\n * @returns {JSX.Element} PDF viewer component with annotation layers\n */\n\n// ============================================================================\n// SECTION 3: COMPONENT DEFINITION\n// ============================================================================\n\nfunction AnnotPdf({\n // Required props\n pdfUrl,\n\n // Optional props with defaults\n page = 1,\n scale = 1.5,\n annotations = [],\n currentTime = 0,\n\n // Continuous sync mode (use instead of currentTime for smoother animation)\n audioRef,\n\n // Stroke configuration\n strokeConfig,\n\n // Callbacks\n onLoad,\n onError,\n onPageChange,\n\n // Styling\n className,\n style,\n canvasStyle\n}) {\n\n // ==========================================================================\n // SECTION 4: REFS INITIALIZATION\n // ==========================================================================\n\n /**\n * Reference to the canvas element for PDF rendering\n * @type {React.RefObject<HTMLCanvasElement>}\n */\n const canvasRef = useRef(null);\n\n /**\n * Reference to the layer container div for annotation layers\n * @type {React.RefObject<HTMLDivElement>}\n */\n const layerContainerRef = useRef(null);\n\n /**\n * Reference to the AnnotationRenderer engine instance\n * Stored in ref to avoid triggering re-renders\n * @type {React.RefObject<AnnotationRenderer|null>}\n */\n const engineRef = useRef(null);\n\n /**\n * Reference to the render operation queue\n * Ensures sequential execution of async canvas operations\n * Prevents PDF.js race condition: \"Cannot use the same canvas during multiple render() operations\"\n * @type {React.RefObject<Promise<void>>}\n */\n const renderQueue = useRef(Promise.resolve());\n\n /**\n * State to track engine initialization\n * Used to trigger dependent effects after engine is ready\n */\n const [isEngineReady, setEngineReady] = useState(false);\n\n // ==========================================================================\n // SECTION 4.5: RENDER QUEUE HELPER\n // ==========================================================================\n\n /**\n * Queue a render operation to execute sequentially\n *\n * This helper ensures that async canvas operations (loadPDF, setPage, setScale)\n * execute one at a time, preventing concurrent access to the PDF.js canvas.\n * Uses Promise chaining to maintain operation order.\n *\n * @param {Function} operation - Async function returning a Promise\n * @returns {void}\n */\n const queueOperation = useCallback((operation) => {\n renderQueue.current = renderQueue.current\n .then(operation)\n .catch(error => {\n // Log errors but don't break the queue\n console.error('AnnotPdf: Queued operation failed:', error);\n });\n }, []);\n\n // ==========================================================================\n // SECTION 4.6: STROKE CONFIG BUILDER\n // ==========================================================================\n\n /**\n * Build merged stroke config from preset and overrides\n *\n * If strokeConfig.preset is provided, loads base config from presets.\n * Then merges any override values (highlight.width, text.width).\n */\n const mergedStrokeConfig = useMemo(() => {\n if (!strokeConfig) {\n return undefined;\n }\n\n // Start with preset or empty object\n const presetName = strokeConfig.preset || 'default';\n const presetConfig = getPreset(presetName);\n\n // Build config object matching StrokeRenderer format\n const config = {\n highlight: {\n color: presetConfig.highlight.color,\n width: strokeConfig.highlight?.width ?? presetConfig.highlight.width\n },\n text: {\n color: presetConfig.handText.color,\n width: strokeConfig.text?.width ?? presetConfig.handText.width\n }\n };\n\n return config;\n }, [strokeConfig]);\n\n // ==========================================================================\n // SECTION 5: ENGINE INITIALIZATION AND CLEANUP\n // ==========================================================================\n\n /**\n * Initialize AnnotationRenderer on component mount\n * Cleanup on component unmount\n */\n useEffect(() => {\n // Guard: Wait for DOM elements to be ready\n if (!canvasRef.current || !layerContainerRef.current) {\n return;\n }\n\n // Initialize engine with stroke config if provided\n try {\n engineRef.current = new AnnotationRenderer({\n canvasElement: canvasRef.current,\n container: layerContainerRef.current,\n strokeConfig: mergedStrokeConfig\n });\n // Signal that engine is ready for dependent effects\n setEngineReady(true);\n } catch (error) {\n console.error('AnnotPdf: Failed to initialize renderer:', error);\n if (onError) {\n onError(error);\n }\n }\n\n // Cleanup on unmount\n return () => {\n setEngineReady(false);\n if (engineRef.current) {\n engineRef.current.destroy();\n engineRef.current = null;\n }\n };\n }, []); // Empty deps - run once on mount\n\n // ==========================================================================\n // SECTION 6: PDF LOADING SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Load PDF document when pdfUrl prop changes\n * Handles async operation with cancellation support\n * Uses render queue to prevent concurrent canvas operations\n */\n useEffect(() => {\n // Guard: Wait for engine and valid pdfUrl\n if (!isEngineReady || !pdfUrl) {\n return;\n }\n\n let cancelled = false;\n\n const loadPdf = async () => {\n // Check engine exists at execution time (not queue time)\n if (!engineRef.current) {\n return;\n }\n\n try {\n const result = await engineRef.current.loadPDF(pdfUrl);\n\n // Check if component unmounted during async operation\n if (cancelled) return;\n\n // Check if load was successful\n if (!result.success) {\n console.error('AnnotPdf: Failed to load PDF:', result.error);\n if (onError) {\n onError(new Error(result.error));\n }\n return;\n }\n\n // Call onLoad callback with pageCount from result\n if (onLoad) {\n onLoad({ pageCount: result.pageCount });\n }\n } catch (error) {\n if (cancelled) return;\n\n console.error('AnnotPdf: Failed to load PDF:', error);\n if (onError) {\n onError(error);\n }\n }\n };\n\n // Queue the PDF loading operation to prevent race conditions\n queueOperation(loadPdf);\n\n // Cleanup: Prevent state updates if component unmounts during load\n return () => {\n cancelled = true;\n };\n }, [pdfUrl, isEngineReady, queueOperation]);\n\n // ==========================================================================\n // SECTION 7: PAGE SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync page prop to engine.setPage() method\n * Uses render queue to prevent concurrent canvas operations\n */\n useEffect(() => {\n // Guard: Wait for engine and valid page\n if (!isEngineReady || !page || typeof page !== 'number') {\n return;\n }\n\n // Queue the page change operation to prevent race conditions\n queueOperation(async () => {\n // Check engine exists at execution time (not queue time)\n if (!engineRef.current) {\n return;\n }\n\n try {\n const result = await engineRef.current.setPage(page);\n\n // Check if page change was successful\n if (!result.success) {\n console.error('AnnotPdf: Failed to set page:', result.error);\n if (onError) {\n onError(new Error(result.error));\n }\n return;\n }\n\n // Optional: Notify parent of successful page change\n if (onPageChange) {\n onPageChange(page);\n }\n } catch (error) {\n console.error('AnnotPdf: Failed to set page:', error);\n if (onError) {\n onError(error);\n }\n }\n });\n }, [page, isEngineReady, queueOperation]);\n\n // ==========================================================================\n // SECTION 8: SCALE SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync scale prop to engine.setScale() method\n * Uses render queue to prevent concurrent canvas operations\n */\n useEffect(() => {\n // Guard: Wait for engine and valid scale\n if (!isEngineReady || !scale || typeof scale !== 'number') {\n return;\n }\n\n // Queue the scale change operation to prevent race conditions\n queueOperation(async () => {\n // Check engine exists at execution time (not queue time)\n if (!engineRef.current) {\n return;\n }\n\n try {\n const result = await engineRef.current.setScale(scale);\n\n // Check if scale change was successful\n if (!result.success) {\n console.error('AnnotPdf: Failed to set scale:', result.error);\n if (onError) {\n onError(new Error(result.error));\n }\n }\n } catch (error) {\n console.error('AnnotPdf: Failed to set scale:', error);\n if (onError) {\n onError(error);\n }\n }\n });\n }, [scale, isEngineReady, queueOperation]);\n\n // ==========================================================================\n // SECTION 9: ANNOTATIONS SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync annotations prop to engine.setAnnotations() method\n */\n useEffect(() => {\n // Guard: Wait for engine\n if (!isEngineReady || !engineRef.current) {\n return;\n }\n\n // Sync annotations to engine (default to empty array)\n try {\n engineRef.current.setAnnotations(annotations || []);\n } catch (error) {\n console.error('AnnotPdf: Failed to set annotations:', error);\n if (onError) {\n onError(error);\n }\n }\n }, [annotations, isEngineReady]);\n\n // ==========================================================================\n // SECTION 10: TIMELINE SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync currentTime prop to engine.setTime() method\n * Only used when audioRef is NOT provided (discrete mode)\n */\n useEffect(() => {\n // Skip if using continuous sync mode\n if (audioRef) {\n return;\n }\n\n // Guard: Wait for engine and valid currentTime\n if (!isEngineReady || !engineRef.current || currentTime === undefined || currentTime === null) {\n return;\n }\n\n // Sync timeline to engine\n try {\n engineRef.current.setTime(currentTime);\n } catch (error) {\n console.error('AnnotPdf: Failed to set time:', error);\n if (onError) {\n onError(error);\n }\n }\n }, [currentTime, audioRef, isEngineReady]);\n\n // ==========================================================================\n // SECTION 10.1: CONTINUOUS SYNC MODE (audioRef)\n // ==========================================================================\n\n /**\n * Manage continuous sync mode when audioRef is provided\n *\n * Uses requestAnimationFrame for 60fps smooth animation instead of\n * discrete currentTime updates (~4fps from audio timeupdate events).\n */\n useEffect(() => {\n // Guard: Skip if not using continuous sync mode\n if (!audioRef?.current) {\n return;\n }\n\n // Guard: Wait for engine\n if (!isEngineReady || !engineRef.current) {\n return;\n }\n\n const audio = audioRef.current;\n /**\n * Start continuous sync when audio plays\n */\n const handlePlay = () => {\n if (!engineRef.current) return;\n engineRef.current.startContinuousSync(() => audio.currentTime);\n };\n\n /**\n * Stop continuous sync when audio pauses\n */\n const handlePause = () => {\n if (!engineRef.current) return;\n engineRef.current.stopContinuousSync();\n engineRef.current.setTime(audio.currentTime);\n };\n\n /**\n * Handle seeking - update time immediately\n */\n const handleSeeked = () => {\n if (!engineRef.current) return;\n engineRef.current.setTime(audio.currentTime);\n };\n\n // Add event listeners\n audio.addEventListener('play', handlePlay);\n audio.addEventListener('pause', handlePause);\n audio.addEventListener('ended', handlePause);\n audio.addEventListener('seeked', handleSeeked);\n\n // If audio is already playing, start sync immediately\n if (!audio.paused) {\n handlePlay();\n }\n\n // Cleanup on unmount or audioRef change\n return () => {\n audio.removeEventListener('play', handlePlay);\n audio.removeEventListener('pause', handlePause);\n audio.removeEventListener('ended', handlePause);\n audio.removeEventListener('seeked', handleSeeked);\n // Guard: engine may have been destroyed by initialization effect cleanup\n if (engineRef.current) {\n engineRef.current.stopContinuousSync();\n }\n };\n }, [audioRef, isEngineReady]);\n\n // ==========================================================================\n // SECTION 10.5: STROKE CONFIG SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync strokeConfig prop to engine at runtime for live preview\n * Skips initial render (handled by initialization)\n */\n const isFirstRender = useRef(true);\n\n useEffect(() => {\n // Skip first render - config is passed during initialization\n if (isFirstRender.current) {\n isFirstRender.current = false;\n return;\n }\n\n // Guard: Engine must exist\n if (!engineRef.current) {\n return;\n }\n\n // Update stroke config if provided\n if (mergedStrokeConfig) {\n try {\n engineRef.current.updateStrokeConfig(mergedStrokeConfig);\n } catch (error) {\n console.error('AnnotPdf: Failed to update stroke config:', error);\n if (onError) {\n onError(error);\n }\n }\n }\n }, [mergedStrokeConfig]);\n\n // ==========================================================================\n // SECTION 11: STYLING DEFINITIONS\n // ==========================================================================\n\n /**\n * Default container styles\n * Merged with user-provided styles (user styles override defaults)\n */\n const defaultContainerStyle = {\n position: 'relative',\n display: 'inline-block',\n lineHeight: 0, // Remove extra space below canvas\n ...style // User styles override defaults\n };\n\n /**\n * Default layer container styles\n * Positions layer div absolutely over canvas\n */\n const defaultLayerStyle = {\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none', // Allow clicks to pass through to canvas\n overflow: 'hidden'\n };\n\n /**\n * Default canvas styles\n * Merged with user-provided canvasStyle\n */\n const defaultCanvasStyle = {\n display: 'block',\n ...canvasStyle // User styles override defaults\n };\n\n // ==========================================================================\n // SECTION 12: JSX RETURN\n // ==========================================================================\n\n return (\n <div className={className} style={defaultContainerStyle}>\n <canvas ref={canvasRef} style={defaultCanvasStyle} />\n <div ref={layerContainerRef} style={defaultLayerStyle} />\n </div>\n );\n}\n\n// ============================================================================\n// SECTION 13: EXPORT\n// ============================================================================\n\nexport default AnnotPdf;\n"],"names":["AnnotPdf","pdfUrl","page","scale","annotations","currentTime","audioRef","strokeConfig","onLoad","onError","onPageChange","className","style","canvasStyle","canvasRef","useRef","layerContainerRef","engineRef","renderQueue","isEngineReady","setEngineReady","useState","queueOperation","useCallback","operation","error","mergedStrokeConfig","useMemo","presetName","presetConfig","getPreset","useEffect","AnnotationRenderer","cancelled","result","audio","handlePlay","handlePause","handleSeeked","isFirstRender","defaultContainerStyle","defaultLayerStyle","defaultCanvasStyle","jsxs","jsx"],"mappings":";;;;AAoGA,SAASA,EAAS;AAAA;AAAA,EAEhB,QAAAC;AAAA;AAAA,EAGA,MAAAC,IAAO;AAAA,EACP,OAAAC,IAAQ;AAAA,EACR,aAAAC,IAAc,CAAA;AAAA,EACd,aAAAC,IAAc;AAAA;AAAA,EAGd,UAAAC;AAAA;AAAA,EAGA,cAAAC;AAAA;AAAA,EAGA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,cAAAC;AAAA;AAAA,EAGA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AACF,GAAG;AAUD,QAAMC,IAAYC,EAAO,IAAI,GAMvBC,IAAoBD,EAAO,IAAI,GAO/BE,IAAYF,EAAO,IAAI,GAQvBG,IAAcH,EAAO,QAAQ,QAAA,CAAS,GAMtC,CAACI,GAAeC,CAAc,IAAIC,EAAS,EAAK,GAgBhDC,IAAiBC,EAAY,CAACC,MAAc;AAChD,IAAAN,EAAY,UAAUA,EAAY,QAC/B,KAAKM,CAAS,EACd,MAAM,CAAAC,MAAS;AAEd,cAAQ,MAAM,sCAAsCA,CAAK;AAAA,IAC3D,CAAC;AAAA,EACL,GAAG,CAAA,CAAE,GAYCC,IAAqBC,EAAQ,MAAM;AACvC,QAAI,CAACpB;AACH;AAIF,UAAMqB,IAAarB,EAAa,UAAU,WACpCsB,IAAeC,EAAUF,CAAU;AAczC,WAXe;AAAA,MACb,WAAW;AAAA,QACT,OAAOC,EAAa,UAAU;AAAA,QAC9B,OAAOtB,EAAa,WA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WACZA,EAAU,QAAQ,mBAAA;AAAA,IAEtB;AAAA,EACF,GAAG,CAACX,GAAUa,CAAa,CAAC;AAU5B,QAAMoB,IAAgBxB,EAAO,EAAI;AAEjC,EAAAgB,EAAU,MAAM;AAEd,QAAIQ,EAAc,SAAS;AACzB,MAAAA,EAAc,UAAU;AACxB;AAAA,IACF;AAGA,QAAKtB,EAAU,WAKXS;AACF,UAAI;AACF,QAAAT,EAAU,QAAQ,mBAAmBS,CAAkB;AAAA,MACzD,SAASD,GAAO;AACd,gBAAQ,MAAM,6CAA6CA,CAAK,GAC5DhB,KACFA,EAAQgB,CAAK;AAAA,MAEjB;AAAA,EAEJ,GAAG,CAACC,CAAkB,CAAC;AAUvB,QAAMc,IAAwB;AAAA,IAC5B,UAAU;AAAA,IACV,SAAS;AAAA,IACT,YAAY;AAAA;AAAA,IACZ,GAAG5B;AAAA;AAAA,EAAA,GAOC6B,IAAoB;AAAA,IACxB,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,eAAe;AAAA;AAAA,IACf,UAAU;AAAA,EAAA,GAONC,IAAqB;AAAA,IACzB,SAAS;AAAA,IACT,GAAG7B;AAAA;AAAA,EAAA;AAOL,SACE,gBAAA8B,EAAC,OAAA,EAAI,WAAAhC,GAAsB,OAAO6B,GAChC,UAAA;AAAA,IAAA,gBAAAI,EAAC,UAAA,EAAO,KAAK9B,GAAW,OAAO4B,GAAoB;AAAA,IACnD,gBAAAE,EAAC,OAAA,EAAI,KAAK5B,GAAmB,OAAOyB,EAAA,CAAmB;AAAA,EAAA,GACzD;AAEJ;"}
1
+ {"version":3,"file":"index13.js","sources":["../src/converters/highlight.js"],"sourcesContent":["/**\n * Highlight Converter - Converts highlight annotations to stroke commands\n *\n * Transforms rectangular quads into horizontal stroke paths that can be\n * rendered progressively on canvas with hand-drawn highlighter style.\n *\n * @module converters/highlight\n */\n\nimport { roughLine, hashSeed } from '../rough/roughPathExtractor.js';\n\nconst SCALE = 1000;\n\n/**\n * Converts a highlight annotation to stroke commands\n *\n * Each quad in the annotation becomes a horizontal stroke at the\n * vertical center of the quad. Multiple quads are staggered in timing.\n * Uses RoughJS for hand-drawn highlighter style.\n *\n * @param {Object} annotation - Highlight 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='butt'] - Line cap style\n * @param {number} [style.roughness=0.5] - Hand-drawn roughness (lower for highlighter)\n * @param {number} [style.bowing=0.5] - Line curvature\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function highlightToStrokes(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 const roughness = style.roughness ?? 0.5;\n const bowing = style.bowing ?? 0.5;\n const curveFitting = style.curveFitting ?? 0.95;\n const curveStepCount = style.curveStepCount ?? 9;\n const maxRandomnessOffset = style.maxRandomnessOffset ?? 2;\n const disableMultiStroke = style.disableMultiStroke ?? false;\n\n for (let i = 0; i < quads.length; i++) {\n const quad = quads[i];\n const { x, y, w, h } = quad;\n\n const yCenter = y + h / 2;\n\n const roughPoints = roughLine(\n x * SCALE,\n yCenter * SCALE,\n (x + w) * SCALE,\n yCenter * SCALE,\n {\n roughness,\n bowing,\n seed: hashSeed(`${id}-${i}`),\n curveFitting,\n curveStepCount,\n maxRandomnessOffset,\n disableMultiStroke\n }\n );\n\n const points = roughPoints.map(([px, py]) => [px / SCALE, py / SCALE]);\n\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(255, 255, 0, 0.3)',\n width: style.width || 24,\n lineCap: style.lineCap || 'butt'\n });\n }\n\n return strokes;\n}\n\nexport default highlightToStrokes;\n"],"names":["SCALE","highlightToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","roughness","bowing","curveFitting","curveStepCount","maxRandomnessOffset","disableMultiStroke","i","quad","x","y","w","h","yCenter","points","roughLine","hashSeed","px","py","quadStart","quadEnd"],"mappings":";AAWA,MAAMA,IAAQ;AAuBP,SAASC,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,GAE/BE,IAAYT,EAAM,aAAa,KAC/BU,IAASV,EAAM,UAAU,KACzBW,IAAeX,EAAM,gBAAgB,MACrCY,IAAiBZ,EAAM,kBAAkB,GACzCa,IAAsBb,EAAM,uBAAuB,GACnDc,IAAqBd,EAAM,sBAAsB;AAEvD,WAASe,IAAI,GAAGA,IAAIX,EAAM,QAAQW,KAAK;AACrC,UAAMC,IAAOZ,EAAMW,CAAC,GACd,EAAE,GAAAE,GAAG,GAAAC,GAAG,GAAAC,GAAG,GAAAC,EAAC,IAAKJ,GAEjBK,IAAUH,IAAIE,IAAI,GAkBlBE,IAhBcC;AAAA,MAClBN,IAAIpB;AAAA,MACJwB,IAAUxB;AAAA,OACToB,IAAIE,KAAKtB;AAAA,MACVwB,IAAUxB;AAAA,MACV;AAAA,QACE,WAAAY;AAAA,QACA,QAAAC;AAAA,QACA,MAAMc,EAAS,GAAGvB,CAAE,IAAIc,CAAC,EAAE;AAAA,QAC3B,cAAAJ;AAAA,QACA,gBAAAC;AAAA,QACA,qBAAAC;AAAA,QACA,oBAAAC;AAAA,MACR;AAAA,IACA,EAE+B,IAAI,CAAC,CAACW,GAAIC,CAAE,MAAM,CAACD,IAAK5B,GAAO6B,IAAK7B,CAAK,CAAC,GAE/D8B,IAAYzB,IAAQa,IAAIP,GACxBoB,IAAUD,IAAYnB;AAE5B,IAAAH,EAAQ,KAAK;AAAA,MACX,IAAI,GAAGJ,CAAE,IAAIc,CAAC;AAAA,MACd,QAAAO;AAAA,MACA,OAAOK;AAAA,MACP,KAAKC;AAAA,MACL,OAAO5B,EAAM,SAAS;AAAA,MACtB,OAAOA,EAAM,SAAS;AAAA,MACtB,SAASA,EAAM,WAAW;AAAA,IAChC,CAAK;AAAA,EACH;AAEA,SAAOK;AACT;"}
package/dist/index14.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("./index6.cjs");function h(g,t){const{id:o,start:u,end:f,quads:r}=g;if(!r||r.length===0)return[];const s=[],q=f-u,S=r.length,i=q/S;for(let e=0;e<r.length;e++){const b=r[e],{x:a,y:C,w:$,h:j}=b,d=C+j/2;let n=[[a,d],[a+$,d]];t.jitter?.amplitude>0&&(n=p.applyJitter(n,t.jitter,`${o}-${e}`));let c=null;(t.pressure?.taperIn>0||t.pressure?.taperOut>0)&&(c=p.applyPressure(n,t.pressure));const l=u+e*i,k=l+i;s.push({id:`${o}-${e}`,points:n,start:l,end:k,color:t.color||"rgba(255, 255, 0, 0.3)",width:t.width||24,lineCap:t.lineCap||"butt",pressures:c})}return s}exports.default=h;exports.highlightToStrokes=h;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("./index11.cjs"),X=require("./index29.cjs");function P(e){const t=Math.sin(e)*1e4;return(t-Math.floor(t))*2-1}function _(e,t,n){return e.map(([r,c],o)=>[r+P(n+o*2)*t,c+P(n+o*2+1)*t])}function A(e,t,n){return e.map(([r,c])=>[(t+r)*n,c*n])}function $(e,t){const{id:n,start:r,end:c,content:o,x:b,y:D,fontSize:T}=e;if(!o||o.length===0)return[];const g=[],v=c-r,w=T||t.fontSize||16,z=t.roughness??1.5,C=w/1e3;let i=0;const M=o.length,p=v/M;for(let a=0;a<o.length;a++){const k=o[a],h=R.resolveGlyph(k);if(!h){i+=.5+.18;continue}const S=h.width||.5,l=h.paths||[],q=h.pathTiming||"sequential";if(l.length===0){i+=S+.18;continue}const d=r+a*p,y=d+p,E=l.length;for(let s=0;s<l.length;s++){const m=l[s].points||[];if(m.length<2)continue;const j=A(m,i,C),G=z*7e-4,I=X.hashSeed(`${n}-${a}-${s}`),O=_(j,G,I);let u,f;if(q==="parallel")u=d,f=y;else{const x=p/E;u=d+s*x,f=u+x}g.push({id:`${n}-${a}-${s}`,points:O,baseX:b,baseY:D,start:u,end:f,color:t.color||"rgba(220, 20, 60, 1.0)",width:t.width||2,lineCap:t.lineCap||"round",uniformScale:!0})}i+=S+.18}return g}exports.default=$;exports.textToStrokes=$;
2
2
  //# sourceMappingURL=index14.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index14.cjs","sources":["../src/converters/highlight.js"],"sourcesContent":["/**\n * Highlight Converter - Converts highlight annotations to stroke commands\n *\n * Transforms rectangular quads into horizontal stroke paths that can be\n * rendered progressively on canvas.\n *\n * @module converters/highlight\n */\n\nimport { applyJitter, applyPressure } from '../pen/effects.js';\n\n/**\n * Converts a highlight annotation to stroke commands\n *\n * Each quad in the annotation becomes a horizontal stroke at the\n * vertical center of the quad. Multiple quads are staggered in timing.\n *\n * @param {Object} annotation - Highlight 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='butt'] - Line cap style\n * @param {Object} [style.jitter] - Jitter configuration\n * @param {Object} [style.pressure] - Pressure configuration\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function highlightToStrokes(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\n // Calculate timing for each quad (staggered)\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 // Calculate center-line Y position\n const yCenter = y + h / 2;\n\n // Create stroke points (left to right horizontal line)\n let points = [\n [x, yCenter],\n [x + w, yCenter]\n ];\n\n // Apply jitter if configured\n if (style.jitter?.amplitude > 0) {\n points = applyJitter(points, style.jitter, `${id}-${i}`);\n }\n\n // Calculate pressure values if configured\n let pressures = null;\n if (style.pressure?.taperIn > 0 || style.pressure?.taperOut > 0) {\n pressures = applyPressure(points, style.pressure);\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(255, 255, 0, 0.3)',\n width: style.width || 24,\n lineCap: style.lineCap || 'butt',\n pressures\n });\n }\n\n return strokes;\n}\n\nexport default highlightToStrokes;\n"],"names":["highlightToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","i","quad","x","y","w","h","yCenter","points","applyJitter","pressures","applyPressure","quadStart","quadEnd"],"mappings":"4IA+BO,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,OAGlBI,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,EAAUH,EAAIE,EAAI,EAGxB,IAAIE,EAAS,CACX,CAACL,EAAGI,CAAO,EACX,CAACJ,EAAIE,EAAGE,CAAO,CACrB,EAGQf,EAAM,QAAQ,UAAY,IAC5BgB,EAASC,EAAAA,YAAYD,EAAQhB,EAAM,OAAQ,GAAGC,CAAE,IAAIQ,CAAC,EAAE,GAIzD,IAAIS,EAAY,MACZlB,EAAM,UAAU,QAAU,GAAKA,EAAM,UAAU,SAAW,KAC5DkB,EAAYC,EAAAA,cAAcH,EAAQhB,EAAM,QAAQ,GAIlD,MAAMoB,EAAYlB,EAAQO,EAAID,EACxBa,EAAUD,EAAYZ,EAE5BH,EAAQ,KAAK,CACX,GAAI,GAAGJ,CAAE,IAAIQ,CAAC,GACd,OAAAO,EACA,MAAOI,EACP,IAAKC,EACL,MAAOrB,EAAM,OAAS,yBACtB,MAAOA,EAAM,OAAS,GACtB,QAASA,EAAM,SAAW,OAC1B,UAAAkB,CACN,CAAK,CACH,CAEA,OAAOb,CACT"}
1
+ {"version":3,"file":"index14.cjs","sources":["../src/converters/text.js"],"sourcesContent":["/**\n * Text Converter - Converts text annotations to stroke commands\n *\n * Transforms text content into stroke paths for each character,\n * using single-stroke font glyphs for smooth writing animation\n * with hand-drawn style.\n *\n * @module converters/text\n */\n\nimport { resolveGlyph } from \"./glyphResolver.js\";\nimport { hashSeed } from \"../rough/roughPathExtractor.js\";\n\n/**\n * Simple seeded random number generator\n * Returns value between -1 and 1\n */\nfunction seededRandom(seed) {\n const x = Math.sin(seed) * 10000;\n return (x - Math.floor(x)) * 2 - 1;\n}\n\n/**\n * Apply hand-drawn jitter to points\n * Each point gets a random offset based on seed for reproducibility\n */\nfunction applyJitter(points, amplitude, seed) {\n return points.map(([x, y], i) => [\n x + seededRandom(seed + i * 2) * amplitude,\n y + seededRandom(seed + i * 2 + 1) * amplitude\n ]);\n}\n\n/**\n * Scales glyph points by fontSize scale factor\n *\n * Glyph points are in normalized space where:\n * - X is 0 to charWidth (already scaled within the glyph)\n * - Y is 0 to ~1.0 (baseline at 0.8, cap height at 0)\n *\n * This scales them to the target size, but does NOT add the base position.\n * The base position is stored separately to allow correct rendering with\n * mixed coordinate systems (position in page coords, offsets in uniform space).\n *\n * @param {Array<[number, number]>} points - Glyph points in normalized space\n * @param {number} offsetX - X offset from base position (character offset within text)\n * @param {number} scale - Scale factor based on fontSize\n * @returns {Array<[number, number]>} Scaled offset points (not absolute positions)\n */\nfunction scaleGlyphPoints(points, offsetX, scale) {\n // Scale points and add character offset (in uniform space)\n return points.map(([px, py]) => [(offsetX + px) * scale, py * scale]);\n}\n\n/**\n * Converts a text annotation to stroke commands\n *\n * Each character in the content becomes one or more strokes.\n * Characters are staggered in timing to create a writing effect.\n * Multi-path characters (like 'i', 'j', '!') use pathTiming to\n * control whether paths are drawn sequentially or in parallel.\n *\n * @param {Object} annotation - Text 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 {string} annotation.content - Text content to render\n * @param {number} annotation.x - X position (normalized 0-1)\n * @param {number} annotation.y - Y position (normalized 0-1)\n * @param {number} [annotation.fontSize=16] - Font size in pixels\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 {number} [style.fontSize=16] - Default font size\n * @param {string} [style.lineCap='round'] - Line cap style\n * @param {number} [style.roughness=1.5] - Hand-drawn jitter amplitude\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function textToStrokes(annotation, style) {\n const { id, start, end, content, x, y, fontSize: annotFontSize } = annotation;\n\n if (!content || content.length === 0) {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const fontSize = annotFontSize || style.fontSize || 16;\n\n const roughness = style.roughness ?? 1.5;\n\n // Scale factor: convert fontSize (pixels) to normalized coordinates\n // Assuming a reference viewport of ~1000px\n const fontScale = fontSize / 1000;\n\n // Track character offset from base position (in glyph units, not page coords)\n let charOffsetX = 0;\n\n // Calculate timing per character\n const charCount = content.length;\n const charDuration = totalDuration / charCount;\n\n for (let charIndex = 0; charIndex < content.length; charIndex++) {\n const char = content[charIndex];\n const glyph = resolveGlyph(char);\n\n if (!glyph) {\n // Skip unknown characters, but advance position with default width\n charOffsetX += 0.5 + 0.18; // default width + spacing (in glyph units)\n continue;\n }\n\n const charWidth = glyph.width || 0.5;\n const charPaths = glyph.paths || [];\n const pathTiming = glyph.pathTiming || \"sequential\";\n\n // Skip if no paths (e.g., space character)\n if (charPaths.length === 0) {\n charOffsetX += charWidth + 0.18;\n continue;\n }\n\n // Calculate timing for this character's paths\n const charStart = start + charIndex * charDuration;\n const charEnd = charStart + charDuration;\n\n // Determine path timing based on pathTiming mode\n const pathCount = charPaths.length;\n\n for (let pathIndex = 0; pathIndex < charPaths.length; pathIndex++) {\n const pathData = charPaths[pathIndex];\n const rawPoints = pathData.points || [];\n\n if (rawPoints.length < 2) continue;\n\n // Scale glyph points to offset coordinates\n const scaledPoints = scaleGlyphPoints(rawPoints, charOffsetX, fontScale);\n\n // Apply hand-drawn jitter effect\n // Amplitude is in offset coordinates (scaled by viewport.height when rendered)\n // 0.0007 = ~0.4 pixels at 600px viewport, subtle hand-drawn effect\n const jitterAmplitude = roughness * 0.0007;\n const seed = hashSeed(`${id}-${charIndex}-${pathIndex}`);\n const points = applyJitter(scaledPoints, jitterAmplitude, seed);\n\n // Calculate path timing based on pathTiming mode\n let pathStart, pathEnd;\n\n if (pathTiming === \"parallel\") {\n // All paths drawn simultaneously during character duration\n pathStart = charStart;\n pathEnd = charEnd;\n } else {\n // Sequential: each path gets a portion of character duration\n const pathDuration = charDuration / pathCount;\n pathStart = charStart + pathIndex * pathDuration;\n pathEnd = pathStart + pathDuration;\n }\n\n strokes.push({\n id: `${id}-${charIndex}-${pathIndex}`,\n points, // Offset coordinates from baseX/baseY (uniform space)\n baseX: x, // Base X position (width-normalized page coords)\n baseY: y, // Base Y position (height-normalized page coords)\n start: pathStart,\n end: pathEnd,\n color: style.color || \"rgba(220, 20, 60, 1.0)\",\n width: style.width || 2,\n lineCap: style.lineCap || \"round\",\n uniformScale: true, // Preserve aspect ratio when rendering\n });\n }\n\n // Advance offset for next character (in glyph units)\n charOffsetX += charWidth + 0.18; // Add small spacing\n }\n\n return strokes;\n}\n\nexport default textToStrokes;\n"],"names":["seededRandom","seed","x","applyJitter","points","amplitude","y","i","scaleGlyphPoints","offsetX","scale","px","py","textToStrokes","annotation","style","id","start","end","content","annotFontSize","strokes","totalDuration","fontSize","roughness","fontScale","charOffsetX","charCount","charDuration","charIndex","char","glyph","resolveGlyph","charWidth","charPaths","pathTiming","charStart","charEnd","pathCount","pathIndex","rawPoints","scaledPoints","jitterAmplitude","hashSeed","pathStart","pathEnd","pathDuration"],"mappings":"wKAiBA,SAASA,EAAaC,EAAM,CAC1B,MAAMC,EAAI,KAAK,IAAID,CAAI,EAAI,IAC3B,OAAQC,EAAI,KAAK,MAAMA,CAAC,GAAK,EAAI,CACnC,CAMA,SAASC,EAAYC,EAAQC,EAAWJ,EAAM,CAC5C,OAAOG,EAAO,IAAI,CAAC,CAACF,EAAGI,CAAC,EAAGC,IAAM,CAC/BL,EAAIF,EAAaC,EAAOM,EAAI,CAAC,EAAIF,EACjCC,EAAIN,EAAaC,EAAOM,EAAI,EAAI,CAAC,EAAIF,CACzC,CAAG,CACH,CAkBA,SAASG,EAAiBJ,EAAQK,EAASC,EAAO,CAEhD,OAAON,EAAO,IAAI,CAAC,CAACO,EAAIC,CAAE,IAAM,EAAEH,EAAUE,GAAMD,EAAOE,EAAKF,CAAK,CAAC,CACtE,CA2BO,SAASG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,MAAMS,EAAelB,EAAeU,EACpCM,EAAYR,EAAYG,EAAYO,EACpCD,EAAUD,EAAYE,CACxB,CAEAzB,EAAQ,KAAK,CACX,GAAI,GAAGL,CAAE,IAAIa,CAAS,IAAIU,CAAS,GACnC,OAAAnC,EACA,MAAOF,EACP,MAAOI,EACP,MAAOsC,EACP,IAAKC,EACL,MAAO9B,EAAM,OAAS,yBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,QAC1B,aAAc,EACtB,CAAO,CACH,CAGAW,GAAeO,EAAY,GAC7B,CAEA,OAAOZ,CACT"}
package/dist/index14.js CHANGED
@@ -1,34 +1,71 @@
1
- import { applyJitter as b, applyPressure as j } from "./index6.js";
2
- function x(l, t) {
3
- const { id: o, start: s, end: h, quads: n } = l;
4
- if (!n || n.length === 0)
1
+ import { resolveGlyph as y } from "./index11.js";
2
+ import { hashSeed as A } from "./index29.js";
3
+ function $(e) {
4
+ const t = Math.sin(e) * 1e4;
5
+ return (t - Math.floor(t)) * 2 - 1;
6
+ }
7
+ function F(e, t, n) {
8
+ return e.map(([a, c], o) => [
9
+ a + $(n + o * 2) * t,
10
+ c + $(n + o * 2 + 1) * t
11
+ ]);
12
+ }
13
+ function J(e, t, n) {
14
+ return e.map(([a, c]) => [(t + a) * n, c * n]);
15
+ }
16
+ function Y(e, t) {
17
+ const { id: n, start: a, end: c, content: o, x: D, y: w, fontSize: z } = e;
18
+ if (!o || o.length === 0)
5
19
  return [];
6
- const u = [], f = h - s, g = n.length, a = f / g;
7
- for (let r = 0; r < n.length; r++) {
8
- const q = n[r], { x: i, y: C, w: $, h: m } = q, p = C + m / 2;
9
- let e = [
10
- [i, p],
11
- [i + $, p]
12
- ];
13
- t.jitter?.amplitude > 0 && (e = b(e, t.jitter, `${o}-${r}`));
14
- let d = null;
15
- (t.pressure?.taperIn > 0 || t.pressure?.taperOut > 0) && (d = j(e, t.pressure));
16
- const c = s + r * a, w = c + a;
17
- u.push({
18
- id: `${o}-${r}`,
19
- points: e,
20
- start: c,
21
- end: w,
22
- color: t.color || "rgba(255, 255, 0, 0.3)",
23
- width: t.width || 24,
24
- lineCap: t.lineCap || "butt",
25
- pressures: d
26
- });
20
+ const g = [], C = c - a, P = z || t.fontSize || 16, b = t.roughness ?? 1.5, T = P / 1e3;
21
+ let i = 0;
22
+ const k = o.length, u = C / k;
23
+ for (let r = 0; r < o.length; r++) {
24
+ const E = o[r], h = y(E);
25
+ if (!h) {
26
+ i += 0.5 + 0.18;
27
+ continue;
28
+ }
29
+ const m = h.width || 0.5, l = h.paths || [], G = h.pathTiming || "sequential";
30
+ if (l.length === 0) {
31
+ i += m + 0.18;
32
+ continue;
33
+ }
34
+ const f = a + r * u, I = f + u, M = l.length;
35
+ for (let s = 0; s < l.length; s++) {
36
+ const S = l[s].points || [];
37
+ if (S.length < 2) continue;
38
+ const X = J(S, i, T), j = b * 7e-4, q = A(`${n}-${r}-${s}`), v = F(X, j, q);
39
+ let p, d;
40
+ if (G === "parallel")
41
+ p = f, d = I;
42
+ else {
43
+ const x = u / M;
44
+ p = f + s * x, d = p + x;
45
+ }
46
+ g.push({
47
+ id: `${n}-${r}-${s}`,
48
+ points: v,
49
+ // Offset coordinates from baseX/baseY (uniform space)
50
+ baseX: D,
51
+ // Base X position (width-normalized page coords)
52
+ baseY: w,
53
+ // Base Y position (height-normalized page coords)
54
+ start: p,
55
+ end: d,
56
+ color: t.color || "rgba(220, 20, 60, 1.0)",
57
+ width: t.width || 2,
58
+ lineCap: t.lineCap || "round",
59
+ uniformScale: !0
60
+ // Preserve aspect ratio when rendering
61
+ });
62
+ }
63
+ i += m + 0.18;
27
64
  }
28
- return u;
65
+ return g;
29
66
  }
30
67
  export {
31
- x as default,
32
- x as highlightToStrokes
68
+ Y as default,
69
+ Y as textToStrokes
33
70
  };
34
71
  //# sourceMappingURL=index14.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index14.js","sources":["../src/converters/highlight.js"],"sourcesContent":["/**\n * Highlight Converter - Converts highlight annotations to stroke commands\n *\n * Transforms rectangular quads into horizontal stroke paths that can be\n * rendered progressively on canvas.\n *\n * @module converters/highlight\n */\n\nimport { applyJitter, applyPressure } from '../pen/effects.js';\n\n/**\n * Converts a highlight annotation to stroke commands\n *\n * Each quad in the annotation becomes a horizontal stroke at the\n * vertical center of the quad. Multiple quads are staggered in timing.\n *\n * @param {Object} annotation - Highlight 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='butt'] - Line cap style\n * @param {Object} [style.jitter] - Jitter configuration\n * @param {Object} [style.pressure] - Pressure configuration\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function highlightToStrokes(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\n // Calculate timing for each quad (staggered)\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 // Calculate center-line Y position\n const yCenter = y + h / 2;\n\n // Create stroke points (left to right horizontal line)\n let points = [\n [x, yCenter],\n [x + w, yCenter]\n ];\n\n // Apply jitter if configured\n if (style.jitter?.amplitude > 0) {\n points = applyJitter(points, style.jitter, `${id}-${i}`);\n }\n\n // Calculate pressure values if configured\n let pressures = null;\n if (style.pressure?.taperIn > 0 || style.pressure?.taperOut > 0) {\n pressures = applyPressure(points, style.pressure);\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(255, 255, 0, 0.3)',\n width: style.width || 24,\n lineCap: style.lineCap || 'butt',\n pressures\n });\n }\n\n return strokes;\n}\n\nexport default highlightToStrokes;\n"],"names":["highlightToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","i","quad","x","y","w","h","yCenter","points","applyJitter","pressures","applyPressure","quadStart","quadEnd"],"mappings":";AA+BO,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,QAGlBI,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,IAAUH,IAAIE,IAAI;AAGxB,QAAIE,IAAS;AAAA,MACX,CAACL,GAAGI,CAAO;AAAA,MACX,CAACJ,IAAIE,GAAGE,CAAO;AAAA,IACrB;AAGI,IAAIf,EAAM,QAAQ,YAAY,MAC5BgB,IAASC,EAAYD,GAAQhB,EAAM,QAAQ,GAAGC,CAAE,IAAIQ,CAAC,EAAE;AAIzD,QAAIS,IAAY;AAChB,KAAIlB,EAAM,UAAU,UAAU,KAAKA,EAAM,UAAU,WAAW,OAC5DkB,IAAYC,EAAcH,GAAQhB,EAAM,QAAQ;AAIlD,UAAMoB,IAAYlB,IAAQO,IAAID,GACxBa,IAAUD,IAAYZ;AAE5B,IAAAH,EAAQ,KAAK;AAAA,MACX,IAAI,GAAGJ,CAAE,IAAIQ,CAAC;AAAA,MACd,QAAAO;AAAA,MACA,OAAOI;AAAA,MACP,KAAKC;AAAA,MACL,OAAOrB,EAAM,SAAS;AAAA,MACtB,OAAOA,EAAM,SAAS;AAAA,MACtB,SAASA,EAAM,WAAW;AAAA,MAC1B,WAAAkB;AAAA,IACN,CAAK;AAAA,EACH;AAEA,SAAOb;AACT;"}
1
+ {"version":3,"file":"index14.js","sources":["../src/converters/text.js"],"sourcesContent":["/**\n * Text Converter - Converts text annotations to stroke commands\n *\n * Transforms text content into stroke paths for each character,\n * using single-stroke font glyphs for smooth writing animation\n * with hand-drawn style.\n *\n * @module converters/text\n */\n\nimport { resolveGlyph } from \"./glyphResolver.js\";\nimport { hashSeed } from \"../rough/roughPathExtractor.js\";\n\n/**\n * Simple seeded random number generator\n * Returns value between -1 and 1\n */\nfunction seededRandom(seed) {\n const x = Math.sin(seed) * 10000;\n return (x - Math.floor(x)) * 2 - 1;\n}\n\n/**\n * Apply hand-drawn jitter to points\n * Each point gets a random offset based on seed for reproducibility\n */\nfunction applyJitter(points, amplitude, seed) {\n return points.map(([x, y], i) => [\n x + seededRandom(seed + i * 2) * amplitude,\n y + seededRandom(seed + i * 2 + 1) * amplitude\n ]);\n}\n\n/**\n * Scales glyph points by fontSize scale factor\n *\n * Glyph points are in normalized space where:\n * - X is 0 to charWidth (already scaled within the glyph)\n * - Y is 0 to ~1.0 (baseline at 0.8, cap height at 0)\n *\n * This scales them to the target size, but does NOT add the base position.\n * The base position is stored separately to allow correct rendering with\n * mixed coordinate systems (position in page coords, offsets in uniform space).\n *\n * @param {Array<[number, number]>} points - Glyph points in normalized space\n * @param {number} offsetX - X offset from base position (character offset within text)\n * @param {number} scale - Scale factor based on fontSize\n * @returns {Array<[number, number]>} Scaled offset points (not absolute positions)\n */\nfunction scaleGlyphPoints(points, offsetX, scale) {\n // Scale points and add character offset (in uniform space)\n return points.map(([px, py]) => [(offsetX + px) * scale, py * scale]);\n}\n\n/**\n * Converts a text annotation to stroke commands\n *\n * Each character in the content becomes one or more strokes.\n * Characters are staggered in timing to create a writing effect.\n * Multi-path characters (like 'i', 'j', '!') use pathTiming to\n * control whether paths are drawn sequentially or in parallel.\n *\n * @param {Object} annotation - Text 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 {string} annotation.content - Text content to render\n * @param {number} annotation.x - X position (normalized 0-1)\n * @param {number} annotation.y - Y position (normalized 0-1)\n * @param {number} [annotation.fontSize=16] - Font size in pixels\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 {number} [style.fontSize=16] - Default font size\n * @param {string} [style.lineCap='round'] - Line cap style\n * @param {number} [style.roughness=1.5] - Hand-drawn jitter amplitude\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function textToStrokes(annotation, style) {\n const { id, start, end, content, x, y, fontSize: annotFontSize } = annotation;\n\n if (!content || content.length === 0) {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const fontSize = annotFontSize || style.fontSize || 16;\n\n const roughness = style.roughness ?? 1.5;\n\n // Scale factor: convert fontSize (pixels) to normalized coordinates\n // Assuming a reference viewport of ~1000px\n const fontScale = fontSize / 1000;\n\n // Track character offset from base position (in glyph units, not page coords)\n let charOffsetX = 0;\n\n // Calculate timing per character\n const charCount = content.length;\n const charDuration = totalDuration / charCount;\n\n for (let charIndex = 0; charIndex < content.length; charIndex++) {\n const char = content[charIndex];\n const glyph = resolveGlyph(char);\n\n if (!glyph) {\n // Skip unknown characters, but advance position with default width\n charOffsetX += 0.5 + 0.18; // default width + spacing (in glyph units)\n continue;\n }\n\n const charWidth = glyph.width || 0.5;\n const charPaths = glyph.paths || [];\n const pathTiming = glyph.pathTiming || \"sequential\";\n\n // Skip if no paths (e.g., space character)\n if (charPaths.length === 0) {\n charOffsetX += charWidth + 0.18;\n continue;\n }\n\n // Calculate timing for this character's paths\n const charStart = start + charIndex * charDuration;\n const charEnd = charStart + charDuration;\n\n // Determine path timing based on pathTiming mode\n const pathCount = charPaths.length;\n\n for (let pathIndex = 0; pathIndex < charPaths.length; pathIndex++) {\n const pathData = charPaths[pathIndex];\n const rawPoints = pathData.points || [];\n\n if (rawPoints.length < 2) continue;\n\n // Scale glyph points to offset coordinates\n const scaledPoints = scaleGlyphPoints(rawPoints, charOffsetX, fontScale);\n\n // Apply hand-drawn jitter effect\n // Amplitude is in offset coordinates (scaled by viewport.height when rendered)\n // 0.0007 = ~0.4 pixels at 600px viewport, subtle hand-drawn effect\n const jitterAmplitude = roughness * 0.0007;\n const seed = hashSeed(`${id}-${charIndex}-${pathIndex}`);\n const points = applyJitter(scaledPoints, jitterAmplitude, seed);\n\n // Calculate path timing based on pathTiming mode\n let pathStart, pathEnd;\n\n if (pathTiming === \"parallel\") {\n // All paths drawn simultaneously during character duration\n pathStart = charStart;\n pathEnd = charEnd;\n } else {\n // Sequential: each path gets a portion of character duration\n const pathDuration = charDuration / pathCount;\n pathStart = charStart + pathIndex * pathDuration;\n pathEnd = pathStart + pathDuration;\n }\n\n strokes.push({\n id: `${id}-${charIndex}-${pathIndex}`,\n points, // Offset coordinates from baseX/baseY (uniform space)\n baseX: x, // Base X position (width-normalized page coords)\n baseY: y, // Base Y position (height-normalized page coords)\n start: pathStart,\n end: pathEnd,\n color: style.color || \"rgba(220, 20, 60, 1.0)\",\n width: style.width || 2,\n lineCap: style.lineCap || \"round\",\n uniformScale: true, // Preserve aspect ratio when rendering\n });\n }\n\n // Advance offset for next character (in glyph units)\n charOffsetX += charWidth + 0.18; // Add small spacing\n }\n\n return strokes;\n}\n\nexport default textToStrokes;\n"],"names":["seededRandom","seed","x","applyJitter","points","amplitude","y","i","scaleGlyphPoints","offsetX","scale","px","py","textToStrokes","annotation","style","id","start","end","content","annotFontSize","strokes","totalDuration","fontSize","roughness","fontScale","charOffsetX","charCount","charDuration","charIndex","char","glyph","resolveGlyph","charWidth","charPaths","pathTiming","charStart","charEnd","pathCount","pathIndex","rawPoints","scaledPoints","jitterAmplitude","hashSeed","pathStart","pathEnd","pathDu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AGvC,QAAIG,EAAU,WAAW,GAAG;AAC1B,MAAAR,KAAeO,IAAY;AAC3B;AAAA,IACF;AAGA,UAAMG,IAAYnB,IAAQY,IAAYD,GAChCS,IAAUD,IAAYR,GAGtBU,IAAYJ,EAAU;AAE5B,aAASK,IAAY,GAAGA,IAAYL,EAAU,QAAQK,KAAa;AAEjE,YAAMC,IADWN,EAAUK,CAAS,EACT,UAAU,CAAA;AAErC,UAAIC,EAAU,SAAS,EAAG;AAG1B,YAAMC,IAAejC,EAAiBgC,GAAWd,GAAaD,CAAS,GAKjEiB,IAAkBlB,IAAY,MAC9BvB,IAAO0C,EAAS,GAAG3B,CAAE,IAAIa,CAAS,IAAIU,CAAS,EAAE,GACjDnC,IAASD,EAAYsC,GAAcC,GAAiBzC,CAAI;AAG9D,UAAI2C,GAAWC;AAEf,UAAIV,MAAe;AAEjB,QAAAS,IAAYR,GACZS,IAAUR;AAAA,WACL;AAEL,cAAMS,IAAelB,IAAeU;AACpC,QAAAM,IAAYR,IAAYG,IAAYO,GACpCD,IAAUD,IAAYE;AAAA,MACxB;AAEA,MAAAzB,EAAQ,KAAK;AAAA,QACX,IAAI,GAAGL,CAAE,IAAIa,CAAS,IAAIU,CAAS;AAAA,QACnC,QAAAnC;AAAA;AAAA,QACA,OAAOF;AAAA;AAAA,QACP,OAAOI;AAAA;AAAA,QACP,OAAOsC;AAAA,QACP,KAAKC;AAAA,QACL,OAAO9B,EAAM,SAAS;AAAA,QACtB,OAAOA,EAAM,SAAS;AAAA,QACtB,SAASA,EAAM,WAAW;AAAA,QAC1B,cAAc;AAAA;AAAA,MACtB,CAAO;AAAA,IACH;AAGA,IAAAW,KAAeO,IAAY;AAAA,EAC7B;AAEA,SAAOZ;AACT;"}
package/dist/index15.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("./index6.cjs"),G=require("./index12.cjs");function M(e,t=2){if(e.length<2||t<1)return e;const n=[];for(let r=0;r<e.length-1;r++){const[a,o]=e[r],[g,S]=e[r+1];n.push([a,o]);for(let s=1;s<=t;s++){const c=s/(t+1);n.push([a+(g-a)*c,o+(S-o)*c])}}return n.push(e[e.length-1]),n}function X(e,t,n){return e.map(([r,a])=>[(t+r)*n,a*n])}function z(e,t){const{id:n,start:r,end:a,content:o,x:g,y:S,fontSize:s}=e;if(!o||o.length===0)return[];const c=[],C=a-r,k=s||t.fontSize||16,m=t.subdivisions??2,q=k/1e3;let u=0;const I=o.length,x=C/I;for(let h=0;h<o.length;h++){const O=o[h],l=G.resolveGlyph(O);if(!l){u+=.5+.18;continue}const v=l.width||.5,p=l.paths||[],$=l.pathTiming||"sequential";if(p.length===0){u+=v+.18;continue}const b=r+h*x,j=b+x,y=p.length;for(let i=0;i<p.length;i++){let f=p[i].points||[];if(f.length<2)continue;m>0&&(f=M(f,m));let D=X(f,u,q),T=null;(t.pressure?.taperIn>0||t.pressure?.taperOut>0)&&(T=E.applyPressure(D,t.pressure));let d,P;if($==="parallel")d=b,P=j;else{const w=x/y;d=b+i*w,P=d+w}c.push({id:`${n}-${h}-${i}`,points:D,baseX:g,baseY:S,start:d,end:P,color:t.color||"rgba(220, 20, 60, 1.0)",width:t.width||2,lineCap:t.lineCap||"round",pressures:T,uniformScale:!0})}u+=v+.18}return c}exports.default=z;exports.textToStrokes=z;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./index29.cjs"),o=1e3;function h(l,t){const{id:s,start:r,end:S,quads:e}=l;if(!e||e.length===0)return[];const u=[],f=S-r,p=e.length,i=f/p,b=t.roughness??1,q=t.bowing??1,m=t.curveFitting??.95,v=t.curveStepCount??9,C=t.maxRandomnessOffset??2,k=t.disableMultiStroke??!1;for(let n=0;n<e.length;n++){const w=e[n],{x:a,y:x,w:M,h:P}=w,c=x+P,$=g.roughLine(a*o,c*o,(a+M)*o,c*o,{roughness:b,bowing:q,seed:g.hashSeed(`${s}-${n}`),curveFitting:m,curveStepCount:v,maxRandomnessOffset:C,disableMultiStroke:k}).map(([O,T])=>[O/o,T/o]),d=r+n*i,E=d+i;u.push({id:`${s}-${n}`,points:$,start:d,end:E,color:t.color||"rgba(0, 0, 255, 0.8)",width:t.width||2,lineCap:t.lineCap||"round"})}return u}exports.default=h;exports.underlineToStrokes=h;
2
2
  //# sourceMappingURL=index15.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index15.cjs","sources":["../src/converters/text.js"],"sourcesContent":["/**\n * Text Converter - Converts text annotations to stroke commands\n *\n * Transforms text content into stroke paths for each character,\n * using single-stroke font glyphs for smooth writing animation.\n *\n * @module converters/text\n */\n\nimport { applyPressure } from \"../pen/effects.js\";\nimport { resolveGlyph } from \"./glyphResolver.js\";\n\n/**\n * Subdivide a path by adding intermediate points between existing points.\n * This creates smoother interpolation during progressive rendering.\n *\n * @param {Array<[number, number]>} points - Original path points\n * @param {number} subdivisions - Number of points to add between each pair (default: 2)\n * @returns {Array<[number, number]>} Subdivided path with more points\n */\nfunction subdividePath(points, subdivisions = 2) {\n if (points.length < 2 || subdivisions < 1) {\n return points;\n }\n\n const result = [];\n\n for (let i = 0; i < points.length - 1; i++) {\n const [x1, y1] = points[i];\n const [x2, y2] = points[i + 1];\n\n // Add the start point\n result.push([x1, y1]);\n\n // Add intermediate points\n for (let j = 1; j <= subdivisions; j++) {\n const t = j / (subdivisions + 1);\n result.push([x1 + (x2 - x1) * t, y1 + (y2 - y1) * t]);\n }\n }\n\n // Add the final point\n result.push(points[points.length - 1]);\n\n return result;\n}\n\n\n/**\n * Scales glyph points by fontSize scale factor\n *\n * Glyph points are in normalized space where:\n * - X is 0 to charWidth (already scaled within the glyph)\n * - Y is 0 to ~1.0 (baseline at 0.8, cap height at 0)\n *\n * This scales them to the target size, but does NOT add the base position.\n * The base position is stored separately to allow correct rendering with\n * mixed coordinate systems (position in page coords, offsets in uniform space).\n *\n * @param {Array<[number, number]>} points - Glyph points in normalized space\n * @param {number} offsetX - X offset from base position (character offset within text)\n * @param {number} scale - Scale factor based on fontSize\n * @returns {Array<[number, number]>} Scaled offset points (not absolute positions)\n */\nfunction scaleGlyphPoints(points, offsetX, scale) {\n // Scale points and add character offset (in uniform space)\n return points.map(([px, py]) => [(offsetX + px) * scale, py * scale]);\n}\n\n/**\n * Converts a text annotation to stroke commands\n *\n * Each character in the content becomes one or more strokes.\n * Characters are staggered in timing to create a writing effect.\n * Multi-path characters (like 'i', 'j', '!') use pathTiming to\n * control whether paths are drawn sequentially or in parallel.\n *\n * @param {Object} annotation - Text 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 {string} annotation.content - Text content to render\n * @param {number} annotation.x - X position (normalized 0-1)\n * @param {number} annotation.y - Y position (normalized 0-1)\n * @param {number} [annotation.fontSize=16] - Font size in pixels\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 {number} [style.fontSize=16] - Default font size\n * @param {string} [style.lineCap='round'] - Line cap style\n * @param {Object} [style.jitter] - Jitter configuration\n * @param {Object} [style.pressure] - Pressure configuration\n * @param {number} [style.subdivisions=2] - Path subdivision level\n * @returns {Array<Object>} Array of stroke commands\n */\nexport function textToStrokes(annotation, style) {\n const { id, start, end, content, x, y, fontSize: annotFontSize } = annotation;\n\n if (!content || content.length === 0) {\n return [];\n }\n\n const strokes = [];\n const totalDuration = end - start;\n const fontSize = annotFontSize || style.fontSize || 16;\n const subdivisions = style.subdivisions ?? 2;\n\n // Scale factor: convert fontSize (pixels) to normalized coordinates\n // Assuming a reference viewport of ~1000px\n const scale = fontSize / 1000;\n\n // Track character offset from base position (in glyph units, not page coords)\n let charOffsetX = 0;\n\n // Calculate timing per character\n const charCount = content.length;\n const charDuration = totalDuration / charCount;\n\n for (let charIndex = 0; charIndex < content.length; charIndex++) {\n const char = content[charIndex];\n const glyph = resolveGlyph(char);\n\n if (!glyph) {\n // Skip unknown characters, but advance position with default width\n charOffsetX += 0.5 + 0.18; // default width + spacing (in glyph units)\n continue;\n }\n\n const charWidth = glyph.width || 0.5;\n const charPaths = glyph.paths || [];\n const pathTiming = glyph.pathTiming || \"sequential\";\n\n // Skip if no paths (e.g., space character)\n if (charPaths.length === 0) {\n charOffsetX += charWidth + 0.18;\n continue;\n }\n\n // Calculate timing for this character's paths\n const charStart = start + charIndex * charDuration;\n const charEnd = charStart + charDuration;\n\n // Determine path timing based on pathTiming mode\n const pathCount = charPaths.length;\n\n for (let pathIndex = 0; pathIndex < charPaths.length; pathIndex++) {\n const pathData = charPaths[pathIndex];\n let rawPoints = pathData.points || [];\n\n if (rawPoints.length < 2) continue;\n\n // Apply path subdivision for smoother interpolation\n if (subdivisions > 0) {\n rawPoints = subdividePath(rawPoints, subdivisions);\n }\n\n // Scale glyph points (offset coordinates, not absolute)\n let points = scaleGlyphPoints(rawPoints, charOffsetX, scale);\n\n // Calculate pressure values if configured\n let pressures = null;\n if (style.pressure?.taperIn > 0 || style.pressure?.taperOut > 0) {\n pressures = applyPressure(points, style.pressure);\n }\n\n // Calculate path timing based on pathTiming mode\n let pathStart, pathEnd;\n\n if (pathTiming === \"parallel\") {\n // All paths drawn simultaneously during character duration\n pathStart = charStart;\n pathEnd = charEnd;\n } else {\n // Sequential: each path gets a portion of character duration\n const pathDuration = charDuration / pathCount;\n pathStart = charStart + pathIndex * pathDuration;\n pathEnd = pathStart + pathDuration;\n }\n\n strokes.push({\n id: `${id}-${charIndex}-${pathIndex}`,\n points, // Offset coordinates from baseX/baseY (uniform space)\n baseX: x, // Base X position (width-normalized page coords)\n baseY: y, // Base Y position (height-normalized page coords)\n start: pathStart,\n end: pathEnd,\n color: style.color || \"rgba(220, 20, 60, 1.0)\",\n width: style.width || 2,\n lineCap: style.lineCap || \"round\",\n pressures,\n uniformScale: true, // Preserve aspect ratio when rendering\n });\n }\n\n // Advance offset for next character (in glyph units)\n charOffsetX += charWidth + 0.18; // Add small spacing\n }\n\n return strokes;\n}\n\nexport default textToStrokes;\n"],"names":["subdividePath","points","subdivisions","result","i","x1","y1","x2","y2","j","t","scaleGlyphPoints","offsetX","scale","px","py","textToStrokes","annotation","style","id","start","end","content","x","y","annotFontSize","strokes","totalDuration","fontSize","charOffsetX","charCount","charDuration","charIndex","char","glyph","resolveGlyph","charWidth","charPaths","pathTiming","charStart","charEnd","pathCount","pathIndex","rawPoints","pressures","applyPressure","pathStart","pathEnd","pathDuration"],"mappings":"uKAoBA,SAASA,EAAcC,EAAQC,EAAe,EAAG,CAC/C,GAAID,EAAO,OAAS,GAAKC,EAAe,EACtC,OAAOD,EAGT,MAAME,EAAS,CAAA,EAEf,QAASC,EAAI,EAAGA,EAAIH,EAAO,OAAS,EAAGG,IAAK,CAC1C,KAAM,CAACC,EAAIC,CAAE,EAAIL,EAAOG,CAAC,EACnB,CAACG,EAAIC,CAAE,EAAIP,EAAOG,EAAI,CAAC,EAG7BD,EAAO,KAAK,CAACE,EAAIC,CAAE,CAAC,EAGpB,QAASG,EAAI,EAAGA,GAAKP,EAAcO,IAAK,CACtC,MAAMC,EAAID,GAAKP,EAAe,GAC9BC,EAAO,KAAK,CAACE,GAAME,EAAKF,GAAMK,EAAGJ,GAAME,EAAKF,GAAMI,CAAC,CAAC,CACtD,CACF,CAGA,OAAAP,EAAO,KAAKF,EAAOA,EAAO,OAAS,CAAC,CAAC,EAE9BE,CACT,CAmBA,SAASQ,EAAiBV,EAAQW,EAASC,EAAO,CAEhD,OAAOZ,EAAO,IAAI,CAAC,CAACa,EAAIC,CAAE,IAAM,EAAEH,EAAUE,GAAMD,EAAOE,EAAKF,CAAK,CAAC,CACtE,CA6BO,SAASG,EAAcC,EAAYC,EAAO,CAC/C,KAAM,CAAE,GAAAC,EAAI,MAAAC,EAAO,IAAAC,EAAK,QAAAC,EAAS,EAAAC,EAAG,EAAAC,EAAG,SAAUC,CAAa,EA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AK,CACX,GAAI,GAAGP,CAAE,IAAIa,CAAS,IAAIU,CAAS,GACnC,OAAAzC,EACA,MAAOsB,EACP,MAAOC,EACP,MAAOsB,EACP,IAAKC,EACL,MAAO7B,EAAM,OAAS,yBACtB,MAAOA,EAAM,OAAS,EACtB,QAASA,EAAM,SAAW,QAC1B,UAAA0B,EACA,aAAc,EACtB,CAAO,CACH,CAGAf,GAAeO,EAAY,GAC7B,CAEA,OAAOV,CACT"}
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 with hand-drawn style.\n *\n * @module converters/underline\n */\n\nimport { roughLine, hashSeed } from '../rough/roughPathExtractor.js';\n\nconst SCALE = 1000;\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 * Uses RoughJS for hand-drawn style.\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 * @param {number} [style.roughness=1.0] - Hand-drawn roughness\n * @param {number} [style.bowing=1.0] - Line curvature\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 const roughness = style.roughness ?? 1.0;\n const bowing = style.bowing ?? 1.0;\n const curveFitting = style.curveFitting ?? 0.95;\n const curveStepCount = style.curveStepCount ?? 9;\n const maxRandomnessOffset = style.maxRandomnessOffset ?? 2;\n const disableMultiStroke = style.disableMultiStroke ?? false;\n\n for (let i = 0; i < quads.length; i++) {\n const quad = quads[i];\n const { x, y, w, h } = quad;\n\n const lineY = y + h;\n\n const roughPoints = roughLine(\n x * SCALE,\n lineY * SCALE,\n (x + w) * SCALE,\n lineY * SCALE,\n {\n roughness,\n bowing,\n seed: hashSeed(`${id}-${i}`),\n curveFitting,\n curveStepCount,\n maxRandomnessOffset,\n disableMultiStroke\n }\n );\n\n const points = roughPoints.map(([px, py]) => [px / SCALE, py / SCALE]);\n\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":["SCALE","underlineToStrokes","annotation","style","id","start","end","quads","strokes","totalDuration","quadCount","quadDuration","roughness","bowing","curveFitting","curveStepCount","maxRandomnessOffset","disableMultiStroke","i","quad","x","y","w","h","lineY","points","roughLine","hashSeed","px","py","quadStart","quadEnd"],"mappings":"6IAWMA,EAAQ,IAuBP,SAASC,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,EAE/BE,EAAYT,EAAM,WAAa,EAC/BU,EAASV,EAAM,QAAU,EACzBW,EAAeX,EAAM,cAAgB,IACrCY,EAAiBZ,EAAM,gBAAkB,EACzCa,EAAsBb,EAAM,qBAAuB,EACnDc,EAAqBd,EAAM,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