@embedpdf/plugin-annotation 3.0.0-next.2 → 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.
@@ -2,6 +2,7 @@ let _embedpdf_core = require("@embedpdf/core");
2
2
  let _embedpdf_plugin_interaction = require("@embedpdf/plugin-interaction");
3
3
  let _embedpdf_engine_core_runtime = require("@embedpdf/engine-core/runtime");
4
4
  let _embedpdf_core_annotation = require("@embedpdf/core-annotation");
5
+ let _embedpdf_core_geometry = require("@embedpdf/core-geometry");
5
6
  //#region src/types.ts
6
7
  /**
7
8
  * The annotation capability token. Typed to the full {@link AnnotationHostCapability}
@@ -522,20 +523,29 @@ const freeText = {
522
523
  };
523
524
  //#endregion
524
525
  //#region src/repository/kinds/quads.ts
525
- const quadsFromDTO = (quadPoints, crop) => quadPoints.map((q) => [
526
- (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p1, crop),
527
- (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p2, crop),
528
- (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p3, crop),
529
- (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p4, crop)
530
- ]);
531
- /** Content quads → engine `/QuadPoints` (PDF user space); null off quads geom. */
526
+ /**
527
+ * Imported `/QuadPoints` → semantic TextQuads. `normalizeQuad` is a
528
+ * NORMALIZER, not a cast: the de-facto zigzag order passes through, ring-order
529
+ * producers are repaired, and garbage gets a deterministic labeling — so
530
+ * drawing code can never put an underline on the wrong edge of a well-formed
531
+ * quad, rotated ones included.
532
+ */
533
+ const quadsFromDTO = (quadPoints, crop) => quadPoints.map((q) => (0, _embedpdf_core_geometry.normalizeQuad)({
534
+ p1: (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p1, crop),
535
+ p2: (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p2, crop),
536
+ p3: (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p3, crop),
537
+ p4: (0, _embedpdf_core_annotation.pdfToContentPoint)(q.p4, crop)
538
+ }));
539
+ /** Content quads → engine `/QuadPoints` (PDF user space, zigzag slot order:
540
+ * p1..p4 = upper-start, upper-end, lower-start, lower-end — under the y-flip
541
+ * exactly PDFium's documented TL, TR, BL, BR); null off quads geom. */
532
542
  function quadPointsFor(a, crop) {
533
543
  if (a.geom.t !== "quads") return null;
534
544
  return a.geom.quads.map((q) => ({
535
- p1: (0, _embedpdf_core_annotation.contentToPdfPoint)(q[0], crop),
536
- p2: (0, _embedpdf_core_annotation.contentToPdfPoint)(q[1], crop),
537
- p3: (0, _embedpdf_core_annotation.contentToPdfPoint)(q[2], crop),
538
- p4: (0, _embedpdf_core_annotation.contentToPdfPoint)(q[3], crop)
545
+ p1: (0, _embedpdf_core_annotation.contentToPdfPoint)(q.upperStart, crop),
546
+ p2: (0, _embedpdf_core_annotation.contentToPdfPoint)(q.upperEnd, crop),
547
+ p3: (0, _embedpdf_core_annotation.contentToPdfPoint)(q.lowerStart, crop),
548
+ p4: (0, _embedpdf_core_annotation.contentToPdfPoint)(q.lowerEnd, crop)
539
549
  }));
540
550
  }
