@embedpdf/plugin-annotation 3.0.0-next.15 → 3.0.0-next.16

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { widgetAppearanceOf } from "./authoring.cjs";
2
2
  import { $ as Color, A as AnnotationResources, At as annotationState, B as AnnotationTool, Bt as ResolvedTool, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as DEFAULT_TOOLS, G as ArmedStampInfo, Gt as Face, H as AnnotationTransfer, Ht as StampSourceSpec, I as AnnotationSettings, It as GhostPolicy, J as AttachmentFileSource, K as ArmedStampPreview, Kt as TextFormat, L as AnnotationStampsApi, Lt as InkAuthoringOptions, M as AnnotationRotationAnchor, Mt as ARMED_STAMP_TOOL_ID, N as AnnotationSelectionAnchor, Nt as AnnotationToolDef, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolInput, Q as ClickCreate, R as AnnotationSubtype, Rt as PromptSourceSpec, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as ToolAuthoringKind, V as AnnotationToolsApi, Vt as SelectionAuthoring, W as AnnotationWriteFailedEvent, Wt as ToolDefaultsFor, X as BlendMode, Y as Behavior, Z as ChromeSettings, _ as AnnotationHoverChangedEvent, _t as MarkupSubtype, a as AnnotationBundle, at as EditableKind, b as AnnotationImportResult, bt as ReviewStatus, c as AnnotationCreatedEvent, ct as FilePickerProvider, d as AnnotationDraftApi, dt as HandleRole, et as CommentThread, f as AnnotationDraftChangedEvent, ft as ImageGhost, g as AnnotationFlags, gt as LinkNavItem, h as AnnotationFilter, ht as LineStyle, i as AnnotationAnchor, it as CreationDraft, j as AnnotationResyncedEvent, jt as AnnotationToken, k as AnnotationResourceRole, kt as ToolDefaultsChangedEvent, l as AnnotationDeletedEvent, lt as FilePromptRequest, m as AnnotationExportSelection, mt as LineEndings, n as AfterCreateSettings, nt as CommentThreadReview, o as AnnotationCapability, ot as EditableKinds, p as AnnotationEditingChangedEvent, pt as LineEnding, q as AttachmentContent, qt as TextSelection, r as Annotation, rt as CommentsApi, s as AnnotationConfig, st as FieldValues, t as ANNOTATION_DEFAULTS, tt as CommentThreadChangedEvent, u as AnnotationDraft, ut as FlagKey, v as AnnotationImportDrop, vt as MeasurementIntent, w as AnnotationPosition, wt as StampPreviewProvider, x as AnnotationLinksApi, xt as SnapSettings, y as AnnotationImportOptions, yt as PdfLinkTarget, z as AnnotationTextApi, zt as ResolvedGhost } from "./contract-BK4LHe9v.cjs";
3
- import { f as AnnotationState, n as AnnotationHostCapability } from "./host-contract-Nzxwh0XS.cjs";
3
+ import { f as AnnotationState, n as AnnotationHostCapability } from "./host-contract-BU29qDEw.cjs";
4
4
  import { MIN_DRAG, Placement, gesturePlacement, kindNamed, propertiesOf, resolveClickPlacement } from "@embedpdf/core-annotation";
5
5
  import { annotationKey } from "@embedpdf/core";
