web-annotation-renderer 0.6.4 → 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/index28.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index28.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index28.js","sources":["../src/rough/roughPathExtractor.js"],"sourcesContent":["/**\n * RoughJS Path Extractor - Utility functions for hand-drawn style paths\n *\n * Wraps RoughJS Generator API to extract path data as points arrays,\n * compatible with the existing StrokeRenderer pipeline.\n *\n * @module rough/roughPathExtractor\n */\n\nimport rough from 'roughjs';\n\nconst generator = rough.generator();\n\n/**\n * Cubic bezier interpolation\n *\n * @param {Array} p0 - Start point [x, y]\n * @param {Array} p1 - Control point 1 [x, y]\n * @param {Array} p2 - Control point 2 [x, y]\n * @param {Array} p3 - End point [x, y]\n * @param {number} t - Interpolation factor (0-1)\n * @returns {Array} Interpolated point [x, y]\n */\nfunction bezierPoint(p0, p1, p2, p3, t) {\n const mt = 1 - t;\n return [\n mt ** 3 * p0[0] + 3 * mt ** 2 * t * p1[0] + 3 * mt * t ** 2 * p2[0] + t ** 3 * p3[0],\n mt ** 3 * p0[1] + 3 * mt ** 2 * t * p1[1] + 3 * mt * t ** 2 * p2[1] + t ** 3 * p3[1]\n ];\n}\n\n/**\n * Convert RoughJS ops array to points array\n *\n * Processes move, lineTo, and bcurveTo operations.\n * Bezier curves are linearized with 4 intermediate points.\n *\n * @param {Array} ops - Array of RoughJS op objects\n * @returns {Array} Array of [x, y] points\n */\nfunction opsToPoints(ops) {\n const points = [];\n let current = [0, 0];\n\n for (const { op, data } of ops) {\n switch (op) {\n case 'move':\n current = [data[0], data[1]];\n points.push([...current]);\n break;\n\n case 'lineTo':\n current = [data[0], data[1]];\n points.push([...current]);\n break;\n\n case 'bcurveTo': {\n const [cx1, cy1, cx2, cy2, x, y] = data;\n const p0 = current;\n const p1 = [cx1, cy1];\n const p2 = [cx2, cy2];\n const p3 = [x, y];\n\n for (let t = 0.25; t <= 1; t += 0.25) {\n points.push(bezierPoint(p0, p1, p2, p3, t));\n }\n current = [x, y];\n break;\n }\n }\n }\n\n return points;\n}\n\n/**\n * Extract points from a RoughJS drawable\n *\n * Collects all path operations from drawable.sets and converts to points.\n *\n * @param {Object} drawable - RoughJS drawable object\n * @returns {Array} Array of [x, y] points\n */\nfunction extractPoints(drawable) {\n const allPoints = [];\n\n for (const set of drawable.sets) {\n if (set.type === 'path') {\n allPoints.push(...opsToPoints(set.ops));\n }\n }\n\n return allPoints;\n}\n\n/**\n * Generate a hash seed from a string\n *\n * Produces a deterministic number from string input for reproducible randomness.\n *\n * @param {string} str - Input string (e.g., annotation ID)\n * @returns {number} Hash value for use as seed\n */\nexport function hashSeed(str) {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) - hash) + str.charCodeAt(i);\n hash |= 0;\n }\n return Math.abs(hash);\n}\n\n/**\n * Convert a line to RoughJS style points\n *\n * @param {number} x1 - Start x coordinate\n * @param {number} y1 - Start y coordinate\n * @param {number} x2 - End x coordinate\n * @param {number} y2 - End y coordinate\n * @param {Object} [options={}] - RoughJS options\n * @param {number} [options.roughness=1.0] - Line irregularity (0=clean, 3+=very rough)\n * @param {number} [options.bowing=1.0] - Line curvature (0=straight, 2+=very curved)\n * @param {number} [options.seed] - Seed for reproducible randomness\n * @param {number} [options.curveFitting=0.95] - Curve fitting (0=loose, 1=tight)\n * @param {number} [options.curveStepCount=9] - Curve resolution (higher=smoother)\n * @param {number} [options.maxRandomnessOffset=2] - Max random offset\n * @param {boolean} [options.disableMultiStroke=false] - Disable double-stroke effect\n * @returns {Array} Array of [x, y] points with hand-drawn style\n */\nexport function roughLine(x1, y1, x2, y2, options = {}) {\n const drawable = generator.line(x1, y1, x2, y2, {\n roughness: options.roughness ?? 1.0,\n bowing: options.bowing ?? 1.0,\n seed: options.seed ?? Math.floor(Math.random() * 2 ** 31),\n curveFitting: options.curveFitting ?? 0.95,\n curveStepCount: options.curveStepCount ?? 9,\n maxRandomnessOffset: options.maxRandomnessOffset ?? 2,\n disableMultiStroke: options.disableMultiStroke ?? false,\n ...options\n });\n\n return extractPoints(drawable);\n}\n\n/**\n * Convert an ellipse to RoughJS style points\n *\n * @param {number} cx - Center x coordinate\n * @param {number} cy - Center y coordinate\n * @param {number} width - Ellipse width\n * @param {number} height - Ellipse height\n * @param {Object} [options={}] - RoughJS options\n * @param {number} [options.roughness=1.0] - Shape irregularity\n * @param {number} [options.bowing=1.0] - Line curvature\n * @param {number} [options.seed] - Seed for reproducible randomness\n * @param {number} [options.curveFitting=0.95] - Curve fitting (0=loose, 1=tight)\n * @param {number} [options.curveStepCount=9] - Curve resolution (higher=smoother)\n * @param {number} [options.maxRandomnessOffset=2] - Max random offset\n * @param {boolean} [options.disableMultiStroke=false] - Disable double-stroke effect\n * @returns {Array} Array of [x, y] points with hand-drawn style\n */\nexport function roughEllipse(cx, cy, width, height, options = {}) {\n const drawable = generator.ellipse(cx, cy, width, height, {\n roughness: options.roughness ?? 1.0,\n bowing: options.bowing ?? 1.0,\n seed: options.seed ?? Math.floor(Math.random() * 2 ** 31),\n curveFitting: options.curveFitting ?? 0.95,\n curveStepCount: options.curveStepCount ?? 9,\n maxRandomnessOffset: options.maxRandomnessOffset ?? 2,\n disableMultiStroke: options.disableMultiStroke ?? false,\n ...options\n });\n\n return extractPoints(drawable);\n}\n\n/**\n * Convert a linear path (multiple connected points) to RoughJS style\n *\n * @param {Array} points - Array of [x, y] points to connect\n * @param {Object} [options={}] - RoughJS options\n * @param {number} [options.roughness=1.0] - Path irregularity\n * @param {number} [options.bowing=1.0] - Line curvature\n * @param {number} [options.seed] - Seed for reproducible randomness\n * @returns {Array} Array of [x, y] points with hand-drawn style\n */\nexport function roughLinearPath(points, options = {}) {\n if (!points || points.length < 2) {\n return points || [];\n }\n\n const drawable = generator.linearPath(points, {\n roughness: options.roughness ?? 1.0,\n bowing: options.bowing ?? 1.0,\n seed: options.seed ?? Math.floor(Math.random() * 2 ** 31),\n ...options\n });\n\n return extractPoints(drawable);\n}\n\nexport default {\n roughLine,\n roughEllipse,\n roughLinearPath,\n hashSeed\n};\n"],"names":["generator","rough","bezierPoint","p0","p1","p2","p3","t","mt","opsToPoints","ops","points","current","op","data","cx1","cy1","cx2","cy2","x","y","extractPoints","drawable","allPoints","set","hashSeed","str","hash","i","roughLine","x1","y1","x2","y2","options","roughEllipse","cx","cy","width","height"],"mappings":"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"}
|
package/dist/index29.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index28.cjs"),u=Object.freeze({roughness:1,bowing:1,curveFitting:.95,curveStepCount:9,maxRandomnessOffset:2,disableMultiStroke:!1});function s(e,t,n={}){const o={...u,...n};return{roughness:e.roughness??o.roughness,bowing:e.bowing??o.bowing,curveFitting:e.curveFitting??o.curveFitting,curveStepCount:e.curveStepCount??o.curveStepCount,maxRandomnessOffset:e.maxRandomnessOffset??o.maxRandomnessOffset,disableMultiStroke:e.disableMultiStroke??o.disableMultiStroke,seed:r.hashSeed(t)}}function i(e,t){return e.color||t}exports.buildRoughOptions=s;exports.resolveColor=i;
|
|
2
2
|
//# sourceMappingURL=index29.cjs.map
|
package/dist/index29.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index29.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index29.cjs","sources":["../src/converters/_shared.js"],"sourcesContent":["/**\n * Shared helpers for converters\n *\n * Centralizes the RoughJS option boilerplate and color fallback resolution\n * shared across highlight / underline / circle / arrow converters.\n *\n * @module converters/_shared\n */\n\nimport { hashSeed } from '../rough/roughPathExtractor.js';\n\n/**\n * Default RoughJS options shared by every stroke converter.\n *\n * Per-converter callers may override `roughness` / `bowing` (these vary by\n * annotation type) by passing a `defaults` argument. Other fields are stable\n * across converters and rarely overridden.\n */\nconst SHARED_ROUGH_DEFAULTS = Object.freeze({\n roughness: 1.0,\n bowing: 1.0,\n curveFitting: 0.95,\n curveStepCount: 9,\n maxRandomnessOffset: 2,\n disableMultiStroke: false,\n});\n\n/**\n * Build a RoughJS options object from the resolved `style` and a seed key.\n *\n * Replaces the 6-line boilerplate that previously lived in each converter:\n *\n * const roughness = style.roughness ?? 1.0;\n * const bowing = style.bowing ?? 1.0;\n * const curveFitting = style.curveFitting ?? 0.95;\n * ... (4 more)\n *\n * @param {Object} style - Resolved style (caller already merged config + annotation.style)\n * @param {string} seedKey - Seed source string (hashed via hashSeed)\n * @param {Object} [defaults] - Per-converter default overrides (roughness/bowing typically)\n * @returns {Object} Options object ready to pass to roughLine / roughEllipse\n */\nexport function buildRoughOptions(style, seedKey, defaults = {}) {\n const merged = { ...SHARED_ROUGH_DEFAULTS, ...defaults };\n return {\n roughness: style.roughness ?? merged.roughness,\n bowing: style.bowing ?? merged.bowing,\n curveFitting: style.curveFitting ?? merged.curveFitting,\n curveStepCount: style.curveStepCount ?? merged.curveStepCount,\n maxRandomnessOffset: style.maxRandomnessOffset ?? merged.maxRandomnessOffset,\n disableMultiStroke: style.disableMultiStroke ?? merged.disableMultiStroke,\n seed: hashSeed(seedKey),\n };\n}\n\n/**\n * Resolve the stroke color from the (already merged) style, falling back to\n * the converter-specific default when `style.color` is absent.\n *\n * Once `config/defaults.js` is the single source of truth (R12) the fallback\n * argument here can be dropped at call sites; until then it preserves\n * v0.6.x behavior.\n *\n * @param {Object} style - Resolved style\n * @param {string} fallback - Converter-specific fallback color\n * @returns {string} Color string\n */\nexport function resolveColor(style, fallback) {\n return style.color || fallback;\n}\n"],"names":["SHARED_ROUGH_DEFAULTS","buildRoughOptions","style","seedKey","defaults","merged","hashSeed","resolveColor","fallback"],"mappings":"iHAkBMA,EAAwB,OAAO,OAAO,CAC1C,UAAW,EACX,OAAQ,EACR,aAAc,IACd,eAAgB,EAChB,oBAAqB,EACrB,mBAAoB,EACtB,CAAC,EAiBM,SAASC,EAAkBC,EAAOC,EAASC,EAAW,CAAA,EAAI,CAC/D,MAAMC,EAAS,CAAE,GAAGL,EAAuB,GAAGI,CAAQ,EACtD,MAAO,CACL,UAAWF,EAAM,WAAaG,EAAO,UACrC,OAAQH,EAAM,QAAUG,EAAO,OAC/B,aAAcH,EAAM,cAAgBG,EAAO,aAC3C,eAAgBH,EAAM,gBAAkBG,EAAO,eAC/C,oBAAqBH,EAAM,qBAAuBG,EAAO,oBACzD,mBAAoBH,EAAM,oBAAsBG,EAAO,mBACvD,KAAMC,EAAAA,SAASH,CAAO,CAC1B,CACA,CAcO,SAASI,EAAaL,EAAOM,EAAU,CAC5C,OAAON,EAAM,OAASM,CACxB"}
|
package/dist/index29.js
CHANGED
|
@@ -1,74 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { hashSeed as r } from "./index28.js";
|
|
2
|
+
const s = Object.freeze({
|
|
3
|
+
roughness: 1,
|
|
4
|
+
bowing: 1,
|
|
5
|
+
curveFitting: 0.95,
|
|
6
|
+
curveStepCount: 9,
|
|
7
|
+
maxRandomnessOffset: 2,
|
|
8
|
+
disableMultiStroke: !1
|
|
9
|
+
});
|
|
10
|
+
function i(e, n, t = {}) {
|
|
11
|
+
const o = { ...s, ...t };
|
|
12
|
+
return {
|
|
13
|
+
roughness: e.roughness ?? o.roughness,
|
|
14
|
+
bowing: e.bowing ?? o.bowing,
|
|
15
|
+
curveFitting: e.curveFitting ?? o.curveFitting,
|
|
16
|
+
curveStepCount: e.curveStepCount ?? o.curveStepCount,
|
|
17
|
+
maxRandomnessOffset: e.maxRandomnessOffset ?? o.maxRandomnessOffset,
|
|
18
|
+
disableMultiStroke: e.disableMultiStroke ?? o.disableMultiStroke,
|
|
19
|
+
seed: r(n)
|
|
20
|
+
};
|
|
9
21
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let n = [0, 0];
|
|
13
|
-
for (const { op: a, data: e } of r)
|
|
14
|
-
switch (a) {
|
|
15
|
-
case "move":
|
|
16
|
-
n = [e[0], e[1]], t.push([...n]);
|
|
17
|
-
break;
|
|
18
|
-
case "lineTo":
|
|
19
|
-
n = [e[0], e[1]], t.push([...n]);
|
|
20
|
-
break;
|
|
21
|
-
case "bcurveTo": {
|
|
22
|
-
const [s, f, h, d, u, c] = e, g = n, b = [s, f], m = [h, d], v = [u, c];
|
|
23
|
-
for (let o = 0.25; o <= 1; o += 0.25)
|
|
24
|
-
t.push(M(g, b, m, v, o));
|
|
25
|
-
n = [u, c];
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return t;
|
|
30
|
-
}
|
|
31
|
-
function l(r) {
|
|
32
|
-
const t = [];
|
|
33
|
-
for (const n of r.sets)
|
|
34
|
-
n.type === "path" && t.push(...S(n.ops));
|
|
35
|
-
return t;
|
|
36
|
-
}
|
|
37
|
-
function w(r) {
|
|
38
|
-
let t = 0;
|
|
39
|
-
for (let n = 0; n < r.length; n++)
|
|
40
|
-
t = (t << 5) - t + r.charCodeAt(n), t |= 0;
|
|
41
|
-
return Math.abs(t);
|
|
42
|
-
}
|
|
43
|
-
function C(r, t, n, a, e = {}) {
|
|
44
|
-
const s = i.line(r, t, n, a, {
|
|
45
|
-
roughness: e.roughness ?? 1,
|
|
46
|
-
bowing: e.bowing ?? 1,
|
|
47
|
-
seed: e.seed ?? Math.floor(Math.random() * 2147483648),
|
|
48
|
-
curveFitting: e.curveFitting ?? 0.95,
|
|
49
|
-
curveStepCount: e.curveStepCount ?? 9,
|
|
50
|
-
maxRandomnessOffset: e.maxRandomnessOffset ?? 2,
|
|
51
|
-
disableMultiStroke: e.disableMultiStroke ?? !1,
|
|
52
|
-
...e
|
|
53
|
-
});
|
|
54
|
-
return l(s);
|
|
55
|
-
}
|
|
56
|
-
function p(r, t, n, a, e = {}) {
|
|
57
|
-
const s = i.ellipse(r, t, n, a, {
|
|
58
|
-
roughness: e.roughness ?? 1,
|
|
59
|
-
bowing: e.bowing ?? 1,
|
|
60
|
-
seed: e.seed ?? Math.floor(Math.random() * 2147483648),
|
|
61
|
-
curveFitting: e.curveFitting ?? 0.95,
|
|
62
|
-
curveStepCount: e.curveStepCount ?? 9,
|
|
63
|
-
maxRandomnessOffset: e.maxRandomnessOffset ?? 2,
|
|
64
|
-
disableMultiStroke: e.disableMultiStroke ?? !1,
|
|
65
|
-
...e
|
|
66
|
-
});
|
|
67
|
-
return l(s);
|
|
22
|
+
function a(e, n) {
|
|
23
|
+
return e.color || n;
|
|
68
24
|
}
|
|
69
25
|
export {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
C as roughLine
|
|
26
|
+
i as buildRoughOptions,
|
|
27
|
+
a as resolveColor
|
|
73
28
|
};
|
|
74
29
|
//# sourceMappingURL=index29.js.map
|
package/dist/index29.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index29.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index29.js","sources":["../src/converters/_shared.js"],"sourcesContent":["/**\n * Shared helpers for converters\n *\n * Centralizes the RoughJS option boilerplate and color fallback resolution\n * shared across highlight / underline / circle / arrow converters.\n *\n * @module converters/_shared\n */\n\nimport { hashSeed } from '../rough/roughPathExtractor.js';\n\n/**\n * Default RoughJS options shared by every stroke converter.\n *\n * Per-converter callers may override `roughness` / `bowing` (these vary by\n * annotation type) by passing a `defaults` argument. Other fields are stable\n * across converters and rarely overridden.\n */\nconst SHARED_ROUGH_DEFAULTS = Object.freeze({\n roughness: 1.0,\n bowing: 1.0,\n curveFitting: 0.95,\n curveStepCount: 9,\n maxRandomnessOffset: 2,\n disableMultiStroke: false,\n});\n\n/**\n * Build a RoughJS options object from the resolved `style` and a seed key.\n *\n * Replaces the 6-line boilerplate that previously lived in each converter:\n *\n * const roughness = style.roughness ?? 1.0;\n * const bowing = style.bowing ?? 1.0;\n * const curveFitting = style.curveFitting ?? 0.95;\n * ... (4 more)\n *\n * @param {Object} style - Resolved style (caller already merged config + annotation.style)\n * @param {string} seedKey - Seed source string (hashed via hashSeed)\n * @param {Object} [defaults] - Per-converter default overrides (roughness/bowing typically)\n * @returns {Object} Options object ready to pass to roughLine / roughEllipse\n */\nexport function buildRoughOptions(style, seedKey, defaults = {}) {\n const merged = { ...SHARED_ROUGH_DEFAULTS, ...defaults };\n return {\n roughness: style.roughness ?? merged.roughness,\n bowing: style.bowing ?? merged.bowing,\n curveFitting: style.curveFitting ?? merged.curveFitting,\n curveStepCount: style.curveStepCount ?? merged.curveStepCount,\n maxRandomnessOffset: style.maxRandomnessOffset ?? merged.maxRandomnessOffset,\n disableMultiStroke: style.disableMultiStroke ?? merged.disableMultiStroke,\n seed: hashSeed(seedKey),\n };\n}\n\n/**\n * Resolve the stroke color from the (already merged) style, falling back to\n * the converter-specific default when `style.color` is absent.\n *\n * Once `config/defaults.js` is the single source of truth (R12) the fallback\n * argument here can be dropped at call sites; until then it preserves\n * v0.6.x behavior.\n *\n * @param {Object} style - Resolved style\n * @param {string} fallback - Converter-specific fallback color\n * @returns {string} Color string\n */\nexport function resolveColor(style, fallback) {\n return style.color || fallback;\n}\n"],"names":["SHARED_ROUGH_DEFAULTS","buildRoughOptions","style","seedKey","defaults","merged","hashSeed","resolveColor","fallback"],"mappings":";AAkBA,MAAMA,IAAwB,OAAO,OAAO;AAAA,EAC1C,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,qBAAqB;AAAA,EACrB,oBAAoB;AACtB,CAAC;AAiBM,SAASC,EAAkBC,GAAOC,GAASC,IAAW,CAAA,GAAI;AAC/D,QAAMC,IAAS,EAAE,GAAGL,GAAuB,GAAGI,EAAQ;AACtD,SAAO;AAAA,IACL,WAAWF,EAAM,aAAaG,EAAO;AAAA,IACrC,QAAQH,EAAM,UAAUG,EAAO;AAAA,IAC/B,cAAcH,EAAM,gBAAgBG,EAAO;AAAA,IAC3C,gBAAgBH,EAAM,kBAAkBG,EAAO;AAAA,IAC/C,qBAAqBH,EAAM,uBAAuBG,EAAO;AAAA,IACzD,oBAAoBH,EAAM,sBAAsBG,EAAO;AAAA,IACvD,MAAMC,EAASH,CAAO;AAAA,EAC1B;AACA;AAcO,SAASI,EAAaL,GAAOM,GAAU;AAC5C,SAAON,EAAM,SAASM;AACxB;"}
|
package/dist/index3.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("pdfjs-dist"),u=require("./index8.cjs");function f(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(r,e,t.get?t:{enumerable:!0,get:()=>s[e]})}}return r.default=s,Object.freeze(r)}const h=f(l);class g{constructor(){this.pdfDoc=null,this.renderTask=null}async loadDocument(r){try{if(!r||typeof r!="string")return{success:!1,error:"Invalid PDF URL provided"};const t=await h.getDocument(r).promise;return this.pdfDoc=t,{success:!0,pageCount:t.numPages}}catch(e){return console.error("PDF loading error:",e),{success:!1,error:`Failed to load PDF: ${e.message}`}}}async renderPage(r,e,t){try{if(!this.pdfDoc)return{success:!1,error:"No PDF document loaded"};if(!e||!(e instanceof HTMLCanvasElement))return{success:!1,error:"Invalid canvas element provided"};if(r<1||r>this.pdfDoc.numPages)return{success:!1,error:`Invalid page number: ${r}. Document has ${this.pdfDoc.numPages} pages.`};this.renderTask&&(this.renderTask.cancel(),this.renderTask=null);const n=await this.pdfDoc.getPage(r),o=u.calculateViewport(n,t),i=typeof window<"u"&&window.devicePixelRatio||1;e.width=Math.floor(o.width*i),e.height=Math.floor(o.height*i),e.style.width=`${o.width}px`,e.style.height=`${o.height}px`;const c=e.getContext("2d");if(!c)return{success:!1,error:"Failed to get canvas 2d context"};const a=n.getViewport({scale:t*i}),d={canvasContext:c,viewport:a};return this.renderTask=n.render(d),await this.renderTask.promise,this.renderTask=null,{success:!0,viewport:o}}catch(n){return n.name==="RenderingCancelledException"?(console.log("Rendering cancelled"),{success:!1,error:"Rendering was cancelled"}):(console.error("Page rendering error:",n),{success:!1,error:`Failed to render page: ${n.message}`})}finally{this.renderTask=null}}getPageCount(){return this.pdfDoc?this.pdfDoc.numPages:0}cancelRender(){if(this.renderTask)try{this.renderTask.cancel()}catch(r){console.log("Render cancellation error (ignored):",r)}finally{this.renderTask=null}}destroy(){this.cancelRender(),this.pdfDoc&&(this.pdfDoc=null),this.renderTask=null}}exports.PDFRenderer=g;
|
|
2
2
|
//# sourceMappingURL=index3.cjs.map
|
package/dist/index3.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index3.cjs","sources":["../src/core/PDFRenderer.js"],"sourcesContent":["/**\n * PDFRenderer - Framework-agnostic PDF rendering subsystem\n *\n * This module encapsulates all pdf.js operations including document loading,\n * page rendering, viewport calculations, and rendering task management.\n *\n * @module core/PDFRenderer\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\nimport { calculateViewport } from \"../utils/viewportUtils.js\";\n\n/**\n * PDFRenderer class\n *\n * Provides framework-agnostic PDF rendering capabilities.\n * Abstracts pdf.js complexity and provides clean interface for engine.\n *\n * @class\n * @example\n * const renderer = new PDFRenderer();\n * await renderer.loadDocument('/path/to/doc.pdf');\n * const result = await renderer.renderPage(1, canvasElement, 1.5);\n */\nexport class PDFRenderer {\n constructor() {\n /**\n * @private\n * @type {PDFDocumentProxy|null}\n */\n this.pdfDoc = null;\n\n /**\n * @private\n * @type {RenderTask|null}\n */\n this.renderTask = null;\n }\n\n /**\n * Load PDF document from URL\n *\n * @param {string} url - URL or path to PDF file\n * @returns {Promise<{success: boolean, pageCount?: number, error?: string}>}\n */\n async loadDocument(url) {\n try {\n if (!url || typeof url !== \"string\") {\n return {\n success: false,\n error: \"Invalid PDF URL provided\",\n };\n }\n\n const loadingTask = pdfjsLib.getDocument(url);\n const pdf = await loadingTask.promise;\n\n this.pdfDoc = pdf;\n\n return {\n success: true,\n pageCount: pdf.numPages,\n };\n } catch (err) {\n console.error(\"PDF loading error:\", err);\n return {\n success: false,\n error: `Failed to load PDF: ${err.message}`,\n };\n }\n }\n\n /**\n * Render PDF page to canvas element\n *\n * @param {number} pageNum - Page number (1-indexed)\n * @param {HTMLCanvasElement} canvas - Canvas element to render to\n * @param {number} scale - Scale factor for rendering\n * @returns {Promise<{success: boolean, viewport?: Object, error?: string}>}\n */\n async renderPage(pageNum, canvas, scale) {\n try {\n if (!this.pdfDoc) {\n return {\n success: false,\n error: \"No PDF document loaded\",\n };\n }\n\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n return {\n success: false,\n error: \"Invalid canvas element provided\",\n };\n }\n\n if (pageNum < 1 || pageNum > this.pdfDoc.numPages) {\n return {\n success: false,\n error: `Invalid page number: ${pageNum}. Document has ${this.pdfDoc.numPages} pages.`,\n };\n }\n\n // Cancel any in-progress rendering\n if (this.renderTask) {\n this.renderTask.cancel();\n this.renderTask = null;\n }\n\n const page = await this.pdfDoc.getPage(pageNum);\n const viewport = calculateViewport(page, scale);\n\n canvas.width = viewport.width;\n canvas.height = viewport.height;\n\n const context = canvas.getContext(\"2d\");\n if (!context) {\n return {\n success: false,\n error: \"Failed to get canvas 2d context\",\n };\n }\n\n const renderContext = {\n canvasContext: context,\n viewport:
|
|
1
|
+
{"version":3,"file":"index3.cjs","sources":["../src/core/PDFRenderer.js"],"sourcesContent":["/**\n * PDFRenderer - Framework-agnostic PDF rendering subsystem\n *\n * This module encapsulates all pdf.js operations including document loading,\n * page rendering, viewport calculations, and rendering task management.\n *\n * @module core/PDFRenderer\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\nimport { calculateViewport } from \"../utils/viewportUtils.js\";\n\n/**\n * PDFRenderer class\n *\n * Provides framework-agnostic PDF rendering capabilities.\n * Abstracts pdf.js complexity and provides clean interface for engine.\n *\n * @class\n * @example\n * const renderer = new PDFRenderer();\n * await renderer.loadDocument('/path/to/doc.pdf');\n * const result = await renderer.renderPage(1, canvasElement, 1.5);\n */\nexport class PDFRenderer {\n constructor() {\n /**\n * @private\n * @type {PDFDocumentProxy|null}\n */\n this.pdfDoc = null;\n\n /**\n * @private\n * @type {RenderTask|null}\n */\n this.renderTask = null;\n }\n\n /**\n * Load PDF document from URL\n *\n * @param {string} url - URL or path to PDF file\n * @returns {Promise<{success: boolean, pageCount?: number, error?: string}>}\n */\n async loadDocument(url) {\n try {\n if (!url || typeof url !== \"string\") {\n return {\n success: false,\n error: \"Invalid PDF URL provided\",\n };\n }\n\n const loadingTask = pdfjsLib.getDocument(url);\n const pdf = await loadingTask.promise;\n\n this.pdfDoc = pdf;\n\n return {\n success: true,\n pageCount: pdf.numPages,\n };\n } catch (err) {\n console.error(\"PDF loading error:\", err);\n return {\n success: false,\n error: `Failed to load PDF: ${err.message}`,\n };\n }\n }\n\n /**\n * Render PDF page to canvas element\n *\n * @param {number} pageNum - Page number (1-indexed)\n * @param {HTMLCanvasElement} canvas - Canvas element to render to\n * @param {number} scale - Scale factor for rendering\n * @returns {Promise<{success: boolean, viewport?: Object, error?: string}>}\n */\n async renderPage(pageNum, canvas, scale) {\n try {\n if (!this.pdfDoc) {\n return {\n success: false,\n error: \"No PDF document loaded\",\n };\n }\n\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n return {\n success: false,\n error: \"Invalid canvas element provided\",\n };\n }\n\n if (pageNum < 1 || pageNum > this.pdfDoc.numPages) {\n return {\n success: false,\n error: `Invalid page number: ${pageNum}. Document has ${this.pdfDoc.numPages} pages.`,\n };\n }\n\n // Cancel any in-progress rendering\n if (this.renderTask) {\n this.renderTask.cancel();\n this.renderTask = null;\n }\n\n const page = await this.pdfDoc.getPage(pageNum);\n\n // CSS-pixel viewport — what the layout (and StrokeRenderer overlay) sees.\n const viewport = calculateViewport(page, scale);\n\n // HiDPI / retina support: upscale the canvas pixel buffer by DPR so the\n // rendered PDF is sharp on high-density displays. Display size stays in\n // CSS pixels so it lines up with the StrokeRenderer overlay (which\n // applies its own DPR internally — see StrokeRenderer.setViewport).\n const dpr = (typeof window !== \"undefined\" && window.devicePixelRatio) || 1;\n\n canvas.width = Math.floor(viewport.width * dpr);\n canvas.height = Math.floor(viewport.height * dpr);\n canvas.style.width = `${viewport.width}px`;\n canvas.style.height = `${viewport.height}px`;\n\n const context = canvas.getContext(\"2d\");\n if (!context) {\n return {\n success: false,\n error: \"Failed to get canvas 2d context\",\n };\n }\n\n // Render at the upscaled resolution so pdf.js fills the full pixel buffer.\n const renderViewport = page.getViewport({ scale: scale * dpr });\n\n const renderContext = {\n canvasContext: context,\n viewport: renderViewport,\n };\n\n this.renderTask = page.render(renderContext);\n await this.renderTask.promise;\n\n this.renderTask = null;\n\n // Return the CSS-pixel viewport — AnnotationRenderer.setPage forwards\n // these dimensions to StrokeRenderer.setViewport, which applies DPR\n // itself. Returning `renderViewport` here would double-apply DPR.\n return {\n success: true,\n viewport: viewport,\n };\n } catch (err) {\n if (err.name === \"RenderingCancelledException\") {\n console.log(\"Rendering cancelled\");\n return {\n success: false,\n error: \"Rendering was cancelled\",\n };\n }\n\n console.error(\"Page rendering error:\", err);\n return {\n success: false,\n error: `Failed to render page: ${err.message}`,\n };\n } finally {\n this.renderTask = null;\n }\n }\n\n /**\n * Get total number of pages in loaded PDF\n *\n * @returns {number} Page count, or 0 if no document loaded\n */\n getPageCount() {\n return this.pdfDoc ? this.pdfDoc.numPages : 0;\n }\n\n /**\n * Cancel current rendering task if active\n *\n * @returns {void}\n */\n cancelRender() {\n if (this.renderTask) {\n try {\n this.renderTask.cancel();\n } catch (err) {\n console.log(\"Render cancellation error (ignored):\", err);\n } finally {\n this.renderTask = null;\n }\n }\n }\n\n /**\n * Clean up resources and release references\n *\n * @returns {void}\n */\n destroy() {\n this.cancelRender();\n\n if (this.pdfDoc) {\n this.pdfDoc = null;\n }\n\n this.renderTask = null;\n }\n}\n"],"names":["PDFRenderer","url","pdf","pdfjsLib","err","pageNum","canvas","scale","page","viewport","calculateViewport","dpr","context","renderViewport","renderContext"],"mappings":"kaAwBO,MAAMA,CAAY,CACvB,aAAc,CAKZ,KAAK,OAAS,KAMd,KAAK,WAAa,IACpB,CAQA,MAAM,aAAaC,EAAK,CACtB,GAAI,CACF,GAAI,CAACA,GAAO,OAAOA,GAAQ,SACzB,MAAO,CACL,QAAS,GACT,MAAO,0BACjB,EAIM,MAAMC,EAAM,MADQC,EAAS,YAAYF,CAAG,EACd,QAE9B,YAAK,OAASC,EAEP,CACL,QAAS,GACT,UAAWA,EAAI,QACvB,CACI,OAASE,EAAK,CACZ,eAAQ,MAAM,qBAAsBA,CAAG,EAChC,CACL,QAAS,GACT,MAAO,uBAAuBA,EAAI,OAAO,EACjD,CACI,CACF,CAUA,MAAM,WAAWC,EAASC,EAAQC,EAAO,CACvC,GAAI,CACF,GAAI,CAAC,KAAK,OACR,MAAO,CACL,QAAS,GACT,MAAO,wBACjB,EAGM,GAAI,CAACD,GAAU,EAAEA,aAAkB,mBACjC,MAAO,CACL,QAAS,GACT,MAAO,iCACjB,EAGM,GAAID,EAAU,GAAKA,EAAU,KAAK,OAAO,SACvC,MAAO,CACL,QAAS,GACT,MAAO,wBAAwBA,CAAO,kBAAkB,KAAK,OAAO,QAAQ,SACtF,EAIU,KAAK,aACP,KAAK,WAAW,OAAM,EACtB,KAAK,WAAa,MAGpB,MAAMG,EAAO,MAAM,KAAK,OAAO,QAAQH,CAAO,EAGxCI,EAAWC,EAAAA,kBAAkBF,EAAMD,CAAK,EAMxCI,EAAO,OAAO,OAAW,KAAe,OAAO,kBAAqB,EAE1EL,EAAO,MAAQ,KAAK,MAAMG,EAAS,MAAQE,CAAG,EAC9CL,EAAO,OAAS,KAAK,MAAMG,EAAS,OAASE,CAAG,EAChDL,EAAO,MAAM,MAAQ,GAAGG,EAAS,KAAK,KACtCH,EAAO,MAAM,OAAS,GAAGG,EAAS,MAAM,KAExC,MAAMG,EAAUN,EAAO,WAAW,IAAI,EACtC,GAAI,CAACM,EACH,MAAO,CACL,QAAS,GACT,MAAO,iCACjB,EAIM,MAAMC,EAAiBL,EAAK,YAAY,CAAE,MAAOD,EAAQI,EAAK,EAExDG,EAAgB,CACpB,cAAeF,EACf,SAAUC,CAClB,EAEM,YAAK,WAAaL,EAAK,OAAOM,CAAa,EAC3C,MAAM,KAAK,WAAW,QAEtB,KAAK,WAAa,KAKX,CACL,QAAS,GACT,SAAUL,CAClB,CACI,OAASL,EAAK,CACZ,OAAIA,EAAI,OAAS,+BACf,QAAQ,IAAI,qBAAqB,EAC1B,CACL,QAAS,GACT,MAAO,yBACjB,IAGM,QAAQ,MAAM,wBAAyBA,CAAG,EACnC,CACL,QAAS,GACT,MAAO,0BAA0BA,EAAI,OAAO,EACpD,EACI,QAAC,CACC,KAAK,WAAa,IACpB,CACF,CAOA,cAAe,CACb,OAAO,KAAK,OAAS,KAAK,OAAO,SAAW,CAC9C,CAOA,cAAe,CACb,GAAI,KAAK,WACP,GAAI,CACF,KAAK,WAAW,OAAM,CACxB,OAASA,EAAK,CACZ,QAAQ,IAAI,uCAAwCA,CAAG,CACzD,QAAC,CACC,KAAK,WAAa,IACpB,CAEJ,CAOA,SAAU,CACR,KAAK,aAAY,EAEb,KAAK,SACP,KAAK,OAAS,MAGhB,KAAK,WAAa,IACpB,CACF"}
|
package/dist/index3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { calculateViewport as
|
|
3
|
-
class
|
|
1
|
+
import * as d from "pdfjs-dist";
|
|
2
|
+
import { calculateViewport as l } from "./index8.js";
|
|
3
|
+
class f {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.pdfDoc = null, this.renderTask = null;
|
|
6
6
|
}
|
|
@@ -10,22 +10,22 @@ class u {
|
|
|
10
10
|
* @param {string} url - URL or path to PDF file
|
|
11
11
|
* @returns {Promise<{success: boolean, pageCount?: number, error?: string}>}
|
|
12
12
|
*/
|
|
13
|
-
async loadDocument(
|
|
13
|
+
async loadDocument(r) {
|
|
14
14
|
try {
|
|
15
|
-
if (!
|
|
15
|
+
if (!r || typeof r != "string")
|
|
16
16
|
return {
|
|
17
17
|
success: !1,
|
|
18
18
|
error: "Invalid PDF URL provided"
|
|
19
19
|
};
|
|
20
|
-
const
|
|
21
|
-
return this.pdfDoc =
|
|
20
|
+
const s = await d.getDocument(r).promise;
|
|
21
|
+
return this.pdfDoc = s, {
|
|
22
22
|
success: !0,
|
|
23
|
-
pageCount:
|
|
23
|
+
pageCount: s.numPages
|
|
24
24
|
};
|
|
25
|
-
} catch (
|
|
26
|
-
return console.error("PDF loading error:",
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return console.error("PDF loading error:", e), {
|
|
27
27
|
success: !1,
|
|
28
|
-
error: `Failed to load PDF: ${
|
|
28
|
+
error: `Failed to load PDF: ${e.message}`
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -37,47 +37,47 @@ class u {
|
|
|
37
37
|
* @param {number} scale - Scale factor for rendering
|
|
38
38
|
* @returns {Promise<{success: boolean, viewport?: Object, error?: string}>}
|
|
39
39
|
*/
|
|
40
|
-
async renderPage(
|
|
40
|
+
async renderPage(r, e, s) {
|
|
41
41
|
try {
|
|
42
42
|
if (!this.pdfDoc)
|
|
43
43
|
return {
|
|
44
44
|
success: !1,
|
|
45
45
|
error: "No PDF document loaded"
|
|
46
46
|
};
|
|
47
|
-
if (!
|
|
47
|
+
if (!e || !(e instanceof HTMLCanvasElement))
|
|
48
48
|
return {
|
|
49
49
|
success: !1,
|
|
50
50
|
error: "Invalid canvas element provided"
|
|
51
51
|
};
|
|
52
|
-
if (
|
|
52
|
+
if (r < 1 || r > this.pdfDoc.numPages)
|
|
53
53
|
return {
|
|
54
54
|
success: !1,
|
|
55
|
-
error: `Invalid page number: ${
|
|
55
|
+
error: `Invalid page number: ${r}. Document has ${this.pdfDoc.numPages} pages.`
|
|
56
56
|
};
|
|
57
57
|
this.renderTask && (this.renderTask.cancel(), this.renderTask = null);
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
58
|
+
const t = await this.pdfDoc.getPage(r), n = l(t, s), o = typeof window < "u" && window.devicePixelRatio || 1;
|
|
59
|
+
e.width = Math.floor(n.width * o), e.height = Math.floor(n.height * o), e.style.width = `${n.width}px`, e.style.height = `${n.height}px`;
|
|
60
|
+
const i = e.getContext("2d");
|
|
61
|
+
if (!i)
|
|
62
62
|
return {
|
|
63
63
|
success: !1,
|
|
64
64
|
error: "Failed to get canvas 2d context"
|
|
65
65
|
};
|
|
66
|
-
const a = {
|
|
67
|
-
canvasContext:
|
|
68
|
-
viewport:
|
|
66
|
+
const c = t.getViewport({ scale: s * o }), a = {
|
|
67
|
+
canvasContext: i,
|
|
68
|
+
viewport: c
|
|
69
69
|
};
|
|
70
|
-
return this.renderTask =
|
|
70
|
+
return this.renderTask = t.render(a), await this.renderTask.promise, this.renderTask = null, {
|
|
71
71
|
success: !0,
|
|
72
|
-
viewport:
|
|
72
|
+
viewport: n
|
|
73
73
|
};
|
|
74
|
-
} catch (
|
|
75
|
-
return
|
|
74
|
+
} catch (t) {
|
|
75
|
+
return t.name === "RenderingCancelledException" ? (console.log("Rendering cancelled"), {
|
|
76
76
|
success: !1,
|
|
77
77
|
error: "Rendering was cancelled"
|
|
78
|
-
}) : (console.error("Page rendering error:",
|
|
78
|
+
}) : (console.error("Page rendering error:", t), {
|
|
79
79
|
success: !1,
|
|
80
|
-
error: `Failed to render page: ${
|
|
80
|
+
error: `Failed to render page: ${t.message}`
|
|
81
81
|
});
|
|
82
82
|
} finally {
|
|
83
83
|
this.renderTask = null;
|
|
@@ -100,8 +100,8 @@ class u {
|
|
|
100
100
|
if (this.renderTask)
|
|
101
101
|
try {
|
|
102
102
|
this.renderTask.cancel();
|
|
103
|
-
} catch (
|
|
104
|
-
console.log("Render cancellation error (ignored):",
|
|
103
|
+
} catch (r) {
|
|
104
|
+
console.log("Render cancellation error (ignored):", r);
|
|
105
105
|
} finally {
|
|
106
106
|
this.renderTask = null;
|
|
107
107
|
}
|
|
@@ -116,6 +116,6 @@ class u {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
export {
|
|
119
|
-
|
|
119
|
+
f as PDFRenderer
|
|
120
120
|
};
|
|
121
121
|
//# sourceMappingURL=index3.js.map
|
package/dist/index3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index3.js","sources":["../src/core/PDFRenderer.js"],"sourcesContent":["/**\n * PDFRenderer - Framework-agnostic PDF rendering subsystem\n *\n * This module encapsulates all pdf.js operations including document loading,\n * page rendering, viewport calculations, and rendering task management.\n *\n * @module core/PDFRenderer\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\nimport { calculateViewport } from \"../utils/viewportUtils.js\";\n\n/**\n * PDFRenderer class\n *\n * Provides framework-agnostic PDF rendering capabilities.\n * Abstracts pdf.js complexity and provides clean interface for engine.\n *\n * @class\n * @example\n * const renderer = new PDFRenderer();\n * await renderer.loadDocument('/path/to/doc.pdf');\n * const result = await renderer.renderPage(1, canvasElement, 1.5);\n */\nexport class PDFRenderer {\n constructor() {\n /**\n * @private\n * @type {PDFDocumentProxy|null}\n */\n this.pdfDoc = null;\n\n /**\n * @private\n * @type {RenderTask|null}\n */\n this.renderTask = null;\n }\n\n /**\n * Load PDF document from URL\n *\n * @param {string} url - URL or path to PDF file\n * @returns {Promise<{success: boolean, pageCount?: number, error?: string}>}\n */\n async loadDocument(url) {\n try {\n if (!url || typeof url !== \"string\") {\n return {\n success: false,\n error: \"Invalid PDF URL provided\",\n };\n }\n\n const loadingTask = pdfjsLib.getDocument(url);\n const pdf = await loadingTask.promise;\n\n this.pdfDoc = pdf;\n\n return {\n success: true,\n pageCount: pdf.numPages,\n };\n } catch (err) {\n console.error(\"PDF loading error:\", err);\n return {\n success: false,\n error: `Failed to load PDF: ${err.message}`,\n };\n }\n }\n\n /**\n * Render PDF page to canvas element\n *\n * @param {number} pageNum - Page number (1-indexed)\n * @param {HTMLCanvasElement} canvas - Canvas element to render to\n * @param {number} scale - Scale factor for rendering\n * @returns {Promise<{success: boolean, viewport?: Object, error?: string}>}\n */\n async renderPage(pageNum, canvas, scale) {\n try {\n if (!this.pdfDoc) {\n return {\n success: false,\n error: \"No PDF document loaded\",\n };\n }\n\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n return {\n success: false,\n error: \"Invalid canvas element provided\",\n };\n }\n\n if (pageNum < 1 || pageNum > this.pdfDoc.numPages) {\n return {\n success: false,\n error: `Invalid page number: ${pageNum}. Document has ${this.pdfDoc.numPages} pages.`,\n };\n }\n\n // Cancel any in-progress rendering\n if (this.renderTask) {\n this.renderTask.cancel();\n this.renderTask = null;\n }\n\n const page = await this.pdfDoc.getPage(pageNum);\n const viewport = calculateViewport(page, scale);\n\n canvas.width = viewport.width;\n canvas.height = viewport.height;\n\n const context = canvas.getContext(\"2d\");\n if (!context) {\n return {\n success: false,\n error: \"Failed to get canvas 2d context\",\n };\n }\n\n const renderContext = {\n canvasContext: context,\n viewport:
|
|
1
|
+
{"version":3,"file":"index3.js","sources":["../src/core/PDFRenderer.js"],"sourcesContent":["/**\n * PDFRenderer - Framework-agnostic PDF rendering subsystem\n *\n * This module encapsulates all pdf.js operations including document loading,\n * page rendering, viewport calculations, and rendering task management.\n *\n * @module core/PDFRenderer\n */\n\nimport * as pdfjsLib from \"pdfjs-dist\";\nimport { calculateViewport } from \"../utils/viewportUtils.js\";\n\n/**\n * PDFRenderer class\n *\n * Provides framework-agnostic PDF rendering capabilities.\n * Abstracts pdf.js complexity and provides clean interface for engine.\n *\n * @class\n * @example\n * const renderer = new PDFRenderer();\n * await renderer.loadDocument('/path/to/doc.pdf');\n * const result = await renderer.renderPage(1, canvasElement, 1.5);\n */\nexport class PDFRenderer {\n constructor() {\n /**\n * @private\n * @type {PDFDocumentProxy|null}\n */\n this.pdfDoc = null;\n\n /**\n * @private\n * @type {RenderTask|null}\n */\n this.renderTask = null;\n }\n\n /**\n * Load PDF document from URL\n *\n * @param {string} url - URL or path to PDF file\n * @returns {Promise<{success: boolean, pageCount?: number, error?: string}>}\n */\n async loadDocument(url) {\n try {\n if (!url || typeof url !== \"string\") {\n return {\n success: false,\n error: \"Invalid PDF URL provided\",\n };\n }\n\n const loadingTask = pdfjsLib.getDocument(url);\n const pdf = await loadingTask.promise;\n\n this.pdfDoc = pdf;\n\n return {\n success: true,\n pageCount: pdf.numPages,\n };\n } catch (err) {\n console.error(\"PDF loading error:\", err);\n return {\n success: false,\n error: `Failed to load PDF: ${err.message}`,\n };\n }\n }\n\n /**\n * Render PDF page to canvas element\n *\n * @param {number} pageNum - Page number (1-indexed)\n * @param {HTMLCanvasElement} canvas - Canvas element to render to\n * @param {number} scale - Scale factor for rendering\n * @returns {Promise<{success: boolean, viewport?: Object, error?: string}>}\n */\n async renderPage(pageNum, canvas, scale) {\n try {\n if (!this.pdfDoc) {\n return {\n success: false,\n error: \"No PDF document loaded\",\n };\n }\n\n if (!canvas || !(canvas instanceof HTMLCanvasElement)) {\n return {\n success: false,\n error: \"Invalid canvas element provided\",\n };\n }\n\n if (pageNum < 1 || pageNum > this.pdfDoc.numPages) {\n return {\n success: false,\n error: `Invalid page number: ${pageNum}. Document has ${this.pdfDoc.numPages} pages.`,\n };\n }\n\n // Cancel any in-progress rendering\n if (this.renderTask) {\n this.renderTask.cancel();\n this.renderTask = null;\n }\n\n const page = await this.pdfDoc.getPage(pageNum);\n\n // CSS-pixel viewport — what the layout (and StrokeRenderer overlay) sees.\n const viewport = calculateViewport(page, scale);\n\n // HiDPI / retina support: upscale the canvas pixel buffer by DPR so the\n // rendered PDF is sharp on high-density displays. Display size stays in\n // CSS pixels so it lines up with the StrokeRenderer overlay (which\n // applies its own DPR internally — see StrokeRenderer.setViewport).\n const dpr = (typeof window !== \"undefined\" && window.devicePixelRatio) || 1;\n\n canvas.width = Math.floor(viewport.width * dpr);\n canvas.height = Math.floor(viewport.height * dpr);\n canvas.style.width = `${viewport.width}px`;\n canvas.style.height = `${viewport.height}px`;\n\n const context = canvas.getContext(\"2d\");\n if (!context) {\n return {\n success: false,\n error: \"Failed to get canvas 2d context\",\n };\n }\n\n // Render at the upscaled resolution so pdf.js fills the full pixel buffer.\n const renderViewport = page.getViewport({ scale: scale * dpr });\n\n const renderContext = {\n canvasContext: context,\n viewport: renderViewport,\n };\n\n this.renderTask = page.render(renderContext);\n await this.renderTask.promise;\n\n this.renderTask = null;\n\n // Return the CSS-pixel viewport — AnnotationRenderer.setPage forwards\n // these dimensions to StrokeRenderer.setViewport, which applies DPR\n // itself. Returning `renderViewport` here would double-apply DPR.\n return {\n success: true,\n viewport: viewport,\n };\n } catch (err) {\n if (err.name === \"RenderingCancelledException\") {\n console.log(\"Rendering cancelled\");\n return {\n success: false,\n error: \"Rendering was cancelled\",\n };\n }\n\n console.error(\"Page rendering error:\", err);\n return {\n success: false,\n error: `Failed to render page: ${err.message}`,\n };\n } finally {\n this.renderTask = null;\n }\n }\n\n /**\n * Get total number of pages in loaded PDF\n *\n * @returns {number} Page count, or 0 if no document loaded\n */\n getPageCount() {\n return this.pdfDoc ? this.pdfDoc.numPages : 0;\n }\n\n /**\n * Cancel current rendering task if active\n *\n * @returns {void}\n */\n cancelRender() {\n if (this.renderTask) {\n try {\n this.renderTask.cancel();\n } catch (err) {\n console.log(\"Render cancellation error (ignored):\", err);\n } finally {\n this.renderTask = null;\n }\n }\n }\n\n /**\n * Clean up resources and release references\n *\n * @returns {void}\n */\n destroy() {\n this.cancelRender();\n\n if (this.pdfDoc) {\n this.pdfDoc = null;\n }\n\n this.renderTask = null;\n }\n}\n"],"names":["PDFRenderer","url","pdf","pdfjsLib","err","pageNum","canvas","scale","page","viewport","calculateViewport","dpr","context","renderViewport","renderContext"],"mappings":"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"}
|
package/dist/index5.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("./index24.cjs"),N=require("./index10.cjs"),S=require("./index7.cjs"),W=require("./index19.cjs"),B=require("./index18.cjs"),O=require("./index17.cjs"),H=require("./index16.cjs"),q=require("./index15.cjs"),I=require("./index14.cjs");class C{constructor(t,e={}){if(!t||!(t instanceof HTMLCanvasElement))throw new Error("StrokeRenderer: canvas must be a valid HTMLCanvasElement");this.canvas=t,this.ctx=t.getContext("2d"),this.strokes=[],this.viewport={width:0,height:0},this._strokeCacheByPage=new Map,this._lastAnnotationsRef=null,this.config={};for(const n of p.ANNOTATION_TYPES)this.config[n]={...p.DEFAULT_CONFIG[n]};Object.keys(e).length>0&&this.setConfig(e),this.converters={highlight:I.highlightToStrokes,text:q.textToStrokes,underline:H.underlineToStrokes,arrow:O.arrowToStrokes,circle:B.circleToStrokes,ink:W.inkToStrokes}}setConfig(t){const e={},n={};for(const[s,i]of Object.entries(t))p.ANNOTATION_TYPES.includes(s)?n[s]=i:e[s]=i;for(const s of p.ANNOTATION_TYPES)this.config[s]={...this.config[s],...e,...n[s]||{}};return this._strokeCacheByPage&&this._strokeCacheByPage.clear(),this._lastAnnotationsRef=null,this}registerConverter(t,e){if(typeof e!="function")throw new Error("StrokeRenderer.registerConverter: converter must be a function");this.converters[t]=e}setViewport(t,e){this.viewport={width:t,height:e};const n=window.devicePixelRatio||1;this.canvas.width=t*n,this.canvas.height=e*n,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.ctx.setTransform(n,0,0,n,0,0)}setAnnotations(t,e=null,n={}){if(!Array.isArray(t)){console.warn("StrokeRenderer.setAnnotations: annotations must be an array"),this.strokes=[],this._strokeCacheByPage.clear(),this._lastAnnotationsRef=null;return}const{validate:s=!1,noCache:i=!1}=n;let r=t;if(s&&(r=N.normalizeAnnotationArray(t).normalized),r!==this._lastAnnotationsRef&&(this._strokeCacheByPage.clear(),this._lastAnnotationsRef=r),i){const o=e!==null?r.filter(c=>c.page===e):r;this.strokes=this._convertAnnotations(o);return}if(this._strokeCacheByPage.size===0){const o=new Map;for(const c of r){const h=c&&c.page!=null?c.page:null;let a=o.get(h);a||(a=[],o.set(h,a)),a.push(c)}for(const[c,h]of o)this._strokeCacheByPage.set(c,this._convertAnnotations(h))}if(e!==null)this.strokes=this._strokeCacheByPage.get(e)||[];else{const o=[];for(const c of this._strokeCacheByPage.values())for(const h of c)o.push(h);this.strokes=o}}_convertAnnotations(t){return t.flatMap(e=>{const n=this.converters[e.type];if(!n)return console.warn(`StrokeRenderer: Unknown annotation type "${e.type}"`),[];const s=this._resolveStyle(e);return n(e,s)})}setStrokes(t){if(!Array.isArray(t)){console.warn("StrokeRenderer.setStrokes: strokes must be an array"),this.strokes=[];return}this.strokes=t}render(t){const{ctx:e,viewport:n,strokes:s}=this;e.clearRect(0,0,n.width,n.height);for(const i of s){if(t<i.start)continue;const r=i.end-i.start,o=t-i.start,c=r>0?Math.min(1,o/r):1;this._drawStroke(i,c)}}clear(){this.ctx.clearRect(0,0,this.viewport.width,this.viewport.height)}destroy(){this.strokes=[],this._strokeCacheByPage&&this._strokeCacheByPage.clear(),this._strokeCacheByPage=null,this._lastAnnotationsRef=null,this.ctx=null,this.canvas=null,this.config=null,this.converters=null}_resolveStyle(t){const{type:e}=t;return this.config[e]||{}}_interpolatePoint(t,e,n){return[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n]}_projectPoint(t,e,n,s,i,r){const{viewport:o}=this;if(s)return[i*o.width+t*o.height,r*o.height+e*o.height];if(n)return[t*o.height,e*o.height];const{x:c,y:h}=S.pointNormToAbs({x:t,y:e},o);return[c,h]}_interpolatePressures(t,e,n){const s=t.slice(0,e+1);if(e<t.length-1&&n>0){const i=t[e],r=t[e+1];s.push(i+(r-i)*n)}return s}_drawStroke(t,e){if(t.screenSpaceWing){this._drawScreenSpaceWingStroke(t,e);return}const{ctx:n}=this,{points:s,color:i,width:r,lineCap:o,pressures:c,uniformScale:h,baseX:a,baseY:u}=t;if(!s||s.length<2)return;if(n.strokeStyle=i||"rgba(0, 0, 0, 0.5)",n.lineCap=o||"round",n.lineJoin="round",e>=1){c&&c.length>=s.length?this._drawVariableWidthStroke(s,r,c,h,a,u):this._drawConstantWidthStroke(s,r,h,a,u);return}const d=s.length-1,g=e*d,l=Math.floor(g),f=g-l,k=s.slice(0,l+1);if(l<d&&f>0){const y=s[l],_=s[l+1];k.push(this._interpolatePoint(y,_,f))}if(!(k.length<2))if(c&&c.length>=s.length){const y=this._interpolatePressures(c,l,f);this._drawVariableWidthStroke(k,r,y,h,a,u)}else this._drawConstantWidthStroke(k,r,h,a,u)}_drawConstantWidthStroke(t,e,n=!1,s=null,i=null){const{ctx:r,viewport:o}=this,c=o.height/p.REFERENCE_HEIGHT;r.lineWidth=(e||2)*c,r.beginPath();const h=n&&s!==null&&i!==null;for(let a=0;a<t.length;a++){const[u,d]=t[a],[g,l]=this._projectPoint(u,d,n,h,s,i);a===0?r.moveTo(g,l):r.lineTo(g,l)}r.stroke()}_drawVariableWidthStroke(t,e,n,s=!1,i=null,r=null){const{ctx:o,viewport:c}=this,h=s&&i!==null&&r!==null,a=c.height/p.REFERENCE_HEIGHT;for(let u=1;u<t.length;u++){const[d,g]=t[u-1],[l,f]=t[u],[k,y]=this._projectPoint(d,g,s,h,i,r),[_,w]=this._projectPoint(l,f,s,h,i,r),v=((n[u-1]||1)+(n[u]||1))/2;o.lineWidth=Math.max(.5,e*v)*a,o.beginPath(),o.moveTo(k,y),o.lineTo(_,w),o.stroke()}}_drawScreenSpaceWingStroke(t,e){const{ctx:n,viewport:s}=this,i=t.screenSpaceWing;if(!i)return;const{fromX:r,fromY:o,toX:c,toY:h,wingSide:a}=i,u=typeof i.headAngle=="number"?i.headAngle:Math.PI/6;if(typeof r!="number"||typeof o!="number"||typeof c!="number"||typeof h!="number")return;const d=S.pointNormToAbs({x:c,y:h},s),g=S.pointNormToAbs({x:r,y:o},s),l=d.x,f=d.y,k=g.x,y=g.y,_=l-k,w=f-y,v=Math.sqrt(_*_+w*w);if(v===0)return;const P=Math.min(v*.2,.03*s.height),T=Math.atan2(w,_),E=a==="right"?T+u:T-u,b=l-P*Math.cos(E),x=f-P*Math.sin(E),A=Math.max(0,Math.min(1,e)),R=l+(b-l)*A,m=f+(x-f)*A,M=s.height/p.REFERENCE_HEIGHT;n.strokeStyle=t.color||"rgba(0, 0, 0, 0.5)",n.lineCap=t.lineCap||"round",n.lineJoin="round",n.lineWidth=(t.width||2)*M,n.beginPath(),n.moveTo(l,f),n.lineTo(R,m),n.stroke()}}exports.REFERENCE_HEIGHT=p.REFERENCE_HEIGHT;exports.StrokeRenderer=C;exports.default=C;
|
|
2
2
|
//# sourceMappingURL=index5.cjs.map
|