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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/contract/host.cjs +16 -2
  2. package/dist/contract/host.cjs.map +1 -0
  3. package/dist/contract/host.d.cts +3 -2
  4. package/dist/contract/host.d.ts +3 -2
  5. package/dist/contract/host.js +16 -2
  6. package/dist/contract/host.js.map +1 -0
  7. package/dist/contract-BUiw1d8F.cjs +36 -0
  8. package/dist/contract-BUiw1d8F.cjs.map +1 -0
  9. package/dist/contract-DBXA64ep.js +26 -0
  10. package/dist/contract-DBXA64ep.js.map +1 -0
  11. package/dist/contract-DLs4vXVt.d.cts +252 -0
  12. package/dist/contract-DLs4vXVt.d.ts +252 -0
  13. package/dist/contract.cjs +3 -6
  14. package/dist/contract.d.cts +2 -7
  15. package/dist/contract.d.ts +2 -7
  16. package/dist/contract.js +2 -7
  17. package/dist/host-contract-DO2aLU2e.d.ts +34 -0
  18. package/dist/host-contract-Ddo4PcJJ.d.cts +34 -0
  19. package/dist/index.cjs +777 -51
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +97 -29
  22. package/dist/index.d.ts +97 -29
  23. package/dist/index.js +772 -51
  24. package/dist/index.js.map +1 -1
  25. package/package.json +5 -9
  26. package/dist/contract.cjs.map +0 -1
  27. package/dist/contract.js.map +0 -1
  28. package/dist/internal.cjs +0 -13
  29. package/dist/internal.d.cts +0 -63
  30. package/dist/internal.d.ts +0 -63
  31. package/dist/internal.js +0 -4
  32. package/dist/reducer-BAOQ2CJ8.cjs +0 -732
  33. package/dist/reducer-BAOQ2CJ8.cjs.map +0 -1
  34. package/dist/reducer-DbKtk9Xl.js +0 -685
  35. package/dist/reducer-DbKtk9Xl.js.map +0 -1
  36. package/dist/types-BVUcOsCh.js +0 -14
  37. package/dist/types-BVUcOsCh.js.map +0 -1
  38. package/dist/types-CUrUVl6K.d.cts +0 -292
  39. package/dist/types-CUrUVl6K.d.ts +0 -292
  40. package/dist/types-D9kEBMFj.cjs +0 -18
  41. package/dist/types-D9kEBMFj.cjs.map +0 -1