6
6
  //#region src/annotation.plugin.d.ts
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { widgetAppearanceOf } from "./authoring.js";
2
2
  import { $ as Color, A as AnnotationResources, At as annotationState, B as AnnotationTool, Bt as ResolvedTool, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as DEFAULT_TOOLS, G as ArmedStampInfo, Gt as Face, H as AnnotationTransfer, Ht as StampSourceSpec, I as AnnotationSettings, It as GhostPolicy, J as AttachmentFileSource, K as ArmedStampPreview, Kt as TextFormat, L as AnnotationStampsApi, Lt as InkAuthoringOptions, M as AnnotationRotationAnchor, Mt as ARMED_STAMP_TOOL_ID, N as AnnotationSelectionAnchor, Nt as AnnotationToolDef, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolInput, Q as ClickCreate, R as AnnotationSubtype, Rt as PromptSourceSpec, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as ToolAuthoringKind, V as AnnotationToolsApi, Vt as SelectionAuthoring, W as AnnotationWriteFailedEvent, Wt as ToolDefaultsFor, X as BlendMode, Y as Behavior, Z as ChromeSettings, _ as AnnotationHoverChangedEvent, _t as MarkupSubtype, a as AnnotationBundle, at as EditableKind, b as AnnotationImportResult, bt as ReviewStatus, c as AnnotationCreatedEvent, ct as FilePickerProvider, d as AnnotationDraftApi, dt as HandleRole, et as CommentThread, f as AnnotationDraftChangedEvent, ft as ImageGhost, g as AnnotationFlags, gt as LinkNavItem, h as AnnotationFilter, ht as LineStyle, i as AnnotationAnchor, it as CreationDraft, j as AnnotationResyncedEvent, jt as AnnotationToken, k as AnnotationResourceRole, kt as ToolDefaultsChangedEvent, l as AnnotationDeletedEvent, lt as FilePromptRequest, m as AnnotationExportSelection, mt as LineEndings, n as AfterCreateSettings, nt as CommentThreadReview, o as AnnotationCapability, ot as EditableKinds, p as AnnotationEditingChangedEvent, pt as LineEnding, q as AttachmentContent, qt as TextSelection, r as Annotation, rt as CommentsApi, s as AnnotationConfig, st as FieldValues, t as ANNOTATION_DEFAULTS, tt as CommentThreadChangedEvent, u as AnnotationDraft, ut as FlagKey, v as AnnotationImportDrop, vt as MeasurementIntent, w as AnnotationPosition, wt as StampPreviewProvider, x as AnnotationLinksApi, xt as SnapSettings, y as AnnotationImportOptions, yt as PdfLinkTarget, z as AnnotationTextApi, zt as ResolvedGhost } from "./contract-BOo9iZKo.js";
3
- import { f as AnnotationState, n as AnnotationHostCapability } from "./host-contract-BbjhS_Fo.js";
3
+ import { f as AnnotationState, n as AnnotationHostCapability } from "./host-contract-DfSvbt8c.js";
4
4
  import { annotationKey } from "@embedpdf/core";
5
5
  import { MIN_DRAG, Placement, gesturePlacement, kindNamed, propertiesOf, resolveClickPlacement } from "@embedpdf/core-annotation";
6
6
  //#region src/annotation.plugin.d.ts
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { InteractionToken } from "@embedpdf/plugin-interaction/contract/host";
7
7
  import { RenderToken } from "@embedpdf/plugin-render/contract";
8
8
  import { SelectionToken } from "@embedpdf/plugin-selection/contract/host";
9
9
  import { ANNOTATION_FIELD_NAMES, STANDARD_FACES, anchorOf, annotationKey as annotationKey$1, annotationPatchBetween, buildCommentThreads, colorOf, compareIsoDateTime, deletedWith, imageSourceOfBytes, isDimension, isLocalEngine, isReadout, measurementReadout, pageBoxOf, reorderPart, reorderedList, resolveAnnotationPatch, resolveBinarySource, serializeError, sniffBinaryMetadata, toPageRef, viewportForPoint } from "@embedpdf/engine-core/runtime";
