@embedpdf/plugin-interaction 3.0.0-next.10 → 3.0.0-next.11

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.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_contract = require("./contract-B3tBU_U9.cjs");
2
3
  let _embedpdf_core = require("@embedpdf/core");
3
4
  //#region src/capability.ts
4
5
  /**
@@ -155,18 +156,6 @@ const interactionReducer = (state, action) => {
155
156
  }
156
157
  };
157
158
  //#endregion
158
- //#region src/types.ts
159
- const InteractionToken = (0, _embedpdf_core.createCapabilityToken)("interaction", { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list` });
160
- /**
161
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
162
- * the page they started on even when the cursor wanders off it — `s.page`
163
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
164
- * prefer the source's unclamped projection and fall back to the page hit only
165
- * when it is the same page. Null → this sample can't speak for the home page.
166
- * Shared by every gesture owner (annotation edit/draw, form placement).
167
- */
168
- const samplePointOn = (s, pon) => s.project?.(pon) ?? (s.page?.pon === pon ? s.page.point : null);
169
- //#endregion
170
159
  //#region src/interaction.plugin.ts
171
160
  /**
172
161
  * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a
@@ -210,7 +199,7 @@ const builtinTools = () => [{
210
199
  */
211
200
  const interactionPlugin = (config = {}) => (0, _embedpdf_core.definePlugin)({
212
201
  id: "interaction",
213
- token: InteractionToken,
202
+ token: require_contract.InteractionToken,
214
203
  scope: "document",
215
204
  initialState: () => initialInteractionState(config),
216
205
  reduce: interactionReducer,
@@ -238,7 +227,6 @@ const interactionPlugin = (config = {}) => (0, _embedpdf_core.definePlugin)({
238
227
  * output; call-site semantics ("word selected", "annotation picked up") pick a
239
228
  * family, they never add one.
240
229
  */
241
- const FeedbackToken = (0, _embedpdf_core.createCapabilityToken)("feedback");
242
230
  /** No provider → every call is a cheap no-op; consumers never branch. */
243
231
  const NOOP = {
244
232
  selection() {},
@@ -252,20 +240,20 @@ const NOOP = {
252
240
  const feedbackPlugin = (options = {}) => (0, _embedpdf_core.definePlugin)({
253
241
  id: "feedback",
254
242
  scope: "workspace",
255
- token: FeedbackToken,
243
+ token: require_contract.FeedbackToken,
256
244
  initialState: () => ({}),
257
245
  reduce: (state) => state,
258
246
  capability: () => options.provider ?? NOOP
259
247
  });
260
248
  //#endregion
261
- exports.FeedbackToken = FeedbackToken;
262
- exports.InteractionToken = InteractionToken;
249
+ exports.FeedbackToken = require_contract.FeedbackToken;
250
+ exports.InteractionToken = require_contract.InteractionToken;
263
251
  exports.builtinTools = builtinTools;
264
252
  exports.createInteractionCapability = createInteractionCapability;
265
253
  exports.feedbackPlugin = feedbackPlugin;
266
254
  exports.initialInteractionState = initialInteractionState;
267
255
  exports.interactionPlugin = interactionPlugin;
268
256
  exports.interactionReducer = interactionReducer;
269
- exports.samplePointOn = samplePointOn;
257
+ exports.samplePointOn = require_contract.samplePointOn;
270
258
 
271
259
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/capability.ts","../src/reducer.ts","../src/types.ts","../src/interaction.plugin.ts","../src/feedback.ts"],"sourcesContent":["import type { PluginContext } from '@embedpdf/core';\nimport type {\n Cursor,\n InteractionAction,\n InteractionCapability,\n InteractionHandler,\n InteractionState,\n Tool,\n ToolCursorSkin,\n ToolId,\n} from './types';\n\ninterface Claim {\n cursor: Cursor;\n priority: number;\n}\n\n/**\n * The interaction hub. Tools + handlers + the captured-gesture owner + cursor\n * claims live in this closure (runtime registries, not serializable state); the\n * reducer state holds only the active tool id and the resolved cursor, so the UI\n * can react to them. The router (`dispatch`) is the heart: on down, the first\n * eligible handler (by priority) to return true OWNS the gesture; move/up route\n * to it; with no owner, move is hover (cursor feedback).\n *\n * Cursor arbitration, top to bottom: the highest-priority CLAIM (hover feedback\n * — 'move' over an annotation, 'text' over text) → over a page, the tool's\n * declared cursor → over a gap, the tool's `gapCursor` (default the neutral\n * arrow). The winning KEYWORD (claim or base, never gap) is then restyled\n * through the armed tool's skin when it maps that keyword. One resolver, so an\n * image cursor can never shadow hover feedback or outlive the page under the\n * pointer.\n */\nexport function createInteractionCapability(\n ctx: PluginContext<InteractionState, InteractionAction>,\n builtinTools: Tool[],\n): InteractionCapability {\n const tools = new Map<ToolId, Tool>();\n for (const t of builtinTools) tools.set(t.id, t);\n const handlers: InteractionHandler[] = [];\n const claims = new Map<string, Claim>();\n const cursorSkins = new Map<ToolId, ToolCursorSkin>();\n const toolCbs = new Set<() => void>();\n let owner: InteractionHandler | null = null;\n // Whether the last dispatched sample hit a page — the base cursor only\n // applies where the tool can act; over gaps it falls back to `gapCursor`.\n let overPage = false;\n\n const toolOf = (id: ToolId): Tool =>\n tools.get(id) ?? { id, cursor: 'default', enables: new Set() };\n const active = (): Tool => toolOf(ctx.getState().activeToolId);\n\n const resolveCursor = (): Cursor => {\n let top: Claim | null = null;\n for (const c of claims.values()) if (!top || c.priority > top.priority) top = c;\n const tool = active();\n const skin = cursorSkins.get(tool.id);\n // The cursor keeps its MEANING (a keyword — the winning claim's, else the\n // tool's declared base); the skin may restyle that keyword in the armed\n // tool's identity (an I-beam + tool icon over text). Unmapped keywords\n // render as-is — a foreign affordance drops the tool identity — and gaps\n // resolve before the skin: identity only where the action is possible.\n if (top) return skin?.[top.cursor] ?? top.cursor;\n if (!overPage) return tool.gapCursor ?? 'default';\n return skin?.[tool.cursor] ?? tool.cursor;\n };\n const syncCursor = (): void => {\n const next = resolveCursor();\n if (next !== ctx.getState().cursor) ctx.dispatch({ type: 'SET_CURSOR', cursor: next });\n };\n\n // Lens scoping: a handler registered with a `source` only sees samples\n // stamped with it. Filtering is on DEFINITE mismatch only — an unstamped\n // sample (custom dispatcher, single-lens embed) still routes everywhere.\n const handlerSources = new Map<InteractionHandler, string>();\n const eligible = (source?: string): InteractionHandler[] => {\n const tool = active();\n return handlers\n .filter((h) => {\n const hs = handlerSources.get(h);\n return hs === undefined || source === undefined || hs === source;\n })\n .filter((h) => h.enabledFor(tool))\n .sort((a, b) => b.priority - a.priority);\n };\n\n return {\n activeTool: active,\n activeToolId: () => ctx.getState().activeToolId,\n cursor: () => ctx.getState().cursor,\n tools: () => [...tools.values()],\n\n activateTool: (id) => {\n if (!tools.has(id)) throw new Error(`[interaction] unknown tool '${id}'`);\n owner = null;\n claims.clear(); // drop the previous tool's hover claims; handlers re-claim on next hover\n ctx.dispatch({ type: 'SET_TOOL', toolId: id });\n syncCursor();\n toolCbs.forEach((cb) => cb());\n },\n\n onToolChange: (cb) => {\n toolCbs.add(cb);\n return () => toolCbs.delete(cb);\n },\n\n registerTool: (tool) => {\n tools.set(tool.id, tool);\n return () => {\n tools.delete(tool.id);\n cursorSkins.delete(tool.id);\n };\n },\n\n setToolCursor: (id, skin) => {\n if (skin === null) cursorSkins.delete(id);\n else cursorSkins.set(id, skin);\n syncCursor();\n },\n\n registerHandler: (handler, options) => {\n handlers.push(handler);\n if (options?.source !== undefined) handlerSources.set(handler, options.source);\n return () => {\n const i = handlers.indexOf(handler);\n if (i >= 0) handlers.splice(i, 1);\n handlerSources.delete(handler);\n if (owner === handler) owner = null;\n };\n },\n\n setCursor: (token, cursor, priority = 0) => {\n if (cursor === null) claims.delete(token);\n else claims.set(token, { cursor, priority });\n syncCursor();\n },\n\n wouldClaimTouch: (sample) => {\n for (const h of eligible(sample.source)) if (h.claimsTouch?.(sample)) return true;\n return false;\n },\n\n dispatch: (sample) => {\n const nowOverPage = sample.page != null;\n if (nowOverPage !== overPage) {\n overPage = nowOverPage;\n syncCursor(); // crossing a page edge re-resolves the base cursor\n }\n if (sample.phase === 'down') {\n owner = null;\n for (const h of eligible(sample.source)) {\n if (h.onDown(sample)) {\n owner = h;\n break;\n }\n }\n } else if (sample.phase === 'move') {\n if (owner) owner.onMove?.(sample);\n else for (const h of eligible(sample.source)) h.onHover?.(sample);\n } else if (sample.phase === 'cancel') {\n // Abort, don't commit: navigation took the pointer (second finger →\n // pinch) or the system cancelled it. onUp is the fallback for handlers\n // that predate cancel — committing beats a stuck gesture.\n const o = owner;\n owner = null;\n if (o) (o.onCancel ?? o.onUp)?.call(o, sample);\n } else {\n owner?.onUp?.(sample);\n owner = null;\n }\n },\n };\n}\n","import type { InteractionAction, InteractionConfig, InteractionState } from './types';\n\nexport const initialInteractionState = (config: InteractionConfig): InteractionState => ({\n activeToolId: config.defaultTool ?? 'pointer',\n cursor: 'default',\n});\n\nexport const interactionReducer = (\n state: InteractionState,\n action: InteractionAction,\n): InteractionState => {\n switch (action.type) {\n case 'SET_TOOL':\n return state.activeToolId === action.toolId\n ? state\n : { ...state, activeToolId: action.toolId };\n case 'SET_CURSOR':\n return state.cursor === action.cursor ? state : { ...state, cursor: action.cursor };\n default:\n return state;\n }\n};\n","import { createCapabilityToken, type PageObjectNumber } from '@embedpdf/core';\nimport type { PageRotation, Point } from '@embedpdf/core-geometry';\n\nexport type ToolId = string;\nexport type Cursor = string;\n\nexport interface Modifiers {\n shift: boolean;\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n}\n\n/**\n * The single active arbiter of what the pointer does. `pan` and `pointer` are\n * built in; features add more (`highlight`, `square`, `redact`…) via\n * `registerTool`. A tool carries no behaviour itself — it turns on capability\n * TAGS that handlers opt into (`enables`), so tools compose features without\n * coupling to them.\n */\nexport interface Tool {\n id: ToolId;\n cursor: Cursor;\n /**\n * Cursor over the viewport's page GAPS. A tool's cursor answers \"what would\n * a click do here\" — and most tools act only on pages, so gaps fall back to\n * the neutral arrow (`'default'`). A tool that works anywhere (pan) declares\n * its own (`'grab'`). Hover claims still outrank both.\n */\n gapCursor?: Cursor;\n enables: ReadonlySet<string>;\n /**\n * TOUCH CONSENT, rung 1 — \"arming this tool is consent to create with a\n * finger\": while it is active, single-finger touch routes to the hub\n * wholesale (draw/markup/redact tools), and navigation moves to two\n * fingers — the drawing-app convention. Default false: a finger navigates\n * first, and only per-point claims ({@link InteractionHandler.claimsTouch})\n * carve out tool gestures.\n */\n touchDirect?: boolean;\n}\n\nexport type Phase = 'down' | 'move' | 'up' | 'cancel';\n\n/** The physical device class behind a sample — `PointerEvent.pointerType`.\n * Adapters fill it so handlers (and arbitration above the hub) can apply\n * modality policy: touch navigates first, pen/mouse are tool-first. */\nexport type PointerKind = 'mouse' | 'pen' | 'touch';\n\n/**\n * One normalized pointer event. `viewport` is the source container's px (the pan\n * handler uses the delta). `page` is the resolved page hit — its `pon` + content\n * point (y-down, PDF units, via the page's transform) — present when the pointer\n * is over a page, absent over gaps. A viewport source (Stage) resolves `page` per\n * event (so a drag can cross pages); a per-page source (PageView) always sets it.\n */\nexport interface PointerSample {\n phase: Phase;\n viewport: Point;\n /** `scale` is the hit page's VIEW px per content unit — handlers use it to\n * convert screen-px chrome settings into content-space tolerances, so grab\n * zones stay screen-constant across zoom. `rotation` is the hit page's TOTAL\n * display rotation (document /Rotate + view rotation) — per-event\n * environmental context like `scale`, for placement rules that depend on how\n * the page is DISPLAYED (an upright stamp). `zoom` is the page's zoom\n * RELATIVE to its 100% baseline (`transform.zoom` — dimensionless, 1 =\n * Acrobat's 100%), for zoom-relative policies (the `/F` NoZoom exemption);\n * distinct from `scale`, which is a units conversion. Absent when the\n * source can't say. */\n page?: {\n pon: PageObjectNumber;\n point: Point;\n scale?: number;\n rotation?: PageRotation;\n zoom?: number;\n };\n modifiers: Modifiers;\n /**\n * Click count for a `down` (1 = single, 2 = double, 3 = triple), from the\n * browser's native multi-click detection (`MouseEvent.detail`). Lets handlers\n * do word/line selection without re-implementing timing. Defaults to 1.\n */\n clickCount?: number;\n /** The device class that produced this sample (see {@link PointerKind}).\n * Absent when the source can't say — treat as 'mouse'. */\n pointerType?: PointerKind;\n /**\n * Present when the sample was SYNTHESIZED from a recognized gesture rather\n * than a raw press. 'long-press': a touch contact held still — the gesture\n * controller forwards it as a down (with `clickCount: 2`, so word-selection\n * keeps working unchanged), and this marker is the honest signal for\n * handlers that must tell a long-press from a genuine double-click\n * (haptics, pickup affordances). Absent on every raw pointer sample.\n */\n gesture?: 'long-press';\n /**\n * The LENS this sample came from — the stage plugin id the emitting surface\n * binding was attached to (a document may be viewed through several stage\n * lenses at once). Handlers registered with a matching `source` scope only\n * see their own lens's input, so one lens's drag can never be captured by\n * another lens's handler. Absent when the source doesn't say (custom\n * dispatchers, single-lens embeds) — such samples route to every handler.\n */\n source?: string;\n /**\n * Project this event onto a SPECIFIC page's content space, unclamped — valid\n * (and expected) outside the page's bounds. `page` answers \"what is under the\n * cursor\" and re-resolves per event; `project` answers \"where is the cursor\n * in MY page's frame\" for a gesture anchored to the page it started on (an\n * annotation drag sliding along the page edge). Null when the source can't\n * project onto that page (not laid out / a per-page source's foreign page).\n */\n project?(pon: PageObjectNumber): Point | null;\n}\n\n/**\n * A pointer handler contributed by a feature plugin. The ONE registration\n * mechanism (replacing v2's registerMode / registerHandlers / registerAlways /\n * enableForMode quartet): a handler declares which tools it's live under and a\n * priority; the hub routes each gesture to the first handler that captures it.\n */\nexport interface InteractionHandler {\n id: string;\n /** Higher wins the gesture. */\n priority: number;\n /** Usually `tool.enables.has('my-tag')`. */\n enabledFor(tool: Tool): boolean;\n /** Return true to CAPTURE: subsequent move/up route here until pointer-up. */\n onDown(sample: PointerSample): boolean;\n onMove?(sample: PointerSample): void;\n onUp?(sample: PointerSample): void;\n /**\n * The gesture was ABORTED, not completed — the pointer was cancelled by the\n * system, or navigation took it over (a second finger converted the drag\n * into a pinch). Discard the in-flight work instead of committing it (a\n * half-drawn shape, a mid-drag selection). Falls back to {@link onUp} when\n * absent, since committing is the lesser evil to a stuck gesture.\n */\n onCancel?(sample: PointerSample): void;\n /** Pointer moved with no active gesture — cursor feedback only. */\n onHover?(sample: PointerSample): void;\n /**\n * TOUCH CONSENT, rung 2 — \"the selected thing owns its drags\". Touch\n * navigation asks this BEFORE a contact is classified: return true and the\n * whole contact routes to the hub as a tool gesture (down/move/up) instead\n * of pan/pinch/tap. Implement it ONLY where the user has already narrowed\n * intent to this point — the annotation handler claims the selected\n * annotation's body and its handles, nothing else. A pure read: it must\n * not mutate anything (the down that follows does the mutating). Handlers\n * without it never claim, so plain surfaces keep navigating.\n */\n claimsTouch?(sample: PointerSample): boolean;\n}\n\n/**\n * A tool's runtime cursor skin: \"while THIS tool is armed, keyword X looks\n * like Y.\" Everything cursor-shaped in the hub speaks KEYWORDS — a tool\n * declares its base ('crosshair', 'copy'), hover claims name what is under\n * the pointer ('text' over text, 'move' over an annotation) — and the skin\n * restyles those keywords, typically as image cursors carrying the tool's\n * icon. Applied uniformly to the winning claim and to the declared base, so\n * same keyword = same meaning = same look. Unmapped keywords render as-is (a\n * foreign 'move' over an annotation drops the tool identity), and page gaps\n * are never skinned — the identity appears exactly where the action is\n * possible, and the skin can only restyle where the tool already acts.\n */\nexport type ToolCursorSkin = Record<Cursor, Cursor>;\n\nexport interface InteractionState {\n activeToolId: ToolId;\n cursor: Cursor;\n}\n\nexport type InteractionAction =\n | { type: 'SET_TOOL'; toolId: ToolId }\n | { type: 'SET_CURSOR'; cursor: Cursor };\n\nexport interface InteractionCapability {\n // ── selectors ──\n activeTool(): Tool;\n activeToolId(): ToolId;\n cursor(): Cursor;\n tools(): Tool[];\n // ── tool intents ──\n activateTool(id: ToolId): void;\n /** Fires after the active tool changes — lets a feature react (e.g. a markup\n * tool taking over the selection visual). Returns an unsubscribe fn. */\n onToolChange(cb: () => void): () => void;\n /**\n * Reskin a tool's cursor keywords at runtime — how an app gives the armed\n * tool an image cursor built from its own toolbar icon (`Cursor` is any CSS\n * cursor string, `url(data:…) x y, crosshair` included). See\n * {@link ToolCursorSkin} for what the map means. `null` removes the skin.\n */\n setToolCursor(id: ToolId, skin: ToolCursorSkin | null): void;\n // ── registries (return an unregister fn) ──\n registerTool(tool: Tool): () => void;\n /**\n * Register a pointer handler. `source` scopes it to ONE lens: the handler\n * then only sees samples stamped with that source (see\n * {@link PointerSample.source}) — mandatory for per-lens handlers like the\n * stage's pan-scroll, or two stages on one document would capture each\n * other's drags. UNSTAMPED samples still route everywhere (only a definite\n * mismatch filters), so custom dispatchers keep working.\n */\n registerHandler(handler: InteractionHandler, options?: { source?: string }): () => void;\n // ── cursor claim stack (highest priority wins; null clears the token) ──\n setCursor(token: string, cursor: Cursor | null, priority?: number): void;\n // ── pointer ingress: the adapter calls this for every normalized event ──\n dispatch(sample: PointerSample): void;\n /**\n * The touch-arbitration pre-flight: would any eligible handler claim a\n * contact at this sample ({@link InteractionHandler.claimsTouch})? Walked\n * in the same priority order `dispatch` uses, first claim wins. Pure —\n * nothing is captured or mutated; the gesture controller calls it at\n * touch-down to route the contact (tool vs navigation), then dispatches\n * normally.\n */\n wouldClaimTouch(sample: PointerSample): boolean;\n}\n\nexport const InteractionToken = createCapabilityToken<InteractionCapability>('interaction', {\n hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list`,\n});\n\n/**\n * Resolve a sample against a gesture's HOME page. Page-anchored gestures track\n * the page they started on even when the cursor wanders off it — `s.page`\n * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so\n * prefer the source's unclamped projection and fall back to the page hit only\n * when it is the same page. Null → this sample can't speak for the home page.\n * Shared by every gesture owner (annotation edit/draw, form placement).\n */\nexport const samplePointOn = (s: PointerSample, pon: PageObjectNumber): Point | null =>\n s.project?.(pon) ?? (s.page?.pon === pon ? s.page.point : null);\n\nexport interface InteractionConfig {\n /** Tool active when a document opens. Default `'pointer'`. */\n defaultTool?: ToolId;\n}\n","import { definePlugin } from '@embedpdf/core';\nimport { createInteractionCapability } from './capability';\nimport { initialInteractionState, interactionReducer } from './reducer';\nimport { InteractionToken } from './types';\nimport type {\n InteractionAction,\n InteractionCapability,\n InteractionConfig,\n InteractionState,\n Tool,\n} from './types';\n\n/**\n * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a\n * redact tool…). `enables` is the composition seam:\n * pointer → text selection + annotation editing + annotation marquee selection\n * pan → scrolling (contributed by Stage) + annotation editing, NO text select\n *\n * Both carry `form-fill`: filling a form is the RESTING state of a viewer\n * (Acrobat's hand tool fills forms too), so widgets are fill-controls under the\n * default tools and only become geometry-editable under a form-design tool.\n * Both carry `link-nav` for the same reason: links navigate under the default\n * tools (Acrobat behaviour) and only become geometry-editable under the link\n * tool. Tags are opaque to the hub — without the form/link plugins they're inert.\n */\nexport const builtinTools = (): Tool[] => [\n {\n id: 'pointer',\n cursor: 'default',\n enables: new Set([\n 'text-select',\n 'annotation-edit',\n 'annotation-marquee',\n 'form-fill',\n 'link-nav',\n ]),\n },\n {\n id: 'pan',\n cursor: 'grab',\n gapCursor: 'grab', // pan works anywhere — the open hand doesn't stop at page edges\n enables: new Set(['scroll', 'annotation-edit', 'form-fill', 'link-nav']),\n },\n];\n\n/**\n * The interaction hub plugin — document-scoped, depends on nothing. Every feature\n * plugin (selection, annotation, forms, redaction) `requires` this token; Stage\n * `optional`-ly contributes a scroll handler. Works with `<Stage>` or a standalone\n * `<PageView>` — it only routes page-space pointer samples.\n */\nexport const interactionPlugin = (config: InteractionConfig = {}) =>\n definePlugin<InteractionState, InteractionAction, InteractionCapability>({\n id: 'interaction',\n token: InteractionToken,\n scope: 'document',\n initialState: () => initialInteractionState(config),\n reduce: interactionReducer,\n capability: (ctx) => createInteractionCapability(ctx, builtinTools()),\n });\n","/**\n * Platform feedback (haptics) — the OUTPUT half of the interaction seam:\n * pointers come in, feedback goes back out to the device.\n *\n * ONE workspace-scoped provider, MANY consumers: any plugin lists\n * {@link FeedbackToken} as an optional dependency and calls the capability at\n * its semantic moments (the selection handler on a long-press word-select; an\n * annotation pickup or a snap later). The plugin itself stays DOM-free — the\n * PROVIDER is injected from outside (`@embedpdf/web` ships `vibrationFeedback`\n * and a WKWebView bridge; native shells bring their own), exactly like the\n * stage's Scheduler seam: host dependencies enter through explicit injection,\n * never a hidden global.\n *\n * The vocabulary is deliberately the PLATFORM's haptic taxonomy — iOS's three\n * generator families, which Android mirrors in `HapticFeedbackConstants` and\n * the web approximates with vibration patterns — not app vocabulary. A verb\n * belongs here only if a provider would map it to a physically different\n * output; call-site semantics (\"word selected\", \"annotation picked up\") pick a\n * family, they never add one.\n */\nimport { createCapabilityToken, definePlugin } from '@embedpdf/core';\n\nexport interface PlatformFeedback {\n /**\n * The featherweight \"selection is changing\" tick\n * (`UISelectionFeedbackGenerator`) — tuned for rapid repetition: a\n * long-press engaging a word, a handle drag ticking across boundaries.\n */\n selection(): void;\n /** A physical-collision bump (`UIImpactFeedbackGenerator`): something was\n * picked up, snapped, or docked. Default weight 'light'. */\n impact(weight?: 'light' | 'medium' | 'heavy'): void;\n /** An outcome announcement (`UINotificationFeedbackGenerator`). */\n notify(kind: 'success' | 'warning' | 'error'): void;\n}\n\nexport const FeedbackToken = createCapabilityToken<PlatformFeedback>('feedback');\n\n/** No provider → every call is a cheap no-op; consumers never branch. */\nconst NOOP: PlatformFeedback = { selection() {}, impact() {}, notify() {} };\n\nexport interface FeedbackPluginOptions {\n /** The platform's feedback implementation. Omit for silence (headless,\n * tests, or a \"haptics off\" preference) — consumers keep working. */\n provider?: PlatformFeedback;\n}\n\n/** The plugin is stateless; the action type exists only to satisfy the\n * reducer contract (nothing ever dispatches it). */\ntype FeedbackAction = { type: 'feedback/noop' };\n\n/**\n * Register the workspace's ONE feedback provider. Stateless: the capability IS\n * the provider (or the no-op).\n */\nexport const feedbackPlugin = (options: FeedbackPluginOptions = {}) =>\n definePlugin<Record<string, never>, FeedbackAction, PlatformFeedback>({\n id: 'feedback',\n scope: 'workspace',\n token: FeedbackToken,\n initialState: () => ({}),\n reduce: (state) => state,\n capability: () => options.provider ?? NOOP,\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,4BACd,KACA,cACuB;CACvB,MAAM,wBAAQ,IAAI,IAAkB;CACpC,KAAK,MAAM,KAAK,cAAc,MAAM,IAAI,EAAE,IAAI,CAAC;CAC/C,MAAM,WAAiC,CAAC;CACxC,MAAM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B;EAAa;CAAU,CAAC;AACzE,CACF;;;;;;;AAQA,MAAa,qBAAqB,SAA4B,CAAC,OAAA,GAAA,eAAA,aAAA,CACY;CACvE,IAAI;CACJ,OAAO;CACP,OAAO;CACP,oBAAoB,wBAAwB,MAAM;CAClD,QAAQ;CACR,aAAa,QAAQ,4BAA4B,KAAK,aAAa,CAAC;AACtE,CAAC;;;;;;;;;;;;;;;;;;;;;;;ACvBH,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAAwD,UAAU;;AAG/E,MAAM,OAAyB;CAAE,YAAY,CAAC;CAAG,SAAS,CAAC;CAAG,SAAS,CAAC;AAAE;;;;;AAgB1E,MAAa,kBAAkB,UAAiC,CAAC,OAAA,GAAA,eAAA,aAAA,CACO;CACpE,IAAI;CACJ,OAAO;CACP,OAAO;CACP,qBAAqB,CAAC;CACtB,SAAS,UAAU;CACnB,kBAAkB,QAAQ,YAAY;AACxC,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["InteractionToken","FeedbackToken"],"sources":["../src/capability.ts","../src/reducer.ts","../src/interaction.plugin.ts","../src/feedback.ts"],"sourcesContent":["import type { PluginContext } from '@embedpdf/core';\nimport type {\n Cursor,\n InteractionAction,\n InteractionCapability,\n InteractionHandler,\n InteractionState,\n Tool,\n ToolCursorSkin,\n ToolId,\n} from './types';\n\ninterface Claim {\n cursor: Cursor;\n priority: number;\n}\n\n/**\n * The interaction hub. Tools + handlers + the captured-gesture owner + cursor\n * claims live in this closure (runtime registries, not serializable state); the\n * reducer state holds only the active tool id and the resolved cursor, so the UI\n * can react to them. The router (`dispatch`) is the heart: on down, the first\n * eligible handler (by priority) to return true OWNS the gesture; move/up route\n * to it; with no owner, move is hover (cursor feedback).\n *\n * Cursor arbitration, top to bottom: the highest-priority CLAIM (hover feedback\n * — 'move' over an annotation, 'text' over text) → over a page, the tool's\n * declared cursor → over a gap, the tool's `gapCursor` (default the neutral\n * arrow). The winning KEYWORD (claim or base, never gap) is then restyled\n * through the armed tool's skin when it maps that keyword. One resolver, so an\n * image cursor can never shadow hover feedback or outlive the page under the\n * pointer.\n */\nexport function createInteractionCapability(\n ctx: PluginContext<InteractionState, InteractionAction>,\n builtinTools: Tool[],\n): InteractionCapability {\n const tools = new Map<ToolId, Tool>();\n for (const t of builtinTools) tools.set(t.id, t);\n const handlers: InteractionHandler[] = [];\n const claims = new Map<string, Claim>();\n const cursorSkins = new Map<ToolId, ToolCursorSkin>();\n const toolCbs = new Set<() => void>();\n let owner: InteractionHandler | null = null;\n // Whether the last dispatched sample hit a page — the base cursor only\n // applies where the tool can act; over gaps it falls back to `gapCursor`.\n let overPage = false;\n\n const toolOf = (id: ToolId): Tool =>\n tools.get(id) ?? { id, cursor: 'default', enables: new Set() };\n const active = (): Tool => toolOf(ctx.getState().activeToolId);\n\n const resolveCursor = (): Cursor => {\n let top: Claim | null = null;\n for (const c of claims.values()) if (!top || c.priority > top.priority) top = c;\n const tool = active();\n const skin = cursorSkins.get(tool.id);\n // The cursor keeps its MEANING (a keyword — the winning claim's, else the\n // tool's declared base); the skin may restyle that keyword in the armed\n // tool's identity (an I-beam + tool icon over text). Unmapped keywords\n // render as-is — a foreign affordance drops the tool identity — and gaps\n // resolve before the skin: identity only where the action is possible.\n if (top) return skin?.[top.cursor] ?? top.cursor;\n if (!overPage) return tool.gapCursor ?? 'default';\n return skin?.[tool.cursor] ?? tool.cursor;\n };\n const syncCursor = (): void => {\n const next = resolveCursor();\n if (next !== ctx.getState().cursor) ctx.dispatch({ type: 'SET_CURSOR', cursor: next });\n };\n\n // Lens scoping: a handler registered with a `source` only sees samples\n // stamped with it. Filtering is on DEFINITE mismatch only — an unstamped\n // sample (custom dispatcher, single-lens embed) still routes everywhere.\n const handlerSources = new Map<InteractionHandler, string>();\n const eligible = (source?: string): InteractionHandler[] => {\n const tool = active();\n return handlers\n .filter((h) => {\n const hs = handlerSources.get(h);\n return hs === undefined || source === undefined || hs === source;\n })\n .filter((h) => h.enabledFor(tool))\n .sort((a, b) => b.priority - a.priority);\n };\n\n return {\n activeTool: active,\n activeToolId: () => ctx.getState().activeToolId,\n cursor: () => ctx.getState().cursor,\n tools: () => [...tools.values()],\n\n activateTool: (id) => {\n if (!tools.has(id)) throw new Error(`[interaction] unknown tool '${id}'`);\n owner = null;\n claims.clear(); // drop the previous tool's hover claims; handlers re-claim on next hover\n ctx.dispatch({ type: 'SET_TOOL', toolId: id });\n syncCursor();\n toolCbs.forEach((cb) => cb());\n },\n\n onToolChange: (cb) => {\n toolCbs.add(cb);\n return () => toolCbs.delete(cb);\n },\n\n registerTool: (tool) => {\n tools.set(tool.id, tool);\n return () => {\n tools.delete(tool.id);\n cursorSkins.delete(tool.id);\n };\n },\n\n setToolCursor: (id, skin) => {\n if (skin === null) cursorSkins.delete(id);\n else cursorSkins.set(id, skin);\n syncCursor();\n },\n\n registerHandler: (handler, options) => {\n handlers.push(handler);\n if (options?.source !== undefined) handlerSources.set(handler, options.source);\n return () => {\n const i = handlers.indexOf(handler);\n if (i >= 0) handlers.splice(i, 1);\n handlerSources.delete(handler);\n if (owner === handler) owner = null;\n };\n },\n\n setCursor: (token, cursor, priority = 0) => {\n if (cursor === null) claims.delete(token);\n else claims.set(token, { cursor, priority });\n syncCursor();\n },\n\n wouldClaimTouch: (sample) => {\n for (const h of eligible(sample.source)) if (h.claimsTouch?.(sample)) return true;\n return false;\n },\n\n dispatch: (sample) => {\n const nowOverPage = sample.page != null;\n if (nowOverPage !== overPage) {\n overPage = nowOverPage;\n syncCursor(); // crossing a page edge re-resolves the base cursor\n }\n if (sample.phase === 'down') {\n owner = null;\n for (const h of eligible(sample.source)) {\n if (h.onDown(sample)) {\n owner = h;\n break;\n }\n }\n } else if (sample.phase === 'move') {\n if (owner) owner.onMove?.(sample);\n else for (const h of eligible(sample.source)) h.onHover?.(sample);\n } else if (sample.phase === 'cancel') {\n // Abort, don't commit: navigation took the pointer (second finger →\n // pinch) or the system cancelled it. onUp is the fallback for handlers\n // that predate cancel — committing beats a stuck gesture.\n const o = owner;\n owner = null;\n if (o) (o.onCancel ?? o.onUp)?.call(o, sample);\n } else {\n owner?.onUp?.(sample);\n owner = null;\n }\n },\n };\n}\n","import type { InteractionAction, InteractionConfig, InteractionState } from './types';\n\nexport const initialInteractionState = (config: InteractionConfig): InteractionState => ({\n activeToolId: config.defaultTool ?? 'pointer',\n cursor: 'default',\n});\n\nexport const interactionReducer = (\n state: InteractionState,\n action: InteractionAction,\n): InteractionState => {\n switch (action.type) {\n case 'SET_TOOL':\n return state.activeToolId === action.toolId\n ? state\n : { ...state, activeToolId: action.toolId };\n case 'SET_CURSOR':\n return state.cursor === action.cursor ? state : { ...state, cursor: action.cursor };\n default:\n return state;\n }\n};\n","import { definePlugin } from '@embedpdf/core';\nimport { createInteractionCapability } from './capability';\nimport { initialInteractionState, interactionReducer } from './reducer';\nimport { InteractionToken } from './types';\nimport type {\n InteractionAction,\n InteractionCapability,\n InteractionConfig,\n InteractionState,\n Tool,\n} from './types';\n\n/**\n * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a\n * redact tool…). `enables` is the composition seam:\n * pointer → text selection + annotation editing + annotation marquee selection\n * pan → scrolling (contributed by Stage) + annotation editing, NO text select\n *\n * Both carry `form-fill`: filling a form is the RESTING state of a viewer\n * (Acrobat's hand tool fills forms too), so widgets are fill-controls under the\n * default tools and only become geometry-editable under a form-design tool.\n * Both carry `link-nav` for the same reason: links navigate under the default\n * tools (Acrobat behaviour) and only become geometry-editable under the link\n * tool. Tags are opaque to the hub — without the form/link plugins they're inert.\n */\nexport const builtinTools = (): Tool[] => [\n {\n id: 'pointer',\n cursor: 'default',\n enables: new Set([\n 'text-select',\n 'annotation-edit',\n 'annotation-marquee',\n 'form-fill',\n 'link-nav',\n ]),\n },\n {\n id: 'pan',\n cursor: 'grab',\n gapCursor: 'grab', // pan works anywhere — the open hand doesn't stop at page edges\n enables: new Set(['scroll', 'annotation-edit', 'form-fill', 'link-nav']),\n },\n];\n\n/**\n * The interaction hub plugin — document-scoped, depends on nothing. Every feature\n * plugin (selection, annotation, forms, redaction) `requires` this token; Stage\n * `optional`-ly contributes a scroll handler. Works with `<Stage>` or a standalone\n * `<PageView>` — it only routes page-space pointer samples.\n */\nexport const interactionPlugin = (config: InteractionConfig = {}) =>\n definePlugin<InteractionState, InteractionAction, InteractionCapability>({\n id: 'interaction',\n token: InteractionToken,\n scope: 'document',\n initialState: () => initialInteractionState(config),\n reduce: interactionReducer,\n capability: (ctx) => createInteractionCapability(ctx, builtinTools()),\n });\n","/**\n * Platform feedback (haptics) — the OUTPUT half of the interaction seam:\n * pointers come in, feedback goes back out to the device.\n *\n * ONE workspace-scoped provider, MANY consumers: any plugin lists\n * {@link FeedbackToken} as an optional dependency and calls the capability at\n * its semantic moments (the selection handler on a long-press word-select; an\n * annotation pickup or a snap later). The plugin itself stays DOM-free — the\n * PROVIDER is injected from outside (`@embedpdf/web` ships `vibrationFeedback`\n * and a WKWebView bridge; native shells bring their own), exactly like the\n * stage's Scheduler seam: host dependencies enter through explicit injection,\n * never a hidden global.\n *\n * The vocabulary is deliberately the PLATFORM's haptic taxonomy — iOS's three\n * generator families, which Android mirrors in `HapticFeedbackConstants` and\n * the web approximates with vibration patterns — not app vocabulary. A verb\n * belongs here only if a provider would map it to a physically different\n * output; call-site semantics (\"word selected\", \"annotation picked up\") pick a\n * family, they never add one.\n */\nimport { definePlugin } from '@embedpdf/core';\n\nimport { FeedbackToken } from './feedback.types';\nimport type { FeedbackPluginOptions, PlatformFeedback } from './feedback.types';\n\n/** No provider → every call is a cheap no-op; consumers never branch. */\nconst NOOP: PlatformFeedback = { selection() {}, impact() {}, notify() {} };\n\n/** The plugin is stateless; the action type exists only to satisfy the\n * reducer contract (nothing ever dispatches it). */\ntype FeedbackAction = { type: 'feedback/noop' };\n\n/**\n * Register the workspace's ONE feedback provider. Stateless: the capability IS\n * the provider (or the no-op).\n */\nexport const feedbackPlugin = (options: FeedbackPluginOptions = {}) =>\n definePlugin<Record<string, never>, FeedbackAction, PlatformFeedback>({\n id: 'feedback',\n scope: 'workspace',\n token: FeedbackToken,\n initialState: () => ({}),\n reduce: (state) => state,\n capability: () => options.provider ?? NOOP,\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,4BACd,KACA,cACuB;CACvB,MAAM,wBAAQ,IAAI,IAAkB;CACpC,KAAK,MAAM,KAAK,cAAc,MAAM,IAAI,EAAE,IAAI,CAAC;CAC/C,MAAM,WAAiC,CAAC;CACxC,MAAM,yBAAS,IAAI,IAAmB;CACtC,MAAM,8BAAc,IAAI,IAA4B;CACpD,MAAM,0BAAU,IAAI,IAAgB;CACpC,IAAI,QAAmC;CAGvC,IAAI,WAAW;CAEf,MAAM,UAAU,OACd,MAAM,IAAI,EAAE,KAAK;EAAE;EAAI,QAAQ;EAAW,yBAAS,IAAI,IAAI;CAAE;CAC/D,MAAM,eAAqB,OAAO,IAAI,SAAS,CAAC,CAAC,YAAY;CAE7D,MAAM,sBAA8B;EAClC,IAAI,MAAoB;EACxB,KAAK,MAAM,KAAK,OAAO,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,IAAI,UAAU,MAAM;EAC9E,MAAM,OAAO,OAAO;EACpB,MAAM,OAAO,YAAY,IAAI,KAAK,EAAE;EAMpC,IAAI,KAAK,OAAO,OAAO,IAAI,WAAW,IAAI;EAC1C,IAAI,CAAC,UAAU,OAAO,KAAK,aAAa;EACxC,OAAO,OAAO,KAAK,WAAW,KAAK;CACrC;CACA,MAAM,mBAAyB;EAC7B,MAAM,OAAO,cAAc;EAC3B,IAAI,SAAS,IAAI,SAAS,CAAC,CAAC,QAAQ,IAAI,SAAS;GAAE,MAAM;GAAc,QAAQ;EAAK,CAAC;CACvF;CAKA,MAAM,iCAAiB,IAAI,IAAgC;CAC3D,MAAM,YAAY,WAA0C;EAC1D,MAAM,OAAO,OAAO;EACpB,OAAO,SACJ,QAAQ,MAAM;GACb,MAAM,KAAK,eAAe,IAAI,CAAC;GAC/B,OAAO,OAAO,KAAA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;CACF,CAAC;AACH,GACA;CACE,IAAI;CACJ,QAAQ;CACR,WAAW;CACX,yBAAS,IAAI,IAAI;EAAC;EAAU;EAAmB;EAAa;CAAU,CAAC;AACzE,CACF;;;;;;;AAQA,MAAa,qBAAqB,SAA4B,CAAC,OAAA,GAAA,eAAA,aAAA,CACY;CACvE,IAAI;CACJ,OAAOA,iBAAAA;CACP,OAAO;CACP,oBAAoB,wBAAwB,MAAM;CAClD,QAAQ;CACR,aAAa,QAAQ,4BAA4B,KAAK,aAAa,CAAC;AACtE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;ACjCH,MAAM,OAAyB;CAAE,YAAY,CAAC;CAAG,SAAS,CAAC;CAAG,SAAS,CAAC;AAAE;;;;;AAU1E,MAAa,kBAAkB,UAAiC,CAAC,OAAA,GAAA,eAAA,aAAA,CACO;CACpE,IAAI;CACJ,OAAO;CACP,OAAOC,iBAAAA;CACP,qBAAqB,CAAC;CACtB,SAAS,UAAU;CACnB,kBAAkB,QAAQ,YAAY;AACxC,CAAC"}
package/dist/index.d.cts CHANGED
@@ -1,229 +1,5 @@
1
- import { PageObjectNumber, PluginContext } from "@embedpdf/core";
2
- import { PageRotation, Point } from "@embedpdf/core-geometry";
3
- //#region src/types.d.ts
4
- type ToolId = string;
5
- type Cursor = string;
6
- interface Modifiers {
7
- shift: boolean;
8
- alt: boolean;
9
- ctrl: boolean;
10
- meta: boolean;
11
- }
12
- /**
13
- * The single active arbiter of what the pointer does. `pan` and `pointer` are
14
- * built in; features add more (`highlight`, `square`, `redact`…) via
15
- * `registerTool`. A tool carries no behaviour itself — it turns on capability
16
- * TAGS that handlers opt into (`enables`), so tools compose features without
17
- * coupling to them.
18
- */
19
- interface Tool {
20
- id: ToolId;
21
- cursor: Cursor;
22
- /**
23
- * Cursor over the viewport's page GAPS. A tool's cursor answers "what would
24
- * a click do here" — and most tools act only on pages, so gaps fall back to
25
- * the neutral arrow (`'default'`). A tool that works anywhere (pan) declares
26
- * its own (`'grab'`). Hover claims still outrank both.
27
- */
28
- gapCursor?: Cursor;
29
- enables: ReadonlySet<string>;
30
- /**
31
- * TOUCH CONSENT, rung 1 — "arming this tool is consent to create with a
32
- * finger": while it is active, single-finger touch routes to the hub
33
- * wholesale (draw/markup/redact tools), and navigation moves to two
34
- * fingers — the drawing-app convention. Default false: a finger navigates
35
- * first, and only per-point claims ({@link InteractionHandler.claimsTouch})
36
- * carve out tool gestures.
37
- */
38
- touchDirect?: boolean;
39
- }
40
- type Phase = 'down' | 'move' | 'up' | 'cancel';
41
- /** The physical device class behind a sample — `PointerEvent.pointerType`.
42
- * Adapters fill it so handlers (and arbitration above the hub) can apply
43
- * modality policy: touch navigates first, pen/mouse are tool-first. */
44
- type PointerKind = 'mouse' | 'pen' | 'touch';
45
- /**
46
- * One normalized pointer event. `viewport` is the source container's px (the pan
47
- * handler uses the delta). `page` is the resolved page hit — its `pon` + content
48
- * point (y-down, PDF units, via the page's transform) — present when the pointer
49
- * is over a page, absent over gaps. A viewport source (Stage) resolves `page` per
50
- * event (so a drag can cross pages); a per-page source (PageView) always sets it.
51
- */
52
- interface PointerSample {
53
- phase: Phase;
54
- viewport: Point;
55
- /** `scale` is the hit page's VIEW px per content unit — handlers use it to
56
- * convert screen-px chrome settings into content-space tolerances, so grab
57
- * zones stay screen-constant across zoom. `rotation` is the hit page's TOTAL
58
- * display rotation (document /Rotate + view rotation) — per-event
59
- * environmental context like `scale`, for placement rules that depend on how
60
- * the page is DISPLAYED (an upright stamp). `zoom` is the page's zoom
61
- * RELATIVE to its 100% baseline (`transform.zoom` — dimensionless, 1 =
62
- * Acrobat's 100%), for zoom-relative policies (the `/F` NoZoom exemption);
63
- * distinct from `scale`, which is a units conversion. Absent when the
64
- * source can't say. */
65
- page?: {
66
- pon: PageObjectNumber;
67
- point: Point;
68
- scale?: number;
69
- rotation?: PageRotation;
70
- zoom?: number;
71
- };
72
- modifiers: Modifiers;
73
- /**
74
- * Click count for a `down` (1 = single, 2 = double, 3 = triple), from the
75
- * browser's native multi-click detection (`MouseEvent.detail`). Lets handlers
76
- * do word/line selection without re-implementing timing. Defaults to 1.
77
- */
78
- clickCount?: number;
79
- /** The device class that produced this sample (see {@link PointerKind}).
80
- * Absent when the source can't say — treat as 'mouse'. */
81
- pointerType?: PointerKind;
82
- /**
83
- * Present when the sample was SYNTHESIZED from a recognized gesture rather
84
- * than a raw press. 'long-press': a touch contact held still — the gesture
85
- * controller forwards it as a down (with `clickCount: 2`, so word-selection
86
- * keeps working unchanged), and this marker is the honest signal for
87
- * handlers that must tell a long-press from a genuine double-click
88
- * (haptics, pickup affordances). Absent on every raw pointer sample.
89
- */
90
- gesture?: 'long-press';
91
- /**
92
- * The LENS this sample came from — the stage plugin id the emitting surface
93
- * binding was attached to (a document may be viewed through several stage
94
- * lenses at once). Handlers registered with a matching `source` scope only
95
- * see their own lens's input, so one lens's drag can never be captured by
96
- * another lens's handler. Absent when the source doesn't say (custom
97
- * dispatchers, single-lens embeds) — such samples route to every handler.
98
- */
99
- source?: string;
100
- /**
101
- * Project this event onto a SPECIFIC page's content space, unclamped — valid
102
- * (and expected) outside the page's bounds. `page` answers "what is under the
103
- * cursor" and re-resolves per event; `project` answers "where is the cursor
104
- * in MY page's frame" for a gesture anchored to the page it started on (an
105
- * annotation drag sliding along the page edge). Null when the source can't
106
- * project onto that page (not laid out / a per-page source's foreign page).
107
- */
108
- project?(pon: PageObjectNumber): Point | null;
109
- }
110
- /**
111
- * A pointer handler contributed by a feature plugin. The ONE registration
112
- * mechanism (replacing v2's registerMode / registerHandlers / registerAlways /
113
- * enableForMode quartet): a handler declares which tools it's live under and a
114
- * priority; the hub routes each gesture to the first handler that captures it.
115
- */
116
- interface InteractionHandler {
117
- id: string;
118
- /** Higher wins the gesture. */
119
- priority: number;
120
- /** Usually `tool.enables.has('my-tag')`. */
121
- enabledFor(tool: Tool): boolean;
122
- /** Return true to CAPTURE: subsequent move/up route here until pointer-up. */
123
- onDown(sample: PointerSample): boolean;
124
- onMove?(sample: PointerSample): void;
125
- onUp?(sample: PointerSample): void;
126
- /**
127
- * The gesture was ABORTED, not completed — the pointer was cancelled by the
128
- * system, or navigation took it over (a second finger converted the drag
129
- * into a pinch). Discard the in-flight work instead of committing it (a
130
- * half-drawn shape, a mid-drag selection). Falls back to {@link onUp} when
131
- * absent, since committing is the lesser evil to a stuck gesture.
132
- */
133
- onCancel?(sample: PointerSample): void;
134
- /** Pointer moved with no active gesture — cursor feedback only. */
135
- onHover?(sample: PointerSample): void;
136
- /**
137
- * TOUCH CONSENT, rung 2 — "the selected thing owns its drags". Touch
138
- * navigation asks this BEFORE a contact is classified: return true and the
139
- * whole contact routes to the hub as a tool gesture (down/move/up) instead
140
- * of pan/pinch/tap. Implement it ONLY where the user has already narrowed
141
- * intent to this point — the annotation handler claims the selected
142
- * annotation's body and its handles, nothing else. A pure read: it must
143
- * not mutate anything (the down that follows does the mutating). Handlers
144
- * without it never claim, so plain surfaces keep navigating.
145
- */
146
- claimsTouch?(sample: PointerSample): boolean;
147
- }
148
- /**
149
- * A tool's runtime cursor skin: "while THIS tool is armed, keyword X looks
150
- * like Y." Everything cursor-shaped in the hub speaks KEYWORDS — a tool
151
- * declares its base ('crosshair', 'copy'), hover claims name what is under
152
- * the pointer ('text' over text, 'move' over an annotation) — and the skin
153
- * restyles those keywords, typically as image cursors carrying the tool's
154
- * icon. Applied uniformly to the winning claim and to the declared base, so
155
- * same keyword = same meaning = same look. Unmapped keywords render as-is (a
156
- * foreign 'move' over an annotation drops the tool identity), and page gaps
157
- * are never skinned — the identity appears exactly where the action is
158
- * possible, and the skin can only restyle where the tool already acts.
159
- */
160
- type ToolCursorSkin = Record<Cursor, Cursor>;
161
- interface InteractionState {
162
- activeToolId: ToolId;
163
- cursor: Cursor;
164
- }
165
- type InteractionAction = {
166
- type: 'SET_TOOL';
167
- toolId: ToolId;
168
- } | {
169
- type: 'SET_CURSOR';
170
- cursor: Cursor;
171
- };
172
- interface InteractionCapability {
173
- activeTool(): Tool;
174
- activeToolId(): ToolId;
175
- cursor(): Cursor;
176
- tools(): Tool[];
177
- activateTool(id: ToolId): void;
178
- /** Fires after the active tool changes — lets a feature react (e.g. a markup
179
- * tool taking over the selection visual). Returns an unsubscribe fn. */
180
- onToolChange(cb: () => void): () => void;
181
- /**
182
- * Reskin a tool's cursor keywords at runtime — how an app gives the armed
183
- * tool an image cursor built from its own toolbar icon (`Cursor` is any CSS
184
- * cursor string, `url(data:…) x y, crosshair` included). See
185
- * {@link ToolCursorSkin} for what the map means. `null` removes the skin.
186
- */
187
- setToolCursor(id: ToolId, skin: ToolCursorSkin | null): void;
188
- registerTool(tool: Tool): () => void;
189
- /**
190
- * Register a pointer handler. `source` scopes it to ONE lens: the handler
191
- * then only sees samples stamped with that source (see
192
- * {@link PointerSample.source}) — mandatory for per-lens handlers like the
193
- * stage's pan-scroll, or two stages on one document would capture each
194
- * other's drags. UNSTAMPED samples still route everywhere (only a definite
195
- * mismatch filters), so custom dispatchers keep working.
196
- */
197
- registerHandler(handler: InteractionHandler, options?: {
198
- source?: string;
199
- }): () => void;
200
- setCursor(token: string, cursor: Cursor | null, priority?: number): void;
201
- dispatch(sample: PointerSample): void;
202
- /**
203
- * The touch-arbitration pre-flight: would any eligible handler claim a
204
- * contact at this sample ({@link InteractionHandler.claimsTouch})? Walked
205
- * in the same priority order `dispatch` uses, first claim wins. Pure —
206
- * nothing is captured or mutated; the gesture controller calls it at
207
- * touch-down to route the contact (tool vs navigation), then dispatches
208
- * normally.
209
- */
210
- wouldClaimTouch(sample: PointerSample): boolean;
211
- }
212
- declare const InteractionToken: import("@embedpdf/core").CapabilityToken<InteractionCapability>;
213
- /**
214
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
215
- * the page they started on even when the cursor wanders off it — `s.page`
216
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
217
- * prefer the source's unclamped projection and fall back to the page hit only
218
- * when it is the same page. Null → this sample can't speak for the home page.
219
- * Shared by every gesture owner (annotation edit/draw, form placement).
220
- */
221
- declare const samplePointOn: (s: PointerSample, pon: PageObjectNumber) => Point | null;
222
- interface InteractionConfig {
223
- /** Tool active when a document opens. Default `'pointer'`. */
224
- defaultTool?: ToolId;
225
- }
226
- //#endregion
1
+ import { _ as samplePointOn, a as InteractionAction, c as InteractionHandler, d as Modifiers, f as Phase, g as ToolId, h as Tool, i as Cursor, l as InteractionState, m as PointerSample, n as FeedbackToken, o as InteractionCapability, p as PointerKind, r as PlatformFeedback, s as InteractionConfig, t as FeedbackPluginOptions, u as InteractionToken } from "./contract-F3gsFtSf.cjs";
2
+ import { PluginContext } from "@embedpdf/core";
227
3
  //#region src/interaction.plugin.d.ts
228
4
  /**
229
5
  * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a
@@ -271,25 +47,6 @@ declare const initialInteractionState: (config: InteractionConfig) => Interactio
271
47
  declare const interactionReducer: (state: InteractionState, action: InteractionAction) => InteractionState;
272
48
  //#endregion
273
49
  //#region src/feedback.d.ts
274
- interface PlatformFeedback {
275
- /**
276
- * The featherweight "selection is changing" tick
277
- * (`UISelectionFeedbackGenerator`) — tuned for rapid repetition: a
278
- * long-press engaging a word, a handle drag ticking across boundaries.
279
- */
280
- selection(): void;
281
- /** A physical-collision bump (`UIImpactFeedbackGenerator`): something was
282
- * picked up, snapped, or docked. Default weight 'light'. */
283
- impact(weight?: 'light' | 'medium' | 'heavy'): void;
284
- /** An outcome announcement (`UINotificationFeedbackGenerator`). */
285
- notify(kind: 'success' | 'warning' | 'error'): void;
286
- }
287
- declare const FeedbackToken: import("@embedpdf/core").CapabilityToken<PlatformFeedback>;
288
- interface FeedbackPluginOptions {
289
- /** The platform's feedback implementation. Omit for silence (headless,
290
- * tests, or a "haptics off" preference) — consumers keep working. */
291
- provider?: PlatformFeedback;
292
- }
293
50
  /** The plugin is stateless; the action type exists only to satisfy the
294
51
  * reducer contract (nothing ever dispatches it). */
295
52
  type FeedbackAction = {