@embedpdf/plugin-interaction 3.0.0-next.1 → 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
  /**
@@ -48,9 +49,13 @@ function createInteractionCapability(ctx, builtinTools) {
48
49
  cursor: next
49
50
  });
50
51
  };
51
- const eligible = () => {
52
+ const handlerSources = /* @__PURE__ */ new Map();
53
+ const eligible = (source) => {
52
54
  const tool = active();
53
- return handlers.filter((h) => h.enabledFor(tool)).sort((a, b) => b.priority - a.priority);
55
+ return handlers.filter((h) => {
56
+ const hs = handlerSources.get(h);
57
+ return hs === void 0 || source === void 0 || hs === source;
58
+ }).filter((h) => h.enabledFor(tool)).sort((a, b) => b.priority - a.priority);
54
59
  };
55
60
  return {
56
61
  activeTool: active,
@@ -84,11 +89,13 @@ function createInteractionCapability(ctx, builtinTools) {
84
89
  else cursorSkins.set(id, skin);
85
90
  syncCursor();
86
91
  },
87
- registerHandler: (handler) => {
92
+ registerHandler: (handler, options) => {
88
93
  handlers.push(handler);
94
+ if (options?.source !== void 0) handlerSources.set(handler, options.source);
89
95
  return () => {
90
96
  const i = handlers.indexOf(handler);
91
97
  if (i >= 0) handlers.splice(i, 1);
98
+ handlerSources.delete(handler);
92
99
  if (owner === handler) owner = null;
93
100
  };
94
101
  },
@@ -100,6 +107,10 @@ function createInteractionCapability(ctx, builtinTools) {
100
107
  });
101
108
  syncCursor();
102
109
  },