10
- import { MIN_DRAG, STANDARD_FONT_STACKS, anchorModeOf, anchoredGeom, annotContentsEditable, annotDeletable, annotTransformable, annotationAfter, annotationAnchor, annotationOfNew, applyStyleToRange, canMove, chrome, creationDraftAnchor, cssFontFamilyForFont, cursorAt, defaultsFor, drawnAfter, expandGroups, faceForFont, fitStampBox, fromDTO, gesturePlacement, gesturePlacement as gesturePlacement$1, groupKeyOf, groupOf, hitTest, initialSession, initialTextStyle, isContentsEditableByHand, isDrag, isEditableByHand, isOnTextBox, isSelectable, isSubstrateOnly, isTransformableByHand, kindNamed, kindNamed as kindNamed$1, kindOf, linkChildRects, linkChildrenOf, linkOf, locateOffset, mountedFontFamily, newRecordsAtMost, pageItems, placedShape, propertiesOf, propertiesOf as propertiesOf$1, readOfDefaults, refOf, resolveClickPlacement, resolveClickPlacement as resolveClickPlacement$1, richDocOf, rotationAnchor, sameSession, selectionAnchor, selectionInBox, shapeOf, sharedProperties, sourceOfConfirmed, sourceOfNew, styleOf, textBoxes, textOf, textPlateInset, toolAnnotation, unanchoredGeom, unmadeItem, update, uprightRotation, viewable, writableTarget } from "@embedpdf/core-annotation";
10
+ import { MIN_DRAG, STANDARD_FONT_STACKS, anchorModeOf, anchoredGeom, annotContentsEditable, annotDeletable, annotTransformable, annotationAfter, annotationAnchor, annotationOfNew, applyStyleToRange, canMove, chrome, creationDraftAnchor, cssFontFamilyForFont, cursorAt, defaultsFor, drawnAfter, expandGroups, faceForFont, fitStampBox, fromDTO, gesturePlacement, gesturePlacement as gesturePlacement$1, groupKeyOf, groupOf, hitTest, initialSession, initialTextStyle, isContentsEditableByHand, isDrag, isEditableByHand, isOnTextBox, isSelectable, isSubstrateOnly, isTransformableByHand, kindNamed, kindNamed as kindNamed$1, kindOf, linkChildRects, linkChildrenOf, linkOf, locateOffset, mountedFontFamily, newRecordsAtMost, pageItems, placedShape, propertiesOf, propertiesOf as propertiesOf$1, readOfDefaults, refOf, resolveClickPlacement, resolveClickPlacement as resolveClickPlacement$1, richDocOf, rotationAnchor, sameSession, selectionAnchor, selectionInBox, shapeOf, sharedProperties, sourceOfConfirmed, sourceOfNew, styleOf, textBoxOf, textBoxes, textOf, textPlateInset, toolAnnotation, unanchoredGeom, unmadeItem, update, uprightRotation, viewable, writableTarget } from "@embedpdf/core-annotation";
11
11
  import { ActionsToken as ActionsToken$1 } from "@embedpdf/plugin-actions/contract/host";
12
12
  import { RenderToken as RenderToken$1 } from "@embedpdf/plugin-render/contract/host";
13
13
  import { InteractionToken as InteractionToken$1 } from "@embedpdf/plugin-interaction/contract";
