@embedpdf/plugin-annotation 3.3.0 → 3.4.0
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/contract/host.d.cts +2 -2
- package/dist/contract/host.d.ts +2 -2
- package/dist/{contract-DkxvCGXL.d.cts → contract-BfZ-mTF7.d.cts} +10 -4
- package/dist/contract-BrvLUGi2.js.map +1 -1
- package/dist/{contract-CQfRsCVj.d.ts → contract-DRUUSPzY.d.ts} +10 -4
- package/dist/contract-X3gZNpwu.cjs.map +1 -1
- package/dist/contract.d.cts +1 -1
- package/dist/contract.d.ts +1 -1
- package/dist/{host-contract-DE9W8GVT.d.ts → host-contract-BrC7hZw_.d.ts} +15 -7
- package/dist/host-contract-C7vx6wTQ.cjs.map +1 -1
- package/dist/host-contract-CDp5skzD.js.map +1 -1
- package/dist/{host-contract-WxgdlBLx.d.cts → host-contract-CjPbxfhS.d.cts} +15 -7
- package/dist/index.cjs +43 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +39 -9
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-contract-C7vx6wTQ.cjs","names":["PublicAnnotationToken"],"sources":["../src/priorities.ts","../src/host-contract.ts"],"sourcesContent":["/**\n * The interaction-hub priorities of the annotation plugin's handlers — the\n * public contract a sibling plugin builds on when it needs to sit above or\n * below one of them for the same gesture. Priority only breaks ties between\n * simultaneously-eligible handlers (the tool's tags decide eligibility).\n *\n * 100 annotation-edit select/move/resize over an existing annotation\n * 95 annotation-place click-to-place an armed payload on empty page space\n * 55 annotation-draw drag-create under a draw tool (below text-select)\n * 50 annotation-marquee empty-space selection, the final fallback\n *\n * Hover runs in the same order, so a handler's hover sees the cursor claims\n * of every handler above it: a create handler shows its tool's ghost only\n * where nothing above it claims the pointer (an annotation, text).\n *\n * A handler that must win a click over an existing annotation while a\n * placing tool is active (a signature mark dropped onto a signature field)\n * registers above {@link ANNOTATION_EDIT_PRIORITY}, not merely above place:\n * the edit handler captures first over any annotation, a widget included.\n */\nexport const ANNOTATION_EDIT_PRIORITY = 100;\nexport const ANNOTATION_PLACE_PRIORITY = 95;\nexport const ANNOTATION_DRAW_PRIORITY = 55;\nexport const ANNOTATION_MARQUEE_PRIORITY = 50;\n","/**\n * @embedpdf/plugin-annotation/contract/host — the host lens: render\n * projections, sync, pointer routing, ghosts, the markup bridge and the\n * extension seams. Same runtime token as the public one, typed wider.\n */\nimport { createHostToken } from '@embedpdf/core';\nimport type { DocumentEvent, EventHook, PredictedOp, Unsubscribe } from '@embedpdf/core';\nimport type {\n ChromeNode,\n Effect,\n Id,\n Model,\n Rect,\n RenderItem,\n SceneNode,\n KindName,\n TextEndAnchor,\n Quad,\n Point,\n ViewEnv,\n} from '@embedpdf/core-annotation';\nimport type { Rotation } from '@embedpdf/core-geometry';\nimport type {\n AnnotationAppearanceImage,\n AnnotationPosition,\n AnnotationRef,\n ChangeOp,\n ImageSource,\n PageMeasurementViewport,\n PageRef,\n PdfMeasure,\n RichTextParagraph,\n SerializedEngineError,\n} from '@embedpdf/engine-core/runtime';\nimport type {\n AnnotationCommitEntry,\n AnnotationCommitResult,\n} from '@embedpdf/plugin-actions/contract/host';\nimport type { AppearancePicture } from '@embedpdf/plugin-render/contract/host';\n\nimport type {\n Annotation,\n AnnotationAnchor,\n AnnotationCapability,\n AnnotationSelectionAnchor,\n ArmedStampInfo,\n ArmedStampPreview,\n Behavior,\n LinkNavItem,\n TextItem,\n ImageGhost,\n} from './contract';\nimport { AnnotationToken as PublicAnnotationToken } from './token';\nimport type { ResolvedTool } from './tools/definitions';\n\nexport * from './contract';\nexport type { AnnotationModel } from './model';\nexport {\n ANNOTATION_DRAW_PRIORITY,\n ANNOTATION_EDIT_PRIORITY,\n ANNOTATION_MARQUEE_PRIORITY,\n ANNOTATION_PLACE_PRIORITY,\n} from './priorities';\n\n/**\n * One annotation's look at rest in one of its states, as the render layer\n * paints it: the engine's picture, or, while the annotation's create is on\n * its way, the one this device made (a placed stamp's preview), which the\n * engine's replaces. `version` is the record's picture version it shows\n * (`RenderItem.pictureVersion`): one drawn at another version shows another look.\n */\nexport interface AnnotationAppearancePicture extends Pick<\n AnnotationAppearanceImage,\n 'ref' | 'mode' | 'state' | 'rect'\n> {\n readonly image: ImageSource;\n readonly version: number;\n}\n\n/**\n * A sibling plugin that lends this plugin records it owns (the form plugin's\n * widgets), so they are selected, moved, resized, restyled and deleted with\n * the annotation tools. This plugin never stores them: it shows them as the\n * lender says, and an edit of one becomes the lender's ops, in the same change\n * as the rest of the edit.\n */\nexport interface AnnotationLender {\n /** Who owns the records, for a refusal that sends you there (`'form'`). */\n readonly owner: string;\n /**\n * Its records as the engine confirmed them and as they show, each list the\n * same object until it changes; `null` while it lends none.\n */\n records(): {\n readonly confirmed: readonly Annotation[];\n readonly shown: readonly Annotation[];\n } | null;\n /**\n * The ops that write a message's effects on its records, all at once:\n * `model` is the model the message left, `before` the one it started from\n * (a record it deleted is there).\n */\n opsOf(effects: readonly Effect[], model: Model, before: Model): readonly ChangeOp[];\n /** What undoing these ops looks like. */\n undoOf(ops: readonly ChangeOp[]): readonly PredictedOp[];\n /** The ops that move these records of one page to `position` in its drawing order. */\n reorderOps(\n page: PageRef,\n refs: readonly AnnotationRef[],\n position: AnnotationPosition,\n ): readonly ChangeOp[];\n /**\n * The ops that copy these records, as the lender copies its own (a form's\n * widgets: a radio button's copy joins its group, any other widget's is a\n * new field), each moved by `offset`, on `page` when one is named; and the\n * copies' refs, in the order of the records given. A record it leaves out\n * has no copy. Resolves once the object numbers the ops take are there.\n */\n copyOps(\n refs: readonly AnnotationRef[],\n placement: {\n readonly page?: PageRef;\n readonly offset?: { readonly x: number; readonly y: number };\n },\n ): Promise<{ readonly ops: readonly ChangeOp[]; readonly copies: readonly AnnotationRef[] }>;\n /** Whether this session may change, delete and copy the record. */\n getAuthority(record: Annotation): {\n readonly update: boolean;\n readonly delete: boolean;\n readonly copy: boolean;\n };\n /** What its records' pictures on a page depend on: a new value means new pictures. */\n getPictureEpoch(page: PageRef): string;\n /** A record's confirmed picture version; kept for one that went, so an undo brings it back with it. */\n getPictureVersion(record: AnnotationRef): number;\n /**\n * The record's look as it shows isn't its confirmed look yet, whatever changed it (a restyle,\n * a resize, one just placed, a change the lender made itself): it draws live, by its\n * {@link painter}, until the engine's picture of it is there.\n */\n isPending(record: AnnotationRef): boolean;\n /**\n * How the lender draws the record live: the record upright in `box` (its box, or where a\n * gesture has it), in page space; `null` for one it doesn't draw. A record with a painter\n * draws live while a gesture reshapes it, as a square does.\n */\n painter(record: Annotation): ((box: Rect) => readonly SceneNode[]) | null;\n /** Its records' pictures on a page, at rest, in every state, each with its record's picture version. */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<readonly AppearancePicture[]>;\n}\n\nexport interface RecalibrationReport {\n page: PageRef;\n scale: PdfMeasure;\n /** Page-wide read failure: no complete annotation set was available to recalculate. */\n error?: SerializedEngineError;\n updated: AnnotationRef[];\n skipped: {\n ref: AnnotationRef;\n reason: 'no-authority' | 'locked' | 'foreign-measure' | 'unavailable';\n }[];\n failed: { ref: AnnotationRef; error: SerializedEngineError }[];\n}\n\nexport interface CapturedAnnotationDraft {\n tool: string;\n page: PageRef;\n from: Point;\n to: Point;\n}\n\n/**\n * Ghost render buckets: powers of two from 128 px up to `cap`. The same policy\n * the page renderer uses — one bitmap per size class, never per zoom step.\n */\nexport function previewBucket(devicePixelWidth: number, maxWidth = 4096): number {\n const px = Math.max(128, Math.ceil(devicePixelWidth));\n return Math.min(maxWidth, 2 ** Math.ceil(Math.log2(px)));\n}\n\n/**\n * The host (framework) surface: everything the render layer, the interaction hub,\n * and sibling plugins need, on top of the public {@link AnnotationCapability}.\n * Host-only: sibling plugins and framework adapters import the token from\n * `@embedpdf/plugin-annotation/contract/host`. Never use it from application code.\n */\nexport interface AnnotationHostCapability extends AnnotationCapability {\n // ── measurement seam ──\n setPageViewports(\n page: PageRef,\n viewports: PageMeasurementViewport[] | undefined,\n fallback: PdfMeasure,\n ): void;\n /**\n * Resolves once the document's measurements can be re-measured: the\n * annotations loaded (a failed load retried) and every pending load settled.\n */\n whenRemeasurable(): Promise<void>;\n /**\n * Stage the update of every measurement on `page` to `scale`, at once, so a\n * group (`ctx.changes.group`) takes it into its change. What it staged is\n * `updated`; a refused change refuses all of it. `error` is set, and\n * nothing staged, when the annotations aren't loaded.\n */\n stageRemeasure(page: PageRef, scale: PdfMeasure): RecalibrationReport;\n /** A distance draft was captured (the measurement plugin turns it into a calibration). */\n readonly onDraftCaptured: EventHook<CapturedAnnotationDraft>;\n getDistanceCreationPage(): PageRef | null;\n /**\n * Whether a shape that is made click by click waits for its next click: a\n * polygon's or polyline's next corner, a callout's knee or box, a distance\n * line's placement. That click is the shape's, also where it lands on an\n * existing annotation.\n */\n hasCreationAwaitingClick(): boolean;\n\n // ── render projections (page space; a view env projects for a rotated / zoomed view) ──\n /**\n * The selection's anchor as a page shows it: its rotation handle where the\n * page's view puts it (screen-sized, so it depends on the zoom), for a menu\n * that stays clear of it. `selection.getAnchor()` is the same without a view.\n */\n getSelectionAnchorIn(view: {\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n }): AnnotationSelectionAnchor | null;\n /**\n * Where UI attaches to one annotation (its page and the box around what it\n * shows, a drag in progress included), or `null` for one that isn't here.\n * Without a view, an annotation that keeps its size on screen carries\n * `boundsIn` for the view it's shown in.\n */\n getAnnotationAnchor(ref: AnnotationRef, view?: ViewEnv): AnnotationAnchor | null;\n listPageItems(page: PageRef, view?: ViewEnv): RenderItem[];\n /**\n * The text boxes the layer draws as elements: the ones typed in or redrawn\n * live. A saved, idle one shows its engine picture instead.\n */\n listTextItems(page: PageRef, view?: ViewEnv): TextItem[];\n /**\n * One free text's text box in every state, saved and idle included: for a\n * renderer that draws the box itself (`useRichTextEditor`), which no\n * engine picture is drawn under. `null` for one that isn't a free text here.\n */\n getTextItem(ref: AnnotationRef, view?: ViewEnv): TextItem | null;\n listChromeNodes(page: PageRef, scale?: number, rotation?: Rotation, zoom?: number): ChromeNode[];\n listLinkItems(page: PageRef): LinkNavItem[];\n /**\n * What a page's pictures depend on: its baked records at their picture\n * versions, the stamps this session placed, the pictures kept for an undone\n * delete and the lender's widgets. Load the pictures again when it changes,\n * or when the appearance scale (`render.getAppearanceScale`) does.\n */\n getAppearanceEpoch(page: PageRef): string;\n /**\n * Every picture a page's annotations show at rest, in every state, each\n * with its record's picture version: the engine's (through the render\n * plugin; none without it), the lender's, and this session's placed stamps.\n */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<AnnotationAppearancePicture[]>;\n\n // ── sync ──\n /**\n * Resolves once the annotations mirror has applied every confirmed change\n * it knows of, including page re-reads that events started.\n */\n whenSynced(): Promise<void>;\n\n // ── text editing (the editor's draft path: shown at once, written after a pause) ──\n getEditingId(): Id | null;\n beginTextEditAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n draftContents(ref: AnnotationRef, text: string): void;\n /** Returns the paragraphs it keeps: the text typed at the caret takes a style chosen there. */\n draftRichText(\n ref: AnnotationRef,\n doc: { paragraphs: RichTextParagraph[] },\n ): { paragraphs: RichTextParagraph[] };\n setTextSelection(ref: AnnotationRef, range: { start: number; end: number } | null): void;\n /**\n * The CSS family list a face is drawn with in a text box (`id`; `null` for\n * none yet): the font programs the engine draws it in, with the fonts\n * plugin installed.\n */\n getCssFontFamily(\n face: { family: string; weight: number; italic: boolean },\n id: string | null,\n ): string;\n /** The family a CSS family a text box was drawn with stands for, for text the browser drew itself. */\n getFamilyOfCss(cssFamily: string): string | undefined;\n\n // ── pointer routing ──\n getHitKind(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): 'handle' | 'rotate' | 'group-handle' | 'annot' | 'empty';\n claimsTouchAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n getCursorAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): string | null;\n hoverAt(\n at: {\n page: PageRef;\n point: Point;\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n } | null,\n ): void;\n editPointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): void;\n marqueePointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): void;\n createPointer(\n tool: string,\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n finish?: boolean,\n displayRotation?: Rotation,\n ): void;\n /**\n * Make the pen drawing that waits for its next stroke an annotation now,\n * as its tool's `afterCreate` says. A stroke still being drawn is left alone.\n */\n finishInkDraft(): void;\n /** Place with the active tool at a click; `displayRotation` and `zoom` are the page's view there. */\n placeAt(page: PageRef, point: Point, displayRotation?: Rotation, zoom?: number): boolean;\n placeArmedStamp(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n requestStampAt(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n\n // ── markup bridge (the selection plugin meets the text tools) ──\n /**\n * Turn the text selection into what the tool makes of it (markup, a caret,\n * a replace-text pair) and clear the selection; `false`, and nothing, for a\n * tool that makes nothing of a selection, without create authority, or\n * without a selection.\n */\n applyToolToSelection(toolId: string): boolean;\n createMarkup(subtype: KindName, page: PageRef, quads: Quad[], preset?: string): void;\n createCaret(page: PageRef, anchor: TextEndAnchor): void;\n createReplaceText(page: PageRef, quads: Quad[], anchor: TextEndAnchor, preset?: string): void;\n previewMarkup(subtype: KindName, quadsByPage: Record<number, Quad[]>, preset?: string): void;\n clearMarkupPreview(): void;\n\n // ── ghosts and previews (tools/ghost.ts) ──\n /**\n * Put the tool's ghost at a hover, what a click there would make;\n * `displayRotation` and `zoom` are the page's view there. The handler that\n * would take the click calls it, only where the click would reach it and\n * the user may create; a tool without a ghost clears it.\n */\n hoverGhostAt(\n toolId: string,\n page: PageRef,\n point: Point,\n displayRotation?: Rotation,\n zoom?: number,\n ): void;\n clearGhost(): void;\n /**\n * A sibling plugin's placement gesture with one of this plugin's tools (the\n * form palette's drag-to-place): its press and the pointer now. Once it is a\n * drag, the page paints what releasing places; under that the tool's ghost\n * still shows the click.\n */\n previewPlacement(toolId: string, page: PageRef, from: Point, to: Point): void;\n clearPlacementPreview(): void;\n /** The armed stamp's ghost on a page, for the render layer's `<img>`. */\n getImageGhost(page: PageRef): ImageGhost | null;\n /** The armed stamp: a new object on every arm, null when nothing is armed. */\n getArmedStamp(): ArmedStampInfo | null;\n /** Render the armed stamp's ghost preview for a device pixel width (cached per size bucket). */\n renderArmedStampPreview(devicePixelWidth?: number): Promise<ArmedStampPreview | null>;\n\n // ── extension ──\n /**\n * Show a sibling's records with the annotations and edit them with the same\n * tools (see {@link AnnotationLender}). One lender at a time; returns the\n * release.\n */\n lend(lender: AnnotationLender): Unsubscribe;\n listResolvedTools(): ResolvedTool[];\n getResolvedTool(id: string): ResolvedTool | null;\n getToolSubtype(id: string): KindName;\n registerBehavior(behavior: Behavior): Unsubscribe;\n /** The engaged behavior that owns this annotation now, or `null`. */\n getBehaviorFor(annotation: Annotation): Behavior | null;\n pruneEngagedSelection(): void;\n commitScriptEffects(entries: AnnotationCommitEntry[]): Promise<AnnotationCommitResult>;\n}\n\n/**\n * The annotation capability token, typed to the full\n * {@link AnnotationHostCapability} (the package internals and `/contract/host`\n * use this view). The package root exports the same runtime token narrowed to\n * {@link AnnotationCapability}.\n */\nexport const AnnotationToken = createHostToken<AnnotationHostCapability>(PublicAnnotationToken);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,2BAA2B;AACxC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,8BAA8B;;;;;;;;;;;;AC4J3C,SAAgB,cAAc,kBAA0B,WAAW,MAAc;CAE/E,OAAO,KAAK,IAAI,UAAU,KAAK,KAAK,KAAK,KAAK,KADnC,KAAK,IAAI,KAAK,KAAK,KAAK,gBAAgB,CACC,CAAC,CAAC,CAAC;AACzD;;;;;;;AAmQA,MAAa,mBAAA,GAAA,eAAA,gBAAA,CAA4DA,iBAAAA,eAAqB"}
|
|
1
|
+
{"version":3,"file":"host-contract-C7vx6wTQ.cjs","names":["PublicAnnotationToken"],"sources":["../src/priorities.ts","../src/host-contract.ts"],"sourcesContent":["/**\n * The interaction-hub priorities of the annotation plugin's handlers — the\n * public contract a sibling plugin builds on when it needs to sit above or\n * below one of them for the same gesture. Priority only breaks ties between\n * simultaneously-eligible handlers (the tool's tags decide eligibility).\n *\n * 100 annotation-edit select/move/resize over an existing annotation\n * 95 annotation-place click-to-place an armed payload on empty page space\n * 55 annotation-draw drag-create under a draw tool (below text-select)\n * 50 annotation-marquee empty-space selection, the final fallback\n *\n * Hover runs in the same order, so a handler's hover sees the cursor claims\n * of every handler above it: a create handler shows its tool's ghost only\n * where nothing above it claims the pointer (an annotation, text).\n *\n * A handler that must win a click over an existing annotation while a\n * placing tool is active (a signature mark dropped onto a signature field)\n * registers above {@link ANNOTATION_EDIT_PRIORITY}, not merely above place:\n * the edit handler captures first over any annotation, a widget included.\n */\nexport const ANNOTATION_EDIT_PRIORITY = 100;\nexport const ANNOTATION_PLACE_PRIORITY = 95;\nexport const ANNOTATION_DRAW_PRIORITY = 55;\nexport const ANNOTATION_MARQUEE_PRIORITY = 50;\n","/**\n * @embedpdf/plugin-annotation/contract/host — the host lens: render\n * projections, sync, pointer routing, ghosts, the markup bridge and the\n * extension seams. Same runtime token as the public one, typed wider.\n */\nimport { createHostToken } from '@embedpdf/core';\nimport type { DocumentEvent, EventHook, PredictedOp, Unsubscribe } from '@embedpdf/core';\nimport type {\n ChromeNode,\n Effect,\n Id,\n Model,\n RecordAccent,\n Rect,\n RenderItem,\n SceneNode,\n KindName,\n TextEndAnchor,\n Quad,\n Point,\n ViewEnv,\n} from '@embedpdf/core-annotation';\nimport type { Rotation } from '@embedpdf/core-geometry';\nimport type {\n AnnotationAppearanceImage,\n AnnotationPosition,\n AnnotationRef,\n ChangeOp,\n ImageSource,\n PageMeasurementViewport,\n PageRef,\n PdfMeasure,\n RichTextParagraph,\n SerializedEngineError,\n} from '@embedpdf/engine-core/runtime';\nimport type {\n AnnotationCommitEntry,\n AnnotationCommitResult,\n} from '@embedpdf/plugin-actions/contract/host';\nimport type { AppearancePicture } from '@embedpdf/plugin-render/contract/host';\n\nimport type {\n Annotation,\n AnnotationAnchor,\n AnnotationCapability,\n AnnotationSelectionAnchor,\n ArmedStampInfo,\n ArmedStampPreview,\n Behavior,\n LinkNavItem,\n TextItem,\n ImageGhost,\n} from './contract';\nimport { AnnotationToken as PublicAnnotationToken } from './token';\nimport type { ResolvedTool } from './tools/definitions';\n\nexport * from './contract';\nexport type { AnnotationModel } from './model';\nexport {\n ANNOTATION_DRAW_PRIORITY,\n ANNOTATION_EDIT_PRIORITY,\n ANNOTATION_MARQUEE_PRIORITY,\n ANNOTATION_PLACE_PRIORITY,\n} from './priorities';\n\n/**\n * One annotation's look at rest in one of its states, as the render layer\n * paints it: the engine's picture, or, while the annotation's create is on\n * its way, the one this device made (a placed stamp's preview), which the\n * engine's replaces. `version` is the record's picture version it shows\n * (`RenderItem.pictureVersion`): one drawn at another version shows another look.\n */\nexport interface AnnotationAppearancePicture extends Pick<\n AnnotationAppearanceImage,\n 'ref' | 'mode' | 'state' | 'rect'\n> {\n readonly image: ImageSource;\n readonly version: number;\n}\n\n/**\n * A sibling plugin that lends this plugin records it owns (the form plugin's\n * widgets), so they are selected, moved, resized, restyled and deleted with\n * the annotation tools. This plugin never stores them: it shows them as the\n * lender says, and an edit of one becomes the lender's ops, in the same change\n * as the rest of the edit.\n */\nexport interface AnnotationLender {\n /** Who owns the records, for a refusal that sends you there (`'form'`). */\n readonly owner: string;\n /**\n * Its records as the engine confirmed them and as they show, each list the\n * same object until it changes; `null` while it lends none.\n */\n records(): {\n readonly confirmed: readonly Annotation[];\n readonly shown: readonly Annotation[];\n } | null;\n /**\n * The ops that write a message's effects on its records, all at once:\n * `model` is the model the message left, `before` the one it started from\n * (a record it deleted is there).\n */\n opsOf(effects: readonly Effect[], model: Model, before: Model): readonly ChangeOp[];\n /** What undoing these ops looks like. */\n undoOf(ops: readonly ChangeOp[]): readonly PredictedOp[];\n /** The ops that move these records of one page to `position` in its drawing order. */\n reorderOps(\n page: PageRef,\n refs: readonly AnnotationRef[],\n position: AnnotationPosition,\n ): readonly ChangeOp[];\n /**\n * The ops that copy these records, as the lender copies its own (a form's\n * widgets: a radio button's copy joins its group, any other widget's is a\n * new field), each moved by `offset`, on `page` when one is named; and the\n * copies' refs, in the order of the records given. A record it leaves out\n * has no copy. Resolves once the object numbers the ops take are there.\n */\n copyOps(\n refs: readonly AnnotationRef[],\n placement: {\n readonly page?: PageRef;\n readonly offset?: { readonly x: number; readonly y: number };\n },\n ): Promise<{ readonly ops: readonly ChangeOp[]; readonly copies: readonly AnnotationRef[] }>;\n /** Whether this session may change, delete and copy the record. */\n getAuthority(record: Annotation): {\n readonly update: boolean;\n readonly delete: boolean;\n readonly copy: boolean;\n };\n /** What its records' pictures on a page depend on: a new value means new pictures. */\n getPictureEpoch(page: PageRef): string;\n /** A record's confirmed picture version; kept for one that went, so an undo brings it back with it. */\n getPictureVersion(record: AnnotationRef): number;\n /**\n * The record's look as it shows isn't its confirmed look yet, whatever changed it (a restyle,\n * a resize, one just placed, a change the lender made itself): it draws live, by its\n * {@link painter}, until the engine's picture of it is there.\n */\n isPending(record: AnnotationRef): boolean;\n /**\n * How the lender draws the record live: the record upright in `box` (its box, or where a\n * gesture has it), in page space; `null` for one it doesn't draw. A record with a painter\n * draws live while a gesture reshapes it, as a square does.\n */\n painter(record: Annotation): ((box: Rect) => readonly SceneNode[]) | null;\n /**\n * The color a record shows in beside its own look, and how strong (a form field's group's);\n * `null` for a record without one. Read again whenever {@link records} hands out a new object.\n */\n accentOf?(record: Annotation): RecordAccent | null;\n /** Its records' pictures on a page, at rest, in every state, each with its record's picture version. */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<readonly AppearancePicture[]>;\n}\n\nexport interface RecalibrationReport {\n page: PageRef;\n scale: PdfMeasure;\n /** Page-wide read failure: no complete annotation set was available to recalculate. */\n error?: SerializedEngineError;\n updated: AnnotationRef[];\n skipped: {\n ref: AnnotationRef;\n reason: 'no-authority' | 'locked' | 'foreign-measure' | 'unavailable';\n }[];\n failed: { ref: AnnotationRef; error: SerializedEngineError }[];\n}\n\nexport interface CapturedAnnotationDraft {\n tool: string;\n page: PageRef;\n from: Point;\n to: Point;\n}\n\n/**\n * Ghost render buckets: powers of two from 128 px up to `cap`. The same policy\n * the page renderer uses — one bitmap per size class, never per zoom step.\n */\nexport function previewBucket(devicePixelWidth: number, maxWidth = 4096): number {\n const px = Math.max(128, Math.ceil(devicePixelWidth));\n return Math.min(maxWidth, 2 ** Math.ceil(Math.log2(px)));\n}\n\n/**\n * The host (framework) surface: everything the render layer, the interaction hub,\n * and sibling plugins need, on top of the public {@link AnnotationCapability}.\n * Host-only: sibling plugins and framework adapters import the token from\n * `@embedpdf/plugin-annotation/contract/host`. Never use it from application code.\n */\nexport interface AnnotationHostCapability extends AnnotationCapability {\n // ── measurement seam ──\n setPageViewports(\n page: PageRef,\n viewports: PageMeasurementViewport[] | undefined,\n fallback: PdfMeasure,\n ): void;\n /**\n * Resolves once the document's measurements can be re-measured: the\n * annotations loaded (a failed load retried) and every pending load settled.\n */\n whenRemeasurable(): Promise<void>;\n /**\n * Stage the update of every measurement on `page` to `scale`, at once, so a\n * group (`ctx.changes.group`) takes it into its change. What it staged is\n * `updated`; a refused change refuses all of it. `error` is set, and\n * nothing staged, when the annotations aren't loaded.\n */\n stageRemeasure(page: PageRef, scale: PdfMeasure): RecalibrationReport;\n /** A distance draft was captured (the measurement plugin turns it into a calibration). */\n readonly onDraftCaptured: EventHook<CapturedAnnotationDraft>;\n getDistanceCreationPage(): PageRef | null;\n /**\n * Whether a shape that is made click by click waits for its next click: a\n * polygon's or polyline's next corner, a callout's knee or box, a distance\n * line's placement. That click is the shape's, also where it lands on an\n * existing annotation.\n */\n hasCreationAwaitingClick(): boolean;\n\n // ── render projections (page space; a view env projects for a rotated / zoomed view) ──\n /**\n * The selection's anchor as a page shows it: its rotation handle where the\n * page's view puts it (screen-sized, so it depends on the zoom), for a menu\n * that stays clear of it. `selection.getAnchor()` is the same without a view.\n */\n getSelectionAnchorIn(view: {\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n }): AnnotationSelectionAnchor | null;\n /**\n * Where UI attaches to one annotation (its page and the box around what it\n * shows, a drag in progress included), or `null` for one that isn't here.\n * Without a view, an annotation that keeps its size on screen carries\n * `boundsIn` for the view it's shown in.\n */\n getAnnotationAnchor(ref: AnnotationRef, view?: ViewEnv): AnnotationAnchor | null;\n listPageItems(page: PageRef, view?: ViewEnv): RenderItem[];\n /**\n * The text boxes the layer draws as elements: the ones typed in or redrawn\n * live. A saved, idle one shows its engine picture instead.\n */\n listTextItems(page: PageRef, view?: ViewEnv): TextItem[];\n /**\n * One free text's text box in every state, saved and idle included: for a\n * renderer that draws the box itself (`useRichTextEditor`), which no\n * engine picture is drawn under. `null` for one that isn't a free text here.\n */\n getTextItem(ref: AnnotationRef, view?: ViewEnv): TextItem | null;\n listChromeNodes(page: PageRef, scale?: number, rotation?: Rotation, zoom?: number): ChromeNode[];\n listLinkItems(page: PageRef): LinkNavItem[];\n /**\n * What a page's pictures depend on: its baked records at their picture\n * versions, the stamps this session placed, the pictures kept for an undone\n * delete and the lender's widgets. Load the pictures again when it changes,\n * or when the appearance scale (`render.getAppearanceScale`) does.\n */\n getAppearanceEpoch(page: PageRef): string;\n /**\n * Every picture a page's annotations show at rest, in every state, each\n * with its record's picture version: the engine's (through the render\n * plugin; none without it), the lender's, and this session's placed stamps.\n */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<AnnotationAppearancePicture[]>;\n\n // ── sync ──\n /**\n * Resolves once the annotations mirror has applied every confirmed change\n * it knows of, including page re-reads that events started.\n */\n whenSynced(): Promise<void>;\n\n // ── text editing (the editor's draft path: shown at once, written after a pause) ──\n getEditingId(): Id | null;\n beginTextEditAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n draftContents(ref: AnnotationRef, text: string): void;\n /** Returns the paragraphs it keeps: the text typed at the caret takes a style chosen there. */\n draftRichText(\n ref: AnnotationRef,\n doc: { paragraphs: RichTextParagraph[] },\n ): { paragraphs: RichTextParagraph[] };\n setTextSelection(ref: AnnotationRef, range: { start: number; end: number } | null): void;\n /**\n * The CSS family list a face is drawn with in a text box (`id`; `null` for\n * none yet): the font programs the engine draws it in, with the fonts\n * plugin installed.\n */\n getCssFontFamily(\n face: { family: string; weight: number; italic: boolean },\n id: string | null,\n ): string;\n /** The family a CSS family a text box was drawn with stands for, for text the browser drew itself. */\n getFamilyOfCss(cssFamily: string): string | undefined;\n\n // ── pointer routing ──\n getHitKind(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): 'handle' | 'rotate' | 'group-handle' | 'annot' | 'empty';\n claimsTouchAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n getCursorAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): string | null;\n hoverAt(\n at: {\n page: PageRef;\n point: Point;\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n } | null,\n ): void;\n editPointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): void;\n marqueePointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): void;\n createPointer(\n tool: string,\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n finish?: boolean,\n displayRotation?: Rotation,\n ): void;\n /**\n * Make the pen drawing that waits for its next stroke an annotation now,\n * as its tool's `afterCreate` says. A stroke still being drawn is left alone.\n */\n finishInkDraft(): void;\n /** Place with the active tool at a click; `displayRotation` and `zoom` are the page's view there. */\n placeAt(page: PageRef, point: Point, displayRotation?: Rotation, zoom?: number): boolean;\n placeArmedStamp(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n requestStampAt(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n\n // ── markup bridge (the selection plugin meets the text tools) ──\n /**\n * Turn the text selection into what the tool makes of it (markup, a caret,\n * a replace-text pair) and clear the selection; `false`, and nothing, for a\n * tool that makes nothing of a selection, without create authority, or\n * without a selection.\n */\n applyToolToSelection(toolId: string): boolean;\n createMarkup(subtype: KindName, page: PageRef, quads: Quad[], preset?: string): void;\n createCaret(page: PageRef, anchor: TextEndAnchor): void;\n createReplaceText(page: PageRef, quads: Quad[], anchor: TextEndAnchor, preset?: string): void;\n previewMarkup(subtype: KindName, quadsByPage: Record<number, Quad[]>, preset?: string): void;\n clearMarkupPreview(): void;\n\n // ── ghosts and previews (tools/ghost.ts) ──\n /**\n * Put the tool's ghost at a hover, what a click there would make;\n * `displayRotation` and `zoom` are the page's view there. The handler that\n * would take the click calls it, only where the click would reach it and\n * the user may create; a tool without a ghost clears it.\n */\n hoverGhostAt(\n toolId: string,\n page: PageRef,\n point: Point,\n displayRotation?: Rotation,\n zoom?: number,\n ): void;\n clearGhost(): void;\n /**\n * A sibling plugin's placement gesture with one of this plugin's tools (the\n * form palette's drag-to-place): its press and the pointer now, and\n * `displayRotation`, the page's view at the press, which an upright tool\n * lays its drag out by. Once it is a drag, the page paints what releasing\n * places; under that the tool's ghost still shows the click.\n */\n previewPlacement(\n toolId: string,\n page: PageRef,\n from: Point,\n to: Point,\n displayRotation?: Rotation,\n ): void;\n clearPlacementPreview(): void;\n /** The armed stamp's ghost on a page, for the render layer's `<img>`. */\n getImageGhost(page: PageRef): ImageGhost | null;\n /** The armed stamp: a new object on every arm, null when nothing is armed. */\n getArmedStamp(): ArmedStampInfo | null;\n /** Render the armed stamp's ghost preview for a device pixel width (cached per size bucket). */\n renderArmedStampPreview(devicePixelWidth?: number): Promise<ArmedStampPreview | null>;\n\n // ── extension ──\n /**\n * Show a sibling's records with the annotations and edit them with the same\n * tools (see {@link AnnotationLender}). One lender at a time; returns the\n * release.\n */\n lend(lender: AnnotationLender): Unsubscribe;\n listResolvedTools(): ResolvedTool[];\n getResolvedTool(id: string): ResolvedTool | null;\n getToolSubtype(id: string): KindName;\n registerBehavior(behavior: Behavior): Unsubscribe;\n /** The engaged behavior that owns this annotation now, or `null`. */\n getBehaviorFor(annotation: Annotation): Behavior | null;\n pruneEngagedSelection(): void;\n commitScriptEffects(entries: AnnotationCommitEntry[]): Promise<AnnotationCommitResult>;\n}\n\n/**\n * The annotation capability token, typed to the full\n * {@link AnnotationHostCapability} (the package internals and `/contract/host`\n * use this view). The package root exports the same runtime token narrowed to\n * {@link AnnotationCapability}.\n */\nexport const AnnotationToken = createHostToken<AnnotationHostCapability>(PublicAnnotationToken);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,2BAA2B;AACxC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,8BAA8B;;;;;;;;;;;;ACkK3C,SAAgB,cAAc,kBAA0B,WAAW,MAAc;CAE/E,OAAO,KAAK,IAAI,UAAU,KAAK,KAAK,KAAK,KAAK,KADnC,KAAK,IAAI,KAAK,KAAK,KAAK,gBAAgB,CACC,CAAC,CAAC,CAAC;AACzD;;;;;;;AA0QA,MAAa,mBAAA,GAAA,eAAA,gBAAA,CAA4DA,iBAAAA,eAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-contract-CDp5skzD.js","names":["PublicAnnotationToken"],"sources":["../src/priorities.ts","../src/host-contract.ts"],"sourcesContent":["/**\n * The interaction-hub priorities of the annotation plugin's handlers — the\n * public contract a sibling plugin builds on when it needs to sit above or\n * below one of them for the same gesture. Priority only breaks ties between\n * simultaneously-eligible handlers (the tool's tags decide eligibility).\n *\n * 100 annotation-edit select/move/resize over an existing annotation\n * 95 annotation-place click-to-place an armed payload on empty page space\n * 55 annotation-draw drag-create under a draw tool (below text-select)\n * 50 annotation-marquee empty-space selection, the final fallback\n *\n * Hover runs in the same order, so a handler's hover sees the cursor claims\n * of every handler above it: a create handler shows its tool's ghost only\n * where nothing above it claims the pointer (an annotation, text).\n *\n * A handler that must win a click over an existing annotation while a\n * placing tool is active (a signature mark dropped onto a signature field)\n * registers above {@link ANNOTATION_EDIT_PRIORITY}, not merely above place:\n * the edit handler captures first over any annotation, a widget included.\n */\nexport const ANNOTATION_EDIT_PRIORITY = 100;\nexport const ANNOTATION_PLACE_PRIORITY = 95;\nexport const ANNOTATION_DRAW_PRIORITY = 55;\nexport const ANNOTATION_MARQUEE_PRIORITY = 50;\n","/**\n * @embedpdf/plugin-annotation/contract/host — the host lens: render\n * projections, sync, pointer routing, ghosts, the markup bridge and the\n * extension seams. Same runtime token as the public one, typed wider.\n */\nimport { createHostToken } from '@embedpdf/core';\nimport type { DocumentEvent, EventHook, PredictedOp, Unsubscribe } from '@embedpdf/core';\nimport type {\n ChromeNode,\n Effect,\n Id,\n Model,\n Rect,\n RenderItem,\n SceneNode,\n KindName,\n TextEndAnchor,\n Quad,\n Point,\n ViewEnv,\n} from '@embedpdf/core-annotation';\nimport type { Rotation } from '@embedpdf/core-geometry';\nimport type {\n AnnotationAppearanceImage,\n AnnotationPosition,\n AnnotationRef,\n ChangeOp,\n ImageSource,\n PageMeasurementViewport,\n PageRef,\n PdfMeasure,\n RichTextParagraph,\n SerializedEngineError,\n} from '@embedpdf/engine-core/runtime';\nimport type {\n AnnotationCommitEntry,\n AnnotationCommitResult,\n} from '@embedpdf/plugin-actions/contract/host';\nimport type { AppearancePicture } from '@embedpdf/plugin-render/contract/host';\n\nimport type {\n Annotation,\n AnnotationAnchor,\n AnnotationCapability,\n AnnotationSelectionAnchor,\n ArmedStampInfo,\n ArmedStampPreview,\n Behavior,\n LinkNavItem,\n TextItem,\n ImageGhost,\n} from './contract';\nimport { AnnotationToken as PublicAnnotationToken } from './token';\nimport type { ResolvedTool } from './tools/definitions';\n\nexport * from './contract';\nexport type { AnnotationModel } from './model';\nexport {\n ANNOTATION_DRAW_PRIORITY,\n ANNOTATION_EDIT_PRIORITY,\n ANNOTATION_MARQUEE_PRIORITY,\n ANNOTATION_PLACE_PRIORITY,\n} from './priorities';\n\n/**\n * One annotation's look at rest in one of its states, as the render layer\n * paints it: the engine's picture, or, while the annotation's create is on\n * its way, the one this device made (a placed stamp's preview), which the\n * engine's replaces. `version` is the record's picture version it shows\n * (`RenderItem.pictureVersion`): one drawn at another version shows another look.\n */\nexport interface AnnotationAppearancePicture extends Pick<\n AnnotationAppearanceImage,\n 'ref' | 'mode' | 'state' | 'rect'\n> {\n readonly image: ImageSource;\n readonly version: number;\n}\n\n/**\n * A sibling plugin that lends this plugin records it owns (the form plugin's\n * widgets), so they are selected, moved, resized, restyled and deleted with\n * the annotation tools. This plugin never stores them: it shows them as the\n * lender says, and an edit of one becomes the lender's ops, in the same change\n * as the rest of the edit.\n */\nexport interface AnnotationLender {\n /** Who owns the records, for a refusal that sends you there (`'form'`). */\n readonly owner: string;\n /**\n * Its records as the engine confirmed them and as they show, each list the\n * same object until it changes; `null` while it lends none.\n */\n records(): {\n readonly confirmed: readonly Annotation[];\n readonly shown: readonly Annotation[];\n } | null;\n /**\n * The ops that write a message's effects on its records, all at once:\n * `model` is the model the message left, `before` the one it started from\n * (a record it deleted is there).\n */\n opsOf(effects: readonly Effect[], model: Model, before: Model): readonly ChangeOp[];\n /** What undoing these ops looks like. */\n undoOf(ops: readonly ChangeOp[]): readonly PredictedOp[];\n /** The ops that move these records of one page to `position` in its drawing order. */\n reorderOps(\n page: PageRef,\n refs: readonly AnnotationRef[],\n position: AnnotationPosition,\n ): readonly ChangeOp[];\n /**\n * The ops that copy these records, as the lender copies its own (a form's\n * widgets: a radio button's copy joins its group, any other widget's is a\n * new field), each moved by `offset`, on `page` when one is named; and the\n * copies' refs, in the order of the records given. A record it leaves out\n * has no copy. Resolves once the object numbers the ops take are there.\n */\n copyOps(\n refs: readonly AnnotationRef[],\n placement: {\n readonly page?: PageRef;\n readonly offset?: { readonly x: number; readonly y: number };\n },\n ): Promise<{ readonly ops: readonly ChangeOp[]; readonly copies: readonly AnnotationRef[] }>;\n /** Whether this session may change, delete and copy the record. */\n getAuthority(record: Annotation): {\n readonly update: boolean;\n readonly delete: boolean;\n readonly copy: boolean;\n };\n /** What its records' pictures on a page depend on: a new value means new pictures. */\n getPictureEpoch(page: PageRef): string;\n /** A record's confirmed picture version; kept for one that went, so an undo brings it back with it. */\n getPictureVersion(record: AnnotationRef): number;\n /**\n * The record's look as it shows isn't its confirmed look yet, whatever changed it (a restyle,\n * a resize, one just placed, a change the lender made itself): it draws live, by its\n * {@link painter}, until the engine's picture of it is there.\n */\n isPending(record: AnnotationRef): boolean;\n /**\n * How the lender draws the record live: the record upright in `box` (its box, or where a\n * gesture has it), in page space; `null` for one it doesn't draw. A record with a painter\n * draws live while a gesture reshapes it, as a square does.\n */\n painter(record: Annotation): ((box: Rect) => readonly SceneNode[]) | null;\n /** Its records' pictures on a page, at rest, in every state, each with its record's picture version. */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<readonly AppearancePicture[]>;\n}\n\nexport interface RecalibrationReport {\n page: PageRef;\n scale: PdfMeasure;\n /** Page-wide read failure: no complete annotation set was available to recalculate. */\n error?: SerializedEngineError;\n updated: AnnotationRef[];\n skipped: {\n ref: AnnotationRef;\n reason: 'no-authority' | 'locked' | 'foreign-measure' | 'unavailable';\n }[];\n failed: { ref: AnnotationRef; error: SerializedEngineError }[];\n}\n\nexport interface CapturedAnnotationDraft {\n tool: string;\n page: PageRef;\n from: Point;\n to: Point;\n}\n\n/**\n * Ghost render buckets: powers of two from 128 px up to `cap`. The same policy\n * the page renderer uses — one bitmap per size class, never per zoom step.\n */\nexport function previewBucket(devicePixelWidth: number, maxWidth = 4096): number {\n const px = Math.max(128, Math.ceil(devicePixelWidth));\n return Math.min(maxWidth, 2 ** Math.ceil(Math.log2(px)));\n}\n\n/**\n * The host (framework) surface: everything the render layer, the interaction hub,\n * and sibling plugins need, on top of the public {@link AnnotationCapability}.\n * Host-only: sibling plugins and framework adapters import the token from\n * `@embedpdf/plugin-annotation/contract/host`. Never use it from application code.\n */\nexport interface AnnotationHostCapability extends AnnotationCapability {\n // ── measurement seam ──\n setPageViewports(\n page: PageRef,\n viewports: PageMeasurementViewport[] | undefined,\n fallback: PdfMeasure,\n ): void;\n /**\n * Resolves once the document's measurements can be re-measured: the\n * annotations loaded (a failed load retried) and every pending load settled.\n */\n whenRemeasurable(): Promise<void>;\n /**\n * Stage the update of every measurement on `page` to `scale`, at once, so a\n * group (`ctx.changes.group`) takes it into its change. What it staged is\n * `updated`; a refused change refuses all of it. `error` is set, and\n * nothing staged, when the annotations aren't loaded.\n */\n stageRemeasure(page: PageRef, scale: PdfMeasure): RecalibrationReport;\n /** A distance draft was captured (the measurement plugin turns it into a calibration). */\n readonly onDraftCaptured: EventHook<CapturedAnnotationDraft>;\n getDistanceCreationPage(): PageRef | null;\n /**\n * Whether a shape that is made click by click waits for its next click: a\n * polygon's or polyline's next corner, a callout's knee or box, a distance\n * line's placement. That click is the shape's, also where it lands on an\n * existing annotation.\n */\n hasCreationAwaitingClick(): boolean;\n\n // ── render projections (page space; a view env projects for a rotated / zoomed view) ──\n /**\n * The selection's anchor as a page shows it: its rotation handle where the\n * page's view puts it (screen-sized, so it depends on the zoom), for a menu\n * that stays clear of it. `selection.getAnchor()` is the same without a view.\n */\n getSelectionAnchorIn(view: {\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n }): AnnotationSelectionAnchor | null;\n /**\n * Where UI attaches to one annotation (its page and the box around what it\n * shows, a drag in progress included), or `null` for one that isn't here.\n * Without a view, an annotation that keeps its size on screen carries\n * `boundsIn` for the view it's shown in.\n */\n getAnnotationAnchor(ref: AnnotationRef, view?: ViewEnv): AnnotationAnchor | null;\n listPageItems(page: PageRef, view?: ViewEnv): RenderItem[];\n /**\n * The text boxes the layer draws as elements: the ones typed in or redrawn\n * live. A saved, idle one shows its engine picture instead.\n */\n listTextItems(page: PageRef, view?: ViewEnv): TextItem[];\n /**\n * One free text's text box in every state, saved and idle included: for a\n * renderer that draws the box itself (`useRichTextEditor`), which no\n * engine picture is drawn under. `null` for one that isn't a free text here.\n */\n getTextItem(ref: AnnotationRef, view?: ViewEnv): TextItem | null;\n listChromeNodes(page: PageRef, scale?: number, rotation?: Rotation, zoom?: number): ChromeNode[];\n listLinkItems(page: PageRef): LinkNavItem[];\n /**\n * What a page's pictures depend on: its baked records at their picture\n * versions, the stamps this session placed, the pictures kept for an undone\n * delete and the lender's widgets. Load the pictures again when it changes,\n * or when the appearance scale (`render.getAppearanceScale`) does.\n */\n getAppearanceEpoch(page: PageRef): string;\n /**\n * Every picture a page's annotations show at rest, in every state, each\n * with its record's picture version: the engine's (through the render\n * plugin; none without it), the lender's, and this session's placed stamps.\n */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<AnnotationAppearancePicture[]>;\n\n // ── sync ──\n /**\n * Resolves once the annotations mirror has applied every confirmed change\n * it knows of, including page re-reads that events started.\n */\n whenSynced(): Promise<void>;\n\n // ── text editing (the editor's draft path: shown at once, written after a pause) ──\n getEditingId(): Id | null;\n beginTextEditAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n draftContents(ref: AnnotationRef, text: string): void;\n /** Returns the paragraphs it keeps: the text typed at the caret takes a style chosen there. */\n draftRichText(\n ref: AnnotationRef,\n doc: { paragraphs: RichTextParagraph[] },\n ): { paragraphs: RichTextParagraph[] };\n setTextSelection(ref: AnnotationRef, range: { start: number; end: number } | null): void;\n /**\n * The CSS family list a face is drawn with in a text box (`id`; `null` for\n * none yet): the font programs the engine draws it in, with the fonts\n * plugin installed.\n */\n getCssFontFamily(\n face: { family: string; weight: number; italic: boolean },\n id: string | null,\n ): string;\n /** The family a CSS family a text box was drawn with stands for, for text the browser drew itself. */\n getFamilyOfCss(cssFamily: string): string | undefined;\n\n // ── pointer routing ──\n getHitKind(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): 'handle' | 'rotate' | 'group-handle' | 'annot' | 'empty';\n claimsTouchAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n getCursorAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): string | null;\n hoverAt(\n at: {\n page: PageRef;\n point: Point;\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n } | null,\n ): void;\n editPointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): void;\n marqueePointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): void;\n createPointer(\n tool: string,\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n finish?: boolean,\n displayRotation?: Rotation,\n ): void;\n /**\n * Make the pen drawing that waits for its next stroke an annotation now,\n * as its tool's `afterCreate` says. A stroke still being drawn is left alone.\n */\n finishInkDraft(): void;\n /** Place with the active tool at a click; `displayRotation` and `zoom` are the page's view there. */\n placeAt(page: PageRef, point: Point, displayRotation?: Rotation, zoom?: number): boolean;\n placeArmedStamp(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n requestStampAt(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n\n // ── markup bridge (the selection plugin meets the text tools) ──\n /**\n * Turn the text selection into what the tool makes of it (markup, a caret,\n * a replace-text pair) and clear the selection; `false`, and nothing, for a\n * tool that makes nothing of a selection, without create authority, or\n * without a selection.\n */\n applyToolToSelection(toolId: string): boolean;\n createMarkup(subtype: KindName, page: PageRef, quads: Quad[], preset?: string): void;\n createCaret(page: PageRef, anchor: TextEndAnchor): void;\n createReplaceText(page: PageRef, quads: Quad[], anchor: TextEndAnchor, preset?: string): void;\n previewMarkup(subtype: KindName, quadsByPage: Record<number, Quad[]>, preset?: string): void;\n clearMarkupPreview(): void;\n\n // ── ghosts and previews (tools/ghost.ts) ──\n /**\n * Put the tool's ghost at a hover, what a click there would make;\n * `displayRotation` and `zoom` are the page's view there. The handler that\n * would take the click calls it, only where the click would reach it and\n * the user may create; a tool without a ghost clears it.\n */\n hoverGhostAt(\n toolId: string,\n page: PageRef,\n point: Point,\n displayRotation?: Rotation,\n zoom?: number,\n ): void;\n clearGhost(): void;\n /**\n * A sibling plugin's placement gesture with one of this plugin's tools (the\n * form palette's drag-to-place): its press and the pointer now. Once it is a\n * drag, the page paints what releasing places; under that the tool's ghost\n * still shows the click.\n */\n previewPlacement(toolId: string, page: PageRef, from: Point, to: Point): void;\n clearPlacementPreview(): void;\n /** The armed stamp's ghost on a page, for the render layer's `<img>`. */\n getImageGhost(page: PageRef): ImageGhost | null;\n /** The armed stamp: a new object on every arm, null when nothing is armed. */\n getArmedStamp(): ArmedStampInfo | null;\n /** Render the armed stamp's ghost preview for a device pixel width (cached per size bucket). */\n renderArmedStampPreview(devicePixelWidth?: number): Promise<ArmedStampPreview | null>;\n\n // ── extension ──\n /**\n * Show a sibling's records with the annotations and edit them with the same\n * tools (see {@link AnnotationLender}). One lender at a time; returns the\n * release.\n */\n lend(lender: AnnotationLender): Unsubscribe;\n listResolvedTools(): ResolvedTool[];\n getResolvedTool(id: string): ResolvedTool | null;\n getToolSubtype(id: string): KindName;\n registerBehavior(behavior: Behavior): Unsubscribe;\n /** The engaged behavior that owns this annotation now, or `null`. */\n getBehaviorFor(annotation: Annotation): Behavior | null;\n pruneEngagedSelection(): void;\n commitScriptEffects(entries: AnnotationCommitEntry[]): Promise<AnnotationCommitResult>;\n}\n\n/**\n * The annotation capability token, typed to the full\n * {@link AnnotationHostCapability} (the package internals and `/contract/host`\n * use this view). The package root exports the same runtime token narrowed to\n * {@link AnnotationCapability}.\n */\nexport const AnnotationToken = createHostToken<AnnotationHostCapability>(PublicAnnotationToken);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,2BAA2B;AACxC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,8BAA8B;;;;;;;;;;;;AC4J3C,SAAgB,cAAc,kBAA0B,WAAW,MAAc;CAE/E,OAAO,KAAK,IAAI,UAAU,KAAK,KAAK,KAAK,KAAK,KADnC,KAAK,IAAI,KAAK,KAAK,KAAK,gBAAgB,CACC,CAAC,CAAC,CAAC;AACzD;;;;;;;AAmQA,MAAa,kBAAkB,gBAA0CA,iBAAqB"}
|
|
1
|
+
{"version":3,"file":"host-contract-CDp5skzD.js","names":["PublicAnnotationToken"],"sources":["../src/priorities.ts","../src/host-contract.ts"],"sourcesContent":["/**\n * The interaction-hub priorities of the annotation plugin's handlers — the\n * public contract a sibling plugin builds on when it needs to sit above or\n * below one of them for the same gesture. Priority only breaks ties between\n * simultaneously-eligible handlers (the tool's tags decide eligibility).\n *\n * 100 annotation-edit select/move/resize over an existing annotation\n * 95 annotation-place click-to-place an armed payload on empty page space\n * 55 annotation-draw drag-create under a draw tool (below text-select)\n * 50 annotation-marquee empty-space selection, the final fallback\n *\n * Hover runs in the same order, so a handler's hover sees the cursor claims\n * of every handler above it: a create handler shows its tool's ghost only\n * where nothing above it claims the pointer (an annotation, text).\n *\n * A handler that must win a click over an existing annotation while a\n * placing tool is active (a signature mark dropped onto a signature field)\n * registers above {@link ANNOTATION_EDIT_PRIORITY}, not merely above place:\n * the edit handler captures first over any annotation, a widget included.\n */\nexport const ANNOTATION_EDIT_PRIORITY = 100;\nexport const ANNOTATION_PLACE_PRIORITY = 95;\nexport const ANNOTATION_DRAW_PRIORITY = 55;\nexport const ANNOTATION_MARQUEE_PRIORITY = 50;\n","/**\n * @embedpdf/plugin-annotation/contract/host — the host lens: render\n * projections, sync, pointer routing, ghosts, the markup bridge and the\n * extension seams. Same runtime token as the public one, typed wider.\n */\nimport { createHostToken } from '@embedpdf/core';\nimport type { DocumentEvent, EventHook, PredictedOp, Unsubscribe } from '@embedpdf/core';\nimport type {\n ChromeNode,\n Effect,\n Id,\n Model,\n RecordAccent,\n Rect,\n RenderItem,\n SceneNode,\n KindName,\n TextEndAnchor,\n Quad,\n Point,\n ViewEnv,\n} from '@embedpdf/core-annotation';\nimport type { Rotation } from '@embedpdf/core-geometry';\nimport type {\n AnnotationAppearanceImage,\n AnnotationPosition,\n AnnotationRef,\n ChangeOp,\n ImageSource,\n PageMeasurementViewport,\n PageRef,\n PdfMeasure,\n RichTextParagraph,\n SerializedEngineError,\n} from '@embedpdf/engine-core/runtime';\nimport type {\n AnnotationCommitEntry,\n AnnotationCommitResult,\n} from '@embedpdf/plugin-actions/contract/host';\nimport type { AppearancePicture } from '@embedpdf/plugin-render/contract/host';\n\nimport type {\n Annotation,\n AnnotationAnchor,\n AnnotationCapability,\n AnnotationSelectionAnchor,\n ArmedStampInfo,\n ArmedStampPreview,\n Behavior,\n LinkNavItem,\n TextItem,\n ImageGhost,\n} from './contract';\nimport { AnnotationToken as PublicAnnotationToken } from './token';\nimport type { ResolvedTool } from './tools/definitions';\n\nexport * from './contract';\nexport type { AnnotationModel } from './model';\nexport {\n ANNOTATION_DRAW_PRIORITY,\n ANNOTATION_EDIT_PRIORITY,\n ANNOTATION_MARQUEE_PRIORITY,\n ANNOTATION_PLACE_PRIORITY,\n} from './priorities';\n\n/**\n * One annotation's look at rest in one of its states, as the render layer\n * paints it: the engine's picture, or, while the annotation's create is on\n * its way, the one this device made (a placed stamp's preview), which the\n * engine's replaces. `version` is the record's picture version it shows\n * (`RenderItem.pictureVersion`): one drawn at another version shows another look.\n */\nexport interface AnnotationAppearancePicture extends Pick<\n AnnotationAppearanceImage,\n 'ref' | 'mode' | 'state' | 'rect'\n> {\n readonly image: ImageSource;\n readonly version: number;\n}\n\n/**\n * A sibling plugin that lends this plugin records it owns (the form plugin's\n * widgets), so they are selected, moved, resized, restyled and deleted with\n * the annotation tools. This plugin never stores them: it shows them as the\n * lender says, and an edit of one becomes the lender's ops, in the same change\n * as the rest of the edit.\n */\nexport interface AnnotationLender {\n /** Who owns the records, for a refusal that sends you there (`'form'`). */\n readonly owner: string;\n /**\n * Its records as the engine confirmed them and as they show, each list the\n * same object until it changes; `null` while it lends none.\n */\n records(): {\n readonly confirmed: readonly Annotation[];\n readonly shown: readonly Annotation[];\n } | null;\n /**\n * The ops that write a message's effects on its records, all at once:\n * `model` is the model the message left, `before` the one it started from\n * (a record it deleted is there).\n */\n opsOf(effects: readonly Effect[], model: Model, before: Model): readonly ChangeOp[];\n /** What undoing these ops looks like. */\n undoOf(ops: readonly ChangeOp[]): readonly PredictedOp[];\n /** The ops that move these records of one page to `position` in its drawing order. */\n reorderOps(\n page: PageRef,\n refs: readonly AnnotationRef[],\n position: AnnotationPosition,\n ): readonly ChangeOp[];\n /**\n * The ops that copy these records, as the lender copies its own (a form's\n * widgets: a radio button's copy joins its group, any other widget's is a\n * new field), each moved by `offset`, on `page` when one is named; and the\n * copies' refs, in the order of the records given. A record it leaves out\n * has no copy. Resolves once the object numbers the ops take are there.\n */\n copyOps(\n refs: readonly AnnotationRef[],\n placement: {\n readonly page?: PageRef;\n readonly offset?: { readonly x: number; readonly y: number };\n },\n ): Promise<{ readonly ops: readonly ChangeOp[]; readonly copies: readonly AnnotationRef[] }>;\n /** Whether this session may change, delete and copy the record. */\n getAuthority(record: Annotation): {\n readonly update: boolean;\n readonly delete: boolean;\n readonly copy: boolean;\n };\n /** What its records' pictures on a page depend on: a new value means new pictures. */\n getPictureEpoch(page: PageRef): string;\n /** A record's confirmed picture version; kept for one that went, so an undo brings it back with it. */\n getPictureVersion(record: AnnotationRef): number;\n /**\n * The record's look as it shows isn't its confirmed look yet, whatever changed it (a restyle,\n * a resize, one just placed, a change the lender made itself): it draws live, by its\n * {@link painter}, until the engine's picture of it is there.\n */\n isPending(record: AnnotationRef): boolean;\n /**\n * How the lender draws the record live: the record upright in `box` (its box, or where a\n * gesture has it), in page space; `null` for one it doesn't draw. A record with a painter\n * draws live while a gesture reshapes it, as a square does.\n */\n painter(record: Annotation): ((box: Rect) => readonly SceneNode[]) | null;\n /**\n * The color a record shows in beside its own look, and how strong (a form field's group's);\n * `null` for a record without one. Read again whenever {@link records} hands out a new object.\n */\n accentOf?(record: Annotation): RecordAccent | null;\n /** Its records' pictures on a page, at rest, in every state, each with its record's picture version. */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<readonly AppearancePicture[]>;\n}\n\nexport interface RecalibrationReport {\n page: PageRef;\n scale: PdfMeasure;\n /** Page-wide read failure: no complete annotation set was available to recalculate. */\n error?: SerializedEngineError;\n updated: AnnotationRef[];\n skipped: {\n ref: AnnotationRef;\n reason: 'no-authority' | 'locked' | 'foreign-measure' | 'unavailable';\n }[];\n failed: { ref: AnnotationRef; error: SerializedEngineError }[];\n}\n\nexport interface CapturedAnnotationDraft {\n tool: string;\n page: PageRef;\n from: Point;\n to: Point;\n}\n\n/**\n * Ghost render buckets: powers of two from 128 px up to `cap`. The same policy\n * the page renderer uses — one bitmap per size class, never per zoom step.\n */\nexport function previewBucket(devicePixelWidth: number, maxWidth = 4096): number {\n const px = Math.max(128, Math.ceil(devicePixelWidth));\n return Math.min(maxWidth, 2 ** Math.ceil(Math.log2(px)));\n}\n\n/**\n * The host (framework) surface: everything the render layer, the interaction hub,\n * and sibling plugins need, on top of the public {@link AnnotationCapability}.\n * Host-only: sibling plugins and framework adapters import the token from\n * `@embedpdf/plugin-annotation/contract/host`. Never use it from application code.\n */\nexport interface AnnotationHostCapability extends AnnotationCapability {\n // ── measurement seam ──\n setPageViewports(\n page: PageRef,\n viewports: PageMeasurementViewport[] | undefined,\n fallback: PdfMeasure,\n ): void;\n /**\n * Resolves once the document's measurements can be re-measured: the\n * annotations loaded (a failed load retried) and every pending load settled.\n */\n whenRemeasurable(): Promise<void>;\n /**\n * Stage the update of every measurement on `page` to `scale`, at once, so a\n * group (`ctx.changes.group`) takes it into its change. What it staged is\n * `updated`; a refused change refuses all of it. `error` is set, and\n * nothing staged, when the annotations aren't loaded.\n */\n stageRemeasure(page: PageRef, scale: PdfMeasure): RecalibrationReport;\n /** A distance draft was captured (the measurement plugin turns it into a calibration). */\n readonly onDraftCaptured: EventHook<CapturedAnnotationDraft>;\n getDistanceCreationPage(): PageRef | null;\n /**\n * Whether a shape that is made click by click waits for its next click: a\n * polygon's or polyline's next corner, a callout's knee or box, a distance\n * line's placement. That click is the shape's, also where it lands on an\n * existing annotation.\n */\n hasCreationAwaitingClick(): boolean;\n\n // ── render projections (page space; a view env projects for a rotated / zoomed view) ──\n /**\n * The selection's anchor as a page shows it: its rotation handle where the\n * page's view puts it (screen-sized, so it depends on the zoom), for a menu\n * that stays clear of it. `selection.getAnchor()` is the same without a view.\n */\n getSelectionAnchorIn(view: {\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n }): AnnotationSelectionAnchor | null;\n /**\n * Where UI attaches to one annotation (its page and the box around what it\n * shows, a drag in progress included), or `null` for one that isn't here.\n * Without a view, an annotation that keeps its size on screen carries\n * `boundsIn` for the view it's shown in.\n */\n getAnnotationAnchor(ref: AnnotationRef, view?: ViewEnv): AnnotationAnchor | null;\n listPageItems(page: PageRef, view?: ViewEnv): RenderItem[];\n /**\n * The text boxes the layer draws as elements: the ones typed in or redrawn\n * live. A saved, idle one shows its engine picture instead.\n */\n listTextItems(page: PageRef, view?: ViewEnv): TextItem[];\n /**\n * One free text's text box in every state, saved and idle included: for a\n * renderer that draws the box itself (`useRichTextEditor`), which no\n * engine picture is drawn under. `null` for one that isn't a free text here.\n */\n getTextItem(ref: AnnotationRef, view?: ViewEnv): TextItem | null;\n listChromeNodes(page: PageRef, scale?: number, rotation?: Rotation, zoom?: number): ChromeNode[];\n listLinkItems(page: PageRef): LinkNavItem[];\n /**\n * What a page's pictures depend on: its baked records at their picture\n * versions, the stamps this session placed, the pictures kept for an undone\n * delete and the lender's widgets. Load the pictures again when it changes,\n * or when the appearance scale (`render.getAppearanceScale`) does.\n */\n getAppearanceEpoch(page: PageRef): string;\n /**\n * Every picture a page's annotations show at rest, in every state, each\n * with its record's picture version: the engine's (through the render\n * plugin; none without it), the lender's, and this session's placed stamps.\n */\n renderAppearances(\n page: PageRef,\n scale: number,\n signal?: AbortSignal,\n ): Promise<AnnotationAppearancePicture[]>;\n\n // ── sync ──\n /**\n * Resolves once the annotations mirror has applied every confirmed change\n * it knows of, including page re-reads that events started.\n */\n whenSynced(): Promise<void>;\n\n // ── text editing (the editor's draft path: shown at once, written after a pause) ──\n getEditingId(): Id | null;\n beginTextEditAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n draftContents(ref: AnnotationRef, text: string): void;\n /** Returns the paragraphs it keeps: the text typed at the caret takes a style chosen there. */\n draftRichText(\n ref: AnnotationRef,\n doc: { paragraphs: RichTextParagraph[] },\n ): { paragraphs: RichTextParagraph[] };\n setTextSelection(ref: AnnotationRef, range: { start: number; end: number } | null): void;\n /**\n * The CSS family list a face is drawn with in a text box (`id`; `null` for\n * none yet): the font programs the engine draws it in, with the fonts\n * plugin installed.\n */\n getCssFontFamily(\n face: { family: string; weight: number; italic: boolean },\n id: string | null,\n ): string;\n /** The family a CSS family a text box was drawn with stands for, for text the browser drew itself. */\n getFamilyOfCss(cssFamily: string): string | undefined;\n\n // ── pointer routing ──\n getHitKind(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): 'handle' | 'rotate' | 'group-handle' | 'annot' | 'empty';\n claimsTouchAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): boolean;\n getCursorAt(\n page: PageRef,\n point: Point,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): string | null;\n hoverAt(\n at: {\n page: PageRef;\n point: Point;\n scale?: number;\n rotation?: Rotation;\n zoom?: number;\n } | null,\n ): void;\n editPointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n touch?: boolean,\n ): void;\n marqueePointer(\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n shift: boolean,\n scale?: number,\n rotation?: Rotation,\n zoom?: number,\n ): void;\n createPointer(\n tool: string,\n phase: 'down' | 'move' | 'up',\n page: PageRef,\n point: Point,\n finish?: boolean,\n displayRotation?: Rotation,\n ): void;\n /**\n * Make the pen drawing that waits for its next stroke an annotation now,\n * as its tool's `afterCreate` says. A stroke still being drawn is left alone.\n */\n finishInkDraft(): void;\n /** Place with the active tool at a click; `displayRotation` and `zoom` are the page's view there. */\n placeAt(page: PageRef, point: Point, displayRotation?: Rotation, zoom?: number): boolean;\n placeArmedStamp(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n requestStampAt(page: PageRef, point: Point, displayRotation?: Rotation): boolean;\n\n // ── markup bridge (the selection plugin meets the text tools) ──\n /**\n * Turn the text selection into what the tool makes of it (markup, a caret,\n * a replace-text pair) and clear the selection; `false`, and nothing, for a\n * tool that makes nothing of a selection, without create authority, or\n * without a selection.\n */\n applyToolToSelection(toolId: string): boolean;\n createMarkup(subtype: KindName, page: PageRef, quads: Quad[], preset?: string): void;\n createCaret(page: PageRef, anchor: TextEndAnchor): void;\n createReplaceText(page: PageRef, quads: Quad[], anchor: TextEndAnchor, preset?: string): void;\n previewMarkup(subtype: KindName, quadsByPage: Record<number, Quad[]>, preset?: string): void;\n clearMarkupPreview(): void;\n\n // ── ghosts and previews (tools/ghost.ts) ──\n /**\n * Put the tool's ghost at a hover, what a click there would make;\n * `displayRotation` and `zoom` are the page's view there. The handler that\n * would take the click calls it, only where the click would reach it and\n * the user may create; a tool without a ghost clears it.\n */\n hoverGhostAt(\n toolId: string,\n page: PageRef,\n point: Point,\n displayRotation?: Rotation,\n zoom?: number,\n ): void;\n clearGhost(): void;\n /**\n * A sibling plugin's placement gesture with one of this plugin's tools (the\n * form palette's drag-to-place): its press and the pointer now, and\n * `displayRotation`, the page's view at the press, which an upright tool\n * lays its drag out by. Once it is a drag, the page paints what releasing\n * places; under that the tool's ghost still shows the click.\n */\n previewPlacement(\n toolId: string,\n page: PageRef,\n from: Point,\n to: Point,\n displayRotation?: Rotation,\n ): void;\n clearPlacementPreview(): void;\n /** The armed stamp's ghost on a page, for the render layer's `<img>`. */\n getImageGhost(page: PageRef): ImageGhost | null;\n /** The armed stamp: a new object on every arm, null when nothing is armed. */\n getArmedStamp(): ArmedStampInfo | null;\n /** Render the armed stamp's ghost preview for a device pixel width (cached per size bucket). */\n renderArmedStampPreview(devicePixelWidth?: number): Promise<ArmedStampPreview | null>;\n\n // ── extension ──\n /**\n * Show a sibling's records with the annotations and edit them with the same\n * tools (see {@link AnnotationLender}). One lender at a time; returns the\n * release.\n */\n lend(lender: AnnotationLender): Unsubscribe;\n listResolvedTools(): ResolvedTool[];\n getResolvedTool(id: string): ResolvedTool | null;\n getToolSubtype(id: string): KindName;\n registerBehavior(behavior: Behavior): Unsubscribe;\n /** The engaged behavior that owns this annotation now, or `null`. */\n getBehaviorFor(annotation: Annotation): Behavior | null;\n pruneEngagedSelection(): void;\n commitScriptEffects(entries: AnnotationCommitEntry[]): Promise<AnnotationCommitResult>;\n}\n\n/**\n * The annotation capability token, typed to the full\n * {@link AnnotationHostCapability} (the package internals and `/contract/host`\n * use this view). The package root exports the same runtime token narrowed to\n * {@link AnnotationCapability}.\n */\nexport const AnnotationToken = createHostToken<AnnotationHostCapability>(PublicAnnotationToken);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,2BAA2B;AACxC,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,8BAA8B;;;;;;;;;;;;ACkK3C,SAAgB,cAAc,kBAA0B,WAAW,MAAc;CAE/E,OAAO,KAAK,IAAI,UAAU,KAAK,KAAK,KAAK,KAAK,KADnC,KAAK,IAAI,KAAK,KAAK,KAAK,gBAAgB,CACC,CAAC,CAAC,CAAC;AACzD;;;;;;;AA0QA,MAAa,kBAAkB,gBAA0CA,iBAAqB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as AnnotationSelectionAnchor, J as ArmedStampPreview, Jt as EditorSelection, Ot as TextItem, Ut as ResolvedTool, Z as Behavior, i as AnnotationAnchor, mt as ImageGhost, o as AnnotationCapability, q as ArmedStampInfo, r as Annotation$1, vt as LinkNavItem } from "./contract-
|
|
2
|
-
import { ChromeNode, EditableKinds, Effect, Id, KindName, Model, Point, Quad, Rect, RenderItem, SceneNode, Session, SnapSettings, TextEndAnchor, ViewEnv } from "@embedpdf/core-annotation";
|
|
1
|
+
import { F as AnnotationSelectionAnchor, J as ArmedStampPreview, Jt as EditorSelection, Ot as TextItem, Ut as ResolvedTool, Z as Behavior, i as AnnotationAnchor, mt as ImageGhost, o as AnnotationCapability, q as ArmedStampInfo, r as Annotation$1, vt as LinkNavItem } from "./contract-BfZ-mTF7.cjs";
|
|
2
|
+
import { ChromeNode, EditableKinds, Effect, Id, KindName, Model, Point, Quad, RecordAccent, Rect, RenderItem, SceneNode, Session, SnapSettings, TextEndAnchor, ViewEnv } from "@embedpdf/core-annotation";
|
|
3
3
|
import { EventHook, PredictedOp, Unsubscribe } from "@embedpdf/core";
|
|
4
4
|
import { Rotation } from "@embedpdf/core-geometry";
|
|
5
5
|
import { AnnotationAppearanceImage, AnnotationPosition, AnnotationRef, ChangeOp, ImageSource, PageMeasurementViewport, PageRef, PdfMeasure, RichTextParagraph, SerializedEngineError } from "@embedpdf/engine-core/runtime";
|
|
@@ -22,6 +22,8 @@ interface ForeignPlacement {
|
|
|
22
22
|
readonly page: PageRef;
|
|
23
23
|
readonly from: Point;
|
|
24
24
|
readonly to: Point;
|
|
25
|
+
/** The page's display rotation at the press (an upright tool lays its drag out as seen). */
|
|
26
|
+
readonly displayRotation?: Rotation;
|
|
25
27
|
}
|
|
26
28
|
interface AnnotationModel {
|
|
27
29
|
/** The core's session: selection, hover, the gesture in progress, tool settings. */
|
|
@@ -159,6 +161,11 @@ interface AnnotationLender {
|
|
|
159
161
|
* draws live while a gesture reshapes it, as a square does.
|
|
160
162
|
*/
|
|
161
163
|
painter(record: Annotation$1): ((box: Rect) => readonly SceneNode[]) | null;
|
|
164
|
+
/**
|
|
165
|
+
* The color a record shows in beside its own look, and how strong (a form field's group's);
|
|
166
|
+
* `null` for a record without one. Read again whenever {@link records} hands out a new object.
|
|
167
|
+
*/
|
|
168
|
+
accentOf?(record: Annotation$1): RecordAccent | null;
|
|
162
169
|
/** Its records' pictures on a page, at rest, in every state, each with its record's picture version. */
|
|
163
170
|
renderAppearances(page: PageRef, scale: number, signal?: AbortSignal): Promise<readonly AppearancePicture[]>;
|
|
164
171
|
}
|
|
@@ -336,11 +343,12 @@ interface AnnotationHostCapability extends AnnotationCapability {
|
|
|
336
343
|
clearGhost(): void;
|
|
337
344
|
/**
|
|
338
345
|
* A sibling plugin's placement gesture with one of this plugin's tools (the
|
|
339
|
-
* form palette's drag-to-place): its press and the pointer now
|
|
340
|
-
*
|
|
341
|
-
*
|
|
346
|
+
* form palette's drag-to-place): its press and the pointer now, and
|
|
347
|
+
* `displayRotation`, the page's view at the press, which an upright tool
|
|
348
|
+
* lays its drag out by. Once it is a drag, the page paints what releasing
|
|
349
|
+
* places; under that the tool's ghost still shows the click.
|
|
342
350
|
*/
|
|
343
|
-
previewPlacement(toolId: string, page: PageRef, from: Point, to: Point): void;
|
|
351
|
+
previewPlacement(toolId: string, page: PageRef, from: Point, to: Point, displayRotation?: Rotation): void;
|
|
344
352
|
clearPlacementPreview(): void;
|
|
345
353
|
/** The armed stamp's ghost on a page, for the render layer's `<img>`. */
|
|
346
354
|
getImageGhost(page: PageRef): ImageGhost | null;
|
|
@@ -372,4 +380,4 @@ interface AnnotationHostCapability extends AnnotationCapability {
|
|
|
372
380
|
declare const AnnotationToken: import("@embedpdf/core").CapabilityToken<AnnotationHostCapability>;
|
|
373
381
|
//#endregion
|
|
374
382
|
export { CapturedAnnotationDraft as a, ANNOTATION_DRAW_PRIORITY as c, ANNOTATION_PLACE_PRIORITY as d, AnnotationModel as f, AnnotationToken as i, ANNOTATION_EDIT_PRIORITY as l, AnnotationHostCapability as n, RecalibrationReport as o, AnnotationLender as r, previewBucket as s, AnnotationAppearancePicture as t, ANNOTATION_MARQUEE_PRIORITY as u };
|
|
375
|
-
//# sourceMappingURL=host-contract-
|
|
383
|
+
//# sourceMappingURL=host-contract-CjPbxfhS.d.cts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1315,6 +1315,7 @@ const FORMATS = /* @__PURE__ */ new Set([
|
|
|
1315
1315
|
/** One property's value, by its key (the border's is its three fields). */
|
|
1316
1316
|
function propertyValue(spec, { data, text, link }) {
|
|
1317
1317
|
if (spec.key === "link") return link ?? null;
|
|
1318
|
+
if (spec.key === "orientation") return String(data.rotation ?? 0);
|
|
1318
1319
|
if (spec.key === "borderStyle") return {
|
|
1319
1320
|
borderStyle: data.borderStyle ?? "solid",
|
|
1320
1321
|
dashArray: data.dashArray ?? null,
|
|
@@ -1982,11 +1983,17 @@ function createView(ctx, records, lending) {
|
|
|
1982
1983
|
const painter = lender.painter(shown);
|
|
1983
1984
|
return painter ? { painter } : {};
|
|
1984
1985
|
};
|
|
1985
|
-
/**
|
|
1986
|
+
/** The same accent: none on both sides, or the same color as strong. */
|
|
1987
|
+
const sameAccent = (left, right) => left === right || left !== null && right !== null && left.color === right.color && left.strength === right.strength;
|
|
1988
|
+
/**
|
|
1989
|
+
* A lent record as the model has it, cached per shown row, the confirmed row it was made from
|
|
1990
|
+
* and the accent its lender gives it.
|
|
1991
|
+
*/
|
|
1986
1992
|
const lent = /* @__PURE__ */ new WeakMap();
|
|
1987
1993
|
const lentRecord = (shown, truth, lender) => {
|
|
1994
|
+
const accent = lender.accentOf?.(shown) ?? null;
|
|
1988
1995
|
const cached = lent.get(shown);
|
|
1989
|
-
if (cached && cached.truth === truth) return cached.record;
|
|
1996
|
+
if (cached && cached.truth === truth && sameAccent(cached.accent, accent)) return cached.record;
|
|
1990
1997
|
let record;
|
|
1991
1998
|
if (!truth) record = {
|
|
1992
1999
|
...(0, _embedpdf_core_annotation.fromDTO)(shown),
|
|
@@ -2018,8 +2025,13 @@ function createView(ctx, records, lending) {
|
|
|
2018
2025
|
source: "vector"
|
|
2019
2026
|
};
|
|
2020
2027
|
}
|
|
2028
|
+
if (accent) record = {
|
|
2029
|
+
...record,
|
|
2030
|
+
accent
|
|
2031
|
+
};
|
|
2021
2032
|
lent.set(shown, {
|
|
2022
2033
|
truth,
|
|
2034
|
+
accent,
|
|
2023
2035
|
record
|
|
2024
2036
|
});
|
|
2025
2037
|
return record;
|
|
@@ -4164,7 +4176,11 @@ function createGhost(ctx, { store, geometry, tools }, stamps) {
|
|
|
4164
4176
|
}
|
|
4165
4177
|
const placingTool = placing && tools.get(placing.toolId);
|
|
4166
4178
|
if (placing?.page.objectNumber === pageObjectNumber && placingTool && (0, _embedpdf_core_annotation.isDrag)("box", placing.from, placing.to)) {
|
|
4167
|
-
const placement = (0, _embedpdf_core_annotation.gesturePlacement)("box", placing.from, placing.to, placingTool.clickCreate, {
|
|
4179
|
+
const placement = (0, _embedpdf_core_annotation.gesturePlacement)("box", placing.from, placing.to, placingTool.clickCreate, {
|
|
4180
|
+
pageBox: geometry.pageBoxOf(pageObjectNumber),
|
|
4181
|
+
upright: placingTool.upright,
|
|
4182
|
+
displayRotation: placing.displayRotation
|
|
4183
|
+
});
|
|
4168
4184
|
const annotation = annotationOfTool(model, placingTool);
|
|
4169
4185
|
const shape = placement && (0, _embedpdf_core_annotation.placedShape)(annotation, placement);
|
|
4170
4186
|
if (shape) items.push((0, _embedpdf_core_annotation.unmadeItem)(PLACING_ID, annotation, shape, "draft", view));
|
|
@@ -4204,12 +4220,13 @@ function createGhost(ctx, { store, geometry, tools }, stamps) {
|
|
|
4204
4220
|
api: {
|
|
4205
4221
|
hoverGhostAt,
|
|
4206
4222
|
clearGhost,
|
|
4207
|
-
previewPlacement: (toolId, page, from, to) => {
|
|
4223
|
+
previewPlacement: (toolId, page, from, to, displayRotation) => {
|
|
4208
4224
|
ctx.state.update(setPlacing, {
|
|
4209
4225
|
toolId,
|
|
4210
4226
|
page,
|
|
4211
4227
|
from,
|
|
4212
|
-
to
|
|
4228
|
+
to,
|
|
4229
|
+
...displayRotation !== void 0 ? { displayRotation } : {}
|
|
4213
4230
|
});
|
|
4214
4231
|
},
|
|
4215
4232
|
clearPlacementPreview: () => {
|
|
@@ -5278,6 +5295,15 @@ function createSelectionWrites(ctx, { store, authority, fonts, behaviors, lendin
|
|
|
5278
5295
|
y: flips("y", "height") ? -10 : DUPLICATE_OFFSET
|
|
5279
5296
|
};
|
|
5280
5297
|
};
|
|
5298
|
+
/** The box of each page the selection is on: where a turn keeps what it turned. */
|
|
5299
|
+
const selectionPageBoxes = () => {
|
|
5300
|
+
const boxes = {};
|
|
5301
|
+
for (const { annotation } of annotations.selectedRecords()) {
|
|
5302
|
+
const box = geometry.pageBoxOf(annotation.page.objectNumber);
|
|
5303
|
+
if (box) boxes[annotation.page.objectNumber] = box;
|
|
5304
|
+
}
|
|
5305
|
+
return boxes;
|
|
5306
|
+
};
|
|
5281
5307
|
/** Commit a selection message; resolves with its outcome over the refs that were selected. */
|
|
5282
5308
|
const commitOverSelection = async (commit, signal) => {
|
|
5283
5309
|
return batchResultOf(selectedRefs(), { failed: (await ctx.cancellable(signal, Promise.all(commit().map((committed) => committed.written)))).flatMap((outcome) => outcome.failed) });
|
|
@@ -5390,12 +5416,16 @@ function createSelectionWrites(ctx, { store, authority, fonts, behaviors, lendin
|
|
|
5390
5416
|
rotateBy: async (degrees, options = {}) => {
|
|
5391
5417
|
const commit = store.commit({
|
|
5392
5418
|
type: "rotateSelection",
|
|
5393
|
-
degrees
|
|
5419
|
+
degrees,
|
|
5420
|
+
pageBoxes: selectionPageBoxes()
|
|
5394
5421
|
});
|
|
5395
5422
|
throwIfFailed(await ctx.cancellable(options.signal, commit.written));
|
|
5396
5423
|
},
|
|
5397
5424
|
resetRotation: async (options = {}) => {
|
|
5398
|
-
const commit = store.commit({
|
|
5425
|
+
const commit = store.commit({
|
|
5426
|
+
type: "resetRotation",
|
|
5427
|
+
pageBoxes: selectionPageBoxes()
|
|
5428
|
+
});
|
|
5399
5429
|
throwIfFailed(await ctx.cancellable(options.signal, commit.written));
|
|
5400
5430
|
},
|
|
5401
5431
|
getAnchor: () => chrome.selectionAnchor(),
|
|
@@ -6072,6 +6102,12 @@ Object.defineProperty(exports, "kindNamed", {
|
|
|
6072
6102
|
return _embedpdf_core_annotation.kindNamed;
|
|
6073
6103
|
}
|
|
6074
6104
|
});
|
|
6105
|
+
Object.defineProperty(exports, "orientationPatch", {
|
|
6106
|
+
enumerable: true,
|
|
6107
|
+
get: function() {
|
|
6108
|
+
return _embedpdf_core_annotation.orientationPatch;
|
|
6109
|
+
}
|
|
6110
|
+
});
|
|
6075
6111
|
Object.defineProperty(exports, "propertiesOf", {
|
|
6076
6112
|
enumerable: true,
|
|
6077
6113
|
get: function() {
|