web-annotation-renderer 0.1.4 → 0.2.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/dist/index15.js CHANGED
@@ -1,35 +1,126 @@
1
- const o = {
2
- page: 1,
3
- start: 0,
4
- end: 0
5
- }, t = {
6
- mode: "quads",
7
- quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],
8
- style: { color: "rgba(255, 255, 0, 0.3)" }
9
- }, s = {
10
- content: "[No content]",
11
- x: 0.1,
12
- y: 0.1,
13
- w: 0.3,
14
- h: 0.1,
15
- style: {
16
- bg: "rgba(255, 255, 255, 0.9)",
17
- color: "#000000"
18
- }
19
- }, e = {
20
- strokes: [{
21
- color: "#1f2937",
22
- size: 3,
23
- points: [
24
- { t: 0, x: 0.1, y: 0.1 },
25
- { t: 1, x: 0.2, y: 0.2 }
26
- ]
27
- }]
28
- };
1
+ import { jsxs as S, jsx as F } from "react/jsx-runtime";
2
+ import { useRef as u, useCallback as k, useEffect as c } from "react";
3
+ import { AnnotationRenderer as x } from "./index2.js";
4
+ function Q({
5
+ // Required props
6
+ pdfUrl: a,
7
+ // Optional props with defaults
8
+ page: i = 1,
9
+ scale: s = 1.5,
10
+ annotations: y = [],
11
+ currentTime: l = 0,
12
+ // Callbacks
13
+ onLoad: P,
14
+ onError: t,
15
+ onPageChange: h,
16
+ // Styling
17
+ className: v,
18
+ style: m,
19
+ canvasStyle: w
20
+ }) {
21
+ const f = u(null), d = u(null), r = u(null), A = u(Promise.resolve()), o = k((e) => {
22
+ A.current = A.current.then(e).catch((p) => {
23
+ console.error("AnnotPdf: Queued operation failed:", p);
24
+ });
25
+ }, []);
26
+ c(() => {
27
+ if (!(!f.current || !d.current)) {
28
+ try {
29
+ r.current = new x({
30
+ canvasElement: f.current,
31
+ container: d.current
32
+ });
33
+ } catch (e) {
34
+ console.error("AnnotPdf: Failed to initialize renderer:", e), t && t(e);
35
+ }
36
+ return () => {
37
+ r.current && (r.current.destroy(), r.current = null);
38
+ };
39
+ }
40
+ }, []), c(() => {
41
+ if (!r.current || !a)
42
+ return;
43
+ let e = !1;
44
+ return o(async () => {
45
+ try {
46
+ const n = await r.current.loadPDF(a);
47
+ if (e) return;
48
+ if (!n.success) {
49
+ console.error("AnnotPdf: Failed to load PDF:", n.error), t && t(new Error(n.error));
50
+ return;
51
+ }
52
+ P && P({ pageCount: n.pageCount });
53
+ } catch (n) {
54
+ if (e) return;
55
+ console.error("AnnotPdf: Failed to load PDF:", n), t && t(n);
56
+ }
57
+ }), () => {
58
+ e = !0;
59
+ };
60
+ }, [a, o]), c(() => {
61
+ !r.current || !i || typeof i != "number" || o(async () => {
62
+ try {
63
+ const e = await r.current.setPage(i);
64
+ if (!e.success) {
65
+ console.error("AnnotPdf: Failed to set page:", e.error), t && t(new Error(e.error));
66
+ return;
67
+ }
68
+ h && h(i);
69
+ } catch (e) {
70
+ console.error("AnnotPdf: Failed to set page:", e), t && t(e);
71
+ }
72
+ });
73
+ }, [i, o]), c(() => {
74
+ !r.current || !s || typeof s != "number" || o(async () => {
75
+ try {
76
+ const e = await r.current.setScale(s);
77
+ e.success || (console.error("AnnotPdf: Failed to set scale:", e.error), t && t(new Error(e.error)));
78
+ } catch (e) {
79
+ console.error("AnnotPdf: Failed to set scale:", e), t && t(e);
80
+ }
81
+ });
82
+ }, [s, o]), c(() => {
83
+ if (r.current)
84
+ try {
85
+ r.current.setAnnotations(y || []);
86
+ } catch (e) {
87
+ console.error("AnnotPdf: Failed to set annotations:", e), t && t(e);
88
+ }
89
+ }, [y]), c(() => {
90
+ if (!(!r.current || l === void 0 || l === null))
91
+ try {
92
+ r.current.setTime(l);
93
+ } catch (e) {
94
+ console.error("AnnotPdf: Failed to set time:", e), t && t(e);
95
+ }
96
+ }, [l]);
97
+ const b = {
98
+ position: "relative",
99
+ display: "inline-block",
100
+ lineHeight: 0,
101
+ // Remove extra space below canvas
102
+ ...m
103
+ // User styles override defaults
104
+ }, C = {
105
+ position: "absolute",
106
+ top: 0,
107
+ left: 0,
108
+ width: "100%",
109
+ height: "100%",
110
+ pointerEvents: "none",
111
+ // Allow clicks to pass through to canvas
112
+ overflow: "hidden"
113
+ }, R = {
114
+ display: "block",
115
+ ...w
116
+ // User styles override defaults
117
+ };
118
+ return /* @__PURE__ */ S("div", { className: v, style: b, children: [
119
+ /* @__PURE__ */ F("canvas", { ref: f, style: R }),
120
+ /* @__PURE__ */ F("div", { ref: d, style: C })
121
+ ] });
122
+ }
29
123
  export {
30
- o as BASE_DEFAULTS,
31
- t as HIGHLIGHT_DEFAULTS,
32
- e as INK_DEFAULTS,
33
- s as TEXT_DEFAULTS
124
+ Q as default
34
125
  };
