@embedpdf/plugin-annotation 3.0.0-next.19 → 3.0.0-next.20

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
- import { $ as Color, A as AnnotationResources, At as AnnotationState, B as AnnotationTool, Bt as ResolvedGhost, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as AnnotationToolInput, G as ArmedStampInfo, Gt as ToolDefaultsFor, H as AnnotationTransfer, Ht as SelectionAuthoring, I as AnnotationSettings, It as DEFAULT_TOOLS, J as AttachmentFileSource, Jt as TextSelection, K as ArmedStampPreview, Kt as Face, L as AnnotationStampsApi, Lt as GhostPolicy, M as AnnotationRotationAnchor, Mt as AnnotationToken, N as AnnotationSelectionAnchor, Nt as ARMED_STAMP_TOOL_ID, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolDef, Q as ClickCreate, R as AnnotationSubtype, Rt as InkAuthoringOptions, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as StampSourceSpec, V as AnnotationToolsApi, Vt as ResolvedTool, W as AnnotationWriteFailedEvent, Wt as ToolAuthoringKind, 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 annotationState, 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 TextFormat, 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 PromptSourceSpec } from "./contract-CX4PcAoR.cjs";
3
- import { f as AnnotationModel, n as AnnotationHostCapability } from "./host-contract-lQ1quQNY.cjs";
2
+ import { $ as Color, A as AnnotationResources, At as AnnotationState, B as AnnotationTool, Bt as ResolvedGhost, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as AnnotationToolInput, G as ArmedStampInfo, Gt as ToolDefaultsFor, H as AnnotationTransfer, Ht as SelectionAuthoring, I as AnnotationSettings, It as DEFAULT_TOOLS, J as AttachmentFileSource, Jt as TextSelection, K as ArmedStampPreview, Kt as Face, L as AnnotationStampsApi, Lt as GhostPolicy, M as AnnotationRotationAnchor, Mt as AnnotationToken, N as AnnotationSelectionAnchor, Nt as ARMED_STAMP_TOOL_ID, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolDef, Q as ClickCreate, R as AnnotationSubtype, Rt as InkAuthoringOptions, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as StampSourceSpec, V as AnnotationToolsApi, Vt as ResolvedTool, W as AnnotationWriteFailedEvent, Wt as ToolAuthoringKind, 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 annotationState, 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 TextFormat, 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 PromptSourceSpec } from "./contract-Cm0cfAzG.cjs";
3
+ import { f as AnnotationModel, n as AnnotationHostCapability } from "./host-contract-BDwyBNrs.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
@@ -9,7 +9,8 @@ import { annotationKey } from "@embedpdf/core";
9
9
  * optionally uses the selection plugin: shapes and ink work without it, text
10
10
  * markup lights up only when it is present. The engine's pictures of its
11
11
  * annotations come through the render plugin; without it, what draws live
12
- * still draws. `config` is the settings the app
12
+ * still draws. With the fonts plugin, text being typed shows in the font
13
+ * programs the engine writes with. `config` is the settings the app
13
14
  * registers, over {@link ANNOTATION_DEFAULTS}.
14
15
  */
15
16
  declare const annotationPlugin: (config?: AnnotationConfig) => import("@embedpdf/core").PluginDef<AnnotationModel, AnnotationHostCapability, AnnotationSettings>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { widgetAppearanceOf } from "./authoring.js";