@@ -1451,31 +1451,39 @@ function createPropertyReads(ctx, { store, fonts }) {
1451
1451
  * core geometry (`textBoxes`) joined with the DTO-derived CSS. Pure; memoized by
1452
1452
  * model identity at the call site so selectors get a stable reference. */
1453
1453
  function buildTextItems(model, page, view) {
1454
- return textBoxes(model, page, view).map((tb) => {
1455
- const record = model.byId[tb.id];
1456
- const style = (record && textOf(record.annotation)) ?? initialTextStyle;
1457
- const sw = record ? styleOf(record.annotation).strokeWidth : 0;
1458
- const doc = record ? richDocOf(record.annotation) : null;
1459
- return {
1460
- id: tb.id,
1461
- ref: refOf(record),
1462
- box: tb.box,
1463
- contents: record?.annotation.contents ?? "",
1464
- richText: { paragraphs: doc ? stripBodyDefaults(doc.paragraphs, doc.body) : [{ runs: [{ text: "" }] }] },
1465
- editing: tb.editing,
1466
- ...tb.rot ? { rot: tb.rot } : {},
1467
- css: {
1468
- fontFamily: cssFontFamilyForFont(style.fontFamily),
1469
- fontSize: style.fontSize,
1470
- color: style.fontColor,
1471
- fontWeight: style.bold ? 700 : 400,
1472
- fontStyle: style.italic ? "italic" : "normal",
1473
- textDecoration: style.underline ? "underline" : "none",
1474
- align: style.textAlign,
1475
- padding: textPlateInset(sw)
1476
- }
1477
- };
1478
- });
1454
+ return textBoxes(model, page, view).map((tb) => textItemOf(model, tb));
1455
+ }
1456
+ /** One free text's {@link TextItem}, live or baked (`textBoxOf`): what a renderer
1457
+ * that draws the text box itself edits. `null` for a record that isn't one. */
1458
+ function buildTextItem(model, id, view) {
1459
+ const tb = textBoxOf(model, id, view);
1460
+ return tb && textItemOf(model, tb);
1461
+ }
1462
+ /** A text box joined with its record's text, style and plate inset. */
1463
+ function textItemOf(model, tb) {
1464
+ const record = model.byId[tb.id];
1465
+ const style = (record && textOf(record.annotation)) ?? initialTextStyle;
1466
+ const sw = record ? styleOf(record.annotation).strokeWidth : 0;
1467
+ const doc = record ? richDocOf(record.annotation) : null;
1468
+ return {
1469
+ id: tb.id,
1470
+ ref: refOf(record),
1471
+ box: tb.box,
1472
+ contents: record?.annotation.contents ?? "",
1473
+ richText: { paragraphs: doc ? stripBodyDefaults(doc.paragraphs, doc.body) : [{ runs: [{ text: "" }] }] },
1474
+ editing: tb.editing,
1475
+ ...tb.rot ? { rot: tb.rot } : {},
1476
+ css: {
1477
+ fontFamily: cssFontFamilyForFont(style.fontFamily),
1478
+ fontSize: style.fontSize,
1479
+ color: style.fontColor,
1480
+ fontWeight: style.bold ? 700 : 400,
1481
+ fontStyle: style.italic ? "italic" : "normal",
1482
+ textDecoration: style.underline ? "underline" : "none",
1483
+ align: style.textAlign,
1484
+ padding: textPlateInset(sw)
1485
+ }
1486
+ };
1479
1487
  }
1480
1488
  //#endregion
1481
1489
  //#region src/read/render.ts
@@ -1524,6 +1532,21 @@ function createRenderReads(ctx, { view: { pageModel }, lending }, ghost, stamps)
1524
1532
  });
1525
1533
  return items;
1526
1534
  };
1535
+ const textCache = /* @__PURE__ */ new Map();
1536
+ const textItemOf = (ref, view) => {
1537
+ const key = annotationKey$1(ref);
1538
+ const model = pageModel(ref.page.objectNumber);
1539
+ const cached = textCache.get(key);
1540
+ if (cached && cached.model === model && cached.zoom === view?.zoom && cached.rotation === view?.rotation) return cached.v;
1541
+ const item = buildTextItem(model, key, view);
1542
+ textCache.set(key, {
1543
+ model,
1544
+ zoom: view?.zoom,
1545
+ rotation: view?.rotation,
1546
+ v: item
1547
+ });
1548
+ return item;
1549
+ };
1527
1550
  const linkItemsCache = /* @__PURE__ */ new Map();
