@embedpdf/engine-core 3.0.0-next.13 → 3.0.0-next.14

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 (58) hide show
  1. package/dist/{AbortError-DHqPBnYc.js → AbortError-DwuHPK_I.js} +2 -2
  2. package/dist/{AbortError-DHqPBnYc.js.map → AbortError-DwuHPK_I.js.map} +1 -1
  3. package/dist/{AbortError-Cq2igpZ6.cjs → AbortError-P0RU0Mgg.cjs} +4 -4
  4. package/dist/{AbortError-Cq2igpZ6.cjs.map → AbortError-P0RU0Mgg.cjs.map} +1 -1
  5. package/dist/{AnnotationListSnapshot-D3mFut1e.d.cts → AnnotationListSnapshot-D9R5n2Kf.d.cts} +237 -7
  6. package/dist/{AnnotationListSnapshot-D3mFut1e.d.ts → AnnotationListSnapshot-D9R5n2Kf.d.ts} +237 -7
  7. package/dist/{DocumentSecurityService-ClTZc0zO.d.cts → DocumentSecurityService-CIx1MT0T.d.cts} +2 -2
  8. package/dist/{DocumentSecurityService-_JRjqvoI.d.ts → DocumentSecurityService-Ca6EK3-3.d.ts} +2 -2
  9. package/dist/{Engine-Bx0NOfmd.d.cts → Engine-EWWHhEIi.d.ts} +17 -4
  10. package/dist/{Engine-DxtpCYcP.d.ts → Engine-FNaAEjfb.d.cts} +17 -4
  11. package/dist/conformance.cjs +382 -95
  12. package/dist/conformance.cjs.map +1 -1
  13. package/dist/conformance.d.cts +7 -3
  14. package/dist/conformance.d.ts +7 -3
  15. package/dist/conformance.js +302 -16
  16. package/dist/conformance.js.map +1 -1
  17. package/dist/derive-BbsDk_Kz.cjs +880 -0
  18. package/dist/derive-BbsDk_Kz.cjs.map +1 -0
  19. package/dist/derive-DAFJolWu.js +647 -0
  20. package/dist/derive-DAFJolWu.js.map +1 -0
  21. package/dist/{PageInsertBlankInput-cHq9-i-z.js → format-Bbphf4zR.js} +59 -2
  22. package/dist/format-Bbphf4zR.js.map +1 -0
  23. package/dist/{PageInsertBlankInput-CqXBmFhN.cjs → format-D_epWlob.cjs} +70 -1
  24. package/dist/format-D_epWlob.cjs.map +1 -0
  25. package/dist/index.cjs +127 -107
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +4 -4
  29. package/dist/runtime.cjs +137 -117
  30. package/dist/runtime.cjs.map +1 -1
  31. package/dist/runtime.d.cts +29 -5
  32. package/dist/runtime.d.ts +29 -5
  33. package/dist/runtime.js +5 -5
  34. package/dist/{schemas-BLARNCgx.js → schemas-CFQGvWiu.js} +134 -4
  35. package/dist/schemas-CFQGvWiu.js.map +1 -0
  36. package/dist/{schemas-DIqFMmrC.cjs → schemas-D0g6tKa9.cjs} +250 -24
  37. package/dist/schemas-D0g6tKa9.cjs.map +1 -0
  38. package/dist/{builders-Bqm8yTpi.cjs → viewport-BWeNHZmb.cjs} +71 -132
  39. package/dist/viewport-BWeNHZmb.cjs.map +1 -0
  40. package/dist/{builders-Dqo2X-dt.js → viewport-CvMcadfQ.js} +39 -88
  41. package/dist/viewport-CvMcadfQ.js.map +1 -0
  42. package/dist/wire.cjs +25 -2
  43. package/dist/wire.cjs.map +1 -1
  44. package/dist/wire.d.cts +2739 -8
  45. package/dist/wire.d.ts +2739 -8
  46. package/dist/wire.js +10 -3
  47. package/dist/wire.js.map +1 -1
  48. package/package.json +1 -1
  49. package/dist/PageInsertBlankInput-CqXBmFhN.cjs.map +0 -1
  50. package/dist/PageInsertBlankInput-cHq9-i-z.js.map +0 -1
  51. package/dist/builders-Bqm8yTpi.cjs.map +0 -1
  52. package/dist/builders-Dqo2X-dt.js.map +0 -1
  53. package/dist/fold-2V29cxCV.cjs +0 -447
  54. package/dist/fold-2V29cxCV.cjs.map +0 -1
  55. package/dist/fold-CdEJTBTn.js +0 -334
  56. package/dist/fold-CdEJTBTn.js.map +0 -1
  57. package/dist/schemas-BLARNCgx.js.map +0 -1
  58. package/dist/schemas-DIqFMmrC.cjs.map +0 -1
