web-annotation-renderer 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -61
- package/dist/index.js.map +1 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.cjs.map +1 -1
- package/dist/index10.js +160 -13
- package/dist/index10.js.map +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.cjs.map +1 -1
- package/dist/index11.js +13 -50
- package/dist/index11.js.map +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.cjs.map +1 -1
- package/dist/index12.js +48 -155
- package/dist/index12.js.map +1 -1
- package/dist/index13.cjs +1 -1
- package/dist/index13.cjs.map +1 -1
- package/dist/index13.js +150 -34
- package/dist/index13.js.map +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.cjs.map +1 -1
- package/dist/index14.js +32 -65
- package/dist/index14.js.map +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.cjs.map +1 -1
- package/dist/index15.js +66 -33
- package/dist/index15.js.map +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.cjs.map +1 -1
- package/dist/index16.js +35 -77
- package/dist/index16.js.map +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.cjs.map +1 -1
- package/dist/index17.js +53 -28
- package/dist/index17.js.map +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.cjs.map +1 -1
- package/dist/index18.js +28 -22
- package/dist/index18.js.map +1 -1
- package/dist/index19.cjs +1 -1
- package/dist/index19.cjs.map +1 -1
- package/dist/index19.js +22 -117
- package/dist/index19.js.map +1 -1
- package/dist/index2.cjs +1 -1
- package/dist/index2.cjs.map +1 -1
- package/dist/index2.js +94 -98
- package/dist/index2.js.map +1 -1
- package/dist/index20.cjs +1 -1
- package/dist/index20.cjs.map +1 -1
- package/dist/index20.js +137 -100
- package/dist/index20.js.map +1 -1
- package/dist/index21.cjs +1 -1
- package/dist/index21.cjs.map +1 -1
- package/dist/index21.js +34 -76
- package/dist/index21.js.map +1 -1
- package/dist/index22.cjs +1 -1
- package/dist/index22.cjs.map +1 -1
- package/dist/index22.js +35 -139
- package/dist/index22.js.map +1 -1
- package/dist/index23.cjs +1 -1
- package/dist/index23.cjs.map +1 -1
- package/dist/index23.js +37 -37
- package/dist/index23.js.map +1 -1
- package/dist/index24.cjs +1 -1
- package/dist/index24.cjs.map +1 -1
- package/dist/index24.js +69 -37
- package/dist/index24.js.map +1 -1
- package/dist/index25.cjs +1 -1
- package/dist/index25.cjs.map +1 -1
- package/dist/index25.js +40 -38
- package/dist/index25.js.map +1 -1
- package/dist/index26.cjs +1 -1
- package/dist/index26.cjs.map +1 -1
- package/dist/index26.js +4 -39
- package/dist/index26.js.map +1 -1
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +4 -4
- package/dist/index28.cjs +1 -1
- package/dist/index28.cjs.map +1 -1
- package/dist/index28.js +71 -5
- package/dist/index28.js.map +1 -1
- package/dist/index29.cjs +1 -1
- package/dist/index29.cjs.map +1 -1
- package/dist/index29.js +24 -69
- package/dist/index29.js.map +1 -1
- package/dist/index3.cjs +1 -1
- package/dist/index3.cjs.map +1 -1
- package/dist/index3.js +31 -31
- package/dist/index3.js.map +1 -1
- package/dist/index5.cjs +1 -1
- package/dist/index5.cjs.map +1 -1
- package/dist/index5.js +237 -190
- package/dist/index5.js.map +1 -1
- package/dist/index6.cjs +1 -1
- package/dist/index6.cjs.map +1 -1
- package/dist/index6.js +37 -19
- package/dist/index6.js.map +1 -1
- package/dist/index7.cjs +1 -1
- package/dist/index7.cjs.map +1 -1
- package/dist/index7.js +11 -17
- package/dist/index7.js.map +1 -1
- package/dist/index8.cjs +1 -1
- package/dist/index8.cjs.map +1 -1
- package/dist/index8.js +16 -125
- package/dist/index8.js.map +1 -1
- package/dist/index9.cjs +1 -1
- package/dist/index9.cjs.map +1 -1
- package/dist/index9.js +118 -201
- package/dist/index9.js.map +1 -1
- package/package.json +6 -3
package/dist/index5.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index5.js","sources":["../src/renderer/StrokeRenderer.js"],"sourcesContent":["/**\n * StrokeRenderer - Unified canvas-based annotation renderer\n *\n * Single entry point for rendering annotations as strokes on canvas.\n * Handles conversion from annotations to strokes and progressive rendering.\n *\n * @module renderer/StrokeRenderer\n */\n\nimport {\n highlightToStrokes,\n textToStrokes,\n underlineToStrokes,\n arrowToStrokes,\n circleToStrokes,\n inkToStrokes,\n} from \"../converters/index.js\";\n\n/**\n * Supported annotation types\n */\nconst ANNOTATION_TYPES = [\n \"highlight\",\n \"text\",\n \"underline\",\n \"arrow\",\n \"circle\",\n \"ink\",\n];\n\n/**\n * Reference viewport height for width scaling\n * Stroke widths are defined relative to this height (500px = roughjs-tester default)\n */\nconst REFERENCE_HEIGHT = 500;\n\n/**\n * Default configuration\n *\n * Each annotation type has:\n * - Rendering options: color, width, lineCap\n * - RoughJS options: roughness, bowing, curveFitting, curveStepCount, maxRandomnessOffset, disableMultiStroke\n */\nconst DEFAULT_CONFIG = {\n highlight: {\n color: \"rgba(255, 255, 0, 0.3)\",\n width: 24,\n lineCap: \"square\",\n roughness: 1.2,\n bowing: 1.2,\n curveFitting: 0.95,\n curveStepCount: 9,\n maxRandomnessOffset: 2,\n disableMultiStroke: false,\n },\n text: {\n color: \"rgba(220, 20, 60, 1.0)\",\n width: 2,\n fontSize: 16,\n lineCap: \"round\",\n roughness: 0.8,\n },\n underline: {\n color: \"rgba(0, 0, 255, 0.8)\",\n width: 2,\n lineCap: \"round\",\n roughness: 1.8,\n bowing: 2,\n curveFitting: 0.85,\n curveStepCount: 9,\n maxRandomnessOffset: 3,\n disableMultiStroke: false,\n },\n arrow: {\n color: \"rgba(255, 0, 0, 0.8)\",\n width: 2,\n lineCap: \"round\",\n roughness: 1.8,\n bowing: 1.8,\n curveFitting: 0.9,\n curveStepCount: 9,\n maxRandomnessOffset: 2,\n disableMultiStroke: false,\n },\n circle: {\n color: \"rgba(255, 165, 0, 0.8)\",\n width: 3,\n lineCap: \"round\",\n roughness: 1.5,\n bowing: 1.7,\n curveFitting: 0.8,\n curveStepCount: 12,\n maxRandomnessOffset: 3,\n disableMultiStroke: false,\n },\n ink: {\n color: \"#DC143C\",\n width: 2,\n lineCap: \"round\",\n },\n};\n\n/**\n * StrokeRenderer class\n *\n * Converts annotations to strokes and renders them progressively on canvas.\n *\n * @class\n * @example\n * const renderer = new StrokeRenderer(canvas, {\n * highlight: { color: 'rgba(0, 255, 200, 0.4)' }\n * });\n * renderer.setViewport(800, 600);\n * renderer.setAnnotations(annotations);\n * renderer.render(1.5); // Render at t=1.5 seconds\n */\nclass StrokeRenderer {\n /**\n * Create StrokeRenderer instance\n *\n * @param {HTMLCanvasElement} canvas - Canvas element for rendering\n * @param {Object} [config={}] - Configuration overrides per annotation type\n * @param {Object} [config.highlight] - Highlight type settings\n * @param {Object} [config.text] - Text type settings\n * @param {Object} [config.underline] - Underline type settings\n * @param {Object} [config.arrow] - Arrow type settings\n * @param {Object} [config.circle] - Circle type settings\n */\n constructor(canvas, config = {}) {\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n throw new Error(\n \"StrokeRenderer: canvas must be a valid HTMLCanvasElement\",\n );\n }\n\n this.canvas = canvas;\n this.ctx = canvas.getContext(\"2d\");\n this.strokes = [];\n this.viewport = { width: 0, height: 0 };\n\n // Initialize config with defaults\n this.config = {};\n for (const type of ANNOTATION_TYPES) {\n this.config[type] = { ...DEFAULT_CONFIG[type] };\n }\n\n // Apply user config if provided\n if (Object.keys(config).length > 0) {\n this.setConfig(config);\n }\n\n // Register built-in converters\n this.converters = {\n highlight: highlightToStrokes,\n text: textToStrokes,\n underline: underlineToStrokes,\n arrow: arrowToStrokes,\n circle: circleToStrokes,\n ink: inkToStrokes,\n };\n }\n\n /**\n * Set configuration options\n *\n * Supports global options (applied to all types) and type-specific options.\n *\n * @param {Object} config - Configuration object\n * @param {number} [config.roughness] - Global roughness for all types\n * @param {string} [config.color] - Global color for all types\n * @param {number} [config.width] - Global width for all types\n * @param {Object} [config.highlight] - Highlight-specific options\n * @param {Object} [config.text] - Text-specific options\n * @param {Object} [config.underline] - Underline-specific options\n * @param {Object} [config.arrow] - Arrow-specific options\n * @param {Object} [config.circle] - Circle-specific options\n * @returns {StrokeRenderer} Returns this for chaining\n *\n * @example\n * // Global options\n * renderer.setConfig({ roughness: 2, color: \"blue\" });\n *\n * // Type-specific options\n * renderer.setConfig({ highlight: { color: \"yellow\", width: 30 } });\n *\n * // Combined\n * renderer.setConfig({\n * roughness: 2,\n * highlight: { color: \"yellow\" }\n * });\n */\n setConfig(config) {\n const globalOptions = {};\n const typeOptions = {};\n\n // Separate global options from type-specific options\n for (const [key, value] of Object.entries(config)) {\n if (ANNOTATION_TYPES.includes(key)) {\n typeOptions[key] = value;\n } else {\n globalOptions[key] = value;\n }\n }\n\n // Apply to each type: current config + global + type-specific\n for (const type of ANNOTATION_TYPES) {\n this.config[type] = {\n ...this.config[type],\n ...globalOptions,\n ...(typeOptions[type] || {}),\n };\n }\n\n return this;\n }\n\n /**\n * Register a custom converter for a new annotation type\n *\n * @param {string} type - Annotation type name\n * @param {Function} converter - Converter function (annotation, style) => strokes[]\n */\n registerConverter(type, converter) {\n if (typeof converter !== \"function\") {\n throw new Error(\n \"StrokeRenderer.registerConverter: converter must be a function\",\n );\n }\n this.converters[type] = converter;\n }\n\n /**\n * Set viewport dimensions and configure canvas\n *\n * Handles high-DPI displays by scaling the canvas buffer.\n *\n * @param {number} width - Viewport width in CSS pixels\n * @param {number} height - Viewport height in CSS pixels\n */\n setViewport(width, height) {\n this.viewport = { width, height };\n\n const dpr = window.devicePixelRatio || 1;\n\n // Set canvas buffer size (high-res)\n this.canvas.width = width * dpr;\n this.canvas.height = 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 // Scale context for high-DPI\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n }\n\n /**\n * Set annotations and convert them to strokes\n *\n * Clears existing strokes and converts all annotations.\n *\n * @param {Array} annotations - Array of annotation objects\n * @param {number} [page] - Optional page filter (only convert annotations for this page)\n */\n setAnnotations(annotations, page = null) {\n if (!Array.isArray(annotations)) {\n console.warn(\n \"StrokeRenderer.setAnnotations: annotations must be an array\",\n );\n this.strokes = [];\n return;\n }\n\n // Filter by page if specified\n const filtered =\n page !== null ? annotations.filter((a) => a.page === page) : annotations;\n\n // Convert each annotation to strokes\n this.strokes = filtered.flatMap((annotation) => {\n const converter = this.converters[annotation.type];\n\n if (!converter) {\n console.warn(\n `StrokeRenderer: Unknown annotation type \"${annotation.type}\"`,\n );\n return [];\n }\n\n // Resolve style: pen → type → annotation.style\n const style = this._resolveStyle(annotation);\n\n return converter(annotation, style);\n });\n }\n\n /**\n * Set pre-converted strokes directly\n *\n * Bypasses conversion, useful when strokes come from external source.\n *\n * @param {Array} strokes - Array of stroke command objects\n */\n setStrokes(strokes) {\n if (!Array.isArray(strokes)) {\n console.warn(\"StrokeRenderer.setStrokes: strokes must be an array\");\n this.strokes = [];\n return;\n }\n this.strokes = strokes;\n }\n\n /**\n * Render strokes at the given time\n *\n * Clears canvas and draws all visible strokes with appropriate progress.\n *\n * @param {number} time - Current time in seconds\n */\n render(time) {\n const { ctx, viewport, strokes } = this;\n\n // Clear canvas\n ctx.clearRect(0, 0, viewport.width, viewport.height);\n\n // Draw each stroke\n for (const stroke of strokes) {\n // Skip if not started yet\n if (time < stroke.start) {\n continue;\n }\n\n // Calculate progress\n const duration = stroke.end - stroke.start;\n const elapsed = time - stroke.start;\n const progress = duration > 0 ? Math.min(1, elapsed / duration) : 1;\n\n this._drawStroke(stroke, progress);\n }\n }\n\n /**\n * Clear the canvas\n */\n clear() {\n this.ctx.clearRect(0, 0, this.viewport.width, this.viewport.height);\n }\n\n /**\n * Destroy the renderer and release resources\n */\n destroy() {\n this.strokes = [];\n this.ctx = null;\n this.canvas = null;\n this.config = null;\n this.converters = null;\n }\n\n /**\n * Resolve style for an annotation\n *\n * Returns the config for the annotation type.\n * Style is managed via setConfig(), not per-annotation.\n *\n * @private\n * @param {Object} annotation - Annotation object\n * @returns {Object} Resolved style object\n */\n _resolveStyle(annotation) {\n const { type } = annotation;\n return this.config[type] || {};\n }\n\n /**\n * Linearly interpolate between two points\n *\n * @private\n * @param {Array} p1 - Start point [x, y]\n * @param {Array} p2 - End point [x, y]\n * @param {number} t - Interpolation factor (0-1)\n * @returns {Array} Interpolated point [x, y]\n */\n _interpolatePoint(p1, p2, t) {\n return [p1[0] + (p2[0] - p1[0]) * t, p1[1] + (p2[1] - p1[1]) * t];\n }\n\n /**\n * Get pressure values for visible points including interpolated final\n *\n * @private\n * @param {Array} pressures - Full pressure array\n * @param {number} lastCompleteIndex - Index of last complete point\n * @param {number} segmentProgress - Progress within current segment (0-1)\n * @returns {Array} Pressure values for visible points\n */\n _interpolatePressures(pressures, lastCompleteIndex, segmentProgress) {\n const visiblePressures = pressures.slice(0, lastCompleteIndex + 1);\n\n if (lastCompleteIndex < pressures.length - 1 && segmentProgress > 0) {\n const p1 = pressures[lastCompleteIndex];\n const p2 = pressures[lastCompleteIndex + 1];\n visiblePressures.push(p1 + (p2 - p1) * segmentProgress);\n }\n\n return visiblePressures;\n }\n\n /**\n * Draw a single stroke with progress\n *\n * Uses endpoint interpolation for smooth progressive rendering.\n *\n * @private\n * @param {Object} stroke - Stroke command object\n * @param {number} progress - Progress from 0 to 1\n */\n _drawStroke(stroke, progress) {\n const { ctx } = this;\n const {\n points,\n color,\n width,\n lineCap,\n pressures,\n uniformScale,\n baseX,\n baseY,\n } = stroke;\n\n if (!points || points.length < 2) return;\n\n // Configure stroke style\n ctx.strokeStyle = color || \"rgba(0, 0, 0, 0.5)\";\n ctx.lineCap = lineCap || \"round\";\n ctx.lineJoin = \"round\";\n\n // Fast path: full stroke, no interpolation needed\n if (progress >= 1) {\n if (pressures && pressures.length >= points.length) {\n this._drawVariableWidthStroke(\n points,\n width,\n pressures,\n uniformScale,\n baseX,\n baseY,\n );\n } else {\n this._drawConstantWidthStroke(\n points,\n width,\n uniformScale,\n baseX,\n baseY,\n );\n }\n return;\n }\n\n // Calculate segment position for interpolation\n const totalSegments = points.length - 1;\n const progressAlongPath = progress * totalSegments;\n const lastCompleteIndex = Math.floor(progressAlongPath);\n const segmentProgress = progressAlongPath - lastCompleteIndex;\n\n // Build visible points array with complete points\n const visiblePoints = points.slice(0, lastCompleteIndex + 1);\n\n // Interpolate final point if mid-segment\n if (lastCompleteIndex < totalSegments && segmentProgress > 0) {\n const p1 = points[lastCompleteIndex];\n const p2 = points[lastCompleteIndex + 1];\n visiblePoints.push(this._interpolatePoint(p1, p2, segmentProgress));\n }\n\n // Need at least 2 points to draw a line\n if (visiblePoints.length < 2) return;\n\n // Draw with variable width if pressures provided\n if (pressures && pressures.length >= points.length) {\n const visiblePressures = this._interpolatePressures(\n pressures,\n lastCompleteIndex,\n segmentProgress,\n );\n this._drawVariableWidthStroke(\n visiblePoints,\n width,\n visiblePressures,\n uniformScale,\n baseX,\n baseY,\n );\n } else {\n this._drawConstantWidthStroke(\n visiblePoints,\n width,\n uniformScale,\n baseX,\n baseY,\n );\n }\n }\n\n /**\n * Draw stroke with constant width\n *\n * @private\n * @param {Array} points - Array of [x, y] coordinates (normalized or offset)\n * @param {number} width - Stroke width in pixels\n * @param {boolean} [uniformScale=false] - Use uniform scaling to preserve aspect ratio\n * @param {number} [baseX] - Base X position in width-normalized coords (for uniformScale with offset points)\n * @param {number} [baseY] - Base Y position in height-normalized coords (for uniformScale with offset points)\n */\n _drawConstantWidthStroke(\n points,\n width,\n uniformScale = false,\n baseX = null,\n baseY = null,\n ) {\n const { ctx, viewport } = this;\n\n // Scale width based on viewport height for consistent appearance\n const scale = viewport.height / REFERENCE_HEIGHT;\n ctx.lineWidth = (width || 2) * scale;\n ctx.beginPath();\n\n // When uniformScale is true and baseX/baseY provided, points are offsets from base position\n // Base position is in mixed coords (X: width-normalized, Y: height-normalized)\n // Offsets are in uniform space (both scaled by viewport.height)\n const hasBasePosition = uniformScale && baseX !== null && baseY !== null;\n\n for (let i = 0; i < points.length; i++) {\n const [coordX, coordY] = points[i];\n let px, py;\n\n if (hasBasePosition) {\n // Base position in pixels + uniform-scaled offset\n px = baseX * viewport.width + coordX * viewport.height;\n py = baseY * viewport.height + coordY * viewport.height;\n } else if (uniformScale) {\n // Legacy: full coordinates in uniform space\n px = coordX * viewport.height;\n py = coordY * viewport.height;\n } else {\n // Standard: X scaled by width, Y by height\n px = coordX * viewport.width;\n py = coordY * viewport.height;\n }\n\n if (i === 0) {\n ctx.moveTo(px, py);\n } else {\n ctx.lineTo(px, py);\n }\n }\n\n ctx.stroke();\n }\n\n /**\n * Draw stroke with variable width based on pressure\n *\n * @private\n * @param {Array} points - Array of [x, y] coordinates (normalized or offset)\n * @param {number} baseWidth - Base stroke width in pixels\n * @param {Array} pressures - Pressure values (0-1) per point\n * @param {boolean} [uniformScale=false] - Use uniform scaling to preserve aspect ratio\n * @param {number} [baseX] - Base X position in width-normalized coords (for uniformScale with offset points)\n * @param {number} [baseY] - Base Y position in height-normalized coords (for uniformScale with offset points)\n */\n _drawVariableWidthStroke(\n points,\n baseWidth,\n pressures,\n uniformScale = false,\n baseX = null,\n baseY = null,\n ) {\n const { ctx, viewport } = this;\n\n // When uniformScale is true and baseX/baseY provided, points are offsets from base position\n const hasBasePosition = uniformScale && baseX !== null && baseY !== null;\n\n for (let i = 1; i < points.length; i++) {\n const [c1x, c1y] = points[i - 1];\n const [c2x, c2y] = points[i];\n\n let px1, py1, px2, py2;\n\n if (hasBasePosition) {\n // Base position in pixels + uniform-scaled offset\n px1 = baseX * viewport.width + c1x * viewport.height;\n py1 = baseY * viewport.height + c1y * viewport.height;\n px2 = baseX * viewport.width + c2x * viewport.height;\n py2 = baseY * viewport.height + c2y * viewport.height;\n } else if (uniformScale) {\n // Legacy: full coordinates in uniform space\n px1 = c1x * viewport.height;\n py1 = c1y * viewport.height;\n px2 = c2x * viewport.height;\n py2 = c2y * viewport.height;\n } else {\n // Standard: X scaled by width, Y by height\n px1 = c1x * viewport.width;\n py1 = c1y * viewport.height;\n px2 = c2x * viewport.width;\n py2 = c2y * viewport.height;\n }\n\n // Average pressure between two points\n const p1 = pressures[i - 1] || 1;\n const p2 = pressures[i] || 1;\n const avgPressure = (p1 + p2) / 2;\n\n // Apply pressure to width (min 0.5) and scale for viewport\n const scale = viewport.height / REFERENCE_HEIGHT;\n const width = Math.max(0.5, baseWidth * avgPressure) * scale;\n\n ctx.lineWidth = width;\n ctx.beginPath();\n ctx.moveTo(px1, py1);\n ctx.lineTo(px2, py2);\n ctx.stroke();\n }\n }\n}\n\nexport { StrokeRenderer };\nexport default StrokeRenderer;\n"],"names":["ANNOTATION_TYPES","REFERENCE_HEIGHT","DEFAULT_CONFIG","StrokeRenderer","canvas","config","type","highlightToStrokes","textToStrokes","underlineToStrokes","arrowToStrokes","circleToStrokes","inkToStrokes","globalOptions","typeOptions","key","value","converter","width","height","dpr","annotations","page","filtered","a","annotation","style","strokes","time","ctx","viewport","stroke","duration","elapsed","progress","p1","p2","t","pressures","lastCompleteIndex","segmentProgress","visiblePressures","points","color","lineCap","uniformScale","baseX","baseY","totalSegments","progressAlongPath","visiblePoints","scale","hasBasePosition","i","coordX","coordY","px","py","baseWidth","c1x","c1y","c2x","c2y","px1","py1","px2","py2","avgPressure"],"mappings":";;;;;;AAqBA,MAAMA,IAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMMC,IAAmB,KASnBC,IAAiB;AAAA,EACrB,WAAW;AAAA,IACT,OAAO;AAAA,IACP,OAAO;AAAA,IACP,SAAS;AAAA,IACT,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,qBAAqB;AAAA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,IAAI,GAAGA,IAAIX,EAAO,QAAQW,KAAK;AACtC,YAAM,CAACM,GAAKC,CAAG,IAAIlB,EAAOW,IAAI,CAAC,GACzB,CAACQ,GAAKC,CAAG,IAAIpB,EAAOW,CAAC;AAE3B,UAAIU,GAAKC,GAAKC,GAAKC;AAEnB,MAAId,KAEFW,IAAMjB,IAAQhB,EAAS,QAAQ6B,IAAM7B,EAAS,QAC9CkC,IAAMjB,IAAQjB,EAAS,SAAS8B,IAAM9B,EAAS,QAC/CmC,IAAMnB,IAAQhB,EAAS,QAAQ+B,IAAM/B,EAAS,QAC9CoC,IAAMnB,IAAQjB,EAAS,SAASgC,IAAMhC,EAAS,UACtCe,KAETkB,IAAMJ,IAAM7B,EAAS,QACrBkC,IAAMJ,IAAM9B,EAAS,QACrBmC,IAAMJ,IAAM/B,EAAS,QACrBoC,IAAMJ,IAAMhC,EAAS,WAGrBiC,IAAMJ,IAAM7B,EAAS,OACrBkC,IAAMJ,IAAM9B,EAAS,QACrBmC,IAAMJ,IAAM/B,EAAS,OACrBoC,IAAMJ,IAAMhC,EAAS;AAIvB,YAAMK,IAAKG,EAAUe,IAAI,CAAC,KAAK,GACzBjB,IAAKE,EAAUe,CAAC,KAAK,GACrBc,KAAehC,IAAKC,KAAM,GAG1Be,IAAQrB,EAAS,SAAS7B,GAC1BiB,IAAQ,KAAK,IAAI,KAAKwC,IAAYS,CAAW,IAAIhB;AAEvD,MAAAtB,EAAI,YAAYX,GAChBW,EAAI,UAAS,GACbA,EAAI,OAAOkC,GAAKC,CAAG,GACnBnC,EAAI,OAAOoC,GAAKC,CAAG,GACnBrC,EAAI,OAAM;AAAA,IACZ;AAAA,EACF;AACF;"}
|
|
1
|
+
{"version":3,"file":"index5.js","sources":["../src/renderer/StrokeRenderer.js"],"sourcesContent":["/**\n * StrokeRenderer - Unified canvas-based annotation renderer\n *\n * Single entry point for rendering annotations as strokes on canvas.\n * Handles conversion from annotations to strokes and progressive rendering.\n *\n * @module renderer/StrokeRenderer\n */\n\nimport {\n highlightToStrokes,\n textToStrokes,\n underlineToStrokes,\n arrowToStrokes,\n circleToStrokes,\n inkToStrokes,\n} from \"../converters/index.js\";\nimport {\n ANNOTATION_TYPES,\n DEFAULT_CONFIG,\n REFERENCE_HEIGHT,\n} from \"../config/defaults.js\";\nimport { normalizeAnnotationArray } from \"../types/validators.js\";\nimport { pointNormToAbs } from \"../utils/coordinateUtils.js\";\n\n// Re-export so converters / callers can import REFERENCE_HEIGHT either from\n// the config module or from StrokeRenderer (keeps both paths working).\nexport { REFERENCE_HEIGHT };\n\n/**\n * StrokeRenderer class\n *\n * Converts annotations to strokes and renders them progressively on canvas.\n *\n * @class\n * @example\n * const renderer = new StrokeRenderer(canvas, {\n * highlight: { color: 'rgba(0, 255, 200, 0.4)' }\n * });\n * renderer.setViewport(800, 600);\n * renderer.setAnnotations(annotations);\n * renderer.render(1.5); // Render at t=1.5 seconds\n */\nclass StrokeRenderer {\n /**\n * Create StrokeRenderer instance\n *\n * @param {HTMLCanvasElement} canvas - Canvas element for rendering\n * @param {Object} [config={}] - Configuration overrides per annotation type\n * @param {Object} [config.highlight] - Highlight type settings\n * @param {Object} [config.text] - Text type settings\n * @param {Object} [config.underline] - Underline type settings\n * @param {Object} [config.arrow] - Arrow type settings\n * @param {Object} [config.circle] - Circle type settings\n */\n constructor(canvas, config = {}) {\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n throw new Error(\n \"StrokeRenderer: canvas must be a valid HTMLCanvasElement\",\n );\n }\n\n this.canvas = canvas;\n this.ctx = canvas.getContext(\"2d\");\n this.strokes = [];\n this.viewport = { width: 0, height: 0 };\n\n // Per-page strokes cache. Populated lazily in setAnnotations.\n // Keyed by page number; value is an array of stroke commands.\n this._strokeCacheByPage = new Map();\n // Identity reference of the last annotations array we cached. Used to\n // detect when the caller swaps in a new array so we can invalidate.\n this._lastAnnotationsRef = null;\n\n // Initialize config with defaults\n this.config = {};\n for (const type of ANNOTATION_TYPES) {\n this.config[type] = { ...DEFAULT_CONFIG[type] };\n }\n\n // Apply user config if provided\n if (Object.keys(config).length > 0) {\n this.setConfig(config);\n }\n\n // Register built-in converters\n this.converters = {\n highlight: highlightToStrokes,\n text: textToStrokes,\n underline: underlineToStrokes,\n arrow: arrowToStrokes,\n circle: circleToStrokes,\n ink: inkToStrokes,\n };\n }\n\n /**\n * Set configuration options\n *\n * Supports global options (applied to all types) and type-specific options.\n *\n * @param {Object} config - Configuration object\n * @param {number} [config.roughness] - Global roughness for all types\n * @param {string} [config.color] - Global color for all types\n * @param {number} [config.width] - Global width for all types\n * @param {Object} [config.highlight] - Highlight-specific options\n * @param {Object} [config.text] - Text-specific options\n * @param {Object} [config.underline] - Underline-specific options\n * @param {Object} [config.arrow] - Arrow-specific options\n * @param {Object} [config.circle] - Circle-specific options\n * @returns {StrokeRenderer} Returns this for chaining\n *\n * @example\n * // Global options\n * renderer.setConfig({ roughness: 2, color: \"blue\" });\n *\n * // Type-specific options\n * renderer.setConfig({ highlight: { color: \"yellow\", width: 30 } });\n *\n * // Combined\n * renderer.setConfig({\n * roughness: 2,\n * highlight: { color: \"yellow\" }\n * });\n */\n setConfig(config) {\n const globalOptions = {};\n const typeOptions = {};\n\n // Separate global options from type-specific options\n for (const [key, value] of Object.entries(config)) {\n if (ANNOTATION_TYPES.includes(key)) {\n typeOptions[key] = value;\n } else {\n globalOptions[key] = value;\n }\n }\n\n // Apply to each type: current config + global + type-specific\n for (const type of ANNOTATION_TYPES) {\n this.config[type] = {\n ...this.config[type],\n ...globalOptions,\n ...(typeOptions[type] || {}),\n };\n }\n\n // Invalidate per-page strokes cache: cached strokes were converted under\n // the previous style and would silently render stale colors / widths if\n // the next setAnnotations call passes the same array reference. The\n // `_lastAnnotationsRef = null` reset forces the next setAnnotations to\n // re-warm the cache regardless of identity. (BLOCKING-1, T17a)\n if (this._strokeCacheByPage) this._strokeCacheByPage.clear();\n this._lastAnnotationsRef = null;\n\n return this;\n }\n\n /**\n * Register a custom converter for a new annotation type\n *\n * @param {string} type - Annotation type name\n * @param {Function} converter - Converter function (annotation, style) => strokes[]\n */\n registerConverter(type, converter) {\n if (typeof converter !== \"function\") {\n throw new Error(\n \"StrokeRenderer.registerConverter: converter must be a function\",\n );\n }\n this.converters[type] = converter;\n }\n\n /**\n * Set viewport dimensions and configure canvas\n *\n * Handles high-DPI displays by scaling the canvas buffer.\n *\n * @param {number} width - Viewport width in CSS pixels\n * @param {number} height - Viewport height in CSS pixels\n */\n setViewport(width, height) {\n this.viewport = { width, height };\n\n const dpr = window.devicePixelRatio || 1;\n\n // Set canvas buffer size (high-res)\n this.canvas.width = width * dpr;\n this.canvas.height = 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 // Scale context for high-DPI\n this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n }\n\n /**\n * Set annotations and convert them to strokes\n *\n * Behavior:\n * - When `page` is null, all annotations are converted and exposed via\n * `this.strokes`. Per-page cache is still populated.\n * - When `page` is a number, conversion is performed per page (cached) and\n * `this.strokes` is set to the cache entry for the requested page.\n * - When the `annotations` reference changes between calls, the cache is\n * invalidated.\n *\n * @param {Array} annotations - Array of annotation objects\n * @param {number|null} [page=null] - Optional page filter\n * @param {Object} [options]\n * @param {boolean} [options.validate=false] - Run normalizeAnnotationArray\n * first and convert the normalized result instead of the raw input.\n * @param {boolean} [options.noCache=false] - Skip the per-page cache and\n * convert the filtered annotations directly (legacy fast path).\n */\n setAnnotations(annotations, page = null, options = {}) {\n if (!Array.isArray(annotations)) {\n console.warn(\n \"StrokeRenderer.setAnnotations: annotations must be an array\",\n );\n this.strokes = [];\n this._strokeCacheByPage.clear();\n this._lastAnnotationsRef = null;\n return;\n }\n\n const { validate = false, noCache = false } = options;\n\n // Optionally normalize input before conversion.\n let source = annotations;\n if (validate) {\n const result = normalizeAnnotationArray(annotations);\n source = result.normalized;\n }\n\n // Detect identity change → invalidate cache.\n if (source !== this._lastAnnotationsRef) {\n this._strokeCacheByPage.clear();\n this._lastAnnotationsRef = source;\n }\n\n // Legacy / opt-out path: convert filtered annotations without caching.\n if (noCache) {\n const filtered =\n page !== null ? source.filter((a) => a.page === page) : source;\n this.strokes = this._convertAnnotations(filtered);\n return;\n }\n\n // Group annotations by page once, populate cache for each touched page.\n // We always (re)populate the cache for every page present in `source`\n // when the cache is empty so subsequent setPage-style calls hit cache.\n if (this._strokeCacheByPage.size === 0) {\n const byPage = new Map();\n for (const ann of source) {\n const key = ann && ann.page != null ? ann.page : null;\n let bucket = byPage.get(key);\n if (!bucket) {\n bucket = [];\n byPage.set(key, bucket);\n }\n bucket.push(ann);\n }\n for (const [key, bucket] of byPage) {\n this._strokeCacheByPage.set(key, this._convertAnnotations(bucket));\n }\n }\n\n // Resolve `this.strokes` from cache.\n if (page !== null) {\n this.strokes = this._strokeCacheByPage.get(page) || [];\n } else {\n // No page filter — flatten all cached pages.\n const all = [];\n for (const bucket of this._strokeCacheByPage.values()) {\n for (const stroke of bucket) all.push(stroke);\n }\n this.strokes = all;\n }\n }\n\n /**\n * Convert a list of annotations to stroke commands using the registered\n * converters. Unknown types are skipped with a warning.\n *\n * @private\n * @param {Array} annotations\n * @returns {Array} stroke command objects\n */\n _convertAnnotations(annotations) {\n return annotations.flatMap((annotation) => {\n const converter = this.converters[annotation.type];\n\n if (!converter) {\n console.warn(\n `StrokeRenderer: Unknown annotation type \"${annotation.type}\"`,\n );\n return [];\n }\n\n const style = this._resolveStyle(annotation);\n return converter(annotation, style);\n });\n }\n\n /**\n * Set pre-converted strokes directly\n *\n * Bypasses conversion, useful when strokes come from external source.\n *\n * @param {Array} strokes - Array of stroke command objects\n */\n setStrokes(strokes) {\n if (!Array.isArray(strokes)) {\n console.warn(\"StrokeRenderer.setStrokes: strokes must be an array\");\n this.strokes = [];\n return;\n }\n this.strokes = strokes;\n }\n\n /**\n * Render strokes at the given time\n *\n * Clears canvas and draws all visible strokes with appropriate progress.\n *\n * @param {number} time - Current time in seconds\n */\n render(time) {\n const { ctx, viewport, strokes } = this;\n\n // Clear canvas\n ctx.clearRect(0, 0, viewport.width, viewport.height);\n\n // Draw each stroke\n for (const stroke of strokes) {\n // Skip if not started yet\n if (time < stroke.start) {\n continue;\n }\n\n // Calculate progress\n const duration = stroke.end - stroke.start;\n const elapsed = time - stroke.start;\n const progress = duration > 0 ? Math.min(1, elapsed / duration) : 1;\n\n this._drawStroke(stroke, progress);\n }\n }\n\n /**\n * Clear the canvas\n */\n clear() {\n this.ctx.clearRect(0, 0, this.viewport.width, this.viewport.height);\n }\n\n /**\n * Destroy the renderer and release resources\n */\n destroy() {\n this.strokes = [];\n if (this._strokeCacheByPage) this._strokeCacheByPage.clear();\n this._strokeCacheByPage = null;\n this._lastAnnotationsRef = null;\n this.ctx = null;\n this.canvas = null;\n this.config = null;\n this.converters = null;\n }\n\n /**\n * Resolve style for an annotation\n *\n * Returns the config for the annotation type.\n * Style is managed via setConfig(), not per-annotation.\n *\n * @private\n * @param {Object} annotation - Annotation object\n * @returns {Object} Resolved style object\n */\n _resolveStyle(annotation) {\n const { type } = annotation;\n return this.config[type] || {};\n }\n\n /**\n * Linearly interpolate between two points\n *\n * @private\n * @param {Array} p1 - Start point [x, y]\n * @param {Array} p2 - End point [x, y]\n * @param {number} t - Interpolation factor (0-1)\n * @returns {Array} Interpolated point [x, y]\n */\n _interpolatePoint(p1, p2, t) {\n return [p1[0] + (p2[0] - p1[0]) * t, p1[1] + (p2[1] - p1[1]) * t];\n }\n\n /**\n * Project a normalized stroke point into screen pixel space, honouring\n * the legacy `uniformScale` / `baseX/baseY` flags used by glyph strokes.\n *\n * Three cases:\n * - hasBase : `[coordX, coordY]` is an offset from `(baseX, baseY)` in\n * uniform-scaled space (both axes by viewport.height).\n * - uniform : `[coordX, coordY]` is a full position in uniform-scaled\n * space (legacy text glyph fallback).\n * - default : `[coordX, coordY]` is a normalized 0–1 page coordinate;\n * converted via `pointNormToAbs`.\n *\n * @private\n * @param {number} coordX\n * @param {number} coordY\n * @param {boolean} uniformScale\n * @param {boolean} hasBase\n * @param {number|null} baseX\n * @param {number|null} baseY\n * @returns {[number, number]}\n */\n _projectPoint(coordX, coordY, uniformScale, hasBase, baseX, baseY) {\n const { viewport } = this;\n if (hasBase) {\n return [\n baseX * viewport.width + coordX * viewport.height,\n baseY * viewport.height + coordY * viewport.height,\n ];\n }\n if (uniformScale) {\n return [coordX * viewport.height, coordY * viewport.height];\n }\n const { x, y } = pointNormToAbs({ x: coordX, y: coordY }, viewport);\n return [x, y];\n }\n\n /**\n * Get pressure values for visible points including interpolated final\n *\n * @private\n * @param {Array} pressures - Full pressure array\n * @param {number} lastCompleteIndex - Index of last complete point\n * @param {number} segmentProgress - Progress within current segment (0-1)\n * @returns {Array} Pressure values for visible points\n */\n _interpolatePressures(pressures, lastCompleteIndex, segmentProgress) {\n const visiblePressures = pressures.slice(0, lastCompleteIndex + 1);\n\n if (lastCompleteIndex < pressures.length - 1 && segmentProgress > 0) {\n const p1 = pressures[lastCompleteIndex];\n const p2 = pressures[lastCompleteIndex + 1];\n visiblePressures.push(p1 + (p2 - p1) * segmentProgress);\n }\n\n return visiblePressures;\n }\n\n /**\n * Draw a single stroke with progress\n *\n * Uses endpoint interpolation for smooth progressive rendering.\n *\n * @private\n * @param {Object} stroke - Stroke command object\n * @param {number} progress - Progress from 0 to 1\n */\n _drawStroke(stroke, progress) {\n // Screen-space wing strokes are recomputed every frame in pixel space so\n // diagonal arrows render symmetric wings regardless of viewport aspect.\n if (stroke.screenSpaceWing) {\n this._drawScreenSpaceWingStroke(stroke, progress);\n return;\n }\n\n const { ctx } = this;\n const {\n points,\n color,\n width,\n lineCap,\n pressures,\n uniformScale,\n baseX,\n baseY,\n } = stroke;\n\n if (!points || points.length < 2) return;\n\n // Configure stroke style\n ctx.strokeStyle = color || \"rgba(0, 0, 0, 0.5)\";\n ctx.lineCap = lineCap || \"round\";\n ctx.lineJoin = \"round\";\n\n // Fast path: full stroke, no interpolation needed\n if (progress >= 1) {\n if (pressures && pressures.length >= points.length) {\n this._drawVariableWidthStroke(\n points,\n width,\n pressures,\n uniformScale,\n baseX,\n baseY,\n );\n } else {\n this._drawConstantWidthStroke(\n points,\n width,\n uniformScale,\n baseX,\n baseY,\n );\n }\n return;\n }\n\n // Calculate segment position for interpolation\n const totalSegments = points.length - 1;\n const progressAlongPath = progress * totalSegments;\n const lastCompleteIndex = Math.floor(progressAlongPath);\n const segmentProgress = progressAlongPath - lastCompleteIndex;\n\n // Build visible points array with complete points\n const visiblePoints = points.slice(0, lastCompleteIndex + 1);\n\n // Interpolate final point if mid-segment\n if (lastCompleteIndex < totalSegments && segmentProgress > 0) {\n const p1 = points[lastCompleteIndex];\n const p2 = points[lastCompleteIndex + 1];\n visiblePoints.push(this._interpolatePoint(p1, p2, segmentProgress));\n }\n\n // Need at least 2 points to draw a line\n if (visiblePoints.length < 2) return;\n\n // Draw with variable width if pressures provided\n if (pressures && pressures.length >= points.length) {\n const visiblePressures = this._interpolatePressures(\n pressures,\n lastCompleteIndex,\n segmentProgress,\n );\n this._drawVariableWidthStroke(\n visiblePoints,\n width,\n visiblePressures,\n uniformScale,\n baseX,\n baseY,\n );\n } else {\n this._drawConstantWidthStroke(\n visiblePoints,\n width,\n uniformScale,\n baseX,\n baseY,\n );\n }\n }\n\n /**\n * Draw stroke with constant width\n *\n * @private\n * @param {Array} points - Array of [x, y] coordinates (normalized or offset)\n * @param {number} width - Stroke width in pixels\n * @param {boolean} [uniformScale=false] - Use uniform scaling to preserve aspect ratio\n * @param {number} [baseX] - Base X position in width-normalized coords (for uniformScale with offset points)\n * @param {number} [baseY] - Base Y position in height-normalized coords (for uniformScale with offset points)\n */\n _drawConstantWidthStroke(\n points,\n width,\n uniformScale = false,\n baseX = null,\n baseY = null,\n ) {\n const { ctx, viewport } = this;\n\n // Scale width based on viewport height for consistent appearance\n const scale = viewport.height / REFERENCE_HEIGHT;\n ctx.lineWidth = (width || 2) * scale;\n ctx.beginPath();\n\n const hasBase = uniformScale && baseX !== null && baseY !== null;\n\n for (let i = 0; i < points.length; i++) {\n const [coordX, coordY] = points[i];\n const [px, py] = this._projectPoint(coordX, coordY, uniformScale, hasBase, baseX, baseY);\n if (i === 0) ctx.moveTo(px, py);\n else ctx.lineTo(px, py);\n }\n\n ctx.stroke();\n }\n\n /**\n * Draw stroke with variable width based on pressure\n *\n * @private\n * @param {Array} points - Array of [x, y] coordinates (normalized or offset)\n * @param {number} baseWidth - Base stroke width in pixels\n * @param {Array} pressures - Pressure values (0-1) per point\n * @param {boolean} [uniformScale=false] - Use uniform scaling to preserve aspect ratio\n * @param {number} [baseX] - Base X position in width-normalized coords (for uniformScale with offset points)\n * @param {number} [baseY] - Base Y position in height-normalized coords (for uniformScale with offset points)\n */\n _drawVariableWidthStroke(\n points,\n baseWidth,\n pressures,\n uniformScale = false,\n baseX = null,\n baseY = null,\n ) {\n const { ctx, viewport } = this;\n const hasBase = uniformScale && baseX !== null && baseY !== null;\n const scale = viewport.height / REFERENCE_HEIGHT;\n\n for (let i = 1; i < points.length; i++) {\n const [c1x, c1y] = points[i - 1];\n const [c2x, c2y] = points[i];\n\n const [px1, py1] = this._projectPoint(c1x, c1y, uniformScale, hasBase, baseX, baseY);\n const [px2, py2] = this._projectPoint(c2x, c2y, uniformScale, hasBase, baseX, baseY);\n\n // Average pressure between two points; clamp width to a min of 0.5px.\n const avgPressure = ((pressures[i - 1] || 1) + (pressures[i] || 1)) / 2;\n ctx.lineWidth = Math.max(0.5, baseWidth * avgPressure) * scale;\n\n ctx.beginPath();\n ctx.moveTo(px1, py1);\n ctx.lineTo(px2, py2);\n ctx.stroke();\n }\n }\n\n /**\n * Draw an arrow wing whose geometry is recomputed in screen-pixel space at\n * every frame, so diagonal arrows render with symmetric wings regardless of\n * viewport aspect ratio.\n *\n * Stroke shape (`stroke.screenSpaceWing`):\n * - fromX, fromY: tail of the main arrow line (normalized 0–1)\n * - toX, toY: tip of the main arrow line (normalized 0–1)\n * - headAngle: wing offset angle in radians (defaults to π/6)\n * - wingSide: 'left' uses (θ - headAngle); 'right' uses (θ + headAngle)\n *\n * The wing is drawn as a single straight line via the canvas API (no\n * RoughJS), since screen-space recomputation runs every render frame and\n * regenerating a rough path each frame would be too expensive.\n *\n * @private\n * @param {Object} stroke\n * @param {number} progress - 0..1 along the wing's full extent\n */\n _drawScreenSpaceWingStroke(stroke, progress) {\n const { ctx, viewport } = this;\n const wing = stroke.screenSpaceWing;\n if (!wing) return;\n\n const { fromX, fromY, toX, toY, wingSide } = wing;\n const headAngle =\n typeof wing.headAngle === \"number\" ? wing.headAngle : Math.PI / 6;\n\n if (\n typeof fromX !== \"number\" ||\n typeof fromY !== \"number\" ||\n typeof toX !== \"number\" ||\n typeof toY !== \"number\"\n ) {\n return;\n }\n\n // Convert main-line endpoints to screen pixels.\n const tip = pointNormToAbs({ x: toX, y: toY }, viewport);\n const tail = pointNormToAbs({ x: fromX, y: fromY }, viewport);\n const tipX = tip.x;\n const tipY = tip.y;\n const tailX = tail.x;\n const tailY = tail.y;\n\n const dx = tipX - tailX;\n const dy = tipY - tailY;\n const length = Math.sqrt(dx * dx + dy * dy);\n if (length === 0) return;\n\n // Same proportional rule as v0.6.4, but in screen pixels.\n const headSize = Math.min(length * 0.2, 0.03 * viewport.height);\n\n const theta = Math.atan2(dy, dx);\n const wingOffsetAngle =\n wingSide === \"right\" ? theta + headAngle : theta - headAngle;\n\n // Full wing endpoint (in screen pixels).\n const fullWingX = tipX - headSize * Math.cos(wingOffsetAngle);\n const fullWingY = tipY - headSize * Math.sin(wingOffsetAngle);\n\n // Apply progress: interpolate from the tip toward the full wing extent.\n const t = Math.max(0, Math.min(1, progress));\n const wingX = tipX + (fullWingX - tipX) * t;\n const wingY = tipY + (fullWingY - tipY) * t;\n\n const scale = viewport.height / REFERENCE_HEIGHT;\n ctx.strokeStyle = stroke.color || \"rgba(0, 0, 0, 0.5)\";\n ctx.lineCap = stroke.lineCap || \"round\";\n ctx.lineJoin = \"round\";\n ctx.lineWidth = (stroke.width || 2) * scale;\n\n ctx.beginPath();\n ctx.moveTo(tipX, tipY);\n ctx.lineTo(wingX, wingY);\n ctx.stroke();\n }\n}\n\nexport { StrokeRenderer };\nexport default StrokeRenderer;\n"],"names":["StrokeRenderer","canvas","config","type","ANNOTATION_TYPES","DEFAULT_CONFIG","highlightToStrokes","textToStrokes","underlineToStrokes","arrowToStrokes","circleToStrokes","inkToStrokes","globalOptions","typeOptions","key","value","converter","width","height","dpr","annotations","page","options","validate","noCache","source","normalizeAnnotationArray","filtered","a","byPage","ann","bucket","all","stroke","annotation","style","strokes","time","ctx","viewport","duration","elapsed","progress","p1","p2","t","coordX","coordY","uniformScale","hasBase","baseX","baseY","x","y","pointNormToAbs","pressures","lastCompleteIndex","segmentProgress","visiblePressures","points","color","lineCap","totalSegments","progressAlongPath","visiblePoints","scale","REFERENCE_HEIGHT","i","px","py","baseWidth","c1x","c1y","c2x","c2y","px1","py1","px2","py2","avgPressure","wing","fromX","fromY","toX","toY","wingSide","headAngle","tip","tail","tipX","tipY","tailX","tailY","dx","dy","length","headSize","theta","wingOffsetAngle","fullWingX","fullWingY","wingX","wingY"],"mappings":";;;;;;;;;AA2CA,MAAMA,EAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYnB,YAAYC,GAAQC,IAAS,IAAI;AAC/B,QAAI,CAACD,KAAU,EAAEA,aAAkB;AACjC,YAAM,IAAI;AAAA,QACR;AAAA,MACR;AAGI,SAAK,SAASA,GACd,KAAK,MAAMA,EAAO,WAAW,IAAI,GACjC,KAAK,UAAU,CAAA,GACf,KAAK,WAAW,EAAE,OAAO,GAAG,QAAQ,EAAC,GAIrC,KAAK,qBAAqB,oBAAI,IAAG,GAGjC,KAAK,sBAAsB,MAG3B,KAAK,SAAS,CAAA;AACd,eAAWE,KAAQC;AACjB,WAAK,OAAOD,CAAI,IAAI,EAAE,GAAGE,EAAeF,CAAI,EAAC;AAI/C,IAAI,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oB,IAAQ1B,EAAS,SAAS2B;AAChC,IAAA5B,EAAI,cAAcL,EAAO,SAAS,sBAClCK,EAAI,UAAUL,EAAO,WAAW,SAChCK,EAAI,WAAW,SACfA,EAAI,aAAaL,EAAO,SAAS,KAAKgC,GAEtC3B,EAAI,UAAS,GACbA,EAAI,OAAOmD,GAAMC,CAAI,GACrBpD,EAAI,OAAO+D,GAAOC,CAAK,GACvBhE,EAAI,OAAM;AAAA,EACZ;AACF;"}
|
package/dist/index6.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("./index24.cjs");function o(r){const c={};for(const t of n.ANNOTATION_TYPES){const l=n.DEFAULT_CONFIG[t],i=r[t];c[t]=i?{...l,...i}:{...l}}return c}const a=o({}),s=o({highlight:{color:"rgba(100, 149, 237, 0.35)"},text:{color:"rgba(30, 64, 175, 1.0)"},underline:{color:"rgba(30, 64, 175, 1.0)"},arrow:{color:"rgba(30, 64, 175, 1.0)"},circle:{color:"rgba(30, 64, 175, 1.0)"}}),u=o({highlight:{color:"rgba(156, 163, 175, 0.25)",widthScale:.85},text:{color:"rgba(75, 85, 99, 1.0)",width:1.5},underline:{color:"rgba(75, 85, 99, 1.0)",width:1.5},arrow:{color:"rgba(75, 85, 99, 1.0)",width:1.5},circle:{color:"rgba(75, 85, 99, 1.0)",width:2}}),e={default:a,blue:s,minimal:u};function g(r){return e[r]||e.default}function E(){return Object.keys(e)}exports.BLUE_PRESET=s;exports.DEFAULT_PRESET=a;exports.MINIMAL_PRESET=u;exports.default=e;exports.getPreset=g;exports.getPresetNames=E;
|
|
2
2
|
//# sourceMappingURL=index6.cjs.map
|
package/dist/index6.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index6.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index6.cjs","sources":["../src/config/presets.js"],"sourcesContent":["/**\n * Style Presets for `strokeConfig`\n *\n * Ready-to-use configurations for `StrokeRenderer.setConfig` /\n * `<AnnotPdf strokeConfig={...} />`. Built on top of the canonical\n * `DEFAULT_CONFIG` from `./defaults.js` so the default preset never\n * drifts from renderer defaults.\n *\n * Keys match annotation types: highlight, text, underline, arrow, circle.\n *\n * @module config/presets\n */\n\nimport { ANNOTATION_TYPES, DEFAULT_CONFIG } from './defaults.js';\n\n/**\n * Build a preset by overriding `color` / `width` / `widthScale` per type on\n * top of `DEFAULT_CONFIG`. Types not listed inherit `DEFAULT_CONFIG`\n * unchanged.\n *\n * @param {Object<string, {color?: string, width?: number, widthScale?: number}>} overrides\n * @returns {Object<string, Object>} Full per-type config object\n */\nfunction buildPreset(overrides) {\n const preset = {};\n for (const type of ANNOTATION_TYPES) {\n const base = DEFAULT_CONFIG[type];\n const override = overrides[type];\n preset[type] = override ? { ...base, ...override } : { ...base };\n }\n return preset;\n}\n\n/**\n * Default preset — yellow highlights, crimson text.\n * Equivalent to `DEFAULT_CONFIG`.\n *\n * @type {Object<string, Object>}\n */\nexport const DEFAULT_PRESET = buildPreset({});\n\n/**\n * Blue preset — blue theme across all annotation types.\n *\n * @type {Object<string, Object>}\n */\nexport const BLUE_PRESET = buildPreset({\n highlight: { color: 'rgba(100, 149, 237, 0.35)' },\n text: { color: 'rgba(30, 64, 175, 1.0)' },\n underline: { color: 'rgba(30, 64, 175, 1.0)' },\n arrow: { color: 'rgba(30, 64, 175, 1.0)' },\n circle: { color: 'rgba(30, 64, 175, 1.0)' },\n});\n\n/**\n * Minimal preset — subtle gray, slightly thinner strokes.\n *\n * @type {Object<string, Object>}\n */\nexport const MINIMAL_PRESET = buildPreset({\n highlight: { color: 'rgba(156, 163, 175, 0.25)', widthScale: 0.85 },\n text: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n underline: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n arrow: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n circle: { color: 'rgba(75, 85, 99, 1.0)', width: 2 },\n});\n\n/**\n * Preset registry.\n *\n * @type {Object<string, Object>}\n */\nconst PRESETS = {\n default: DEFAULT_PRESET,\n blue: BLUE_PRESET,\n minimal: MINIMAL_PRESET,\n};\n\n/**\n * Look up a preset by name. Falls back to `default` when the name is unknown.\n *\n * @param {string} name - Preset name\n * @returns {Object<string, Object>} Preset configuration\n */\nexport function getPreset(name) {\n return PRESETS[name] || PRESETS.default;\n}\n\n/**\n * List all registered preset names.\n *\n * @returns {string[]}\n */\nexport function getPresetNames() {\n return Object.keys(PRESETS);\n}\n\nexport default PRESETS;\n"],"names":["buildPreset","overrides","preset","type","ANNOTATION_TYPES","base","DEFAULT_CONFIG","override","DEFAULT_PRESET","BLUE_PRESET","MINIMAL_PRESET","PRESETS","getPreset","name","getPresetNames"],"mappings":"6IAuBA,SAASA,EAAYC,EAAW,CAC9B,MAAMC,EAAS,CAAA,EACf,UAAWC,KAAQC,mBAAkB,CACnC,MAAMC,EAAOC,EAAAA,eAAeH,CAAI,EAC1BI,EAAWN,EAAUE,CAAI,EAC/BD,EAAOC,CAAI,EAAII,EAAW,CAAE,GAAGF,EAAM,GAAGE,CAAQ,EAAK,CAAE,GAAGF,CAAI,CAChE,CACA,OAAOH,CACT,CAQY,MAACM,EAAiBR,EAAY,CAAA,CAAE,EAO/BS,EAAcT,EAAY,CACrC,UAAW,CAAE,MAAO,2BAA2B,EAC/C,KAAW,CAAE,MAAO,wBAAwB,EAC5C,UAAW,CAAE,MAAO,wBAAwB,EAC5C,MAAW,CAAE,MAAO,wBAAwB,EAC5C,OAAW,CAAE,MAAO,wBAAwB,CAC9C,CAAC,EAOYU,EAAiBV,EAAY,CACxC,UAAW,CAAE,MAAO,4BAA6B,WAAY,GAAI,EACjE,KAAW,CAAE,MAAO,wBAAyB,MAAO,GAAG,EACvD,UAAW,CAAE,MAAO,wBAAyB,MAAO,GAAG,EACvD,MAAW,CAAE,MAAO,wBAAyB,MAAO,GAAG,EACvD,OAAW,CAAE,MAAO,wBAAyB,MAAO,CAAC,CACvD,CAAC,EAOKW,EAAU,CACd,QAASH,EACT,KAAMC,EACN,QAASC,CACX,EAQO,SAASE,EAAUC,EAAM,CAC9B,OAAOF,EAAQE,CAAI,GAAKF,EAAQ,OAClC,CAOO,SAASG,GAAiB,CAC/B,OAAO,OAAO,KAAKH,CAAO,CAC5B"}
|
package/dist/index6.js
CHANGED
|
@@ -1,23 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { ANNOTATION_TYPES as i, DEFAULT_CONFIG as a } from "./index24.js";
|
|
2
|
+
function e(r) {
|
|
3
|
+
const c = {};
|
|
4
|
+
for (const o of i) {
|
|
5
|
+
const l = a[o], n = r[o];
|
|
6
|
+
c[o] = n ? { ...l, ...n } : { ...l };
|
|
7
|
+
}
|
|
8
|
+
return c;
|
|
9
|
+
}
|
|
10
|
+
const g = e({}), s = e({
|
|
11
|
+
highlight: { color: "rgba(100, 149, 237, 0.35)" },
|
|
12
|
+
text: { color: "rgba(30, 64, 175, 1.0)" },
|
|
13
|
+
underline: { color: "rgba(30, 64, 175, 1.0)" },
|
|
14
|
+
arrow: { color: "rgba(30, 64, 175, 1.0)" },
|
|
15
|
+
circle: { color: "rgba(30, 64, 175, 1.0)" }
|
|
16
|
+
}), b = e({
|
|
17
|
+
highlight: { color: "rgba(156, 163, 175, 0.25)", widthScale: 0.85 },
|
|
18
|
+
text: { color: "rgba(75, 85, 99, 1.0)", width: 1.5 },
|
|
19
|
+
underline: { color: "rgba(75, 85, 99, 1.0)", width: 1.5 },
|
|
20
|
+
arrow: { color: "rgba(75, 85, 99, 1.0)", width: 1.5 },
|
|
21
|
+
circle: { color: "rgba(75, 85, 99, 1.0)", width: 2 }
|
|
22
|
+
}), t = {
|
|
23
|
+
default: g,
|
|
24
|
+
blue: s,
|
|
25
|
+
minimal: b
|
|
26
|
+
};
|
|
27
|
+
function d(r) {
|
|
28
|
+
return t[r] || t.default;
|
|
29
|
+
}
|
|
30
|
+
function E() {
|
|
31
|
+
return Object.keys(t);
|
|
17
32
|
}
|
|
18
33
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
s as BLUE_PRESET,
|
|
35
|
+
g as DEFAULT_PRESET,
|
|
36
|
+
b as MINIMAL_PRESET,
|
|
37
|
+
t as default,
|
|
38
|
+
d as getPreset,
|
|
39
|
+
E as getPresetNames
|
|
22
40
|
};
|
|
23
41
|
//# sourceMappingURL=index6.js.map
|
package/dist/index6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index6.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index6.js","sources":["../src/config/presets.js"],"sourcesContent":["/**\n * Style Presets for `strokeConfig`\n *\n * Ready-to-use configurations for `StrokeRenderer.setConfig` /\n * `<AnnotPdf strokeConfig={...} />`. Built on top of the canonical\n * `DEFAULT_CONFIG` from `./defaults.js` so the default preset never\n * drifts from renderer defaults.\n *\n * Keys match annotation types: highlight, text, underline, arrow, circle.\n *\n * @module config/presets\n */\n\nimport { ANNOTATION_TYPES, DEFAULT_CONFIG } from './defaults.js';\n\n/**\n * Build a preset by overriding `color` / `width` / `widthScale` per type on\n * top of `DEFAULT_CONFIG`. Types not listed inherit `DEFAULT_CONFIG`\n * unchanged.\n *\n * @param {Object<string, {color?: string, width?: number, widthScale?: number}>} overrides\n * @returns {Object<string, Object>} Full per-type config object\n */\nfunction buildPreset(overrides) {\n const preset = {};\n for (const type of ANNOTATION_TYPES) {\n const base = DEFAULT_CONFIG[type];\n const override = overrides[type];\n preset[type] = override ? { ...base, ...override } : { ...base };\n }\n return preset;\n}\n\n/**\n * Default preset — yellow highlights, crimson text.\n * Equivalent to `DEFAULT_CONFIG`.\n *\n * @type {Object<string, Object>}\n */\nexport const DEFAULT_PRESET = buildPreset({});\n\n/**\n * Blue preset — blue theme across all annotation types.\n *\n * @type {Object<string, Object>}\n */\nexport const BLUE_PRESET = buildPreset({\n highlight: { color: 'rgba(100, 149, 237, 0.35)' },\n text: { color: 'rgba(30, 64, 175, 1.0)' },\n underline: { color: 'rgba(30, 64, 175, 1.0)' },\n arrow: { color: 'rgba(30, 64, 175, 1.0)' },\n circle: { color: 'rgba(30, 64, 175, 1.0)' },\n});\n\n/**\n * Minimal preset — subtle gray, slightly thinner strokes.\n *\n * @type {Object<string, Object>}\n */\nexport const MINIMAL_PRESET = buildPreset({\n highlight: { color: 'rgba(156, 163, 175, 0.25)', widthScale: 0.85 },\n text: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n underline: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n arrow: { color: 'rgba(75, 85, 99, 1.0)', width: 1.5 },\n circle: { color: 'rgba(75, 85, 99, 1.0)', width: 2 },\n});\n\n/**\n * Preset registry.\n *\n * @type {Object<string, Object>}\n */\nconst PRESETS = {\n default: DEFAULT_PRESET,\n blue: BLUE_PRESET,\n minimal: MINIMAL_PRESET,\n};\n\n/**\n * Look up a preset by name. Falls back to `default` when the name is unknown.\n *\n * @param {string} name - Preset name\n * @returns {Object<string, Object>} Preset configuration\n */\nexport function getPreset(name) {\n return PRESETS[name] || PRESETS.default;\n}\n\n/**\n * List all registered preset names.\n *\n * @returns {string[]}\n */\nexport function getPresetNames() {\n return Object.keys(PRESETS);\n}\n\nexport default PRESETS;\n"],"names":["buildPreset","overrides","preset","type","ANNOTATION_TYPES","base","DEFAULT_CONFIG","override","DEFAULT_PRESET","BLUE_PRESET","MINIMAL_PRESET","PRESETS","getPreset","name","getPresetNames"],"mappings":";AAuBA,SAASA,EAAYC,GAAW;AAC9B,QAAMC,IAAS,CAAA;AACf,aAAWC,KAAQC,GAAkB;AACnC,UAAMC,IAAOC,EAAeH,CAAI,GAC1BI,IAAWN,EAAUE,CAAI;AAC/B,IAAAD,EAAOC,CAAI,IAAII,IAAW,EAAE,GAAGF,GAAM,GAAGE,EAAQ,IAAK,EAAE,GAAGF,EAAI;AAAA,EAChE;AACA,SAAOH;AACT;AAQY,MAACM,IAAiBR,EAAY,CAAA,CAAE,GAO/BS,IAAcT,EAAY;AAAA,EACrC,WAAW,EAAE,OAAO,4BAA2B;AAAA,EAC/C,MAAW,EAAE,OAAO,yBAAwB;AAAA,EAC5C,WAAW,EAAE,OAAO,yBAAwB;AAAA,EAC5C,OAAW,EAAE,OAAO,yBAAwB;AAAA,EAC5C,QAAW,EAAE,OAAO,yBAAwB;AAC9C,CAAC,GAOYU,IAAiBV,EAAY;AAAA,EACxC,WAAW,EAAE,OAAO,6BAA6B,YAAY,KAAI;AAAA,EACjE,MAAW,EAAE,OAAO,yBAAyB,OAAO,IAAG;AAAA,EACvD,WAAW,EAAE,OAAO,yBAAyB,OAAO,IAAG;AAAA,EACvD,OAAW,EAAE,OAAO,yBAAyB,OAAO,IAAG;AAAA,EACvD,QAAW,EAAE,OAAO,yBAAyB,OAAO,EAAC;AACvD,CAAC,GAOKW,IAAU;AAAA,EACd,SAASH;AAAA,EACT,MAAMC;AAAA,EACN,SAASC;AACX;AAQO,SAASE,EAAUC,GAAM;AAC9B,SAAOF,EAAQE,CAAI,KAAKF,EAAQ;AAClC;AAOO,SAASG,IAAiB;AAC/B,SAAO,OAAO,KAAKH,CAAO;AAC5B;"}
|
package/dist/index7.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(t,o)=>({left:t.x*o.width,top:t.y*o.height,width:(t.w??0)*o.width,height:(t.h??0)*o.height});function h(t,o){return{x:t.x*o.width,y:t.y*o.height}}exports.pointNormToAbs=h;exports.rectNormToAbs=e;
|
|
2
2
|
//# sourceMappingURL=index7.cjs.map
|
package/dist/index7.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.cjs","sources":["../src/utils/
|
|
1
|
+
{"version":3,"file":"index7.cjs","sources":["../src/utils/coordinateUtils.js"],"sourcesContent":["/**\n * Coordinate Utility Functions\n *\n * This module provides utility functions for coordinate transformations\n * between normalized (0-1) coordinates and absolute pixel coordinates.\n * Used by annotation layers to position elements on the PDF canvas.\n */\n\n/**\n * Convert normalized rectangle to absolute pixel coordinates\n *\n * Transforms a rectangle with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number, w: number, h: number}} rect - Normalized rectangle (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{left: number, top: number, width: number, height: number}} Absolute coordinates in pixels\n *\n * @example\n * const rect = { x: 0.1, y: 0.2, w: 0.5, h: 0.3 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = rectNormToAbs(rect, viewport);\n * // Returns: { left: 100, top: 280, width: 500, height: 420 }\n */\nexport const rectNormToAbs = (r, vp) => ({\n left: r.x * vp.width,\n top: r.y * vp.height,\n width: (r.w ?? 0) * vp.width,\n height: (r.h ?? 0) * vp.height,\n});\n\n/**\n * Convert normalized point to absolute pixel coordinates\n *\n * Transforms a point with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number}} point - Normalized point (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{x: number, y: number}} Absolute coordinates in pixels\n *\n * @example\n * const point = { x: 0.5, y: 0.5 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = pointNormToAbs(point, viewport);\n * // Returns: { x: 500, y: 700 }\n */\nexport function pointNormToAbs(point, viewport) {\n return {\n x: point.x * viewport.width,\n y: point.y * viewport.height,\n };\n}\n"],"names":["rectNormToAbs","r","vp","pointNormToAbs","point","viewport"],"mappings":"gFAwBY,MAACA,EAAgB,CAACC,EAAGC,KAAQ,CACvC,KAAMD,EAAE,EAAIC,EAAG,MACf,IAAKD,EAAE,EAAIC,EAAG,OACd,OAAQD,EAAE,GAAK,GAAKC,EAAG,MACvB,QAASD,EAAE,GAAK,GAAKC,EAAG,MAC1B,GAkBO,SAASC,EAAeC,EAAOC,EAAU,CAC9C,MAAO,CACL,EAAGD,EAAM,EAAIC,EAAS,MACtB,EAAGD,EAAM,EAAIC,EAAS,MAC1B,CACA"}
|
package/dist/index7.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
width: t.width,
|
|
9
|
-
height: t.height
|
|
10
|
-
} : { width: 0, height: 0 };
|
|
11
|
-
}
|
|
12
|
-
function h(t, e, i) {
|
|
1
|
+
const i = (t, h) => ({
|
|
2
|
+
left: t.x * h.width,
|
|
3
|
+
top: t.y * h.height,
|
|
4
|
+
width: (t.w ?? 0) * h.width,
|
|
5
|
+
height: (t.h ?? 0) * h.height
|
|
6
|
+
});
|
|
7
|
+
function e(t, h) {
|
|
13
8
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
x: t.x * h.width,
|
|
10
|
+
y: t.y * h.height
|
|
16
11
|
};
|
|
17
12
|
}
|
|
18
13
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
n as getViewportDimensions
|
|
14
|
+
e as pointNormToAbs,
|
|
15
|
+
i as rectNormToAbs
|
|
22
16
|
};
|
|
23
17
|
//# sourceMappingURL=index7.js.map
|
package/dist/index7.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.js","sources":["../src/utils/
|
|
1
|
+
{"version":3,"file":"index7.js","sources":["../src/utils/coordinateUtils.js"],"sourcesContent":["/**\n * Coordinate Utility Functions\n *\n * This module provides utility functions for coordinate transformations\n * between normalized (0-1) coordinates and absolute pixel coordinates.\n * Used by annotation layers to position elements on the PDF canvas.\n */\n\n/**\n * Convert normalized rectangle to absolute pixel coordinates\n *\n * Transforms a rectangle with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number, w: number, h: number}} rect - Normalized rectangle (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{left: number, top: number, width: number, height: number}} Absolute coordinates in pixels\n *\n * @example\n * const rect = { x: 0.1, y: 0.2, w: 0.5, h: 0.3 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = rectNormToAbs(rect, viewport);\n * // Returns: { left: 100, top: 280, width: 500, height: 420 }\n */\nexport const rectNormToAbs = (r, vp) => ({\n left: r.x * vp.width,\n top: r.y * vp.height,\n width: (r.w ?? 0) * vp.width,\n height: (r.h ?? 0) * vp.height,\n});\n\n/**\n * Convert normalized point to absolute pixel coordinates\n *\n * Transforms a point with normalized coordinates (0-1 range) to\n * absolute pixel coordinates based on viewport dimensions.\n *\n * @param {{x: number, y: number}} point - Normalized point (0-1)\n * @param {{width: number, height: number}} viewport - Viewport dimensions in pixels\n * @returns {{x: number, y: number}} Absolute coordinates in pixels\n *\n * @example\n * const point = { x: 0.5, y: 0.5 };\n * const viewport = { width: 1000, height: 1400 };\n * const absolute = pointNormToAbs(point, viewport);\n * // Returns: { x: 500, y: 700 }\n */\nexport function pointNormToAbs(point, viewport) {\n return {\n x: point.x * viewport.width,\n y: point.y * viewport.height,\n };\n}\n"],"names":["rectNormToAbs","r","vp","pointNormToAbs","point","viewport"],"mappings":"AAwBY,MAACA,IAAgB,CAACC,GAAGC,OAAQ;AAAA,EACvC,MAAMD,EAAE,IAAIC,EAAG;AAAA,EACf,KAAKD,EAAE,IAAIC,EAAG;AAAA,EACd,QAAQD,EAAE,KAAK,KAAKC,EAAG;AAAA,EACvB,SAASD,EAAE,KAAK,KAAKC,EAAG;AAC1B;AAkBO,SAASC,EAAeC,GAAOC,GAAU;AAC9C,SAAO;AAAA,IACL,GAAGD,EAAM,IAAIC,EAAS;AAAA,IACtB,GAAGD,EAAM,IAAIC,EAAS;AAAA,EAC1B;AACA;"}
|
package/dist/index8.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(e,t){if(!e)throw new Error("Page object is required");return e.getViewport({scale:t})}function r(e){return e?{width:e.width,height:e.height}:{width:0,height:0}}function o(e,t,i){return{width:e*i,height:t*i}}exports.calculateScaledDimensions=o;exports.calculateViewport=n;exports.getViewportDimensions=r;
|
|
2
2
|
//# sourceMappingURL=index8.cjs.map
|
package/dist/index8.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index8.cjs","sources":["../src/utils/pdfExtractor.js"],"sourcesContent":["/**\n * PDF Data Extractor - Extract text and image blocks from PDF\n *\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering.\n *\n * @module utils/pdfExtractor\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\n\n/**\n * Extract text blocks from a PDF page with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of text blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractTextBlocks(page) {\n try {\n const textContent = await page.getTextContent();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const textBlocks = [];\n\n for (const item of textContent.items) {\n // Skip empty text\n if (!item.str || !item.str.trim()) {\n continue;\n }\n\n // Get transform matrix [a, b, c, d, e, f]\n const transform = item.transform;\n const fontSize = Math.sqrt(transform[2] * transform[2] + transform[3] * transform[3]);\n\n // Calculate bounding box (absolute coordinates)\n const x = transform[4];\n const y = viewport.height - transform[5]; // Convert to top-left origin\n const width = item.width;\n const height = item.height || fontSize;\n\n const x1 = x;\n const y1 = y - height;\n const x2 = x + width;\n const y2 = y;\n\n // Normalize coordinates to 0-1 range\n const bbox_norm = [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n\n textBlocks.push({\n type: \"text\",\n text: item.str,\n bbox_norm: bbox_norm,\n font: item.fontName || \"unknown\",\n fontSize: fontSize,\n source: \"pdfjs\"\n });\n }\n\n return textBlocks;\n } catch (error) {\n console.error(\"Error extracting text blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract normalized bounding box from PDF transformation matrix\n *\n * @param {Array} transform - PDF transformation matrix [a, b, c, d, e, f]\n * @param {number} pageWidth - Page width for normalization\n * @param {number} pageHeight - Page height for coordinate conversion and normalization\n * @returns {Array} Normalized bounding box [x1, y1, x2, y2] in 0-1 range\n */\nfunction extractBBoxFromTransform(transform, pageWidth, pageHeight) {\n const x = transform[4];\n const y = transform[5];\n const scaleX = transform[0];\n const scaleY = transform[3];\n\n // Scale factors represent image dimensions\n const width = Math.abs(scaleX);\n const height = Math.abs(scaleY);\n\n // Convert from PDF bottom-left to image top-left origin\n const y1 = pageHeight - y - height;\n const y2 = pageHeight - y;\n const x1 = x;\n const x2 = x + width;\n\n // Normalize to 0-1 range\n return [\n Math.max(0.0, Math.min(1.0, x1 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y1 / pageHeight)),\n Math.max(0.0, Math.min(1.0, x2 / pageWidth)),\n Math.max(0.0, Math.min(1.0, y2 / pageHeight))\n ];\n}\n\n/**\n * Multiply two transformation matrices\n *\n * @param {Array} m1 - First matrix [a, b, c, d, e, f]\n * @param {Array} m2 - Second matrix [a, b, c, d, e, f]\n * @returns {Array} Result matrix [a, b, c, d, e, f]\n */\nfunction multiplyTransforms(m1, m2) {\n return [\n m1[0] * m2[0] + m1[2] * m2[1],\n m1[1] * m2[0] + m1[3] * m2[1],\n m1[0] * m2[2] + m1[2] * m2[3],\n m1[1] * m2[2] + m1[3] * m2[3],\n m1[0] * m2[4] + m1[2] * m2[5] + m1[4],\n m1[1] * m2[4] + m1[3] * m2[5] + m1[5]\n ];\n}\n\n/**\n * Get human-readable operator name\n *\n * @param {number} op - Operator code\n * @param {Object} OPS - PDF.js OPS constants\n * @returns {string} Operator name\n */\nfunction getOperatorName(op, OPS) {\n const opNames = {\n [OPS.paintImageXObject]: \"paintImageXObject\",\n [OPS.paintInlineImageXObject]: \"paintInlineImageXObject\",\n [OPS.paintImageMaskXObject]: \"paintImageMaskXObject\",\n [OPS.paintJpegXObject]: \"paintJpegXObject\"\n };\n return opNames[op] || \"unknown\";\n}\n\n/**\n * Extract image blocks from a PDF page using getOperatorList with normalized coordinates\n *\n * @param {PDFPageProxy} page - PDF.js page object\n * @returns {Promise<Array>} Array of image blocks with normalized bounding boxes (0-1 range)\n */\nasync function extractImageBlocks(page) {\n try {\n const operatorList = await page.getOperatorList();\n const viewport = page.getViewport({ scale: 1.0 });\n\n const pageWidth = viewport.width;\n const pageHeight = viewport.height;\n\n const imageBlocks = [];\n const graphicsStateStack = []; // Track graphics state transformations\n let currentTransform = [1, 0, 0, 1, 0, 0]; // Identity matrix\n\n const ops = operatorList.fnArray;\n const args = operatorList.argsArray;\n\n // Image paint operator constants from PDF.js\n const OPS = pdfjsLib.OPS;\n const IMAGE_OPS = [\n OPS.paintImageXObject,\n OPS.paintInlineImageXObject,\n OPS.paintImageMaskXObject,\n OPS.paintJpegXObject\n ];\n\n for (let i = 0; i < ops.length; i++) {\n const op = ops[i];\n const arg = args[i];\n\n // Track graphics state stack\n if (op === OPS.save) {\n graphicsStateStack.push([...currentTransform]);\n } else if (op === OPS.restore) {\n if (graphicsStateStack.length > 0) {\n currentTransform = graphicsStateStack.pop();\n }\n } else if (op === OPS.transform) {\n // Update current transformation matrix\n const [a, b, c, d, e, f] = arg;\n currentTransform = multiplyTransforms(currentTransform, [a, b, c, d, e, f]);\n } else if (IMAGE_OPS.includes(op)) {\n // Extract image bounding box (normalized)\n const bbox_norm = extractBBoxFromTransform(currentTransform, pageWidth, pageHeight);\n\n imageBlocks.push({\n type: \"image\",\n bbox_norm: bbox_norm,\n source: \"pdfjs\",\n operator: getOperatorName(op, OPS)\n });\n }\n }\n\n return imageBlocks;\n } catch (error) {\n console.error(\"Error extracting image blocks:\", error);\n return [];\n }\n}\n\n/**\n * Extract all blocks (text and images) from a PDF page\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {number} pageNumber - Page number (1-indexed)\n * @returns {Promise<Object>} Object with textBlocks and imageBlocks arrays\n */\nexport async function extractAllBlocks(pdfPath, pageNumber) {\n try {\n // Load PDF document\n const loadingTask = pdfjsLib.getDocument(pdfPath);\n const pdfDoc = await loadingTask.promise;\n\n // Validate page number\n if (pageNumber < 1 || pageNumber > pdfDoc.numPages) {\n throw new Error(`Invalid page number: ${pageNumber}. Document has ${pdfDoc.numPages} pages.`);\n }\n\n // Get page\n const page = await pdfDoc.getPage(pageNumber);\n const viewport = page.getViewport({ scale: 1.0 });\n\n // Extract text and image blocks in parallel\n const [textBlocks, imageBlocks] = await Promise.all([\n extractTextBlocks(page),\n extractImageBlocks(page)\n ]);\n\n return {\n textBlocks,\n imageBlocks,\n pageDimensions: {\n width: viewport.width,\n height: viewport.height\n },\n pageNumber: pageNumber\n };\n } catch (error) {\n console.error(`Error extracting blocks from page ${pageNumber}:`, error);\n throw error;\n }\n}\n\n/**\n * Extract blocks from multiple pages\n *\n * @param {string} pdfPath - Path to PDF file\n * @param {Array<number>} pageNumbers - Array of page numbers (1-indexed)\n * @returns {Promise<Array>} Array of extraction results, one per page\n */\nexport async function extractMultiplePages(pdfPath, pageNumbers) {\n const results = [];\n\n for (const pageNum of pageNumbers) {\n try {\n const pageData = await extractAllBlocks(pdfPath, pageNum);\n results.push(pageData);\n } catch (error) {\n console.error(`Failed to extract page ${pageNum}:`, error);\n results.push({\n textBlocks: [],\n imageBlocks: [],\n pageDimensions: null,\n pageNumber: pageNum,\n error: error.message\n });\n }\n }\n\n return results;\n}\n"],"names":["extractTextBlocks","page","textContent","viewport","pageWidth","pageHeight","textBlocks","item","transform","fontSize","x","y","width","height","x1","y1","x2","y2","bbox_norm","error","extractBBoxFromTransform","scaleX","scaleY","multiplyTransforms","m1","m2","getOperatorName","op","OPS","extractImageBlocks","operatorList","imageBlocks","graphicsStateStack","currentTransform","ops","args","pdfjsLib","IMAGE_OPS","i","arg","a","b","c","d","e","f","extractAllBlocks","pdfPath","pageNumber","pdfDoc","extractMultiplePages","pageNumbers","results","pageNum","pageData"],"mappings":"wYAgBA,eAAeA,EAAkBC,EAAM,CACrC,GAAI,CACF,MAAMC,EAAc,MAAMD,EAAK,eAAc,EACvCE,EAAWF,EAAK,YAAY,CAAE,MAAO,CAAG,CAAE,EAE1CG,EAAYD,EAAS,MACrBE,EAAaF,EAAS,OAEtBG,EAAa,CAAA,EAEnB,UAAWC,KAAQL,EAAY,MAAO,CAEpC,GAAI,CAACK,EAAK,KAAO,CAACA,EAAK,IAAI,OACzB,SAIF,MAAMC,EAAYD,EAAK,UACjBE,EAAW,KAAK,KAAKD,EAAU,CAAC,EAAIA,EAAU,CAAC,EAAIA,EAAU,CAAC,EAAIA,EAAU,CAAC,CAAC,EAG9EE,EAAIF,EAAU,CAAC,EACfG,EAAIR,EAAS,OAASK,EAAU,CAAC,EACjCI,EAAQL,EAAK,MACbM,EAASN,EAAK,QAAUE,EAExBK,EAAKJ,EACLK,EAAKJ,EAAIE,EACTG,EAAKN,EAAIE,EACTK,EAAKN,EAGLO,EAAY,CAChB,KAAK,IAAI,EAAK,KAAK,IAAI,EAAKJ,EAAKV,CAAS,CAAC,EAC3C,KAAK,IAAI,EAAK,KAAK,IAAI,EAAKW,EAAKV,CAAU,CAAC,EAC5C,KAAK,IAAI,EAAK,KAAK,IAAI,EAAKW,EA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,EACZ,YAAa,CAAA,EACb,eAAgB,KAChB,WAAYC,EACZ,MAAOlC,EAAM,OACrB,CAAO,CACH,CAGF,OAAOiC,CACT"}
|
|
1
|
+
{"version":3,"file":"index8.cjs","sources":["../src/utils/viewportUtils.js"],"sourcesContent":["/**\n * Viewport Utility Functions\n *\n * This module provides utility functions for PDF viewport calculations\n * and transformations. These functions are used by the PDF viewer to\n * calculate viewport dimensions and manage scaling.\n */\n\n/**\n * Calculate viewport from PDF page\n *\n * Creates a viewport object from a PDF.js page with the specified scale.\n * The viewport contains dimensions and transformation matrix for rendering.\n *\n * @param {Object} page - PDF.js page object\n * @param {number} scale - Scale factor for rendering\n * @returns {Object} Viewport object with width, height, and transform matrix\n *\n * @example\n * const viewport = calculateViewport(pdfPage, 1.5);\n * // Returns: { width: 1200, height: 1600, scale: 1.5, ... }\n */\nexport function calculateViewport(page, scale) {\n if (!page) {\n throw new Error('Page object is required');\n }\n\n return page.getViewport({ scale });\n}\n\n/**\n * Get viewport dimensions\n *\n * Extracts width and height from a viewport object.\n * Useful for coordinate transformations and layout calculations.\n *\n * @param {Object} viewport - Viewport object from PDF.js\n * @returns {{width: number, height: number}} Dimensions object\n *\n * @example\n * const { width, height } = getViewportDimensions(viewport);\n * // Returns: { width: 1200, height: 1600 }\n */\nexport function getViewportDimensions(viewport) {\n if (!viewport) {\n return { width: 0, height: 0 };\n }\n\n return {\n width: viewport.width,\n height: viewport.height\n };\n}\n\n/**\n * Calculate scaled dimensions\n *\n * Calculates dimensions for a given scale factor.\n * Used when zoom level changes to determine new canvas size.\n *\n * @param {number} baseWidth - Original width\n * @param {number} baseHeight - Original height\n * @param {number} scale - Scale factor\n * @returns {{width: number, height: number}} Scaled dimensions\n *\n * @example\n * const scaled = calculateScaledDimensions(800, 1000, 1.5);\n * // Returns: { width: 1200, height: 1500 }\n */\nexport function calculateScaledDimensions(baseWidth, baseHeight, scale) {\n return {\n width: baseWidth * scale,\n height: baseHeight * scale\n };\n}\n"],"names":["calculateViewport","page","scale","getViewportDimensions","viewport","calculateScaledDimensions","baseWidth","baseHeight"],"mappings":"gFAsBO,SAASA,EAAkBC,EAAMC,EAAO,CAC7C,GAAI,CAACD,EACH,MAAM,IAAI,MAAM,yBAAyB,EAG3C,OAAOA,EAAK,YAAY,CAAE,MAAAC,EAAO,CACnC,CAeO,SAASC,EAAsBC,EAAU,CAC9C,OAAKA,EAIE,CACL,MAAOA,EAAS,MAChB,OAAQA,EAAS,MACrB,EANW,CAAE,MAAO,EAAG,OAAQ,CAAC,CAOhC,CAiBO,SAASC,EAA0BC,EAAWC,EAAYL,EAAO,CACtE,MAAO,CACL,MAAOI,EAAYJ,EACnB,OAAQK,EAAaL,CACzB,CACA"}
|
package/dist/index8.js
CHANGED
|
@@ -1,132 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (const r of t.items) {
|
|
6
|
-
if (!r.str || !r.str.trim())
|
|
7
|
-
continue;
|
|
8
|
-
const a = r.transform, g = Math.sqrt(a[2] * a[2] + a[3] * a[3]), l = a[4], c = o.height - a[5], x = r.width, h = r.height || g, p = l, f = c - h, u = l + x, m = c, b = [
|
|
9
|
-
Math.max(0, Math.min(1, p / s)),
|
|
10
|
-
Math.max(0, Math.min(1, f / n)),
|
|
11
|
-
Math.max(0, Math.min(1, u / s)),
|
|
12
|
-
Math.max(0, Math.min(1, m / n))
|
|
13
|
-
];
|
|
14
|
-
i.push({
|
|
15
|
-
type: "text",
|
|
16
|
-
text: r.str,
|
|
17
|
-
bbox_norm: b,
|
|
18
|
-
font: r.fontName || "unknown",
|
|
19
|
-
fontSize: g,
|
|
20
|
-
source: "pdfjs"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return i;
|
|
24
|
-
} catch (t) {
|
|
25
|
-
return console.error("Error extracting text blocks:", t), [];
|
|
26
|
-
}
|
|
1
|
+
function r(t, e) {
|
|
2
|
+
if (!t)
|
|
3
|
+
throw new Error("Page object is required");
|
|
4
|
+
return t.getViewport({ scale: e });
|
|
27
5
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Math.max(0, Math.min(1, h / t)),
|
|
34
|
-
Math.max(0, Math.min(1, c / o))
|
|
35
|
-
];
|
|
6
|
+
function n(t) {
|
|
7
|
+
return t ? {
|
|
8
|
+
width: t.width,
|
|
9
|
+
height: t.height
|
|
10
|
+
} : { width: 0, height: 0 };
|
|
36
11
|
}
|
|
37
|
-
function
|
|
38
|
-
return [
|
|
39
|
-
e[0] * t[0] + e[2] * t[1],
|
|
40
|
-
e[1] * t[0] + e[3] * t[1],
|
|
41
|
-
e[0] * t[2] + e[2] * t[3],
|
|
42
|
-
e[1] * t[2] + e[3] * t[3],
|
|
43
|
-
e[0] * t[4] + e[2] * t[5] + e[4],
|
|
44
|
-
e[1] * t[4] + e[3] * t[5] + e[5]
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
function O(e, t) {
|
|
12
|
+
function h(t, e, i) {
|
|
48
13
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
[t.paintJpegXObject]: "paintJpegXObject"
|
|
53
|
-
}[e] || "unknown";
|
|
54
|
-
}
|
|
55
|
-
async function X(e) {
|
|
56
|
-
try {
|
|
57
|
-
const t = await e.getOperatorList(), o = e.getViewport({ scale: 1 }), s = o.width, n = o.height, i = [], r = [];
|
|
58
|
-
let a = [1, 0, 0, 1, 0, 0];
|
|
59
|
-
const g = t.fnArray, l = t.argsArray, c = w.OPS, x = [
|
|
60
|
-
c.paintImageXObject,
|
|
61
|
-
c.paintInlineImageXObject,
|
|
62
|
-
c.paintImageMaskXObject,
|
|
63
|
-
c.paintJpegXObject
|
|
64
|
-
];
|
|
65
|
-
for (let h = 0; h < g.length; h++) {
|
|
66
|
-
const p = g[h], f = l[h];
|
|
67
|
-
if (p === c.save)
|
|
68
|
-
r.push([...a]);
|
|
69
|
-
else if (p === c.restore)
|
|
70
|
-
r.length > 0 && (a = r.pop());
|
|
71
|
-
else if (p === c.transform) {
|
|
72
|
-
const [u, m, b, M, k, y] = f;
|
|
73
|
-
a = I(a, [u, m, b, M, k, y]);
|
|
74
|
-
} else if (x.includes(p)) {
|
|
75
|
-
const u = j(a, s, n);
|
|
76
|
-
i.push({
|
|
77
|
-
type: "image",
|
|
78
|
-
bbox_norm: u,
|
|
79
|
-
source: "pdfjs",
|
|
80
|
-
operator: O(p, c)
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return i;
|
|
85
|
-
} catch (t) {
|
|
86
|
-
return console.error("Error extracting image blocks:", t), [];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async function B(e, t) {
|
|
90
|
-
try {
|
|
91
|
-
const s = await w.getDocument(e).promise;
|
|
92
|
-
if (t < 1 || t > s.numPages)
|
|
93
|
-
throw new Error(`Invalid page number: ${t}. Document has ${s.numPages} pages.`);
|
|
94
|
-
const n = await s.getPage(t), i = n.getViewport({ scale: 1 }), [r, a] = await Promise.all([
|
|
95
|
-
d(n),
|
|
96
|
-
X(n)
|
|
97
|
-
]);
|
|
98
|
-
return {
|
|
99
|
-
textBlocks: r,
|
|
100
|
-
imageBlocks: a,
|
|
101
|
-
pageDimensions: {
|
|
102
|
-
width: i.width,
|
|
103
|
-
height: i.height
|
|
104
|
-
},
|
|
105
|
-
pageNumber: t
|
|
106
|
-
};
|
|
107
|
-
} catch (o) {
|
|
108
|
-
throw console.error(`Error extracting blocks from page ${t}:`, o), o;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async function T(e, t) {
|
|
112
|
-
const o = [];
|
|
113
|
-
for (const s of t)
|
|
114
|
-
try {
|
|
115
|
-
const n = await B(e, s);
|
|
116
|
-
o.push(n);
|
|
117
|
-
} catch (n) {
|
|
118
|
-
console.error(`Failed to extract page ${s}:`, n), o.push({
|
|
119
|
-
textBlocks: [],
|
|
120
|
-
imageBlocks: [],
|
|
121
|
-
pageDimensions: null,
|
|
122
|
-
pageNumber: s,
|
|
123
|
-
error: n.message
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return o;
|
|
14
|
+
width: t * i,
|
|
15
|
+
height: e * i
|
|
16
|
+
};
|
|
127
17
|
}
|
|
128
18
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
19
|
+
h as calculateScaledDimensions,
|
|
20
|
+
r as calculateViewport,
|
|
21
|
+
n as getViewportDimensions
|
|
131
22
|
};
|
|
132
23
|
//# sourceMappingURL=index8.js.map
|