541
551
  /** PDF-space bounding box of a set of `/QuadPoints` quads — the `/Rect` a
@@ -593,15 +603,17 @@ const strikeout = markupProjection("strikeout");
593
603
  const caret = {
594
604
  ingest: (dto, crop) => {
595
605
  const d = dto;
606
+ const rot = d.rotation ? fromPdfRotation(d.rotation) : 0;
596
607
  return {
597
608
  geom: {
598
609
  t: "caret",
599
- rect: (0, _embedpdf_core_annotation.pdfToContentRect)(d.rect, crop)
610
+ rect: (0, _embedpdf_core_annotation.pdfToContentRect)(rot && d.unrotatedRect ? d.unrotatedRect : d.rect, crop),
611
+ ...rot ? { rot } : {}
600
612
  },
601
613
  ...d.intent ? { intent: d.intent } : {}
602
614
  };
603
615
  },
604
- geometry: (a, crop) => a.geom.t === "caret" ? { rect: (0, _embedpdf_core_annotation.contentToPdfRect)(a.geom.rect, crop) } : null,
616
+ geometry: (a, crop) => a.geom.t === "caret" ? boxGeomFields(a.geom.rect, a.geom.rot ?? 0, crop) : null,
605
617
  draftExtras: (a) => ({
606
618
  rectDifferences: {
607
619
  left: .5,
@@ -780,8 +792,6 @@ function foldAttachedLinks(annots) {
780
792
  if (!folded.size) return annots;
781
793
  return annots.filter((a) => !folded.has(a.id)).map((a) => patched.get(a.id) ?? a);
782
794
  }
783
- /** Bounds of one quad (content space). */
784
- const quadBounds = (q) => (0, _embedpdf_core_annotation.unionRect)(q);
785
795
  /**
786
796
  * The DESIRED hit rects (content space) of a parent's attached link
787
797
  * children — derived fresh from the parent's committed geometry, never
@@ -797,7 +807,7 @@ const quadBounds = (q) => (0, _embedpdf_core_annotation.unionRect)(q);
797
807
  * `/QuadPoints` (tier 2).
798
808
  */
799
809
  function linkChildRects(a) {
800
- if (a.geom.t === "quads") return a.geom.quads.map(quadBounds);
810
+ if (a.geom.t === "quads") return a.geom.quads.map(_embedpdf_core_geometry.textQuadBounds);
801
811
  return [(0, _embedpdf_core_annotation.unionRect)((0, _embedpdf_core_annotation.selectionQuad)(a.geom, a.style.strokeWidth, a.style.border))];
802
812
  }
803
813
  //#endregion
@@ -2477,30 +2487,30 @@ function createAnnotationCapability(ctx, config = {}) {
2477
2487
  finishCreationDraft: () => apply({ t: "finishCreationDraft" }),
2478
2488
  finishInkDraft: () => apply({ t: "finishInkDraft" }),
2479
2489
  cancelCreationDraft: () => apply({ t: "cancel" }),
2480
- createMarkup: (subtype, pon, rects, preset) => apply({
2490
+ createMarkup: (subtype, pon, quads, preset) => apply({
2481
2491
  t: "createMarkup",
2482
2492
  subtype,
2483
2493
  pon,
2484
- rects,
2494
+ quads,
2485
2495
  preset,
2486
2496
  flags: preset ? registry.get(preset)?.flags : void 0
2487
2497
  }),
2488
- createCaret: (pon, textEndRect) => apply({
2498
+ createCaret: (pon, anchor) => apply({
2489
2499
  t: "createCaret",
2490
2500
  pon,
2491
- rect: textEndRect
2501
+ anchor
2492
2502
  }),
2493
- createReplaceText: (pon, rects, textEndRect, preset) => apply({
2503
+ createReplaceText: (pon, quads, anchor, preset) => apply({
2494
2504
  t: "createReplaceText",
2495
2505
  pon,
2496
- rects,
2497
- endRect: textEndRect,
2506
+ quads,
2507
+ anchor,
2498
2508
  preset
2499
2509
  }),
2500
- previewMarkup: (subtype, rectsByPage, preset) => apply({
2510
+ previewMarkup: (subtype, quadsByPage, preset) => apply({
2501
2511
  t: "setMarkupPreview",
2502
2512
  subtype,
2503
- rectsByPage,
2513
+ quadsByPage,
2504
2514
  preset
2505
2515
  }),
2506
2516
  clearMarkupPreview: () => apply({ t: "clearMarkupPreview" }),
@@ -2736,4 +2746,4 @@ Object.defineProperty(exports, "widgetAppearanceFromProps", {
2736
2746
  }
2737
2747
  });
2738
2748
 
2739
- //# sourceMappingURL=capability-hb2AU0f6.cjs.map
2749
+ //# sourceMappingURL=capability-CYbikyob.cjs.map