@@ -1,447 +0,0 @@
1
- const require_PageInsertBlankInput = require("./PageInsertBlankInput-CqXBmFhN.cjs");
2
- //#region src/geometry/convert.ts
3
- /**
4
- * Normalize a `PdfRect` to the y-up invariant (`left <= right`, `bottom <= top`),
5
- * regardless of how the PDF ordered the corners (a `/Rect` array or `FS_RECTF`
6
- * may carry them in any order). THE enforcement point for the "PdfRect is always
7
- * normalized" rule: every producer that reads a raw box from PDFium passes it
8
- * through here, so the invariant holds once, centrally — downstream `width =
9
- * right - left` is never negative.
10
- */
11
- function normalizePdfRect(r) {
12
- return {
13
- left: Math.min(r.left, r.right),
14
- right: Math.max(r.left, r.right),
15
- bottom: Math.min(r.top, r.bottom),
16
- top: Math.max(r.top, r.bottom)
17
- };
18
- }
19
- function pdfRectWidth(r) {
20
- return r.right - r.left;
21
- }
22
- function pdfRectHeight(r) {
23
- return r.top - r.bottom;
24
- }
25
- function pdfRectSize(r) {
26
- return {
27
- width: r.right - r.left,
28
- height: r.top - r.bottom
29
- };
30
- }
31
- /** Convert edges -> origin+size, staying y-up (origin at bottom-left). */
32
- function pdfRectToOriginSize(r) {
33
- return {
34
- x: r.left,
35
- y: r.bottom,
36
- width: r.right - r.left,
37
- height: r.top - r.bottom
38
- };
39
- }
40
- /** Convert y-up origin+size back to edges. */
41
- function pdfRectFromOriginSize(o) {
42
- return {
43
- left: o.x,
44
- bottom: o.y,
45
- right: o.x + o.width,
46
- top: o.y + o.height
47
- };
48
- }
49
- /**
50
- * Enclosing axis-aligned box of a quad, in PDF user space. Orientation
51
- * agnostic (correct for rotated/skewed quads) — this is what highlight
52
- * rendering and hit-testing want.
53
- */
54
- function pdfQuadBounds(q) {
55
- const xs = [
56
- q.p1.x,
57
- q.p2.x,
58
- q.p3.x,
59
- q.p4.x
60
- ];
61
- const ys = [
62
- q.p1.y,
63
- q.p2.y,
64
- q.p3.y,
65
- q.p4.y
66
- ];
67
- return {
68
- left: Math.min(...xs),
69
- right: Math.max(...xs),
70
- bottom: Math.min(...ys),
71
- top: Math.max(...ys)
72
- };
73
- }
74
- /**
75
- * Axis-aligned named-corner interpretation of a quad.
76
- *
77
- * VALID ONLY for upright (non-rotated, non-skewed) quads: it is derived from
78
- * the enclosing bounds, so for rotated/skewed quads it returns the bounding
79
- * box corners, not the true geometric corners. For arbitrary quads use the
80
- * positional `p1..p4` or `pdfQuadBounds` directly.
81
- */
82
- function pdfQuadCorners(q) {
83
- const b = pdfQuadBounds(q);
84
- return {
85
- topLeft: {
86
- x: b.left,
87
- y: b.top
88
- },
89
- topRight: {
90
- x: b.right,
91
- y: b.top
92
- },
93
- bottomLeft: {
94
- x: b.left,
95
- y: b.bottom
96
- },
97
- bottomRight: {
98
- x: b.right,
99
- y: b.bottom
100
- }
101
- };
102
- }
103
- /**
104
- * Build a quad from named corners, in PDFium `FS_QUADPOINTSF` slot order
105
- * (`p1 = topLeft`, `p2 = topRight`, `p3 = bottomLeft`, `p4 = bottomRight`).
106
- * The inverse of `pdfQuadCorners` for upright quads.
107
- */
108
- function pdfQuadFromCorners(c) {
109
- return {
110
- p1: c.topLeft,
111
- p2: c.topRight,
112
- p3: c.bottomLeft,
113
- p4: c.bottomRight
114
- };
115
- }
116
- //#endregion
117
- //#region src/dto/PageGeometrySnapshot.ts
118
- /** Narrowing guard: is this run the rotated (non-upright) variant? */
119
- function isRotatedGeometryRun(run) {
120
- return "rotation" in run;
121
- }
122
- /**
123
- * Uniform oriented-cell view over either run variant: the glyph's loose cell
124
- * as a quad (synthesized from the box corners when the run is upright, in
125
- * the same frame-geometric slot order).
126
- */
127
- function glyphLooseQuad(run, index) {
128
- if (isRotatedGeometryRun(run)) return run.glyphs[index].looseQuad;
129
- const b = run.glyphs[index].looseBox;
130
- return {
131
- p1: {
132
- x: b.left,
133
- y: b.top
134
- },
135
- p2: {
136
- x: b.right,
137
- y: b.top
138
- },
139
- p3: {
140
- x: b.left,
141
- y: b.bottom
142
- },
143
- p4: {
144
- x: b.right,
145
- y: b.bottom
146
- }
147
- };
148
- }
149
- /**
150
- * Uniform AABB view over either run variant: the glyph's loose box, or the
151
- * enclosing bounds of its oriented cell when the run is rotated. The
152
- * conservative envelope for consumers that genuinely want a box (culling,
153
- * scroll targets) — never a substitute for handling orientation in geometry
154
- * that gets DRAWN.
155
- */
156
- function glyphLooseBounds(run, index) {
157
- if (isRotatedGeometryRun(run)) return pdfQuadBounds(run.glyphs[index].looseQuad);
158
- return run.glyphs[index].looseBox;
159
- }
160
- //#endregion
161
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
162
- function _typeof(o) {
163
- "@babel/helpers - typeof";
164
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
165
- return typeof o;
166
- } : function(o) {
167
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
168
- }, _typeof(o);
169
- }
170
- //#endregion
171
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
172
- function toPrimitive(t, r) {
173
- if ("object" != _typeof(t) || !t) return t;
174
- var e = t[Symbol.toPrimitive];
175
- if (void 0 !== e) {
176
- var i = e.call(t, r || "default");
177
- if ("object" != _typeof(i)) return i;
178
- throw new TypeError("@@toPrimitive must return a primitive value.");
179
- }
180
- return ("string" === r ? String : Number)(t);
181
- }
182
- //#endregion
183
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
184
- function toPropertyKey(t) {
185
- var i = toPrimitive(t, "string");
186
- return "symbol" == _typeof(i) ? i : i + "";
187
- }
188
- //#endregion
189
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
190
- function _defineProperty(e, r, t) {
191
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
192
- value: t,
193
- enumerable: !0,
194
- configurable: !0,
195
- writable: !0
196
- }) : e[r] = t, e;
197
- }
198
- //#endregion
199
- //#region src/errors/EngineError.ts
200
- /**
201
- * Single error class shared across engine implementations. Has a stable
202
- * machine-readable `code` (see EngineErrorCode) so callers can match without
203
- * sniffing message strings.
204
- */
205
- var EngineError = class EngineError extends Error {
206
- constructor(code, message, opts = {}) {
207
- super(message ?? code, opts.cause === void 0 ? void 0 : { cause: opts.cause });
208
- _defineProperty(this, "name", "EngineError");
209
- _defineProperty(this, "code", void 0);
210
- _defineProperty(this, "details", void 0);
211
- this.code = code;
212
- this.details = opts.details;
213
- }
214
- static is(value, code) {
215
- if (!(value instanceof EngineError) && value?.name !== "EngineError") return false;
216
- if (code === void 0) return true;
217
- return value.code === code;
218
- }
219
- toJSON() {
220
- return {
221
- name: "EngineError",
222
- code: this.code,
223
- message: this.message,
224
- details: this.details
225
- };
226
- }
227
- };
228
- function serializeError(err) {
229
- if (EngineError.is(err)) return err.toJSON();
230
- if (err instanceof Error) return {
231
- name: "EngineError",
232
- code: err.name === "AbortError" ? require_PageInsertBlankInput.EngineErrorCode.Aborted : require_PageInsertBlankInput.EngineErrorCode.Unknown,
233
- message: err.message
234
- };
235
- return {
236
- name: "EngineError",
237
- code: require_PageInsertBlankInput.EngineErrorCode.Unknown,
238
- message: String(err ?? "unknown error")
239
- };
240
- }
241
- function deserializeError(payload) {
242
- return new EngineError(payload.code, payload.message, { details: payload.details });
243
- }
244
- //#endregion
245
- //#region src/search/fold.ts
246
- /**
247
- * Text folding for literal search: the deterministic normalization applied
248
- * to BOTH the page text and the needle so that "Café" finds "cafe" and a
249
- * line-wrapped "hello\n world" finds "hello world".
250
- *
251
- * Fold version 1:
252
- * - whitespace runs collapse to a single space (any `\s`, including the
253
- * spaces some compatibility decompositions emit),
254
- * - each code point is NFKD-decomposed (ligatures split: "fi" → "fi",
255
- * "²" → "2"),
256
- * - combining marks are stripped unless `keepMarks`,
257
- * - case is folded via upper→lower round-trip unless `keepCase` (this
258
- * poor-man's full fold catches "ß"→"ss" and "ς"→"σ", which a plain
259
- * `toLowerCase` misses).
260
- *
261
- * Every folded code unit remembers which original code point produced it
262
- * (`map`), so match ranges found in folded space translate back to exact
263
- * original-text ranges — the property the whole anchor stage rests on.
264
- *
265
- * Pre-folded corpus artifacts store this fold's output; bump
266
- * `SEARCH_FOLD_VERSION` on ANY semantic change so stored corpora are
267
- * rebuilt instead of silently mismatching fresh needles.
268
- */
269
- /** Version stamp for persisted pre-folded corpus artifacts. */
270
- const SEARCH_FOLD_VERSION = 1;
271
- const WHITESPACE = /\s/;
272
- const MARKS = /\p{M}/gu;
273
- function foldText(original, options = {}) {
274
- const units = [];
275
- const map = [];
276
- let lastWasSpace = false;
277
- let index = 0;
278
- for (const cp of original) {
279
- let piece;
280
- if (WHITESPACE.test(cp)) piece = " ";
281
- else {
282
- piece = cp.normalize("NFKD");
283
- if (!options.keepMarks) piece = piece.replace(MARKS, "");
284
- if (!options.keepCase) piece = piece.toUpperCase().toLowerCase();
285
- }
286
- for (let u = 0; u < piece.length; u++) {
287
- const unit = piece[u];
288
- if (WHITESPACE.test(unit)) {
289
- if (lastWasSpace) continue;
290
- units.push(" ");
291
- map.push(index);
292
- lastWasSpace = true;
293
- } else {
294
- units.push(unit);
295
- map.push(index);
296
- lastWasSpace = false;
297
- }
298
- }
299
- index += cp.length;
300
- }
301
- return {
302
- folded: units.join(""),
303
- map: Uint32Array.from(map),
304
- original
305
- };
306
- }
307
- /** Code-unit length of the code point starting at `index` (1 or 2). */
308
- function codePointLengthAt(text, index) {
309
- const unit = text.charCodeAt(index);
310
- if (unit >= 55296 && unit <= 56319 && index + 1 < text.length) {
311
- const next = text.charCodeAt(index + 1);
312
- if (next >= 56320 && next <= 57343) return 2;
313
- }
314
- return 1;
315
- }
316
- /**
317
- * Translate a match found in folded space back to the original text.
318
- * The range covers whole original code points: a hit on either folded
319
- * half of "fi" spans the full ligature, and a hit ending on a collapsed
320
- * space extends only through the first whitespace char of the run (the
321
- * remainder is presentation, not match).
322
- */
323
- function toOriginalRange(folded, foldedStart, foldedLength) {
324
- const start = folded.map[foldedStart];
325
- const lastOriginal = folded.map[foldedStart + foldedLength - 1];
326
- return {
327
- start,
328
- length: lastOriginal + codePointLengthAt(folded.original, lastOriginal) - start
329
- };
330
- }
331
- //#endregion
332
- Object.defineProperty(exports, "EngineError", {
333
- enumerable: true,
334
- get: function() {
335
- return EngineError;
336
- }
337
- });
338
- Object.defineProperty(exports, "SEARCH_FOLD_VERSION", {
339
- enumerable: true,
340
- get: function() {
341
- return SEARCH_FOLD_VERSION;
342
- }
343
- });
344
- Object.defineProperty(exports, "_defineProperty", {
345
- enumerable: true,
346
- get: function() {
347
- return _defineProperty;
348
- }
349
- });
350
- Object.defineProperty(exports, "deserializeError", {
351
- enumerable: true,
352
- get: function() {
353
- return deserializeError;
354
- }
355
- });
356
- Object.defineProperty(exports, "foldText", {
357
- enumerable: true,
358
- get: function() {
359
- return foldText;
360
- }
361
- });
362
- Object.defineProperty(exports, "glyphLooseBounds", {
363
- enumerable: true,
364
- get: function() {
365
- return glyphLooseBounds;
366
- }
367
- });
368
- Object.defineProperty(exports, "glyphLooseQuad", {
369
- enumerable: true,
370
- get: function() {
371
- return glyphLooseQuad;
372
- }
373
- });
374
- Object.defineProperty(exports, "isRotatedGeometryRun", {
375
- enumerable: true,
376
- get: function() {
377
- return isRotatedGeometryRun;
378
- }
379
- });
380
- Object.defineProperty(exports, "normalizePdfRect", {
381
- enumerable: true,
382
- get: function() {
383
- return normalizePdfRect;
384
- }
385
- });
386
- Object.defineProperty(exports, "pdfQuadBounds", {
387
- enumerable: true,
388
- get: function() {
389
- return pdfQuadBounds;
390
- }
391
- });
392
- Object.defineProperty(exports, "pdfQuadCorners", {
393
- enumerable: true,
394
- get: function() {
395
- return pdfQuadCorners;
396
- }
397
- });
398
- Object.defineProperty(exports, "pdfQuadFromCorners", {
399
- enumerable: true,
400
- get: function() {
401
- return pdfQuadFromCorners;
402
- }
403
- });
404
- Object.defineProperty(exports, "pdfRectFromOriginSize", {
405
- enumerable: true,
406
- get: function() {
407
- return pdfRectFromOriginSize;
408
- }
409
- });
410
- Object.defineProperty(exports, "pdfRectHeight", {
411
- enumerable: true,
412
- get: function() {
413
- return pdfRectHeight;
414
- }
415
- });
416
- Object.defineProperty(exports, "pdfRectSize", {
417
- enumerable: true,
418
- get: function() {
419
- return pdfRectSize;
420
- }
421
- });
422
- Object.defineProperty(exports, "pdfRectToOriginSize", {
423
- enumerable: true,
424
- get: function() {
425
- return pdfRectToOriginSize;
426
- }
427
- });
428
- Object.defineProperty(exports, "pdfRectWidth", {
429
- enumerable: true,
430
- get: function() {
431
- return pdfRectWidth;
432
- }
433
- });
434
- Object.defineProperty(exports, "serializeError", {
435
- enumerable: true,
436
- get: function() {
437
- return serializeError;
438
- }
439
- });
440
- Object.defineProperty(exports, "toOriginalRange", {
441
- enumerable: true,
442
- get: function() {
443
- return toOriginalRange;
444
- }
445
- });
446
-
447
- //# sourceMappingURL=fold-2V29cxCV.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fold-2V29cxCV.cjs","names":["EngineErrorCode"],"sources":["../src/geometry/convert.ts","../src/dto/PageGeometrySnapshot.ts","../src/errors/EngineError.ts","../src/search/fold.ts"],"sourcesContent":["/**\n * PDF-space-internal geometry helpers.\n *\n * These operate ENTIRELY within PDF user space (y-up, edges). They never\n * produce viewer-local (y-down) geometry — that conversion needs the crop box\n * plus rotation/scale and lives in the v3 viewer layer (the `Mat2D` matrix\n * model), never here.\n */\n\nimport type { PdfPoint, PdfQuad, PdfRect, PdfSize } from './primitives';\n\n/** Origin + size form of a `PdfRect`, still y-up (origin = bottom-left). */\nexport interface PdfOriginSize {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Normalize a `PdfRect` to the y-up invariant (`left <= right`, `bottom <= top`),\n * regardless of how the PDF ordered the corners (a `/Rect` array or `FS_RECTF`\n * may carry them in any order). THE enforcement point for the \"PdfRect is always\n * normalized\" rule: every producer that reads a raw box from PDFium passes it\n * through here, so the invariant holds once, centrally — downstream `width =\n * right - left` is never negative.\n */\nexport function normalizePdfRect(r: PdfRect): PdfRect {\n return {\n left: Math.min(r.left, r.right),\n right: Math.max(r.left, r.right),\n bottom: Math.min(r.top, r.bottom),\n top: Math.max(r.top, r.bottom),\n };\n}\n\nexport function pdfRectWidth(r: PdfRect): number {\n return r.right - r.left;\n}\n\nexport function pdfRectHeight(r: PdfRect): number {\n return r.top - r.bottom;\n}\n\nexport function pdfRectSize(r: PdfRect): PdfSize {\n return { width: r.right - r.left, height: r.top - r.bottom };\n}\n\n/** Convert edges -> origin+size, staying y-up (origin at bottom-left). */\nexport function pdfRectToOriginSize(r: PdfRect): PdfOriginSize {\n return { x: r.left, y: r.bottom, width: r.right - r.left, height: r.top - r.bottom };\n}\n\n/** Convert y-up origin+size back to edges. */\nexport function pdfRectFromOriginSize(o: PdfOriginSize): PdfRect {\n return { left: o.x, bottom: o.y, right: o.x + o.width, top: o.y + o.height };\n}\n\n/**\n * Enclosing axis-aligned box of a quad, in PDF user space. Orientation\n * agnostic (correct for rotated/skewed quads) — this is what highlight\n * rendering and hit-testing want.\n */\nexport function pdfQuadBounds(q: PdfQuad): PdfRect {\n const xs = [q.p1.x, q.p2.x, q.p3.x, q.p4.x];\n const ys = [q.p1.y, q.p2.y, q.p3.y, q.p4.y];\n return {\n left: Math.min(...xs),\n right: Math.max(...xs),\n bottom: Math.min(...ys),\n top: Math.max(...ys),\n };\n}\n\n/** Named corners of a quad, in PDF user space (y-up). */\nexport interface PdfQuadCorners {\n topLeft: PdfPoint;\n topRight: PdfPoint;\n bottomLeft: PdfPoint;\n bottomRight: PdfPoint;\n}\n\n/**\n * Axis-aligned named-corner interpretation of a quad.\n *\n * VALID ONLY for upright (non-rotated, non-skewed) quads: it is derived from\n * the enclosing bounds, so for rotated/skewed quads it returns the bounding\n * box corners, not the true geometric corners. For arbitrary quads use the\n * positional `p1..p4` or `pdfQuadBounds` directly.\n */\nexport function pdfQuadCorners(q: PdfQuad): PdfQuadCorners {\n const b = pdfQuadBounds(q);\n return {\n topLeft: { x: b.left, y: b.top },\n topRight: { x: b.right, y: b.top },\n bottomLeft: { x: b.left, y: b.bottom },\n bottomRight: { x: b.right, y: b.bottom },\n };\n}\n\n/**\n * Build a quad from named corners, in PDFium `FS_QUADPOINTSF` slot order\n * (`p1 = topLeft`, `p2 = topRight`, `p3 = bottomLeft`, `p4 = bottomRight`).\n * The inverse of `pdfQuadCorners` for upright quads.\n */\nexport function pdfQuadFromCorners(c: PdfQuadCorners): PdfQuad {\n return { p1: c.topLeft, p2: c.topRight, p3: c.bottomLeft, p4: c.bottomRight };\n}\n","import { pdfQuadBounds } from '../geometry/convert';\nimport type { PdfQuad, PdfRect } from '../geometry/primitives';\n\n/**\n * One upright glyph's geometry in PDF user space (y-up edges).\n *\n * `looseBox` is the loose char cell (pdfium `FPDFText_GetLooseCharBox`): the\n * font-metric box covering the full glyph cell without regard to the actual\n * glyph shape. Always present (zeroed + flagged empty for degenerate glyphs);\n * it's the box selection envelopes are built from.\n *\n * `tightBox` is the tight char box (pdfium `FPDFText_GetCharBox`): the box\n * hugging the actual glyph shape. Optional — absent for empty/whitespace\n * glyphs that have no real outline.\n *\n * `flags` carries slim per-glyph state (bit 1 = space, bit 2 = empty).\n */\nexport interface PageGeometryGlyph {\n looseBox: PdfRect;\n flags: number;\n tightBox?: PdfRect;\n}\n\n/**\n * One non-upright glyph's geometry: the exact oriented cells, in PDF user\n * space (page coordinates — NOT a local frame). The corner SLOTS are\n * frame-geometric in the glyph's own upright frame:\n * `p1` = upper-start, `p2` = upper-end, `p3` = lower-start, `p4` = lower-end,\n * where \"upper\" is the ascent side and \"start\" is the frame's minimum-x side.\n * Deliberately NOT a bidi/reading-order statement — advance direction is a\n * glyph-sequence concern, carried separately where consumers need it.\n *\n * Degenerate glyphs carry a zeroed `looseQuad` plus the empty flag (bit 2),\n * mirroring the upright variant's zeroed-box convention. `flags` bits match\n * {@link PageGeometryGlyph.flags}.\n */\nexport interface RotatedGeometryGlyph {\n looseQuad: PdfQuad;\n flags: number;\n tightQuad?: PdfQuad;\n}\n\n/**\n * A run whose char matrix is upright — byte-identical to the wire shape that\n * predates orientation support, so upright documents never pay for it.\n */\nexport interface UprightGeometryRun {\n rect: PdfRect;\n charStart: number;\n glyphs: PageGeometryGlyph[];\n fontSize?: number;\n}\n\n/**\n * A run whose char matrix is NOT upright (rotated, sheared, or mirrored).\n *\n * `rect` stays a page-space AABB (culling), like every other wire rect.\n * `rotation` is the baseline angle in radians, CCW in PDF y-up space\n * (`atan2(m.b, m.a)` of the run's char matrix). Note a shear-only run has\n * `rotation === 0` and still uses this variant — its cells are\n * parallelograms an AABB would misrepresent. `ascentFlip` is true when the\n * ascent vector maps opposite the rotated frame's +y (mirrored /\n * negative-determinant content).\n */\nexport interface RotatedGeometryRun {\n rect: PdfRect;\n charStart: number;\n glyphs: RotatedGeometryGlyph[];\n rotation: number;\n ascentFlip: boolean;\n fontSize?: number;\n}\n\n/**\n * One text run (contiguous glyphs sharing a text object and orientation).\n * A discriminated union so consumers CANNOT read axis-aligned boxes off\n * rotated text by accident — handling orientation is a compile-time\n * obligation, not a runtime discovery. Narrow with\n * {@link isRotatedGeometryRun}, or use the uniform {@link glyphLooseQuad} /\n * {@link glyphLooseBounds} views.\n */\nexport type PageGeometryRun = UprightGeometryRun | RotatedGeometryRun;\n\n/**\n * Geometry-only text layout for one page, in PDF user space (y-up). The v3\n * viewer converts to content/view space via the page geometry matrix.\n *\n * Pure content, addressed and cached by `contentVersion`. Carries NO\n * annotation liveness envelope (`PageState`) — see `PageTextSnapshot` for\n * the rationale; liveness lives on annotation reads.\n */\nexport interface PageGeometrySnapshot {\n runs: PageGeometryRun[];\n}\n\n/** Narrowing guard: is this run the rotated (non-upright) variant? */\nexport function isRotatedGeometryRun(run: PageGeometryRun): run is RotatedGeometryRun {\n return 'rotation' in run;\n}\n\n/**\n * Uniform oriented-cell view over either run variant: the glyph's loose cell\n * as a quad (synthesized from the box corners when the run is upright, in\n * the same frame-geometric slot order).\n */\nexport function glyphLooseQuad(run: PageGeometryRun, index: number): PdfQuad {\n if (isRotatedGeometryRun(run)) return run.glyphs[index].looseQuad;\n const b = run.glyphs[index].looseBox;\n return {\n p1: { x: b.left, y: b.top },\n p2: { x: b.right, y: b.top },\n p3: { x: b.left, y: b.bottom },\n p4: { x: b.right, y: b.bottom },\n };\n}\n\n/**\n * Uniform AABB view over either run variant: the glyph's loose box, or the\n * enclosing bounds of its oriented cell when the run is rotated. The\n * conservative envelope for consumers that genuinely want a box (culling,\n * scroll targets) — never a substitute for handling orientation in geometry\n * that gets DRAWN.\n */\nexport function glyphLooseBounds(run: PageGeometryRun, index: number): PdfRect {\n if (isRotatedGeometryRun(run)) return pdfQuadBounds(run.glyphs[index].looseQuad);\n return run.glyphs[index].looseBox;\n}\n","import { EngineErrorCode } from './EngineErrorCode';\n\nexport interface EngineErrorOptions {\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\n/**\n * Single error class shared across engine implementations. Has a stable\n * machine-readable `code` (see EngineErrorCode) so callers can match without\n * sniffing message strings.\n */\nexport class EngineError extends Error {\n override readonly name = 'EngineError';\n readonly code: EngineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(code: EngineErrorCode, message?: string, opts: EngineErrorOptions = {}) {\n super(message ?? code, opts.cause === undefined ? undefined : { cause: opts.cause });\n this.code = code;\n this.details = opts.details;\n }\n\n static is(value: unknown, code?: EngineErrorCode): value is EngineError {\n if (\n !(value instanceof EngineError) &&\n (value as { name?: string } | null)?.name !== 'EngineError'\n ) {\n return false;\n }\n if (code === undefined) return true;\n return (value as EngineError).code === code;\n }\n\n toJSON(): {\n name: 'EngineError';\n code: EngineErrorCode;\n message: string;\n details?: Record<string, unknown>;\n } {\n return {\n name: 'EngineError',\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n\nexport interface SerializedEngineError {\n name: 'EngineError';\n code: EngineErrorCode;\n message: string;\n details?: Record<string, unknown>;\n}\n\nexport function serializeError(err: unknown): SerializedEngineError {\n if (EngineError.is(err)) {\n return err.toJSON();\n }\n if (err instanceof Error) {\n const code: EngineErrorCode =\n err.name === 'AbortError' ? EngineErrorCode.Aborted : EngineErrorCode.Unknown;\n return { name: 'EngineError', code, message: err.message };\n }\n return {\n name: 'EngineError',\n code: EngineErrorCode.Unknown,\n message: String(err ?? 'unknown error'),\n };\n}\n\nexport function deserializeError(payload: SerializedEngineError): EngineError {\n return new EngineError(payload.code, payload.message, { details: payload.details });\n}\n","/**\n * Text folding for literal search: the deterministic normalization applied\n * to BOTH the page text and the needle so that \"Café\" finds \"cafe\" and a\n * line-wrapped \"hello\\n world\" finds \"hello world\".\n *\n * Fold version 1:\n * - whitespace runs collapse to a single space (any `\\s`, including the\n * spaces some compatibility decompositions emit),\n * - each code point is NFKD-decomposed (ligatures split: \"fi\" → \"fi\",\n * \"²\" → \"2\"),\n * - combining marks are stripped unless `keepMarks`,\n * - case is folded via upper→lower round-trip unless `keepCase` (this\n * poor-man's full fold catches \"ß\"→\"ss\" and \"ς\"→\"σ\", which a plain\n * `toLowerCase` misses).\n *\n * Every folded code unit remembers which original code point produced it\n * (`map`), so match ranges found in folded space translate back to exact\n * original-text ranges — the property the whole anchor stage rests on.\n *\n * Pre-folded corpus artifacts store this fold's output; bump\n * `SEARCH_FOLD_VERSION` on ANY semantic change so stored corpora are\n * rebuilt instead of silently mismatching fresh needles.\n */\n\n/** Version stamp for persisted pre-folded corpus artifacts. */\nexport const SEARCH_FOLD_VERSION = 1;\n\nexport interface FoldOptions {\n /** Preserve case (matchCase). */\n keepCase?: boolean;\n /** Preserve combining marks (matchDiacritics). */\n keepMarks?: boolean;\n}\n\nexport interface FoldedText {\n folded: string;\n /** Folded code unit i → code-unit index of the original code point it came from. */\n map: Uint32Array;\n original: string;\n}\n\n/** A half-open match range in ORIGINAL code-unit space. */\nexport interface SearchMatchRange {\n start: number;\n length: number;\n}\n\nconst WHITESPACE = /\\s/;\nconst MARKS = /\\p{M}/gu;\n\nexport function foldText(original: string, options: FoldOptions = {}): FoldedText {\n const units: string[] = [];\n const map: number[] = [];\n let lastWasSpace = false;\n\n let index = 0;\n for (const cp of original) {\n let piece: string;\n if (WHITESPACE.test(cp)) {\n piece = ' ';\n } else {\n piece = cp.normalize('NFKD');\n if (!options.keepMarks) piece = piece.replace(MARKS, '');\n if (!options.keepCase) piece = piece.toUpperCase().toLowerCase();\n }\n // A decomposition can itself contain whitespace (U+00A8 → space +\n // combining diaeresis), so collapse runs at the unit level, not just\n // for source whitespace.\n for (let u = 0; u < piece.length; u++) {\n const unit = piece[u];\n if (WHITESPACE.test(unit)) {\n if (lastWasSpace) continue;\n units.push(' ');\n map.push(index);\n lastWasSpace = true;\n } else {\n units.push(unit);\n map.push(index);\n lastWasSpace = false;\n }\n }\n index += cp.length;\n }\n\n return { folded: units.join(''), map: Uint32Array.from(map), original };\n}\n\n/** Code-unit length of the code point starting at `index` (1 or 2). */\nfunction codePointLengthAt(text: string, index: number): number {\n const unit = text.charCodeAt(index);\n if (unit >= 0xd800 && unit <= 0xdbff && index + 1 < text.length) {\n const next = text.charCodeAt(index + 1);\n if (next >= 0xdc00 && next <= 0xdfff) return 2;\n }\n return 1;\n}\n\n/**\n * Translate a match found in folded space back to the original text.\n * The range covers whole original code points: a hit on either folded\n * half of \"fi\" spans the full ligature, and a hit ending on a collapsed\n * space extends only through the first whitespace char of the run (the\n * remainder is presentation, not match).\n */\nexport function toOriginalRange(\n folded: FoldedText,\n foldedStart: number,\n foldedLength: number,\n): SearchMatchRange {\n const start = folded.map[foldedStart];\n const lastOriginal = folded.map[foldedStart + foldedLength - 1];\n const end = lastOriginal + codePointLengthAt(folded.original, lastOriginal);\n return { start, length: end - start };\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,iBAAiB,GAAqB;CACpD,OAAO;EACL,MAAM,KAAK,IAAI,EAAE,MAAM,EAAE,KAAK;EAC9B,OAAO,KAAK,IAAI,EAAE,MAAM,EAAE,KAAK;EAC/B,QAAQ,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM;EAChC,KAAK,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM;CAC/B;AACF;AAEA,SAAg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