2
- import { $ as Color, A as AnnotationResources, At as AnnotationState, B as AnnotationTool, Bt as ResolvedGhost, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as AnnotationToolInput, G as ArmedStampInfo, Gt as ToolDefaultsFor, H as AnnotationTransfer, Ht as SelectionAuthoring, I as AnnotationSettings, It as DEFAULT_TOOLS, J as AttachmentFileSource, Jt as TextSelection, K as ArmedStampPreview, Kt as Face, L as AnnotationStampsApi, Lt as GhostPolicy, M as AnnotationRotationAnchor, Mt as AnnotationToken, N as AnnotationSelectionAnchor, Nt as ARMED_STAMP_TOOL_ID, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolDef, Q as ClickCreate, R as AnnotationSubtype, Rt as InkAuthoringOptions, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as StampSourceSpec, V as AnnotationToolsApi, Vt as ResolvedTool, W as AnnotationWriteFailedEvent, Wt as ToolAuthoringKind, 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 annotationState, 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 TextFormat, 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 PromptSourceSpec } from "./contract-D6a0ANBk.js";
3
- import { f as AnnotationModel, n as AnnotationHostCapability } from "./host-contract-PNwb5DEw.js";
2
+ import { $ as Color, A as AnnotationResources, At as AnnotationState, B as AnnotationTool, Bt as ResolvedGhost, C as AnnotationPatch, Ct as StampPlacement, D as AnnotationRef, Dt as ThreadDeleteResult, E as AnnotationProperty, Et as TextItem, F as AnnotationSelectionChangedEvent, Ft as AnnotationToolInput, G as ArmedStampInfo, Gt as ToolDefaultsFor, H as AnnotationTransfer, Ht as SelectionAuthoring, I as AnnotationSettings, It as DEFAULT_TOOLS, J as AttachmentFileSource, Jt as TextSelection, K as ArmedStampPreview, Kt as Face, L as AnnotationStampsApi, Lt as GhostPolicy, M as AnnotationRotationAnchor, Mt as AnnotationToken, N as AnnotationSelectionAnchor, Nt as ARMED_STAMP_TOOL_ID, O as AnnotationReorderedEvent, Ot as ToolDefaults, P as AnnotationSelectionApi, Pt as AnnotationToolDef, Q as ClickCreate, R as AnnotationSubtype, Rt as InkAuthoringOptions, S as AnnotationOption, St as StampInput, T as AnnotationProperties, Tt as TextAlign, U as AnnotationUpdatedEvent, Ut as StampSourceSpec, V as AnnotationToolsApi, Vt as ResolvedTool, W as AnnotationWriteFailedEvent, Wt as ToolAuthoringKind, 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 annotationState, 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 TextFormat, 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 PromptSourceSpec } from "./contract-QAvnfm2b.js";
3
+ import { f as AnnotationModel, n as AnnotationHostCapability } from "./host-contract-BUub1Un-.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
@@ -9,7 +9,8 @@ import { MIN_DRAG, Placement, gesturePlacement, kindNamed, propertiesOf, resolve
9
9
  * optionally uses the selection plugin: shapes and ink work without it, text
10
10
  * markup lights up only when it is present. The engine's pictures of its
11
11
  * annotations come through the render plugin; without it, what draws live
12
- * still draws. `config` is the settings the app
12
+ * still draws. With the fonts plugin, text being typed shows in the font
13
+ * programs the engine writes with. `config` is the settings the app
13
14
  * registers, over {@link ANNOTATION_DEFAULTS}.
14
15
  */
15
16
  declare const annotationPlugin: (config?: AnnotationConfig) => import("@embedpdf/core").PluginDef<AnnotationModel, AnnotationHostCapability, AnnotationSettings>;
package/dist/index.js CHANGED
@@ -3,13 +3,15 @@ import { n as previewBucket, t as AnnotationToken$1 } from "./host-contract-CxrQ
3
3
  import { widgetAppearanceOf } from "./authoring.js";
4
4
  import { PluginError, annotationKey, composeApi, definePlugin, memo, pageRefsEqual, reload, toPluginError, toPluginErrorInfo } from "@embedpdf/core";
5
5
  import { ActionsToken, createHoverPump } from "@embedpdf/plugin-actions/contract";
6
+ import { FontsToken } from "@embedpdf/plugin-fonts/contract";
6
7
  import { InteractionToken } from "@embedpdf/plugin-interaction/contract/host";
7
8
  import { RenderToken } from "@embedpdf/plugin-render/contract";
8
9
  import { SelectionToken } from "@embedpdf/plugin-selection/contract/host";
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, textBoxOf, textBoxes, textOf, textPlateInset, toolAnnotation, unanchoredGeom, unmadeItem, update, uprightRotation, viewable, writableTarget } from "@embedpdf/core-annotation";
10
+ import { ANNOTATION_FIELD_NAMES, STANDARD_FACES, anchorOf, annotationKey as annotationKey$1, annotationPatchBetween, buildCommentThreads, colorOf, compareIsoDateTime, deletedWith, faceForFontName, familyKey, fontNameForFace, imageSourceOfBytes, isDimension, isLocalEngine, isReadout, measurementReadout, pageBoxOf, reorderPart, reorderedList, resolveAnnotationPatch, resolveBinarySource, serializeError, sniffBinaryMetadata, toPageRef, viewportForPoint } from "@embedpdf/engine-core/runtime";
11
+ import { MIN_DRAG, anchorModeOf, anchoredGeom, annotContentsEditable, annotDeletable, annotTransformable, annotationAfter, annotationAnchor, annotationOfNew, applyStyleToRange, canMove, chrome, creationDraftAnchor, 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, 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
12
  import { ActionsToken as ActionsToken$1 } from "@embedpdf/plugin-actions/contract/host";
12
13
  import { RenderToken as RenderToken$1 } from "@embedpdf/plugin-render/contract/host";
14
+ import { standardFontCss, standardFontForFace, standardFontOf, standardFontOfProgramFamily } from "@embedpdf/core-fonts";
13
15
  import { InteractionToken as InteractionToken$1 } from "@embedpdf/plugin-interaction/contract";
14
16
  import { SelectionToken as SelectionToken$1 } from "@embedpdf/plugin-selection/contract";
15
17
  import { scriptColorToRgb } from "@embedpdf/core-acrojs";
@@ -1135,7 +1137,7 @@ function createChromeReads(ctx, { store, geometry, behaviors, settings }) {
1135
1137
  * • a flat props patch → the run delta it means for a text range (font,
1136
1138
  * size, colour, bold/italic/underline) and the keys left for the body
1137
1139
  * • what a range reads back for those keys (agree → the value, else mixed)
1138
- * • faces: the DTO font a face names, and a CSS family list for either
1140
+ * • faces: the DTO font a face names
1139
1141
  * • the commit rule: a document nothing overrides on a plain annotation
1140
1142
  * commits as `contents`; anything else as `richText`
1141
1143
  */
@@ -1148,65 +1150,29 @@ const RANGE_KEYS = [
1148
1150
  "italic",
1149
1151
  "underline"
1150
1152
  ];
1151
- /** Family names compare without case, spaces, hyphens, underscores and
1152
- * quotes — the engine's own rule. */
1153
- function familyKey(family) {
1154
- return family.toLowerCase().replace(/[\s\-_'"]/g, "");
1155
- }
1156
- const STANDARD_FAMILY_KEYS = {
1157
- helvetica: "Helvetica",
1158
- arial: "Helvetica",
1159
- arialmt: "Helvetica",
1160
- sansserif: "Helvetica",
1161
- times: "Times",
1162
- timesroman: "Times",
1163
- timesnewroman: "Times",
1164
- timesnewromanpsmt: "Times",
1165
- serif: "Times",
1166
- courier: "Courier",
1167
- couriernew: "Courier",
1168
- couriernewpsmt: "Courier",
1169
- monospace: "Courier",
1170
- symbol: "Symbol",
1171
- zapfdingbats: "ZapfDingbats",
1172
- dingbats: "ZapfDingbats"
1173
- };
1174
1153
  /** The DTO font for a face: the registered key whose identity matches (the
1175
1154
  * closest weight, italic first), else the standard kebab name, else the
1176
1155
  * family itself. The inverse of {@link faceForFont}. */
1177
1156
  function fontForFace(face, fonts) {
1178
- const wanted = familyKey(face.family);
1179
1157
  const weight = face.weight ?? 400;
1180
1158
  const italic = face.italic ?? false;
1181
- let best;
1182
- for (const handle of fonts?.() ?? []) {
1183
- if (familyKey(handle.familyName) !== wanted) continue;
1184
- const score = Math.abs(handle.weight - weight) + (handle.italic === italic ? 0 : 1e3);
1185
- if (!best || score < best.score) best = {
1186
- key: handle.key,
1187
- score
1188
- };
1189
- }
1190
- if (best) return best.key;
1191
- const standard = STANDARD_FAMILY_KEYS[wanted];
1192
- if (standard) {
1193
- const bold = weight >= 600;
1194
- for (const [name, spec] of Object.entries(STANDARD_FACES)) if (spec.family === standard && spec.weight >= 600 === bold && spec.italic === italic) return name;
1195
- for (const [name, spec] of Object.entries(STANDARD_FACES)) if (spec.family === standard) return name;
1196
- }
1197
- return face.family;
1198
- }
1199
- /** The CSS family list for a face family: a standard family's web stack, a
1200
- * registered family's mounted `@font-face` ({@link mountedFontFamily}), else
1201
- * the family itself with a generic fallback. A DTO font's list is
1202
- * `cssFontFamilyForFont`'s, in `@embedpdf/core-annotation`. */
1203
- function cssFontFamilyForFace(family, fonts) {
1204
- const standard = STANDARD_FAMILY_KEYS[familyKey(family)];
1205
- if (standard) return STANDARD_FONT_STACKS[standard];
1206
- const wanted = familyKey(family);
1207
- const registered = fonts?.().find((handle) => familyKey(handle.familyName) === wanted);
1208
- if (registered) return mountedFontFamily(registered.key);
1209
- return `"${family}", sans-serif`;
1159
+ return fontNameForFace({
1160
+ family: face.family,
1161
+ weight,
1162
+ italic
1163
+ }, (family) => {
1164
+ const wanted = familyKey(family);
1165
+ let best;
1166
+ for (const handle of fonts?.() ?? []) {
1167
+ if (familyKey(handle.familyName) !== wanted) continue;
1168
+ const score = Math.abs(handle.weight - weight) + (handle.italic === italic ? 0 : 1e3);
1169
+ if (!best || score < best.score) best = {
1170
+ key: handle.key,
1171
+ score
1172
+ };
1173
+ }
1174
+ return best?.key;
1175
+ });
1210
1176
  }
1211
1177
  const hex = (css) => css.trim().toUpperCase();
1212
1178
  /**
@@ -1445,36 +1411,49 @@ function createPropertyReads(ctx, { store, fonts }) {
1445
1411
  * The free-text presentation projection: the core's geometry-only `textBoxes`
1446
1412
  * joined with the DTO-derived font + CSS into render-ready {@link TextItem}s. This
1447
1413
  * is the text analogue of the core's `scene()` "paint" for shapes, shared across
1448
- * every web framework; the font's CSS family is the core's `cssFontFamilyForFont`.
1414
+ * every web framework. The fonts are the text fonts' (the programs the engine
1415
+ * draws with), else the standard font the engine falls back to.
1449
1416
  */
1450
1417
  /** Project the model's free-text boxes into render-ready {@link TextItem}s — the
1451
1418
  * core geometry (`textBoxes`) joined with the DTO-derived CSS. Pure; memoized by
1452
1419
  * model identity at the call site so selectors get a stable reference. */
1453
- function buildTextItems(model, page, view) {
1454
- return textBoxes(model, page, view).map((tb) => textItemOf(model, tb));
1420
+ function buildTextItems(model, page, view, fonts) {
1421
+ return textBoxes(model, page, view).map((tb) => textItemOf(model, tb, fonts));
1455
1422
  }
1456
1423
  /** One free text's {@link TextItem}, live or baked (`textBoxOf`): what a renderer
1457
1424
  * that draws the text box itself edits. `null` for a record that isn't one. */
1458
- function buildTextItem(model, id, view) {
1425
+ function buildTextItem(model, id, view, fonts) {
1459
1426
  const tb = textBoxOf(model, id, view);
1460
- return tb && textItemOf(model, tb);
1427
+ return tb && textItemOf(model, tb, fonts);
1461
1428
  }
1462
- /** A text box joined with its record's text, style and plate inset. */
1463
- function textItemOf(model, tb) {
1429
+ /** A text box joined with its record's text, style, faces and plate inset. */
1430
+ function textItemOf(model, tb, fonts) {
1464
1431
  const record = model.byId[tb.id];
1465
1432
  const style = (record && textOf(record.annotation)) ?? initialTextStyle;
1466
1433
  const sw = record ? styleOf(record.annotation).strokeWidth : 0;
1467
- const doc = record ? richDocOf(record.annotation) : null;
1434
+ const doc = record ? richDocOf(record.annotation, fonts?.lookup) : null;
1435
+ const face = doc ? {
1436
+ family: doc.body.family,
1437
+ weight: doc.body.weight,
1438
+ italic: doc.body.italic
1439
+ } : {
1440
+ family: "Helvetica",
1441
+ weight: 400,
1442
+ italic: false
1443
+ };
1444
+ const bodyCss = fonts?.text.bodyCss(tb.id, style, face) ?? standardFontCss(standardFontOf(style.fontFamily));
1468
1445
  return {
1469
1446
  id: tb.id,
1470
1447
  ref: refOf(record),
1471
1448
  box: tb.box,
1472
1449
  contents: record?.annotation.contents ?? "",
1473
1450
  richText: { paragraphs: doc ? stripBodyDefaults(doc.paragraphs, doc.body) : [{ runs: [{ text: "" }] }] },
1451
+ face,
1452
+ programs: fonts && doc ? programsOf(tb.id, doc, face, bodyCss.programs, fonts.text) : bodyCss.programs,
1474
1453
  editing: tb.editing,
1475
1454
  ...tb.rot ? { rot: tb.rot } : {},
1476
1455
  css: {
1477
- fontFamily: cssFontFamilyForFont(style.fontFamily),
1456
+ fontFamily: bodyCss.fontFamily,
1478
1457
  fontSize: style.fontSize,
1479
1458
  color: style.fontColor,
1480
1459
  fontWeight: style.bold ? 700 : 400,
@@ -1485,6 +1464,21 @@ function textItemOf(model, tb) {
1485
1464
  }
1486
1465
  };
1487
1466
  }
1467
+ /** The programs a box's text is drawn in: the body's, then those of each face a run names. */
1468
+ function programsOf(id, doc, body, bodyPrograms, text) {
1469
+ const programs = [...bodyPrograms];
1470
+ for (const paragraph of doc.paragraphs) for (const run of paragraph.runs) {
1471
+ const own = run.style;
1472
+ if (own?.family === void 0 && own?.weight === void 0 && own?.italic === void 0) continue;
1473
+ const css = text.faceCss(id, {
1474
+ family: own.family ?? body.family,
1475
+ weight: own.weight ?? body.weight,
1476
+ italic: own.italic ?? body.italic
1477
+ });
1478
+ for (const program of css.programs) if (!programs.some((known) => known.hash === program.hash)) programs.push(program);
1479
+ }
1480
+ return programs;
1481
+ }
1488
1482
  //#endregion
1489
1483
  //#region src/read/render.ts
1490
1484
  /**
@@ -1496,23 +1490,42 @@ function textItemOf(model, tb) {
1496
1490
  * engine's picture of it exists, and an annotation an undo brings back the
1497
1491
  * picture it had.
1498
1492
  */
1499
- function createRenderReads(ctx, { view: { pageModel }, lending }, ghost, stamps) {
1493
+ function createRenderReads(ctx, { view: { pageModel }, lending, fonts: fontLookup, textFonts }, ghost, stamps) {
1500
1494
  const itemsCache = /* @__PURE__ */ new Map();
1495
+ const fonts = () => ctx.tryGet(FontsToken);
1496
+ /**
1497
+ * A hovered redaction's label with the fonts its preview draws it in, as
1498
+ * the engine picks them for the label's font; without the fonts plugin, or
1499
+ * while it finds them, the label's standard font draws it.
1500
+ */
1501
+ const withLabelFonts = (item) => {
1502
+ if (!item.hovered || !item.label) return item;
1503
+ const labelFonts = fonts()?.getPaintFonts(item.text?.fontFamily ?? "helvetica", item.label.text);
1504
+ return labelFonts ? {
1505
+ ...item,
1506
+ label: {
1507
+ ...item.label,
1508
+ fonts: labelFonts
1509
+ }
1510
+ } : item;
1511
+ };
1501
1512
  const pageItemsOf = (page, view) => {
1502
1513
  const pageObjectNumber = page.objectNumber;
1503
1514
  const model = pageModel(pageObjectNumber);
1504
1515
  const state = ctx.state.get();
1505
1516
  const ghostAt = state.ghostAt?.page.objectNumber === pageObjectNumber ? state.ghostAt : null;
1506
1517
  const placing = state.placing?.page.objectNumber === pageObjectNumber ? state.placing : null;
1518
+ const fontsEpoch = fonts()?.getPaintFontsEpoch() ?? 0;
1507
1519
  const cached = itemsCache.get(pageObjectNumber);
1508
- if (cached && cached.model === model && cached.ghostAt === ghostAt && cached.placing === placing && cached.zoom === view?.zoom && cached.rotation === view?.rotation) return cached.v;
1509
- const items = [...pageItems(model, page, view), ...ghost.itemsOn(pageObjectNumber, model, view)];
1520
+ if (cached && cached.model === model && cached.ghostAt === ghostAt && cached.placing === placing && cached.zoom === view?.zoom && cached.rotation === view?.rotation && cached.fontsEpoch === fontsEpoch) return cached.v;
1521
+ const items = [...pageItems(model, page, view).map(withLabelFonts), ...ghost.itemsOn(pageObjectNumber, model, view)];
1510
1522
  itemsCache.set(pageObjectNumber, {
1511
1523
  model,
1512
1524
  ghostAt,
1513
1525
  placing,
1514
1526
  zoom: view?.zoom,
1515
1527
  rotation: view?.rotation,
1528
+ fontsEpoch,
1516
1529
  v: items
1517
1530
  });
1518
1531
  return items;
@@ -1521,13 +1534,18 @@ function createRenderReads(ctx, { view: { pageModel }, lending }, ghost, stamps)
1521
1534
  const textItemsOf = (page, view) => {
1522
1535
  const pageObjectNumber = page.objectNumber;
1523
1536
  const model = pageModel(pageObjectNumber);
1537
+ const fonts = textFonts.version();
1524
1538
  const cached = textsCache.get(pageObjectNumber);
1525
- if (cached && cached.model === model && cached.zoom === view?.zoom && cached.rotation === view?.rotation) return cached.v;
1526
- const items = buildTextItems(model, page, view);
1539
+ if (cached && cached.model === model && cached.zoom === view?.zoom && cached.rotation === view?.rotation && cached.fonts === fonts) return cached.v;
1540
+ const items = buildTextItems(model, page, view, {
1541
+ lookup: fontLookup,
1542
+ text: textFonts
1543
+ });
1527
1544
  textsCache.set(pageObjectNumber, {
1528
1545
  model,
1529
1546
  zoom: view?.zoom,
1530
1547
  rotation: view?.rotation,
1548
+ fonts,
1531
1549
  v: items
1532
1550
  });
1533
1551
  return items;
@@ -1536,13 +1554,18 @@ function createRenderReads(ctx, { view: { pageModel }, lending }, ghost, stamps)
1536
1554
  const textItemOf = (ref, view) => {
1537
1555
  const key = annotationKey$1(ref);
1538
1556
  const model = pageModel(ref.page.objectNumber);
1557
+ const fonts = textFonts.version();
1539
1558
  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);
1559
+ if (cached && cached.model === model && cached.zoom === view?.zoom && cached.rotation === view?.rotation && cached.fonts === fonts) return cached.v;
1560
+ const item = buildTextItem(model, key, view, {
1561
+ lookup: fontLookup,
1562
+ text: textFonts
1563
+ });
1542
1564
  textCache.set(key, {
1543
1565
  model,
1544
1566
  zoom: view?.zoom,
1545
1567
  rotation: view?.rotation,
1568
+ fonts,
1546
1569
  v: item
1547
1570
  });
1548
1571
  return item;
@@ -3053,6 +3076,171 @@ function createStore(ctx, view, records, events, lending) {
3053
3076
  };
3054
3077
  }
3055
3078
  //#endregion
3079
+ //#region src/read/text-fonts.ts
3080
+ /**
3081
+ * The fonts a free text box's text is drawn in by the browser, so it shows the
3082
+ * program the engine writes with. A box someone types in is resolved the way
3083
+ * its write will be (the fonts plugin's `resolve`, with the box, so its own
3084
+ * font counts): when the edit starts, and again after a pause in typing once
3085
+ * the text has a character it wasn't resolved with. Any other box is drawn in
3086
+ * the fonts its names say. Without the fonts plugin, a box is drawn in the
3087
+ * standard font the engine falls back to for its font or face, in that
3088
+ * font's built-in program (`@embedpdf/core-fonts`).
3089
+ */
3090
+ /** How long typing pauses before a box with new characters is resolved again. */
3091
+ const RESOLVE_DELAY_MS = 250;
3092
+ const faceKey = (face) => `${familyKey(face.family)}|${face.weight}|${face.italic}`;
3093
+ /** The key of a box's body in a resolved box's faces. */
3094
+ const BODY = "body";
3095
+ /** Every code point of a text. */
3096
+ const codePointsOf = (text) => Array.from(text, (char) => char.codePointAt(0));
3097
+ function createTextFonts(ctx, store, lookup) {
3098
+ const fonts = () => ctx.tryGet(FontsToken);
3099
+ /**
3100
+ * What the engine answered per box: the run each face its text was resolved with drew in, its
3101
+ * CSS asked for on each read (it changes as the programs reach the browser).
3102
+ */
3103
+ const answers = /* @__PURE__ */ new Map();
3104
+ /** The box being typed in, and the characters its last resolve asked about. */
3105
+ let asked = null;
3106
+ let resolving = null;
3107
+ let cancelPause = () => {};
3108
+ let answered = 0;
3109
+ let token = {
3110
+ list: null,
3111
+ answered,
3112
+ epoch: 0
3113
+ };
3114
+ /** The body's face named by its font alone: then the box's font is the one drawn. */
3115
+ const bodyIsItsFont = (style, body) => {
3116
+ const face = faceForFontName(style.fontFamily, (key) => lookup().find((font) => font.key === key));
3117
+ return (face.weight ?? 400) === body.weight && (face.italic ?? false) === body.italic;
3118
+ };
3119
+ /** Ask the engine what the box's text will be drawn in, and keep the answer. */
3120
+ const resolveBox = async (id) => {
3121
+ const api = fonts();
3122
+ const record = store.model().byId[id];
3123
+ const style = record && textOf(record.annotation);
3124
+ if (!api || !record || !style || record.annotation.subtype !== "free-text") return;
3125
+ const ref = refOf(record) ?? void 0;
3126
+ const doc = richDocOf(record.annotation, lookup);
3127
+ const body = doc.body;
3128
+ const faces = [BODY];
3129
+ const runs = [bodyRun(style, body, bodyIsItsFont(style, body))];
3130
+ let text = "";
3131
+ for (const paragraph of doc.paragraphs) for (const run of paragraph.runs) {
3132
+ text += run.text;
3133
+ const own = run.style;
3134
+ if (own?.family === void 0 && own?.weight === void 0 && own?.italic === void 0) {
3135
+ faces.push(BODY);
3136
+ runs.push({
3137
+ ...bodyRun(style, body, bodyIsItsFont(style, body)),
3138
+ text: run.text
3139
+ });
3140
+ continue;
3141
+ }
3142
+ const face = {
3143
+ family: own.family ?? body.family,
3144
+ weight: own.weight ?? body.weight,
3145
+ italic: own.italic ?? body.italic
3146
+ };
3147
+ faces.push(faceKey(face));
3148
+ runs.push({
3149
+ text: run.text,
3150
+ ...face
3151
+ });
3152
+ }
3153
+ asked = {
3154
+ id,
3155
+ codePoints: new Set(codePointsOf(text))
3156
+ };
3157
+ resolving?.abort();
3158
+ const request = new AbortController();
3159
+ resolving = request;
3160
+ try {
3161
+ await api.ensureLoaded();
3162
+ const answer = await api.resolve({
3163
+ ...ref ? { annotation: ref } : {},
3164
+ runs
3165
+ }, { signal: request.signal });
3166
+ if (resolving !== request) return;
3167
+ const byFace = /* @__PURE__ */ new Map();
3168
+ answer.runs.forEach((run, index) => {
3169
+ const face = faces[index];
3170
+ if (!byFace.has(face)) byFace.set(face, run);
3171
+ });
3172
+ if (!byFace.has(faceKey(body))) byFace.set(faceKey(body), byFace.get(BODY));
3173
+ answers.set(id, byFace);
3174
+ answered++;
3175
+ ctx.notify();
3176
+ } catch {}
3177
+ };
3178
+ let editing = null;
3179
+ ctx.state.onChange(() => {
3180
+ const next = store.model().editing;
3181
+ if (next === editing) return;
3182
+ editing = next;
3183
+ cancelPause();
3184
+ asked = null;
3185
+ if (next !== null) resolveBox(next);
3186
+ });
3187
+ return {
3188
+ bodyCss: (id, style, body) => {
3189
+ const api = fonts();
3190
+ const byFont = bodyIsItsFont(style, body);
3191
+ if (!api) return standardFontCss(byFont ? standardFontOf(style.fontFamily) : standardFontForFace(body));
3192
+ const run = answers.get(id)?.get(BODY);
3193
+ if (run) return api.getRunCss(run);
3194
+ return byFont ? api.getFontCss(style.fontFamily) : api.getFaceCss(body);
3195
+ },
3196
+ faceCss: (id, face) => {
3197
+ const api = fonts();
3198
+ if (!api) return standardFontCss(standardFontForFace(face));
3199
+ const run = id !== null ? answers.get(id)?.get(faceKey(face)) : void 0;
3200
+ return run ? api.getRunCss(run) : api.getFaceCss(face);
3201
+ },
3202
+ familyOfCss: (cssFamily) => {
3203
+ const face = fonts()?.getFaceOfCssFamily(cssFamily);
3204
+ if (face) return face.family;
3205
+ const standard = standardFontOfProgramFamily(cssFamily);
3206
+ return standard && STANDARD_FACES[standard].family;
3207
+ },
3208
+ version: () => {
3209
+ const api = fonts();
3210
+ const list = api?.getFontList() ?? null;
3211
+ const epoch = api?.getPaintFontsEpoch() ?? 0;
3212
+ if (token.list !== list || token.answered !== answered || token.epoch !== epoch) token = {
3213
+ list,
3214
+ answered,
3215
+ epoch
3216
+ };
3217
+ return token;
3218
+ },
3219
+ typed: (id) => {
3220
+ if (editing !== id) return;
3221
+ const record = store.model().byId[id];
3222
+ if (!record) return;
3223
+ const text = richDocOf(record.annotation, lookup).paragraphs.flatMap((paragraph) => paragraph.runs.map((run) => run.text)).join("");
3224
+ const known = asked?.id === id ? asked.codePoints : null;
3225
+ if (known && codePointsOf(text).every((point) => known.has(point))) return;
3226
+ cancelPause();
3227
+ cancelPause = ctx.clock.after(RESOLVE_DELAY_MS, () => void resolveBox(id));
3228
+ }
3229
+ };
3230
+ }
3231
+ /** The body as a run: by the box's font when its face is that font's, else by face. */
3232
+ function bodyRun(style, body, byFont) {
3233
+ return byFont ? {
3234
+ text: "",
3235
+ fontFamily: style.fontFamily
3236
+ } : {
3237
+ text: "",
3238
+ family: body.family,
3239
+ weight: body.weight,
3240
+ italic: body.italic
3241
+ };
3242
+ }
3243
+ //#endregion
3056
3244
  //#region src/tools/behaviors.ts
3057
3245
  /**
3058
3246
  * Behaviors: a sibling plugin (forms, links) or an interactive renderer marks
@@ -3307,6 +3495,7 @@ function createServices(ctx) {
3307
3495
  const view = createView(ctx, records, lending);
3308
3496
  const store = createStore(ctx, view, records, events, lending);
3309
3497
  const tools = createToolRegistry(ctx, settings.get().tools, store, events);
3498
+ const fonts = createFontLookup(ctx);
3310
3499
  return {
3311
3500
  settings,
3312
3501
  events,
@@ -3317,7 +3506,8 @@ function createServices(ctx) {
3317
3506
  geometry,
3318
3507
  authority: createAuthority(ctx, store),
3319
3508
  filePicker: createFilePickerPort(ctx),
3320
- fonts: () => isLocalEngine(ctx.engine) ? ctx.engine.fonts.list() : [],
3509
+ fonts,
3510
+ textFonts: createTextFonts(ctx, store, fonts),
3321
3511
  tools,
3322
3512
  behaviors: createBehaviors(store),
3323
3513
  afterCreate: createAfterCreate(ctx, {
@@ -3327,6 +3517,24 @@ function createServices(ctx) {
3327
3517
  })
3328
3518
  };
3329
3519
  }
3520
+ /** The fonts a box can name: the fonts plugin's list, mapped once per list, else the registered ones. */
3521
+ function createFontLookup(ctx) {
3522
+ let mapped = null;
3523
+ return () => {
3524
+ const list = ctx.tryGet(FontsToken)?.getFontList();
3525
+ if (!list) return isLocalEngine(ctx.engine) ? ctx.engine.fonts.list() : [];
3526
+ if (mapped?.list !== list) mapped = {
3527
+ list,
3528
+ fonts: list.fonts.filter((font) => font.source !== "standard").map(({ name, familyName, weight, italic }) => ({
3529
+ key: name,
3530
+ familyName,
3531
+ weight,
3532
+ italic
3533
+ }))
3534
+ };
3535
+ return mapped.fonts;
3536
+ };
3537
+ }
3330
3538
  //#endregion
3331
3539
  //#region src/services/announce.ts
3332
3540
  /**
@@ -4979,7 +5187,7 @@ function createStamps(ctx, { store, geometry, tools, filePicker, afterCreate })
4979
5187
  * typed after that goes into a new one.
4980
5188
  */
4981
5189
  const TEXT_WRITE_DELAY_MS = 250;
4982
- function createTextEditing(ctx, { store, fonts }, chrome) {
5190
+ function createTextEditing(ctx, { store, fonts, textFonts }, chrome) {
4983
5191
  /** What is being typed: the record, the change it goes into, how it settles, and the pause before it is sent. */
4984
5192
  let typing = null;
4985
5193
  /** Send what was typed now. Resolves once the engine answered it; never rejects. */
@@ -5005,6 +5213,7 @@ function createTextEditing(ctx, { store, fonts }, chrome) {
5005
5213
  });
5006
5214
  const current = typing;
5007
5215
  const commit = store.commit(message, { into: current.hold });
5216
+ textFonts.typed(id);
5008
5217
  current.written = commit.written;
5009
5218
  current.cancelPause();
5010
5219
  current.cancelPause = ctx.clock.after(TEXT_WRITE_DELAY_MS, () => {
@@ -5086,7 +5295,8 @@ function createTextEditing(ctx, { store, fonts }, chrome) {
5086
5295
  if (previous === null === (next === null) && (!previous || !next || previous.id === next.id && previous.start === next.start && previous.end === next.end)) return;
5087
5296
  ctx.state.update(setTextSelection, next);
5088
5297
  },
5089
- getCssFontFamily: (family) => cssFontFamilyForFace(family, fonts)
5298
+ getCssFontFamily: (face, id) => textFonts.faceCss(id, face).fontFamily,
5299
+ getFamilyOfCss: (cssFamily) => textFonts.familyOfCss(cssFamily) ?? cssFamily
5090
5300
  }
5091
5301
  };
5092
5302
  }
@@ -5207,7 +5417,8 @@ function createAnnotationController(ctx) {
5207
5417
  * optionally uses the selection plugin: shapes and ink work without it, text
5208
5418
  * markup lights up only when it is present. The engine's pictures of its
5209
5419
  * annotations come through the render plugin; without it, what draws live
5210
- * still draws. `config` is the settings the app
5420
+ * still draws. With the fonts plugin, text being typed shows in the font
5421
+ * programs the engine writes with. `config` is the settings the app
5211
5422
  * registers, over {@link ANNOTATION_DEFAULTS}.
5212
5423
  */
5213
5424
  const annotationPlugin = (config) => definePlugin({
@@ -5218,7 +5429,8 @@ const annotationPlugin = (config) => definePlugin({
5218
5429
  optional: [
5219
5430
  SelectionToken,
5220
5431
  ActionsToken,
5221
- RenderToken
5432
+ RenderToken,
5433
+ FontsToken
5222
5434
  ],
5223
5435
  state: initialAnnotationModel,
5224
5436
  settings: {