@embedpdf/plugin-interaction 3.0.0-next.13 → 3.0.0-next.15

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.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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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a,kBAAkB,UAAiC,CAAC,MAC/D,aAAsE;CACpE,IAAI;CACJ,OAAO;CACP,OAAO;CACP,qBAAqB,CAAC;CACtB,SAAS,UAAU;CACnB,kBAAkB,QAAQ,YAAY;AACxC,CAAC"}
1
+ {"version":3,"file":"index.js","names":["InteractionToken"],"sources":["../src/model.ts","../src/controller.ts","../src/interaction.plugin.ts","../src/state.ts","../src/feedback.ts"],"sourcesContent":["/**\n * The interaction state: the active tool, the stack `pushTool` saves, and the\n * resolved cursor, so UI can react. Tools, handlers and cursor claims are\n * registries in the controller's closure. Every function below is a pure\n * transition; the controller applies them with `ctx.state.update`.\n */\nimport type { Cursor, ToolId } from './contract';\nimport type { HostTool } from './host-contract';\n\nexport interface InteractionState {\n readonly activeToolId: ToolId;\n /** Tools activated with `pushTool`, oldest first; `popTool` restores the last. */\n readonly toolStack: readonly ToolId[];\n readonly cursor: Cursor;\n}\n\n/** A document starts on `pointer`; the controller then activates the `defaultTool` setting. */\nexport const initialInteractionState = (): InteractionState => ({\n activeToolId: 'pointer',\n toolStack: [],\n cursor: 'default',\n});\n\n/** Activate a tool and forget every pushed one. */\nexport function activateTool(state: InteractionState, toolId: ToolId): InteractionState {\n if (state.activeToolId === toolId && state.toolStack.length === 0) return state;\n return { ...state, activeToolId: toolId, toolStack: [] };\n}\n\n/** Activate a tool for a moment, saving the active one for {@link popTool}. */\nexport function pushTool(state: InteractionState, toolId: ToolId): InteractionState {\n return { ...state, toolStack: [...state.toolStack, state.activeToolId], activeToolId: toolId };\n}\n\n/** Activate the tool saved last; an empty stack changes nothing. */\nexport function popTool(state: InteractionState): InteractionState {\n if (state.toolStack.length === 0) return state;\n return {\n ...state,\n toolStack: state.toolStack.slice(0, -1),\n activeToolId: state.toolStack[state.toolStack.length - 1],\n };\n}\n\nexport function setCursor(state: InteractionState, cursor: Cursor): InteractionState {\n return state.cursor === cursor ? state : { ...state, cursor };\n}\n\n/**\n * The two built-in tools. Features add tools via `registerTool`. `enables`\n * is the composition seam:\n * pointer → text selection + annotation editing + marquee selection\n * pan → scrolling (contributed by Stage) + annotation editing, no text select\n * Both carry `form-fill` and `link-nav`: filling forms and following links is\n * the resting state of a viewer (Acrobat's hand tool does both).\n */\nexport const builtinTools = (): HostTool[] => [\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',\n enables: new Set(['scroll', 'annotation-edit', 'form-fill', 'link-nav']),\n },\n];\n","import {\n memo,\n PluginError,\n type PageRef,\n type PluginContext,\n type Unsubscribe,\n} from '@embedpdf/core';\n\nimport type {\n Cursor,\n GestureCancelledEvent,\n GestureEndedEvent,\n GestureStartedEvent,\n InteractionSettings,\n ToolChangedEvent,\n ToolCursors,\n ToolId,\n ToolPointerEvent,\n} from './contract';\nimport {\n samplePointOn,\n type HostTool,\n type HostToolInput,\n type InteractionHandler,\n type InteractionHostCapability,\n type PointerSample,\n} from './host-contract';\nimport { activateTool, popTool, pushTool, setCursor, type InteractionState } from './model';\n\ninterface Claim {\n cursor: Cursor;\n priority: number;\n}\n\n/** A tool's own pointer methods take a press before every handler a plugin registers. */\nconst OWN_POINTER_PRIORITY = 1000;\n\nconst NO_TAGS: ReadonlySet<string> = new Set();\n\n/**\n * The interaction hub. Tools, handlers, the captured-gesture owner and cursor\n * claims are registries in this closure; the state holds only the active\n * tool, the tool stack and the resolved cursor, so UI can react. Registering\n * or removing a tool wakes readers with `ctx.notify()`.\n *\n * Cursor arbitration, top to bottom: the highest-priority claim (hover\n * feedback) → over a page, the tool's declared cursor → over a gap, the\n * tool's `gapCursor`. The winning keyword is replaced through the active\n * tool's cursors (`setToolCursor`) when they name that keyword.\n */\nexport function createInteractionController(\n ctx: PluginContext<InteractionState, InteractionSettings>,\n builtinTools: readonly HostTool[],\n) {\n const settings = ctx.settings();\n const tools = new Map<ToolId, HostTool>();\n /** The handler each tool with its own pointer methods brings, registered beside the plugins' handlers. */\n const ownHandlers = new Map<HostTool, InteractionHandler>();\n /** Bumped on every tool registry change: the input of the tool list. */\n let toolsVersion = 0;\n const handlers: InteractionHandler[] = [];\n const handlerSources = new Map<InteractionHandler, string>();\n const claims = new Map<string, Claim>();\n const toolCursors = new Map<ToolId, ToolCursors>();\n let owner: InteractionHandler | null = null;\n /** The gesture `owner` took, as its events report it. */\n let gesture: GestureStartedEvent | null = null;\n /** Whether the last dispatched sample hit a page: gaps fall back to `gapCursor`. */\n let overPage = false;\n\n const toolChanged = ctx.events.source<ToolChangedEvent>();\n const gestureStarted = ctx.events.source<GestureStartedEvent>();\n const gestureEnded = ctx.events.source<GestureEndedEvent>();\n const gestureCancelled = ctx.events.source<GestureCancelledEvent>();\n const cursorChanged = ctx.events.source<{ readonly cursor: Cursor }>();\n\n ctx.state.onChange(({ previous, next }) => {\n if (previous.cursor !== next.cursor) cursorChanged.emit({ cursor: next.cursor });\n });\n\n const state = () => ctx.state.get();\n const toolOf = (id: ToolId): HostTool =>\n tools.get(id) ?? { id, cursor: 'default', enables: NO_TAGS };\n const active = (): HostTool => toolOf(state().activeToolId);\n const listTools = memo(\n () => [toolsVersion],\n (_version) => [...tools.values()],\n );\n\n const resolveCursor = (): Cursor => {\n let top: Claim | null = null;\n for (const claim of claims.values()) if (!top || claim.priority > top.priority) top = claim;\n const tool = active();\n const cursors = toolCursors.get(tool.id);\n if (top) return cursors?.[top.cursor] ?? top.cursor;\n if (!overPage) return tool.gapCursor ?? 'default';\n return cursors?.[tool.cursor] ?? tool.cursor;\n };\n const syncCursor = (): void => ctx.state.update(setCursor, resolveCursor());\n\n // ── tools ─────────────────────────────────────────────────────────────\n\n const removeHandler = (handler: InteractionHandler): void => {\n const index = handlers.indexOf(handler);\n if (index >= 0) handlers.splice(index, 1);\n handlerSources.delete(handler);\n if (owner === handler) {\n owner = null;\n gesture = null;\n }\n };\n const addHandler = (handler: InteractionHandler, source?: string): Unsubscribe => {\n handlers.push(handler);\n if (source !== undefined) handlerSources.set(handler, source);\n return () => removeHandler(handler);\n };\n\n /** Take a tool out of the registry, with the handler its pointer methods brought. */\n const removeTool = (tool: HostTool): void => {\n tools.delete(tool.id);\n const handler = ownHandlers.get(tool);\n ownHandlers.delete(tool);\n if (handler) removeHandler(handler);\n };\n\n /**\n * Put a tool in the registry without waking readers, and return the stored\n * tool (tags filled in). A taken id is refused unless `replace`.\n */\n const addTool = (input: HostToolInput, replace: boolean): HostTool => {\n const taken = tools.get(input.id);\n if (taken && !replace) {\n throw new PluginError(\n 'conflict',\n 'interaction',\n `tool '${input.id}' is already registered; pass { replace: true } to replace it`,\n );\n }\n if (taken) removeTool(taken);\n const tool: HostTool = input.enables ? (input as HostTool) : { ...input, enables: NO_TAGS };\n tools.set(tool.id, tool);\n const handler = ownPointerHandler(tool);\n if (handler) {\n ownHandlers.set(tool, handler);\n addHandler(handler);\n }\n return tool;\n };\n\n const toolsChanged = (): void => {\n toolsVersion += 1;\n ctx.notify();\n };\n\n /** The registration's remover: it removes this registration only, never a later one with its id. */\n const removerOf = (tool: HostTool) => (): void => {\n if (tools.get(tool.id) !== tool) return;\n removeTool(tool);\n toolCursors.delete(tool.id);\n toolsChanged();\n };\n\n for (const tool of builtinTools) addTool(tool, true);\n // The `tools` setting's tools, registered over the built-in ones; a change of\n // the setting swaps them for the new list.\n let removeSettingTools: Array<() => void> = settings\n .get()\n .tools.map((tool) => removerOf(addTool(tool, true)));\n settings.api.onSettingsChanged(({ changed }) => {\n if (!changed.includes('tools')) return;\n for (const remove of removeSettingTools) remove();\n removeSettingTools = settings.get().tools.map((tool) => removerOf(addTool(tool, true)));\n toolsChanged();\n });\n ctx.state.update(activateTool, settings.get().defaultTool);\n syncCursor();\n\n // ── routing ───────────────────────────────────────────────────────────\n\n /** Lens scoping: a handler registered with a `source` only sees samples stamped with it. */\n const eligible = (source?: string): InteractionHandler[] => {\n const tool = active();\n return handlers\n .filter((handler) => {\n const handlerSource = handlerSources.get(handler);\n return handlerSource === undefined || source === undefined || handlerSource === source;\n })\n .filter((handler) => handler.enabledFor(tool))\n .sort((left, right) => right.priority - left.priority);\n };\n\n /**\n * Activate a tool through `transition`. Every activation is announced,\n * including activating the active tool again.\n */\n function arm(id: ToolId, transition: (current: InteractionState) => InteractionState): void {\n if (!tools.has(id)) throw new PluginError('not-found', 'interaction', `unknown tool '${id}'`);\n const previousToolId = state().activeToolId;\n owner = null;\n gesture = null;\n claims.clear(); // the previous tool's hover claims go with it; handlers claim again on hover\n ctx.state.update(transition);\n syncCursor();\n toolChanged.emit({ toolId: id, previousToolId });\n }\n\n const api: InteractionHostCapability = {\n ...settings.api,\n\n // ── public ────────────────────────────────────────────────────────────\n getActiveTool: active,\n getActiveToolId: () => state().activeToolId,\n getDefaultToolId: () => settings.get().defaultTool,\n listTools,\n getTool: (id) => tools.get(id) ?? null,\n hasTool: (id) => tools.has(id),\n activateTool: (id) => arm(id, (current) => activateTool(current, id)),\n activateDefaultTool: () => {\n const id = settings.get().defaultTool;\n arm(id, (current) => activateTool(current, id));\n },\n pushTool: (id) => arm(id, (current) => pushTool(current, id)),\n popTool: () => {\n const stack = state().toolStack;\n if (stack.length === 0) return;\n arm(stack[stack.length - 1], popTool);\n },\n setToolCursor: (id, cursors) => {\n if (cursors === null) toolCursors.delete(id);\n else toolCursors.set(id, cursors);\n syncCursor();\n },\n registerTool: (tool, options) => {\n const stored = addTool(tool, options?.replace ?? false);\n toolsChanged();\n return removerOf(stored);\n },\n onToolChanged: toolChanged.on,\n onGestureStarted: gestureStarted.on,\n onGestureEnded: gestureEnded.on,\n onGestureCancelled: gestureCancelled.on,\n\n // ── host ──────────────────────────────────────────────────────────────\n activeToolEnables: (behavior) => active().enables.has(behavior),\n registerHandler: (handler, options) => addHandler(handler, options?.source),\n claimCursor: (token, cursor, priority = 0) => {\n if (cursor === null) claims.delete(token);\n else claims.set(token, { cursor, priority });\n syncCursor();\n },\n getCursor: () => state().cursor,\n hasCursorClaim: () => claims.size > 0,\n onCursorChanged: cursorChanged.on,\n wouldClaimTouch: (sample) => {\n for (const handler of eligible(sample.source)) if (handler.claimsTouch?.(sample)) return true;\n return false;\n },\n dispatchPointer: (sample) => {\n const nowOverPage = sample.page != null;\n if (nowOverPage !== overPage) {\n overPage = nowOverPage;\n syncCursor(); // crossing a page edge resolves the base cursor again\n }\n if (sample.phase === 'down') {\n owner = null;\n gesture = null;\n for (const handler of eligible(sample.source)) {\n if (handler.onDown(sample)) {\n owner = handler;\n gesture = {\n toolId: state().activeToolId,\n page: sample.page?.ref ?? null,\n pointerType: sample.pointerType ?? 'mouse',\n };\n gestureStarted.emit(gesture);\n break;\n }\n }\n } else if (sample.phase === 'move') {\n if (owner) owner.onMove?.(sample);\n else for (const handler of eligible(sample.source)) handler.onHover?.(sample);\n } else {\n const captured = owner;\n const taken = gesture;\n owner = null;\n gesture = null;\n if (!captured || !taken) return;\n if (sample.phase === 'cancel') {\n // Abort, don't commit: navigation took the pointer or the system cancelled it.\n (captured.onCancel ?? captured.onUp)?.call(captured, sample);\n gestureCancelled.emit(taken);\n } else {\n captured.onUp?.(sample);\n gestureEnded.emit(taken);\n }\n }\n },\n };\n\n return { api };\n}\n\n/**\n * The handler a tool's own pointer methods bring, or null for a tool without\n * them: it is live only while that tool is active, and turns samples into\n * {@link ToolPointerEvent}s in page coordinates. A gesture keeps the page it\n * started on, so a drag that leaves the page goes on in that page's\n * coordinates.\n */\nfunction ownPointerHandler(tool: HostTool): InteractionHandler | null {\n if (!tool.onPointerDown && !tool.onHover) return null;\n let home: PageRef | null = null;\n let last: ToolPointerEvent | null = null;\n\n const eventOf = (page: PageRef, point: ToolPointerEvent['point'], sample: PointerSample) => ({\n page,\n point,\n modifiers: sample.modifiers,\n pointerType: sample.pointerType ?? 'mouse',\n });\n /** The sample on the gesture's page, or the last event when the source can't project it there. */\n const follow = (sample: PointerSample): ToolPointerEvent | null => {\n if (!home) return null;\n const point = samplePointOn(sample, home);\n if (point) last = eventOf(home, point, sample);\n return last;\n };\n const end = (sample: PointerSample): void => {\n const event = follow(sample);\n home = null;\n last = null;\n if (event) tool.onPointerUp?.(event);\n };\n\n return {\n id: `tool:${tool.id}`,\n priority: OWN_POINTER_PRIORITY,\n enabledFor: (active) => active === tool,\n onDown: (sample) => {\n if (!sample.page || !tool.onPointerDown) return false;\n const event = eventOf(sample.page.ref, sample.page.point, sample);\n if (tool.onPointerDown(event) !== true) return false;\n home = sample.page.ref;\n last = event;\n return true;\n },\n onMove: (sample) => {\n const event = follow(sample);\n if (event) tool.onPointerMove?.(event);\n },\n onUp: end,\n onCancel: end,\n onHover: (sample) => {\n if (sample.page) tool.onHover?.(eventOf(sample.page.ref, sample.page.point, sample));\n },\n };\n}\n","import { definePlugin } from '@embedpdf/core';\n\nimport { INTERACTION_DEFAULTS, type InteractionConfig } from './contract';\nimport { createInteractionController } from './controller';\nimport { InteractionToken } from './host-contract';\nimport { builtinTools, initialInteractionState } from './model';\n\n/**\n * The interaction hub: document-scoped, depends on nothing. Feature plugins\n * `require` this token; the Stage `optional`-ly contributes a scroll handler.\n * `config` is the settings the app registers, over {@link INTERACTION_DEFAULTS}.\n */\nexport const interactionPlugin = (config?: InteractionConfig) =>\n definePlugin({\n id: 'interaction',\n token: InteractionToken,\n scope: 'document',\n state: initialInteractionState,\n settings: { defaults: INTERACTION_DEFAULTS, registered: config },\n create: (ctx) => createInteractionController(ctx, builtinTools()),\n });\n","/**\n * The tools page's State table as code: what `useInteractionState()` returns,\n * and the same fields in every other framework. With no document there is no\n * active tool and no tool to switch to.\n */\nimport { defineState } from '@embedpdf/core';\n\nimport { InteractionToken, type ToolId } from './contract';\n\nexport const interactionState = defineState(InteractionToken, {\n read: (interaction) => ({\n // Widened: the empty state has no active tool.\n activeToolId: interaction.getActiveToolId() as ToolId | null,\n tools: interaction.listTools(),\n }),\n empty: { activeToolId: null, tools: [] },\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).\n * The plugin itself stays DOM-free — the provider is injected from outside\n * (`@embedpdf/web` ships `vibrationFeedback` and a WKWebView bridge; native\n * shells bring their own), as the host's clock enters the kernel\n * (`createKernel({ clock })`): host dependencies enter through explicit\n * injection, 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/**\n * Register the workspace's one feedback provider. Stateless: the capability\n * is the provider (or the no-op).\n */\nexport const feedbackPlugin = (options: FeedbackPluginOptions = {}) =>\n definePlugin({\n id: 'feedback',\n scope: 'workspace',\n token: FeedbackToken,\n create: () => ({ api: options.provider ?? NOOP }),\n });\n"],"mappings":";;;;;AAiBA,MAAa,iCAAmD;CAC9D,cAAc;CACd,WAAW,CAAC;CACZ,QAAQ;AACV;;AAGA,SAAgB,aAAa,OAAyB,QAAkC;CACtF,IAAI,MAAM,iBAAiB,UAAU,MAAM,UAAU,WAAW,GAAG,OAAO;CAC1E,OAAO;EAAE,GAAG;EAAO,cAAc;EAAQ,WAAW,CAAC;CAAE;AACzD;;AAGA,SAAgB,SAAS,OAAyB,QAAkC;CAClF,OAAO;EAAE,GAAG;EAAO,WAAW,CAAC,GAAG,MAAM,WAAW,MAAM,YAAY;EAAG,cAAc;CAAO;AAC/F;;AAGA,SAAgB,QAAQ,OAA2C;CACjE,IAAI,MAAM,UAAU,WAAW,GAAG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AAU;EAAsB,YAAY;CAAO;CAC/D,SAAS,QAAQ,4BAA4B,KAAK,aAAa,CAAC;AAClE,CAAC;;;;;;;;ACXH,MAAa,mBAAmB,YAAY,kBAAkB;CAC5D,OAAO,iBAAiB;EAEtB,cAAc,YAAY,gBAAgB;EAC1C,OAAO,YAAY,UAAU;CAC/B;CACA,OAAO;EAAE,cAAc;EAAM,OAAO,CAAC;CAAE;AACzC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;ACUD,MAAM,OAAyB;CAAE,YAAY,CAAC;CAAG,SAAS,CAAC;CAAG,SAAS,CAAC;AAAE;;;;;AAM1E,MAAa,kBAAkB,UAAiC,CAAC,MAC/D,aAAa;CACX,IAAI;CACJ,OAAO;CACP,OAAO;CACP,eAAe,EAAE,KAAK,QAAQ,YAAY,KAAK;AACjD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-interaction",
3
- "version": "3.0.0-next.13",
3
+ "version": "3.0.0-next.15",
4
4
  "private": false,
5
5
  "description": "The interaction hub: the active tool, the cursor, and pointer routing. Pure mechanism — knows nothing about selection/annotations/forms; they contribute tools + handlers.",
6
6
  "type": "module",
@@ -16,14 +16,18 @@
16
16
  "import": "./dist/contract.js",
17
17
  "require": "./dist/contract.cjs"
18
18
  },
