@embedpdf/core-geometry 3.0.0-next.3 → 3.0.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +204 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +198 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -393,6 +393,203 @@ function pageGeometry(input, zoom) {
|
|
|
393
393
|
viewToPdf: invert(pdfToView)
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
|
+
/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */
|
|
397
|
+
function textQuadFromRect(r) {
|
|
398
|
+
return {
|
|
399
|
+
upperStart: {
|
|
400
|
+
x: r.x,
|
|
401
|
+
y: r.y
|
|
402
|
+
},
|
|
403
|
+
upperEnd: {
|
|
404
|
+
x: r.x + r.width,
|
|
405
|
+
y: r.y
|
|
406
|
+
},
|
|
407
|
+
lowerStart: {
|
|
408
|
+
x: r.x,
|
|
409
|
+
y: r.y + r.height
|
|
410
|
+
},
|
|
411
|
+
lowerEnd: {
|
|
412
|
+
x: r.x + r.width,
|
|
413
|
+
y: r.y + r.height
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */
|
|
418
|
+
function textQuadPoints(t) {
|
|
419
|
+
return [
|
|
420
|
+
t.upperStart,
|
|
421
|
+
t.upperEnd,
|
|
422
|
+
t.lowerStart,
|
|
423
|
+
t.lowerEnd
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */
|
|
427
|
+
function textQuadRing(t) {
|
|
428
|
+
return [
|
|
429
|
+
t.upperStart,
|
|
430
|
+
t.upperEnd,
|
|
431
|
+
t.lowerEnd,
|
|
432
|
+
t.lowerStart
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
/** Axis-aligned bounds of a TextQuad. */
|
|
436
|
+
function textQuadBounds(t) {
|
|
437
|
+
const xs = [
|
|
438
|
+
t.upperStart.x,
|
|
439
|
+
t.upperEnd.x,
|
|
440
|
+
t.lowerStart.x,
|
|
441
|
+
t.lowerEnd.x
|
|
442
|
+
];
|
|
443
|
+
const ys = [
|
|
444
|
+
t.upperStart.y,
|
|
445
|
+
t.upperEnd.y,
|
|
446
|
+
t.lowerStart.y,
|
|
447
|
+
t.lowerEnd.y
|
|
448
|
+
];
|
|
449
|
+
const minX = Math.min(...xs);
|
|
450
|
+
const minY = Math.min(...ys);
|
|
451
|
+
return {
|
|
452
|
+
x: minX,
|
|
453
|
+
y: minY,
|
|
454
|
+
width: Math.max(...xs) - minX,
|
|
455
|
+
height: Math.max(...ys) - minY
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
/** Map a TextQuad through an affine transform (corner semantics ride along). */
|
|
459
|
+
function applyTextQuad(m, t) {
|
|
460
|
+
return {
|
|
461
|
+
upperStart: applyPoint(m, t.upperStart),
|
|
462
|
+
upperEnd: applyPoint(m, t.upperEnd),
|
|
463
|
+
lowerStart: applyPoint(m, t.lowerStart),
|
|
464
|
+
lowerEnd: applyPoint(m, t.lowerEnd)
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */
|
|
468
|
+
function positionalQuad(t) {
|
|
469
|
+
return {
|
|
470
|
+
p1: t.upperStart,
|
|
471
|
+
p2: t.upperEnd,
|
|
472
|
+
p3: t.lowerStart,
|
|
473
|
+
p4: t.lowerEnd
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const QUAD_EPSILON = 1e-6;
|
|
477
|
+
function finitePoint(p) {
|
|
478
|
+
return Number.isFinite(p.x) && Number.isFinite(p.y);
|
|
479
|
+
}
|
|
480
|
+
/** Is `[us, ue, ls, le]` a well-formed zigzag reading of a quad? */
|
|
481
|
+
function zigzagWellFormed([us, ue, ls, le]) {
|
|
482
|
+
if (![
|
|
483
|
+
us,
|
|
484
|
+
ue,
|
|
485
|
+
ls,
|
|
486
|
+
le
|
|
487
|
+
].every(finitePoint)) return false;
|
|
488
|
+
const upper = {
|
|
489
|
+
x: ue.x - us.x,
|
|
490
|
+
y: ue.y - us.y
|
|
491
|
+
};
|
|
492
|
+
const lower = {
|
|
493
|
+
x: le.x - ls.x,
|
|
494
|
+
y: le.y - ls.y
|
|
495
|
+
};
|
|
496
|
+
const startSide = {
|
|
497
|
+
x: ls.x - us.x,
|
|
498
|
+
y: ls.y - us.y
|
|
499
|
+
};
|
|
500
|
+
const endSide = {
|
|
501
|
+
x: le.x - ue.x,
|
|
502
|
+
y: le.y - ue.y
|
|
503
|
+
};
|
|
504
|
+
const lenU = Math.hypot(upper.x, upper.y);
|
|
505
|
+
const lenL = Math.hypot(lower.x, lower.y);
|
|
506
|
+
const lenS = Math.hypot(startSide.x, startSide.y);
|
|
507
|
+
const lenE = Math.hypot(endSide.x, endSide.y);
|
|
508
|
+
if (lenU <= QUAD_EPSILON || lenL <= QUAD_EPSILON || lenS <= QUAD_EPSILON || lenE <= QUAD_EPSILON) return false;
|
|
509
|
+
if (upper.x * lower.x + upper.y * lower.y <= 0) return false;
|
|
510
|
+
if (startSide.x * endSide.x + startSide.y * endSide.y <= 0) return false;
|
|
511
|
+
const startArea = upper.x * startSide.y - upper.y * startSide.x;
|
|
512
|
+
const endArea = lower.x * endSide.y - lower.y * endSide.x;
|
|
513
|
+
if (Math.abs(startArea) <= QUAD_EPSILON * lenU * lenS) return false;
|
|
514
|
+
if (Math.abs(endArea) <= QUAD_EPSILON * lenL * lenE) return false;
|
|
515
|
+
return Math.sign(startArea) === Math.sign(endArea);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,
|
|
519
|
+
* already in content space) as a TextQuad — a NORMALIZER, not a cast:
|
|
520
|
+
*
|
|
521
|
+
* 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —
|
|
522
|
+
* this covers every well-formed writer, rotated quads included;
|
|
523
|
+
* 2. the common ring order (US, UE, LE, LS) is recognized and repaired;
|
|
524
|
+
* 3. anything else gets a deterministic geometric labeling: corners sorted
|
|
525
|
+
* into a ring around their centroid, "upper" = the edge whose midpoint
|
|
526
|
+
* sits highest on screen (smallest y). The 180° "which side is up"
|
|
527
|
+
* ambiguity is unresolvable from geometry alone — convention decides.
|
|
528
|
+
*
|
|
529
|
+
* Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a
|
|
530
|
+
* mislabeled import can shift an underline to the wrong edge but can never
|
|
531
|
+
* crash or self-intersect.
|
|
532
|
+
*/
|
|
533
|
+
function normalizeQuad(q) {
|
|
534
|
+
if (zigzagWellFormed([
|
|
535
|
+
q.p1,
|
|
536
|
+
q.p2,
|
|
537
|
+
q.p3,
|
|
538
|
+
q.p4
|
|
539
|
+
])) return {
|
|
540
|
+
upperStart: q.p1,
|
|
541
|
+
upperEnd: q.p2,
|
|
542
|
+
lowerStart: q.p3,
|
|
543
|
+
lowerEnd: q.p4
|
|
544
|
+
};
|
|
545
|
+
if (zigzagWellFormed([
|
|
546
|
+
q.p1,
|
|
547
|
+
q.p2,
|
|
548
|
+
q.p4,
|
|
549
|
+
q.p3
|
|
550
|
+
])) return {
|
|
551
|
+
upperStart: q.p1,
|
|
552
|
+
upperEnd: q.p2,
|
|
553
|
+
lowerStart: q.p4,
|
|
554
|
+
lowerEnd: q.p3
|
|
555
|
+
};
|
|
556
|
+
const pts = [
|
|
557
|
+
q.p1,
|
|
558
|
+
q.p2,
|
|
559
|
+
q.p3,
|
|
560
|
+
q.p4
|
|
561
|
+
].map((p) => finitePoint(p) ? p : {
|
|
562
|
+
x: 0,
|
|
563
|
+
y: 0
|
|
564
|
+
});
|
|
565
|
+
const cx = (pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4;
|
|
566
|
+
const cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4;
|
|
567
|
+
const ringSorted = [...pts].sort((a, b) => Math.atan2(a.y - cy, a.x - cx) - Math.atan2(b.y - cy, b.x - cx));
|
|
568
|
+
let upperEdge = 0;
|
|
569
|
+
let bestY = Infinity;
|
|
570
|
+
for (let i = 0; i < 4; i++) {
|
|
571
|
+
const midY = (ringSorted[i].y + ringSorted[(i + 1) % 4].y) / 2;
|
|
572
|
+
if (midY < bestY) {
|
|
573
|
+
bestY = midY;
|
|
574
|
+
upperEdge = i;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const a = ringSorted[upperEdge];
|
|
578
|
+
const b = ringSorted[(upperEdge + 1) % 4];
|
|
579
|
+
const c = ringSorted[(upperEdge + 2) % 4];
|
|
580
|
+
const d = ringSorted[(upperEdge + 3) % 4];
|
|
581
|
+
return a.x <= b.x ? {
|
|
582
|
+
upperStart: a,
|
|
583
|
+
upperEnd: b,
|
|
584
|
+
lowerStart: d,
|
|
585
|
+
lowerEnd: c
|
|
586
|
+
} : {
|
|
587
|
+
upperStart: b,
|
|
588
|
+
upperEnd: a,
|
|
589
|
+
lowerStart: c,
|
|
590
|
+
lowerEnd: d
|
|
591
|
+
};
|
|
592
|
+
}
|
|
396
593
|
//#endregion
|
|
397
594
|
exports.NO_FRAME = NO_FRAME;
|
|
398
595
|
exports.addRotations = addRotations;
|
|
@@ -400,6 +597,7 @@ exports.angleOf = angleOf;
|
|
|
400
597
|
exports.applyPoint = applyPoint;
|
|
401
598
|
exports.applyQuad = applyQuad;
|
|
402
599
|
exports.applyRect = applyRect;
|
|
600
|
+
exports.applyTextQuad = applyTextQuad;
|
|
403
601
|
exports.boundsOfRects = boundsOfRects;
|
|
404
602
|
exports.compose = compose;
|
|
405
603
|
exports.deviceHeightForWidth = deviceHeightForWidth;
|
|
@@ -409,15 +607,21 @@ exports.intersectRects = intersectRects;
|
|
|
409
607
|
exports.invert = invert;
|
|
410
608
|
exports.isQuarterTurn = isQuarterTurn;
|
|
411
609
|
exports.matrixToCss = matrixToCss;
|
|
610
|
+
exports.normalizeQuad = normalizeQuad;
|
|
412
611
|
exports.pageGeometry = pageGeometry;
|
|
413
612
|
exports.pageTransform = pageTransform;
|
|
414
613
|
exports.pdfToContentMatrix = pdfToContentMatrix;
|
|
614
|
+
exports.positionalQuad = positionalQuad;
|
|
415
615
|
exports.rotate = rotate;
|
|
416
616
|
exports.rotateAbout = rotateAbout;
|
|
417
617
|
exports.rotateScaleMatrix = rotateScaleMatrix;
|
|
418
618
|
exports.scale = scale;
|
|
419
619
|
exports.scaleAbout = scaleAbout;
|
|
420
620
|
exports.snapToDevice = snapToDevice;
|
|
621
|
+
exports.textQuadBounds = textQuadBounds;
|
|
622
|
+
exports.textQuadFromRect = textQuadFromRect;
|
|
623
|
+
exports.textQuadPoints = textQuadPoints;
|
|
624
|
+
exports.textQuadRing = textQuadRing;
|
|
421
625
|
exports.translate = translate;
|
|
422
626
|
|
|
423
627
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @embedpdf/core-geometry — the viewer's pure 2D coordinate primitives.\n *\n * The bottom of the pyramid: stage-core (layout), plugin-stage (`pageToWorld`),\n * and every framework adapter (`toPagePoint` hit-testing) all sit on these.\n * Zero dependencies, DOM-free, serializable — Rust-portable.\n *\n * The page-rotation transforms are the reason this package exists: the same\n * quarter-turn maps content↔box in BOTH directions, and that one rule must not\n * be hand-written (and drift, or be bug-fixed in only one of four adapters).\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\nexport interface Size {\n width: number;\n height: number;\n}\n/** Viewer-side rect: top-left origin, y-down (view/page-point convention — NOT the\n * engine's bottom-left PDF rect). */\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * The bounding box of a set of rects (null for the empty set). Space-\n * agnostic: works on any y-down `{x,y,width,height}` rects — search hit\n * bounds, selection line-merge unions, multi-quad annotation extents.\n */\nexport function boundsOfRects(rects: readonly Rect[]): Rect | null {\n if (rects.length === 0) return null;\n let x1 = Infinity;\n let y1 = Infinity;\n let x2 = -Infinity;\n let y2 = -Infinity;\n for (const r of rects) {\n x1 = Math.min(x1, r.x);\n y1 = Math.min(y1, r.y);\n x2 = Math.max(x2, r.x + r.width);\n y2 = Math.max(y2, r.y + r.height);\n }\n return { x: x1, y: y1, width: x2 - x1, height: y2 - y1 };\n}\n\n/**\n * Intersection of two y-down rects — zero-sized (width/height 0, origin at\n * the would-be corner) when disjoint, so callers can test `width > 0`\n * without a null branch. Space-agnostic like {@link boundsOfRects}: view-px\n * viewport ∩ footprint, page-point visibility ∩ tile footprints, ….\n */\nexport function intersectRects(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return {\n x,\n y,\n width: Math.max(0, Math.min(a.x + a.width, b.x + b.width) - x),\n height: Math.max(0, Math.min(a.y + a.height, b.y + b.height) - y),\n };\n}\n\n/**\n * Quarter-turn display rotation, degrees clockwise. The viewer-side notion of a\n * page's on-screen rotation — the TOTAL = (document /Rotate + any view\n * rotation), resolved by the shell. Structurally identical to the engine's\n * `PageRotation`, so the two interoperate without this package depending on the\n * engine.\n */\nexport type PageRotation = 0 | 90 | 180 | 270;\n\n/**\n * Reserved chrome real estate around a page, one thickness per side (screen px\n * in the shell; world units in the pure layout). The page content sits inset\n * by these; the bands hold box-space chrome (labels, buttons, rails) that does\n * not rotate. The layout reserves the matching space so nothing overlaps.\n */\nexport interface PageFrame {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\nexport const NO_FRAME: PageFrame = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** True for the quarter-turns that swap a page's width and height. */\nexport function isQuarterTurn(rotation: PageRotation): boolean {\n return rotation === 90 || rotation === 270;\n}\n\n/**\n * Compose two quarter-turn rotations (mod 360). THE way the shell resolves a\n * page's TOTAL display rotation — `addRotations(page /Rotate, view rotation)`\n * — so the wrap arithmetic is never hand-written (and drift) per call site.\n */\nexport function addRotations(a: PageRotation, b: PageRotation): PageRotation {\n return ((a + b) % 360) as PageRotation;\n}\n\n/**\n * Snap a view-px value to the device pixel grid: round to a whole device pixel,\n * back to view px. Used for a page's screen POSITION so a CSS-rotated page lands\n * on the grid (no sub-pixel anti-aliased fringe). The shell never hand-rounds.\n */\nexport function snapToDevice(value: number, dpr: number): number {\n return Math.round(value * dpr) / dpr;\n}\n\n/** A page's on-screen footprint: width and height swapped for quarter-turns. */\nexport function displaySize(content: Size, rotation: PageRotation): Size {\n return isQuarterTurn(rotation)\n ? { width: content.height, height: content.width }\n : { width: content.width, height: content.height };\n}\n\n/**\n * The engine's `kind:'width'` height rule, replicated EXACTLY so the viewer can\n * predict the rendered bitmap's height up front — the page box is sized to it,\n * so the box matches the bitmap with no reflow and no 1px seam.\n *\n * Mirrors `PageRenderReader.resolveDeviceSize` (engine-services): we render the\n * page UN-rotated (CSS applies the rotation), so there is no width/height swap\n * here — `pageSize` is the page's own points. MUST stay in lockstep with that\n * function; the round-trip test in the render plugin asserts they agree.\n */\nexport function deviceHeightForWidth(pageSize: Size, deviceWidth: number): number {\n return Math.max(1, Math.round((deviceWidth * pageSize.height) / pageSize.width));\n}\n\n/**\n * The single per-page bridge between the viewer's three coordinate spaces. NB:\n * these are all VIEWER spaces — top-left origin, y-down. They are NOT the\n * engine's PDF user space (`Pdf*`, bottom-left origin, y-up); the engine→content\n * hop (the y-flip + crop offset) is a separate matrix (`pageGeometry`).\n *\n * content space page-local points, top-left, y-down — un-rotated page frame\n * view space platform logical px (web: CSS px) — layout, DOM, pointer events\n * device space physical pixels — the rendered bitmap\n *\n * PAGE-LOCAL by design: it knows this page's own box, NOT where the page sits in\n * the scene. Placement (camera/layout) stays on `VisiblePage.{x,y}` and positions\n * the page container; the transform converts everything INSIDE that container. So\n * it is camera/pan-invariant — it only changes on zoom / rotation / contentScale\n * / dpr, which makes it cheap to memoize.\n *\n * Every plugin and framework adapter consumes THIS — never `x * scale`, never\n * `pageToWorld()∘toScreen()`, never `* dpr`. New plugins (annotations, search,\n * forms) do no coordinate math; new platforms (iOS/Android) inject a different\n * `scale` and reuse all of it.\n */\nexport interface PageTransform {\n /**\n * The page's TOTAL display rotation (document /Rotate + any view rotation) —\n * the same value the transform's matrices were built from, exposed so\n * consumers that need the quarter-turn itself (an upright-placement rule, a\n * pointer sample) read it HERE instead of re-deriving it from the matrix.\n */\n readonly rotation: PageRotation;\n /** Display footprint in VIEW px (device-snapped) — the page container's size.\n * Width↔height already swapped for quarter-turns. */\n readonly viewWidth: number;\n readonly viewHeight: number;\n /** The UN-rotated content box in VIEW px — the size of the wrapper the bitmap\n * and content-space overlays live in (before the wrapper's CSS rotation). */\n readonly contentWidth: number;\n readonly contentHeight: number;\n /** Render the (un-rotated) bitmap at EXACTLY this — `viewport: {kind:'width', width: deviceWidth}`.\n * Integer device px; `deviceHeight` is the engine's exact derived height. */\n readonly deviceWidth: number;\n readonly deviceHeight: number;\n /** Device px per PDF point (uniform). */\n readonly renderScale: number;\n /** VIEW px per PDF point (uniform, device-snapped) — the one factor for\n * screen-constant chrome: content units = CSS px ÷ `viewScale`. */\n readonly viewScale: number;\n /**\n * View px per PDF point at 100% ZOOM — the page's physical baseline:\n * `viewUnitsPerPoint × userUnit` (web: 96/72 × `/UserUnit`, so 100% maps to\n * inches on screen, Acrobat-style). What \"100%\" MEANS for this page.\n */\n readonly baseScale: number;\n /**\n * The page's zoom RELATIVE to its 100% baseline (`viewScale / baseScale`,\n * dimensionless; exactly 1 at 100% for any `userUnit`). THE number\n * zoom-relative policies consume — e.g. the `/F` NoZoom exemption clamps\n * its body to `zoom ≤ 1`. Distinct from `viewScale` (a units conversion).\n */\n readonly zoom: number;\n /** Content point → UN-rotated content view px. For overlays INSIDE the rotated\n * content wrapper (markers, annotations) — they ride the wrapper's rotation,\n * so they place in content space and only scale here. */\n pageToContent(p: Point): Point;\n /** Content point → page-local view px in the DISPLAY box (rotation applied). For\n * footprint-space layers (outside the wrapper). */\n pageToView(p: Point): Point;\n /** Content rect → its axis-aligned view-px rect (exact for quarter-turns). */\n pageToViewRect(r: Rect): Rect;\n /** Inverse — display-box view px (box-local) → content point. Hit-testing. */\n viewToPage(p: Point): Point;\n /** Inverse of {@link pageToViewRect}: display-box view-px rect → its content\n * AABB (exact for quarter-turns). The visibility primitive — projecting a\n * viewport rect into page points is THIS, never per-adapter corner math. */\n viewToPageRect(r: Rect): Rect;\n /** CSS `matrix()` mapping content space → this page's display box. Drop it on\n * a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in content points — rotation + scale handled for free. */\n readonly cssMatrix: string;\n}\n\n/**\n * Build a page's transform from its intrinsic size + the platform/view scale.\n * `scale` is VIEW px per PDF point (the shell composes it: `viewUnitsPerPoint ×\n * contentScale × zoom`); `dpr` is device px per view px. Device dimensions snap\n * to the grid (crisp, no rotation fringe) and follow the engine's width rule\n * (box == bitmap, no reflow).\n */\nexport function pageTransform(input: {\n /** Un-rotated page size in PDF points. */\n pageSize: Size;\n rotation: PageRotation;\n /** View px per PDF point = viewUnitsPerPoint × contentScale × zoom. */\n scale: number;\n /**\n * View px per PDF point at 100% zoom (`viewUnitsPerPoint × userUnit`) — the\n * page's physical baseline, so `zoom = viewScale / baseScale` reads as\n * \"percent of Acrobat's 100%\". Default = `scale`, i.e. zoom ≈ 1: headless /\n * standalone callers stay neutral unless they declare a baseline.\n */\n baseScale?: number;\n /** Device px per view px (web: devicePixelRatio). */\n dpr: number;\n}): PageTransform {\n const { pageSize, rotation, scale, dpr } = input;\n\n // Raster: pin the width (snapped to the device grid), derive the height with\n // the engine's exact rule → uniform scale, integer device px, box == bitmap.\n const deviceWidth = Math.max(1, Math.round(pageSize.width * scale * dpr));\n const deviceHeight = deviceHeightForWidth(pageSize, deviceWidth);\n const renderScale = deviceWidth / pageSize.width;\n\n // The un-rotated content box in VIEW px, taken from the snapped device dims so\n // every edge lands on a whole device pixel. The effective view scale is derived\n // from it (not the raw `scale`) so `pageToView(pageWidth) === content edge`.\n const content: Size = { width: deviceWidth / dpr, height: deviceHeight / dpr };\n const viewScale = content.width / pageSize.width;\n const baseScale = input.baseScale ?? scale;\n const zoom = baseScale > 0 ? viewScale / baseScale : 1;\n\n const footprint = displaySize(content, rotation);\n\n // The two affines this page needs, as Mat2D — the matrix is the source of\n // truth; the methods and `cssMatrix` below are sugar over it (so they can\n // never drift).\n // content point (top-left, y-down) → content view px: pure isotropic scale.\n const contentMat = [viewScale, 0, 0, viewScale, 0, 0] as Mat2D;\n // content point → display-box view px: scale + the page's quarter-turn, from\n // the shared builder (the one quarter-turn encoding).\n const viewMat = rotateScaleMatrix(viewScale, content.width, content.height, rotation);\n const invMat = invert(viewMat);\n\n const pageToContent = (p: Point): Point => applyPoint(contentMat, p);\n const pageToView = (p: Point): Point => applyPoint(viewMat, p);\n const viewToPage = (p: Point): Point => applyPoint(invMat, p);\n const pageToViewRect = (r: Rect): Rect => applyRect(viewMat, r);\n const viewToPageRect = (r: Rect): Rect => applyRect(invMat, r);\n const cssMatrix = matrixToCss(viewMat);\n\n return {\n rotation,\n viewWidth: footprint.width,\n viewHeight: footprint.height,\n contentWidth: content.width,\n contentHeight: content.height,\n deviceWidth,\n deviceHeight,\n renderScale,\n viewScale,\n baseScale,\n zoom,\n pageToContent,\n pageToView,\n pageToViewRect,\n viewToPage,\n viewToPageRect,\n cssMatrix,\n };\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Matrix-native geometry — the composable primitive under every space hop.\n *\n * A coordinate-space conversion is a 2D affine `Mat2D = [a,b,c,d,e,f]` (the same\n * six numbers as CSS `matrix()`, `CGAffineTransform`, and Android `Matrix`):\n *\n * x' = a·x + c·y + e\n * y' = b·x + d·y + f\n *\n * Three generic appliers + `compose` + `invert` are the ENTIRE runtime — they\n * never grow as spaces/shapes/directions multiply, and they port 1:1 to Rust /\n * Swift / Kotlin (every target has a native affine). Inverses (hit-testing) and\n * screen composition fall out for free; there is no per-space hand-rolled y-flip\n * to drift between adapters.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * The coordinate spaces a viewer touches. `pdf` is the engine's PDF user space\n * (y-up, origin at the crop box bottom-left); the rest are viewer-local, y-down.\n */\nexport type Space = 'pdf' | 'content' | 'view' | 'screen';\n\n/**\n * Phantom space brand. It is OPTIONAL so plain `{ x, y }` / `{ x, y, w, h }`\n * literals stay assignable day-to-day (terse), but a value EXPLICITLY tagged\n * with the wrong space is rejected — and `Mat2D<From, To>` enforces the hop at\n * the matrix, so you cannot `applyRect` a `pdf` rect with a `content→view`\n * matrix. The brand is type-only; it carries no runtime field.\n */\ninterface SpaceBrand<S extends Space> {\n readonly __space?: S;\n}\n\n/** A point tagged with its coordinate space. */\nexport type PointIn<S extends Space> = Point & SpaceBrand<S>;\n/**\n * An axis-aligned rect tagged with its space, as min-corner + positive extent:\n * `(x, y)` is the corner with the smallest coordinates and `(x+width, y+height)`\n * the largest. In `pdf` space (y-up) that corner is bottom-left (`x=left`,\n * `y=bottom`); in the y-down viewer spaces it is top-left.\n */\nexport type RectIn<S extends Space> = Rect & SpaceBrand<S>;\n\n/**\n * Four POSITIONAL points (no corner semantics) — the viewer twin of the engine's\n * `PdfQuad`. Use this (via {@link applyQuad}) for rotatable/skewed content where\n * an axis-aligned rect would lie.\n */\nexport interface Quad {\n p1: Point;\n p2: Point;\n p3: Point;\n p4: Point;\n}\n/** A quad tagged with its coordinate space. */\nexport type QuadIn<S extends Space> = Quad & SpaceBrand<S>;\n\n/**\n * A 2D affine transform from space `From` to space `To`, stored as the six\n * numbers `[a, b, c, d, e, f]`. The phantom `From`/`To` make the compiler track\n * which spaces a matrix bridges, so composition and application can only be\n * wired up in the one correct order.\n */\nexport type Mat2D<From extends Space = Space, To extends Space = Space> = readonly [\n number,\n number,\n number,\n number,\n number,\n number,\n] & {\n readonly __from?: From;\n readonly __to?: To;\n};\n\n/** The identity transform within a single space. */\nexport function identity<S extends Space>(): Mat2D<S, S> {\n return [1, 0, 0, 1, 0, 0] as Mat2D<S, S>;\n}\n\n/**\n * Compose two matrices: `compose(m, n)` applies `n` first, then `m` (matrix\n * product `m · n`). The shared middle space `B` must line up, so the type system\n * rejects composing mismatched hops.\n */\nexport function compose<A extends Space, B extends Space, C extends Space>(\n m: Mat2D<B, C>,\n n: Mat2D<A, B>,\n): Mat2D<A, C> {\n const [a, b, c, d, e, f] = m;\n const [a2, b2, c2, d2, e2, f2] = n;\n return [\n a * a2 + c * b2,\n b * a2 + d * b2,\n a * c2 + c * d2,\n b * c2 + d * d2,\n a * e2 + c * f2 + e,\n b * e2 + d * f2 + f,\n ] as Mat2D<A, C>;\n}\n\n/** Invert a transform — `invert(pdfToView)` is `viewToPdf`, i.e. hit-testing for free. */\nexport function invert<F extends Space, T extends Space>(m: Mat2D<F, T>): Mat2D<T, F> {\n const [a, b, c, d, e, f] = m;\n const det = a * d - b * c;\n if (det === 0) throw new Error('Mat2D.invert: non-invertible matrix (det = 0)');\n const ia = d / det;\n const ib = -b / det;\n const ic = -c / det;\n const id = a / det;\n return [ia, ib, ic, id, -(ia * e + ic * f), -(ib * e + id * f)] as Mat2D<T, F>;\n}\n\n/** Apply a transform to a point. */\nexport function applyPoint<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n p: PointIn<F>,\n): PointIn<T> {\n const [a, b, c, d, e, f] = m;\n return { x: a * p.x + c * p.y + e, y: b * p.x + d * p.y + f } as PointIn<T>;\n}\n\n/**\n * Apply a transform to a rect, returning the axis-aligned bounding box of the\n * four transformed corners. EXACT for translate/scale/quarter-turn (every page\n * transform `pageGeometry` produces); lossy under skew — use {@link applyQuad}\n * for content that can be rotated off-axis.\n */\nexport function applyRect<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n r: RectIn<F>,\n): RectIn<T> {\n const c0 = applyPoint(m, { x: r.x, y: r.y } as PointIn<F>);\n const c1 = applyPoint(m, { x: r.x + r.width, y: r.y } as PointIn<F>);\n const c2 = applyPoint(m, { x: r.x, y: r.y + r.height } as PointIn<F>);\n const c3 = applyPoint(m, { x: r.x + r.width, y: r.y + r.height } as PointIn<F>);\n const xs = [c0.x, c1.x, c2.x, c3.x];\n const ys = [c0.y, c1.y, c2.y, c3.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return {\n x: minX,\n y: minY,\n width: Math.max(...xs) - minX,\n height: Math.max(...ys) - minY,\n } as RectIn<T>;\n}\n\n/** Apply a transform to a quad, preserving orientation (maps the four points). */\nexport function applyQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n q: QuadIn<F>,\n): QuadIn<T> {\n return {\n p1: applyPoint(m, q.p1 as PointIn<F>),\n p2: applyPoint(m, q.p2 as PointIn<F>),\n p3: applyPoint(m, q.p3 as PointIn<F>),\n p4: applyPoint(m, q.p4 as PointIn<F>),\n } as QuadIn<T>;\n}\n\n/**\n * A `Mat2D` IS a CSS `matrix()` — the six numbers are identical. Drop the result\n * on a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in the source space; the rotation + scale are handled for free.\n */\nexport function matrixToCss(m: Mat2D): string {\n const [a, b, c, d, e, f] = m;\n return `matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`;\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Same-space affine builders — generic, free-angle transforms WITHIN one space\n * (`Mat2D<S, S>`). The `rotateScaleMatrix` above is a quarter-turn, cross-space\n * builder for page layout; these are the arbitrary-angle primitives content\n * editing (annotation rotation/scale, future stamps/skew) composes from. They\n * never know about annotations — they are the bottom-of-the-pyramid matrix math,\n * so it isn't hand-rolled (and drift) in every plugin.\n *\n * Convention: a viewer content space is y-DOWN, so `rotate(rad)` —\n * `[cos, sin, -sin, cos, 0, 0]` — turns CLOCKWISE on screen (matching the\n * viewer's page-rotation direction). The PDF (y-up) flip, when one is needed,\n * is a separate hop applied once at the engine boundary.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** Translate within a space. */\nexport function translate<S extends Space>(tx: number, ty: number): Mat2D<S, S> {\n return [1, 0, 0, 1, tx, ty] as Mat2D<S, S>;\n}\n\n/** Scale about the space origin. */\nexport function scale<S extends Space>(sx: number, sy: number): Mat2D<S, S> {\n return [sx, 0, 0, sy, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about the space origin (radians; clockwise in y-down content space). */\nexport function rotate<S extends Space>(rad: number): Mat2D<S, S> {\n const c = Math.cos(rad);\n const s = Math.sin(rad);\n return [c, s, -s, c, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about an arbitrary pivot: `T(c) · R(rad) · T(-c)`. */\nexport function rotateAbout<S extends Space>(c: PointIn<S>, rad: number): Mat2D<S, S> {\n return compose(translate<S>(c.x, c.y), compose(rotate<S>(rad), translate<S>(-c.x, -c.y)));\n}\n\n/** Scale about an arbitrary anchor: `T(a) · S(sx, sy) · T(-a)`. */\nexport function scaleAbout<S extends Space>(a: PointIn<S>, sx: number, sy: number): Mat2D<S, S> {\n return compose(translate<S>(a.x, a.y), compose(scale<S>(sx, sy), translate<S>(-a.x, -a.y)));\n}\n\n/** The rotation angle (radians) encoded in a matrix — `atan2(b, a)`. Positive is\n * clockwise in y-down content space (the inverse of {@link rotate}). */\nexport function angleOf(m: Mat2D): number {\n return Math.atan2(m[1], m[0]);\n}\n\n/**\n * The page's scale + integer quarter-turn as a `Mat2D`: a content point maps to\n * its place in the rotated DISPLAY box. `scale` is output units per content\n * point; `boxW`/`boxH` are the UN-rotated content's extents in those same output\n * units, and the offsets keep the footprint in the box's positive quadrant\n * (origin at the box top-left).\n *\n * THE single encoding of the quarter-turn — `pageTransform` (view px),\n * `pageGeometry` (the `content→view` hop), and `pageToWorld` (world units) all\n * build on this one function, so the rotation can never drift between them.\n */\nexport function rotateScaleMatrix(\n scale: number,\n boxW: number,\n boxH: number,\n rotation: PageRotation,\n): Mat2D {\n switch (rotation) {\n case 90:\n return [0, scale, -scale, 0, boxH, 0] as Mat2D;\n case 180:\n return [-scale, 0, 0, -scale, boxW, boxH] as Mat2D;\n case 270:\n return [0, -scale, scale, 0, 0, boxW] as Mat2D;\n default:\n return [scale, 0, 0, scale, 0, 0] as Mat2D;\n }\n}\n\n/**\n * The per-page geometry input. Structurally a subset of the engine's\n * `PageLayout` (so a layout can be passed straight in), but defined here to keep\n * this package dependency-free — the same reason {@link PageRotation} is a\n * structural twin of the engine's rotation.\n */\nexport interface PageGeometryInput {\n /** Effective crop box in PDF user space (y-up edges); origin preserved, so\n * `left`/`bottom` may be non-zero or negative. */\n crop: { left: number; bottom: number; right: number; top: number };\n /** Persistent page rotation (the document's `/Rotate`). */\n rotation: PageRotation;\n /** PDF `userUnit` (§14.11.6): scales PDF points into the layout. 1 for most docs. */\n userUnit: number;\n}\n\n/** The matrices bridging one page's spaces — every other matrix composes from these. */\nexport interface PageGeometry {\n /** PDF user space (y-up, crop-relative) → content space (y-down, crop top-left, unscaled points). */\n readonly pdfToContent: Mat2D<'pdf', 'content'>;\n /** Content → view: scale (zoom × userUnit) + the page's quarter-turn rotation. */\n readonly contentToView: Mat2D<'content', 'view'>;\n /** PDF → view, precomposed. */\n readonly pdfToView: Mat2D<'pdf', 'view'>;\n /** View → PDF, the inverse — hit-testing for free. */\n readonly viewToPdf: Mat2D<'view', 'pdf'>;\n}\n\n/**\n * PDF user space (y-up, origin = crop bottom-left) → content space (y-down,\n * origin = crop top-left, unscaled points). THE single encoding of the engine→\n * content y-flip + crop offset: `pageGeometry` composes its `pdfToContent` from\n * this, and pure annotation geometry (content-space editing) reuses it too, so\n * the rule can never be hand-written twice and drift.\n */\nexport function pdfToContentMatrix(crop: { left: number; top: number }): Mat2D<'pdf', 'content'> {\n return [1, 0, 0, -1, -crop.left, crop.top] as Mat2D<'pdf', 'content'>;\n}\n\n/**\n * Build a page's space matrices from its crop box, rotation, and `userUnit` plus\n * the viewer `zoom`. This is the ONE function that knows the y-flip, crop origin,\n * `userUnit`, and rotation; everything else composes from its output. The engine\n * never emits these — they bake in viewer state (zoom, later scroll/dpr) — so the\n * boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.\n */\nexport function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry {\n const { crop, rotation, userUnit } = input;\n const s = zoom * userUnit; // view px per PDF point — userUnit folded in HERE, once\n\n // PDF user space (y-up, origin = crop bottom-left) → content (y-down, origin = crop top-left).\n const pdfToContent = pdfToContentMatrix(crop);\n\n // Content → view: scale + integer quarter-turn, from the shared builder (the\n // one quarter-turn encoding). `Wc`/`Hc` are the unrotated content's view-px\n // extents (the builder places the footprint in the box's positive quadrant).\n const Wc = (crop.right - crop.left) * s;\n const Hc = (crop.top - crop.bottom) * s;\n const contentToView = rotateScaleMatrix(s, Wc, Hc, rotation) as Mat2D<'content', 'view'>;\n\n const pdfToView = compose(contentToView, pdfToContent);\n return { pdfToContent, contentToView, pdfToView, viewToPdf: invert(pdfToView) };\n}\n"],"mappings":";;;;;;;AAkCA,SAAgB,cAAc,OAAqC;CACjE,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,MAAM,KAAK,OAAO;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,CAAC;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,CAAC;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,KAAK;EAC/B,KAAK,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM;CAClC;CACA,OAAO;EAAE,GAAG;EAAI,GAAG;EAAI,OAAO,KAAK;EAAI,QAAQ,KAAK;CAAG;AACzD;;;;;;;AAQA,SAAgB,eAAe,GAAS,GAAe;CACrD,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;CAC3B,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;CAC3B,OAAO;EACL;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AM;EAAC;EACtC,KAAK,KACH,OAAO;GAAC,CAAC;GAAO;GAAG;GAAG,CAAC;GAAO;GAAM;EAAI;EAC1C,KAAK,KACH,OAAO;GAAC;GAAG,CAAC;GAAO;GAAO;GAAG;GAAG;EAAI;EACtC,SACE,OAAO;GAAC;GAAO;GAAG;GAAG;GAAO;GAAG;EAAC;CACpC;AACF;;;;;;;;AAqCA,SAAgB,mBAAmB,MAA8D;CAC/F,OAAO;EAAC;EAAG;EAAG;EAAG;EAAI,CAAC,KAAK;EAAM,KAAK;CAAG;AAC3C;;;;;;;;AASA,SAAgB,aAAa,OAA0B,MAA4B;CACjF,MAAM,EAAE,MAAM,UAAU,aAAa;CACrC,MAAM,IAAI,OAAO;CAGjB,MAAM,eAAe,mBAAmB,IAAI;CAO5C,MAAM,gBAAgB,kBAAkB,IAF5B,KAAK,QAAQ,KAAK,QAAQ,IAC1B,KAAK,MAAM,KAAK,UAAU,GACa,QAAQ;CAE3D,MAAM,YAAY,QAAQ,eAAe,YAAY;CACrD,OAAO;EAAE;EAAc;EAAe;EAAW,WAAW,OAAO,SAAS;CAAE;AAChF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @embedpdf/core-geometry — the viewer's pure 2D coordinate primitives.\n *\n * The bottom of the pyramid: stage-core (layout), plugin-stage (`pageToWorld`),\n * and every framework adapter (`toPagePoint` hit-testing) all sit on these.\n * Zero dependencies, DOM-free, serializable — Rust-portable.\n *\n * The page-rotation transforms are the reason this package exists: the same\n * quarter-turn maps content↔box in BOTH directions, and that one rule must not\n * be hand-written (and drift, or be bug-fixed in only one of four adapters).\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\nexport interface Size {\n width: number;\n height: number;\n}\n/** Viewer-side rect: top-left origin, y-down (view/page-point convention — NOT the\n * engine's bottom-left PDF rect). */\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * The bounding box of a set of rects (null for the empty set). Space-\n * agnostic: works on any y-down `{x,y,width,height}` rects — search hit\n * bounds, selection line-merge unions, multi-quad annotation extents.\n */\nexport function boundsOfRects(rects: readonly Rect[]): Rect | null {\n if (rects.length === 0) return null;\n let x1 = Infinity;\n let y1 = Infinity;\n let x2 = -Infinity;\n let y2 = -Infinity;\n for (const r of rects) {\n x1 = Math.min(x1, r.x);\n y1 = Math.min(y1, r.y);\n x2 = Math.max(x2, r.x + r.width);\n y2 = Math.max(y2, r.y + r.height);\n }\n return { x: x1, y: y1, width: x2 - x1, height: y2 - y1 };\n}\n\n/**\n * Intersection of two y-down rects — zero-sized (width/height 0, origin at\n * the would-be corner) when disjoint, so callers can test `width > 0`\n * without a null branch. Space-agnostic like {@link boundsOfRects}: view-px\n * viewport ∩ footprint, page-point visibility ∩ tile footprints, ….\n */\nexport function intersectRects(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return {\n x,\n y,\n width: Math.max(0, Math.min(a.x + a.width, b.x + b.width) - x),\n height: Math.max(0, Math.min(a.y + a.height, b.y + b.height) - y),\n };\n}\n\n/**\n * Quarter-turn display rotation, degrees clockwise. The viewer-side notion of a\n * page's on-screen rotation — the TOTAL = (document /Rotate + any view\n * rotation), resolved by the shell. Structurally identical to the engine's\n * `PageRotation`, so the two interoperate without this package depending on the\n * engine.\n */\nexport type PageRotation = 0 | 90 | 180 | 270;\n\n/**\n * Reserved chrome real estate around a page, one thickness per side (screen px\n * in the shell; world units in the pure layout). The page content sits inset\n * by these; the bands hold box-space chrome (labels, buttons, rails) that does\n * not rotate. The layout reserves the matching space so nothing overlaps.\n */\nexport interface PageFrame {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\nexport const NO_FRAME: PageFrame = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** True for the quarter-turns that swap a page's width and height. */\nexport function isQuarterTurn(rotation: PageRotation): boolean {\n return rotation === 90 || rotation === 270;\n}\n\n/**\n * Compose two quarter-turn rotations (mod 360). THE way the shell resolves a\n * page's TOTAL display rotation — `addRotations(page /Rotate, view rotation)`\n * — so the wrap arithmetic is never hand-written (and drift) per call site.\n */\nexport function addRotations(a: PageRotation, b: PageRotation): PageRotation {\n return ((a + b) % 360) as PageRotation;\n}\n\n/**\n * Snap a view-px value to the device pixel grid: round to a whole device pixel,\n * back to view px. Used for a page's screen POSITION so a CSS-rotated page lands\n * on the grid (no sub-pixel anti-aliased fringe). The shell never hand-rounds.\n */\nexport function snapToDevice(value: number, dpr: number): number {\n return Math.round(value * dpr) / dpr;\n}\n\n/** A page's on-screen footprint: width and height swapped for quarter-turns. */\nexport function displaySize(content: Size, rotation: PageRotation): Size {\n return isQuarterTurn(rotation)\n ? { width: content.height, height: content.width }\n : { width: content.width, height: content.height };\n}\n\n/**\n * The engine's `kind:'width'` height rule, replicated EXACTLY so the viewer can\n * predict the rendered bitmap's height up front — the page box is sized to it,\n * so the box matches the bitmap with no reflow and no 1px seam.\n *\n * Mirrors `PageRenderReader.resolveDeviceSize` (engine-services): we render the\n * page UN-rotated (CSS applies the rotation), so there is no width/height swap\n * here — `pageSize` is the page's own points. MUST stay in lockstep with that\n * function; the round-trip test in the render plugin asserts they agree.\n */\nexport function deviceHeightForWidth(pageSize: Size, deviceWidth: number): number {\n return Math.max(1, Math.round((deviceWidth * pageSize.height) / pageSize.width));\n}\n\n/**\n * The single per-page bridge between the viewer's three coordinate spaces. NB:\n * these are all VIEWER spaces — top-left origin, y-down. They are NOT the\n * engine's PDF user space (`Pdf*`, bottom-left origin, y-up); the engine→content\n * hop (the y-flip + crop offset) is a separate matrix (`pageGeometry`).\n *\n * content space page-local points, top-left, y-down — un-rotated page frame\n * view space platform logical px (web: CSS px) — layout, DOM, pointer events\n * device space physical pixels — the rendered bitmap\n *\n * PAGE-LOCAL by design: it knows this page's own box, NOT where the page sits in\n * the scene. Placement (camera/layout) stays on `VisiblePage.{x,y}` and positions\n * the page container; the transform converts everything INSIDE that container. So\n * it is camera/pan-invariant — it only changes on zoom / rotation / contentScale\n * / dpr, which makes it cheap to memoize.\n *\n * Every plugin and framework adapter consumes THIS — never `x * scale`, never\n * `pageToWorld()∘toScreen()`, never `* dpr`. New plugins (annotations, search,\n * forms) do no coordinate math; new platforms (iOS/Android) inject a different\n * `scale` and reuse all of it.\n */\nexport interface PageTransform {\n /**\n * The page's TOTAL display rotation (document /Rotate + any view rotation) —\n * the same value the transform's matrices were built from, exposed so\n * consumers that need the quarter-turn itself (an upright-placement rule, a\n * pointer sample) read it HERE instead of re-deriving it from the matrix.\n */\n readonly rotation: PageRotation;\n /** Display footprint in VIEW px (device-snapped) — the page container's size.\n * Width↔height already swapped for quarter-turns. */\n readonly viewWidth: number;\n readonly viewHeight: number;\n /** The UN-rotated content box in VIEW px — the size of the wrapper the bitmap\n * and content-space overlays live in (before the wrapper's CSS rotation). */\n readonly contentWidth: number;\n readonly contentHeight: number;\n /** Render the (un-rotated) bitmap at EXACTLY this — `viewport: {kind:'width', width: deviceWidth}`.\n * Integer device px; `deviceHeight` is the engine's exact derived height. */\n readonly deviceWidth: number;\n readonly deviceHeight: number;\n /** Device px per PDF point (uniform). */\n readonly renderScale: number;\n /** VIEW px per PDF point (uniform, device-snapped) — the one factor for\n * screen-constant chrome: content units = CSS px ÷ `viewScale`. */\n readonly viewScale: number;\n /**\n * View px per PDF point at 100% ZOOM — the page's physical baseline:\n * `viewUnitsPerPoint × userUnit` (web: 96/72 × `/UserUnit`, so 100% maps to\n * inches on screen, Acrobat-style). What \"100%\" MEANS for this page.\n */\n readonly baseScale: number;\n /**\n * The page's zoom RELATIVE to its 100% baseline (`viewScale / baseScale`,\n * dimensionless; exactly 1 at 100% for any `userUnit`). THE number\n * zoom-relative policies consume — e.g. the `/F` NoZoom exemption clamps\n * its body to `zoom ≤ 1`. Distinct from `viewScale` (a units conversion).\n */\n readonly zoom: number;\n /** Content point → UN-rotated content view px. For overlays INSIDE the rotated\n * content wrapper (markers, annotations) — they ride the wrapper's rotation,\n * so they place in content space and only scale here. */\n pageToContent(p: Point): Point;\n /** Content point → page-local view px in the DISPLAY box (rotation applied). For\n * footprint-space layers (outside the wrapper). */\n pageToView(p: Point): Point;\n /** Content rect → its axis-aligned view-px rect (exact for quarter-turns). */\n pageToViewRect(r: Rect): Rect;\n /** Inverse — display-box view px (box-local) → content point. Hit-testing. */\n viewToPage(p: Point): Point;\n /** Inverse of {@link pageToViewRect}: display-box view-px rect → its content\n * AABB (exact for quarter-turns). The visibility primitive — projecting a\n * viewport rect into page points is THIS, never per-adapter corner math. */\n viewToPageRect(r: Rect): Rect;\n /** CSS `matrix()` mapping content space → this page's display box. Drop it on\n * a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in content points — rotation + scale handled for free. */\n readonly cssMatrix: string;\n}\n\n/**\n * Build a page's transform from its intrinsic size + the platform/view scale.\n * `scale` is VIEW px per PDF point (the shell composes it: `viewUnitsPerPoint ×\n * contentScale × zoom`); `dpr` is device px per view px. Device dimensions snap\n * to the grid (crisp, no rotation fringe) and follow the engine's width rule\n * (box == bitmap, no reflow).\n */\nexport function pageTransform(input: {\n /** Un-rotated page size in PDF points. */\n pageSize: Size;\n rotation: PageRotation;\n /** View px per PDF point = viewUnitsPerPoint × contentScale × zoom. */\n scale: number;\n /**\n * View px per PDF point at 100% zoom (`viewUnitsPerPoint × userUnit`) — the\n * page's physical baseline, so `zoom = viewScale / baseScale` reads as\n * \"percent of Acrobat's 100%\". Default = `scale`, i.e. zoom ≈ 1: headless /\n * standalone callers stay neutral unless they declare a baseline.\n */\n baseScale?: number;\n /** Device px per view px (web: devicePixelRatio). */\n dpr: number;\n}): PageTransform {\n const { pageSize, rotation, scale, dpr } = input;\n\n // Raster: pin the width (snapped to the device grid), derive the height with\n // the engine's exact rule → uniform scale, integer device px, box == bitmap.\n const deviceWidth = Math.max(1, Math.round(pageSize.width * scale * dpr));\n const deviceHeight = deviceHeightForWidth(pageSize, deviceWidth);\n const renderScale = deviceWidth / pageSize.width;\n\n // The un-rotated content box in VIEW px, taken from the snapped device dims so\n // every edge lands on a whole device pixel. The effective view scale is derived\n // from it (not the raw `scale`) so `pageToView(pageWidth) === content edge`.\n const content: Size = { width: deviceWidth / dpr, height: deviceHeight / dpr };\n const viewScale = content.width / pageSize.width;\n const baseScale = input.baseScale ?? scale;\n const zoom = baseScale > 0 ? viewScale / baseScale : 1;\n\n const footprint = displaySize(content, rotation);\n\n // The two affines this page needs, as Mat2D — the matrix is the source of\n // truth; the methods and `cssMatrix` below are sugar over it (so they can\n // never drift).\n // content point (top-left, y-down) → content view px: pure isotropic scale.\n const contentMat = [viewScale, 0, 0, viewScale, 0, 0] as Mat2D;\n // content point → display-box view px: scale + the page's quarter-turn, from\n // the shared builder (the one quarter-turn encoding).\n const viewMat = rotateScaleMatrix(viewScale, content.width, content.height, rotation);\n const invMat = invert(viewMat);\n\n const pageToContent = (p: Point): Point => applyPoint(contentMat, p);\n const pageToView = (p: Point): Point => applyPoint(viewMat, p);\n const viewToPage = (p: Point): Point => applyPoint(invMat, p);\n const pageToViewRect = (r: Rect): Rect => applyRect(viewMat, r);\n const viewToPageRect = (r: Rect): Rect => applyRect(invMat, r);\n const cssMatrix = matrixToCss(viewMat);\n\n return {\n rotation,\n viewWidth: footprint.width,\n viewHeight: footprint.height,\n contentWidth: content.width,\n contentHeight: content.height,\n deviceWidth,\n deviceHeight,\n renderScale,\n viewScale,\n baseScale,\n zoom,\n pageToContent,\n pageToView,\n pageToViewRect,\n viewToPage,\n viewToPageRect,\n cssMatrix,\n };\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Matrix-native geometry — the composable primitive under every space hop.\n *\n * A coordinate-space conversion is a 2D affine `Mat2D = [a,b,c,d,e,f]` (the same\n * six numbers as CSS `matrix()`, `CGAffineTransform`, and Android `Matrix`):\n *\n * x' = a·x + c·y + e\n * y' = b·x + d·y + f\n *\n * Three generic appliers + `compose` + `invert` are the ENTIRE runtime — they\n * never grow as spaces/shapes/directions multiply, and they port 1:1 to Rust /\n * Swift / Kotlin (every target has a native affine). Inverses (hit-testing) and\n * screen composition fall out for free; there is no per-space hand-rolled y-flip\n * to drift between adapters.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * The coordinate spaces a viewer touches. `pdf` is the engine's PDF user space\n * (y-up, origin at the crop box bottom-left); the rest are viewer-local, y-down.\n */\nexport type Space = 'pdf' | 'content' | 'view' | 'screen';\n\n/**\n * Phantom space brand. It is OPTIONAL so plain `{ x, y }` / `{ x, y, w, h }`\n * literals stay assignable day-to-day (terse), but a value EXPLICITLY tagged\n * with the wrong space is rejected — and `Mat2D<From, To>` enforces the hop at\n * the matrix, so you cannot `applyRect` a `pdf` rect with a `content→view`\n * matrix. The brand is type-only; it carries no runtime field.\n */\ninterface SpaceBrand<S extends Space> {\n readonly __space?: S;\n}\n\n/** A point tagged with its coordinate space. */\nexport type PointIn<S extends Space> = Point & SpaceBrand<S>;\n/**\n * An axis-aligned rect tagged with its space, as min-corner + positive extent:\n * `(x, y)` is the corner with the smallest coordinates and `(x+width, y+height)`\n * the largest. In `pdf` space (y-up) that corner is bottom-left (`x=left`,\n * `y=bottom`); in the y-down viewer spaces it is top-left.\n */\nexport type RectIn<S extends Space> = Rect & SpaceBrand<S>;\n\n/**\n * Four POSITIONAL points (no corner semantics) — the viewer twin of the engine's\n * `PdfQuad`. Use this (via {@link applyQuad}) for rotatable/skewed content where\n * an axis-aligned rect would lie.\n */\nexport interface Quad {\n p1: Point;\n p2: Point;\n p3: Point;\n p4: Point;\n}\n/** A quad tagged with its coordinate space. */\nexport type QuadIn<S extends Space> = Quad & SpaceBrand<S>;\n\n/**\n * A 2D affine transform from space `From` to space `To`, stored as the six\n * numbers `[a, b, c, d, e, f]`. The phantom `From`/`To` make the compiler track\n * which spaces a matrix bridges, so composition and application can only be\n * wired up in the one correct order.\n */\nexport type Mat2D<From extends Space = Space, To extends Space = Space> = readonly [\n number,\n number,\n number,\n number,\n number,\n number,\n] & {\n readonly __from?: From;\n readonly __to?: To;\n};\n\n/** The identity transform within a single space. */\nexport function identity<S extends Space>(): Mat2D<S, S> {\n return [1, 0, 0, 1, 0, 0] as Mat2D<S, S>;\n}\n\n/**\n * Compose two matrices: `compose(m, n)` applies `n` first, then `m` (matrix\n * product `m · n`). The shared middle space `B` must line up, so the type system\n * rejects composing mismatched hops.\n */\nexport function compose<A extends Space, B extends Space, C extends Space>(\n m: Mat2D<B, C>,\n n: Mat2D<A, B>,\n): Mat2D<A, C> {\n const [a, b, c, d, e, f] = m;\n const [a2, b2, c2, d2, e2, f2] = n;\n return [\n a * a2 + c * b2,\n b * a2 + d * b2,\n a * c2 + c * d2,\n b * c2 + d * d2,\n a * e2 + c * f2 + e,\n b * e2 + d * f2 + f,\n ] as Mat2D<A, C>;\n}\n\n/** Invert a transform — `invert(pdfToView)` is `viewToPdf`, i.e. hit-testing for free. */\nexport function invert<F extends Space, T extends Space>(m: Mat2D<F, T>): Mat2D<T, F> {\n const [a, b, c, d, e, f] = m;\n const det = a * d - b * c;\n if (det === 0) throw new Error('Mat2D.invert: non-invertible matrix (det = 0)');\n const ia = d / det;\n const ib = -b / det;\n const ic = -c / det;\n const id = a / det;\n return [ia, ib, ic, id, -(ia * e + ic * f), -(ib * e + id * f)] as Mat2D<T, F>;\n}\n\n/** Apply a transform to a point. */\nexport function applyPoint<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n p: PointIn<F>,\n): PointIn<T> {\n const [a, b, c, d, e, f] = m;\n return { x: a * p.x + c * p.y + e, y: b * p.x + d * p.y + f } as PointIn<T>;\n}\n\n/**\n * Apply a transform to a rect, returning the axis-aligned bounding box of the\n * four transformed corners. EXACT for translate/scale/quarter-turn (every page\n * transform `pageGeometry` produces); lossy under skew — use {@link applyQuad}\n * for content that can be rotated off-axis.\n */\nexport function applyRect<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n r: RectIn<F>,\n): RectIn<T> {\n const c0 = applyPoint(m, { x: r.x, y: r.y } as PointIn<F>);\n const c1 = applyPoint(m, { x: r.x + r.width, y: r.y } as PointIn<F>);\n const c2 = applyPoint(m, { x: r.x, y: r.y + r.height } as PointIn<F>);\n const c3 = applyPoint(m, { x: r.x + r.width, y: r.y + r.height } as PointIn<F>);\n const xs = [c0.x, c1.x, c2.x, c3.x];\n const ys = [c0.y, c1.y, c2.y, c3.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return {\n x: minX,\n y: minY,\n width: Math.max(...xs) - minX,\n height: Math.max(...ys) - minY,\n } as RectIn<T>;\n}\n\n/** Apply a transform to a quad, preserving orientation (maps the four points). */\nexport function applyQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n q: QuadIn<F>,\n): QuadIn<T> {\n return {\n p1: applyPoint(m, q.p1 as PointIn<F>),\n p2: applyPoint(m, q.p2 as PointIn<F>),\n p3: applyPoint(m, q.p3 as PointIn<F>),\n p4: applyPoint(m, q.p4 as PointIn<F>),\n } as QuadIn<T>;\n}\n\n/**\n * A `Mat2D` IS a CSS `matrix()` — the six numbers are identical. Drop the result\n * on a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in the source space; the rotation + scale are handled for free.\n */\nexport function matrixToCss(m: Mat2D): string {\n const [a, b, c, d, e, f] = m;\n return `matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`;\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Same-space affine builders — generic, free-angle transforms WITHIN one space\n * (`Mat2D<S, S>`). The `rotateScaleMatrix` above is a quarter-turn, cross-space\n * builder for page layout; these are the arbitrary-angle primitives content\n * editing (annotation rotation/scale, future stamps/skew) composes from. They\n * never know about annotations — they are the bottom-of-the-pyramid matrix math,\n * so it isn't hand-rolled (and drift) in every plugin.\n *\n * Convention: a viewer content space is y-DOWN, so `rotate(rad)` —\n * `[cos, sin, -sin, cos, 0, 0]` — turns CLOCKWISE on screen (matching the\n * viewer's page-rotation direction). The PDF (y-up) flip, when one is needed,\n * is a separate hop applied once at the engine boundary.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** Translate within a space. */\nexport function translate<S extends Space>(tx: number, ty: number): Mat2D<S, S> {\n return [1, 0, 0, 1, tx, ty] as Mat2D<S, S>;\n}\n\n/** Scale about the space origin. */\nexport function scale<S extends Space>(sx: number, sy: number): Mat2D<S, S> {\n return [sx, 0, 0, sy, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about the space origin (radians; clockwise in y-down content space). */\nexport function rotate<S extends Space>(rad: number): Mat2D<S, S> {\n const c = Math.cos(rad);\n const s = Math.sin(rad);\n return [c, s, -s, c, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about an arbitrary pivot: `T(c) · R(rad) · T(-c)`. */\nexport function rotateAbout<S extends Space>(c: PointIn<S>, rad: number): Mat2D<S, S> {\n return compose(translate<S>(c.x, c.y), compose(rotate<S>(rad), translate<S>(-c.x, -c.y)));\n}\n\n/** Scale about an arbitrary anchor: `T(a) · S(sx, sy) · T(-a)`. */\nexport function scaleAbout<S extends Space>(a: PointIn<S>, sx: number, sy: number): Mat2D<S, S> {\n return compose(translate<S>(a.x, a.y), compose(scale<S>(sx, sy), translate<S>(-a.x, -a.y)));\n}\n\n/** The rotation angle (radians) encoded in a matrix — `atan2(b, a)`. Positive is\n * clockwise in y-down content space (the inverse of {@link rotate}). */\nexport function angleOf(m: Mat2D): number {\n return Math.atan2(m[1], m[0]);\n}\n\n/**\n * The page's scale + integer quarter-turn as a `Mat2D`: a content point maps to\n * its place in the rotated DISPLAY box. `scale` is output units per content\n * point; `boxW`/`boxH` are the UN-rotated content's extents in those same output\n * units, and the offsets keep the footprint in the box's positive quadrant\n * (origin at the box top-left).\n *\n * THE single encoding of the quarter-turn — `pageTransform` (view px),\n * `pageGeometry` (the `content→view` hop), and `pageToWorld` (world units) all\n * build on this one function, so the rotation can never drift between them.\n */\nexport function rotateScaleMatrix(\n scale: number,\n boxW: number,\n boxH: number,\n rotation: PageRotation,\n): Mat2D {\n switch (rotation) {\n case 90:\n return [0, scale, -scale, 0, boxH, 0] as Mat2D;\n case 180:\n return [-scale, 0, 0, -scale, boxW, boxH] as Mat2D;\n case 270:\n return [0, -scale, scale, 0, 0, boxW] as Mat2D;\n default:\n return [scale, 0, 0, scale, 0, 0] as Mat2D;\n }\n}\n\n/**\n * The per-page geometry input. Structurally a subset of the engine's\n * `PageLayout` (so a layout can be passed straight in), but defined here to keep\n * this package dependency-free — the same reason {@link PageRotation} is a\n * structural twin of the engine's rotation.\n */\nexport interface PageGeometryInput {\n /** Effective crop box in PDF user space (y-up edges); origin preserved, so\n * `left`/`bottom` may be non-zero or negative. */\n crop: { left: number; bottom: number; right: number; top: number };\n /** Persistent page rotation (the document's `/Rotate`). */\n rotation: PageRotation;\n /** PDF `userUnit` (§14.11.6): scales PDF points into the layout. 1 for most docs. */\n userUnit: number;\n}\n\n/** The matrices bridging one page's spaces — every other matrix composes from these. */\nexport interface PageGeometry {\n /** PDF user space (y-up, crop-relative) → content space (y-down, crop top-left, unscaled points). */\n readonly pdfToContent: Mat2D<'pdf', 'content'>;\n /** Content → view: scale (zoom × userUnit) + the page's quarter-turn rotation. */\n readonly contentToView: Mat2D<'content', 'view'>;\n /** PDF → view, precomposed. */\n readonly pdfToView: Mat2D<'pdf', 'view'>;\n /** View → PDF, the inverse — hit-testing for free. */\n readonly viewToPdf: Mat2D<'view', 'pdf'>;\n}\n\n/**\n * PDF user space (y-up, origin = crop bottom-left) → content space (y-down,\n * origin = crop top-left, unscaled points). THE single encoding of the engine→\n * content y-flip + crop offset: `pageGeometry` composes its `pdfToContent` from\n * this, and pure annotation geometry (content-space editing) reuses it too, so\n * the rule can never be hand-written twice and drift.\n */\nexport function pdfToContentMatrix(crop: { left: number; top: number }): Mat2D<'pdf', 'content'> {\n return [1, 0, 0, -1, -crop.left, crop.top] as Mat2D<'pdf', 'content'>;\n}\n\n/**\n * Build a page's space matrices from its crop box, rotation, and `userUnit` plus\n * the viewer `zoom`. This is the ONE function that knows the y-flip, crop origin,\n * `userUnit`, and rotation; everything else composes from its output. The engine\n * never emits these — they bake in viewer state (zoom, later scroll/dpr) — so the\n * boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.\n */\nexport function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry {\n const { crop, rotation, userUnit } = input;\n const s = zoom * userUnit; // view px per PDF point — userUnit folded in HERE, once\n\n // PDF user space (y-up, origin = crop bottom-left) → content (y-down, origin = crop top-left).\n const pdfToContent = pdfToContentMatrix(crop);\n\n // Content → view: scale + integer quarter-turn, from the shared builder (the\n // one quarter-turn encoding). `Wc`/`Hc` are the unrotated content's view-px\n // extents (the builder places the footprint in the box's positive quadrant).\n const Wc = (crop.right - crop.left) * s;\n const Hc = (crop.top - crop.bottom) * s;\n const contentToView = rotateScaleMatrix(s, Wc, Hc, rotation) as Mat2D<'content', 'view'>;\n\n const pdfToView = compose(contentToView, pdfToContent);\n return { pdfToContent, contentToView, pdfToView, viewToPdf: invert(pdfToView) };\n}\n\n/* ── TextQuad — corner-named quads for text-anchored geometry ──────────────\n *\n * {@link Quad} is deliberately positional (no corner guarantee) because\n * imported PDF quads have chaotic corner orders. TextQuad is the SEMANTIC\n * counterpart for quads whose orientation is KNOWN — produced only by code\n * that established it (selection segments, glyph cells, or `normalizeQuad`\n * at an ingest boundary), never by casting.\n *\n * Corner names are FRAME-GEOMETRIC in the text's own upright frame:\n * `upper` is the ascent side, `lower` the baseline side, and `start` → `end`\n * runs along the frame's +x. VISUAL semantics — deliberately NOT reading\n * order: bidi/advance direction is a glyph-sequence concern carried\n * separately where consumers need it. In y-down content space an upright\n * TextQuad has `upper*` at the smaller y.\n */\n\nexport interface TextQuad {\n upperStart: Point;\n upperEnd: Point;\n lowerStart: Point;\n lowerEnd: Point;\n}\n\n/** A TextQuad tagged with its coordinate space. */\nexport type TextQuadIn<S extends Space> = TextQuad & SpaceBrand<S>;\n\n/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */\nexport function textQuadFromRect(r: Rect): TextQuad {\n return {\n upperStart: { x: r.x, y: r.y },\n upperEnd: { x: r.x + r.width, y: r.y },\n lowerStart: { x: r.x, y: r.y + r.height },\n lowerEnd: { x: r.x + r.width, y: r.y + r.height },\n };\n}\n\n/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */\nexport function textQuadPoints(t: TextQuad): [Point, Point, Point, Point] {\n return [t.upperStart, t.upperEnd, t.lowerStart, t.lowerEnd];\n}\n\n/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */\nexport function textQuadRing(t: TextQuad): [Point, Point, Point, Point] {\n return [t.upperStart, t.upperEnd, t.lowerEnd, t.lowerStart];\n}\n\n/** Axis-aligned bounds of a TextQuad. */\nexport function textQuadBounds(t: TextQuad): Rect {\n const xs = [t.upperStart.x, t.upperEnd.x, t.lowerStart.x, t.lowerEnd.x];\n const ys = [t.upperStart.y, t.upperEnd.y, t.lowerStart.y, t.lowerEnd.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return { x: minX, y: minY, width: Math.max(...xs) - minX, height: Math.max(...ys) - minY };\n}\n\n/** Map a TextQuad through an affine transform (corner semantics ride along). */\nexport function applyTextQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n t: TextQuadIn<F>,\n): TextQuadIn<T> {\n return {\n upperStart: applyPoint(m, t.upperStart as PointIn<F>),\n upperEnd: applyPoint(m, t.upperEnd as PointIn<F>),\n lowerStart: applyPoint(m, t.lowerStart as PointIn<F>),\n lowerEnd: applyPoint(m, t.lowerEnd as PointIn<F>),\n } as TextQuadIn<T>;\n}\n\n/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */\nexport function positionalQuad(t: TextQuad): Quad {\n return { p1: t.upperStart, p2: t.upperEnd, p3: t.lowerStart, p4: t.lowerEnd };\n}\n\nconst QUAD_EPSILON = 1e-6;\n\ntype QuadCornerList = [Point, Point, Point, Point];\n\nfunction finitePoint(p: Point): boolean {\n return Number.isFinite(p.x) && Number.isFinite(p.y);\n}\n\n/** Is `[us, ue, ls, le]` a well-formed zigzag reading of a quad? */\nfunction zigzagWellFormed([us, ue, ls, le]: QuadCornerList): boolean {\n if (![us, ue, ls, le].every(finitePoint)) return false;\n const upper = { x: ue.x - us.x, y: ue.y - us.y };\n const lower = { x: le.x - ls.x, y: le.y - ls.y };\n const startSide = { x: ls.x - us.x, y: ls.y - us.y };\n const endSide = { x: le.x - ue.x, y: le.y - ue.y };\n const lenU = Math.hypot(upper.x, upper.y);\n const lenL = Math.hypot(lower.x, lower.y);\n const lenS = Math.hypot(startSide.x, startSide.y);\n const lenE = Math.hypot(endSide.x, endSide.y);\n if (lenU <= QUAD_EPSILON || lenL <= QUAD_EPSILON || lenS <= QUAD_EPSILON || lenE <= QUAD_EPSILON)\n return false;\n // Opposite edges roughly parallel, same direction (rejects crossed/reversed).\n if (upper.x * lower.x + upper.y * lower.y <= 0) return false;\n if (startSide.x * endSide.x + startSide.y * endSide.y <= 0) return false;\n // Usable area, consistent winding on both ends.\n const startArea = upper.x * startSide.y - upper.y * startSide.x;\n const endArea = lower.x * endSide.y - lower.y * endSide.x;\n if (Math.abs(startArea) <= QUAD_EPSILON * lenU * lenS) return false;\n if (Math.abs(endArea) <= QUAD_EPSILON * lenL * lenE) return false;\n return Math.sign(startArea) === Math.sign(endArea);\n}\n\n/**\n * Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,\n * already in content space) as a TextQuad — a NORMALIZER, not a cast:\n *\n * 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —\n * this covers every well-formed writer, rotated quads included;\n * 2. the common ring order (US, UE, LE, LS) is recognized and repaired;\n * 3. anything else gets a deterministic geometric labeling: corners sorted\n * into a ring around their centroid, \"upper\" = the edge whose midpoint\n * sits highest on screen (smallest y). The 180° \"which side is up\"\n * ambiguity is unresolvable from geometry alone — convention decides.\n *\n * Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a\n * mislabeled import can shift an underline to the wrong edge but can never\n * crash or self-intersect.\n */\nexport function normalizeQuad(q: Quad): TextQuad {\n const zigzag: QuadCornerList = [q.p1, q.p2, q.p3, q.p4];\n if (zigzagWellFormed(zigzag)) {\n return { upperStart: q.p1, upperEnd: q.p2, lowerStart: q.p3, lowerEnd: q.p4 };\n }\n const ring: QuadCornerList = [q.p1, q.p2, q.p4, q.p3];\n if (zigzagWellFormed(ring)) {\n return { upperStart: q.p1, upperEnd: q.p2, lowerStart: q.p4, lowerEnd: q.p3 };\n }\n\n // Deterministic fallback for degenerate/garbage producers.\n const pts = [q.p1, q.p2, q.p3, q.p4].map((p) => (finitePoint(p) ? p : { x: 0, y: 0 }));\n const cx = (pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4;\n const cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4;\n const ringSorted = [...pts].sort(\n (a, b) => Math.atan2(a.y - cy, a.x - cx) - Math.atan2(b.y - cy, b.x - cx),\n );\n // Pick the ring edge whose midpoint sits highest on screen as the upper edge.\n let upperEdge = 0;\n let bestY = Infinity;\n for (let i = 0; i < 4; i++) {\n const midY = (ringSorted[i].y + ringSorted[(i + 1) % 4].y) / 2;\n if (midY < bestY) {\n bestY = midY;\n upperEdge = i;\n }\n }\n const a = ringSorted[upperEdge];\n const b = ringSorted[(upperEdge + 1) % 4];\n const c = ringSorted[(upperEdge + 2) % 4];\n const d = ringSorted[(upperEdge + 3) % 4];\n // Ring [a, b, c, d] with upper edge a→b ⇒ the opposite edge runs d→c.\n const startFirst = a.x <= b.x;\n return startFirst\n ? { upperStart: a, upperEnd: b, lowerStart: d, lowerEnd: c }\n : { upperStart: b, upperEnd: a, lowerStart: c, lowerEnd: d };\n}\n"],"mappings":";;;;;;;AAkCA,SAAgB,cAAc,OAAqC;CACjE,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,MAAM,KAAK,OAAO;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,CAAC;EAC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,WAAW;CACrB,MAAM,IAAI,YAAY,YAAY,KAAK;CACvC,MAAM,IAAI,YAAY,YAAY,KAAK;CACvC,MAAM,IAAI,YAAY,YAAY,KAAK;CAGvC,OADmB,EAAE,KAAK,EAAE,IAExB;EAAE,YAAY;EAAG,UAAU;EAAG,YAAY;EAAG,UAAU;CAAE,IACzD;EAAE,YAAY;EAAG,UAAU;EAAG,YAAY;EAAG,UAAU;CAAE;AAC/D"}
|
package/dist/index.d.cts
CHANGED
|
@@ -338,6 +338,43 @@ declare function pdfToContentMatrix(crop: {
|
|
|
338
338
|
* boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.
|
|
339
339
|
*/
|
|
340
340
|
declare function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry;
|
|
341
|
+
interface TextQuad {
|
|
342
|
+
upperStart: Point;
|
|
343
|
+
upperEnd: Point;
|
|
344
|
+
lowerStart: Point;
|
|
345
|
+
lowerEnd: Point;
|
|
346
|
+
}
|
|
347
|
+
/** A TextQuad tagged with its coordinate space. */
|
|
348
|
+
type TextQuadIn<S extends Space> = TextQuad & SpaceBrand<S>;
|
|
349
|
+
/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */
|
|
350
|
+
declare function textQuadFromRect(r: Rect): TextQuad;
|
|
351
|
+
/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */
|
|
352
|
+
declare function textQuadPoints(t: TextQuad): [Point, Point, Point, Point];
|
|
353
|
+
/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */
|
|
354
|
+
declare function textQuadRing(t: TextQuad): [Point, Point, Point, Point];
|
|
355
|
+
/** Axis-aligned bounds of a TextQuad. */
|
|
356
|
+
declare function textQuadBounds(t: TextQuad): Rect;
|
|
357
|
+
/** Map a TextQuad through an affine transform (corner semantics ride along). */
|
|
358
|
+
declare function applyTextQuad<F extends Space, T extends Space>(m: Mat2D<F, T>, t: TextQuadIn<F>): TextQuadIn<T>;
|
|
359
|
+
/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */
|
|
360
|
+
declare function positionalQuad(t: TextQuad): Quad;
|
|
361
|
+
/**
|
|
362
|
+
* Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,
|
|
363
|
+
* already in content space) as a TextQuad — a NORMALIZER, not a cast:
|
|
364
|
+
*
|
|
365
|
+
* 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —
|
|
366
|
+
* this covers every well-formed writer, rotated quads included;
|
|
367
|
+
* 2. the common ring order (US, UE, LE, LS) is recognized and repaired;
|
|
368
|
+
* 3. anything else gets a deterministic geometric labeling: corners sorted
|
|
369
|
+
* into a ring around their centroid, "upper" = the edge whose midpoint
|
|
370
|
+
* sits highest on screen (smallest y). The 180° "which side is up"
|
|
371
|
+
* ambiguity is unresolvable from geometry alone — convention decides.
|
|
372
|
+
*
|
|
373
|
+
* Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a
|
|
374
|
+
* mislabeled import can shift an underline to the wrong edge but can never
|
|
375
|
+
* crash or self-intersect.
|
|
376
|
+
*/
|
|
377
|
+
declare function normalizeQuad(q: Quad): TextQuad;
|
|
341
378
|
//#endregion
|
|
342
|
-
export { Mat2D, NO_FRAME, PageFrame, PageGeometry, PageGeometryInput, PageRotation, PageTransform, Point, PointIn, Quad, QuadIn, Rect, RectIn, Size, Space, addRotations, angleOf, applyPoint, applyQuad, applyRect, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, pageGeometry, pageTransform, pdfToContentMatrix, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, translate };
|
|
379
|
+
export { Mat2D, NO_FRAME, PageFrame, PageGeometry, PageGeometryInput, PageRotation, PageTransform, Point, PointIn, Quad, QuadIn, Rect, RectIn, Size, Space, TextQuad, TextQuadIn, addRotations, angleOf, applyPoint, applyQuad, applyRect, applyTextQuad, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, normalizeQuad, pageGeometry, pageTransform, pdfToContentMatrix, positionalQuad, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, textQuadBounds, textQuadFromRect, textQuadPoints, textQuadRing, translate };
|
|
343
380
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -338,6 +338,43 @@ declare function pdfToContentMatrix(crop: {
|
|
|
338
338
|
* boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.
|
|
339
339
|
*/
|
|
340
340
|
declare function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry;
|
|
341
|
+
interface TextQuad {
|
|
342
|
+
upperStart: Point;
|
|
343
|
+
upperEnd: Point;
|
|
344
|
+
lowerStart: Point;
|
|
345
|
+
lowerEnd: Point;
|
|
346
|
+
}
|
|
347
|
+
/** A TextQuad tagged with its coordinate space. */
|
|
348
|
+
type TextQuadIn<S extends Space> = TextQuad & SpaceBrand<S>;
|
|
349
|
+
/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */
|
|
350
|
+
declare function textQuadFromRect(r: Rect): TextQuad;
|
|
351
|
+
/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */
|
|
352
|
+
declare function textQuadPoints(t: TextQuad): [Point, Point, Point, Point];
|
|
353
|
+
/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */
|
|
354
|
+
declare function textQuadRing(t: TextQuad): [Point, Point, Point, Point];
|
|
355
|
+
/** Axis-aligned bounds of a TextQuad. */
|
|
356
|
+
declare function textQuadBounds(t: TextQuad): Rect;
|
|
357
|
+
/** Map a TextQuad through an affine transform (corner semantics ride along). */
|
|
358
|
+
declare function applyTextQuad<F extends Space, T extends Space>(m: Mat2D<F, T>, t: TextQuadIn<F>): TextQuadIn<T>;
|
|
359
|
+
/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */
|
|
360
|
+
declare function positionalQuad(t: TextQuad): Quad;
|
|
361
|
+
/**
|
|
362
|
+
* Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,
|
|
363
|
+
* already in content space) as a TextQuad — a NORMALIZER, not a cast:
|
|
364
|
+
*
|
|
365
|
+
* 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —
|
|
366
|
+
* this covers every well-formed writer, rotated quads included;
|
|
367
|
+
* 2. the common ring order (US, UE, LE, LS) is recognized and repaired;
|
|
368
|
+
* 3. anything else gets a deterministic geometric labeling: corners sorted
|
|
369
|
+
* into a ring around their centroid, "upper" = the edge whose midpoint
|
|
370
|
+
* sits highest on screen (smallest y). The 180° "which side is up"
|
|
371
|
+
* ambiguity is unresolvable from geometry alone — convention decides.
|
|
372
|
+
*
|
|
373
|
+
* Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a
|
|
374
|
+
* mislabeled import can shift an underline to the wrong edge but can never
|
|
375
|
+
* crash or self-intersect.
|
|
376
|
+
*/
|
|
377
|
+
declare function normalizeQuad(q: Quad): TextQuad;
|
|
341
378
|
//#endregion
|
|
342
|
-
export { Mat2D, NO_FRAME, PageFrame, PageGeometry, PageGeometryInput, PageRotation, PageTransform, Point, PointIn, Quad, QuadIn, Rect, RectIn, Size, Space, addRotations, angleOf, applyPoint, applyQuad, applyRect, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, pageGeometry, pageTransform, pdfToContentMatrix, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, translate };
|
|
379
|
+
export { Mat2D, NO_FRAME, PageFrame, PageGeometry, PageGeometryInput, PageRotation, PageTransform, Point, PointIn, Quad, QuadIn, Rect, RectIn, Size, Space, TextQuad, TextQuadIn, addRotations, angleOf, applyPoint, applyQuad, applyRect, applyTextQuad, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, normalizeQuad, pageGeometry, pageTransform, pdfToContentMatrix, positionalQuad, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, textQuadBounds, textQuadFromRect, textQuadPoints, textQuadRing, translate };
|
|
343
380
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -392,7 +392,204 @@ function pageGeometry(input, zoom) {
|
|
|
392
392
|
viewToPdf: invert(pdfToView)
|
|
393
393
|
};
|
|
394
394
|
}
|
|
395
|
+
/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */
|
|
396
|
+
function textQuadFromRect(r) {
|
|
397
|
+
return {
|
|
398
|
+
upperStart: {
|
|
399
|
+
x: r.x,
|
|
400
|
+
y: r.y
|
|
401
|
+
},
|
|
402
|
+
upperEnd: {
|
|
403
|
+
x: r.x + r.width,
|
|
404
|
+
y: r.y
|
|
405
|
+
},
|
|
406
|
+
lowerStart: {
|
|
407
|
+
x: r.x,
|
|
408
|
+
y: r.y + r.height
|
|
409
|
+
},
|
|
410
|
+
lowerEnd: {
|
|
411
|
+
x: r.x + r.width,
|
|
412
|
+
y: r.y + r.height
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */
|
|
417
|
+
function textQuadPoints(t) {
|
|
418
|
+
return [
|
|
419
|
+
t.upperStart,
|
|
420
|
+
t.upperEnd,
|
|
421
|
+
t.lowerStart,
|
|
422
|
+
t.lowerEnd
|
|
423
|
+
];
|
|
424
|
+
}
|
|
425
|
+
/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */
|
|
426
|
+
function textQuadRing(t) {
|
|
427
|
+
return [
|
|
428
|
+
t.upperStart,
|
|
429
|
+
t.upperEnd,
|
|
430
|
+
t.lowerEnd,
|
|
431
|
+
t.lowerStart
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
/** Axis-aligned bounds of a TextQuad. */
|
|
435
|
+
function textQuadBounds(t) {
|
|
436
|
+
const xs = [
|
|
437
|
+
t.upperStart.x,
|
|
438
|
+
t.upperEnd.x,
|
|
439
|
+
t.lowerStart.x,
|
|
440
|
+
t.lowerEnd.x
|
|
441
|
+
];
|
|
442
|
+
const ys = [
|
|
443
|
+
t.upperStart.y,
|
|
444
|
+
t.upperEnd.y,
|
|
445
|
+
t.lowerStart.y,
|
|
446
|
+
t.lowerEnd.y
|
|
447
|
+
];
|
|
448
|
+
const minX = Math.min(...xs);
|
|
449
|
+
const minY = Math.min(...ys);
|
|
450
|
+
return {
|
|
451
|
+
x: minX,
|
|
452
|
+
y: minY,
|
|
453
|
+
width: Math.max(...xs) - minX,
|
|
454
|
+
height: Math.max(...ys) - minY
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/** Map a TextQuad through an affine transform (corner semantics ride along). */
|
|
458
|
+
function applyTextQuad(m, t) {
|
|
459
|
+
return {
|
|
460
|
+
upperStart: applyPoint(m, t.upperStart),
|
|
461
|
+
upperEnd: applyPoint(m, t.upperEnd),
|
|
462
|
+
lowerStart: applyPoint(m, t.lowerStart),
|
|
463
|
+
lowerEnd: applyPoint(m, t.lowerEnd)
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */
|
|
467
|
+
function positionalQuad(t) {
|
|
468
|
+
return {
|
|
469
|
+
p1: t.upperStart,
|
|
470
|
+
p2: t.upperEnd,
|
|
471
|
+
p3: t.lowerStart,
|
|
472
|
+
p4: t.lowerEnd
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const QUAD_EPSILON = 1e-6;
|
|
476
|
+
function finitePoint(p) {
|
|
477
|
+
return Number.isFinite(p.x) && Number.isFinite(p.y);
|
|
478
|
+
}
|
|
479
|
+
/** Is `[us, ue, ls, le]` a well-formed zigzag reading of a quad? */
|
|
480
|
+
function zigzagWellFormed([us, ue, ls, le]) {
|
|
481
|
+
if (![
|
|
482
|
+
us,
|
|
483
|
+
ue,
|
|
484
|
+
ls,
|
|
485
|
+
le
|
|
486
|
+
].every(finitePoint)) return false;
|
|
487
|
+
const upper = {
|
|
488
|
+
x: ue.x - us.x,
|
|
489
|
+
y: ue.y - us.y
|
|
490
|
+
};
|
|
491
|
+
const lower = {
|
|
492
|
+
x: le.x - ls.x,
|
|
493
|
+
y: le.y - ls.y
|
|
494
|
+
};
|
|
495
|
+
const startSide = {
|
|
496
|
+
x: ls.x - us.x,
|
|
497
|
+
y: ls.y - us.y
|
|
498
|
+
};
|
|
499
|
+
const endSide = {
|
|
500
|
+
x: le.x - ue.x,
|
|
501
|
+
y: le.y - ue.y
|
|
502
|
+
};
|
|
503
|
+
const lenU = Math.hypot(upper.x, upper.y);
|
|
504
|
+
const lenL = Math.hypot(lower.x, lower.y);
|
|
505
|
+
const lenS = Math.hypot(startSide.x, startSide.y);
|
|
506
|
+
const lenE = Math.hypot(endSide.x, endSide.y);
|
|
507
|
+
if (lenU <= QUAD_EPSILON || lenL <= QUAD_EPSILON || lenS <= QUAD_EPSILON || lenE <= QUAD_EPSILON) return false;
|
|
508
|
+
if (upper.x * lower.x + upper.y * lower.y <= 0) return false;
|
|
509
|
+
if (startSide.x * endSide.x + startSide.y * endSide.y <= 0) return false;
|
|
510
|
+
const startArea = upper.x * startSide.y - upper.y * startSide.x;
|
|
511
|
+
const endArea = lower.x * endSide.y - lower.y * endSide.x;
|
|
512
|
+
if (Math.abs(startArea) <= QUAD_EPSILON * lenU * lenS) return false;
|
|
513
|
+
if (Math.abs(endArea) <= QUAD_EPSILON * lenL * lenE) return false;
|
|
514
|
+
return Math.sign(startArea) === Math.sign(endArea);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,
|
|
518
|
+
* already in content space) as a TextQuad — a NORMALIZER, not a cast:
|
|
519
|
+
*
|
|
520
|
+
* 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —
|
|
521
|
+
* this covers every well-formed writer, rotated quads included;
|
|
522
|
+
* 2. the common ring order (US, UE, LE, LS) is recognized and repaired;
|
|
523
|
+
* 3. anything else gets a deterministic geometric labeling: corners sorted
|
|
524
|
+
* into a ring around their centroid, "upper" = the edge whose midpoint
|
|
525
|
+
* sits highest on screen (smallest y). The 180° "which side is up"
|
|
526
|
+
* ambiguity is unresolvable from geometry alone — convention decides.
|
|
527
|
+
*
|
|
528
|
+
* Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a
|
|
529
|
+
* mislabeled import can shift an underline to the wrong edge but can never
|
|
530
|
+
* crash or self-intersect.
|
|
531
|
+
*/
|
|
532
|
+
function normalizeQuad(q) {
|
|
533
|
+
if (zigzagWellFormed([
|
|
534
|
+
q.p1,
|
|
535
|
+
q.p2,
|
|
536
|
+
q.p3,
|
|
537
|
+
q.p4
|
|
538
|
+
])) return {
|
|
539
|
+
upperStart: q.p1,
|
|
540
|
+
upperEnd: q.p2,
|
|
541
|
+
lowerStart: q.p3,
|
|
542
|
+
lowerEnd: q.p4
|
|
543
|
+
};
|
|
544
|
+
if (zigzagWellFormed([
|
|
545
|
+
q.p1,
|
|
546
|
+
q.p2,
|
|
547
|
+
q.p4,
|
|
548
|
+
q.p3
|
|
549
|
+
])) return {
|
|
550
|
+
upperStart: q.p1,
|
|
551
|
+
upperEnd: q.p2,
|
|
552
|
+
lowerStart: q.p4,
|
|
553
|
+
lowerEnd: q.p3
|
|
554
|
+
};
|
|
555
|
+
const pts = [
|
|
556
|
+
q.p1,
|
|
557
|
+
q.p2,
|
|
558
|
+
q.p3,
|
|
559
|
+
q.p4
|
|
560
|
+
].map((p) => finitePoint(p) ? p : {
|
|
561
|
+
x: 0,
|
|
562
|
+
y: 0
|
|
563
|
+
});
|
|
564
|
+
const cx = (pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4;
|
|
565
|
+
const cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4;
|
|
566
|
+
const ringSorted = [...pts].sort((a, b) => Math.atan2(a.y - cy, a.x - cx) - Math.atan2(b.y - cy, b.x - cx));
|
|
567
|
+
let upperEdge = 0;
|
|
568
|
+
let bestY = Infinity;
|
|
569
|
+
for (let i = 0; i < 4; i++) {
|
|
570
|
+
const midY = (ringSorted[i].y + ringSorted[(i + 1) % 4].y) / 2;
|
|
571
|
+
if (midY < bestY) {
|
|
572
|
+
bestY = midY;
|
|
573
|
+
upperEdge = i;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const a = ringSorted[upperEdge];
|
|
577
|
+
const b = ringSorted[(upperEdge + 1) % 4];
|
|
578
|
+
const c = ringSorted[(upperEdge + 2) % 4];
|
|
579
|
+
const d = ringSorted[(upperEdge + 3) % 4];
|
|
580
|
+
return a.x <= b.x ? {
|
|
581
|
+
upperStart: a,
|
|
582
|
+
upperEnd: b,
|
|
583
|
+
lowerStart: d,
|
|
584
|
+
lowerEnd: c
|
|
585
|
+
} : {
|
|
586
|
+
upperStart: b,
|
|
587
|
+
upperEnd: a,
|
|
588
|
+
lowerStart: c,
|
|
589
|
+
lowerEnd: d
|
|
590
|
+
};
|
|
591
|
+
}
|
|
395
592
|
//#endregion
|
|
396
|
-
export { NO_FRAME, addRotations, angleOf, applyPoint, applyQuad, applyRect, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, pageGeometry, pageTransform, pdfToContentMatrix, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, translate };
|
|
593
|
+
export { NO_FRAME, addRotations, angleOf, applyPoint, applyQuad, applyRect, applyTextQuad, boundsOfRects, compose, deviceHeightForWidth, displaySize, identity, intersectRects, invert, isQuarterTurn, matrixToCss, normalizeQuad, pageGeometry, pageTransform, pdfToContentMatrix, positionalQuad, rotate, rotateAbout, rotateScaleMatrix, scale, scaleAbout, snapToDevice, textQuadBounds, textQuadFromRect, textQuadPoints, textQuadRing, translate };
|
|
397
594
|
|
|
398
595
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @embedpdf/core-geometry — the viewer's pure 2D coordinate primitives.\n *\n * The bottom of the pyramid: stage-core (layout), plugin-stage (`pageToWorld`),\n * and every framework adapter (`toPagePoint` hit-testing) all sit on these.\n * Zero dependencies, DOM-free, serializable — Rust-portable.\n *\n * The page-rotation transforms are the reason this package exists: the same\n * quarter-turn maps content↔box in BOTH directions, and that one rule must not\n * be hand-written (and drift, or be bug-fixed in only one of four adapters).\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\nexport interface Size {\n width: number;\n height: number;\n}\n/** Viewer-side rect: top-left origin, y-down (view/page-point convention — NOT the\n * engine's bottom-left PDF rect). */\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * The bounding box of a set of rects (null for the empty set). Space-\n * agnostic: works on any y-down `{x,y,width,height}` rects — search hit\n * bounds, selection line-merge unions, multi-quad annotation extents.\n */\nexport function boundsOfRects(rects: readonly Rect[]): Rect | null {\n if (rects.length === 0) return null;\n let x1 = Infinity;\n let y1 = Infinity;\n let x2 = -Infinity;\n let y2 = -Infinity;\n for (const r of rects) {\n x1 = Math.min(x1, r.x);\n y1 = Math.min(y1, r.y);\n x2 = Math.max(x2, r.x + r.width);\n y2 = Math.max(y2, r.y + r.height);\n }\n return { x: x1, y: y1, width: x2 - x1, height: y2 - y1 };\n}\n\n/**\n * Intersection of two y-down rects — zero-sized (width/height 0, origin at\n * the would-be corner) when disjoint, so callers can test `width > 0`\n * without a null branch. Space-agnostic like {@link boundsOfRects}: view-px\n * viewport ∩ footprint, page-point visibility ∩ tile footprints, ….\n */\nexport function intersectRects(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return {\n x,\n y,\n width: Math.max(0, Math.min(a.x + a.width, b.x + b.width) - x),\n height: Math.max(0, Math.min(a.y + a.height, b.y + b.height) - y),\n };\n}\n\n/**\n * Quarter-turn display rotation, degrees clockwise. The viewer-side notion of a\n * page's on-screen rotation — the TOTAL = (document /Rotate + any view\n * rotation), resolved by the shell. Structurally identical to the engine's\n * `PageRotation`, so the two interoperate without this package depending on the\n * engine.\n */\nexport type PageRotation = 0 | 90 | 180 | 270;\n\n/**\n * Reserved chrome real estate around a page, one thickness per side (screen px\n * in the shell; world units in the pure layout). The page content sits inset\n * by these; the bands hold box-space chrome (labels, buttons, rails) that does\n * not rotate. The layout reserves the matching space so nothing overlaps.\n */\nexport interface PageFrame {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\nexport const NO_FRAME: PageFrame = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** True for the quarter-turns that swap a page's width and height. */\nexport function isQuarterTurn(rotation: PageRotation): boolean {\n return rotation === 90 || rotation === 270;\n}\n\n/**\n * Compose two quarter-turn rotations (mod 360). THE way the shell resolves a\n * page's TOTAL display rotation — `addRotations(page /Rotate, view rotation)`\n * — so the wrap arithmetic is never hand-written (and drift) per call site.\n */\nexport function addRotations(a: PageRotation, b: PageRotation): PageRotation {\n return ((a + b) % 360) as PageRotation;\n}\n\n/**\n * Snap a view-px value to the device pixel grid: round to a whole device pixel,\n * back to view px. Used for a page's screen POSITION so a CSS-rotated page lands\n * on the grid (no sub-pixel anti-aliased fringe). The shell never hand-rounds.\n */\nexport function snapToDevice(value: number, dpr: number): number {\n return Math.round(value * dpr) / dpr;\n}\n\n/** A page's on-screen footprint: width and height swapped for quarter-turns. */\nexport function displaySize(content: Size, rotation: PageRotation): Size {\n return isQuarterTurn(rotation)\n ? { width: content.height, height: content.width }\n : { width: content.width, height: content.height };\n}\n\n/**\n * The engine's `kind:'width'` height rule, replicated EXACTLY so the viewer can\n * predict the rendered bitmap's height up front — the page box is sized to it,\n * so the box matches the bitmap with no reflow and no 1px seam.\n *\n * Mirrors `PageRenderReader.resolveDeviceSize` (engine-services): we render the\n * page UN-rotated (CSS applies the rotation), so there is no width/height swap\n * here — `pageSize` is the page's own points. MUST stay in lockstep with that\n * function; the round-trip test in the render plugin asserts they agree.\n */\nexport function deviceHeightForWidth(pageSize: Size, deviceWidth: number): number {\n return Math.max(1, Math.round((deviceWidth * pageSize.height) / pageSize.width));\n}\n\n/**\n * The single per-page bridge between the viewer's three coordinate spaces. NB:\n * these are all VIEWER spaces — top-left origin, y-down. They are NOT the\n * engine's PDF user space (`Pdf*`, bottom-left origin, y-up); the engine→content\n * hop (the y-flip + crop offset) is a separate matrix (`pageGeometry`).\n *\n * content space page-local points, top-left, y-down — un-rotated page frame\n * view space platform logical px (web: CSS px) — layout, DOM, pointer events\n * device space physical pixels — the rendered bitmap\n *\n * PAGE-LOCAL by design: it knows this page's own box, NOT where the page sits in\n * the scene. Placement (camera/layout) stays on `VisiblePage.{x,y}` and positions\n * the page container; the transform converts everything INSIDE that container. So\n * it is camera/pan-invariant — it only changes on zoom / rotation / contentScale\n * / dpr, which makes it cheap to memoize.\n *\n * Every plugin and framework adapter consumes THIS — never `x * scale`, never\n * `pageToWorld()∘toScreen()`, never `* dpr`. New plugins (annotations, search,\n * forms) do no coordinate math; new platforms (iOS/Android) inject a different\n * `scale` and reuse all of it.\n */\nexport interface PageTransform {\n /**\n * The page's TOTAL display rotation (document /Rotate + any view rotation) —\n * the same value the transform's matrices were built from, exposed so\n * consumers that need the quarter-turn itself (an upright-placement rule, a\n * pointer sample) read it HERE instead of re-deriving it from the matrix.\n */\n readonly rotation: PageRotation;\n /** Display footprint in VIEW px (device-snapped) — the page container's size.\n * Width↔height already swapped for quarter-turns. */\n readonly viewWidth: number;\n readonly viewHeight: number;\n /** The UN-rotated content box in VIEW px — the size of the wrapper the bitmap\n * and content-space overlays live in (before the wrapper's CSS rotation). */\n readonly contentWidth: number;\n readonly contentHeight: number;\n /** Render the (un-rotated) bitmap at EXACTLY this — `viewport: {kind:'width', width: deviceWidth}`.\n * Integer device px; `deviceHeight` is the engine's exact derived height. */\n readonly deviceWidth: number;\n readonly deviceHeight: number;\n /** Device px per PDF point (uniform). */\n readonly renderScale: number;\n /** VIEW px per PDF point (uniform, device-snapped) — the one factor for\n * screen-constant chrome: content units = CSS px ÷ `viewScale`. */\n readonly viewScale: number;\n /**\n * View px per PDF point at 100% ZOOM — the page's physical baseline:\n * `viewUnitsPerPoint × userUnit` (web: 96/72 × `/UserUnit`, so 100% maps to\n * inches on screen, Acrobat-style). What \"100%\" MEANS for this page.\n */\n readonly baseScale: number;\n /**\n * The page's zoom RELATIVE to its 100% baseline (`viewScale / baseScale`,\n * dimensionless; exactly 1 at 100% for any `userUnit`). THE number\n * zoom-relative policies consume — e.g. the `/F` NoZoom exemption clamps\n * its body to `zoom ≤ 1`. Distinct from `viewScale` (a units conversion).\n */\n readonly zoom: number;\n /** Content point → UN-rotated content view px. For overlays INSIDE the rotated\n * content wrapper (markers, annotations) — they ride the wrapper's rotation,\n * so they place in content space and only scale here. */\n pageToContent(p: Point): Point;\n /** Content point → page-local view px in the DISPLAY box (rotation applied). For\n * footprint-space layers (outside the wrapper). */\n pageToView(p: Point): Point;\n /** Content rect → its axis-aligned view-px rect (exact for quarter-turns). */\n pageToViewRect(r: Rect): Rect;\n /** Inverse — display-box view px (box-local) → content point. Hit-testing. */\n viewToPage(p: Point): Point;\n /** Inverse of {@link pageToViewRect}: display-box view-px rect → its content\n * AABB (exact for quarter-turns). The visibility primitive — projecting a\n * viewport rect into page points is THIS, never per-adapter corner math. */\n viewToPageRect(r: Rect): Rect;\n /** CSS `matrix()` mapping content space → this page's display box. Drop it on\n * a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in content points — rotation + scale handled for free. */\n readonly cssMatrix: string;\n}\n\n/**\n * Build a page's transform from its intrinsic size + the platform/view scale.\n * `scale` is VIEW px per PDF point (the shell composes it: `viewUnitsPerPoint ×\n * contentScale × zoom`); `dpr` is device px per view px. Device dimensions snap\n * to the grid (crisp, no rotation fringe) and follow the engine's width rule\n * (box == bitmap, no reflow).\n */\nexport function pageTransform(input: {\n /** Un-rotated page size in PDF points. */\n pageSize: Size;\n rotation: PageRotation;\n /** View px per PDF point = viewUnitsPerPoint × contentScale × zoom. */\n scale: number;\n /**\n * View px per PDF point at 100% zoom (`viewUnitsPerPoint × userUnit`) — the\n * page's physical baseline, so `zoom = viewScale / baseScale` reads as\n * \"percent of Acrobat's 100%\". Default = `scale`, i.e. zoom ≈ 1: headless /\n * standalone callers stay neutral unless they declare a baseline.\n */\n baseScale?: number;\n /** Device px per view px (web: devicePixelRatio). */\n dpr: number;\n}): PageTransform {\n const { pageSize, rotation, scale, dpr } = input;\n\n // Raster: pin the width (snapped to the device grid), derive the height with\n // the engine's exact rule → uniform scale, integer device px, box == bitmap.\n const deviceWidth = Math.max(1, Math.round(pageSize.width * scale * dpr));\n const deviceHeight = deviceHeightForWidth(pageSize, deviceWidth);\n const renderScale = deviceWidth / pageSize.width;\n\n // The un-rotated content box in VIEW px, taken from the snapped device dims so\n // every edge lands on a whole device pixel. The effective view scale is derived\n // from it (not the raw `scale`) so `pageToView(pageWidth) === content edge`.\n const content: Size = { width: deviceWidth / dpr, height: deviceHeight / dpr };\n const viewScale = content.width / pageSize.width;\n const baseScale = input.baseScale ?? scale;\n const zoom = baseScale > 0 ? viewScale / baseScale : 1;\n\n const footprint = displaySize(content, rotation);\n\n // The two affines this page needs, as Mat2D — the matrix is the source of\n // truth; the methods and `cssMatrix` below are sugar over it (so they can\n // never drift).\n // content point (top-left, y-down) → content view px: pure isotropic scale.\n const contentMat = [viewScale, 0, 0, viewScale, 0, 0] as Mat2D;\n // content point → display-box view px: scale + the page's quarter-turn, from\n // the shared builder (the one quarter-turn encoding).\n const viewMat = rotateScaleMatrix(viewScale, content.width, content.height, rotation);\n const invMat = invert(viewMat);\n\n const pageToContent = (p: Point): Point => applyPoint(contentMat, p);\n const pageToView = (p: Point): Point => applyPoint(viewMat, p);\n const viewToPage = (p: Point): Point => applyPoint(invMat, p);\n const pageToViewRect = (r: Rect): Rect => applyRect(viewMat, r);\n const viewToPageRect = (r: Rect): Rect => applyRect(invMat, r);\n const cssMatrix = matrixToCss(viewMat);\n\n return {\n rotation,\n viewWidth: footprint.width,\n viewHeight: footprint.height,\n contentWidth: content.width,\n contentHeight: content.height,\n deviceWidth,\n deviceHeight,\n renderScale,\n viewScale,\n baseScale,\n zoom,\n pageToContent,\n pageToView,\n pageToViewRect,\n viewToPage,\n viewToPageRect,\n cssMatrix,\n };\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Matrix-native geometry — the composable primitive under every space hop.\n *\n * A coordinate-space conversion is a 2D affine `Mat2D = [a,b,c,d,e,f]` (the same\n * six numbers as CSS `matrix()`, `CGAffineTransform`, and Android `Matrix`):\n *\n * x' = a·x + c·y + e\n * y' = b·x + d·y + f\n *\n * Three generic appliers + `compose` + `invert` are the ENTIRE runtime — they\n * never grow as spaces/shapes/directions multiply, and they port 1:1 to Rust /\n * Swift / Kotlin (every target has a native affine). Inverses (hit-testing) and\n * screen composition fall out for free; there is no per-space hand-rolled y-flip\n * to drift between adapters.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * The coordinate spaces a viewer touches. `pdf` is the engine's PDF user space\n * (y-up, origin at the crop box bottom-left); the rest are viewer-local, y-down.\n */\nexport type Space = 'pdf' | 'content' | 'view' | 'screen';\n\n/**\n * Phantom space brand. It is OPTIONAL so plain `{ x, y }` / `{ x, y, w, h }`\n * literals stay assignable day-to-day (terse), but a value EXPLICITLY tagged\n * with the wrong space is rejected — and `Mat2D<From, To>` enforces the hop at\n * the matrix, so you cannot `applyRect` a `pdf` rect with a `content→view`\n * matrix. The brand is type-only; it carries no runtime field.\n */\ninterface SpaceBrand<S extends Space> {\n readonly __space?: S;\n}\n\n/** A point tagged with its coordinate space. */\nexport type PointIn<S extends Space> = Point & SpaceBrand<S>;\n/**\n * An axis-aligned rect tagged with its space, as min-corner + positive extent:\n * `(x, y)` is the corner with the smallest coordinates and `(x+width, y+height)`\n * the largest. In `pdf` space (y-up) that corner is bottom-left (`x=left`,\n * `y=bottom`); in the y-down viewer spaces it is top-left.\n */\nexport type RectIn<S extends Space> = Rect & SpaceBrand<S>;\n\n/**\n * Four POSITIONAL points (no corner semantics) — the viewer twin of the engine's\n * `PdfQuad`. Use this (via {@link applyQuad}) for rotatable/skewed content where\n * an axis-aligned rect would lie.\n */\nexport interface Quad {\n p1: Point;\n p2: Point;\n p3: Point;\n p4: Point;\n}\n/** A quad tagged with its coordinate space. */\nexport type QuadIn<S extends Space> = Quad & SpaceBrand<S>;\n\n/**\n * A 2D affine transform from space `From` to space `To`, stored as the six\n * numbers `[a, b, c, d, e, f]`. The phantom `From`/`To` make the compiler track\n * which spaces a matrix bridges, so composition and application can only be\n * wired up in the one correct order.\n */\nexport type Mat2D<From extends Space = Space, To extends Space = Space> = readonly [\n number,\n number,\n number,\n number,\n number,\n number,\n] & {\n readonly __from?: From;\n readonly __to?: To;\n};\n\n/** The identity transform within a single space. */\nexport function identity<S extends Space>(): Mat2D<S, S> {\n return [1, 0, 0, 1, 0, 0] as Mat2D<S, S>;\n}\n\n/**\n * Compose two matrices: `compose(m, n)` applies `n` first, then `m` (matrix\n * product `m · n`). The shared middle space `B` must line up, so the type system\n * rejects composing mismatched hops.\n */\nexport function compose<A extends Space, B extends Space, C extends Space>(\n m: Mat2D<B, C>,\n n: Mat2D<A, B>,\n): Mat2D<A, C> {\n const [a, b, c, d, e, f] = m;\n const [a2, b2, c2, d2, e2, f2] = n;\n return [\n a * a2 + c * b2,\n b * a2 + d * b2,\n a * c2 + c * d2,\n b * c2 + d * d2,\n a * e2 + c * f2 + e,\n b * e2 + d * f2 + f,\n ] as Mat2D<A, C>;\n}\n\n/** Invert a transform — `invert(pdfToView)` is `viewToPdf`, i.e. hit-testing for free. */\nexport function invert<F extends Space, T extends Space>(m: Mat2D<F, T>): Mat2D<T, F> {\n const [a, b, c, d, e, f] = m;\n const det = a * d - b * c;\n if (det === 0) throw new Error('Mat2D.invert: non-invertible matrix (det = 0)');\n const ia = d / det;\n const ib = -b / det;\n const ic = -c / det;\n const id = a / det;\n return [ia, ib, ic, id, -(ia * e + ic * f), -(ib * e + id * f)] as Mat2D<T, F>;\n}\n\n/** Apply a transform to a point. */\nexport function applyPoint<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n p: PointIn<F>,\n): PointIn<T> {\n const [a, b, c, d, e, f] = m;\n return { x: a * p.x + c * p.y + e, y: b * p.x + d * p.y + f } as PointIn<T>;\n}\n\n/**\n * Apply a transform to a rect, returning the axis-aligned bounding box of the\n * four transformed corners. EXACT for translate/scale/quarter-turn (every page\n * transform `pageGeometry` produces); lossy under skew — use {@link applyQuad}\n * for content that can be rotated off-axis.\n */\nexport function applyRect<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n r: RectIn<F>,\n): RectIn<T> {\n const c0 = applyPoint(m, { x: r.x, y: r.y } as PointIn<F>);\n const c1 = applyPoint(m, { x: r.x + r.width, y: r.y } as PointIn<F>);\n const c2 = applyPoint(m, { x: r.x, y: r.y + r.height } as PointIn<F>);\n const c3 = applyPoint(m, { x: r.x + r.width, y: r.y + r.height } as PointIn<F>);\n const xs = [c0.x, c1.x, c2.x, c3.x];\n const ys = [c0.y, c1.y, c2.y, c3.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return {\n x: minX,\n y: minY,\n width: Math.max(...xs) - minX,\n height: Math.max(...ys) - minY,\n } as RectIn<T>;\n}\n\n/** Apply a transform to a quad, preserving orientation (maps the four points). */\nexport function applyQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n q: QuadIn<F>,\n): QuadIn<T> {\n return {\n p1: applyPoint(m, q.p1 as PointIn<F>),\n p2: applyPoint(m, q.p2 as PointIn<F>),\n p3: applyPoint(m, q.p3 as PointIn<F>),\n p4: applyPoint(m, q.p4 as PointIn<F>),\n } as QuadIn<T>;\n}\n\n/**\n * A `Mat2D` IS a CSS `matrix()` — the six numbers are identical. Drop the result\n * on a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in the source space; the rotation + scale are handled for free.\n */\nexport function matrixToCss(m: Mat2D): string {\n const [a, b, c, d, e, f] = m;\n return `matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`;\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Same-space affine builders — generic, free-angle transforms WITHIN one space\n * (`Mat2D<S, S>`). The `rotateScaleMatrix` above is a quarter-turn, cross-space\n * builder for page layout; these are the arbitrary-angle primitives content\n * editing (annotation rotation/scale, future stamps/skew) composes from. They\n * never know about annotations — they are the bottom-of-the-pyramid matrix math,\n * so it isn't hand-rolled (and drift) in every plugin.\n *\n * Convention: a viewer content space is y-DOWN, so `rotate(rad)` —\n * `[cos, sin, -sin, cos, 0, 0]` — turns CLOCKWISE on screen (matching the\n * viewer's page-rotation direction). The PDF (y-up) flip, when one is needed,\n * is a separate hop applied once at the engine boundary.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** Translate within a space. */\nexport function translate<S extends Space>(tx: number, ty: number): Mat2D<S, S> {\n return [1, 0, 0, 1, tx, ty] as Mat2D<S, S>;\n}\n\n/** Scale about the space origin. */\nexport function scale<S extends Space>(sx: number, sy: number): Mat2D<S, S> {\n return [sx, 0, 0, sy, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about the space origin (radians; clockwise in y-down content space). */\nexport function rotate<S extends Space>(rad: number): Mat2D<S, S> {\n const c = Math.cos(rad);\n const s = Math.sin(rad);\n return [c, s, -s, c, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about an arbitrary pivot: `T(c) · R(rad) · T(-c)`. */\nexport function rotateAbout<S extends Space>(c: PointIn<S>, rad: number): Mat2D<S, S> {\n return compose(translate<S>(c.x, c.y), compose(rotate<S>(rad), translate<S>(-c.x, -c.y)));\n}\n\n/** Scale about an arbitrary anchor: `T(a) · S(sx, sy) · T(-a)`. */\nexport function scaleAbout<S extends Space>(a: PointIn<S>, sx: number, sy: number): Mat2D<S, S> {\n return compose(translate<S>(a.x, a.y), compose(scale<S>(sx, sy), translate<S>(-a.x, -a.y)));\n}\n\n/** The rotation angle (radians) encoded in a matrix — `atan2(b, a)`. Positive is\n * clockwise in y-down content space (the inverse of {@link rotate}). */\nexport function angleOf(m: Mat2D): number {\n return Math.atan2(m[1], m[0]);\n}\n\n/**\n * The page's scale + integer quarter-turn as a `Mat2D`: a content point maps to\n * its place in the rotated DISPLAY box. `scale` is output units per content\n * point; `boxW`/`boxH` are the UN-rotated content's extents in those same output\n * units, and the offsets keep the footprint in the box's positive quadrant\n * (origin at the box top-left).\n *\n * THE single encoding of the quarter-turn — `pageTransform` (view px),\n * `pageGeometry` (the `content→view` hop), and `pageToWorld` (world units) all\n * build on this one function, so the rotation can never drift between them.\n */\nexport function rotateScaleMatrix(\n scale: number,\n boxW: number,\n boxH: number,\n rotation: PageRotation,\n): Mat2D {\n switch (rotation) {\n case 90:\n return [0, scale, -scale, 0, boxH, 0] as Mat2D;\n case 180:\n return [-scale, 0, 0, -scale, boxW, boxH] as Mat2D;\n case 270:\n return [0, -scale, scale, 0, 0, boxW] as Mat2D;\n default:\n return [scale, 0, 0, scale, 0, 0] as Mat2D;\n }\n}\n\n/**\n * The per-page geometry input. Structurally a subset of the engine's\n * `PageLayout` (so a layout can be passed straight in), but defined here to keep\n * this package dependency-free — the same reason {@link PageRotation} is a\n * structural twin of the engine's rotation.\n */\nexport interface PageGeometryInput {\n /** Effective crop box in PDF user space (y-up edges); origin preserved, so\n * `left`/`bottom` may be non-zero or negative. */\n crop: { left: number; bottom: number; right: number; top: number };\n /** Persistent page rotation (the document's `/Rotate`). */\n rotation: PageRotation;\n /** PDF `userUnit` (§14.11.6): scales PDF points into the layout. 1 for most docs. */\n userUnit: number;\n}\n\n/** The matrices bridging one page's spaces — every other matrix composes from these. */\nexport interface PageGeometry {\n /** PDF user space (y-up, crop-relative) → content space (y-down, crop top-left, unscaled points). */\n readonly pdfToContent: Mat2D<'pdf', 'content'>;\n /** Content → view: scale (zoom × userUnit) + the page's quarter-turn rotation. */\n readonly contentToView: Mat2D<'content', 'view'>;\n /** PDF → view, precomposed. */\n readonly pdfToView: Mat2D<'pdf', 'view'>;\n /** View → PDF, the inverse — hit-testing for free. */\n readonly viewToPdf: Mat2D<'view', 'pdf'>;\n}\n\n/**\n * PDF user space (y-up, origin = crop bottom-left) → content space (y-down,\n * origin = crop top-left, unscaled points). THE single encoding of the engine→\n * content y-flip + crop offset: `pageGeometry` composes its `pdfToContent` from\n * this, and pure annotation geometry (content-space editing) reuses it too, so\n * the rule can never be hand-written twice and drift.\n */\nexport function pdfToContentMatrix(crop: { left: number; top: number }): Mat2D<'pdf', 'content'> {\n return [1, 0, 0, -1, -crop.left, crop.top] as Mat2D<'pdf', 'content'>;\n}\n\n/**\n * Build a page's space matrices from its crop box, rotation, and `userUnit` plus\n * the viewer `zoom`. This is the ONE function that knows the y-flip, crop origin,\n * `userUnit`, and rotation; everything else composes from its output. The engine\n * never emits these — they bake in viewer state (zoom, later scroll/dpr) — so the\n * boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.\n */\nexport function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry {\n const { crop, rotation, userUnit } = input;\n const s = zoom * userUnit; // view px per PDF point — userUnit folded in HERE, once\n\n // PDF user space (y-up, origin = crop bottom-left) → content (y-down, origin = crop top-left).\n const pdfToContent = pdfToContentMatrix(crop);\n\n // Content → view: scale + integer quarter-turn, from the shared builder (the\n // one quarter-turn encoding). `Wc`/`Hc` are the unrotated content's view-px\n // extents (the builder places the footprint in the box's positive quadrant).\n const Wc = (crop.right - crop.left) * s;\n const Hc = (crop.top - crop.bottom) * s;\n const contentToView = rotateScaleMatrix(s, Wc, Hc, rotation) as Mat2D<'content', 'view'>;\n\n const pdfToView = compose(contentToView, pdfToContent);\n return { pdfToContent, contentToView, pdfToView, viewToPdf: invert(pdfToView) };\n}\n"],"mappings":";;;;;;AAkCA,SAAgB,cAAc,OAAqC;CACjE,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,KAAK;CACT,IAAI,K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,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @embedpdf/core-geometry — the viewer's pure 2D coordinate primitives.\n *\n * The bottom of the pyramid: stage-core (layout), plugin-stage (`pageToWorld`),\n * and every framework adapter (`toPagePoint` hit-testing) all sit on these.\n * Zero dependencies, DOM-free, serializable — Rust-portable.\n *\n * The page-rotation transforms are the reason this package exists: the same\n * quarter-turn maps content↔box in BOTH directions, and that one rule must not\n * be hand-written (and drift, or be bug-fixed in only one of four adapters).\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\nexport interface Size {\n width: number;\n height: number;\n}\n/** Viewer-side rect: top-left origin, y-down (view/page-point convention — NOT the\n * engine's bottom-left PDF rect). */\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * The bounding box of a set of rects (null for the empty set). Space-\n * agnostic: works on any y-down `{x,y,width,height}` rects — search hit\n * bounds, selection line-merge unions, multi-quad annotation extents.\n */\nexport function boundsOfRects(rects: readonly Rect[]): Rect | null {\n if (rects.length === 0) return null;\n let x1 = Infinity;\n let y1 = Infinity;\n let x2 = -Infinity;\n let y2 = -Infinity;\n for (const r of rects) {\n x1 = Math.min(x1, r.x);\n y1 = Math.min(y1, r.y);\n x2 = Math.max(x2, r.x + r.width);\n y2 = Math.max(y2, r.y + r.height);\n }\n return { x: x1, y: y1, width: x2 - x1, height: y2 - y1 };\n}\n\n/**\n * Intersection of two y-down rects — zero-sized (width/height 0, origin at\n * the would-be corner) when disjoint, so callers can test `width > 0`\n * without a null branch. Space-agnostic like {@link boundsOfRects}: view-px\n * viewport ∩ footprint, page-point visibility ∩ tile footprints, ….\n */\nexport function intersectRects(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return {\n x,\n y,\n width: Math.max(0, Math.min(a.x + a.width, b.x + b.width) - x),\n height: Math.max(0, Math.min(a.y + a.height, b.y + b.height) - y),\n };\n}\n\n/**\n * Quarter-turn display rotation, degrees clockwise. The viewer-side notion of a\n * page's on-screen rotation — the TOTAL = (document /Rotate + any view\n * rotation), resolved by the shell. Structurally identical to the engine's\n * `PageRotation`, so the two interoperate without this package depending on the\n * engine.\n */\nexport type PageRotation = 0 | 90 | 180 | 270;\n\n/**\n * Reserved chrome real estate around a page, one thickness per side (screen px\n * in the shell; world units in the pure layout). The page content sits inset\n * by these; the bands hold box-space chrome (labels, buttons, rails) that does\n * not rotate. The layout reserves the matching space so nothing overlaps.\n */\nexport interface PageFrame {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\nexport const NO_FRAME: PageFrame = { top: 0, right: 0, bottom: 0, left: 0 };\n\n/** True for the quarter-turns that swap a page's width and height. */\nexport function isQuarterTurn(rotation: PageRotation): boolean {\n return rotation === 90 || rotation === 270;\n}\n\n/**\n * Compose two quarter-turn rotations (mod 360). THE way the shell resolves a\n * page's TOTAL display rotation — `addRotations(page /Rotate, view rotation)`\n * — so the wrap arithmetic is never hand-written (and drift) per call site.\n */\nexport function addRotations(a: PageRotation, b: PageRotation): PageRotation {\n return ((a + b) % 360) as PageRotation;\n}\n\n/**\n * Snap a view-px value to the device pixel grid: round to a whole device pixel,\n * back to view px. Used for a page's screen POSITION so a CSS-rotated page lands\n * on the grid (no sub-pixel anti-aliased fringe). The shell never hand-rounds.\n */\nexport function snapToDevice(value: number, dpr: number): number {\n return Math.round(value * dpr) / dpr;\n}\n\n/** A page's on-screen footprint: width and height swapped for quarter-turns. */\nexport function displaySize(content: Size, rotation: PageRotation): Size {\n return isQuarterTurn(rotation)\n ? { width: content.height, height: content.width }\n : { width: content.width, height: content.height };\n}\n\n/**\n * The engine's `kind:'width'` height rule, replicated EXACTLY so the viewer can\n * predict the rendered bitmap's height up front — the page box is sized to it,\n * so the box matches the bitmap with no reflow and no 1px seam.\n *\n * Mirrors `PageRenderReader.resolveDeviceSize` (engine-services): we render the\n * page UN-rotated (CSS applies the rotation), so there is no width/height swap\n * here — `pageSize` is the page's own points. MUST stay in lockstep with that\n * function; the round-trip test in the render plugin asserts they agree.\n */\nexport function deviceHeightForWidth(pageSize: Size, deviceWidth: number): number {\n return Math.max(1, Math.round((deviceWidth * pageSize.height) / pageSize.width));\n}\n\n/**\n * The single per-page bridge between the viewer's three coordinate spaces. NB:\n * these are all VIEWER spaces — top-left origin, y-down. They are NOT the\n * engine's PDF user space (`Pdf*`, bottom-left origin, y-up); the engine→content\n * hop (the y-flip + crop offset) is a separate matrix (`pageGeometry`).\n *\n * content space page-local points, top-left, y-down — un-rotated page frame\n * view space platform logical px (web: CSS px) — layout, DOM, pointer events\n * device space physical pixels — the rendered bitmap\n *\n * PAGE-LOCAL by design: it knows this page's own box, NOT where the page sits in\n * the scene. Placement (camera/layout) stays on `VisiblePage.{x,y}` and positions\n * the page container; the transform converts everything INSIDE that container. So\n * it is camera/pan-invariant — it only changes on zoom / rotation / contentScale\n * / dpr, which makes it cheap to memoize.\n *\n * Every plugin and framework adapter consumes THIS — never `x * scale`, never\n * `pageToWorld()∘toScreen()`, never `* dpr`. New plugins (annotations, search,\n * forms) do no coordinate math; new platforms (iOS/Android) inject a different\n * `scale` and reuse all of it.\n */\nexport interface PageTransform {\n /**\n * The page's TOTAL display rotation (document /Rotate + any view rotation) —\n * the same value the transform's matrices were built from, exposed so\n * consumers that need the quarter-turn itself (an upright-placement rule, a\n * pointer sample) read it HERE instead of re-deriving it from the matrix.\n */\n readonly rotation: PageRotation;\n /** Display footprint in VIEW px (device-snapped) — the page container's size.\n * Width↔height already swapped for quarter-turns. */\n readonly viewWidth: number;\n readonly viewHeight: number;\n /** The UN-rotated content box in VIEW px — the size of the wrapper the bitmap\n * and content-space overlays live in (before the wrapper's CSS rotation). */\n readonly contentWidth: number;\n readonly contentHeight: number;\n /** Render the (un-rotated) bitmap at EXACTLY this — `viewport: {kind:'width', width: deviceWidth}`.\n * Integer device px; `deviceHeight` is the engine's exact derived height. */\n readonly deviceWidth: number;\n readonly deviceHeight: number;\n /** Device px per PDF point (uniform). */\n readonly renderScale: number;\n /** VIEW px per PDF point (uniform, device-snapped) — the one factor for\n * screen-constant chrome: content units = CSS px ÷ `viewScale`. */\n readonly viewScale: number;\n /**\n * View px per PDF point at 100% ZOOM — the page's physical baseline:\n * `viewUnitsPerPoint × userUnit` (web: 96/72 × `/UserUnit`, so 100% maps to\n * inches on screen, Acrobat-style). What \"100%\" MEANS for this page.\n */\n readonly baseScale: number;\n /**\n * The page's zoom RELATIVE to its 100% baseline (`viewScale / baseScale`,\n * dimensionless; exactly 1 at 100% for any `userUnit`). THE number\n * zoom-relative policies consume — e.g. the `/F` NoZoom exemption clamps\n * its body to `zoom ≤ 1`. Distinct from `viewScale` (a units conversion).\n */\n readonly zoom: number;\n /** Content point → UN-rotated content view px. For overlays INSIDE the rotated\n * content wrapper (markers, annotations) — they ride the wrapper's rotation,\n * so they place in content space and only scale here. */\n pageToContent(p: Point): Point;\n /** Content point → page-local view px in the DISPLAY box (rotation applied). For\n * footprint-space layers (outside the wrapper). */\n pageToView(p: Point): Point;\n /** Content rect → its axis-aligned view-px rect (exact for quarter-turns). */\n pageToViewRect(r: Rect): Rect;\n /** Inverse — display-box view px (box-local) → content point. Hit-testing. */\n viewToPage(p: Point): Point;\n /** Inverse of {@link pageToViewRect}: display-box view-px rect → its content\n * AABB (exact for quarter-turns). The visibility primitive — projecting a\n * viewport rect into page points is THIS, never per-adapter corner math. */\n viewToPageRect(r: Rect): Rect;\n /** CSS `matrix()` mapping content space → this page's display box. Drop it on\n * a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in content points — rotation + scale handled for free. */\n readonly cssMatrix: string;\n}\n\n/**\n * Build a page's transform from its intrinsic size + the platform/view scale.\n * `scale` is VIEW px per PDF point (the shell composes it: `viewUnitsPerPoint ×\n * contentScale × zoom`); `dpr` is device px per view px. Device dimensions snap\n * to the grid (crisp, no rotation fringe) and follow the engine's width rule\n * (box == bitmap, no reflow).\n */\nexport function pageTransform(input: {\n /** Un-rotated page size in PDF points. */\n pageSize: Size;\n rotation: PageRotation;\n /** View px per PDF point = viewUnitsPerPoint × contentScale × zoom. */\n scale: number;\n /**\n * View px per PDF point at 100% zoom (`viewUnitsPerPoint × userUnit`) — the\n * page's physical baseline, so `zoom = viewScale / baseScale` reads as\n * \"percent of Acrobat's 100%\". Default = `scale`, i.e. zoom ≈ 1: headless /\n * standalone callers stay neutral unless they declare a baseline.\n */\n baseScale?: number;\n /** Device px per view px (web: devicePixelRatio). */\n dpr: number;\n}): PageTransform {\n const { pageSize, rotation, scale, dpr } = input;\n\n // Raster: pin the width (snapped to the device grid), derive the height with\n // the engine's exact rule → uniform scale, integer device px, box == bitmap.\n const deviceWidth = Math.max(1, Math.round(pageSize.width * scale * dpr));\n const deviceHeight = deviceHeightForWidth(pageSize, deviceWidth);\n const renderScale = deviceWidth / pageSize.width;\n\n // The un-rotated content box in VIEW px, taken from the snapped device dims so\n // every edge lands on a whole device pixel. The effective view scale is derived\n // from it (not the raw `scale`) so `pageToView(pageWidth) === content edge`.\n const content: Size = { width: deviceWidth / dpr, height: deviceHeight / dpr };\n const viewScale = content.width / pageSize.width;\n const baseScale = input.baseScale ?? scale;\n const zoom = baseScale > 0 ? viewScale / baseScale : 1;\n\n const footprint = displaySize(content, rotation);\n\n // The two affines this page needs, as Mat2D — the matrix is the source of\n // truth; the methods and `cssMatrix` below are sugar over it (so they can\n // never drift).\n // content point (top-left, y-down) → content view px: pure isotropic scale.\n const contentMat = [viewScale, 0, 0, viewScale, 0, 0] as Mat2D;\n // content point → display-box view px: scale + the page's quarter-turn, from\n // the shared builder (the one quarter-turn encoding).\n const viewMat = rotateScaleMatrix(viewScale, content.width, content.height, rotation);\n const invMat = invert(viewMat);\n\n const pageToContent = (p: Point): Point => applyPoint(contentMat, p);\n const pageToView = (p: Point): Point => applyPoint(viewMat, p);\n const viewToPage = (p: Point): Point => applyPoint(invMat, p);\n const pageToViewRect = (r: Rect): Rect => applyRect(viewMat, r);\n const viewToPageRect = (r: Rect): Rect => applyRect(invMat, r);\n const cssMatrix = matrixToCss(viewMat);\n\n return {\n rotation,\n viewWidth: footprint.width,\n viewHeight: footprint.height,\n contentWidth: content.width,\n contentHeight: content.height,\n deviceWidth,\n deviceHeight,\n renderScale,\n viewScale,\n baseScale,\n zoom,\n pageToContent,\n pageToView,\n pageToViewRect,\n viewToPage,\n viewToPageRect,\n cssMatrix,\n };\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Matrix-native geometry — the composable primitive under every space hop.\n *\n * A coordinate-space conversion is a 2D affine `Mat2D = [a,b,c,d,e,f]` (the same\n * six numbers as CSS `matrix()`, `CGAffineTransform`, and Android `Matrix`):\n *\n * x' = a·x + c·y + e\n * y' = b·x + d·y + f\n *\n * Three generic appliers + `compose` + `invert` are the ENTIRE runtime — they\n * never grow as spaces/shapes/directions multiply, and they port 1:1 to Rust /\n * Swift / Kotlin (every target has a native affine). Inverses (hit-testing) and\n * screen composition fall out for free; there is no per-space hand-rolled y-flip\n * to drift between adapters.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/**\n * The coordinate spaces a viewer touches. `pdf` is the engine's PDF user space\n * (y-up, origin at the crop box bottom-left); the rest are viewer-local, y-down.\n */\nexport type Space = 'pdf' | 'content' | 'view' | 'screen';\n\n/**\n * Phantom space brand. It is OPTIONAL so plain `{ x, y }` / `{ x, y, w, h }`\n * literals stay assignable day-to-day (terse), but a value EXPLICITLY tagged\n * with the wrong space is rejected — and `Mat2D<From, To>` enforces the hop at\n * the matrix, so you cannot `applyRect` a `pdf` rect with a `content→view`\n * matrix. The brand is type-only; it carries no runtime field.\n */\ninterface SpaceBrand<S extends Space> {\n readonly __space?: S;\n}\n\n/** A point tagged with its coordinate space. */\nexport type PointIn<S extends Space> = Point & SpaceBrand<S>;\n/**\n * An axis-aligned rect tagged with its space, as min-corner + positive extent:\n * `(x, y)` is the corner with the smallest coordinates and `(x+width, y+height)`\n * the largest. In `pdf` space (y-up) that corner is bottom-left (`x=left`,\n * `y=bottom`); in the y-down viewer spaces it is top-left.\n */\nexport type RectIn<S extends Space> = Rect & SpaceBrand<S>;\n\n/**\n * Four POSITIONAL points (no corner semantics) — the viewer twin of the engine's\n * `PdfQuad`. Use this (via {@link applyQuad}) for rotatable/skewed content where\n * an axis-aligned rect would lie.\n */\nexport interface Quad {\n p1: Point;\n p2: Point;\n p3: Point;\n p4: Point;\n}\n/** A quad tagged with its coordinate space. */\nexport type QuadIn<S extends Space> = Quad & SpaceBrand<S>;\n\n/**\n * A 2D affine transform from space `From` to space `To`, stored as the six\n * numbers `[a, b, c, d, e, f]`. The phantom `From`/`To` make the compiler track\n * which spaces a matrix bridges, so composition and application can only be\n * wired up in the one correct order.\n */\nexport type Mat2D<From extends Space = Space, To extends Space = Space> = readonly [\n number,\n number,\n number,\n number,\n number,\n number,\n] & {\n readonly __from?: From;\n readonly __to?: To;\n};\n\n/** The identity transform within a single space. */\nexport function identity<S extends Space>(): Mat2D<S, S> {\n return [1, 0, 0, 1, 0, 0] as Mat2D<S, S>;\n}\n\n/**\n * Compose two matrices: `compose(m, n)` applies `n` first, then `m` (matrix\n * product `m · n`). The shared middle space `B` must line up, so the type system\n * rejects composing mismatched hops.\n */\nexport function compose<A extends Space, B extends Space, C extends Space>(\n m: Mat2D<B, C>,\n n: Mat2D<A, B>,\n): Mat2D<A, C> {\n const [a, b, c, d, e, f] = m;\n const [a2, b2, c2, d2, e2, f2] = n;\n return [\n a * a2 + c * b2,\n b * a2 + d * b2,\n a * c2 + c * d2,\n b * c2 + d * d2,\n a * e2 + c * f2 + e,\n b * e2 + d * f2 + f,\n ] as Mat2D<A, C>;\n}\n\n/** Invert a transform — `invert(pdfToView)` is `viewToPdf`, i.e. hit-testing for free. */\nexport function invert<F extends Space, T extends Space>(m: Mat2D<F, T>): Mat2D<T, F> {\n const [a, b, c, d, e, f] = m;\n const det = a * d - b * c;\n if (det === 0) throw new Error('Mat2D.invert: non-invertible matrix (det = 0)');\n const ia = d / det;\n const ib = -b / det;\n const ic = -c / det;\n const id = a / det;\n return [ia, ib, ic, id, -(ia * e + ic * f), -(ib * e + id * f)] as Mat2D<T, F>;\n}\n\n/** Apply a transform to a point. */\nexport function applyPoint<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n p: PointIn<F>,\n): PointIn<T> {\n const [a, b, c, d, e, f] = m;\n return { x: a * p.x + c * p.y + e, y: b * p.x + d * p.y + f } as PointIn<T>;\n}\n\n/**\n * Apply a transform to a rect, returning the axis-aligned bounding box of the\n * four transformed corners. EXACT for translate/scale/quarter-turn (every page\n * transform `pageGeometry` produces); lossy under skew — use {@link applyQuad}\n * for content that can be rotated off-axis.\n */\nexport function applyRect<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n r: RectIn<F>,\n): RectIn<T> {\n const c0 = applyPoint(m, { x: r.x, y: r.y } as PointIn<F>);\n const c1 = applyPoint(m, { x: r.x + r.width, y: r.y } as PointIn<F>);\n const c2 = applyPoint(m, { x: r.x, y: r.y + r.height } as PointIn<F>);\n const c3 = applyPoint(m, { x: r.x + r.width, y: r.y + r.height } as PointIn<F>);\n const xs = [c0.x, c1.x, c2.x, c3.x];\n const ys = [c0.y, c1.y, c2.y, c3.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return {\n x: minX,\n y: minY,\n width: Math.max(...xs) - minX,\n height: Math.max(...ys) - minY,\n } as RectIn<T>;\n}\n\n/** Apply a transform to a quad, preserving orientation (maps the four points). */\nexport function applyQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n q: QuadIn<F>,\n): QuadIn<T> {\n return {\n p1: applyPoint(m, q.p1 as PointIn<F>),\n p2: applyPoint(m, q.p2 as PointIn<F>),\n p3: applyPoint(m, q.p3 as PointIn<F>),\n p4: applyPoint(m, q.p4 as PointIn<F>),\n } as QuadIn<T>;\n}\n\n/**\n * A `Mat2D` IS a CSS `matrix()` — the six numbers are identical. Drop the result\n * on a footprint-space layer (`transform`, `transform-origin: 0 0`) and place\n * children in the source space; the rotation + scale are handled for free.\n */\nexport function matrixToCss(m: Mat2D): string {\n const [a, b, c, d, e, f] = m;\n return `matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`;\n}\n\n/* ────────────────────────────────────────────────────────────────────────────\n * Same-space affine builders — generic, free-angle transforms WITHIN one space\n * (`Mat2D<S, S>`). The `rotateScaleMatrix` above is a quarter-turn, cross-space\n * builder for page layout; these are the arbitrary-angle primitives content\n * editing (annotation rotation/scale, future stamps/skew) composes from. They\n * never know about annotations — they are the bottom-of-the-pyramid matrix math,\n * so it isn't hand-rolled (and drift) in every plugin.\n *\n * Convention: a viewer content space is y-DOWN, so `rotate(rad)` —\n * `[cos, sin, -sin, cos, 0, 0]` — turns CLOCKWISE on screen (matching the\n * viewer's page-rotation direction). The PDF (y-up) flip, when one is needed,\n * is a separate hop applied once at the engine boundary.\n * ──────────────────────────────────────────────────────────────────────────── */\n\n/** Translate within a space. */\nexport function translate<S extends Space>(tx: number, ty: number): Mat2D<S, S> {\n return [1, 0, 0, 1, tx, ty] as Mat2D<S, S>;\n}\n\n/** Scale about the space origin. */\nexport function scale<S extends Space>(sx: number, sy: number): Mat2D<S, S> {\n return [sx, 0, 0, sy, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about the space origin (radians; clockwise in y-down content space). */\nexport function rotate<S extends Space>(rad: number): Mat2D<S, S> {\n const c = Math.cos(rad);\n const s = Math.sin(rad);\n return [c, s, -s, c, 0, 0] as Mat2D<S, S>;\n}\n\n/** Rotate about an arbitrary pivot: `T(c) · R(rad) · T(-c)`. */\nexport function rotateAbout<S extends Space>(c: PointIn<S>, rad: number): Mat2D<S, S> {\n return compose(translate<S>(c.x, c.y), compose(rotate<S>(rad), translate<S>(-c.x, -c.y)));\n}\n\n/** Scale about an arbitrary anchor: `T(a) · S(sx, sy) · T(-a)`. */\nexport function scaleAbout<S extends Space>(a: PointIn<S>, sx: number, sy: number): Mat2D<S, S> {\n return compose(translate<S>(a.x, a.y), compose(scale<S>(sx, sy), translate<S>(-a.x, -a.y)));\n}\n\n/** The rotation angle (radians) encoded in a matrix — `atan2(b, a)`. Positive is\n * clockwise in y-down content space (the inverse of {@link rotate}). */\nexport function angleOf(m: Mat2D): number {\n return Math.atan2(m[1], m[0]);\n}\n\n/**\n * The page's scale + integer quarter-turn as a `Mat2D`: a content point maps to\n * its place in the rotated DISPLAY box. `scale` is output units per content\n * point; `boxW`/`boxH` are the UN-rotated content's extents in those same output\n * units, and the offsets keep the footprint in the box's positive quadrant\n * (origin at the box top-left).\n *\n * THE single encoding of the quarter-turn — `pageTransform` (view px),\n * `pageGeometry` (the `content→view` hop), and `pageToWorld` (world units) all\n * build on this one function, so the rotation can never drift between them.\n */\nexport function rotateScaleMatrix(\n scale: number,\n boxW: number,\n boxH: number,\n rotation: PageRotation,\n): Mat2D {\n switch (rotation) {\n case 90:\n return [0, scale, -scale, 0, boxH, 0] as Mat2D;\n case 180:\n return [-scale, 0, 0, -scale, boxW, boxH] as Mat2D;\n case 270:\n return [0, -scale, scale, 0, 0, boxW] as Mat2D;\n default:\n return [scale, 0, 0, scale, 0, 0] as Mat2D;\n }\n}\n\n/**\n * The per-page geometry input. Structurally a subset of the engine's\n * `PageLayout` (so a layout can be passed straight in), but defined here to keep\n * this package dependency-free — the same reason {@link PageRotation} is a\n * structural twin of the engine's rotation.\n */\nexport interface PageGeometryInput {\n /** Effective crop box in PDF user space (y-up edges); origin preserved, so\n * `left`/`bottom` may be non-zero or negative. */\n crop: { left: number; bottom: number; right: number; top: number };\n /** Persistent page rotation (the document's `/Rotate`). */\n rotation: PageRotation;\n /** PDF `userUnit` (§14.11.6): scales PDF points into the layout. 1 for most docs. */\n userUnit: number;\n}\n\n/** The matrices bridging one page's spaces — every other matrix composes from these. */\nexport interface PageGeometry {\n /** PDF user space (y-up, crop-relative) → content space (y-down, crop top-left, unscaled points). */\n readonly pdfToContent: Mat2D<'pdf', 'content'>;\n /** Content → view: scale (zoom × userUnit) + the page's quarter-turn rotation. */\n readonly contentToView: Mat2D<'content', 'view'>;\n /** PDF → view, precomposed. */\n readonly pdfToView: Mat2D<'pdf', 'view'>;\n /** View → PDF, the inverse — hit-testing for free. */\n readonly viewToPdf: Mat2D<'view', 'pdf'>;\n}\n\n/**\n * PDF user space (y-up, origin = crop bottom-left) → content space (y-down,\n * origin = crop top-left, unscaled points). THE single encoding of the engine→\n * content y-flip + crop offset: `pageGeometry` composes its `pdfToContent` from\n * this, and pure annotation geometry (content-space editing) reuses it too, so\n * the rule can never be hand-written twice and drift.\n */\nexport function pdfToContentMatrix(crop: { left: number; top: number }): Mat2D<'pdf', 'content'> {\n return [1, 0, 0, -1, -crop.left, crop.top] as Mat2D<'pdf', 'content'>;\n}\n\n/**\n * Build a page's space matrices from its crop box, rotation, and `userUnit` plus\n * the viewer `zoom`. This is the ONE function that knows the y-flip, crop origin,\n * `userUnit`, and rotation; everything else composes from its output. The engine\n * never emits these — they bake in viewer state (zoom, later scroll/dpr) — so the\n * boundary stays clean: engine owns `Pdf*` truth, the viewer composes the rest.\n */\nexport function pageGeometry(input: PageGeometryInput, zoom: number): PageGeometry {\n const { crop, rotation, userUnit } = input;\n const s = zoom * userUnit; // view px per PDF point — userUnit folded in HERE, once\n\n // PDF user space (y-up, origin = crop bottom-left) → content (y-down, origin = crop top-left).\n const pdfToContent = pdfToContentMatrix(crop);\n\n // Content → view: scale + integer quarter-turn, from the shared builder (the\n // one quarter-turn encoding). `Wc`/`Hc` are the unrotated content's view-px\n // extents (the builder places the footprint in the box's positive quadrant).\n const Wc = (crop.right - crop.left) * s;\n const Hc = (crop.top - crop.bottom) * s;\n const contentToView = rotateScaleMatrix(s, Wc, Hc, rotation) as Mat2D<'content', 'view'>;\n\n const pdfToView = compose(contentToView, pdfToContent);\n return { pdfToContent, contentToView, pdfToView, viewToPdf: invert(pdfToView) };\n}\n\n/* ── TextQuad — corner-named quads for text-anchored geometry ──────────────\n *\n * {@link Quad} is deliberately positional (no corner guarantee) because\n * imported PDF quads have chaotic corner orders. TextQuad is the SEMANTIC\n * counterpart for quads whose orientation is KNOWN — produced only by code\n * that established it (selection segments, glyph cells, or `normalizeQuad`\n * at an ingest boundary), never by casting.\n *\n * Corner names are FRAME-GEOMETRIC in the text's own upright frame:\n * `upper` is the ascent side, `lower` the baseline side, and `start` → `end`\n * runs along the frame's +x. VISUAL semantics — deliberately NOT reading\n * order: bidi/advance direction is a glyph-sequence concern carried\n * separately where consumers need it. In y-down content space an upright\n * TextQuad has `upper*` at the smaller y.\n */\n\nexport interface TextQuad {\n upperStart: Point;\n upperEnd: Point;\n lowerStart: Point;\n lowerEnd: Point;\n}\n\n/** A TextQuad tagged with its coordinate space. */\nexport type TextQuadIn<S extends Space> = TextQuad & SpaceBrand<S>;\n\n/** Axis-aligned TextQuad over a rect (y-down: upper = smaller y). */\nexport function textQuadFromRect(r: Rect): TextQuad {\n return {\n upperStart: { x: r.x, y: r.y },\n upperEnd: { x: r.x + r.width, y: r.y },\n lowerStart: { x: r.x, y: r.y + r.height },\n lowerEnd: { x: r.x + r.width, y: r.y + r.height },\n };\n}\n\n/** The four corners in slot order: upper-start, upper-end, lower-start, lower-end. */\nexport function textQuadPoints(t: TextQuad): [Point, Point, Point, Point] {\n return [t.upperStart, t.upperEnd, t.lowerStart, t.lowerEnd];\n}\n\n/** The corners as a polygon RING (US → UE → LE → LS) — for `<polygon>`/fills. */\nexport function textQuadRing(t: TextQuad): [Point, Point, Point, Point] {\n return [t.upperStart, t.upperEnd, t.lowerEnd, t.lowerStart];\n}\n\n/** Axis-aligned bounds of a TextQuad. */\nexport function textQuadBounds(t: TextQuad): Rect {\n const xs = [t.upperStart.x, t.upperEnd.x, t.lowerStart.x, t.lowerEnd.x];\n const ys = [t.upperStart.y, t.upperEnd.y, t.lowerStart.y, t.lowerEnd.y];\n const minX = Math.min(...xs);\n const minY = Math.min(...ys);\n return { x: minX, y: minY, width: Math.max(...xs) - minX, height: Math.max(...ys) - minY };\n}\n\n/** Map a TextQuad through an affine transform (corner semantics ride along). */\nexport function applyTextQuad<F extends Space, T extends Space>(\n m: Mat2D<F, T>,\n t: TextQuadIn<F>,\n): TextQuadIn<T> {\n return {\n upperStart: applyPoint(m, t.upperStart as PointIn<F>),\n upperEnd: applyPoint(m, t.upperEnd as PointIn<F>),\n lowerStart: applyPoint(m, t.lowerStart as PointIn<F>),\n lowerEnd: applyPoint(m, t.lowerEnd as PointIn<F>),\n } as TextQuadIn<T>;\n}\n\n/** Serialize to the positional zigzag convention (`p1..p4` = US, UE, LS, LE). */\nexport function positionalQuad(t: TextQuad): Quad {\n return { p1: t.upperStart, p2: t.upperEnd, p3: t.lowerStart, p4: t.lowerEnd };\n}\n\nconst QUAD_EPSILON = 1e-6;\n\ntype QuadCornerList = [Point, Point, Point, Point];\n\nfunction finitePoint(p: Point): boolean {\n return Number.isFinite(p.x) && Number.isFinite(p.y);\n}\n\n/** Is `[us, ue, ls, le]` a well-formed zigzag reading of a quad? */\nfunction zigzagWellFormed([us, ue, ls, le]: QuadCornerList): boolean {\n if (![us, ue, ls, le].every(finitePoint)) return false;\n const upper = { x: ue.x - us.x, y: ue.y - us.y };\n const lower = { x: le.x - ls.x, y: le.y - ls.y };\n const startSide = { x: ls.x - us.x, y: ls.y - us.y };\n const endSide = { x: le.x - ue.x, y: le.y - ue.y };\n const lenU = Math.hypot(upper.x, upper.y);\n const lenL = Math.hypot(lower.x, lower.y);\n const lenS = Math.hypot(startSide.x, startSide.y);\n const lenE = Math.hypot(endSide.x, endSide.y);\n if (lenU <= QUAD_EPSILON || lenL <= QUAD_EPSILON || lenS <= QUAD_EPSILON || lenE <= QUAD_EPSILON)\n return false;\n // Opposite edges roughly parallel, same direction (rejects crossed/reversed).\n if (upper.x * lower.x + upper.y * lower.y <= 0) return false;\n if (startSide.x * endSide.x + startSide.y * endSide.y <= 0) return false;\n // Usable area, consistent winding on both ends.\n const startArea = upper.x * startSide.y - upper.y * startSide.x;\n const endArea = lower.x * endSide.y - lower.y * endSide.x;\n if (Math.abs(startArea) <= QUAD_EPSILON * lenU * lenS) return false;\n if (Math.abs(endArea) <= QUAD_EPSILON * lenL * lenE) return false;\n return Math.sign(startArea) === Math.sign(endArea);\n}\n\n/**\n * Interpret an arbitrary positional quad (an imported `/QuadPoints` entry,\n * already in content space) as a TextQuad — a NORMALIZER, not a cast:\n *\n * 1. the de-facto zigzag order (US, UE, LS, LE) passes through untouched —\n * this covers every well-formed writer, rotated quads included;\n * 2. the common ring order (US, UE, LE, LS) is recognized and repaired;\n * 3. anything else gets a deterministic geometric labeling: corners sorted\n * into a ring around their centroid, \"upper\" = the edge whose midpoint\n * sits highest on screen (smallest y). The 180° \"which side is up\"\n * ambiguity is unresolvable from geometry alone — convention decides.\n *\n * Drawing code downstream (`markupScene`) reads corner SEMANTICS, so a\n * mislabeled import can shift an underline to the wrong edge but can never\n * crash or self-intersect.\n */\nexport function normalizeQuad(q: Quad): TextQuad {\n const zigzag: QuadCornerList = [q.p1, q.p2, q.p3, q.p4];\n if (zigzagWellFormed(zigzag)) {\n return { upperStart: q.p1, upperEnd: q.p2, lowerStart: q.p3, lowerEnd: q.p4 };\n }\n const ring: QuadCornerList = [q.p1, q.p2, q.p4, q.p3];\n if (zigzagWellFormed(ring)) {\n return { upperStart: q.p1, upperEnd: q.p2, lowerStart: q.p4, lowerEnd: q.p3 };\n }\n\n // Deterministic fallback for degenerate/garbage producers.\n const pts = [q.p1, q.p2, q.p3, q.p4].map((p) => (finitePoint(p) ? p : { x: 0, y: 0 }));\n const cx = (pts[0].x + pts[1].x + pts[2].x + pts[3].x) / 4;\n const cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4;\n const ringSorted = [...pts].sort(\n (a, b) => Math.atan2(a.y - cy, a.x - cx) - Math.atan2(b.y - cy, b.x - cx),\n );\n // Pick the ring edge whose midpoint sits highest on screen as the upper edge.\n let upperEdge = 0;\n let bestY = Infinity;\n for (let i = 0; i < 4; i++) {\n const midY = (ringSorted[i].y + ringSorted[(i + 1) % 4].y) / 2;\n if (midY < bestY) {\n bestY = midY;\n upperEdge = i;\n }\n }\n const a = ringSorted[upperEdge];\n const b = ringSorted[(upperEdge + 1) % 4];\n const c = ringSorted[(upperEdge + 2) % 4];\n const d = ringSorted[(upperEdge + 3) % 4];\n // Ring [a, b, c, d] with upper edge a→b ⇒ the opposite edge runs d→c.\n const startFirst = a.x <= b.x;\n return startFirst\n ? { upperStart: a, upperEnd: b, lowerStart: d, lowerEnd: c }\n : { upperStart: b, upperEnd: a, lowerStart: c, lowerEnd: d };\n}\n"],"mappings":";;;;;;AAkCA,SAAgB,cAAc,OAAqC;CACjE,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,MAAM,KAAK,OAAO;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,CAAC;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,CAAC;EACrB,KAAK,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,KAAK;EAC/B,KAAK,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM;CAClC;CACA,OAAO;EAAE,GAAG;EAAI,GAAG;EAAI,OAAO,KAAK;EAAI,QAAQ,KAAK;CAAG;AACzD;;;;;;;AAQA,SAAgB,eAAe,GAAS,GAAe;CACrD,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;CAC3B,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;CAC3B,OAAO;EACL;EACA;EACA,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;EAC7D,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;CAClE;AACF;AAuBA,MAAa,WAAsB;CAAE,KAAK;CAAG,OAAO;CAAG,QAAQ;CAAG,MAAM;AAAE;;AAG1E,SAAgB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,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,KAAK;CACzD,MAAM,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,MACzB,GAAG,MAAM,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,IAAI,EAAE,CAC1E;CAEA,IAAI,YAAY;CAChB,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EAC1B,MAAM,QAAQ,WAAW,EAAE,CAAC,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC,KAAK;EAC7D,IAAI,OAAO,OAAO;GAChB,QAAQ;GACR,YAAY;EACd;CACF;CACA,MAAM,IAAI,WAAW;CACrB,MAAM,IAAI,YAAY,YAAY,KAAK;CACvC,MAAM,IAAI,YAAY,YAAY,KAAK;CACvC,MAAM,IAAI,YAAY,YAAY,KAAK;CAGvC,OADmB,EAAE,KAAK,EAAE,IAExB;EAAE,YAAY;EAAG,UAAU;EAAG,YAAY;EAAG,UAAU;CAAE,IACzD;EAAE,YAAY;EAAG,UAAU;EAAG,YAAY;EAAG,UAAU;CAAE;AAC/D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/core-geometry",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The viewer's pure 2D coordinate primitives: Point/Size, page rotation, and the rotation/scale transforms shared by stage-core, the stage plugin, and every framework adapter. Zero dependencies, DOM-free, serializable — the bottom of the pyramid.",
|
|
6
6
|
"type": "module",
|