@@ -0,0 +1,252 @@
1
+ import { DeepPartial, EventHook, OperationOptions, PageRef, SettingsApi } from "@embedpdf/core";
2
+ import { Point, Quad, Rect } from "@embedpdf/core-geometry";
3
+ import { PdfTextSegment } from "@embedpdf/engine-core/runtime";
4
+ //#region src/geometry.d.ts
5
+ /**
6
+ * One merged visual line of a selection, as the engine's layout gives it.
7
+ * `quad` carries the corners, named in the line's own frame; `advance` is the
8
+ * reading direction along the baseline (+1 = toward the right end), derived
9
+ * from the glyph sequence, so geometry and bidi stay separate concerns.
10
+ * `rect` is its bounding box.
11
+ */
12
+ type SelectionSegment = PdfTextSegment;
13
+ //#endregion
14
+ //#region src/token.d.ts
15
+ declare const SelectionToken: import("@embedpdf/core").CapabilityToken<SelectionCapability>;
16
+ //#endregion
17
+ //#region src/contract.d.ts
18
+ /**
19
+ * The selection plugin's settings. `selectionPlugin(config)` registers them
20
+ * over {@link SELECTION_DEFAULTS}, and `updateSettings()` changes them for
21
+ * every document while the app runs. The colors and the shadow can also come
22
+ * from CSS (`--epdf-text-selection`, `--epdf-text-selection-handle`,
23
+ * `--epdf-text-selection-handle-shadow`), which wins over the setting.
24
+ */
25
+ interface SelectionSettings {
26
+ /** How far, in viewport pixels, the pointer travels before a press becomes a drag that selects. */
27
+ readonly dragThreshold: number;
28
+ /** The color of selected text: a CSS color, or `null` for the viewer's accent at 35%. */
29
+ readonly color: string | null;
30
+ /** The grips at the selection's ends, on touch screens. */
31
+ readonly handles: {
32
+ /** A CSS color, or `null` for the viewer's accent. */
33
+ readonly color: string | null;
34
+ /** A CSS `box-shadow`. */
35
+ readonly shadow: string;
36
+ };
37
+ }
38
+ /** What the selection settings are when the app registers none. */
39
+ declare const SELECTION_DEFAULTS: SelectionSettings;
40
+ /** What `selectionPlugin(config)` takes: any of the settings, merged over the defaults. */
41
+ type SelectionConfig = DeepPartial<SelectionSettings>;
42
+ /**
43
+ * A position in a page's character space — the space the engine's geometry
44
+ * runs tile (`PageGeometryRun.charStart`) and search hits address
45
+ * (`SearchMatch.charStart`). Not a string offset into extracted text; the
46
+ * two spaces are joined by the engine's `charMap` (see engine-core
47
+ * `text/charmap.ts`), which `readText()` applies for you.
48
+ */
49
+ interface TextPosition {
50
+ page: PageRef;
51
+ /** Character index, 0-based. */
52
+ index: number;
53
+ }
54
+ /**
55
+ * A half-open range in character space: `start` inclusive, `end` exclusive,
56
+ * in document order (`start` at or before `end`). `end.index` may be 0 to
57
+ * end a range exactly at a page boundary.
58
+ */
59
+ interface TextRange {
60
+ start: TextPosition;
61
+ end: TextPosition;
62
+ }
63
+ /**
64
+ * What {@link SelectionCapability.select} accepts: a cross-page
65
+ * {@link TextRange}, or a single-page span — the shape of a search hit, so
66
+ * `select({ page: hit.page, start: hit.charStart, count: hit.charCount })`
67
+ * needs no conversion.
68
+ */
69
+ type SelectionRangeInput = TextRange | {
70
+ page: PageRef;
71
+ start: number;
72
+ count: number;
73
+ };
74
+ /**
75
+ * A selection boundary, anchored to the boundary glyph's own oriented cell.
76
+ * `advance` is the reading direction of the segment it belongs to (+1 = the
77
+ * frame's +x), so caret consumers place at the trailing edge without
78
+ * re-deriving bidi from geometry. `rect` is the AABB (scroll targets).
79
+ */
80
+ interface SelectionEndpoint {
81
+ page: PageRef;
82
+ glyphQuad: Quad;
83
+ advance: 1 | -1;
84
+ rect: Rect;
85
+ }
86
+ /** Where selection-scoped floating UI attaches: a page + the selection's
87
+ * union box on it, in page space. See {@link SelectionCapability.getAnchor}. */
88
+ interface SelectionAnchor {
89
+ page: PageRef;
90
+ bounds: Rect;
91
+ }
92
+ interface SelectionSnapshot {
93
+ /** Per-page canonical segments — the one geometry consumers act on.
94
+ * Boxes are derived views (`segment.rect`, or `listRects()`). */
95
+ readonly pages: readonly {
96
+ page: PageRef;
97
+ segments: readonly SelectionSegment[];
98
+ }[];
99
+ readonly start: SelectionEndpoint | null;
100
+ readonly end: SelectionEndpoint | null;
101
+ readonly direction: 'forward' | 'backward';
102
+ /**
103
+ * The selection as a half-open character range in document order — a
104
+ * valid {@link SelectionCapability.select} input (persist and restore).
105
+ * Null when nothing is selected. Until a boundary page's text geometry
106
+ * has loaded, its index may still exceed the page's character count
107
+ * (`selectAll` settles as geometry arrives); consumers of the range
108
+ * (`select`, `readTextInRange`) clamp, so round-tripping is always safe.
109
+ */
110
+ readonly range: TextRange | null;
111
+ }
112
+ /**
113
+ * The selection's range or segments changed: a gesture step, a programmatic
114
+ * select, a boundary page's text geometry arriving, or a clear. Selection is
115
+ * session state, so the event carries no document origin.
116
+ */
117
+ interface SelectionChangedEvent {
118
+ readonly range: TextRange | null;
119
+ /** The pages that carry a segment right now. */
120
+ readonly pages: readonly PageRef[];
121
+ }
122
+ /** A selection gesture ended (pointer-up, handle release) with a selection in
123
+ * place — the commit point markup creation and clipboard prefetch act on.
124
+ * Never fires for programmatic selection. */
125
+ interface SelectionCommittedEvent {
126
+ readonly range: TextRange;
127
+ }
128
+ /** The selection went from a range to nothing. */
129
+ type SelectionClearedEvent = Record<string, never>;
130
+ /**
131
+ * The public selection API — the documented, stable surface for application
132
+ * code (toolbars, context menus, automation).
133
+ *
134
+ * The permission model: geometry enables selection (`doc.text.select`),
135
+ * text enables extraction (`doc.text.copy`) — neither implies the other.
136
+ * Everything here except the `readText` pair works with the select scope
137
+ * alone, so a deployment can allow selecting and highlighting while denying
138
+ * copy. Writes without the scope throw `PluginError('permission-denied')`;
139
+ * gate UI with {@link canSelect} / {@link canCopy}.
140
+ *
141
+ * Every gesture has a programmatic twin: drag = {@link select} (or
142
+ * `beginGestureAt` + {@link extendTo} for point-driven code on the host
143
+ * lens), double-click = {@link selectWordAt}, triple-click =
144
+ * {@link selectLineAt}, handle drag = {@link extendTo}, click on empty space
145
+ * = {@link clear}, select-all = {@link selectAll}.
146
+ *
147
+ * A page argument is a `PageRef` or a zero-based index. A verb given a page
148
+ * that isn't in the document throws `not-found`; a read returns empty.
149
+ *
150
+ * The settings (`getSettings`, `updateSettings`, `resetSettings`,
151
+ * `onSettingsChanged`) belong to the plugin, not to a document: a change
152
+ * reaches every open document.
153
+ *
154
+ * Framework-only plumbing (gesture bracketing, geometry warming, the
155
+ * highlight-visibility handshake) lives on `SelectionHostCapability`,
156
+ * reachable through `@embedpdf/plugin-selection/contract/host`. Both are the
157
+ * same runtime object — two typed lenses on one token.
158
+ */
159
+ interface SelectionCapability extends SettingsApi<SelectionSettings> {
160
+ /** Whether this caller may create selections at all (`doc.text.select`). */
161
+ canSelect(): boolean;
162
+ /** Whether this caller may extract literal text (`doc.text.copy`). */
163
+ canCopy(): boolean;
164
+ /**
165
+ * Select a range — the same path gestures use, so the highlight, events
166
+ * and markup bridges behave identically. An empty range clears. Throws
167
+ * `permission-denied` without `doc.text.select`, `not-found` for a page
168
+ * that is not in this document. Fires `onChanged`, or `onCleared`.
169
+ */
170
+ select(range: SelectionRangeInput): void;
171
+ /** Select every character of the document. Throws `permission-denied` without `doc.text.select`. */
172
+ selectAll(): void;
173
+ /**
174
+ * Select every character on one page. Throws `permission-denied` without
175
+ * `doc.text.select`, `not-found` for a page that is not in this document.
176
+ */
177
+ selectPage(page: PageRef | number): void;
178
+ /**
179
+ * Select the word around a page point. Returns false when the point has no
180
+ * selectable text (geometry not loaded yet, or no glyph there). Throws
181
+ * `permission-denied` without `doc.text.select`, `not-found` for a page that
182
+ * is not in this document.
183
+ */
184
+ selectWordAt(page: PageRef | number, point: Point): boolean;
185
+ /** Select the visual line around a page point. Same result and errors as {@link selectWordAt}. */
186
+ selectLineAt(page: PageRef | number, point: Point): boolean;
187
+ /**
188
+ * Extend the current selection to a page point (a drag step). No selection
189
+ * → no-op; a page whose geometry has not loaded is warmed and the extension
190
+ * lands when it arrives. Errors as {@link selectPage}.
191
+ */
192
+ extendTo(page: PageRef | number, point: Point): void;
193
+ /** Clear the selection. Always allowed. Fires `onCleared` when something was selected. */
194
+ clear(): void;
195
+ /** Whether anything is selected. */
196
+ hasSelection(): boolean;
197
+ /**
198
+ * Whether the user is still selecting: from the press of a drag, a
199
+ * double-click or a handle until it lifts. A selection made from code is
200
+ * never in progress.
201
+ */
202
+ isSelecting(): boolean;
203
+ /** Per-page segments, endpoints, direction and the range. Reference-stable
204
+ * until the selection changes. */
205
+ getSnapshot(): SelectionSnapshot;
206
+ /** The selected character range, or null. */
207
+ getRange(): TextRange | null;
208
+ /** The pages the current selection covers (those with at least one
209
+ * segment), in document order — so a cross-page action can fan out per page. */
210
+ listSelectedPages(): readonly PageRef[];
211
+ /** Per-line oriented segments for a page, in page space — build your own
212
+ * highlight layer from these. Reference-stable per page. */
213
+ listSegments(page: PageRef | number): readonly SelectionSegment[];
214
+ /** The segments' AABBs — for consumers that genuinely want boxes (scroll,
215
+ * conservative regions). Never a substitute for the oriented quads in
216
+ * geometry that gets drawn or persisted. */
217
+ listRects(page: PageRef | number): readonly Rect[];
218
+ /**
219
+ * Where selection-scoped floating UI should attach: the union box of the
220
+ * selection's segments on its end page (where the gesture finished),
221
+ * falling back to the last page with materialized segments while a
222
+ * boundary page's geometry is still loading. One anchor regardless of
223
+ * cross-page selection. Null when nothing is selected (or nothing has
224
+ * materialized yet).
225
+ */
226
+ getAnchor(): SelectionAnchor | null;
227
+ /**
228
+ * The selected text. Each page's text snapshot is fetched once per content
229
+ * version and sliced through the engine's `charMap`; pages are joined with
230
+ * `\n`. Resolves `''` when nothing is selected. Rejects `permission-denied`
231
+ * without `doc.text.copy`, and `operation-cancelled` when `options.signal`
232
+ * fires. Clipboard writes are deliberately not here — this package is
233
+ * DOM-free; use `@embedpdf/web`'s clipboard helpers.
234
+ */
235
+ readText(options?: OperationOptions): Promise<string>;
236
+ /**
237
+ * Text for any range, without touching the selection. Rejects as
238
+ * {@link readText} does, and `not-found` for a page that is not in this
239
+ * document.
240
+ */
241
+ readTextInRange(range: TextRange, options?: OperationOptions): Promise<string>;
242
+ /** The range or its segments changed, whoever changed them. */
243
+ readonly onChanged: EventHook<SelectionChangedEvent>;
244
+ /** A selection gesture ended with a selection in place. */
245
+ readonly onCommitted: EventHook<SelectionCommittedEvent>;
246
+ /** The selection went from a range to nothing: a clear, an empty range, or
247
+ * its pages' content changed or left the document. */
248
+ readonly onCleared: EventHook<SelectionClearedEvent>;
249
+ }
250
+ //#endregion
251
+ export { SelectionClearedEvent as a, SelectionEndpoint as c, SelectionSnapshot as d, TextPosition as f, SelectionSegment as h, SelectionChangedEvent as i, SelectionRangeInput as l, SelectionToken as m, SelectionAnchor as n, SelectionCommittedEvent as o, TextRange as p, SelectionCapability as r, SelectionConfig as s, SELECTION_DEFAULTS as t, SelectionSettings as u };
252
+ //# sourceMappingURL=contract-DLs4vXVt.d.ts.map
package/dist/contract.cjs CHANGED
@@ -1,7 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/contract.ts
3
- const SelectionToken = require("./types-D9kEBMFj.cjs").SelectionToken;
4
- //#endregion
5
- exports.SelectionToken = SelectionToken;
6
-
7
- //# sourceMappingURL=contract.cjs.map
2
+ const require_contract = require("./contract-BUiw1d8F.cjs");
3
+ exports.SELECTION_DEFAULTS = require_contract.SELECTION_DEFAULTS;
4
+ exports.SelectionToken = require_contract.SelectionToken;
@@ -1,7 +1,2 @@
1
- import { c as SelectionRangeInput, f as TextPosition, h as SelectionSegment, i as SelectionEndpoint, l as SelectionSnapshot, o as SelectionMenuAnchor, p as TextRange, r as SelectionCapability } from "./types-CUrUVl6K.cjs";
2
- import { CapabilityToken } from "@embedpdf/core";
3
- //#region src/contract.d.ts
4
- declare const SelectionToken: CapabilityToken<SelectionCapability>;
5
- //#endregion
6
- export { type SelectionCapability, type SelectionEndpoint, type SelectionMenuAnchor, type SelectionRangeInput, type SelectionSegment, type SelectionSnapshot, SelectionToken, type TextPosition, type TextRange };
7
- //# sourceMappingURL=contract.d.cts.map
1
+ import { a as SelectionClearedEvent, c as SelectionEndpoint, d as SelectionSnapshot, f as TextPosition, h as SelectionSegment, i as SelectionChangedEvent, l as SelectionRangeInput, m as SelectionToken, n as SelectionAnchor, o as SelectionCommittedEvent, p as TextRange, r as SelectionCapability, s as SelectionConfig, t as SELECTION_DEFAULTS, u as SelectionSettings } from "./contract-DLs4vXVt.cjs";
2
+ export { SELECTION_DEFAULTS, SelectionAnchor, SelectionCapability, SelectionChangedEvent, SelectionClearedEvent, SelectionCommittedEvent, SelectionConfig, SelectionEndpoint, SelectionRangeInput, type SelectionSegment, SelectionSettings, SelectionSnapshot, SelectionToken, TextPosition, TextRange };
@@ -1,7 +1,2 @@
1
- import { c as SelectionRangeInput, f as TextPosition, h as SelectionSegment, i as SelectionEndpoint, l as SelectionSnapshot, o as SelectionMenuAnchor, p as TextRange, r as SelectionCapability } from "./types-CUrUVl6K.js";
2
- import { CapabilityToken } from "@embedpdf/core";
3
- //#region src/contract.d.ts
4
- declare const SelectionToken: CapabilityToken<SelectionCapability>;
5
- //#endregion
6
- export { type SelectionCapability, type SelectionEndpoint, type SelectionMenuAnchor, type SelectionRangeInput, type SelectionSegment, type SelectionSnapshot, SelectionToken, type TextPosition, type TextRange };
7
- //# sourceMappingURL=contract.d.ts.map
1
+ import { a as SelectionClearedEvent, c as SelectionEndpoint, d as SelectionSnapshot, f as TextPosition, h as SelectionSegment, i as SelectionChangedEvent, l as SelectionRangeInput, m as SelectionToken, n as SelectionAnchor, o as SelectionCommittedEvent, p as TextRange, r as SelectionCapability, s as SelectionConfig, t as SELECTION_DEFAULTS, u as SelectionSettings } from "./contract-DLs4vXVt.js";
2
+ export { SELECTION_DEFAULTS, SelectionAnchor, SelectionCapability, SelectionChangedEvent, SelectionClearedEvent, SelectionCommittedEvent, SelectionConfig, SelectionEndpoint, SelectionRangeInput, type SelectionSegment, SelectionSettings, SelectionSnapshot, SelectionToken, TextPosition, TextRange };
package/dist/contract.js CHANGED
@@ -1,7 +1,2 @@
1
- import { t as SelectionToken$1 } from "./types-BVUcOsCh.js";
2
- //#region src/contract.ts
3
- const SelectionToken = SelectionToken$1;
4
- //#endregion
5
- export { SelectionToken };
6
-
7
- //# sourceMappingURL=contract.js.map
1
+ import { n as SelectionToken, t as SELECTION_DEFAULTS } from "./contract-DBXA64ep.js";
2
+ export { SELECTION_DEFAULTS, SelectionToken };
@@ -0,0 +1,34 @@
1
+ import { r as SelectionCapability } from "./contract-DLs4vXVt.js";
2
+ import { PageRef } from "@embedpdf/core";
3
+ import { Point } from "@embedpdf/core-geometry";
4
+ //#region src/host-contract.d.ts
5
+ interface SelectionHostCapability extends SelectionCapability {
6
+ /** Warm a page's text geometry. Resolves once loaded; resolves immediately
7
+ * (nothing requested) without `doc.text.select` or for an unknown page. A
8
+ * failed read resolves too — the layer simply has nothing to paint. */
9
+ ensureLoaded(page: PageRef): Promise<void>;
10
+ /** Whether the page's text geometry is loaded and current. */
11
+ isLoaded(page: PageRef): boolean;
12
+ /** Is a page-space point on (or near) text? Drives the I-beam cursor. */
13
+ isOverText(page: PageRef, point: Point): boolean;
14
+ /**
15
+ * A pointer gesture that drives the selection opened (pointer-down). From
16
+ * here until {@link endGesture}, `isSelecting()` is true and
17
+ * selection-scoped UI hides. Programmatic writes never open a gesture.
18
+ */
19
+ beginGesture(): void;
20
+ /** Open a caret selection at a page point (the first drag step). Returns
21
+ * false when the point has no text — the caller lets the gesture go. */
22
+ beginGestureAt(page: PageRef, point: Point): boolean;
23
+ /** The gesture ended (pointer-up). Settles first, then emits `onCommitted`
24
+ * when a selection is in place. */
25
+ endGesture(): void;
26
+ /** Suppress / restore the default highlight visual (a consumer drawing its
27
+ * own preview — the markup ghost). */
28
+ setHighlightVisible(visible: boolean): void;
29
+ isHighlightVisible(): boolean;
30
+ }
31
+ declare const SelectionToken: import("@embedpdf/core").CapabilityToken<SelectionHostCapability>;
32
+ //#endregion
33
+ export { SelectionToken as n, SelectionHostCapability as t };
34
+ //# sourceMappingURL=host-contract-DO2aLU2e.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { r as SelectionCapability } from "./contract-DLs4vXVt.cjs";
2
+ import { PageRef } from "@embedpdf/core";
3
+ import { Point } from "@embedpdf/core-geometry";
4
+ //#region src/host-contract.d.ts
5
+ interface SelectionHostCapability extends SelectionCapability {
6
+ /** Warm a page's text geometry. Resolves once loaded; resolves immediately
7
+ * (nothing requested) without `doc.text.select` or for an unknown page. A
8
+ * failed read resolves too — the layer simply has nothing to paint. */
9
+ ensureLoaded(page: PageRef): Promise<void>;
10
+ /** Whether the page's text geometry is loaded and current. */
11
+ isLoaded(page: PageRef): boolean;
12
+ /** Is a page-space point on (or near) text? Drives the I-beam cursor. */
13
+ isOverText(page: PageRef, point: Point): boolean;
14
+ /**
15
+ * A pointer gesture that drives the selection opened (pointer-down). From
16
+ * here until {@link endGesture}, `isSelecting()` is true and
17
+ * selection-scoped UI hides. Programmatic writes never open a gesture.
18
+ */
19
+ beginGesture(): void;
20
+ /** Open a caret selection at a page point (the first drag step). Returns
21
+ * false when the point has no text — the caller lets the gesture go. */
22
+ beginGestureAt(page: PageRef, point: Point): boolean;
23
+ /** The gesture ended (pointer-up). Settles first, then emits `onCommitted`
24
+ * when a selection is in place. */
25
+ endGesture(): void;
26
+ /** Suppress / restore the default highlight visual (a consumer drawing its
27
+ * own preview — the markup ghost). */
28
+ setHighlightVisible(visible: boolean): void;
29
+ isHighlightVisible(): boolean;
30
+ }
31
+ declare const SelectionToken: import("@embedpdf/core").CapabilityToken<SelectionHostCapability>;
32
+ //#endregion
33
+ export { SelectionToken as n, SelectionHostCapability as t };
34
+ //# sourceMappingURL=host-contract-Ddo4PcJJ.d.cts.map