110
+ wouldClaimTouch: (sample) => {
111
+ for (const h of eligible(sample.source)) if (h.claimsTouch?.(sample)) return true;
112
+ return false;
113
+ },
103
114
  dispatch: (sample) => {
104
115
  const nowOverPage = sample.page != null;
105
116
  if (nowOverPage !== overPage) {
@@ -108,13 +119,17 @@ function createInteractionCapability(ctx, builtinTools) {
108
119
  }
109
120
  if (sample.phase === "down") {
110
121
  owner = null;
111
- for (const h of eligible()) if (h.onDown(sample)) {
122
+ for (const h of eligible(sample.source)) if (h.onDown(sample)) {
112
123
  owner = h;
113
124
  break;
114
125
  }
115
126
  } else if (sample.phase === "move") if (owner) owner.onMove?.(sample);
116
- else for (const h of eligible()) h.onHover?.(sample);
117
- else {
127
+ else for (const h of eligible(sample.source)) h.onHover?.(sample);
128
+ else if (sample.phase === "cancel") {
129
+ const o = owner;
130
+ owner = null;
131
+ if (o) (o.onCancel ?? o.onUp)?.call(o, sample);
132
+ } else {
118
133
  owner?.onUp?.(sample);
119
134
  owner = null;
120
135
  }
@@ -141,18 +156,6 @@ const interactionReducer = (state, action) => {
141
156
  }
142
157
  };
143
158
  //#endregion
144
- //#region src/types.ts
145
- const InteractionToken = (0, _embedpdf_core.createCapabilityToken)("interaction");
146
- /**
147
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
148
- * the page they started on even when the cursor wanders off it — `s.page`
149
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
150
- * prefer the source's unclamped projection and fall back to the page hit only
151
- * when it is the same page. Null → this sample can't speak for the home page.
152
- * Shared by every gesture owner (annotation edit/draw, form placement).
153
- */
154
- const samplePointOn = (s, pon) => s.project?.(pon) ?? (s.page?.pon === pon ? s.page.point : null);
155
- //#endregion
156
159
  //#region src/interaction.plugin.ts
157
160
  /**
158
161
  * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a
@@ -196,19 +199,61 @@ const builtinTools = () => [{
196
199
  */
197
200
  const interactionPlugin = (config = {}) => (0, _embedpdf_core.definePlugin)({
198
201
  id: "interaction",
199
- token: InteractionToken,
202
+ token: require_contract.InteractionToken,
200
203
  scope: "document",
201
204
  initialState: () => initialInteractionState(config),
202
205
  reduce: interactionReducer,
203
206
  capability: (ctx) => createInteractionCapability(ctx, builtinTools())
204
207
  });
205
208
  //#endregion
206
- exports.InteractionToken = InteractionToken;
209
+ //#region src/feedback.ts
210
+ /**
211
+ * Platform feedback (haptics) — the OUTPUT half of the interaction seam:
212
+ * pointers come in, feedback goes back out to the device.
213
+ *
214
+ * ONE workspace-scoped provider, MANY consumers: any plugin lists
215
+ * {@link FeedbackToken} as an optional dependency and calls the capability at
216
+ * its semantic moments (the selection handler on a long-press word-select; an
217
+ * annotation pickup or a snap later). The plugin itself stays DOM-free — the
218
+ * PROVIDER is injected from outside (`@embedpdf/web` ships `vibrationFeedback`
219
+ * and a WKWebView bridge; native shells bring their own), exactly like the
220
+ * stage's Scheduler seam: host dependencies enter through explicit injection,
221
+ * never a hidden global.
222
+ *
223
+ * The vocabulary is deliberately the PLATFORM's haptic taxonomy — iOS's three
224
+ * generator families, which Android mirrors in `HapticFeedbackConstants` and
225
+ * the web approximates with vibration patterns — not app vocabulary. A verb
226
+ * belongs here only if a provider would map it to a physically different
227
+ * output; call-site semantics ("word selected", "annotation picked up") pick a
228
+ * family, they never add one.
229
+ */
230
+ /** No provider → every call is a cheap no-op; consumers never branch. */
231
+ const NOOP = {
232
+ selection() {},
233
+ impact() {},
234
+ notify() {}
235
+ };
236
+ /**
237
+ * Register the workspace's ONE feedback provider. Stateless: the capability IS
238
+ * the provider (or the no-op).
239
+ */
240
+ const feedbackPlugin = (options = {}) => (0, _embedpdf_core.definePlugin)({
241
+ id: "feedback",
242
+ scope: "workspace",
243
+ token: require_contract.FeedbackToken,
244
+ initialState: () => ({}),
245
+ reduce: (state) => state,
246
+ capability: () => options.provider ?? NOOP
247
+ });
248
+ //#endregion
249
+ exports.FeedbackToken = require_contract.FeedbackToken;
250
+ exports.InteractionToken = require_contract.InteractionToken;
207
251
  exports.builtinTools = builtinTools;
208
252
  exports.createInteractionCapability = createInteractionCapability;
253
+ exports.feedbackPlugin = feedbackPlugin;
209
254
  exports.initialInteractionState = initialInteractionState;
210
255
  exports.interactionPlugin = interactionPlugin;
211
256
  exports.interactionReducer = interactionReducer;
212
- exports.samplePointOn = samplePointOn;
257
+ exports.samplePointOn = require_contract.samplePointOn;
213
258
 
214
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"],"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 const eligible = (): InteractionHandler[] => {\n const tool = active();\n return handlers.filter((h) => h.enabledFor(tool)).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) => {\n handlers.push(handler);\n return () => {\n const i = handlers.indexOf(handler);\n if (i >= 0) handlers.splice(i, 1);\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 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()) {\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()) h.onHover?.(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\nexport type Phase = 'down' | 'move' | 'up';\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 /**\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 /** Pointer moved with no active gesture — cursor feedback only. */\n onHover?(sample: PointerSample): void;\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 registerHandler(handler: InteractionHandler): () => 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\nexport const InteractionToken = createCapabilityToken<InteractionCapability>('interaction');\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"],"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,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AU,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"}
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,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;;;;;;;;;;;;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,157 +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
- type Phase = 'down' | 'move' | 'up';
32
- /**
33
- * One normalized pointer event. `viewport` is the source container's px (the pan
34
- * handler uses the delta). `page` is the resolved page hit — its `pon` + content
35
- * point (y-down, PDF units, via the page's transform) — present when the pointer
36
- * is over a page, absent over gaps. A viewport source (Stage) resolves `page` per
37
- * event (so a drag can cross pages); a per-page source (PageView) always sets it.
38
- */
39
- interface PointerSample {
40
- phase: Phase;
41
- viewport: Point;
42
- /** `scale` is the hit page's VIEW px per content unit — handlers use it to
43
- * convert screen-px chrome settings into content-space tolerances, so grab
44
- * zones stay screen-constant across zoom. `rotation` is the hit page's TOTAL
45
- * display rotation (document /Rotate + view rotation) — per-event
46
- * environmental context like `scale`, for placement rules that depend on how
47
- * the page is DISPLAYED (an upright stamp). `zoom` is the page's zoom
48
- * RELATIVE to its 100% baseline (`transform.zoom` — dimensionless, 1 =
49
- * Acrobat's 100%), for zoom-relative policies (the `/F` NoZoom exemption);
50
- * distinct from `scale`, which is a units conversion. Absent when the
51
- * source can't say. */
52
- page?: {
53
- pon: PageObjectNumber;
54
- point: Point;
55
- scale?: number;
56
- rotation?: PageRotation;
57
- zoom?: number;
58
- };
59
- modifiers: Modifiers;
60
- /**
61
- * Click count for a `down` (1 = single, 2 = double, 3 = triple), from the
62
- * browser's native multi-click detection (`MouseEvent.detail`). Lets handlers
63
- * do word/line selection without re-implementing timing. Defaults to 1.
64
- */
65
- clickCount?: number;
66
- /**
67
- * Project this event onto a SPECIFIC page's content space, unclamped — valid
68
- * (and expected) outside the page's bounds. `page` answers "what is under the
69
- * cursor" and re-resolves per event; `project` answers "where is the cursor
70
- * in MY page's frame" for a gesture anchored to the page it started on (an
71
- * annotation drag sliding along the page edge). Null when the source can't
72
- * project onto that page (not laid out / a per-page source's foreign page).
73
- */
74
- project?(pon: PageObjectNumber): Point | null;
75
- }
76
- /**
77
- * A pointer handler contributed by a feature plugin. The ONE registration
78
- * mechanism (replacing v2's registerMode / registerHandlers / registerAlways /
79
- * enableForMode quartet): a handler declares which tools it's live under and a
80
- * priority; the hub routes each gesture to the first handler that captures it.
81
- */
82
- interface InteractionHandler {
83
- id: string;
84
- /** Higher wins the gesture. */
85
- priority: number;
86
- /** Usually `tool.enables.has('my-tag')`. */
87
- enabledFor(tool: Tool): boolean;
88
- /** Return true to CAPTURE: subsequent move/up route here until pointer-up. */
89
- onDown(sample: PointerSample): boolean;
90
- onMove?(sample: PointerSample): void;
91
- onUp?(sample: PointerSample): void;
92
- /** Pointer moved with no active gesture — cursor feedback only. */
93
- onHover?(sample: PointerSample): void;
94
- }
95
- /**
96
- * A tool's runtime cursor skin: "while THIS tool is armed, keyword X looks
97
- * like Y." Everything cursor-shaped in the hub speaks KEYWORDS — a tool
98
- * declares its base ('crosshair', 'copy'), hover claims name what is under
99
- * the pointer ('text' over text, 'move' over an annotation) — and the skin
100
- * restyles those keywords, typically as image cursors carrying the tool's
101
- * icon. Applied uniformly to the winning claim and to the declared base, so
102
- * same keyword = same meaning = same look. Unmapped keywords render as-is (a
103
- * foreign 'move' over an annotation drops the tool identity), and page gaps
104
- * are never skinned — the identity appears exactly where the action is
105
- * possible, and the skin can only restyle where the tool already acts.
106
- */
107
- type ToolCursorSkin = Record<Cursor, Cursor>;
108
- interface InteractionState {
109
- activeToolId: ToolId;
110
- cursor: Cursor;
111
- }
112
- type InteractionAction = {
113
- type: 'SET_TOOL';
114
- toolId: ToolId;
115
- } | {
116
- type: 'SET_CURSOR';
117
- cursor: Cursor;
118
- };
119
- interface InteractionCapability {
120
- activeTool(): Tool;
121
- activeToolId(): ToolId;
122
- cursor(): Cursor;
123
- tools(): Tool[];
124
- activateTool(id: ToolId): void;
125
- /** Fires after the active tool changes — lets a feature react (e.g. a markup
126
- * tool taking over the selection visual). Returns an unsubscribe fn. */
127
- onToolChange(cb: () => void): () => void;
128
- /**
129
- * Reskin a tool's cursor keywords at runtime — how an app gives the armed
130
- * tool an image cursor built from its own toolbar icon (`Cursor` is any CSS
131
- * cursor string, `url(data:…) x y, crosshair` included). See
132
- * {@link ToolCursorSkin} for what the map means. `null` removes the skin.
133
- */
134
- setToolCursor(id: ToolId, skin: ToolCursorSkin | null): void;
135
- registerTool(tool: Tool): () => void;
136
- registerHandler(handler: InteractionHandler): () => void;
137
- setCursor(token: string, cursor: Cursor | null, priority?: number): void;
138
- dispatch(sample: PointerSample): void;
139
- }
140
- declare const InteractionToken: import("@embedpdf/core").CapabilityToken<InteractionCapability>;
141
- /**
142
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
143
- * the page they started on even when the cursor wanders off it — `s.page`
144
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
145
- * prefer the source's unclamped projection and fall back to the page hit only
146
- * when it is the same page. Null → this sample can't speak for the home page.
147
- * Shared by every gesture owner (annotation edit/draw, form placement).
148
- */
149
- declare const samplePointOn: (s: PointerSample, pon: PageObjectNumber) => Point | null;
150
- interface InteractionConfig {
151
- /** Tool active when a document opens. Default `'pointer'`. */
152
- defaultTool?: ToolId;
153
- }
154
- //#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";
155
3
  //#region src/interaction.plugin.d.ts
156
4
  /**
157
5
  * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a
@@ -198,5 +46,17 @@ declare function createInteractionCapability(ctx: PluginContext<InteractionState
198
46
  declare const initialInteractionState: (config: InteractionConfig) => InteractionState;
199
47
  declare const interactionReducer: (state: InteractionState, action: InteractionAction) => InteractionState;
200
48
  //#endregion
201
- export { type Cursor, type InteractionAction, type InteractionCapability, type InteractionConfig, type InteractionHandler, type InteractionState, InteractionToken, type Modifiers, type Phase, type PointerSample, type Tool, type ToolId, builtinTools, createInteractionCapability, initialInteractionState, interactionPlugin, interactionReducer, samplePointOn };
49
+ //#region src/feedback.d.ts
50
+ /** The plugin is stateless; the action type exists only to satisfy the
51
+ * reducer contract (nothing ever dispatches it). */
52
+ type FeedbackAction = {
53
+ type: 'feedback/noop';
54
+ };
55
+ /**
56
+ * Register the workspace's ONE feedback provider. Stateless: the capability IS
57
+ * the provider (or the no-op).
58
+ */
59
+ declare const feedbackPlugin: (options?: FeedbackPluginOptions) => import("@embedpdf/core").PluginDef<Record<string, never>, FeedbackAction, PlatformFeedback>;
60
+ //#endregion
61
+ export { type Cursor, type FeedbackPluginOptions, FeedbackToken, type InteractionAction, type InteractionCapability, type InteractionConfig, type InteractionHandler, type InteractionState, InteractionToken, type Modifiers, type Phase, type PlatformFeedback, type PointerKind, type PointerSample, type Tool, type ToolId, builtinTools, createInteractionCapability, feedbackPlugin, initialInteractionState, interactionPlugin, interactionReducer, samplePointOn };
202
62
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,157 +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
- type Phase = 'down' | 'move' | 'up';
32
- /**
33
- * One normalized pointer event. `viewport` is the source container's px (the pan
34
- * handler uses the delta). `page` is the resolved page hit — its `pon` + content
35
- * point (y-down, PDF units, via the page's transform) — present when the pointer
36
- * is over a page, absent over gaps. A viewport source (Stage) resolves `page` per
37
- * event (so a drag can cross pages); a per-page source (PageView) always sets it.
38
- */
39
- interface PointerSample {
40
- phase: Phase;
41
- viewport: Point;
42
- /** `scale` is the hit page's VIEW px per content unit — handlers use it to
43
- * convert screen-px chrome settings into content-space tolerances, so grab
44
- * zones stay screen-constant across zoom. `rotation` is the hit page's TOTAL
45
- * display rotation (document /Rotate + view rotation) — per-event
46
- * environmental context like `scale`, for placement rules that depend on how
47
- * the page is DISPLAYED (an upright stamp). `zoom` is the page's zoom
48
- * RELATIVE to its 100% baseline (`transform.zoom` — dimensionless, 1 =
49
- * Acrobat's 100%), for zoom-relative policies (the `/F` NoZoom exemption);
50
- * distinct from `scale`, which is a units conversion. Absent when the
51
- * source can't say. */
52
- page?: {
53
- pon: PageObjectNumber;
54
- point: Point;
55
- scale?: number;
56
- rotation?: PageRotation;
57
- zoom?: number;
58
- };
59
- modifiers: Modifiers;
60
- /**
61
- * Click count for a `down` (1 = single, 2 = double, 3 = triple), from the
62
- * browser's native multi-click detection (`MouseEvent.detail`). Lets handlers
63
- * do word/line selection without re-implementing timing. Defaults to 1.
64
- */
65
- clickCount?: number;
66
- /**
67
- * Project this event onto a SPECIFIC page's content space, unclamped — valid
68
- * (and expected) outside the page's bounds. `page` answers "what is under the
69
- * cursor" and re-resolves per event; `project` answers "where is the cursor
70
- * in MY page's frame" for a gesture anchored to the page it started on (an
71
- * annotation drag sliding along the page edge). Null when the source can't
72
- * project onto that page (not laid out / a per-page source's foreign page).
73
- */
74
- project?(pon: PageObjectNumber): Point | null;
75
- }
76
- /**
77
- * A pointer handler contributed by a feature plugin. The ONE registration
78
- * mechanism (replacing v2's registerMode / registerHandlers / registerAlways /
79
- * enableForMode quartet): a handler declares which tools it's live under and a
80
- * priority; the hub routes each gesture to the first handler that captures it.
81
- */
82
- interface InteractionHandler {
83
- id: string;
84
- /** Higher wins the gesture. */
85
- priority: number;
86
- /** Usually `tool.enables.has('my-tag')`. */
87
- enabledFor(tool: Tool): boolean;
88
- /** Return true to CAPTURE: subsequent move/up route here until pointer-up. */
89
- onDown(sample: PointerSample): boolean;
90
- onMove?(sample: PointerSample): void;
91
- onUp?(sample: PointerSample): void;
92
- /** Pointer moved with no active gesture — cursor feedback only. */
93
- onHover?(sample: PointerSample): void;
94
- }
95
- /**
96
- * A tool's runtime cursor skin: "while THIS tool is armed, keyword X looks
97
- * like Y." Everything cursor-shaped in the hub speaks KEYWORDS — a tool
98
- * declares its base ('crosshair', 'copy'), hover claims name what is under
99
- * the pointer ('text' over text, 'move' over an annotation) — and the skin
100
- * restyles those keywords, typically as image cursors carrying the tool's
101
- * icon. Applied uniformly to the winning claim and to the declared base, so
102
- * same keyword = same meaning = same look. Unmapped keywords render as-is (a
103
- * foreign 'move' over an annotation drops the tool identity), and page gaps
104
- * are never skinned — the identity appears exactly where the action is
105
- * possible, and the skin can only restyle where the tool already acts.
106
- */
107
- type ToolCursorSkin = Record<Cursor, Cursor>;
108
- interface InteractionState {
109
- activeToolId: ToolId;
110
- cursor: Cursor;
111
- }
112
- type InteractionAction = {
113
- type: 'SET_TOOL';
114
- toolId: ToolId;
115
- } | {
116
- type: 'SET_CURSOR';
117
- cursor: Cursor;
118
- };
119
- interface InteractionCapability {
120
- activeTool(): Tool;
121
- activeToolId(): ToolId;
122
- cursor(): Cursor;
123
- tools(): Tool[];
124
- activateTool(id: ToolId): void;
125
- /** Fires after the active tool changes — lets a feature react (e.g. a markup
126
- * tool taking over the selection visual). Returns an unsubscribe fn. */
127
- onToolChange(cb: () => void): () => void;
128
- /**
129
- * Reskin a tool's cursor keywords at runtime — how an app gives the armed
130
- * tool an image cursor built from its own toolbar icon (`Cursor` is any CSS
131
- * cursor string, `url(data:…) x y, crosshair` included). See
132
- * {@link ToolCursorSkin} for what the map means. `null` removes the skin.
133
- */
134
- setToolCursor(id: ToolId, skin: ToolCursorSkin | null): void;
135
- registerTool(tool: Tool): () => void;
136
- registerHandler(handler: InteractionHandler): () => void;
137
- setCursor(token: string, cursor: Cursor | null, priority?: number): void;
138
- dispatch(sample: PointerSample): void;
139
- }
140
- declare const InteractionToken: import("@embedpdf/core").CapabilityToken<InteractionCapability>;
141
- /**
142
- * Resolve a sample against a gesture's HOME page. Page-anchored gestures track
143
- * the page they started on even when the cursor wanders off it — `s.page`
144
- * re-resolves per event (a foreign page is a DIFFERENT coordinate frame), so
145
- * prefer the source's unclamped projection and fall back to the page hit only
146
- * when it is the same page. Null → this sample can't speak for the home page.
147
- * Shared by every gesture owner (annotation edit/draw, form placement).
148
- */
149
- declare const samplePointOn: (s: PointerSample, pon: PageObjectNumber) => Point | null;
150
- interface InteractionConfig {
151
- /** Tool active when a document opens. Default `'pointer'`. */
152
- defaultTool?: ToolId;
153
- }
154
- //#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.js";
2
+ import { PluginContext } from "@embedpdf/core";
155
3
  //#region src/interaction.plugin.d.ts
156
4
  /**
157
5
  * The two built-in tools. Features ADD tools via `registerTool` (a draw tool, a
@@ -198,5 +46,17 @@ declare function createInteractionCapability(ctx: PluginContext<InteractionState
198
46
  declare const initialInteractionState: (config: InteractionConfig) => InteractionState;
199
47
  declare const interactionReducer: (state: InteractionState, action: InteractionAction) => InteractionState;
200
48
  //#endregion
201
- export { type Cursor, type InteractionAction, type InteractionCapability, type InteractionConfig, type InteractionHandler, type InteractionState, InteractionToken, type Modifiers, type Phase, type PointerSample, type Tool, type ToolId, builtinTools, createInteractionCapability, initialInteractionState, interactionPlugin, interactionReducer, samplePointOn };
49
+ //#region src/feedback.d.ts
50
+ /** The plugin is stateless; the action type exists only to satisfy the
51
+ * reducer contract (nothing ever dispatches it). */
52
+ type FeedbackAction = {
53
+ type: 'feedback/noop';
54
+ };
55
+ /**
56
+ * Register the workspace's ONE feedback provider. Stateless: the capability IS
57
+ * the provider (or the no-op).
58
+ */
59
+ declare const feedbackPlugin: (options?: FeedbackPluginOptions) => import("@embedpdf/core").PluginDef<Record<string, never>, FeedbackAction, PlatformFeedback>;
60
+ //#endregion
61
+ export { type Cursor, type FeedbackPluginOptions, FeedbackToken, type InteractionAction, type InteractionCapability, type InteractionConfig, type InteractionHandler, type InteractionState, InteractionToken, type Modifiers, type Phase, type PlatformFeedback, type PointerKind, type PointerSample, type Tool, type ToolId, builtinTools, createInteractionCapability, feedbackPlugin, initialInteractionState, interactionPlugin, interactionReducer, samplePointOn };
202
62
  //# sourceMappingURL=index.d.ts.map