35
126
  //# sourceMappingURL=index15.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index15.js","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"AAiBY,MAACA,IAAgB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AACP,GAYaC,IAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM;AAAA,EAC3C,OAAO,EAAE,OAAO,yBAAwB;AAC1C,GAeaC,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,EACX;AACA,GAUaC,IAAe;AAAA,EAC1B,SAAS,CAAC;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,MACtB,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,IAC5B;AAAA,EACA,CAAG;AACH;"}
1
+ {"version":3,"file":"index15.js","sources":["../src/adapters/AnnotPdf.jsx"],"sourcesContent":["// ============================================================================\n// SECTION 1: IMPORTS\n// ============================================================================\n\nimport { useRef, useEffect, useCallback } from 'react';\nimport { AnnotationRenderer } from '../core/AnnotationRenderer.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\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 * @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\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 {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 // 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 // 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 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\n try {\n engineRef.current = new AnnotationRenderer({\n canvasElement: canvasRef.current,\n container: layerContainerRef.current\n });\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 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: Engine must exist and pdfUrl must be valid\n if (!engineRef.current || !pdfUrl) {\n return;\n }\n\n let cancelled = false;\n\n const loadPdf = async () => {\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, 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: Engine must exist and page must be valid\n if (!engineRef.current || !page || typeof page !== 'number') {\n return;\n }\n\n // Queue the page change operation to prevent race conditions\n queueOperation(async () => {\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, 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: Engine must exist and scale must be valid\n if (!engineRef.current || !scale || typeof scale !== 'number') {\n return;\n }\n\n // Queue the scale change operation to prevent race conditions\n queueOperation(async () => {\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, queueOperation]);\n\n // ==========================================================================\n // SECTION 9: ANNOTATIONS SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync annotations prop to engine.setAnnotations() method\n */\n useEffect(() => {\n // Guard: Engine must exist\n if (!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]);\n\n // ==========================================================================\n // SECTION 10: TIMELINE SYNCHRONIZATION\n // ==========================================================================\n\n /**\n * Sync currentTime prop to engine.setTime() method\n */\n useEffect(() => {\n // Guard: Engine must exist and currentTime must be defined\n if (!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]);\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","onLoad","onError","onPageChange","className","style","canvasStyle","canvasRef","useRef","layerContainerRef","engineRef","renderQueue","queueOperation","useCallback","operation","error","useEffect","AnnotationRenderer","cancelled","result","defaultContainerStyle","defaultLayerStyle","defaultCanvasStyle","jsxs","jsx"],"mappings":";;;AA4EA,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,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,cAAAC;AAAA;AAAA,EAGA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AACF,GAAG;AAUD,QAAMC,IAAYC,EAAO,IAAI,GAMvBC,IAAoBD,EAAO,IAAI,GAO/BE,IAAYF,EAAO,IAAI,GAQvBG,IA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U,MAAM;AAEd,QAAI,GAACN,EAAU,WAAWV,MAAgB,UAAaA,MAAgB;AAKvE,UAAI;AACF,QAAAU,EAAU,QAAQ,QAAQV,CAAW;AAAA,MACvC,SAASe,GAAO;AACd,gBAAQ,MAAM,iCAAiCA,CAAK,GAChDb,KACFA,EAAQa,CAAK;AAAA,MAEjB;AAAA,EACF,GAAG,CAACf,CAAW,CAAC;AAUhB,QAAMoB,IAAwB;AAAA,IAC5B,UAAU;AAAA,IACV,SAAS;AAAA,IACT,YAAY;AAAA;AAAA,IACZ,GAAGf;AAAA;AAAA,EAAA,GAOCgB,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,GAAGhB;AAAA;AAAA,EAAA;AAOL,SACE,gBAAAiB,EAAC,OAAA,EAAI,WAAAnB,GAAsB,OAAOgB,GAChC,UAAA;AAAA,IAAA,gBAAAI,EAAC,UAAA,EAAO,KAAKjB,GAAW,OAAOe,GAAoB;AAAA,IACnD,gBAAAE,EAAC,OAAA,EAAI,KAAKf,GAAmB,OAAOY,EAAA,CAAmB;AAAA,EAAA,GACzD;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={page:1,start:0,end:0},o={mode:"quads",quads:[{x:.1,y:.1,w:.8,h:.05}],style:{color:"rgba(255, 255, 0, 0.3)"}},e={content:"[No content]",x:.1,y:.1,w:.3,h:.1,style:{bg:"rgba(255, 255, 255, 0.9)",color:"#000000"}},s={strokes:[{color:"#1f2937",size:3,points:[{t:0,x:.1,y:.1},{t:1,x:.2,y:.2}]}]};exports.BASE_DEFAULTS=t;exports.HIGHLIGHT_DEFAULTS=o;exports.INK_DEFAULTS=s;exports.TEXT_DEFAULTS=e;
2
+ //# sourceMappingURL=index16.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index16.cjs","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"gFAiBY,MAACA,EAAgB,CAC3B,KAAM,EACN,MAAO,EACP,IAAK,CACP,EAYaC,EAAqB,CAChC,KAAM,QACN,MAAO,CAAC,CAAE,EAAG,GAAK,EAAG,GAAK,EAAG,GAAK,EAAG,IAAM,EAC3C,MAAO,CAAE,MAAO,wBAAwB,CAC1C,EAeaC,EAAgB,CAC3B,QAAS,eACT,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,MAAO,CACL,GAAI,2BACJ,MAAO,SACX,CACA,EAUaC,EAAe,CAC1B,QAAS,CAAC,CACR,MAAO,UACP,KAAM,EACN,OAAQ,CACN,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,EACtB,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,CAC5B,CACA,CAAG,CACH"}
@@ -0,0 +1,35 @@
1
+ const o = {
2
+ page: 1,
3
+ start: 0,
4
+ end: 0
5
+ }, t = {
6
+ mode: "quads",
7
+ quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],
8
+ style: { color: "rgba(255, 255, 0, 0.3)" }
9
+ }, s = {
10
+ content: "[No content]",
11
+ x: 0.1,
12
+ y: 0.1,
13
+ w: 0.3,
14
+ h: 0.1,
15
+ style: {
16
+ bg: "rgba(255, 255, 255, 0.9)",
17
+ color: "#000000"
18
+ }
19
+ }, e = {
20
+ strokes: [{
21
+ color: "#1f2937",
22
+ size: 3,
23
+ points: [
24
+ { t: 0, x: 0.1, y: 0.1 },
25
+ { t: 1, x: 0.2, y: 0.2 }
26
+ ]
27
+ }]
28
+ };
29
+ export {
30
+ o as BASE_DEFAULTS,
31
+ t as HIGHLIGHT_DEFAULTS,
32
+ e as INK_DEFAULTS,
33
+ s as TEXT_DEFAULTS
34
+ };
35
+ //# sourceMappingURL=index16.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index16.js","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"AAiBY,MAACA,IAAgB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AACP,GAYaC,IAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM;AAAA,EAC3C,OAAO,EAAE,OAAO,yBAAwB;AAC1C,GAeaC,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,EACX;AACA,GAUaC,IAAe;AAAA,EAC1B,SAAS,CAAC;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,MACtB,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,IAC5B;AAAA,EACA,CAAG;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-annotation-renderer",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Framework-agnostic PDF annotation renderer with timeline synchronization for educational content and interactive documents",
6
6
  "keywords": [
@@ -34,6 +34,10 @@
34
34
  "import": "./dist/index.js",
35
35
  "require": "./dist/index.cjs"
36
36
  },
37
+ "./extract": {
38
+ "import": "./dist/index.js",
39
+ "require": "./dist/index.cjs"
40
+ },
37
41
  "./package.json": "./package.json"
38
42
  },
39
43
  "files": [