web-annotation-renderer 0.5.0 → 0.5.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 (73) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +39 -33
  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 +154 -119
  8. package/dist/index10.js.map +1 -1
  9. package/dist/index11.cjs +1 -1
  10. package/dist/index11.js +1 -1
  11. package/dist/index12.cjs +1 -1
  12. package/dist/index12.cjs.map +1 -1
  13. package/dist/index12.js +87 -87
  14. package/dist/index12.js.map +1 -1
  15. package/dist/index14.cjs +1 -1
  16. package/dist/index14.js +1 -1
  17. package/dist/index15.cjs +1 -1
  18. package/dist/index15.cjs.map +1 -1
  19. package/dist/index15.js +23 -117
  20. package/dist/index15.js.map +1 -1
  21. package/dist/index16.cjs +1 -1
  22. package/dist/index16.cjs.map +1 -1
  23. package/dist/index16.js +53 -103
  24. package/dist/index16.js.map +1 -1
  25. package/dist/index17.cjs +1 -1
  26. package/dist/index17.cjs.map +1 -1
  27. package/dist/index17.js +22 -57
  28. package/dist/index17.js.map +1 -1
  29. package/dist/index18.cjs +1 -1
  30. package/dist/index18.cjs.map +1 -1
  31. package/dist/index18.js +113 -136
  32. package/dist/index18.js.map +1 -1
  33. package/dist/index19.cjs +1 -1
  34. package/dist/index19.cjs.map +1 -1
  35. package/dist/index19.js +101 -35
  36. package/dist/index19.js.map +1 -1
  37. package/dist/index20.cjs +1 -1
  38. package/dist/index20.cjs.map +1 -1
  39. package/dist/index20.js +58 -36
  40. package/dist/index20.js.map +1 -1
  41. package/dist/index21.cjs +1 -1
  42. package/dist/index21.cjs.map +1 -1
  43. package/dist/index21.js +140 -37
  44. package/dist/index21.js.map +1 -1
  45. package/dist/index22.cjs +1 -1
  46. package/dist/index22.cjs.map +1 -1
  47. package/dist/index22.js +37 -21
  48. package/dist/index22.js.map +1 -1
  49. package/dist/index23.cjs +1 -1
  50. package/dist/index23.cjs.map +1 -1
  51. package/dist/index23.js +37 -5
  52. package/dist/index23.js.map +1 -1
  53. package/dist/index24.cjs +1 -1
  54. package/dist/index24.cjs.map +1 -1
  55. package/dist/index24.js +37 -4
  56. package/dist/index24.js.map +1 -1
  57. package/dist/index25.cjs +2 -0
  58. package/dist/index25.cjs.map +1 -0
  59. package/dist/index25.js +43 -0
  60. package/dist/index25.js.map +1 -0
  61. package/dist/index26.cjs +2 -0
  62. package/dist/index26.cjs.map +1 -0
  63. package/dist/index26.js +8 -0
  64. package/dist/index26.js.map +1 -0
  65. package/dist/index27.cjs +2 -0
  66. package/dist/index27.cjs.map +1 -0
  67. package/dist/index27.js +8 -0
  68. package/dist/index27.js.map +1 -0
  69. package/dist/index5.cjs +1 -1
  70. package/dist/index5.cjs.map +1 -1
  71. package/dist/index5.js +57 -36
  72. package/dist/index5.js.map +1 -1
  73. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index12.cjs","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 const engine = engineRef.current;\n\n /**\n * Start continuous sync when audio plays\n */\n const handlePlay = () => {\n engine.startContinuousSync(() => audio.currentTime);\n };\n\n /**\n * Stop continuous sync when audio pauses\n */\n const handlePause = () => {\n engine.stopContinuousSync();\n // Do one final sync to ensure we're at the correct position\n engine.setTime(audio.currentTime);\n };\n\n /**\n * Handle seeking - update time immediately\n */\n const handleSeeked = () => {\n engine.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 engine.stopContinuousSync();\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","engine","handlePlay","handlePause","handleSeeked","isFirstRender","defaultContainerStyle","defaultLayerStyle","defaultCanvasStyle","jsxs","jsx"],"mappings":"yNAoGA,SAASA,EAAS,CAEhB,OAAAC,EAGA,KAAAC,EAAO,EACP,MAAAC,EAAQ,IACR,YAAAC,EAAc,CAAA,EACd,YAAAC,EAAc,EAGd,SAAAC,EAGA,aAAAC,EAGA,OAAAC,EACA,QAAAC,EACA,aAAAC,EAGA,UAAAC,EACA,MAAAC,EACA,YAAAC,CACF,EAAG,CAUD,MAAMC,EAAYC,EAAAA,OAAO,IAAI,EAMvBC,EAAoBD,EAAAA,OAAO,IAAI,EAO/BE,EAAYF,EAAAA,OAA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CAAU,EAC5CF,EAAM,oBAAoB,QAASG,CAAW,EAC9CH,EAAM,oBAAoB,QAASG,CAAW,EAC9CH,EAAM,oBAAoB,SAAUI,CAAY,EAChDH,EAAO,mBAAA,CACT,CACF,EAAG,CAAC9B,EAAUa,CAAa,CAAC,EAU5B,MAAMqB,EAAgBzB,EAAAA,OAAO,EAAI,EAEjCgB,EAAAA,UAAU,IAAM,CAEd,GAAIS,EAAc,QAAS,CACzBA,EAAc,QAAU,GACxB,MACF,CAGA,GAAKvB,EAAU,SAKXS,EACF,GAAI,CACFT,EAAU,QAAQ,mBAAmBS,CAAkB,CACzD,OAASD,EAAO,CACd,QAAQ,MAAM,4CAA6CA,CAAK,EAC5DhB,GACFA,EAAQgB,CAAK,CAEjB,CAEJ,EAAG,CAACC,CAAkB,CAAC,EAUvB,MAAMe,EAAwB,CAC5B,SAAU,WACV,QAAS,eACT,WAAY,EACZ,GAAG7B,CAAA,EAOC8B,EAAoB,CACxB,SAAU,WACV,IAAK,EACL,KAAM,EACN,MAAO,OACP,OAAQ,OACR,cAAe,OACf,SAAU,QAAA,EAONC,EAAqB,CACzB,QAAS,QACT,GAAG9B,CAAA,EAOL,OACE+B,EAAAA,KAAC,MAAA,CAAI,UAAAjC,EAAsB,MAAO8B,EAChC,SAAA,CAAAI,EAAAA,IAAC,SAAA,CAAO,IAAK/B,EAAW,MAAO6B,EAAoB,EACnDE,EAAAA,IAAC,MAAA,CAAI,IAAK7B,EAAmB,MAAO0B,CAAA,CAAmB,CAAA,EACzD,CAEJ"}
1
+ {"version":3,"file":"index12.cjs","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","default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,MAAO6B,EAChC,SAAA,CAAAI,EAAAA,IAAC,SAAA,CAAO,IAAK9B,EAAW,MAAO4B,EAAoB,EACnDE,EAAAA,IAAC,MAAA,CAAI,IAAK5B,EAAmB,MAAOyB,CAAA,CAAmB,CAAA,EACzD,CAEJ"}
package/dist/index12.js CHANGED
@@ -1,156 +1,156 @@
1
- import { jsxs as Q, jsx as x } from "react/jsx-runtime";
2
- import { useRef as d, useState as q, useCallback as z, useMemo as H, useEffect as s } from "react";
3
- import { AnnotationRenderer as M } from "./index2.js";
4
- import { getPreset as N } from "./index17.js";
5
- function J({
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 "./index20.js";
5
+ function I({
6
6
  // Required props
7
- pdfUrl: v,
7
+ pdfUrl: p,
8
8
  // Optional props with defaults
9
9
  page: u = 1,
10
10
  scale: f = 1.5,
11
- annotations: g = [],
11
+ annotations: P = [],
12
12
  currentTime: h = 0,
13
13
  // Continuous sync mode (use instead of currentTime for smoother animation)
14
14
  audioRef: l,
15
15
  // Stroke configuration
16
16
  strokeConfig: a,
17
17
  // Callbacks
18
- onLoad: w,
19
- onError: t,
20
- onPageChange: A,
18
+ onLoad: g,
19
+ onError: r,
20
+ onPageChange: w,
21
21
  // Styling
22
- className: b,
23
- style: k,
24
- canvasStyle: T
22
+ className: x,
23
+ style: b,
24
+ canvasStyle: k
25
25
  }) {
26
- const m = d(null), P = d(null), r = d(null), F = d(Promise.resolve()), [i, S] = q(!1), c = z((e) => {
27
- F.current = F.current.then(e).catch((n) => {
28
- console.error("AnnotPdf: Queued operation failed:", n);
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
29
  });
30
- }, []), y = H(() => {
30
+ }, []), y = z(() => {
31
31
  if (!a)
32
32
  return;
33
- const e = a.preset || "default", n = N(e);
33
+ const e = a.preset || "default", o = M(e);
34
34
  return {
35
35
  highlight: {
36
- color: n.highlight.color,
37
- width: a.highlight?.width ?? n.highlight.width
36
+ color: o.highlight.color,
37
+ width: a.highlight?.width ?? o.highlight.width
38
38
  },
39
39
  text: {
40
- color: n.handText.color,
41
- width: a.text?.width ?? n.handText.width
40
+ color: o.handText.color,
41
+ width: a.text?.width ?? o.handText.width
42
42
  }
43
43
  };
44
44
  }, [a]);
45
- s(() => {
46
- if (!(!m.current || !P.current)) {
45
+ c(() => {
46
+ if (!(!v.current || !m.current)) {
47
47
  try {
48
- r.current = new M({
49
- canvasElement: m.current,
50
- container: P.current,
48
+ t.current = new H({
49
+ canvasElement: v.current,
50
+ container: m.current,
51
51
  strokeConfig: y
52
- }), S(!0);
52
+ }), F(!0);
53
53
  } catch (e) {
54
- console.error("AnnotPdf: Failed to initialize renderer:", e), t && t(e);
54
+ console.error("AnnotPdf: Failed to initialize renderer:", e), r && r(e);
55
55
  }
56
56
  return () => {
57
- S(!1), r.current && (r.current.destroy(), r.current = null);
57
+ F(!1), t.current && (t.current.destroy(), t.current = null);
58
58
  };
59
59
  }
60
- }, []), s(() => {
61
- if (!i || !v)
60
+ }, []), c(() => {
61
+ if (!i || !p)
62
62
  return;
63
63
  let e = !1;
64
- return c(async () => {
65
- if (r.current)
64
+ return s(async () => {
65
+ if (t.current)
66
66
  try {
67
- const o = await r.current.loadPDF(v);
67
+ const n = await t.current.loadPDF(p);
68
68
  if (e) return;
69
- if (!o.success) {
70
- console.error("AnnotPdf: Failed to load PDF:", o.error), t && t(new Error(o.error));
69
+ if (!n.success) {
70
+ console.error("AnnotPdf: Failed to load PDF:", n.error), r && r(new Error(n.error));
71
71
  return;
72
72
  }
73
- w && w({ pageCount: o.pageCount });
74
- } catch (o) {
73
+ g && g({ pageCount: n.pageCount });
74
+ } catch (n) {
75
75
  if (e) return;
76
- console.error("AnnotPdf: Failed to load PDF:", o), t && t(o);
76
+ console.error("AnnotPdf: Failed to load PDF:", n), r && r(n);
77
77
  }
78
78
  }), () => {
79
79
  e = !0;
80
80
  };
81
- }, [v, i, c]), s(() => {
82
- !i || !u || typeof u != "number" || c(async () => {
83
- if (r.current)
81
+ }, [p, i, s]), c(() => {
82
+ !i || !u || typeof u != "number" || s(async () => {
83
+ if (t.current)
84
84
  try {
85
- const e = await r.current.setPage(u);
85
+ const e = await t.current.setPage(u);
86
86
  if (!e.success) {
87
- console.error("AnnotPdf: Failed to set page:", e.error), t && t(new Error(e.error));
87
+ console.error("AnnotPdf: Failed to set page:", e.error), r && r(new Error(e.error));
88
88
  return;
89
89
  }
90
- A && A(u);
90
+ w && w(u);
91
91
  } catch (e) {
92
- console.error("AnnotPdf: Failed to set page:", e), t && t(e);
92
+ console.error("AnnotPdf: Failed to set page:", e), r && r(e);
93
93
  }
94
94
  });
95
- }, [u, i, c]), s(() => {
96
- !i || !f || typeof f != "number" || c(async () => {
97
- if (r.current)
95
+ }, [u, i, s]), c(() => {
96
+ !i || !f || typeof f != "number" || s(async () => {
97
+ if (t.current)
98
98
  try {
99
- const e = await r.current.setScale(f);
100
- e.success || (console.error("AnnotPdf: Failed to set scale:", e.error), t && t(new Error(e.error)));
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
101
  } catch (e) {
102
- console.error("AnnotPdf: Failed to set scale:", e), t && t(e);
102
+ console.error("AnnotPdf: Failed to set scale:", e), r && r(e);
103
103
  }
104
104
  });
105
- }, [f, i, c]), s(() => {
106
- if (!(!i || !r.current))
105
+ }, [f, i, s]), c(() => {
106
+ if (!(!i || !t.current))
107
107
  try {
108
- r.current.setAnnotations(g || []);
108
+ t.current.setAnnotations(P || []);
109
109
  } catch (e) {
110
- console.error("AnnotPdf: Failed to set annotations:", e), t && t(e);
110
+ console.error("AnnotPdf: Failed to set annotations:", e), r && r(e);
111
111
  }
112
- }, [g, i]), s(() => {
113
- if (!l && !(!i || !r.current || h === void 0 || h === null))
112
+ }, [P, i]), c(() => {
113
+ if (!l && !(!i || !t.current || h === void 0 || h === null))
114
114
  try {
115
- r.current.setTime(h);
115
+ t.current.setTime(h);
116
116
  } catch (e) {
117
- console.error("AnnotPdf: Failed to set time:", e), t && t(e);
117
+ console.error("AnnotPdf: Failed to set time:", e), r && r(e);
118
118
  }
119
- }, [h, l, i]), s(() => {
120
- if (!l?.current || !i || !r.current)
119
+ }, [h, l, i]), c(() => {
120
+ if (!l?.current || !i || !t.current)
121
121
  return;
122
- const e = l.current, n = r.current, o = () => {
123
- n.startContinuousSync(() => e.currentTime);
124
- }, p = () => {
125
- n.stopContinuousSync(), n.setTime(e.currentTime);
126
- }, L = () => {
127
- n.setTime(e.currentTime);
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
128
  };
129
- return e.addEventListener("play", o), e.addEventListener("pause", p), e.addEventListener("ended", p), e.addEventListener("seeked", L), e.paused || o(), () => {
130
- e.removeEventListener("play", o), e.removeEventListener("pause", p), e.removeEventListener("ended", p), e.removeEventListener("seeked", L), n.stopContinuousSync();
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
131
  };
132
132
  }, [l, i]);
133
- const C = d(!0);
134
- s(() => {
135
- if (C.current) {
136
- C.current = !1;
133
+ const S = d(!0);
134
+ c(() => {
135
+ if (S.current) {
136
+ S.current = !1;
137
137
  return;
138
138
  }
139
- if (r.current && y)
139
+ if (t.current && y)
140
140
  try {
141
- r.current.updateStrokeConfig(y);
141
+ t.current.updateStrokeConfig(y);
142
142
  } catch (e) {
143
- console.error("AnnotPdf: Failed to update stroke config:", e), t && t(e);
143
+ console.error("AnnotPdf: Failed to update stroke config:", e), r && r(e);
144
144
  }
145
145
  }, [y]);
146
- const R = {
146
+ const T = {
147
147
  position: "relative",
148
148
  display: "inline-block",
149
149
  lineHeight: 0,
150
150
  // Remove extra space below canvas
151
- ...k
151
+ ...b
152
152
  // User styles override defaults
153
- }, D = {
153
+ }, R = {
154
154
  position: "absolute",
155
155
  top: 0,
156
156
  left: 0,
@@ -159,17 +159,17 @@ function J({
159
159
  pointerEvents: "none",
160
160
  // Allow clicks to pass through to canvas
161
161
  overflow: "hidden"
162
- }, j = {
162
+ }, D = {
163
163
  display: "block",
164
- ...T
164
+ ...k
165
165
  // User styles override defaults
166
166
  };
167
- return /* @__PURE__ */ Q("div", { className: b, style: R, children: [
168
- /* @__PURE__ */ x("canvas", { ref: m, style: j }),
169
- /* @__PURE__ */ x("div", { ref: P, style: D })
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
170
  ] });
171
171
  }
172
172
  export {
173
- J as default
173
+ I as default
174
174
  };
175
175
  //# sourceMappingURL=index12.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index12.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 const engine = engineRef.current;\n\n /**\n * Start continuous sync when audio plays\n */\n const handlePlay = () => {\n engine.startContinuousSync(() => audio.currentTime);\n };\n\n /**\n * Stop continuous sync when audio pauses\n */\n const handlePause = () => {\n engine.stopContinuousSync();\n // Do one final sync to ensure we're at the correct position\n engine.setTime(audio.currentTime);\n };\n\n /**\n * Handle seeking - update time immediately\n */\n const handleSeeked = () => {\n engine.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 engine.stopContinuousSync();\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","engine","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,CA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AAA,IACZ,GAAG7B;AAAA;AAAA,EAAA,GAOC8B,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,GAAG9B;AAAA;AAAA,EAAA;AAOL,SACE,gBAAA+B,EAAC,OAAA,EAAI,WAAAjC,GAAsB,OAAO8B,GAChC,UAAA;AAAA,IAAA,gBAAAI,EAAC,UAAA,EAAO,KAAK/B,GAAW,OAAO6B,GAAoB;AAAA,IACnD,gBAAAE,EAAC,OAAA,EAAI,KAAK7B,GAAmB,OAAO0B,EAAA,CAAmB;AAAA,EAAA,GACzD;AAEJ;"}
1
+ {"version":3,"file":"index12.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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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;"}
package/dist/index14.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("./index6.cjs"),P=require("./index23.cjs");function X(t,e=2){if(t.length<2||e<1)return t;const n=[];for(let r=0;r<t.length-1;r++){const[a,o]=t[r],[g,S]=t[r+1];n.push([a,o]);for(let s=1;s<=e;s++){const u=s/(e+1);n.push([a+(g-a)*u,o+(S-o)*u])}}return n.push(t[t.length-1]),n}function _(t){return P.default.glyphs&&P.default.glyphs[t]?P.default.glyphs[t]:t===" "?{paths:[],width:.35}:null}function F(t,e,n){return t.map(([r,a])=>[(e+r)*n,a*n])}function z(t,e){const{id:n,start:r,end:a,content:o,x:g,y:S,fontSize:s}=t;if(!o||o.length===0)return[];const u=[],q=a-r,v=s||e.fontSize||16,k=e.subdivisions??2,I=v/1e3;let h=0;const O=o.length,x=q/O;for(let c=0;c<o.length;c++){const $=o[c],l=_($);if(!l){h+=.5+.18;continue}const m=l.width||.5,f=l.paths||[],j=l.pathTiming||"sequential";if(f.length===0){h+=m+.18;continue}const b=r+c*x,y=b+x,E=f.length;for(let i=0;i<f.length;i++){let p=f[i].points||[];if(p.length<2)continue;k>0&&(p=X(p,k));let w=F(p,h,I),C=null;(e.pressure?.taperIn>0||e.pressure?.taperOut>0)&&(C=M.applyPressure(w,e.pressure));let d,D;if(j==="parallel")d=b,D=y;else{const T=x/E;d=b+i*T,D=d+T}u.push({id:`${n}-${c}-${i}`,points:w,baseX:g,baseY:S,start:d,end:D,color:e.color||"rgba(220, 20, 60, 1.0)",width:e.width||2,lineCap:e.lineCap||"round",pressures:C,uniformScale:!0})}h+=m+.18}return u}exports.default=z;exports.textToStrokes=z;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("./index6.cjs"),P=require("./index26.cjs");function X(t,e=2){if(t.length<2||e<1)return t;const n=[];for(let r=0;r<t.length-1;r++){const[a,o]=t[r],[g,S]=t[r+1];n.push([a,o]);for(let s=1;s<=e;s++){const u=s/(e+1);n.push([a+(g-a)*u,o+(S-o)*u])}}return n.push(t[t.length-1]),n}function _(t){return P.default.glyphs&&P.default.glyphs[t]?P.default.glyphs[t]:t===" "?{paths:[],width:.35}:null}function F(t,e,n){return t.map(([r,a])=>[(e+r)*n,a*n])}function z(t,e){const{id:n,start:r,end:a,content:o,x:g,y:S,fontSize:s}=t;if(!o||o.length===0)return[];const u=[],q=a-r,v=s||e.fontSize||16,k=e.subdivisions??2,I=v/1e3;let h=0;const O=o.length,x=q/O;for(let c=0;c<o.length;c++){const $=o[c],l=_($);if(!l){h+=.5+.18;continue}const m=l.width||.5,f=l.paths||[],j=l.pathTiming||"sequential";if(f.length===0){h+=m+.18;continue}const b=r+c*x,y=b+x,E=f.length;for(let i=0;i<f.length;i++){let p=f[i].points||[];if(p.length<2)continue;k>0&&(p=X(p,k));let w=F(p,h,I),C=null;(e.pressure?.taperIn>0||e.pressure?.taperOut>0)&&(C=M.applyPressure(w,e.pressure));let d,D;if(j==="parallel")d=b,D=y;else{const T=x/E;d=b+i*T,D=d+T}u.push({id:`${n}-${c}-${i}`,points:w,baseX:g,baseY:S,start:d,end:D,color:e.color||"rgba(220, 20, 60, 1.0)",width:e.width||2,lineCap:e.lineCap||"round",pressures:C,uniformScale:!0})}h+=m+.18}return u}exports.default=z;exports.textToStrokes=z;
2
2
  //# sourceMappingURL=index14.cjs.map
package/dist/index14.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { applyPressure as q } from "./index6.js";
2
- import w from "./index23.js";
2
+ import w from "./index26.js";
3
3
  function v(t, n = 2) {
4
4
  if (t.length < 2 || n < 1)
5
5
  return t;
package/dist/index15.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("./index16.cjs");class o{constructor(t,s){this.canvas=t,this.dimensions={...s},this.ctx=null,this.strokeDrawer=null,this.strokeCommands=[],this.currentTime=0,this.isDestroyed=!1,this._setupCanvas()}_setupCanvas(){const t=window.devicePixelRatio||1,{width:s,height:e}=this.dimensions;this.canvas.width=Math.round(s*t),this.canvas.height=Math.round(e*t),this.canvas.style.width=`${s}px`,this.canvas.style.height=`${e}px`,this.ctx=this.canvas.getContext("2d"),this.ctx.setTransform(t,0,0,t,0,0),this.strokeDrawer=new n.default(this.ctx,this.dimensions)}setStrokeCommands(t){this.isDestroyed||(this.strokeCommands=t||[],this.strokeCommands.sort((s,e)=>{const r=s.start??0,i=e.start??0;return r-i}))}setTime(t){this.isDestroyed||(this.currentTime=t)}setDimensions(t){this.isDestroyed||(this.dimensions={...t},this._setupCanvas())}render(){if(!(this.isDestroyed||!this.ctx)){this.strokeDrawer.clear();for(const t of this.strokeCommands){const s=t.start??0,e=t.end??s+1;if(this.currentTime<s)continue;const r=this._calculateProgress(s,e);this.strokeDrawer.drawStroke(t,r)}}}_calculateProgress(t,s){if(this.currentTime>=s)return 1;const e=s-t;if(e<=0)return 1;const r=this.currentTime-t;return Math.max(0,Math.min(1,r/e))}clear(){this.isDestroyed||!this.strokeDrawer||this.strokeDrawer.clear()}getVisibleStrokeCount(){let t=0;for(const s of this.strokeCommands){const e=s.start??0;this.currentTime>=e&&t++}return t}destroy(){this.isDestroyed||(this.strokeCommands=[],this.strokeDrawer=null,this.ctx=null,this.canvas=null,this.isDestroyed=!0)}}exports.default=o;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function i(c,o){const{id:l,start:e,end:h,quads:t}=c;if(!t||t.length===0)return[];const r=[],g=h-e,q=t.length,u=g/q;for(let n=0;n<t.length;n++){const f=t[n],{x:s,y:p,w:S,h:b}=f,d=p+b,k=[[s,d],[s+S,d]],a=e+n*u,w=a+u;r.push({id:`${l}-${n}`,points:k,start:a,end:w,color:o.color||"rgba(0, 0, 255, 0.8)",width:o.width||2,lineCap:o.lineCap||"round"})}return r}exports.default=i;exports.underlineToStrokes=i;
2
2
  //# sourceMappingURL=index15.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index15.cjs","sources":["../src/pen/GradualRenderer.js"],"sourcesContent":["import StrokeDrawer from './StrokeDrawer.js';\n\n/**\n * GradualRenderer - Progressive stroke rendering synced to timeline\n *\n * Renders stroke commands with progressive reveal based on current\n * audio/video timeline position.\n *\n * Features:\n * - Progressive stroke reveal synced to audio timeline\n * - High-DPI canvas support for crisp rendering\n * - Efficient single-pass render per timeline update\n * - Accepts timing in seconds (start/end fields)\n *\n * @example\n * const renderer = new GradualRenderer(canvas, { width: 800, height: 600 });\n * renderer.setStrokeCommands(commands);\n * renderer.setTime(1.5); // seconds\n * renderer.render();\n */\nclass GradualRenderer {\n /**\n * Creates a new GradualRenderer instance\n *\n * @param {HTMLCanvasElement} canvas - Canvas element for rendering\n * @param {Object} pdfDimensions - PDF page dimensions\n * @param {number} pdfDimensions.width - Page width in pixels\n * @param {number} pdfDimensions.height - Page height in pixels\n */\n constructor(canvas, pdfDimensions) {\n this.canvas = canvas;\n this.dimensions = { ...pdfDimensions };\n this.ctx = null;\n this.strokeDrawer = null;\n this.strokeCommands = [];\n this.currentTime = 0; // seconds\n this.isDestroyed = false;\n\n this._setupCanvas();\n }\n\n /**\n * Configures canvas for high-DPI rendering\n *\n * @private\n */\n _setupCanvas() {\n const dpr = window.devicePixelRatio || 1;\n const { width, height } = this.dimensions;\n\n // Set canvas buffer resolution (high-res)\n this.canvas.width = Math.round(width * dpr);\n this.canvas.height = Math.round(height * dpr);\n\n // Set canvas display size (CSS)\n this.canvas.style.width = `${width}px`;\n this.canvas.style.height = `${height}px`;\n\n // Get context and scale for DPR\n this.ctx = this.canvas.getContext('2d');\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n // Create stroke drawer\n this.strokeDrawer = new StrokeDrawer(this.ctx, this.dimensions);\n }\n\n /**\n * Sets the stroke commands to render\n *\n * @param {Array} commands - Array of stroke command objects\n * @param {string} commands[].id - Unique stroke identifier\n * @param {Array} commands[].points - [[x, y], ...] normalized coordinates\n * @param {string} commands[].color - Stroke color\n * @param {number} commands[].width - Stroke width in pixels\n * @param {number} commands[].start - Start time in seconds\n * @param {number} commands[].end - End time in seconds\n */\n setStrokeCommands(commands) {\n if (this.isDestroyed) return;\n\n this.strokeCommands = commands || [];\n\n // Sort by start time for efficient rendering\n this.strokeCommands.sort((a, b) => {\n const startA = a.start ?? 0;\n const startB = b.start ?? 0;\n return startA - startB;\n });\n }\n\n /**\n * Sets the current timeline position\n *\n * @param {number} time - Current time in seconds\n */\n setTime(time) {\n if (this.isDestroyed) return;\n this.currentTime = time;\n }\n\n /**\n * Updates dimensions when viewport changes\n *\n * @param {Object} dimensions - New dimensions\n * @param {number} dimensions.width - Width in pixels\n * @param {number} dimensions.height - Height in pixels\n */\n setDimensions(dimensions) {\n if (this.isDestroyed) return;\n\n this.dimensions = { ...dimensions };\n this._setupCanvas();\n }\n\n /**\n * Renders all visible strokes at current timeline position\n *\n * Called once per timeline update. Clears canvas and redraws\n * all strokes with appropriate progress.\n */\n render() {\n if (this.isDestroyed || !this.ctx) return;\n\n // Clear canvas\n this.strokeDrawer.clear();\n\n // Draw each stroke based on timing\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n const end = stroke.end ?? start + 1;\n\n // Skip strokes that haven't started\n if (this.currentTime < start) {\n continue;\n }\n\n // Calculate progress\n const progress = this._calculateProgress(start, end);\n\n // Draw stroke with progress\n this.strokeDrawer.drawStroke(stroke, progress);\n }\n }\n\n /**\n * Calculates stroke progress based on timing\n *\n * @private\n * @param {number} start - Stroke start time in seconds\n * @param {number} end - Stroke end time in seconds\n * @returns {number} Progress from 0 to 1\n */\n _calculateProgress(start, end) {\n if (this.currentTime >= end) {\n return 1.0; // Fully visible\n }\n\n const duration = end - start;\n if (duration <= 0) return 1.0;\n\n const elapsed = this.currentTime - start;\n return Math.max(0, Math.min(1, elapsed / duration));\n }\n\n /**\n * Clears the canvas\n */\n clear() {\n if (this.isDestroyed || !this.strokeDrawer) return;\n this.strokeDrawer.clear();\n }\n\n /**\n * Gets visible stroke count at current time\n *\n * @returns {number} Number of visible strokes\n */\n getVisibleStrokeCount() {\n let count = 0;\n for (const stroke of this.strokeCommands) {\n const start = stroke.start ?? 0;\n if (this.currentTime >= start) {\n count++;\n }\n }\n return count;\n }\n\n /**\n * Destroys the renderer and releases resources\n */\n destroy() {\n if (this.isDestroyed) return;\n\n this.strokeCommands = [];\n this.strokeDrawer = null;\n this.ctx = null;\n this.canvas = null;\n this.isDestroyed = true;\n }\n}\n\nexport default GradualRenderer;\n"],"names":["GradualRenderer","canvas","pdfDimensions","dpr","width","height","StrokeDrawer","commands","a","b","startA","startB","time","dimensions","stroke","start","end","progress","duration","elapsed","count"],"mappings":"6IAoBA,MAAMA,CAAgB,CASpB,YAAYC,EAAQC,EAAe,CACjC,KAAK,OAASD,EACd,KAAK,WAAa,CAAE,GAAGC,CAAa,EACpC,KAAK,IAAM,KACX,KAAK,aAAe,KACpB,KAAK,eAAiB,CAAA,EACtB,KAAK,YAAc,EACnB,KAAK,YAAc,GAEnB,KAAK,aAAY,CACnB,CAOA,cAAe,CACb,MAAMC,EAAM,OAAO,kBAAoB,EACjC,CAAE,MAAAC,EAAO,OAAAC,CAAM,EAAK,KAAK,WAG/B,KAAK,OAAO,MAAQ,KAAK,MAAMD,EAAQD,CAAG,EAC1C,KAAK,OAAO,OAAS,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,aAAa,MAAK,CACzB,CAOA,uBAAwB,CACtB,IAAIE,EAAQ,EACZ,UAAWN,KAAU,KAAK,eAAgB,CACxC,MAAMC,EAAQD,EAAO,OAAS,EAC1B,KAAK,aAAeC,GACtBK,GAEJ,CACA,OAAOA,CACT,CAKA,SAAU,CACJ,KAAK,cAET,KAAK,eAAiB,CAAA,EACtB,KAAK,aAAe,KACpB,KAAK,IAAM,KACX,KAAK,OAAS,KACd,KAAK,YAAc,GACrB,CACF"}
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"}