@embedpdf/plugin-annotation 3.0.0-next.3 → 3.0.0-next.5

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