web-annotation-renderer 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +39 -33
  4. package/dist/index.js.map +1 -1
  5. package/dist/index10.cjs +1 -1
  6. package/dist/index10.cjs.map +1 -1
  7. package/dist/index10.js +154 -119
  8. package/dist/index10.js.map +1 -1
  9. package/dist/index11.cjs +1 -1
  10. package/dist/index11.js +1 -1
  11. package/dist/index12.cjs +1 -1
  12. package/dist/index12.cjs.map +1 -1
  13. package/dist/index12.js +87 -87
  14. package/dist/index12.js.map +1 -1
  15. package/dist/index14.cjs +1 -1
  16. package/dist/index14.js +1 -1
  17. package/dist/index15.cjs +1 -1
  18. package/dist/index15.cjs.map +1 -1
  19. package/dist/index15.js +23 -117
  20. package/dist/index15.js.map +1 -1
  21. package/dist/index16.cjs +1 -1
  22. package/dist/index16.cjs.map +1 -1
  23. package/dist/index16.js +53 -103
  24. package/dist/index16.js.map +1 -1
  25. package/dist/index17.cjs +1 -1
  26. package/dist/index17.cjs.map +1 -1
  27. package/dist/index17.js +22 -57
  28. package/dist/index17.js.map +1 -1
  29. package/dist/index18.cjs +1 -1
  30. package/dist/index18.cjs.map +1 -1
  31. package/dist/index18.js +113 -136
  32. package/dist/index18.js.map +1 -1
  33. package/dist/index19.cjs +1 -1
  34. package/dist/index19.cjs.map +1 -1
  35. package/dist/index19.js +101 -35
  36. package/dist/index19.js.map +1 -1
  37. package/dist/index20.cjs +1 -1
  38. package/dist/index20.cjs.map +1 -1
  39. package/dist/index20.js +58 -36
  40. package/dist/index20.js.map +1 -1
  41. package/dist/index21.cjs +1 -1
  42. package/dist/index21.cjs.map +1 -1
  43. package/dist/index21.js +140 -37
  44. package/dist/index21.js.map +1 -1
  45. package/dist/index22.cjs +1 -1
  46. package/dist/index22.cjs.map +1 -1
  47. package/dist/index22.js +37 -21
  48. package/dist/index22.js.map +1 -1
  49. package/dist/index23.cjs +1 -1
  50. package/dist/index23.cjs.map +1 -1
  51. package/dist/index23.js +37 -5
  52. package/dist/index23.js.map +1 -1
  53. package/dist/index24.cjs +1 -1
  54. package/dist/index24.cjs.map +1 -1
  55. package/dist/index24.js +37 -4
  56. package/dist/index24.js.map +1 -1
  57. package/dist/index25.cjs +2 -0
  58. package/dist/index25.cjs.map +1 -0
  59. package/dist/index25.js +43 -0
  60. package/dist/index25.js.map +1 -0
  61. package/dist/index26.cjs +2 -0
  62. package/dist/index26.cjs.map +1 -0
  63. package/dist/index26.js +8 -0
  64. package/dist/index26.js.map +1 -0
  65. package/dist/index27.cjs +2 -0
  66. package/dist/index27.cjs.map +1 -0
  67. package/dist/index27.js +8 -0
  68. package/dist/index27.js.map +1 -0
  69. package/dist/index5.cjs +1 -1
  70. package/dist/index5.cjs.map +1 -1
  71. package/dist/index5.js +57 -36
  72. package/dist/index5.js.map +1 -1
  73. package/package.json +1 -1