19
+ "./contract/host": {
20
+ "import": "./dist/contract/host.js",
21
+ "require": "./dist/contract/host.cjs"
22
+ },
19
23
  "./package.json": "./package.json"
20
24
  },
21
25
  "files": [
22
26
  "dist"
23
27
  ],
24
28
  "dependencies": {
25
- "@embedpdf/core": "3.0.0-next.13",
26
- "@embedpdf/core-geometry": "3.0.0-next.13"
29
+ "@embedpdf/core-geometry": "3.0.0-next.15",
30
+ "@embedpdf/core": "3.0.0-next.15"
27
31
  },
28
32
  "devDependencies": {
29
33
  "typescript": "^5.0.0",
@@ -1,36 +0,0 @@
1
- let _embedpdf_core = require("@embedpdf/core");
2
- //#region src/types.ts
3
- const InteractionToken = (0, _embedpdf_core.createCapabilityToken)("interaction", { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list` });
4
- /**
5
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
6
- * the page they started on even when the cursor wanders off it — `s.page`
7
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
8
- * prefer the source's unclamped projection and fall back to the page hit only
9
- * when it is the same page. Null → this sample can't speak for the home page.
10
- * Shared by every gesture owner (annotation edit/draw, form placement).
11
- */
12
- const samplePointOn = (s, pon) => s.project?.(pon) ?? (s.page?.pon === pon ? s.page.point : null);
13
- //#endregion
14
- //#region src/feedback.types.ts
15
- const FeedbackToken = (0, _embedpdf_core.createCapabilityToken)("feedback");
16
- //#endregion
17
- Object.defineProperty(exports, "FeedbackToken", {
18
- enumerable: true,
19
- get: function() {
20
- return FeedbackToken;
21
- }
22
- });
23
- Object.defineProperty(exports, "InteractionToken", {
24
- enumerable: true,
25
- get: function() {
26
- return InteractionToken;
27
- }
28
- });
29
- Object.defineProperty(exports, "samplePointOn", {
30
- enumerable: true,
31
- get: function() {
32
- return samplePointOn;
33
- }
34
- });
35
-
36
- //# sourceMappingURL=contract-B3tBU_U9.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-B3tBU_U9.cjs","names":[],"sources":["../src/types.ts","../src/feedback.types.ts"],"sourcesContent":["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 { createCapabilityToken } from '@embedpdf/core';\n\nexport interface PlatformFeedback {\n selection(): void;\n impact(weight?: 'light' | 'medium' | 'heavy'): void;\n notify(kind: 'success' | 'warning' | 'error'): void;\n}\n\nexport const FeedbackToken = createCapabilityToken<PlatformFeedback>('feedback');\n\nexport interface FeedbackPluginOptions {\n provider?: PlatformFeedback;\n}\n"],"mappings":";;AA6NA,MAAa,oBAAA,GAAA,eAAA,sBAAA,CAAgE,eAAe,EAC1F,MAAM,mFACR,CAAC;;;;;;;;;AAUD,MAAa,iBAAiB,GAAkB,QAC9C,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM,QAAQ,MAAM,EAAE,KAAK,QAAQ;;;AClO5D,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAAwD,UAAU"}
@@ -1,19 +0,0 @@
1
- import { createCapabilityToken } from "@embedpdf/core";
2
- //#region src/types.ts
3
- const InteractionToken = createCapabilityToken("interaction", { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list` });
4
- /**
5
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
6
- * the page they started on even when the cursor wanders off it — `s.page`
7
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
8
- * prefer the source's unclamped projection and fall back to the page hit only
9
- * when it is the same page. Null → this sample can't speak for the home page.
10
- * Shared by every gesture owner (annotation edit/draw, form placement).
11
- */
12
- const samplePointOn = (s, pon) => s.project?.(pon) ?? (s.page?.pon === pon ? s.page.point : null);
13
- //#endregion
14
- //#region src/feedback.types.ts
15
- const FeedbackToken = createCapabilityToken("feedback");
16
- //#endregion
17
- export { InteractionToken as n, samplePointOn as r, FeedbackToken as t };
18
-
19
- //# sourceMappingURL=contract-CrM0i9pQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-CrM0i9pQ.js","names":[],"sources":["../src/types.ts","../src/feedback.types.ts"],"sourcesContent":["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 { createCapabilityToken } from '@embedpdf/core';\n\nexport interface PlatformFeedback {\n selection(): void;\n impact(weight?: 'light' | 'medium' | 'heavy'): void;\n notify(kind: 'success' | 'warning' | 'error'): void;\n}\n\nexport const FeedbackToken = createCapabilityToken<PlatformFeedback>('feedback');\n\nexport interface FeedbackPluginOptions {\n provider?: PlatformFeedback;\n}\n"],"mappings":";;AA6NA,MAAa,mBAAmB,sBAA6C,eAAe,EAC1F,MAAM,mFACR,CAAC;;;;;;;;;AAUD,MAAa,iBAAiB,GAAkB,QAC9C,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM,QAAQ,MAAM,EAAE,KAAK,QAAQ;;;AClO5D,MAAa,gBAAgB,sBAAwC,UAAU"}
@@ -1,239 +0,0 @@
1
- import { PageObjectNumber } 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
227
- //#region src/feedback.types.d.ts
228
- interface PlatformFeedback {
229
- selection(): void;
230
- impact(weight?: 'light' | 'medium' | 'heavy'): void;
231
- notify(kind: 'success' | 'warning' | 'error'): void;
232
- }
233
- declare const FeedbackToken: import("@embedpdf/core").CapabilityToken<PlatformFeedback>;
234
- interface FeedbackPluginOptions {
235
- provider?: PlatformFeedback;
236
- }
237
- //#endregion
238
- export { samplePointOn as _, InteractionAction as a, InteractionHandler as c, Modifiers as d, Phase as f, ToolId as g, Tool as h, Cursor as i, InteractionState as l, PointerSample as m, FeedbackToken as n, InteractionCapability as o, PointerKind as p, PlatformFeedback as r, InteractionConfig as s, FeedbackPluginOptions as t, InteractionToken as u };
239
- //# sourceMappingURL=contract-F3gsFtSf.d.cts.map