@embedpdf/plugin-interaction 3.0.0-next.14 → 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/contract/host.cjs +17 -0
- package/dist/contract/host.cjs.map +1 -0
- package/dist/contract/host.d.cts +3 -0
- package/dist/contract/host.d.ts +3 -0
- package/dist/contract/host.js +14 -0
- package/dist/contract/host.js.map +1 -0
- package/dist/contract-C9IFDdDd.d.cts +179 -0
- package/dist/contract-C9IFDdDd.d.ts +179 -0
- package/dist/contract-CmEMPz9L.js +19 -0
- package/dist/contract-CmEMPz9L.js.map +1 -0
- package/dist/contract-yO6QKpba.cjs +36 -0
- package/dist/contract-yO6QKpba.cjs.map +1 -0
- package/dist/contract.cjs +2 -2
- package/dist/contract.d.cts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/host-contract-Crcu-9DW.d.ts +121 -0
- package/dist/host-contract-DCb-QVfd.d.cts +121 -0
- package/dist/index.cjs +347 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -52
- package/dist/index.d.ts +23 -52
- package/dist/index.js +347 -163
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
- package/dist/contract-B3tBU_U9.cjs +0 -36
- package/dist/contract-B3tBU_U9.cjs.map +0 -1
- package/dist/contract-CrM0i9pQ.js +0 -19
- package/dist/contract-CrM0i9pQ.js.map +0 -1
- package/dist/contract-F3gsFtSf.d.cts +0 -239
- package/dist/contract-F3gsFtSf.d.ts +0 -239
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_contract = require("../contract-yO6QKpba.cjs");
|
|
3
|
+
//#region src/host-contract.ts
|
|
4
|
+
const InteractionToken = (0, require("@embedpdf/core").createHostToken)(require_contract.InteractionToken);
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a sample against a gesture's home page: prefer the source's
|
|
7
|
+
* unclamped projection, fall back to the page hit only when it is the same
|
|
8
|
+
* page. Null: this sample can't speak for the home page.
|
|
9
|
+
*/
|
|
10
|
+
const samplePointOn = (sample, page) => sample.project?.(page) ?? (sample.page?.ref.objectNumber === page.objectNumber ? sample.page.point : null);
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.FeedbackToken = require_contract.FeedbackToken;
|
|
13
|
+
exports.INTERACTION_DEFAULTS = require_contract.INTERACTION_DEFAULTS;
|
|
14
|
+
exports.InteractionToken = InteractionToken;
|
|
15
|
+
exports.samplePointOn = samplePointOn;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.cjs","names":["PublicInteractionToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["import { createHostToken, type EventHook, type PageRef, type Unsubscribe } from '@embedpdf/core';\nimport type { PageRotation, Point } from '@embedpdf/core-geometry';\n\nimport { InteractionToken as PublicInteractionToken } from './contract';\nimport type {\n Cursor,\n InteractionCapability,\n Modifiers,\n PointerKind,\n RegisterToolOptions,\n Tool,\n ToolId,\n} from './contract';\n\n/**\n * A tool as plugins see it: a public tool plus the behavior tags it turns on.\n * A tool doesn't act by itself: handlers opt into tags (`enabledFor`), so a\n * tool composes features without depending on them. A tool registered without\n * tags has none.\n */\nexport interface HostTool extends Tool {\n /** The behavior tags the tool turns on, such as `'text-select'` or `'annotation-draw'`. */\n readonly enables: ReadonlySet<string>;\n /**\n * The cursor over the space between pages. Most tools act only on pages, so\n * the gaps show the plain arrow (`'default'`); a tool that works anywhere\n * (pan) names its own (`'grab'`). Hover claims outrank both.\n */\n readonly gapCursor?: Cursor;\n}\n\n/** A tool as a plugin registers it: its tags may be left out. */\nexport type HostToolInput = Tool & Partial<Pick<HostTool, 'enables' | 'gapCursor'>>;\n\nexport type Phase = 'down' | 'move' | 'up' | 'cancel';\n\n/**\n * One normalized pointer event. `viewport` is the source container's px. `page`\n * is the resolved page hit (its `ref` and page-space point), present when the\n * pointer is over a page, absent over gaps.\n */\nexport interface PointerSample {\n phase: Phase;\n viewport: Point;\n /** `scale` = view px per page unit; `rotation` = the page's total display\n * rotation; `zoom` = the page's zoom relative to its 100% baseline. */\n page?: {\n ref: PageRef;\n point: Point;\n scale?: number;\n rotation?: PageRotation;\n zoom?: number;\n };\n modifiers: Modifiers;\n /** Click count for a `down` (1 single, 2 double, 3 triple). Defaults to 1. */\n clickCount?: number;\n /** Absent when the source can't say: treat as 'mouse'. */\n pointerType?: PointerKind;\n /** Present when the sample was synthesized from a recognized gesture. */\n gesture?: 'long-press';\n /** The lens this sample came from (the stage plugin id); absent = route everywhere. */\n source?: string;\n /** Project this event onto a specific page's frame, unclamped; null when the source cannot. */\n project?(page: PageRef): Point | null;\n}\n\n/**\n * A pointer handler contributed by a feature plugin: it declares which tools\n * it is live under and a priority; the hub routes each gesture to the first\n * 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: HostTool): 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 /** The gesture was aborted, not completed. Falls back to `onUp` when absent. */\n onCancel?(sample: PointerSample): void;\n /** Pointer moved with no active gesture: cursor feedback only. */\n onHover?(sample: PointerSample): void;\n /** Touch consent, second rung: a pure read asked before a touch contact is classified. */\n claimsTouch?(sample: PointerSample): boolean;\n}\n\n/**\n * The host lens: what pointer sources (the Stage surface, `PagePointerSource`)\n * and feature plugins with gestures need. The same runtime token as the\n * public contract, typed wider. Application code never needs it.\n */\nexport interface InteractionHostCapability extends InteractionCapability {\n getActiveTool(): HostTool;\n listTools(): readonly HostTool[];\n getTool(id: ToolId): HostTool | null;\n /** Add a tool, with the behavior tags it turns on. The rules are those of the public `registerTool`. */\n registerTool(tool: HostToolInput, options?: RegisterToolOptions): Unsubscribe;\n /** Whether the active tool turns on a behavior tag such as `'text-select'`. */\n activeToolEnables(behavior: string): boolean;\n /** Pointer ingress: a source calls it for every normalized event. */\n dispatchPointer(sample: PointerSample): void;\n /** Touch-arbitration pre-flight: would any eligible handler claim this contact. Pure. */\n wouldClaimTouch(sample: PointerSample): boolean;\n /** Register a pointer handler; `source` scopes it to one lens. */\n registerHandler(handler: InteractionHandler, options?: { source?: string }): Unsubscribe;\n /** Push or clear a cursor claim on the priority stack (hover feedback). */\n claimCursor(token: string, cursor: Cursor | null, priority?: number): void;\n /**\n * Whether a hover claim holds the cursor: the pointer is over something a\n * click acts on instead of the tool (an annotation, text). A handler's hover\n * sees the claims of every handler above it, so a create handler asks this\n * to know whether its click would reach it (its ghost shows only then).\n */\n hasCursorClaim(): boolean;\n /** The resolved cursor string. */\n getCursor(): Cursor;\n /** The resolved cursor changed. */\n readonly onCursorChanged: EventHook<{ readonly cursor: Cursor }>;\n}\n\nexport const InteractionToken = createHostToken<InteractionHostCapability>(PublicInteractionToken);\n\n/**\n * Resolve a sample against a gesture's home page: prefer the source's\n * unclamped projection, fall back to the page hit only when it is the same\n * page. Null: this sample can't speak for the home page.\n */\nexport const samplePointOn = (sample: PointerSample, page: PageRef): Point | null =>\n sample.project?.(page) ??\n (sample.page?.ref.objectNumber === page.objectNumber ? sample.page.point : null);\n\n// The host entry is a superset of the public contract: everything public is reachable here too.\nexport * from './contract';\n"],"mappings":";;;AA2HA,MAAa,oBAAA,2BAAA,CAAA,CAAA,gBAAA,CAA8DA,iBAAAA,gBAAsB;;;;;;AAOjG,MAAa,iBAAiB,QAAuB,SACnD,OAAO,UAAU,IAAI,MACpB,OAAO,MAAM,IAAI,iBAAiB,KAAK,eAAe,OAAO,KAAK,QAAQ"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as ToolTouch, a as INTERACTION_DEFAULTS, b as FeedbackToken, c as InteractionSettings, d as RegisterToolOptions, f as Tool, g as ToolPointerEvent, h as ToolId, i as GestureStartedEvent, l as Modifiers, m as ToolCursors, n as GestureCancelledEvent, o as InteractionCapability, p as ToolChangedEvent, r as GestureEndedEvent, s as InteractionConfig, t as Cursor, u as PointerKind, x as PlatformFeedback, y as FeedbackPluginOptions } from "../contract-C9IFDdDd.cjs";
|
|
2
|
+
import { a as InteractionToken, c as samplePointOn, i as InteractionHostCapability, n as HostToolInput, o as Phase, r as InteractionHandler, s as PointerSample, t as HostTool } from "../host-contract-DCb-QVfd.cjs";
|
|
3
|
+
export { Cursor, type FeedbackPluginOptions, FeedbackToken, GestureCancelledEvent, GestureEndedEvent, GestureStartedEvent, HostTool, HostToolInput, INTERACTION_DEFAULTS, InteractionCapability, InteractionConfig, InteractionHandler, InteractionHostCapability, InteractionSettings, InteractionToken, Modifiers, Phase, type PlatformFeedback, PointerKind, PointerSample, RegisterToolOptions, Tool, ToolChangedEvent, ToolCursors, ToolId, ToolPointerEvent, ToolTouch, samplePointOn };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as ToolTouch, a as INTERACTION_DEFAULTS, b as FeedbackToken, c as InteractionSettings, d as RegisterToolOptions, f as Tool, g as ToolPointerEvent, h as ToolId, i as GestureStartedEvent, l as Modifiers, m as ToolCursors, n as GestureCancelledEvent, o as InteractionCapability, p as ToolChangedEvent, r as GestureEndedEvent, s as InteractionConfig, t as Cursor, u as PointerKind, x as PlatformFeedback, y as FeedbackPluginOptions } from "../contract-C9IFDdDd.js";
|
|
2
|
+
import { a as InteractionToken, c as samplePointOn, i as InteractionHostCapability, n as HostToolInput, o as Phase, r as InteractionHandler, s as PointerSample, t as HostTool } from "../host-contract-Crcu-9DW.js";
|
|
3
|
+
export { Cursor, type FeedbackPluginOptions, FeedbackToken, GestureCancelledEvent, GestureEndedEvent, GestureStartedEvent, HostTool, HostToolInput, INTERACTION_DEFAULTS, InteractionCapability, InteractionConfig, InteractionHandler, InteractionHostCapability, InteractionSettings, InteractionToken, Modifiers, Phase, type PlatformFeedback, PointerKind, PointerSample, RegisterToolOptions, Tool, ToolChangedEvent, ToolCursors, ToolId, ToolPointerEvent, ToolTouch, samplePointOn };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as InteractionToken$1, r as FeedbackToken, t as INTERACTION_DEFAULTS } from "../contract-CmEMPz9L.js";
|
|
2
|
+
import { createHostToken } from "@embedpdf/core";
|
|
3
|
+
//#region src/host-contract.ts
|
|
4
|
+
const InteractionToken = createHostToken(InteractionToken$1);
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a sample against a gesture's home page: prefer the source's
|
|
7
|
+
* unclamped projection, fall back to the page hit only when it is the same
|
|
8
|
+
* page. Null: this sample can't speak for the home page.
|
|
9
|
+
*/
|
|
10
|
+
const samplePointOn = (sample, page) => sample.project?.(page) ?? (sample.page?.ref.objectNumber === page.objectNumber ? sample.page.point : null);
|
|
11
|
+
//#endregion
|
|
12
|
+
export { FeedbackToken, INTERACTION_DEFAULTS, InteractionToken, samplePointOn };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":["PublicInteractionToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["import { createHostToken, type EventHook, type PageRef, type Unsubscribe } from '@embedpdf/core';\nimport type { PageRotation, Point } from '@embedpdf/core-geometry';\n\nimport { InteractionToken as PublicInteractionToken } from './contract';\nimport type {\n Cursor,\n InteractionCapability,\n Modifiers,\n PointerKind,\n RegisterToolOptions,\n Tool,\n ToolId,\n} from './contract';\n\n/**\n * A tool as plugins see it: a public tool plus the behavior tags it turns on.\n * A tool doesn't act by itself: handlers opt into tags (`enabledFor`), so a\n * tool composes features without depending on them. A tool registered without\n * tags has none.\n */\nexport interface HostTool extends Tool {\n /** The behavior tags the tool turns on, such as `'text-select'` or `'annotation-draw'`. */\n readonly enables: ReadonlySet<string>;\n /**\n * The cursor over the space between pages. Most tools act only on pages, so\n * the gaps show the plain arrow (`'default'`); a tool that works anywhere\n * (pan) names its own (`'grab'`). Hover claims outrank both.\n */\n readonly gapCursor?: Cursor;\n}\n\n/** A tool as a plugin registers it: its tags may be left out. */\nexport type HostToolInput = Tool & Partial<Pick<HostTool, 'enables' | 'gapCursor'>>;\n\nexport type Phase = 'down' | 'move' | 'up' | 'cancel';\n\n/**\n * One normalized pointer event. `viewport` is the source container's px. `page`\n * is the resolved page hit (its `ref` and page-space point), present when the\n * pointer is over a page, absent over gaps.\n */\nexport interface PointerSample {\n phase: Phase;\n viewport: Point;\n /** `scale` = view px per page unit; `rotation` = the page's total display\n * rotation; `zoom` = the page's zoom relative to its 100% baseline. */\n page?: {\n ref: PageRef;\n point: Point;\n scale?: number;\n rotation?: PageRotation;\n zoom?: number;\n };\n modifiers: Modifiers;\n /** Click count for a `down` (1 single, 2 double, 3 triple). Defaults to 1. */\n clickCount?: number;\n /** Absent when the source can't say: treat as 'mouse'. */\n pointerType?: PointerKind;\n /** Present when the sample was synthesized from a recognized gesture. */\n gesture?: 'long-press';\n /** The lens this sample came from (the stage plugin id); absent = route everywhere. */\n source?: string;\n /** Project this event onto a specific page's frame, unclamped; null when the source cannot. */\n project?(page: PageRef): Point | null;\n}\n\n/**\n * A pointer handler contributed by a feature plugin: it declares which tools\n * it is live under and a priority; the hub routes each gesture to the first\n * 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: HostTool): 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 /** The gesture was aborted, not completed. Falls back to `onUp` when absent. */\n onCancel?(sample: PointerSample): void;\n /** Pointer moved with no active gesture: cursor feedback only. */\n onHover?(sample: PointerSample): void;\n /** Touch consent, second rung: a pure read asked before a touch contact is classified. */\n claimsTouch?(sample: PointerSample): boolean;\n}\n\n/**\n * The host lens: what pointer sources (the Stage surface, `PagePointerSource`)\n * and feature plugins with gestures need. The same runtime token as the\n * public contract, typed wider. Application code never needs it.\n */\nexport interface InteractionHostCapability extends InteractionCapability {\n getActiveTool(): HostTool;\n listTools(): readonly HostTool[];\n getTool(id: ToolId): HostTool | null;\n /** Add a tool, with the behavior tags it turns on. The rules are those of the public `registerTool`. */\n registerTool(tool: HostToolInput, options?: RegisterToolOptions): Unsubscribe;\n /** Whether the active tool turns on a behavior tag such as `'text-select'`. */\n activeToolEnables(behavior: string): boolean;\n /** Pointer ingress: a source calls it for every normalized event. */\n dispatchPointer(sample: PointerSample): void;\n /** Touch-arbitration pre-flight: would any eligible handler claim this contact. Pure. */\n wouldClaimTouch(sample: PointerSample): boolean;\n /** Register a pointer handler; `source` scopes it to one lens. */\n registerHandler(handler: InteractionHandler, options?: { source?: string }): Unsubscribe;\n /** Push or clear a cursor claim on the priority stack (hover feedback). */\n claimCursor(token: string, cursor: Cursor | null, priority?: number): void;\n /**\n * Whether a hover claim holds the cursor: the pointer is over something a\n * click acts on instead of the tool (an annotation, text). A handler's hover\n * sees the claims of every handler above it, so a create handler asks this\n * to know whether its click would reach it (its ghost shows only then).\n */\n hasCursorClaim(): boolean;\n /** The resolved cursor string. */\n getCursor(): Cursor;\n /** The resolved cursor changed. */\n readonly onCursorChanged: EventHook<{ readonly cursor: Cursor }>;\n}\n\nexport const InteractionToken = createHostToken<InteractionHostCapability>(PublicInteractionToken);\n\n/**\n * Resolve a sample against a gesture's home page: prefer the source's\n * unclamped projection, fall back to the page hit only when it is the same\n * page. Null: this sample can't speak for the home page.\n */\nexport const samplePointOn = (sample: PointerSample, page: PageRef): Point | null =>\n sample.project?.(page) ??\n (sample.page?.ref.objectNumber === page.objectNumber ? sample.page.point : null);\n\n// The host entry is a superset of the public contract: everything public is reachable here too.\nexport * from './contract';\n"],"mappings":";;;AA2HA,MAAa,mBAAmB,gBAA2CA,kBAAsB;;;;;;AAOjG,MAAa,iBAAiB,QAAuB,SACnD,OAAO,UAAU,IAAI,MACpB,OAAO,MAAM,IAAI,iBAAiB,KAAK,eAAe,OAAO,KAAK,QAAQ"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { DeepPartial, EventHook, PageRef, SettingsApi, Unsubscribe } from "@embedpdf/core";
|
|
2
|
+
import { Point } from "@embedpdf/core-geometry";
|
|
3
|
+
//#region src/feedback.types.d.ts
|
|
4
|
+
interface PlatformFeedback {
|
|
5
|
+
selection(): void;
|
|
6
|
+
impact(weight?: 'light' | 'medium' | 'heavy'): void;
|
|
7
|
+
notify(kind: 'success' | 'warning' | 'error'): void;
|
|
8
|
+
}
|
|
9
|
+
declare const FeedbackToken: import("@embedpdf/core").CapabilityToken<PlatformFeedback>;
|
|
10
|
+
interface FeedbackPluginOptions {
|
|
11
|
+
provider?: PlatformFeedback;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/token.d.ts
|
|
15
|
+
declare const InteractionToken: import("@embedpdf/core").CapabilityToken<InteractionCapability>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/contract.d.ts
|
|
18
|
+
type ToolId = string;
|
|
19
|
+
/** A CSS cursor: a keyword such as `'crosshair'`, or an image built with `svgCursor()`. */
|
|
20
|
+
type Cursor = string;
|
|
21
|
+
interface Modifiers {
|
|
22
|
+
readonly shift: boolean;
|
|
23
|
+
readonly alt: boolean;
|
|
24
|
+
readonly ctrl: boolean;
|
|
25
|
+
readonly meta: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The physical device class behind a pointer: `PointerEvent.pointerType`. */
|
|
28
|
+
type PointerKind = 'mouse' | 'pen' | 'touch';
|
|
29
|
+
/**
|
|
30
|
+
* What one finger does on a touch screen while the tool is active. `'draw'`:
|
|
31
|
+
* one finger drives the tool, and two fingers scroll and zoom, for tools you
|
|
32
|
+
* drag with. `'tap'`: a tap is a click and a drag scrolls, for tools you click
|
|
33
|
+
* with.
|
|
34
|
+
*/
|
|
35
|
+
type ToolTouch = 'draw' | 'tap';
|
|
36
|
+
/** The pointer on a page, as a tool's own pointer methods receive it. */
|
|
37
|
+
interface ToolPointerEvent {
|
|
38
|
+
/** The page under the pointer. During a gesture the tool took, the page it started on. */
|
|
39
|
+
readonly page: PageRef;
|
|
40
|
+
/**
|
|
41
|
+
* Where on that page, in page coordinates. During a gesture that leaves its
|
|
42
|
+
* page, the point lies outside the page's box.
|
|
43
|
+
*/
|
|
44
|
+
readonly point: Point;
|
|
45
|
+
readonly modifiers: Modifiers;
|
|
46
|
+
readonly pointerType: PointerKind;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A tool: what the pointer does on the page while it is active. `pointer` and
|
|
50
|
+
* `pan` are built in, and plugins add their own. A tool of your own handles
|
|
51
|
+
* the pointer itself with its pointer methods, in page coordinates.
|
|
52
|
+
*/
|
|
53
|
+
interface Tool {
|
|
54
|
+
/** The tool's name, for `activateTool(id)`. */
|
|
55
|
+
readonly id: ToolId;
|
|
56
|
+
/** The cursor over the page while the tool is active. */
|
|
57
|
+
readonly cursor: Cursor;
|
|
58
|
+
/** What one finger does on a touch screen. Default `'tap'`. */
|
|
59
|
+
readonly touch?: ToolTouch;
|
|
60
|
+
/**
|
|
61
|
+
* A press on a page. Return `true` to take the gesture: its moves and its
|
|
62
|
+
* release then come to `onPointerMove` and `onPointerUp`, and nothing else
|
|
63
|
+
* acts on it.
|
|
64
|
+
*/
|
|
65
|
+
onPointerDown?(event: ToolPointerEvent): boolean | void;
|
|
66
|
+
/** The pointer moved during a gesture the tool took. */
|
|
67
|
+
onPointerMove?(event: ToolPointerEvent): void;
|
|
68
|
+
/**
|
|
69
|
+
* The gesture the tool took ended: the button or finger was released, or the
|
|
70
|
+
* gesture was cancelled, for example by a second finger.
|
|
71
|
+
*/
|
|
72
|
+
onPointerUp?(event: ToolPointerEvent): void;
|
|
73
|
+
/** The pointer moved over a page with no button pressed. */
|
|
74
|
+
onHover?(event: ToolPointerEvent): void;
|
|
75
|
+
}
|
|
76
|
+
/** A tool's cursors replaced by name: "while this tool is active, show cursor X as Y". */
|
|
77
|
+
type ToolCursors = Readonly<Record<Cursor, Cursor>>;
|
|
78
|
+
/**
|
|
79
|
+
* The interaction plugin's settings. `interactionPlugin(config)` registers
|
|
80
|
+
* them over {@link INTERACTION_DEFAULTS}, and `updateSettings()` changes them
|
|
81
|
+
* for every document while the app runs.
|
|
82
|
+
*/
|
|
83
|
+
interface InteractionSettings {
|
|
84
|
+
/** The tool that's active when a document opens. */
|
|
85
|
+
readonly defaultTool: ToolId;
|
|
86
|
+
/** Tools of your own, registered from the start beside the built-in ones. */
|
|
87
|
+
readonly tools: readonly Tool[];
|
|
88
|
+
}
|
|
89
|
+
/** What the interaction settings are when the app registers none. */
|
|
90
|
+
declare const INTERACTION_DEFAULTS: InteractionSettings;
|
|
91
|
+
/** What `interactionPlugin(config)` takes: any of the settings, merged over the defaults. */
|
|
92
|
+
type InteractionConfig = DeepPartial<InteractionSettings>;
|
|
93
|
+
interface RegisterToolOptions {
|
|
94
|
+
/** Replace a tool registered under the same id instead of refusing. */
|
|
95
|
+
readonly replace?: boolean;
|
|
96
|
+
}
|
|
97
|
+
interface ToolChangedEvent {
|
|
98
|
+
readonly toolId: ToolId;
|
|
99
|
+
readonly previousToolId: ToolId;
|
|
100
|
+
}
|
|
101
|
+
interface GestureStartedEvent {
|
|
102
|
+
/** The tool that was active when the gesture began. */
|
|
103
|
+
readonly toolId: ToolId;
|
|
104
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
105
|
+
readonly page: PageRef | null;
|
|
106
|
+
readonly pointerType: PointerKind;
|
|
107
|
+
}
|
|
108
|
+
interface GestureEndedEvent {
|
|
109
|
+
/** The tool that was active when the gesture began. */
|
|
110
|
+
readonly toolId: ToolId;
|
|
111
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
112
|
+
readonly page: PageRef | null;
|
|
113
|
+
readonly pointerType: PointerKind;
|
|
114
|
+
}
|
|
115
|
+
interface GestureCancelledEvent {
|
|
116
|
+
/** The tool that was active when the gesture began. */
|
|
117
|
+
readonly toolId: ToolId;
|
|
118
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
119
|
+
readonly page: PageRef | null;
|
|
120
|
+
readonly pointerType: PointerKind;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The tools of one document: which one is active, the tools you can switch
|
|
124
|
+
* to, and the events that report tool changes and gestures. Its settings
|
|
125
|
+
* (`getSettings`, `updateSettings`, `resetSettings`, `onSettingsChanged`)
|
|
126
|
+
* belong to the plugin, not to a document: a change reaches every open
|
|
127
|
+
* document.
|
|
128
|
+
*/
|
|
129
|
+
interface InteractionCapability extends SettingsApi<InteractionSettings> {
|
|
130
|
+
/** The active tool. */
|
|
131
|
+
getActiveTool(): Tool;
|
|
132
|
+
getActiveToolId(): ToolId;
|
|
133
|
+
/** The tool a document opens with: the `defaultTool` setting. */
|
|
134
|
+
getDefaultToolId(): ToolId;
|
|
135
|
+
/** Every tool, in the order they were added, the built-in ones first. The same array until a tool is added or removed. */
|
|
136
|
+
listTools(): readonly Tool[];
|
|
137
|
+
getTool(id: ToolId): Tool | null;
|
|
138
|
+
hasTool(id: ToolId): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Make a tool the active one, and forget the tools `pushTool` saved. Fires
|
|
141
|
+
* `onToolChanged`. Throws `not-found` for an id that isn't registered.
|
|
142
|
+
*/
|
|
143
|
+
activateTool(id: ToolId): void;
|
|
144
|
+
/** Make the default tool the active one. Fires `onToolChanged`. */
|
|
145
|
+
activateDefaultTool(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Make a tool the active one for a moment, remembering the active one for
|
|
148
|
+
* `popTool`. Fires `onToolChanged`. Throws `not-found` for an id that isn't
|
|
149
|
+
* registered.
|
|
150
|
+
*/
|
|
151
|
+
pushTool(id: ToolId): void;
|
|
152
|
+
/** Go back to the tool active before the last `pushTool`; nothing to go back to does nothing. */
|
|
153
|
+
popTool(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Replace a tool's cursors by name while the app runs (`{ crosshair: penCursor }`);
|
|
156
|
+
* `null` brings the tool's own back.
|
|
157
|
+
*/
|
|
158
|
+
setToolCursor(id: ToolId, cursors: ToolCursors | null): void;
|
|
159
|
+
/**
|
|
160
|
+
* Add a tool, and return a function that removes it again. Throws
|
|
161
|
+
* `conflict` for an id that's taken, unless `{ replace: true }`; the
|
|
162
|
+
* function only removes this registration, not a later one with its id.
|
|
163
|
+
*/
|
|
164
|
+
registerTool(tool: Tool, options?: RegisterToolOptions): Unsubscribe;
|
|
165
|
+
/**
|
|
166
|
+
* A tool became active (`activateTool`, `activateDefaultTool`, `pushTool`,
|
|
167
|
+
* `popTool`), including activating the active tool again.
|
|
168
|
+
*/
|
|
169
|
+
readonly onToolChanged: EventHook<ToolChangedEvent>;
|
|
170
|
+
/** A press began a gesture that a tool took. */
|
|
171
|
+
readonly onGestureStarted: EventHook<GestureStartedEvent>;
|
|
172
|
+
/** That gesture ended with a release. */
|
|
173
|
+
readonly onGestureEnded: EventHook<GestureEndedEvent>;
|
|
174
|
+
/** That gesture was cancelled, for example by a second finger. */
|
|
175
|
+
readonly onGestureCancelled: EventHook<GestureCancelledEvent>;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { ToolTouch as _, INTERACTION_DEFAULTS as a, FeedbackToken as b, InteractionSettings as c, RegisterToolOptions as d, Tool as f, ToolPointerEvent as g, ToolId as h, GestureStartedEvent as i, Modifiers as l, ToolCursors as m, GestureCancelledEvent as n, InteractionCapability as o, ToolChangedEvent as p, GestureEndedEvent as r, InteractionConfig as s, Cursor as t, PointerKind as u, InteractionToken as v, PlatformFeedback as x, FeedbackPluginOptions as y };
|
|
179
|
+
//# sourceMappingURL=contract-C9IFDdDd.d.cts.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { DeepPartial, EventHook, PageRef, SettingsApi, Unsubscribe } from "@embedpdf/core";
|
|
2
|
+
import { Point } from "@embedpdf/core-geometry";
|
|
3
|
+
//#region src/feedback.types.d.ts
|
|
4
|
+
interface PlatformFeedback {
|
|
5
|
+
selection(): void;
|
|
6
|
+
impact(weight?: 'light' | 'medium' | 'heavy'): void;
|
|
7
|
+
notify(kind: 'success' | 'warning' | 'error'): void;
|
|
8
|
+
}
|
|
9
|
+
declare const FeedbackToken: import("@embedpdf/core").CapabilityToken<PlatformFeedback>;
|
|
10
|
+
interface FeedbackPluginOptions {
|
|
11
|
+
provider?: PlatformFeedback;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/token.d.ts
|
|
15
|
+
declare const InteractionToken: import("@embedpdf/core").CapabilityToken<InteractionCapability>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/contract.d.ts
|
|
18
|
+
type ToolId = string;
|
|
19
|
+
/** A CSS cursor: a keyword such as `'crosshair'`, or an image built with `svgCursor()`. */
|
|
20
|
+
type Cursor = string;
|
|
21
|
+
interface Modifiers {
|
|
22
|
+
readonly shift: boolean;
|
|
23
|
+
readonly alt: boolean;
|
|
24
|
+
readonly ctrl: boolean;
|
|
25
|
+
readonly meta: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The physical device class behind a pointer: `PointerEvent.pointerType`. */
|
|
28
|
+
type PointerKind = 'mouse' | 'pen' | 'touch';
|
|
29
|
+
/**
|
|
30
|
+
* What one finger does on a touch screen while the tool is active. `'draw'`:
|
|
31
|
+
* one finger drives the tool, and two fingers scroll and zoom, for tools you
|
|
32
|
+
* drag with. `'tap'`: a tap is a click and a drag scrolls, for tools you click
|
|
33
|
+
* with.
|
|
34
|
+
*/
|
|
35
|
+
type ToolTouch = 'draw' | 'tap';
|
|
36
|
+
/** The pointer on a page, as a tool's own pointer methods receive it. */
|
|
37
|
+
interface ToolPointerEvent {
|
|
38
|
+
/** The page under the pointer. During a gesture the tool took, the page it started on. */
|
|
39
|
+
readonly page: PageRef;
|
|
40
|
+
/**
|
|
41
|
+
* Where on that page, in page coordinates. During a gesture that leaves its
|
|
42
|
+
* page, the point lies outside the page's box.
|
|
43
|
+
*/
|
|
44
|
+
readonly point: Point;
|
|
45
|
+
readonly modifiers: Modifiers;
|
|
46
|
+
readonly pointerType: PointerKind;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A tool: what the pointer does on the page while it is active. `pointer` and
|
|
50
|
+
* `pan` are built in, and plugins add their own. A tool of your own handles
|
|
51
|
+
* the pointer itself with its pointer methods, in page coordinates.
|
|
52
|
+
*/
|
|
53
|
+
interface Tool {
|
|
54
|
+
/** The tool's name, for `activateTool(id)`. */
|
|
55
|
+
readonly id: ToolId;
|
|
56
|
+
/** The cursor over the page while the tool is active. */
|
|
57
|
+
readonly cursor: Cursor;
|
|
58
|
+
/** What one finger does on a touch screen. Default `'tap'`. */
|
|
59
|
+
readonly touch?: ToolTouch;
|
|
60
|
+
/**
|
|
61
|
+
* A press on a page. Return `true` to take the gesture: its moves and its
|
|
62
|
+
* release then come to `onPointerMove` and `onPointerUp`, and nothing else
|
|
63
|
+
* acts on it.
|
|
64
|
+
*/
|
|
65
|
+
onPointerDown?(event: ToolPointerEvent): boolean | void;
|
|
66
|
+
/** The pointer moved during a gesture the tool took. */
|
|
67
|
+
onPointerMove?(event: ToolPointerEvent): void;
|
|
68
|
+
/**
|
|
69
|
+
* The gesture the tool took ended: the button or finger was released, or the
|
|
70
|
+
* gesture was cancelled, for example by a second finger.
|
|
71
|
+
*/
|
|
72
|
+
onPointerUp?(event: ToolPointerEvent): void;
|
|
73
|
+
/** The pointer moved over a page with no button pressed. */
|
|
74
|
+
onHover?(event: ToolPointerEvent): void;
|
|
75
|
+
}
|
|
76
|
+
/** A tool's cursors replaced by name: "while this tool is active, show cursor X as Y". */
|
|
77
|
+
type ToolCursors = Readonly<Record<Cursor, Cursor>>;
|
|
78
|
+
/**
|
|
79
|
+
* The interaction plugin's settings. `interactionPlugin(config)` registers
|
|
80
|
+
* them over {@link INTERACTION_DEFAULTS}, and `updateSettings()` changes them
|
|
81
|
+
* for every document while the app runs.
|
|
82
|
+
*/
|
|
83
|
+
interface InteractionSettings {
|
|
84
|
+
/** The tool that's active when a document opens. */
|
|
85
|
+
readonly defaultTool: ToolId;
|
|
86
|
+
/** Tools of your own, registered from the start beside the built-in ones. */
|
|
87
|
+
readonly tools: readonly Tool[];
|
|
88
|
+
}
|
|
89
|
+
/** What the interaction settings are when the app registers none. */
|
|
90
|
+
declare const INTERACTION_DEFAULTS: InteractionSettings;
|
|
91
|
+
/** What `interactionPlugin(config)` takes: any of the settings, merged over the defaults. */
|
|
92
|
+
type InteractionConfig = DeepPartial<InteractionSettings>;
|
|
93
|
+
interface RegisterToolOptions {
|
|
94
|
+
/** Replace a tool registered under the same id instead of refusing. */
|
|
95
|
+
readonly replace?: boolean;
|
|
96
|
+
}
|
|
97
|
+
interface ToolChangedEvent {
|
|
98
|
+
readonly toolId: ToolId;
|
|
99
|
+
readonly previousToolId: ToolId;
|
|
100
|
+
}
|
|
101
|
+
interface GestureStartedEvent {
|
|
102
|
+
/** The tool that was active when the gesture began. */
|
|
103
|
+
readonly toolId: ToolId;
|
|
104
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
105
|
+
readonly page: PageRef | null;
|
|
106
|
+
readonly pointerType: PointerKind;
|
|
107
|
+
}
|
|
108
|
+
interface GestureEndedEvent {
|
|
109
|
+
/** The tool that was active when the gesture began. */
|
|
110
|
+
readonly toolId: ToolId;
|
|
111
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
112
|
+
readonly page: PageRef | null;
|
|
113
|
+
readonly pointerType: PointerKind;
|
|
114
|
+
}
|
|
115
|
+
interface GestureCancelledEvent {
|
|
116
|
+
/** The tool that was active when the gesture began. */
|
|
117
|
+
readonly toolId: ToolId;
|
|
118
|
+
/** The page the gesture began on, or null over the space between pages. */
|
|
119
|
+
readonly page: PageRef | null;
|
|
120
|
+
readonly pointerType: PointerKind;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The tools of one document: which one is active, the tools you can switch
|
|
124
|
+
* to, and the events that report tool changes and gestures. Its settings
|
|
125
|
+
* (`getSettings`, `updateSettings`, `resetSettings`, `onSettingsChanged`)
|
|
126
|
+
* belong to the plugin, not to a document: a change reaches every open
|
|
127
|
+
* document.
|
|
128
|
+
*/
|
|
129
|
+
interface InteractionCapability extends SettingsApi<InteractionSettings> {
|
|
130
|
+
/** The active tool. */
|
|
131
|
+
getActiveTool(): Tool;
|
|
132
|
+
getActiveToolId(): ToolId;
|
|
133
|
+
/** The tool a document opens with: the `defaultTool` setting. */
|
|
134
|
+
getDefaultToolId(): ToolId;
|
|
135
|
+
/** Every tool, in the order they were added, the built-in ones first. The same array until a tool is added or removed. */
|
|
136
|
+
listTools(): readonly Tool[];
|
|
137
|
+
getTool(id: ToolId): Tool | null;
|
|
138
|
+
hasTool(id: ToolId): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Make a tool the active one, and forget the tools `pushTool` saved. Fires
|
|
141
|
+
* `onToolChanged`. Throws `not-found` for an id that isn't registered.
|
|
142
|
+
*/
|
|
143
|
+
activateTool(id: ToolId): void;
|
|
144
|
+
/** Make the default tool the active one. Fires `onToolChanged`. */
|
|
145
|
+
activateDefaultTool(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Make a tool the active one for a moment, remembering the active one for
|
|
148
|
+
* `popTool`. Fires `onToolChanged`. Throws `not-found` for an id that isn't
|
|
149
|
+
* registered.
|
|
150
|
+
*/
|
|
151
|
+
pushTool(id: ToolId): void;
|
|
152
|
+
/** Go back to the tool active before the last `pushTool`; nothing to go back to does nothing. */
|
|
153
|
+
popTool(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Replace a tool's cursors by name while the app runs (`{ crosshair: penCursor }`);
|
|
156
|
+
* `null` brings the tool's own back.
|
|
157
|
+
*/
|
|
158
|
+
setToolCursor(id: ToolId, cursors: ToolCursors | null): void;
|
|
159
|
+
/**
|
|
160
|
+
* Add a tool, and return a function that removes it again. Throws
|
|
161
|
+
* `conflict` for an id that's taken, unless `{ replace: true }`; the
|
|
162
|
+
* function only removes this registration, not a later one with its id.
|
|
163
|
+
*/
|
|
164
|
+
registerTool(tool: Tool, options?: RegisterToolOptions): Unsubscribe;
|
|
165
|
+
/**
|
|
166
|
+
* A tool became active (`activateTool`, `activateDefaultTool`, `pushTool`,
|
|
167
|
+
* `popTool`), including activating the active tool again.
|
|
168
|
+
*/
|
|
169
|
+
readonly onToolChanged: EventHook<ToolChangedEvent>;
|
|
170
|
+
/** A press began a gesture that a tool took. */
|
|
171
|
+
readonly onGestureStarted: EventHook<GestureStartedEvent>;
|
|
172
|
+
/** That gesture ended with a release. */
|
|
173
|
+
readonly onGestureEnded: EventHook<GestureEndedEvent>;
|
|
174
|
+
/** That gesture was cancelled, for example by a second finger. */
|
|
175
|
+
readonly onGestureCancelled: EventHook<GestureCancelledEvent>;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { ToolTouch as _, INTERACTION_DEFAULTS as a, FeedbackToken as b, InteractionSettings as c, RegisterToolOptions as d, Tool as f, ToolPointerEvent as g, ToolId as h, GestureStartedEvent as i, Modifiers as l, ToolCursors as m, GestureCancelledEvent as n, InteractionCapability as o, ToolChangedEvent as p, GestureEndedEvent as r, InteractionConfig as s, Cursor as t, PointerKind as u, InteractionToken as v, PlatformFeedback as x, FeedbackPluginOptions as y };
|
|
179
|
+
//# sourceMappingURL=contract-C9IFDdDd.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createCapabilityToken } from "@embedpdf/core";
|
|
2
|
+
//#region src/feedback.types.ts
|
|
3
|
+
const FeedbackToken = createCapabilityToken("feedback");
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/token.ts
|
|
6
|
+
/** The package token, created once here; `contract.ts` re-exports it and
|
|
7
|
+
* `host-contract.ts` widens it. */
|
|
8
|
+
const InteractionToken = createCapabilityToken("interaction", { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list` });
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/contract.ts
|
|
11
|
+
/** What the interaction settings are when the app registers none. */
|
|
12
|
+
const INTERACTION_DEFAULTS = {
|
|
13
|
+
defaultTool: "pointer",
|
|
14
|
+
tools: []
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { InteractionToken as n, FeedbackToken as r, INTERACTION_DEFAULTS as t };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=contract-CmEMPz9L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-CmEMPz9L.js","names":[],"sources":["../src/feedback.types.ts","../src/token.ts","../src/contract.ts"],"sourcesContent":["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","/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { InteractionCapability } from './contract';\n\nexport const InteractionToken = createCapabilityToken<InteractionCapability>('interaction', {\n hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list`,\n});\n","import {\n type DeepPartial,\n type EventHook,\n type PageRef,\n type SettingsApi,\n type Unsubscribe,\n} from '@embedpdf/core';\nimport type { Point } from '@embedpdf/core-geometry';\n\nexport { FeedbackToken } from './feedback.types';\nexport type { FeedbackPluginOptions, PlatformFeedback } from './feedback.types';\n\nexport type ToolId = string;\n\n/** A CSS cursor: a keyword such as `'crosshair'`, or an image built with `svgCursor()`. */\nexport type Cursor = string;\n\nexport interface Modifiers {\n readonly shift: boolean;\n readonly alt: boolean;\n readonly ctrl: boolean;\n readonly meta: boolean;\n}\n\n/** The physical device class behind a pointer: `PointerEvent.pointerType`. */\nexport type PointerKind = 'mouse' | 'pen' | 'touch';\n\n/**\n * What one finger does on a touch screen while the tool is active. `'draw'`:\n * one finger drives the tool, and two fingers scroll and zoom, for tools you\n * drag with. `'tap'`: a tap is a click and a drag scrolls, for tools you click\n * with.\n */\nexport type ToolTouch = 'draw' | 'tap';\n\n/** The pointer on a page, as a tool's own pointer methods receive it. */\nexport interface ToolPointerEvent {\n /** The page under the pointer. During a gesture the tool took, the page it started on. */\n readonly page: PageRef;\n /**\n * Where on that page, in page coordinates. During a gesture that leaves its\n * page, the point lies outside the page's box.\n */\n readonly point: Point;\n readonly modifiers: Modifiers;\n readonly pointerType: PointerKind;\n}\n\n/**\n * A tool: what the pointer does on the page while it is active. `pointer` and\n * `pan` are built in, and plugins add their own. A tool of your own handles\n * the pointer itself with its pointer methods, in page coordinates.\n */\nexport interface Tool {\n /** The tool's name, for `activateTool(id)`. */\n readonly id: ToolId;\n /** The cursor over the page while the tool is active. */\n readonly cursor: Cursor;\n /** What one finger does on a touch screen. Default `'tap'`. */\n readonly touch?: ToolTouch;\n /**\n * A press on a page. Return `true` to take the gesture: its moves and its\n * release then come to `onPointerMove` and `onPointerUp`, and nothing else\n * acts on it.\n */\n onPointerDown?(event: ToolPointerEvent): boolean | void;\n /** The pointer moved during a gesture the tool took. */\n onPointerMove?(event: ToolPointerEvent): void;\n /**\n * The gesture the tool took ended: the button or finger was released, or the\n * gesture was cancelled, for example by a second finger.\n */\n onPointerUp?(event: ToolPointerEvent): void;\n /** The pointer moved over a page with no button pressed. */\n onHover?(event: ToolPointerEvent): void;\n}\n\n/** A tool's cursors replaced by name: \"while this tool is active, show cursor X as Y\". */\nexport type ToolCursors = Readonly<Record<Cursor, Cursor>>;\n\n// ── settings ──────────────────────────────────────────────────────────────\n\n/**\n * The interaction plugin's settings. `interactionPlugin(config)` registers\n * them over {@link INTERACTION_DEFAULTS}, and `updateSettings()` changes them\n * for every document while the app runs.\n */\nexport interface InteractionSettings {\n /** The tool that's active when a document opens. */\n readonly defaultTool: ToolId;\n /** Tools of your own, registered from the start beside the built-in ones. */\n readonly tools: readonly Tool[];\n}\n\n/** What the interaction settings are when the app registers none. */\nexport const INTERACTION_DEFAULTS: InteractionSettings = { defaultTool: 'pointer', tools: [] };\n\n/** What `interactionPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type InteractionConfig = DeepPartial<InteractionSettings>;\n\nexport interface RegisterToolOptions {\n /** Replace a tool registered under the same id instead of refusing. */\n readonly replace?: boolean;\n}\n\n// ── events ────────────────────────────────────────────────────────────────\n\nexport interface ToolChangedEvent {\n readonly toolId: ToolId;\n readonly previousToolId: ToolId;\n}\n\nexport interface GestureStartedEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\nexport interface GestureEndedEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\nexport interface GestureCancelledEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\n/**\n * The tools of one document: which one is active, the tools you can switch\n * to, and the events that report tool changes and gestures. Its settings\n * (`getSettings`, `updateSettings`, `resetSettings`, `onSettingsChanged`)\n * belong to the plugin, not to a document: a change reaches every open\n * document.\n */\nexport interface InteractionCapability extends SettingsApi<InteractionSettings> {\n /** The active tool. */\n getActiveTool(): Tool;\n getActiveToolId(): ToolId;\n /** The tool a document opens with: the `defaultTool` setting. */\n getDefaultToolId(): ToolId;\n /** Every tool, in the order they were added, the built-in ones first. The same array until a tool is added or removed. */\n listTools(): readonly Tool[];\n getTool(id: ToolId): Tool | null;\n hasTool(id: ToolId): boolean;\n /**\n * Make a tool the active one, and forget the tools `pushTool` saved. Fires\n * `onToolChanged`. Throws `not-found` for an id that isn't registered.\n */\n activateTool(id: ToolId): void;\n /** Make the default tool the active one. Fires `onToolChanged`. */\n activateDefaultTool(): void;\n /**\n * Make a tool the active one for a moment, remembering the active one for\n * `popTool`. Fires `onToolChanged`. Throws `not-found` for an id that isn't\n * registered.\n */\n pushTool(id: ToolId): void;\n /** Go back to the tool active before the last `pushTool`; nothing to go back to does nothing. */\n popTool(): void;\n /**\n * Replace a tool's cursors by name while the app runs (`{ crosshair: penCursor }`);\n * `null` brings the tool's own back.\n */\n setToolCursor(id: ToolId, cursors: ToolCursors | null): void;\n /**\n * Add a tool, and return a function that removes it again. Throws\n * `conflict` for an id that's taken, unless `{ replace: true }`; the\n * function only removes this registration, not a later one with its id.\n */\n registerTool(tool: Tool, options?: RegisterToolOptions): Unsubscribe;\n\n /**\n * A tool became active (`activateTool`, `activateDefaultTool`, `pushTool`,\n * `popTool`), including activating the active tool again.\n */\n readonly onToolChanged: EventHook<ToolChangedEvent>;\n /** A press began a gesture that a tool took. */\n readonly onGestureStarted: EventHook<GestureStartedEvent>;\n /** That gesture ended with a release. */\n readonly onGestureEnded: EventHook<GestureEndedEvent>;\n /** That gesture was cancelled, for example by a second finger. */\n readonly onGestureCancelled: EventHook<GestureCancelledEvent>;\n}\n\nexport { InteractionToken } from './token';\n"],"mappings":";;AAQA,MAAa,gBAAgB,sBAAwC,UAAU;;;;;ACF/E,MAAa,mBAAmB,sBAA6C,eAAe,EAC1F,MAAM,mFACR,CAAC;;;;ACuFD,MAAa,uBAA4C;CAAE,aAAa;CAAW,OAAO,CAAC;AAAE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
let _embedpdf_core = require("@embedpdf/core");
|
|
2
|
+
//#region src/feedback.types.ts
|
|
3
|
+
const FeedbackToken = (0, _embedpdf_core.createCapabilityToken)("feedback");
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/token.ts
|
|
6
|
+
/** The package token, created once here; `contract.ts` re-exports it and
|
|
7
|
+
* `host-contract.ts` widens it. */
|
|
8
|
+
const InteractionToken = (0, _embedpdf_core.createCapabilityToken)("interaction", { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list` });
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/contract.ts
|
|
11
|
+
/** What the interaction settings are when the app registers none. */
|
|
12
|
+
const INTERACTION_DEFAULTS = {
|
|
13
|
+
defaultTool: "pointer",
|
|
14
|
+
tools: []
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
Object.defineProperty(exports, "FeedbackToken", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return FeedbackToken;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "INTERACTION_DEFAULTS", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return INTERACTION_DEFAULTS;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "InteractionToken", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return InteractionToken;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=contract-yO6QKpba.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-yO6QKpba.cjs","names":[],"sources":["../src/feedback.types.ts","../src/token.ts","../src/contract.ts"],"sourcesContent":["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","/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { InteractionCapability } from './contract';\n\nexport const InteractionToken = createCapabilityToken<InteractionCapability>('interaction', {\n hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list`,\n});\n","import {\n type DeepPartial,\n type EventHook,\n type PageRef,\n type SettingsApi,\n type Unsubscribe,\n} from '@embedpdf/core';\nimport type { Point } from '@embedpdf/core-geometry';\n\nexport { FeedbackToken } from './feedback.types';\nexport type { FeedbackPluginOptions, PlatformFeedback } from './feedback.types';\n\nexport type ToolId = string;\n\n/** A CSS cursor: a keyword such as `'crosshair'`, or an image built with `svgCursor()`. */\nexport type Cursor = string;\n\nexport interface Modifiers {\n readonly shift: boolean;\n readonly alt: boolean;\n readonly ctrl: boolean;\n readonly meta: boolean;\n}\n\n/** The physical device class behind a pointer: `PointerEvent.pointerType`. */\nexport type PointerKind = 'mouse' | 'pen' | 'touch';\n\n/**\n * What one finger does on a touch screen while the tool is active. `'draw'`:\n * one finger drives the tool, and two fingers scroll and zoom, for tools you\n * drag with. `'tap'`: a tap is a click and a drag scrolls, for tools you click\n * with.\n */\nexport type ToolTouch = 'draw' | 'tap';\n\n/** The pointer on a page, as a tool's own pointer methods receive it. */\nexport interface ToolPointerEvent {\n /** The page under the pointer. During a gesture the tool took, the page it started on. */\n readonly page: PageRef;\n /**\n * Where on that page, in page coordinates. During a gesture that leaves its\n * page, the point lies outside the page's box.\n */\n readonly point: Point;\n readonly modifiers: Modifiers;\n readonly pointerType: PointerKind;\n}\n\n/**\n * A tool: what the pointer does on the page while it is active. `pointer` and\n * `pan` are built in, and plugins add their own. A tool of your own handles\n * the pointer itself with its pointer methods, in page coordinates.\n */\nexport interface Tool {\n /** The tool's name, for `activateTool(id)`. */\n readonly id: ToolId;\n /** The cursor over the page while the tool is active. */\n readonly cursor: Cursor;\n /** What one finger does on a touch screen. Default `'tap'`. */\n readonly touch?: ToolTouch;\n /**\n * A press on a page. Return `true` to take the gesture: its moves and its\n * release then come to `onPointerMove` and `onPointerUp`, and nothing else\n * acts on it.\n */\n onPointerDown?(event: ToolPointerEvent): boolean | void;\n /** The pointer moved during a gesture the tool took. */\n onPointerMove?(event: ToolPointerEvent): void;\n /**\n * The gesture the tool took ended: the button or finger was released, or the\n * gesture was cancelled, for example by a second finger.\n */\n onPointerUp?(event: ToolPointerEvent): void;\n /** The pointer moved over a page with no button pressed. */\n onHover?(event: ToolPointerEvent): void;\n}\n\n/** A tool's cursors replaced by name: \"while this tool is active, show cursor X as Y\". */\nexport type ToolCursors = Readonly<Record<Cursor, Cursor>>;\n\n// ── settings ──────────────────────────────────────────────────────────────\n\n/**\n * The interaction plugin's settings. `interactionPlugin(config)` registers\n * them over {@link INTERACTION_DEFAULTS}, and `updateSettings()` changes them\n * for every document while the app runs.\n */\nexport interface InteractionSettings {\n /** The tool that's active when a document opens. */\n readonly defaultTool: ToolId;\n /** Tools of your own, registered from the start beside the built-in ones. */\n readonly tools: readonly Tool[];\n}\n\n/** What the interaction settings are when the app registers none. */\nexport const INTERACTION_DEFAULTS: InteractionSettings = { defaultTool: 'pointer', tools: [] };\n\n/** What `interactionPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type InteractionConfig = DeepPartial<InteractionSettings>;\n\nexport interface RegisterToolOptions {\n /** Replace a tool registered under the same id instead of refusing. */\n readonly replace?: boolean;\n}\n\n// ── events ────────────────────────────────────────────────────────────────\n\nexport interface ToolChangedEvent {\n readonly toolId: ToolId;\n readonly previousToolId: ToolId;\n}\n\nexport interface GestureStartedEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\nexport interface GestureEndedEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\nexport interface GestureCancelledEvent {\n /** The tool that was active when the gesture began. */\n readonly toolId: ToolId;\n /** The page the gesture began on, or null over the space between pages. */\n readonly page: PageRef | null;\n readonly pointerType: PointerKind;\n}\n\n/**\n * The tools of one document: which one is active, the tools you can switch\n * to, and the events that report tool changes and gestures. Its settings\n * (`getSettings`, `updateSettings`, `resetSettings`, `onSettingsChanged`)\n * belong to the plugin, not to a document: a change reaches every open\n * document.\n */\nexport interface InteractionCapability extends SettingsApi<InteractionSettings> {\n /** The active tool. */\n getActiveTool(): Tool;\n getActiveToolId(): ToolId;\n /** The tool a document opens with: the `defaultTool` setting. */\n getDefaultToolId(): ToolId;\n /** Every tool, in the order they were added, the built-in ones first. The same array until a tool is added or removed. */\n listTools(): readonly Tool[];\n getTool(id: ToolId): Tool | null;\n hasTool(id: ToolId): boolean;\n /**\n * Make a tool the active one, and forget the tools `pushTool` saved. Fires\n * `onToolChanged`. Throws `not-found` for an id that isn't registered.\n */\n activateTool(id: ToolId): void;\n /** Make the default tool the active one. Fires `onToolChanged`. */\n activateDefaultTool(): void;\n /**\n * Make a tool the active one for a moment, remembering the active one for\n * `popTool`. Fires `onToolChanged`. Throws `not-found` for an id that isn't\n * registered.\n */\n pushTool(id: ToolId): void;\n /** Go back to the tool active before the last `pushTool`; nothing to go back to does nothing. */\n popTool(): void;\n /**\n * Replace a tool's cursors by name while the app runs (`{ crosshair: penCursor }`);\n * `null` brings the tool's own back.\n */\n setToolCursor(id: ToolId, cursors: ToolCursors | null): void;\n /**\n * Add a tool, and return a function that removes it again. Throws\n * `conflict` for an id that's taken, unless `{ replace: true }`; the\n * function only removes this registration, not a later one with its id.\n */\n registerTool(tool: Tool, options?: RegisterToolOptions): Unsubscribe;\n\n /**\n * A tool became active (`activateTool`, `activateDefaultTool`, `pushTool`,\n * `popTool`), including activating the active tool again.\n */\n readonly onToolChanged: EventHook<ToolChangedEvent>;\n /** A press began a gesture that a tool took. */\n readonly onGestureStarted: EventHook<GestureStartedEvent>;\n /** That gesture ended with a release. */\n readonly onGestureEnded: EventHook<GestureEndedEvent>;\n /** That gesture was cancelled, for example by a second finger. */\n readonly onGestureCancelled: EventHook<GestureCancelledEvent>;\n}\n\nexport { InteractionToken } from './token';\n"],"mappings":";;AAQA,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAAwD,UAAU;;;;;ACF/E,MAAa,oBAAA,GAAA,eAAA,sBAAA,CAAgE,eAAe,EAC1F,MAAM,mFACR,CAAC;;;;ACuFD,MAAa,uBAA4C;CAAE,aAAa;CAAW,OAAO,CAAC;AAAE"}
|
package/dist/contract.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_contract = require("./contract-
|
|
2
|
+
const require_contract = require("./contract-yO6QKpba.cjs");
|
|
3
3
|
exports.FeedbackToken = require_contract.FeedbackToken;
|
|
4
|
+
exports.INTERACTION_DEFAULTS = require_contract.INTERACTION_DEFAULTS;
|
|
4
5
|
exports.InteractionToken = require_contract.InteractionToken;
|
|
5
|
-
exports.samplePointOn = require_contract.samplePointOn;
|
package/dist/contract.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export {
|
|
1
|
+
import { _ as ToolTouch, a as INTERACTION_DEFAULTS, b as FeedbackToken, c as InteractionSettings, d as RegisterToolOptions, f as Tool, g as ToolPointerEvent, h as ToolId, i as GestureStartedEvent, l as Modifiers, m as ToolCursors, n as GestureCancelledEvent, o as InteractionCapability, p as ToolChangedEvent, r as GestureEndedEvent, s as InteractionConfig, t as Cursor, u as PointerKind, v as InteractionToken, x as PlatformFeedback, y as FeedbackPluginOptions } from "./contract-C9IFDdDd.cjs";
|
|
2
|
+
export { Cursor, type FeedbackPluginOptions, FeedbackToken, GestureCancelledEvent, GestureEndedEvent, GestureStartedEvent, INTERACTION_DEFAULTS, InteractionCapability, InteractionConfig, InteractionSettings, InteractionToken, Modifiers, type PlatformFeedback, PointerKind, RegisterToolOptions, Tool, ToolChangedEvent, ToolCursors, ToolId, ToolPointerEvent, ToolTouch };
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export {
|
|
1
|
+
import { _ as ToolTouch, a as INTERACTION_DEFAULTS, b as FeedbackToken, c as InteractionSettings, d as RegisterToolOptions, f as Tool, g as ToolPointerEvent, h as ToolId, i as GestureStartedEvent, l as Modifiers, m as ToolCursors, n as GestureCancelledEvent, o as InteractionCapability, p as ToolChangedEvent, r as GestureEndedEvent, s as InteractionConfig, t as Cursor, u as PointerKind, v as InteractionToken, x as PlatformFeedback, y as FeedbackPluginOptions } from "./contract-C9IFDdDd.js";
|
|
2
|
+
export { Cursor, type FeedbackPluginOptions, FeedbackToken, GestureCancelledEvent, GestureEndedEvent, GestureStartedEvent, INTERACTION_DEFAULTS, InteractionCapability, InteractionConfig, InteractionSettings, InteractionToken, Modifiers, type PlatformFeedback, PointerKind, RegisterToolOptions, Tool, ToolChangedEvent, ToolCursors, ToolId, ToolPointerEvent, ToolTouch };
|
package/dist/contract.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as InteractionToken, r as
|
|
2
|
-
export { FeedbackToken,
|
|
1
|
+
import { n as InteractionToken, r as FeedbackToken, t as INTERACTION_DEFAULTS } from "./contract-CmEMPz9L.js";
|
|
2
|
+
export { FeedbackToken, INTERACTION_DEFAULTS, InteractionToken };
|