package/dist/index10.js CHANGED
@@ -1,20 +1,20 @@
1
- import { HIGHLIGHT_DEFAULTS as u, TEXT_DEFAULTS as a, BASE_DEFAULTS as f } from "./index22.js";
2
- function d(n, e, i, s, t) {
3
- let o = n;
4
- return typeof n == "string" && (o = parseFloat(n)), typeof o != "number" || isNaN(o) ? (t.push(
5
- `[${i}]: Field "${s}" invalid value "${n}", using default ${e}`
6
- ), e) : o < 0 ? (t.push(
7
- `[${i}]: Field "${s}" value ${o} below range [0,1], clamping to 0`
8
- ), 0) : o > 1 ? (t.push(
9
- `[${i}]: Field "${s}" value ${o} exceeds range [0,1], clamping to 1`
10
- ), 1) : o;
1
+ import { HIGHLIGHT_DEFAULTS as a, TEXT_DEFAULTS as u, BASE_DEFAULTS as p, UNDERLINE_DEFAULTS as m, ARROW_DEFAULTS as f, CIRCLE_DEFAULTS as y } from "./index25.js";
2
+ function r(t, n, e, l, o) {
3
+ let i = t;
4
+ return typeof t == "string" && (i = parseFloat(t)), typeof i != "number" || isNaN(i) ? (o.push(
5
+ `[${e}]: Field "${l}" invalid value "${t}", using default ${n}`
6
+ ), n) : i < 0 ? (o.push(
7
+ `[${e}]: Field "${l}" value ${i} below range [0,1], clamping to 0`
8
+ ), 0) : i > 1 ? (o.push(
9
+ `[${e}]: Field "${l}" value ${i} exceeds range [0,1], clamping to 1`
10
+ ), 1) : i;
11
11
  }
12
- function c(n, e, i, s) {
13
- if (typeof n != "string" || n.trim().length === 0)
14
- return s.push(
15
- `[${i}]: Invalid color format "${n}", using default ${e}`
16
- ), e;
17
- const t = n.trim(), o = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/, l = /^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/, r = [
12
+ function c(t, n, e, l) {
13
+ if (typeof t != "string" || t.trim().length === 0)
14
+ return l.push(
15
+ `[${e}]: Invalid color format "${t}", using default ${n}`
16
+ ), n;
17
+ const o = t.trim(), i = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/, s = /^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/, d = [
18
18
  "red",
19
19
  "blue",
20
20
  "green",
@@ -28,151 +28,186 @@ function c(n, e, i, s) {
28
28
  "pink",
29
29
  "brown",
30
30
  "transparent"
31
- ], p = o.test(t), g = l.test(t), m = r.includes(t.toLowerCase());
32
- return p || g || m ? t : (s.push(
33
- `[${i}]: Invalid color format "${n}", using default ${e}`
34
- ), e);
31
+ ], h = i.test(o), $ = s.test(o), x = d.includes(o.toLowerCase());
32
+ return h || $ || x ? o : (l.push(
33
+ `[${e}]: Invalid color format "${t}", using default ${n}`
34
+ ), n);
35
35
  }
36
- function x(n, e, i, s, t) {
37
- let o = n;
38
- return typeof n == "string" && (o = parseFloat(n)), typeof o != "number" || isNaN(o) || o <= 0 ? (t.push(
39
- `[${i}]: Field "${s}" invalid value "${n}", using default ${e}`
40
- ), e) : o;
36
+ function I(t, n, e, l, o) {
37
+ let i = t;
38
+ return typeof t == "string" && (i = parseFloat(t)), typeof i != "number" || isNaN(i) || i <= 0 ? (o.push(
39
+ `[${e}]: Field "${l}" invalid value "${t}", using default ${n}`
40
+ ), n) : i;
41
41
  }
42
- function y(n, e, i) {
43
- const s = {};
44
- if (typeof n.id != "string" || n.id.trim().length === 0) {
45
- const t = Date.now(), o = Math.random().toString(36).substr(2, 9);
46
- s.id = `anno-${t}-${o}`, i.push(`[${s.id}]: Auto-generated ID (original was missing or invalid)`);
42
+ function A(t, n, e) {
43
+ const l = {};
44
+ if (typeof t.id != "string" || t.id.trim().length === 0) {
45
+ const o = Date.now(), i = Math.random().toString(36).substr(2, 9);
46
+ l.id = `anno-${o}-${i}`, e.push(`[${l.id}]: Auto-generated ID (original was missing or invalid)`);
47
47
  } else
48
- s.id = n.id.trim();
49
- return s.type = n.type, typeof n.page != "number" || n.page < 1 ? (e.push(
50
- `[${s.id}]: Field "page" invalid value "${n.page}", using default ${f.page}`
51
- ), s.page = f.page) : s.page = Math.floor(n.page), typeof n.start != "number" || n.start < 0 ? (e.push(
52
- `[${s.id}]: Field "start" invalid value "${n.start}", using default ${f.start}`
53
- ), s.start = f.start) : s.start = n.start, typeof n.end != "number" || n.end < 0 ? (e.push(
54
- `[${s.id}]: Field "end" invalid value "${n.end}", using start value ${s.start}`
55
- ), s.end = s.start) : n.end < s.start ? (e.push(
56
- `[${s.id}]: Field "end" (${n.end}) less than start (${s.start}), clamping to start`
57
- ), s.end = s.start) : s.end = n.end, s;
48
+ l.id = t.id.trim();
49
+ return l.type = t.type, typeof t.page != "number" || t.page < 1 ? (n.push(
50
+ `[${l.id}]: Field "page" invalid value "${t.page}", using default ${p.page}`
51
+ ), l.page = p.page) : l.page = Math.floor(t.page), typeof t.start != "number" || t.start < 0 ? (n.push(
52
+ `[${l.id}]: Field "start" invalid value "${t.start}", using default ${p.start}`
53
+ ), l.start = p.start) : l.start = t.start, typeof t.end != "number" || t.end < 0 ? (n.push(
54
+ `[${l.id}]: Field "end" invalid value "${t.end}", using start value ${l.start}`
55
+ ), l.end = l.start) : t.end < l.start ? (n.push(
56
+ `[${l.id}]: Field "end" (${t.end}) less than start (${l.start}), clamping to start`
57
+ ), l.end = l.start) : l.end = t.end, l;
58
58
  }
59
- function h(n, e, i) {
60
- return !n || typeof n != "object" ? (i.push(`[${e}]: Invalid quad object, using default`), { x: 0.1, y: 0.1, w: 0.8, h: 0.05 }) : {
61
- x: d(n.x, 0.1, e, "quad.x", i),
62
- y: d(n.y, 0.1, e, "quad.y", i),
63
- w: d(n.w, 0.8, e, "quad.w", i),
64
- h: d(n.h, 0.05, e, "quad.h", i)
59
+ function g(t, n, e) {
60
+ return !t || typeof t != "object" ? (e.push(`[${n}]: Invalid quad object, using default`), { x: 0.1, y: 0.1, w: 0.8, h: 0.05 }) : {
61
+ x: r(t.x, 0.1, n, "quad.x", e),
62
+ y: r(t.y, 0.1, n, "quad.y", e),
63
+ w: r(t.w, 0.8, n, "quad.w", e),
64
+ h: r(t.h, 0.05, n, "quad.h", e)
65
65
  };
66
66
  }
67
- function $(n, e, i, s) {
68
- const t = { ...n };
69
- e.mode !== "quads" ? (i.push(
70
- `[${n.id}]: Field "mode" invalid value "${e.mode}", using default "${u.mode}"`
71
- ), t.mode = u.mode) : t.mode = e.mode, !Array.isArray(e.quads) || e.quads.length === 0 ? (i.push(
72
- `[${n.id}]: Field "quads" missing or empty, using default`
73
- ), t.quads = u.quads) : t.quads = e.quads.map((l, r) => h(l, n.id, i));
74
- const o = u.style.color;
75
- return !e.style || typeof e.style != "object" ? (i.push(
76
- `[${n.id}]: Field "style" missing or invalid, using default`
77
- ), t.style = { color: o }) : t.style = {
78
- color: c(e.style.color, o, n.id, i)
79
- }, t;
67
+ function F(t, n, e, l) {
68
+ const o = { ...t };
69
+ n.mode !== "quads" ? (e.push(
70
+ `[${t.id}]: Field "mode" invalid value "${n.mode}", using default "${a.mode}"`
71
+ ), o.mode = a.mode) : o.mode = n.mode, !Array.isArray(n.quads) || n.quads.length === 0 ? (e.push(
72
+ `[${t.id}]: Field "quads" missing or empty, using default`
73
+ ), o.quads = a.quads) : o.quads = n.quads.map((s, d) => g(s, t.id, e));
74
+ const i = a.style.color;
75
+ return !n.style || typeof n.style != "object" ? (e.push(
76
+ `[${t.id}]: Field "style" missing or invalid, using default`
77
+ ), o.style = { color: i }) : o.style = {
78
+ color: c(n.style.color, i, t.id, e)
79
+ }, o;
80
80
  }
81
- function A(n, e, i, s) {
82
- const t = { ...n };
83
- typeof e.content != "string" || e.content.trim().length === 0 ? (i.push(
84
- `[${n.id}]: Field "content" missing or empty, using default "${a.content}"`
85
- ), t.content = a.content) : t.content = e.content, t.x = d(e.x, a.x, n.id, "x", i), t.y = d(e.y, a.y, n.id, "y", i), t.w = d(e.w, a.w, n.id, "w", i), t.h = d(e.h, a.h, n.id, "h", i);
86
- const o = a.style.bg, l = a.style.color;
87
- return !e.style || typeof e.style != "object" ? (i.push(
88
- `[${n.id}]: Field "style" missing or invalid, using defaults`
89
- ), t.style = {
90
- bg: o,
91
- color: l
92
- }) : t.style = {
93
- bg: c(e.style.bg, o, n.id, i),
94
- color: c(e.style.color, l, n.id, i)
95
- }, t;
81
+ function z(t, n, e, l) {
82
+ const o = { ...t };
83
+ typeof n.content != "string" || n.content.trim().length === 0 ? (e.push(
84
+ `[${t.id}]: Field "content" missing or empty, using default "${u.content}"`
85
+ ), o.content = u.content) : o.content = n.content, o.x = r(n.x, u.x, t.id, "x", e), o.y = r(n.y, u.y, t.id, "y", e), o.w = r(n.w, u.w, t.id, "w", e), o.h = r(n.h, u.h, t.id, "h", e);
86
+ const i = u.style.bg, s = u.style.color;
87
+ return !n.style || typeof n.style != "object" ? (e.push(
88
+ `[${t.id}]: Field "style" missing or invalid, using defaults`
89
+ ), o.style = {
90
+ bg: i,
91
+ color: s
92
+ }) : o.style = {
93
+ bg: c(n.style.bg, i, t.id, e),
94
+ color: c(n.style.color, s, t.id, e)
95
+ }, o;
96
96
  }
97
- function F(n, e) {
98
- const i = [], s = [];
99
- if (!n || typeof n != "object")
97
+ function _(t, n, e, l) {
98
+ const o = { ...t };
99
+ !Array.isArray(n.quads) || n.quads.length === 0 ? (e.push(
100
+ `[${t.id}]: Field "quads" missing or empty, using default`
101
+ ), o.quads = m.quads) : o.quads = n.quads.map((s) => g(s, t.id, e));
102
+ const i = m.style.color;
103
+ return !n.style || typeof n.style != "object" ? o.style = { color: i } : o.style = {
104
+ color: c(n.style.color, i, t.id, e)
105
+ }, o;
106
+ }
107
+ function E(t, n, e, l) {
108
+ const o = { ...t };
109
+ o.from_x = r(n.from_x, f.from_x, t.id, "from_x", e), o.from_y = r(n.from_y, f.from_y, t.id, "from_y", e), o.to_x = r(n.to_x, f.to_x, t.id, "to_x", e), o.to_y = r(n.to_y, f.to_y, t.id, "to_y", e);
110
+ const i = f.style.color;
111
+ return !n.style || typeof n.style != "object" ? o.style = { color: i } : o.style = {
112
+ color: c(n.style.color, i, t.id, e)
113
+ }, o;
114
+ }
115
+ function q(t, n, e, l) {
116
+ const o = { ...t };
117
+ o.cx = r(n.cx, y.cx, t.id, "cx", e), o.cy = r(n.cy, y.cy, t.id, "cy", e), o.rx = r(n.rx, y.rx, t.id, "rx", e), o.ry = r(n.ry, y.ry, t.id, "ry", e);
118
+ const i = y.style.color;
119
+ return !n.style || typeof n.style != "object" ? o.style = { color: i } : o.style = {
120
+ color: c(n.style.color, i, t.id, e)
121
+ }, o;
122
+ }
123
+ function v(t, n) {
124
+ const e = [], l = [];
125
+ if (!t || typeof t != "object")
100
126
  return {
101
127
  annotation: null,
102
128
  warnings: [],
103
129
  info: [],
104
- critical: `Annotation at index ${e}: Not a valid object`
130
+ critical: `Annotation at index ${n}: Not a valid object`
105
131
  };
106
- if (typeof n.type != "string" || n.type.trim().length === 0)
132
+ if (typeof t.type != "string" || t.type.trim().length === 0)
107
133
  return {
108
134
  annotation: null,
109
135
  warnings: [],
110
136
  info: [],
111
- critical: `Annotation at index ${e}: Missing or invalid type field`
137
+ critical: `Annotation at index ${n}: Missing or invalid type field`
112
138
  };
113
- const t = n.type.trim(), o = y(n, i, s);
114
- let l;
115
- if (t === "highlight")
116
- l = $(o, n, i);
117
- else if (t === "text")
118
- l = A(o, n, i);
139
+ const o = t.type.trim(), i = A(t, e, l);
140
+ let s;
141
+ if (o === "highlight")
142
+ s = F(i, t, e);
143
+ else if (o === "text")
144
+ s = z(i, t, e);
145
+ else if (o === "underline")
146
+ s = _(i, t, e);
147
+ else if (o === "arrow")
148
+ s = E(i, t, e);
149
+ else if (o === "circle")
150
+ s = q(i, t, e);
119
151
  else
120
152
  return {
121
153
  annotation: null,
122
154
  warnings: [],
123
155
  info: [],
124
- critical: `Annotation at index ${e}: Unsupported type "${t}"`
156
+ critical: `Annotation at index ${n}: Unsupported type "${o}"`
125
157
  };
126
158
  return {
127
- annotation: l,
128
- warnings: i,
129
- info: s,
159
+ annotation: s,
160
+ warnings: e,
161
+ info: l,
130
162
  critical: null
131
163
  };
132
164
  }
133
- function v(n, e = {}) {
134
- e.skipInvalid;
135
- const i = e.warnInConsole !== !1, s = e.onWarning || null, t = {
165
+ function k(t, n = {}) {
166
+ n.skipInvalid;
167
+ const e = n.warnInConsole !== !1, l = n.onWarning || null, o = {
136
168
  normalized: [],
137
169
  warnings: [],
138
170
  info: [],
139
171
  skipped: []
140
172
  };
141
- if (!Array.isArray(n)) {
142
- const o = "normalizeAnnotationArray: Input is not an array, returning empty result";
143
- return t.warnings.push(o), i && console.warn(`[Annotation Normalizer] ${o}`), t;
173
+ if (!Array.isArray(t)) {
174
+ const i = "normalizeAnnotationArray: Input is not an array, returning empty result";
175
+ return o.warnings.push(i), e && console.warn(`[Annotation Normalizer] ${i}`), o;
144
176
  }
145
- return n.forEach((o, l) => {
146
- if (o == null) {
147
- t.skipped.push({
148
- index: l,
149
- annotation: o,
177
+ return t.forEach((i, s) => {
178
+ if (i == null) {
179
+ o.skipped.push({
180
+ index: s,
181
+ annotation: i,
150
182
  reason: "Annotation is null or undefined"
151
183
  });
152
184
  return;
153
185
  }
154
- const r = F(o, l);
155
- if (r.critical) {
156
- t.skipped.push({
157
- index: l,
158
- annotation: o,
159
- reason: r.critical
160
- }), i && console.error(`[Annotation Normalizer] ${r.critical}`);
186
+ const d = v(i, s);
187
+ if (d.critical) {
188
+ o.skipped.push({
189
+ index: s,
190
+ annotation: i,
191
+ reason: d.critical
192
+ }), e && console.error(`[Annotation Normalizer] ${d.critical}`);
161
193
  return;
162
194
  }
163
- t.normalized.push(r.annotation), t.warnings.push(...r.warnings), t.info.push(...r.info);
164
- }), i && (t.warnings.length > 0 || t.info.length > 0 || t.skipped.length > 0) && (console.group("[Annotation Normalizer] Validation Summary"), t.normalized.length > 0 && console.info(`✓ Normalized ${t.normalized.length} annotation(s)`), t.skipped.length > 0 && (console.error(`✗ Skipped ${t.skipped.length} annotation(s)`), t.skipped.forEach((o) => {
165
- console.error(` Index ${o.index}: ${o.reason}`);
166
- })), t.warnings.length > 0 && (console.warn(`⚠ ${t.warnings.length} warning(s):`), t.warnings.forEach((o) => console.warn(` ${o}`))), t.info.length > 0 && (console.info(`ℹ ${t.info.length} info message(s):`), t.info.forEach((o) => console.info(` ${o}`))), console.groupEnd()), s && typeof s == "function" && s(t), t;
195
+ o.normalized.push(d.annotation), o.warnings.push(...d.warnings), o.info.push(...d.info);
196
+ }), e && (o.warnings.length > 0 || o.info.length > 0 || o.skipped.length > 0) && (console.group("[Annotation Normalizer] Validation Summary"), o.normalized.length > 0 && console.info(`✓ Normalized ${o.normalized.length} annotation(s)`), o.skipped.length > 0 && (console.error(`✗ Skipped ${o.skipped.length} annotation(s)`), o.skipped.forEach((i) => {
197
+ console.error(` Index ${i.index}: ${i.reason}`);
198
+ })), o.warnings.length > 0 && (console.warn(`⚠ ${o.warnings.length} warning(s):`), o.warnings.forEach((i) => console.warn(` ${i}`))), o.info.length > 0 && (console.info(`ℹ ${o.info.length} info message(s):`), o.info.forEach((i) => console.info(` ${i}`))), console.groupEnd()), l && typeof l == "function" && l(o), o;
167
199
  }
168
200
  export {
169
- F as normalizeAnnotation,
170
- v as normalizeAnnotationArray,
171
- y as normalizeBaseFields,
201
+ v as normalizeAnnotation,
202
+ k as normalizeAnnotationArray,
203
+ E as normalizeArrow,
204
+ A as normalizeBaseFields,
205
+ q as normalizeCircle,
172
206
  c as normalizeColor,
173
- d as normalizeCoordinate,
174
- $ as normalizeHighlight,
175
- x as normalizePositiveNumber,
176
- A as normalizeText
207
+ r as normalizeCoordinate,
208
+ F as normalizeHighlight,
209
+ I as normalizePositiveNumber,
210
+ z as normalizeText,
211
+ _ as normalizeUnderline
177
212
  };
178
213
  //# sourceMappingURL=index10.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index10.js","sources":["../src/types/validators.js"],"sourcesContent":["/**\n * Annotation Data Normalization Utilities\n *\n * This module provides defensive normalization functions that validate and fix\n * annotation data. Invalid values are replaced with safe defaults and warnings\n * are collected for user feedback.\n *\n * @module types/validators\n */\n\nimport {\n BASE_DEFAULTS,\n HIGHLIGHT_DEFAULTS,\n TEXT_DEFAULTS\n} from './defaults.js';\n\n// ============================================================================\n// FIELD-LEVEL NORMALIZERS\n// ============================================================================\n\n/**\n * Normalize coordinate value to 0-1 range\n *\n * Validates that a value is a number in the 0-1 range. Out-of-range values\n * are clamped. Invalid values use the provided default.\n *\n * @param {*} value - Value to normalize\n * @param {number} defaultValue - Fallback value if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {string} fieldName - Field name for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {number} Normalized coordinate value in range [0, 1]\n *\n * @example\n * normalizeCoordinate(0.5, 0.1, 'txt-1', 'x', warnings) // Returns: 0.5\n * normalizeCoordinate(5, 0.1, 'txt-1', 'x', warnings) // Returns: 1, adds warning\n * normalizeCoordinate('abc', 0.1, 'txt-1', 'x', warnings) // Returns: 0.1, adds warning\n */\nexport function normalizeCoordinate(value, defaultValue, id, fieldName, warnings) {\n // Type coercion: parse string to number if needed\n let numValue = value;\n if (typeof value === 'string') {\n numValue = parseFloat(value);\n if (!isNaN(numValue) && numValue === value) {\n // Successfully parsed - no warning needed\n }\n }\n\n // Validate is valid number\n if (typeof numValue !== 'number' || isNaN(numValue)) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" invalid value \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n // Range check: clamp to [0, 1]\n if (numValue < 0) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" value ${numValue} below range [0,1], clamping to 0`\n );\n return 0;\n }\n\n if (numValue > 1) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" value ${numValue} exceeds range [0,1], clamping to 1`\n );\n return 1;\n }\n\n // Valid value\n return numValue;\n}\n\n/**\n * Normalize color string\n *\n * Validates that a value is a valid color string. Supports hex, rgb/rgba,\n * and named colors. Invalid colors use the provided default.\n *\n * @param {*} value - Color value to normalize\n * @param {string} defaultValue - Fallback color if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {string} Valid color string\n *\n * @example\n * normalizeColor('#fff', '#000', 'txt-1', warnings) // Returns: '#fff'\n * normalizeColor('rgba(255,0,0,0.5)', '#000', 'txt-1', warnings) // Returns: 'rgba(255,0,0,0.5)'\n * normalizeColor('notacolor', '#000', 'txt-1', warnings) // Returns: '#000', adds warning\n */\nexport function normalizeColor(value, defaultValue, id, warnings) {\n // Type check: must be non-empty string\n if (typeof value !== 'string' || value.trim().length === 0) {\n warnings.push(\n `[${id}]: Invalid color format \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n const trimmed = value.trim();\n\n // Regex patterns for color validation (cached at module level)\n const hexPattern = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;\n const rgbPattern = /^rgba?\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*(,\\s*[\\d.]+\\s*)?\\)$/;\n\n // Named colors (basic set)\n const namedColors = [\n 'red', 'blue', 'green', 'yellow', 'black', 'white', 'gray',\n 'grey', 'orange', 'purple', 'pink', 'brown', 'transparent'\n ];\n\n // Validate format\n const isHex = hexPattern.test(trimmed);\n const isRgb = rgbPattern.test(trimmed);\n const isNamed = namedColors.includes(trimmed.toLowerCase());\n\n if (isHex || isRgb || isNamed) {\n return trimmed;\n }\n\n // Invalid format\n warnings.push(\n `[${id}]: Invalid color format \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n}\n\n/**\n * Normalize positive number\n *\n * Validates that a value is a positive number. Invalid values use the\n * provided default.\n *\n * @param {*} value - Value to normalize\n * @param {number} defaultValue - Fallback value if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {string} fieldName - Field name for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {number} Positive number\n *\n * @example\n * normalizePositiveNumber(5, 3, 'ink-1', 'size', warnings) // Returns: 5\n * normalizePositiveNumber(-1, 3, 'ink-1', 'size', warnings) // Returns: 3, adds warning\n * normalizePositiveNumber('abc', 3, 'ink-1', 'size', warnings) // Returns: 3, adds warning\n */\nexport function normalizePositiveNumber(value, defaultValue, id, fieldName, warnings) {\n // Type coercion: parse string to number if needed\n let numValue = value;\n if (typeof value === 'string') {\n numValue = parseFloat(value);\n }\n\n // Validate is valid number and positive\n if (typeof numValue !== 'number' || isNaN(numValue) || numValue <= 0) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" invalid value \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n return numValue;\n}\n\n// ============================================================================\n// BASE FIELDS NORMALIZER\n// ============================================================================\n\n/**\n * Normalize common base annotation fields\n *\n * Validates and normalizes fields common to all annotation types: id, type,\n * page, start, and end. Auto-generates ID if missing. Applies safe defaults\n * for invalid values.\n *\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Array to collect warning messages\n * @param {Array<string>} info - Array to collect info messages\n * @returns {Object} Object with normalized base fields\n *\n * @example\n * normalizeBaseFields({ type: 'text', page: 2 }, warnings, info)\n * // Returns: { id: 'anno-1234...', type: 'text', page: 2, start: 0, end: 0 }\n */\nexport function normalizeBaseFields(raw, warnings, info) {\n const base = {};\n\n // ===== ID Field =====\n // Check: non-empty string\n // Invalid: auto-generate unique ID\n if (typeof raw.id !== 'string' || raw.id.trim().length === 0) {\n const timestamp = Date.now();\n const random = Math.random().toString(36).substr(2, 9);\n base.id = `anno-${timestamp}-${random}`;\n info.push(`[${base.id}]: Auto-generated ID (original was missing or invalid)`);\n } else {\n base.id = raw.id.trim();\n }\n\n // ===== Type Field =====\n // Pass through as-is (validated in parent function)\n base.type = raw.type;\n\n // ===== Page Field =====\n // Check: positive integer\n // Invalid: default to 1\n if (typeof raw.page !== 'number' || raw.page < 1) {\n warnings.push(\n `[${base.id}]: Field \"page\" invalid value \"${raw.page}\", using default ${BASE_DEFAULTS.page}`\n );\n base.page = BASE_DEFAULTS.page;\n } else {\n // Floor to ensure integer\n base.page = Math.floor(raw.page);\n }\n\n // ===== Start Field =====\n // Check: non-negative number\n // Invalid: default to 0\n if (typeof raw.start !== 'number' || raw.start < 0) {\n warnings.push(\n `[${base.id}]: Field \"start\" invalid value \"${raw.start}\", using default ${BASE_DEFAULTS.start}`\n );\n base.start = BASE_DEFAULTS.start;\n } else {\n base.start = raw.start;\n }\n\n // ===== End Field =====\n // Check: non-negative number >= start\n // Invalid: clamp to start value\n if (typeof raw.end !== 'number' || raw.end < 0) {\n warnings.push(\n `[${base.id}]: Field \"end\" invalid value \"${raw.end}\", using start value ${base.start}`\n );\n base.end = base.start;\n } else if (raw.end < base.start) {\n warnings.push(\n `[${base.id}]: Field \"end\" (${raw.end}) less than start (${base.start}), clamping to start`\n );\n base.end = base.start;\n } else {\n base.end = raw.end;\n }\n\n return base;\n}\n\n// ============================================================================\n// TYPE-SPECIFIC NORMALIZERS\n// ============================================================================\n\n/**\n * Normalize a single quad (rectangular region)\n *\n * @private\n * @param {Object} quad - Quad object with x, y, w, h\n * @param {string} id - Annotation ID\n * @param {Array<string>} warnings - Warnings array\n * @returns {Object} Normalized quad\n */\nfunction normalizeQuad(quad, id, warnings) {\n if (!quad || typeof quad !== 'object') {\n warnings.push(`[${id}]: Invalid quad object, using default`);\n return { x: 0.1, y: 0.1, w: 0.8, h: 0.05 };\n }\n\n return {\n x: normalizeCoordinate(quad.x, 0.1, id, 'quad.x', warnings),\n y: normalizeCoordinate(quad.y, 0.1, id, 'quad.y', warnings),\n w: normalizeCoordinate(quad.w, 0.8, id, 'quad.w', warnings),\n h: normalizeCoordinate(quad.h, 0.05, id, 'quad.h', warnings)\n };\n}\n\n/**\n * Normalize highlight annotation\n *\n * Validates and normalizes highlight-specific fields: mode, quads array,\n * and style.color. Applies defaults for invalid fields.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized highlight annotation\n *\n * @example\n * normalizeHighlight(base, raw, warnings, info)\n * // Returns: { ...base, mode: 'quads', quads: [...], style: {...} }\n */\nexport function normalizeHighlight(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Mode Field =====\n // Check: value equals \"quads\"\n // Invalid: default to \"quads\"\n if (raw.mode !== 'quads') {\n warnings.push(\n `[${base.id}]: Field \"mode\" invalid value \"${raw.mode}\", using default \"${HIGHLIGHT_DEFAULTS.mode}\"`\n );\n annotation.mode = HIGHLIGHT_DEFAULTS.mode;\n } else {\n annotation.mode = raw.mode;\n }\n\n // ===== Quads Array =====\n // Check: non-empty array\n // Invalid: use default quads\n if (!Array.isArray(raw.quads) || raw.quads.length === 0) {\n warnings.push(\n `[${base.id}]: Field \"quads\" missing or empty, using default`\n );\n annotation.quads = HIGHLIGHT_DEFAULTS.quads;\n } else {\n // Normalize each quad\n annotation.quads = raw.quads.map((quad, idx) => normalizeQuad(quad, base.id, warnings));\n }\n\n // ===== Style Object =====\n // Check: object with color property\n const defaultColor = HIGHLIGHT_DEFAULTS.style.color;\n if (!raw.style || typeof raw.style !== 'object') {\n warnings.push(\n `[${base.id}]: Field \"style\" missing or invalid, using default`\n );\n annotation.style = { color: defaultColor };\n } else {\n annotation.style = {\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n/**\n * Normalize text annotation\n *\n * Validates and normalizes text-specific fields: content, position (x, y),\n * dimensions (w, h), and style (bg, color). Applies defaults for invalid fields.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized text annotation\n *\n * @example\n * normalizeText(base, raw, warnings, info)\n * // Returns: { ...base, content: '...', x: 0.1, y: 0.1, w: 0.3, h: 0.1, style: {...} }\n */\nexport function normalizeText(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Content Field =====\n // Check: non-empty string\n // Invalid: default to placeholder\n if (typeof raw.content !== 'string' || raw.content.trim().length === 0) {\n warnings.push(\n `[${base.id}]: Field \"content\" missing or empty, using default \"${TEXT_DEFAULTS.content}\"`\n );\n annotation.content = TEXT_DEFAULTS.content;\n } else {\n annotation.content = raw.content;\n }\n\n // ===== Position Fields (x, y) =====\n annotation.x = normalizeCoordinate(raw.x, TEXT_DEFAULTS.x, base.id, 'x', warnings);\n annotation.y = normalizeCoordinate(raw.y, TEXT_DEFAULTS.y, base.id, 'y', warnings);\n\n // ===== Dimension Fields (w, h) =====\n annotation.w = normalizeCoordinate(raw.w, TEXT_DEFAULTS.w, base.id, 'w', warnings);\n annotation.h = normalizeCoordinate(raw.h, TEXT_DEFAULTS.h, base.id, 'h', warnings);\n\n // ===== Style Object =====\n const defaultBg = TEXT_DEFAULTS.style.bg;\n const defaultColor = TEXT_DEFAULTS.style.color;\n\n if (!raw.style || typeof raw.style !== 'object') {\n warnings.push(\n `[${base.id}]: Field \"style\" missing or invalid, using defaults`\n );\n annotation.style = {\n bg: defaultBg,\n color: defaultColor\n };\n } else {\n annotation.style = {\n bg: normalizeColor(raw.style.bg, defaultBg, base.id, warnings),\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n// ============================================================================\n// ORCHESTRATION - SINGLE ANNOTATION & ARRAY\n// ============================================================================\n\n/**\n * Normalize a single annotation\n *\n * Routes annotation to appropriate type-specific normalizer based on type field.\n * Handles critical validation errors (missing/invalid type).\n *\n * @param {Object} raw - Raw annotation object\n * @param {number} index - Position in original array (for error context)\n * @returns {Object} Result object with annotation, warnings, info, and critical error\n * @returns {Object|null} return.annotation - Normalized annotation or null if critical error\n * @returns {Array<string>} return.warnings - Warning messages\n * @returns {Array<string>} return.info - Info messages\n * @returns {string|null} return.critical - Critical error message or null\n *\n * @example\n * normalizeAnnotation({ type: 'text', content: 'Hello' }, 0)\n * // Returns: { annotation: {...}, warnings: [], info: [], critical: null }\n */\nexport function normalizeAnnotation(raw, index) {\n const warnings = [];\n const info = [];\n\n // Validate input is object\n if (!raw || typeof raw !== 'object') {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Not a valid object`\n };\n }\n\n // Check type field (critical - cannot route without type)\n if (typeof raw.type !== 'string' || raw.type.trim().length === 0) {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Missing or invalid type field`\n };\n }\n\n const type = raw.type.trim();\n\n // Normalize base fields first\n const base = normalizeBaseFields(raw, warnings, info);\n\n // Route to type-specific normalizer\n let annotation;\n\n if (type === 'highlight') {\n annotation = normalizeHighlight(base, raw, warnings, info);\n } else if (type === 'text') {\n annotation = normalizeText(base, raw, warnings, info);\n } else {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Unsupported type \"${type}\"`\n };\n }\n\n return {\n annotation,\n warnings,\n info,\n critical: null\n };\n}\n\n/**\n * Normalize array of annotations\n *\n * MAIN ENTRY POINT for annotation normalization. Processes each annotation,\n * collects warnings, and returns normalized data ready for rendering.\n *\n * @param {Array} rawAnnotations - Array of raw annotation objects\n * @param {Object} [options] - Configuration options\n * @param {boolean} [options.skipInvalid=true] - Skip critically invalid annotations\n * @param {boolean} [options.warnInConsole=true] - Log warnings to console\n * @param {Function} [options.onWarning] - Custom warning callback\n * @returns {Object} ValidationResult with normalized annotations and messages\n * @returns {Array} return.normalized - Successfully normalized annotations\n * @returns {Array<string>} return.warnings - Warning messages\n * @returns {Array<string>} return.info - Informational messages\n * @returns {Array<Object>} return.skipped - Skipped annotations with reasons\n *\n * @example\n * const result = normalizeAnnotationArray(rawAnnotations, {\n * skipInvalid: true,\n * warnInConsole: true\n * });\n *\n * renderer.setAnnotations(result.normalized);\n */\nexport function normalizeAnnotationArray(rawAnnotations, options = {}) {\n // Default options\n const skipInvalid = options.skipInvalid !== false; // Default: true\n const warnInConsole = options.warnInConsole !== false; // Default: true\n const onWarning = options.onWarning || null;\n\n // Initialize result structure\n const result = {\n normalized: [],\n warnings: [],\n info: [],\n skipped: []\n };\n\n // Validate input is array\n if (!Array.isArray(rawAnnotations)) {\n const warning = 'normalizeAnnotationArray: Input is not an array, returning empty result';\n result.warnings.push(warning);\n\n if (warnInConsole) {\n console.warn(`[Annotation Normalizer] ${warning}`);\n }\n\n return result;\n }\n\n // Process each annotation\n rawAnnotations.forEach((raw, index) => {\n // Skip null/undefined\n if (raw == null) {\n result.skipped.push({\n index,\n annotation: raw,\n reason: 'Annotation is null or undefined'\n });\n return;\n }\n\n // Normalize annotation\n const normalized = normalizeAnnotation(raw, index);\n\n // Check for critical error\n if (normalized.critical) {\n result.skipped.push({\n index,\n annotation: raw,\n reason: normalized.critical\n });\n\n if (warnInConsole) {\n console.error(`[Annotation Normalizer] ${normalized.critical}`);\n }\n\n return;\n }\n\n // Add to normalized array\n result.normalized.push(normalized.annotation);\n\n // Collect warnings and info\n result.warnings.push(...normalized.warnings);\n result.info.push(...normalized.info);\n });\n\n // Console output\n if (warnInConsole) {\n if (result.warnings.length > 0 || result.info.length > 0 || result.skipped.length > 0) {\n console.group('[Annotation Normalizer] Validation Summary');\n\n if (result.normalized.length > 0) {\n console.info(`✓ Normalized ${result.normalized.length} annotation(s)`);\n }\n\n if (result.skipped.length > 0) {\n console.error(`✗ Skipped ${result.skipped.length} annotation(s)`);\n result.skipped.forEach(s => {\n console.error(` Index ${s.index}: ${s.reason}`);\n });\n }\n\n if (result.warnings.length > 0) {\n console.warn(`⚠ ${result.warnings.length} warning(s):`);\n result.warnings.forEach(w => console.warn(` ${w}`));\n }\n\n if (result.info.length > 0) {\n console.info(`ℹ ${result.info.length} info message(s):`);\n result.info.forEach(i => console.info(` ${i}`));\n }\n\n console.groupEnd();\n }\n }\n\n // Call custom warning handler\n if (onWarning && typeof onWarning === 'function') {\n onWarning(result);\n }\n\n return result;\n}\n"],"names":["normalizeCoordinate","value","defaultValue","id","fieldName","warnings","numValue","normalizeColor","trimmed","hexPattern","rgbPattern","namedColors","isHex","isRgb","isNamed","normalizePositiveNumber","normalizeBaseFields","raw","info","base","timestamp","random","BASE_DEFAULTS","normalizeQuad","quad","normalizeHighlight","annotation","HIGHLIGHT_DEFAULTS","idx","defaultColor","normalizeText","TEXT_DEFAULTS","defaultBg","normalizeAnnotation","index","type","normalizeAnnotationArray","rawAnnotations","options","warnInConsole","onWarning","result","warning","normalized","s","w","i"],"mappings":";AAsCO,SAASA,EAAoBC,GAAOC,GAAcC,GAAIC,GAAWC,GAAU;AAEhF,MAAIC,IAAWL;AASf,SARI,OAAOA,KAAU,aACnBK,IAAW,WAAWL,CAAK,IAOzB,OAAOK,KAAa,YAAY,MAAMA,CAAQ,KAChDD,EAAS;AAAA,IACP,IAAIF,CAAE,aAAaC,CAAS,oBAAoBH,CAAK,oBAAoBC,CAAY;AAAA,EAC3F,GACWA,KAILI,IAAW,KACbD,EAAS;AAAA,IACP,IAAIF,CAAE,aAAaC,CAAS,WAAWE,CAAQ;AAAA,EACrD,GACW,KAGLA,IAAW,KACbD,EAAS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,GAGXA;AACT;"}
1
+ {"version":3,"file":"index10.js","sources":["../src/types/validators.js"],"sourcesContent":["/**\n * Annotation Data Normalization Utilities\n *\n * This module provides defensive normalization functions that validate and fix\n * annotation data. Invalid values are replaced with safe defaults and warnings\n * are collected for user feedback.\n *\n * @module types/validators\n */\n\nimport {\n BASE_DEFAULTS,\n HIGHLIGHT_DEFAULTS,\n TEXT_DEFAULTS,\n UNDERLINE_DEFAULTS,\n ARROW_DEFAULTS,\n CIRCLE_DEFAULTS\n} from './defaults.js';\n\n// ============================================================================\n// FIELD-LEVEL NORMALIZERS\n// ============================================================================\n\n/**\n * Normalize coordinate value to 0-1 range\n *\n * Validates that a value is a number in the 0-1 range. Out-of-range values\n * are clamped. Invalid values use the provided default.\n *\n * @param {*} value - Value to normalize\n * @param {number} defaultValue - Fallback value if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {string} fieldName - Field name for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {number} Normalized coordinate value in range [0, 1]\n *\n * @example\n * normalizeCoordinate(0.5, 0.1, 'txt-1', 'x', warnings) // Returns: 0.5\n * normalizeCoordinate(5, 0.1, 'txt-1', 'x', warnings) // Returns: 1, adds warning\n * normalizeCoordinate('abc', 0.1, 'txt-1', 'x', warnings) // Returns: 0.1, adds warning\n */\nexport function normalizeCoordinate(value, defaultValue, id, fieldName, warnings) {\n // Type coercion: parse string to number if needed\n let numValue = value;\n if (typeof value === 'string') {\n numValue = parseFloat(value);\n if (!isNaN(numValue) && numValue === value) {\n // Successfully parsed - no warning needed\n }\n }\n\n // Validate is valid number\n if (typeof numValue !== 'number' || isNaN(numValue)) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" invalid value \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n // Range check: clamp to [0, 1]\n if (numValue < 0) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" value ${numValue} below range [0,1], clamping to 0`\n );\n return 0;\n }\n\n if (numValue > 1) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" value ${numValue} exceeds range [0,1], clamping to 1`\n );\n return 1;\n }\n\n // Valid value\n return numValue;\n}\n\n/**\n * Normalize color string\n *\n * Validates that a value is a valid color string. Supports hex, rgb/rgba,\n * and named colors. Invalid colors use the provided default.\n *\n * @param {*} value - Color value to normalize\n * @param {string} defaultValue - Fallback color if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {string} Valid color string\n *\n * @example\n * normalizeColor('#fff', '#000', 'txt-1', warnings) // Returns: '#fff'\n * normalizeColor('rgba(255,0,0,0.5)', '#000', 'txt-1', warnings) // Returns: 'rgba(255,0,0,0.5)'\n * normalizeColor('notacolor', '#000', 'txt-1', warnings) // Returns: '#000', adds warning\n */\nexport function normalizeColor(value, defaultValue, id, warnings) {\n // Type check: must be non-empty string\n if (typeof value !== 'string' || value.trim().length === 0) {\n warnings.push(\n `[${id}]: Invalid color format \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n const trimmed = value.trim();\n\n // Regex patterns for color validation (cached at module level)\n const hexPattern = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;\n const rgbPattern = /^rgba?\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*(,\\s*[\\d.]+\\s*)?\\)$/;\n\n // Named colors (basic set)\n const namedColors = [\n 'red', 'blue', 'green', 'yellow', 'black', 'white', 'gray',\n 'grey', 'orange', 'purple', 'pink', 'brown', 'transparent'\n ];\n\n // Validate format\n const isHex = hexPattern.test(trimmed);\n const isRgb = rgbPattern.test(trimmed);\n const isNamed = namedColors.includes(trimmed.toLowerCase());\n\n if (isHex || isRgb || isNamed) {\n return trimmed;\n }\n\n // Invalid format\n warnings.push(\n `[${id}]: Invalid color format \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n}\n\n/**\n * Normalize positive number\n *\n * Validates that a value is a positive number. Invalid values use the\n * provided default.\n *\n * @param {*} value - Value to normalize\n * @param {number} defaultValue - Fallback value if invalid\n * @param {string} id - Annotation ID for warning messages\n * @param {string} fieldName - Field name for warning messages\n * @param {Array<string>} warnings - Array to collect warning messages\n * @returns {number} Positive number\n *\n * @example\n * normalizePositiveNumber(5, 3, 'ink-1', 'size', warnings) // Returns: 5\n * normalizePositiveNumber(-1, 3, 'ink-1', 'size', warnings) // Returns: 3, adds warning\n * normalizePositiveNumber('abc', 3, 'ink-1', 'size', warnings) // Returns: 3, adds warning\n */\nexport function normalizePositiveNumber(value, defaultValue, id, fieldName, warnings) {\n // Type coercion: parse string to number if needed\n let numValue = value;\n if (typeof value === 'string') {\n numValue = parseFloat(value);\n }\n\n // Validate is valid number and positive\n if (typeof numValue !== 'number' || isNaN(numValue) || numValue <= 0) {\n warnings.push(\n `[${id}]: Field \"${fieldName}\" invalid value \"${value}\", using default ${defaultValue}`\n );\n return defaultValue;\n }\n\n return numValue;\n}\n\n// ============================================================================\n// BASE FIELDS NORMALIZER\n// ============================================================================\n\n/**\n * Normalize common base annotation fields\n *\n * Validates and normalizes fields common to all annotation types: id, type,\n * page, start, and end. Auto-generates ID if missing. Applies safe defaults\n * for invalid values.\n *\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Array to collect warning messages\n * @param {Array<string>} info - Array to collect info messages\n * @returns {Object} Object with normalized base fields\n *\n * @example\n * normalizeBaseFields({ type: 'text', page: 2 }, warnings, info)\n * // Returns: { id: 'anno-1234...', type: 'text', page: 2, start: 0, end: 0 }\n */\nexport function normalizeBaseFields(raw, warnings, info) {\n const base = {};\n\n // ===== ID Field =====\n // Check: non-empty string\n // Invalid: auto-generate unique ID\n if (typeof raw.id !== 'string' || raw.id.trim().length === 0) {\n const timestamp = Date.now();\n const random = Math.random().toString(36).substr(2, 9);\n base.id = `anno-${timestamp}-${random}`;\n info.push(`[${base.id}]: Auto-generated ID (original was missing or invalid)`);\n } else {\n base.id = raw.id.trim();\n }\n\n // ===== Type Field =====\n // Pass through as-is (validated in parent function)\n base.type = raw.type;\n\n // ===== Page Field =====\n // Check: positive integer\n // Invalid: default to 1\n if (typeof raw.page !== 'number' || raw.page < 1) {\n warnings.push(\n `[${base.id}]: Field \"page\" invalid value \"${raw.page}\", using default ${BASE_DEFAULTS.page}`\n );\n base.page = BASE_DEFAULTS.page;\n } else {\n // Floor to ensure integer\n base.page = Math.floor(raw.page);\n }\n\n // ===== Start Field =====\n // Check: non-negative number\n // Invalid: default to 0\n if (typeof raw.start !== 'number' || raw.start < 0) {\n warnings.push(\n `[${base.id}]: Field \"start\" invalid value \"${raw.start}\", using default ${BASE_DEFAULTS.start}`\n );\n base.start = BASE_DEFAULTS.start;\n } else {\n base.start = raw.start;\n }\n\n // ===== End Field =====\n // Check: non-negative number >= start\n // Invalid: clamp to start value\n if (typeof raw.end !== 'number' || raw.end < 0) {\n warnings.push(\n `[${base.id}]: Field \"end\" invalid value \"${raw.end}\", using start value ${base.start}`\n );\n base.end = base.start;\n } else if (raw.end < base.start) {\n warnings.push(\n `[${base.id}]: Field \"end\" (${raw.end}) less than start (${base.start}), clamping to start`\n );\n base.end = base.start;\n } else {\n base.end = raw.end;\n }\n\n return base;\n}\n\n// ============================================================================\n// TYPE-SPECIFIC NORMALIZERS\n// ============================================================================\n\n/**\n * Normalize a single quad (rectangular region)\n *\n * @private\n * @param {Object} quad - Quad object with x, y, w, h\n * @param {string} id - Annotation ID\n * @param {Array<string>} warnings - Warnings array\n * @returns {Object} Normalized quad\n */\nfunction normalizeQuad(quad, id, warnings) {\n if (!quad || typeof quad !== 'object') {\n warnings.push(`[${id}]: Invalid quad object, using default`);\n return { x: 0.1, y: 0.1, w: 0.8, h: 0.05 };\n }\n\n return {\n x: normalizeCoordinate(quad.x, 0.1, id, 'quad.x', warnings),\n y: normalizeCoordinate(quad.y, 0.1, id, 'quad.y', warnings),\n w: normalizeCoordinate(quad.w, 0.8, id, 'quad.w', warnings),\n h: normalizeCoordinate(quad.h, 0.05, id, 'quad.h', warnings)\n };\n}\n\n/**\n * Normalize highlight annotation\n *\n * Validates and normalizes highlight-specific fields: mode, quads array,\n * and style.color. Applies defaults for invalid fields.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized highlight annotation\n *\n * @example\n * normalizeHighlight(base, raw, warnings, info)\n * // Returns: { ...base, mode: 'quads', quads: [...], style: {...} }\n */\nexport function normalizeHighlight(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Mode Field =====\n // Check: value equals \"quads\"\n // Invalid: default to \"quads\"\n if (raw.mode !== 'quads') {\n warnings.push(\n `[${base.id}]: Field \"mode\" invalid value \"${raw.mode}\", using default \"${HIGHLIGHT_DEFAULTS.mode}\"`\n );\n annotation.mode = HIGHLIGHT_DEFAULTS.mode;\n } else {\n annotation.mode = raw.mode;\n }\n\n // ===== Quads Array =====\n // Check: non-empty array\n // Invalid: use default quads\n if (!Array.isArray(raw.quads) || raw.quads.length === 0) {\n warnings.push(\n `[${base.id}]: Field \"quads\" missing or empty, using default`\n );\n annotation.quads = HIGHLIGHT_DEFAULTS.quads;\n } else {\n // Normalize each quad\n annotation.quads = raw.quads.map((quad, idx) => normalizeQuad(quad, base.id, warnings));\n }\n\n // ===== Style Object =====\n // Check: object with color property\n const defaultColor = HIGHLIGHT_DEFAULTS.style.color;\n if (!raw.style || typeof raw.style !== 'object') {\n warnings.push(\n `[${base.id}]: Field \"style\" missing or invalid, using default`\n );\n annotation.style = { color: defaultColor };\n } else {\n annotation.style = {\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n/**\n * Normalize text annotation\n *\n * Validates and normalizes text-specific fields: content, position (x, y),\n * dimensions (w, h), and style (bg, color). Applies defaults for invalid fields.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized text annotation\n *\n * @example\n * normalizeText(base, raw, warnings, info)\n * // Returns: { ...base, content: '...', x: 0.1, y: 0.1, w: 0.3, h: 0.1, style: {...} }\n */\nexport function normalizeText(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Content Field =====\n // Check: non-empty string\n // Invalid: default to placeholder\n if (typeof raw.content !== 'string' || raw.content.trim().length === 0) {\n warnings.push(\n `[${base.id}]: Field \"content\" missing or empty, using default \"${TEXT_DEFAULTS.content}\"`\n );\n annotation.content = TEXT_DEFAULTS.content;\n } else {\n annotation.content = raw.content;\n }\n\n // ===== Position Fields (x, y) =====\n annotation.x = normalizeCoordinate(raw.x, TEXT_DEFAULTS.x, base.id, 'x', warnings);\n annotation.y = normalizeCoordinate(raw.y, TEXT_DEFAULTS.y, base.id, 'y', warnings);\n\n // ===== Dimension Fields (w, h) =====\n annotation.w = normalizeCoordinate(raw.w, TEXT_DEFAULTS.w, base.id, 'w', warnings);\n annotation.h = normalizeCoordinate(raw.h, TEXT_DEFAULTS.h, base.id, 'h', warnings);\n\n // ===== Style Object =====\n const defaultBg = TEXT_DEFAULTS.style.bg;\n const defaultColor = TEXT_DEFAULTS.style.color;\n\n if (!raw.style || typeof raw.style !== 'object') {\n warnings.push(\n `[${base.id}]: Field \"style\" missing or invalid, using defaults`\n );\n annotation.style = {\n bg: defaultBg,\n color: defaultColor\n };\n } else {\n annotation.style = {\n bg: normalizeColor(raw.style.bg, defaultBg, base.id, warnings),\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n/**\n * Normalize underline annotation\n *\n * Validates and normalizes underline-specific fields: quads array and style.color.\n * Uses same quad structure as highlight for consistency.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized underline annotation\n */\nexport function normalizeUnderline(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Quads Array =====\n if (!Array.isArray(raw.quads) || raw.quads.length === 0) {\n warnings.push(\n `[${base.id}]: Field \"quads\" missing or empty, using default`\n );\n annotation.quads = UNDERLINE_DEFAULTS.quads;\n } else {\n annotation.quads = raw.quads.map((quad) => normalizeQuad(quad, base.id, warnings));\n }\n\n // ===== Style Object =====\n const defaultColor = UNDERLINE_DEFAULTS.style.color;\n if (!raw.style || typeof raw.style !== 'object') {\n annotation.style = { color: defaultColor };\n } else {\n annotation.style = {\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n/**\n * Normalize arrow annotation\n *\n * Validates and normalizes arrow-specific fields: from_x, from_y, to_x, to_y,\n * and style.color.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized arrow annotation\n */\nexport function normalizeArrow(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Coordinate Fields =====\n annotation.from_x = normalizeCoordinate(raw.from_x, ARROW_DEFAULTS.from_x, base.id, 'from_x', warnings);\n annotation.from_y = normalizeCoordinate(raw.from_y, ARROW_DEFAULTS.from_y, base.id, 'from_y', warnings);\n annotation.to_x = normalizeCoordinate(raw.to_x, ARROW_DEFAULTS.to_x, base.id, 'to_x', warnings);\n annotation.to_y = normalizeCoordinate(raw.to_y, ARROW_DEFAULTS.to_y, base.id, 'to_y', warnings);\n\n // ===== Style Object =====\n const defaultColor = ARROW_DEFAULTS.style.color;\n if (!raw.style || typeof raw.style !== 'object') {\n annotation.style = { color: defaultColor };\n } else {\n annotation.style = {\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n/**\n * Normalize circle annotation\n *\n * Validates and normalizes circle-specific fields: cx, cy, rx, ry,\n * and style.color.\n *\n * @param {Object} base - Object with normalized base fields\n * @param {Object} raw - Raw annotation object\n * @param {Array<string>} warnings - Warnings array\n * @param {Array<string>} info - Info array\n * @returns {Object} Fully normalized circle annotation\n */\nexport function normalizeCircle(base, raw, warnings, info) {\n const annotation = { ...base };\n\n // ===== Center and Radii Fields =====\n annotation.cx = normalizeCoordinate(raw.cx, CIRCLE_DEFAULTS.cx, base.id, 'cx', warnings);\n annotation.cy = normalizeCoordinate(raw.cy, CIRCLE_DEFAULTS.cy, base.id, 'cy', warnings);\n annotation.rx = normalizeCoordinate(raw.rx, CIRCLE_DEFAULTS.rx, base.id, 'rx', warnings);\n annotation.ry = normalizeCoordinate(raw.ry, CIRCLE_DEFAULTS.ry, base.id, 'ry', warnings);\n\n // ===== Style Object =====\n const defaultColor = CIRCLE_DEFAULTS.style.color;\n if (!raw.style || typeof raw.style !== 'object') {\n annotation.style = { color: defaultColor };\n } else {\n annotation.style = {\n color: normalizeColor(raw.style.color, defaultColor, base.id, warnings)\n };\n }\n\n return annotation;\n}\n\n// ============================================================================\n// ORCHESTRATION - SINGLE ANNOTATION & ARRAY\n// ============================================================================\n\n/**\n * Normalize a single annotation\n *\n * Routes annotation to appropriate type-specific normalizer based on type field.\n * Handles critical validation errors (missing/invalid type).\n *\n * @param {Object} raw - Raw annotation object\n * @param {number} index - Position in original array (for error context)\n * @returns {Object} Result object with annotation, warnings, info, and critical error\n * @returns {Object|null} return.annotation - Normalized annotation or null if critical error\n * @returns {Array<string>} return.warnings - Warning messages\n * @returns {Array<string>} return.info - Info messages\n * @returns {string|null} return.critical - Critical error message or null\n *\n * @example\n * normalizeAnnotation({ type: 'text', content: 'Hello' }, 0)\n * // Returns: { annotation: {...}, warnings: [], info: [], critical: null }\n */\nexport function normalizeAnnotation(raw, index) {\n const warnings = [];\n const info = [];\n\n // Validate input is object\n if (!raw || typeof raw !== 'object') {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Not a valid object`\n };\n }\n\n // Check type field (critical - cannot route without type)\n if (typeof raw.type !== 'string' || raw.type.trim().length === 0) {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Missing or invalid type field`\n };\n }\n\n const type = raw.type.trim();\n\n // Normalize base fields first\n const base = normalizeBaseFields(raw, warnings, info);\n\n // Route to type-specific normalizer\n let annotation;\n\n if (type === 'highlight') {\n annotation = normalizeHighlight(base, raw, warnings, info);\n } else if (type === 'text') {\n annotation = normalizeText(base, raw, warnings, info);\n } else if (type === 'underline') {\n annotation = normalizeUnderline(base, raw, warnings, info);\n } else if (type === 'arrow') {\n annotation = normalizeArrow(base, raw, warnings, info);\n } else if (type === 'circle') {\n annotation = normalizeCircle(base, raw, warnings, info);\n } else {\n return {\n annotation: null,\n warnings: [],\n info: [],\n critical: `Annotation at index ${index}: Unsupported type \"${type}\"`\n };\n }\n\n return {\n annotation,\n warnings,\n info,\n critical: null\n };\n}\n\n/**\n * Normalize array of annotations\n *\n * MAIN ENTRY POINT for annotation normalization. Processes each annotation,\n * collects warnings, and returns normalized data ready for rendering.\n *\n * @param {Array} rawAnnotations - Array of raw annotation objects\n * @param {Object} [options] - Configuration options\n * @param {boolean} [options.skipInvalid=true] - Skip critically invalid annotations\n * @param {boolean} [options.warnInConsole=true] - Log warnings to console\n * @param {Function} [options.onWarning] - Custom warning callback\n * @returns {Object} ValidationResult with normalized annotations and messages\n * @returns {Array} return.normalized - Successfully normalized annotations\n * @returns {Array<string>} return.warnings - Warning messages\n * @returns {Array<string>} return.info - Informational messages\n * @returns {Array<Object>} return.skipped - Skipped annotations with reasons\n *\n * @example\n * const result = normalizeAnnotationArray(rawAnnotations, {\n * skipInvalid: true,\n * warnInConsole: true\n * });\n *\n * renderer.setAnnotations(result.normalized);\n */\nexport function normalizeAnnotationArray(rawAnnotations, options = {}) {\n // Default options\n const skipInvalid = options.skipInvalid !== false; // Default: true\n const warnInConsole = options.warnInConsole !== false; // Default: true\n const onWarning = options.onWarning || null;\n\n // Initialize result structure\n const result = {\n normalized: [],\n warnings: [],\n info: [],\n skipped: []\n };\n\n // Validate input is array\n if (!Array.isArray(rawAnnotations)) {\n const warning = 'normalizeAnnotationArray: Input is not an array, returning empty result';\n result.warnings.push(warning);\n\n if (warnInConsole) {\n console.warn(`[Annotation Normalizer] ${warning}`);\n }\n\n return result;\n }\n\n // Process each annotation\n rawAnnotations.forEach((raw, index) => {\n // Skip null/undefined\n if (raw == null) {\n result.skipped.push({\n index,\n annotation: raw,\n reason: 'Annotation is null or undefined'\n });\n return;\n }\n\n // Normalize annotation\n const normalized = normalizeAnnotation(raw, index);\n\n // Check for critical error\n if (normalized.critical) {\n result.skipped.push({\n index,\n annotation: raw,\n reason: normalized.critical\n });\n\n if (warnInConsole) {\n console.error(`[Annotation Normalizer] ${normalized.critical}`);\n }\n\n return;\n }\n\n // Add to normalized array\n result.normalized.push(normalized.annotation);\n\n // Collect warnings and info\n result.warnings.push(...normalized.warnings);\n result.info.push(...normalized.info);\n });\n\n // Console output\n if (warnInConsole) {\n if (result.warnings.length > 0 || result.info.length > 0 || result.skipped.length > 0) {\n console.group('[Annotation Normalizer] Validation Summary');\n\n if (result.normalized.length > 0) {\n console.info(`✓ Normalized ${result.normalized.length} annotation(s)`);\n }\n\n if (result.skipped.length > 0) {\n console.error(`✗ Skipped ${result.skipped.length} annotation(s)`);\n result.skipped.forEach(s => {\n console.error(` Index ${s.index}: ${s.reason}`);\n });\n }\n\n if (result.warnings.length > 0) {\n console.warn(`⚠ ${result.warnings.length} warning(s):`);\n result.warnings.forEach(w => console.warn(` ${w}`));\n }\n\n if (result.info.length > 0) {\n console.info(`ℹ ${result.info.length} info message(s):`);\n result.info.forEach(i => console.info(` ${i}`));\n }\n\n console.groupEnd();\n }\n }\n\n // Call custom warning handler\n if (onWarning && typeof onWarning === 'function') {\n onWarning(result);\n }\n\n return result;\n}\n"],"names":["normalizeCoordinate","value","defaultValue","id","fieldName","warnings","numValue","normalizeColor","trimmed","hexPattern","rgbPattern","namedColors","isHex","isRgb","isNamed","normalizePositiveNumber","normalizeBaseFields","raw","info","base","timestamp","random","BASE_DEFAULTS","normalizeQuad","quad","normalizeHighlight","annotation","HIGHLIGHT_DEFAULTS","idx","defaultColor","normalizeText","TEXT_DEFAULTS","defaultBg","normalizeUnderline","UNDERLINE_DEFAULTS","normalizeArrow","ARROW_DEFAULTS","normalizeCircle","CIRCLE_DEFAULTS","normalizeAnnotation","index","type","normalizeAnnotationArray","rawAnnotations","options","warnInConsole","onWarning","result","warning","normalized","s","w"],"mappings":";AAyCO,SAASA,EAAoBC,GAAOC,GAAcC,GAAIC,GAAWC,GAAU;AAEhF,MAAIC,IAAWL;AASf,SARI,OAAOA,KAAU,aACnBK,IAAW,WAAWL,CAAK,IAOzB,OAAOK,KAAa,YAAY,MAAMA,CAAQ,KAChDD,EAAS;AAAA,IACP,IAAIF,CAAE,aAAaC,CAAS,oBAAoBH,CAAK,oBAAoBC,CAAY;AAAA,EAC3F,GACWA,KAILI,IAAW,KACbD,EAAS;AAAA,IACP,IAAIF,CAAE,aAAaC,CAAS,WAAWE,CAAQ;AAAA,EACrD,GACW,KAGLA,IAAW,KACbD,EAAS;AAAA,IACP,IAAIF,CAAE,aAAaC,CAAS,WAAWE,CAAQ;AAAA,EACrD,GACW,KAIFA;AACT;AAmBO,SAASC,EAAeN,GAAOC,GAAcC,GAAIE,GAAU;AAEhE,MAAI,OAAOJ,KAAU,YAAYA,EAAM,KAAI,EAAG,WAAW;AACvD,WAAAI,EAAS;AAAA,MACP,IAAIF,CAAE,4BAA4BF,CAAK,oBAAoBC,CAAY;AAAA,IAC7E,GACWA;AAGT,QAAMM,IAAUP,EAAM,KAAI,GAGpBQ,IAAa,sCACbC,IAAa,4DAGbC,IAAc;AAAA,IAClB;AAAA,IAAO;AAAA,IAAQ;AAAA,IAAS;AAAA,IAAU;AAAA,IAAS;AAAA,IAAS;AAAA,IACpD;AAAA,IAAQ;AAAA,IAAU;AAAA,IAAU;AAAA,IAAQ;AAAA,IAAS;AAAA,EACjD,GAGQC,IAAQH,EAAW,KAAKD,CAAO,GA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AC,IAGCH,EAAO,SAAS,SAAS,MAC3B,QAAQ,KAAK,KAAKA,EAAO,SAAS,MAAM,cAAc,GACtDA,EAAO,SAAS,QAAQ,CAAAI,MAAK,QAAQ,KAAK,KAAKA,CAAC,EAAE,CAAC,IAGjDJ,EAAO,KAAK,SAAS,MACvB,QAAQ,KAAK,KAAKA,EAAO,KAAK,MAAM,mBAAmB,GACvDA,EAAO,KAAK,QAAQ,OAAK,QAAQ,KAAK,KAAK,CAAC,EAAE,CAAC,IAGjD,QAAQ,SAAQ,IAKhBD,KAAa,OAAOA,KAAc,cACpCA,EAAUC,CAAM,GAGXA;AACT;"}
package/dist/index11.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index10.cjs"),e=require("./index22.cjs");exports.normalizeAnnotation=o.normalizeAnnotation;exports.normalizeAnnotationArray=o.normalizeAnnotationArray;exports.normalizeBaseFields=o.normalizeBaseFields;exports.normalizeColor=o.normalizeColor;exports.normalizeCoordinate=o.normalizeCoordinate;exports.normalizeHighlight=o.normalizeHighlight;exports.normalizePositiveNumber=o.normalizePositiveNumber;exports.normalizeText=o.normalizeText;exports.BASE_DEFAULTS=e.BASE_DEFAULTS;exports.HIGHLIGHT_DEFAULTS=e.HIGHLIGHT_DEFAULTS;exports.TEXT_DEFAULTS=e.TEXT_DEFAULTS;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index10.cjs"),e=require("./index25.cjs");exports.normalizeAnnotation=o.normalizeAnnotation;exports.normalizeAnnotationArray=o.normalizeAnnotationArray;exports.normalizeBaseFields=o.normalizeBaseFields;exports.normalizeColor=o.normalizeColor;exports.normalizeCoordinate=o.normalizeCoordinate;exports.normalizeHighlight=o.normalizeHighlight;exports.normalizePositiveNumber=o.normalizePositiveNumber;exports.normalizeText=o.normalizeText;exports.BASE_DEFAULTS=e.BASE_DEFAULTS;exports.HIGHLIGHT_DEFAULTS=e.HIGHLIGHT_DEFAULTS;exports.TEXT_DEFAULTS=e.TEXT_DEFAULTS;
2
2
  //# sourceMappingURL=index11.cjs.map
package/dist/index11.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { normalizeAnnotation as e, normalizeAnnotationArray as i, normalizeBaseFields as n, normalizeColor as a, normalizeCoordinate as l, normalizeHighlight as m, normalizePositiveNumber as t, normalizeText as z } from "./index10.js";
2
- import { BASE_DEFAULTS as T, HIGHLIGHT_DEFAULTS as E, TEXT_DEFAULTS as F } from "./index22.js";
2
+ import { BASE_DEFAULTS as T, HIGHLIGHT_DEFAULTS as E, TEXT_DEFAULTS as F } from "./index25.js";
3
3
  export {
4
4
  T as BASE_DEFAULTS,
5
5
  E as HIGHLIGHT_DEFAULTS,
package/dist/index12.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("react/jsx-runtime"),n=require("react"),q=require("./index2.cjs"),E=require("./index17.cjs");function D({pdfUrl:v,page:u=1,scale:f=1.5,annotations:m=[],currentTime:d=0,audioRef:l,strokeConfig:a,onLoad:w,onError:t,onPageChange:A,className:x,style:C,canvasStyle:L}){const p=n.useRef(null),P=n.useRef(null),r=n.useRef(null),F=n.useRef(Promise.resolve()),[i,S]=n.useState(!1),o=n.useCallback(e=>{F.current=F.current.then(e).catch(s=>{console.error("AnnotPdf: Queued operation failed:",s)})},[]),h=n.useMemo(()=>{if(!a)return;const e=a.preset||"default",s=E.getPreset(e);return{highlight:{color:s.highlight.color,width:a.highlight?.width??s.highlight.width},text:{color:s.handText.color,width:a.text?.width??s.handText.width}}},[a]);n.useEffect(()=>{if(!(!p.current||!P.current)){try{r.current=new q.AnnotationRenderer({canvasElement:p.current,container:P.current,strokeConfig:h}),S(!0)}catch(e){console.error("AnnotPdf: Failed to initialize renderer:",e),t&&t(e)}return()=>{S(!1),r.current&&(r.current.destroy(),r.current=null)}}},[]),n.useEffect(()=>{if(!i||!v)return;let e=!1;return o(async()=>{if(r.current)try{const c=await r.current.loadPDF(v);if(e)return;if(!c.success){console.error("AnnotPdf: Failed to load PDF:",c.error),t&&t(new Error(c.error));return}w&&w({pageCount:c.pageCount})}catch(c){if(e)return;console.error("AnnotPdf: Failed to load PDF:",c),t&&t(c)}}),()=>{e=!0}},[v,i,o]),n.useEffect(()=>{!i||!u||typeof u!="number"||o(async()=>{if(r.current)try{const e=await r.current.setPage(u);if(!e.success){console.error("AnnotPdf: Failed to set page:",e.error),t&&t(new Error(e.error));return}A&&A(u)}catch(e){console.error("AnnotPdf: Failed to set page:",e),t&&t(e)}})},[u,i,o]),n.useEffect(()=>{!i||!f||typeof f!="number"||o(async()=>{if(r.current)try{const e=await r.current.setScale(f);e.success||(console.error("AnnotPdf: Failed to set scale:",e.error),t&&t(new Error(e.error)))}catch(e){console.error("AnnotPdf: Failed to set scale:",e),t&&t(e)}})},[f,i,o]),n.useEffect(()=>{if(!(!i||!r.current))try{r.current.setAnnotations(m||[])}catch(e){console.error("AnnotPdf: Failed to set annotations:",e),t&&t(e)}},[m,i]),n.useEffect(()=>{if(!l&&!(!i||!r.current||d===void 0||d===null))try{r.current.setTime(d)}catch(e){console.error("AnnotPdf: Failed to set time:",e),t&&t(e)}},[d,l,i]),n.useEffect(()=>{if(!l?.current||!i||!r.current)return;const e=l.current,s=r.current,c=()=>{s.startContinuousSync(()=>e.currentTime)},y=()=>{s.stopContinuousSync(),s.setTime(e.currentTime)},b=()=>{s.setTime(e.currentTime)};return e.addEventListener("play",c),e.addEventListener("pause",y),e.addEventListener("ended",y),e.addEventListener("seeked",b),e.paused||c(),()=>{e.removeEventListener("play",c),e.removeEventListener("pause",y),e.removeEventListener("ended",y),e.removeEventListener("seeked",b),s.stopContinuousSync()}},[l,i]);const R=n.useRef(!0);n.useEffect(()=>{if(R.current){R.current=!1;return}if(r.current&&h)try{r.current.updateStrokeConfig(h)}catch(e){console.error("AnnotPdf: Failed to update stroke config:",e),t&&t(e)}},[h]);const k={position:"relative",display:"inline-block",lineHeight:0,...C},T={position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"hidden"},j={display:"block",...L};return g.jsxs("div",{className:x,style:k,children:[g.jsx("canvas",{ref:p,style:j}),g.jsx("div",{ref:P,style:T})]})}exports.default=D;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("react/jsx-runtime"),n=require("react"),j=require("./index2.cjs"),q=require("./index20.cjs");function E({pdfUrl:y,page:o=1,scale:a=1.5,annotations:g=[],currentTime:d=0,audioRef:f,strokeConfig:l,onLoad:m,onError:r,onPageChange:w,className:b,style:x,canvasStyle:C}){const v=n.useRef(null),p=n.useRef(null),t=n.useRef(null),A=n.useRef(Promise.resolve()),[i,F]=n.useState(!1),u=n.useCallback(e=>{A.current=A.current.then(e).catch(c=>{console.error("AnnotPdf: Queued operation failed:",c)})},[]),h=n.useMemo(()=>{if(!l)return;const e=l.preset||"default",c=q.getPreset(e);return{highlight:{color:c.highlight.color,width:l.highlight?.width??c.highlight.width},text:{color:c.handText.color,width:l.text?.width??c.handText.width}}},[l]);n.useEffect(()=>{if(!(!v.current||!p.current)){try{t.current=new j.AnnotationRenderer({canvasElement:v.current,container:p.current,strokeConfig:h}),F(!0)}catch(e){console.error("AnnotPdf: Failed to initialize renderer:",e),r&&r(e)}return()=>{F(!1),t.current&&(t.current.destroy(),t.current=null)}}},[]),n.useEffect(()=>{if(!i||!y)return;let e=!1;return u(async()=>{if(t.current)try{const s=await t.current.loadPDF(y);if(e)return;if(!s.success){console.error("AnnotPdf: Failed to load PDF:",s.error),r&&r(new Error(s.error));return}m&&m({pageCount:s.pageCount})}catch(s){if(e)return;console.error("AnnotPdf: Failed to load PDF:",s),r&&r(s)}}),()=>{e=!0}},[y,i,u]),n.useEffect(()=>{!i||!o||typeof o!="number"||u(async()=>{if(t.current)try{const e=await t.current.setPage(o);if(!e.success){console.error("AnnotPdf: Failed to set page:",e.error),r&&r(new Error(e.error));return}w&&w(o)}catch(e){console.error("AnnotPdf: Failed to set page:",e),r&&r(e)}})},[o,i,u]),n.useEffect(()=>{!i||!a||typeof a!="number"||u(async()=>{if(t.current)try{const e=await t.current.setScale(a);e.success||(console.error("AnnotPdf: Failed to set scale:",e.error),r&&r(new Error(e.error)))}catch(e){console.error("AnnotPdf: Failed to set scale:",e),r&&r(e)}})},[a,i,u]),n.useEffect(()=>{if(!(!i||!t.current))try{t.current.setAnnotations(g||[])}catch(e){console.error("AnnotPdf: Failed to set annotations:",e),r&&r(e)}},[g,i]),n.useEffect(()=>{if(!f&&!(!i||!t.current||d===void 0||d===null))try{t.current.setTime(d)}catch(e){console.error("AnnotPdf: Failed to set time:",e),r&&r(e)}},[d,f,i]),n.useEffect(()=>{if(!f?.current||!i||!t.current)return;const e=f.current,c=()=>{t.current&&t.current.startContinuousSync(()=>e.currentTime)},s=()=>{t.current&&(t.current.stopContinuousSync(),t.current.setTime(e.currentTime))},R=()=>{t.current&&t.current.setTime(e.currentTime)};return e.addEventListener("play",c),e.addEventListener("pause",s),e.addEventListener("ended",s),e.addEventListener("seeked",R),e.paused||c(),()=>{e.removeEventListener("play",c),e.removeEventListener("pause",s),e.removeEventListener("ended",s),e.removeEventListener("seeked",R),t.current&&t.current.stopContinuousSync()}},[f,i]);const S=n.useRef(!0);n.useEffect(()=>{if(S.current){S.current=!1;return}if(t.current&&h)try{t.current.updateStrokeConfig(h)}catch(e){console.error("AnnotPdf: Failed to update stroke config:",e),r&&r(e)}},[h]);const L={position:"relative",display:"inline-block",lineHeight:0,...x},k={position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"hidden"},T={display:"block",...C};return P.jsxs("div",{className:b,style:L,children:[P.jsx("canvas",{ref:v,style:T}),P.jsx("div",{ref:p,style:k})]})}exports.default=E;
2
2
  //# sourceMappingURL=index12.cjs.map