1528
1551
  const linkItemsOf = (pageObjectNumber) => {
1529
1552
  const model = pageModel(pageObjectNumber);
@@ -1564,6 +1587,7 @@ function createRenderReads(ctx, { view: { pageModel }, lending }, ghost, stamps)
1564
1587
  const api = {
1565
1588
  listPageItems: (page, view) => pageItemsOf(page, view),
1566
1589
  listTextItems: (page, view) => textItemsOf(page, view),
1590
+ getTextItem: (ref, view) => textItemOf(ref, view),
1567
1591
  listLinkItems: (page) => linkItemsOf(page.objectNumber),
1568
1592
  getAppearanceEpoch: (page) => {
1569
1593
  const { engine, placed, lent } = epochOf(page);
@@ -2265,6 +2289,33 @@ const keysOnPages = (records, pages) => {
2265
2289
  return records.order.filter((key) => wanted.has(records.byKey[key].dto.page.objectNumber));
2266
2290
  };
2267
2291
  /**
2292
+ * The other pages whose annotations go to `pages`: a target or an action
2293
+ * that names one, or one that couldn't be read (the page it goes to wasn't
2294
+ * there). A link is read against the pages there are, so when pages go, come
2295
+ * or come back, these read differently.
2296
+ */
2297
+ function pagesGoingTo(records, pages) {
2298
+ const named = new Set(pages.map((page) => page.objectNumber));
2299
+ const found = /* @__PURE__ */ new Map();
2300
+ for (const key of records.order) {
2301
+ const { dto } = records.byKey[key];
2302
+ const { target, actions } = dto;
2303
+ if (named.has(dto.page.objectNumber) || found.has(dto.page.objectNumber)) continue;
2304
+ if (goesTo(target, named) || goesTo(actions, named)) found.set(dto.page.objectNumber, dto.page);
2305
+ }
2306
+ return [...found.values()];
2307
+ }
2308
+ /** Whether a target or an action tree names one of `pages`, or holds what couldn't be read. */
2309
+ function goesTo(value, pages) {
2310
+ if (!value || typeof value !== "object") return false;
2311
+ if (Array.isArray(value)) return value.some((entry) => goesTo(entry, pages));
2312
+ const node = value;
2313
+ if (node["kind"] === "unsupported") return true;
2314
+ const page = node["page"]?.objectNumber;
2315
+ if (typeof page === "number" && pages.has(page)) return true;
2316
+ return Object.values(node).some((entry) => goesTo(entry, pages));
2317
+ }
2318
+ /**
2268
2319
  * A fresh read of the whole document. Every record's appearance version moves
2269
2320
  * past the one it had, so a reload after a desync re-fetches every raster
2270
2321
  * (the appearances may have changed while the event stream was not trusted).
@@ -2305,8 +2356,12 @@ function foldRecords(records, event) {
2305
2356
  }
2306
2357
  case "annotations.deleted": return drop(records, event.deleted.map(annotationKey$1));
2307
2358
  case "annotations.restored": return reload({ pages: [event.page] });
2308
- case "pages.deleted": return drop(records, keysOnPages(records, event.pages));
2309
- case "pages.inserted": return event.insertedPages.length ? reload({ pages: event.insertedPages }) : records;
2359
+ case "pages.deleted": {
2360
+ const going = pagesGoingTo(records, event.pages);
2361
+ return going.length ? reload({ pages: [...event.pages, ...going] }) : drop(records, keysOnPages(records, event.pages));
2362
+ }
2363
+ case "pages.inserted": return event.insertedPages.length ? reload({ pages: [...event.insertedPages, ...pagesGoingTo(records, event.insertedPages)] }) : records;
2364
+ case "pages.restored": return reload({ pages: [...event.pages, ...pagesGoingTo(records, event.pages)] });
2310
2365
  case "redaction.applied":
2311
2366
  case "pages.flattened": {
2312
2367
  const pages = event.results.filter((result) => result.status === "applied").map((result) => result.page);
@@ -2501,7 +2556,9 @@ function createRecordsMirror(ctx, events) {
2501
2556
  fold: foldRecords,
2502
2557
  predict: predictRecords,
2503
2558
  loadPages: async (doc, pages) => {
2504
- const { annotations } = await doc.annotations.list({ pages });
2559
+ const present = new Set(ctx.document()?.pages.map((page) => page.ref.objectNumber));
2560
+ const reading = pages.filter((page) => present.has(page.objectNumber));
2561
+ const { annotations } = reading.length ? await doc.annotations.list({ pages: reading }) : { annotations: [] };
2505
2562
  return (current) => withPages(current, pages, annotations);
2506
2563
  },
2507
2564
  changed: (change) => events.recordsChanged.emit(change)