@embedpdf/plugin-selection 2.15.0 → 3.0.0-next.0
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/LICENSE +192 -21
- package/dist/index.cjs +575 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +167 -0
- package/dist/index.d.ts +167 -1
- package/dist/index.js +549 -1508
- package/dist/index.js.map +1 -1
- package/package.json +21 -62
- package/dist/lib/actions.d.ts +0 -103
- package/dist/lib/handlers/index.d.ts +0 -2
- package/dist/lib/handlers/marquee-selection.handler.d.ts +0 -30
- package/dist/lib/handlers/text-selection.handler.d.ts +0 -52
- package/dist/lib/index.d.ts +0 -9
- package/dist/lib/manifest.d.ts +0 -4
- package/dist/lib/reducer.d.ts +0 -5
- package/dist/lib/selection-plugin.d.ts +0 -121
- package/dist/lib/selectors.d.ts +0 -14
- package/dist/lib/types.d.ts +0 -268
- package/dist/lib/utils.d.ts +0 -108
- package/dist/preact/adapter.d.ts +0 -4
- package/dist/preact/core.d.ts +0 -1
- package/dist/preact/index.cjs +0 -2
- package/dist/preact/index.cjs.map +0 -1
- package/dist/preact/index.d.ts +0 -1
- package/dist/preact/index.js +0 -218
- package/dist/preact/index.js.map +0 -1
- package/dist/preact/interaction-manager.d.ts +0 -1
- package/dist/preact/utils.d.ts +0 -1
- package/dist/react/adapter.d.ts +0 -2
- package/dist/react/core.d.ts +0 -1
- package/dist/react/index.cjs +0 -2
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -217
- package/dist/react/index.js.map +0 -1
- package/dist/react/interaction-manager.d.ts +0 -1
- package/dist/react/utils.d.ts +0 -1
- package/dist/shared/components/copy-to-clipboard.d.ts +0 -1
- package/dist/shared/components/index.d.ts +0 -4
- package/dist/shared/components/marquee-selection.d.ts +0 -36
- package/dist/shared/components/selection-layer.d.ts +0 -29
- package/dist/shared/components/text-selection.d.ts +0 -21
- package/dist/shared/hooks/index.d.ts +0 -1
- package/dist/shared/hooks/use-selection.d.ts +0 -11
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/types.d.ts +0 -7
- package/dist/shared-preact/components/copy-to-clipboard.d.ts +0 -1
- package/dist/shared-preact/components/index.d.ts +0 -4
- package/dist/shared-preact/components/marquee-selection.d.ts +0 -36
- package/dist/shared-preact/components/selection-layer.d.ts +0 -29
- package/dist/shared-preact/components/text-selection.d.ts +0 -21
- package/dist/shared-preact/hooks/index.d.ts +0 -1
- package/dist/shared-preact/hooks/use-selection.d.ts +0 -11
- package/dist/shared-preact/index.d.ts +0 -5
- package/dist/shared-preact/types.d.ts +0 -7
- package/dist/shared-react/components/copy-to-clipboard.d.ts +0 -1
- package/dist/shared-react/components/index.d.ts +0 -4
- package/dist/shared-react/components/marquee-selection.d.ts +0 -36
- package/dist/shared-react/components/selection-layer.d.ts +0 -29
- package/dist/shared-react/components/text-selection.d.ts +0 -21
- package/dist/shared-react/hooks/index.d.ts +0 -1
- package/dist/shared-react/hooks/use-selection.d.ts +0 -11
- package/dist/shared-react/index.d.ts +0 -5
- package/dist/shared-react/types.d.ts +0 -7
- package/dist/svelte/components/CopyToClipboard.svelte.d.ts +0 -3
- package/dist/svelte/components/MarqueeSelection.svelte.d.ts +0 -27
- package/dist/svelte/components/SelectionLayer.svelte.d.ts +0 -32
- package/dist/svelte/components/TextSelection.svelte.d.ts +0 -22
- package/dist/svelte/components/index.d.ts +0 -4
- package/dist/svelte/hooks/index.d.ts +0 -1
- package/dist/svelte/hooks/use-selection.svelte.d.ts +0 -19
- package/dist/svelte/index.cjs +0 -2
- package/dist/svelte/index.cjs.map +0 -1
- package/dist/svelte/index.d.ts +0 -5
- package/dist/svelte/index.js +0 -359
- package/dist/svelte/index.js.map +0 -1
- package/dist/svelte/types.d.ts +0 -7
- package/dist/vue/components/copy-to-clipboard.vue.d.ts +0 -3
- package/dist/vue/components/index.d.ts +0 -4
- package/dist/vue/components/marquee-selection.vue.d.ts +0 -29
- package/dist/vue/components/selection-layer.vue.d.ts +0 -60
- package/dist/vue/components/text-selection.vue.d.ts +0 -51
- package/dist/vue/hooks/index.d.ts +0 -1
- package/dist/vue/hooks/use-selection.d.ts +0 -11
- package/dist/vue/index.cjs +0 -2
- package/dist/vue/index.cjs.map +0 -1
- package/dist/vue/index.d.ts +0 -5
- package/dist/vue/index.js +0 -311
- package/dist/vue/index.js.map +0 -1
- package/dist/vue/types.d.ts +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,167 @@
|
|
|
1
|
-
|
|
1
|
+
import { PageObjectNumber, PluginContext } from "@embedpdf/core";
|
|
2
|
+
import { InteractionCapability, InteractionHandler } from "@embedpdf/plugin-interaction";
|
|
3
|
+
import { Point, Rect } from "@embedpdf/core-geometry";
|
|
4
|
+
import { PageGeometrySnapshot, PdfRect } from "@embedpdf/engine-core/runtime";
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/** A glyph address: a page + a flat glyph index within that page's geometry. */
|
|
7
|
+
interface GlyphPointer {
|
|
8
|
+
pon: PageObjectNumber;
|
|
9
|
+
glyph: number;
|
|
10
|
+
}
|
|
11
|
+
/** Anchor = where the drag began, focus = the current end. Inclusive. */
|
|
12
|
+
interface SelectionRange {
|
|
13
|
+
anchor: GlyphPointer;
|
|
14
|
+
focus: GlyphPointer;
|
|
15
|
+
}
|
|
16
|
+
interface SelectionEndpoint {
|
|
17
|
+
pon: PageObjectNumber;
|
|
18
|
+
rect: Rect;
|
|
19
|
+
}
|
|
20
|
+
interface SelectionSnapshot {
|
|
21
|
+
pages: Array<{
|
|
22
|
+
pon: PageObjectNumber;
|
|
23
|
+
rects: Rect[];
|
|
24
|
+
}>;
|
|
25
|
+
start: SelectionEndpoint | null;
|
|
26
|
+
end: SelectionEndpoint | null;
|
|
27
|
+
direction: 'forward' | 'backward';
|
|
28
|
+
}
|
|
29
|
+
interface SelectionState {
|
|
30
|
+
selection: SelectionRange | null;
|
|
31
|
+
/** Derived highlight rects per page, in CONTENT space (y-down, PDF units). */
|
|
32
|
+
rects: Record<number, Rect[]>;
|
|
33
|
+
/** Pages whose text geometry has loaded (so the layer re-renders when ready). */
|
|
34
|
+
loaded: Record<number, boolean>;
|
|
35
|
+
/** When a consumer owns the selection visual (e.g. a markup tool draws its own
|
|
36
|
+
* preview), the default highlight rects are suppressed. */
|
|
37
|
+
highlightHidden: boolean;
|
|
38
|
+
}
|
|
39
|
+
type SelectionAction = {
|
|
40
|
+
type: 'PAGE_LOADED';
|
|
41
|
+
pon: PageObjectNumber;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'SET';
|
|
44
|
+
selection: SelectionRange;
|
|
45
|
+
rects: Record<number, Rect[]>;
|
|
46
|
+
} | {
|
|
47
|
+
type: 'CLEAR';
|
|
48
|
+
} | {
|
|
49
|
+
type: 'SET_HIGHLIGHT_HIDDEN';
|
|
50
|
+
hidden: boolean;
|
|
51
|
+
};
|
|
52
|
+
interface SelectionCapability {
|
|
53
|
+
/** Warm a page's text geometry (idempotent). Layers call this when a page mounts. */
|
|
54
|
+
ensurePage(pon: PageObjectNumber): void;
|
|
55
|
+
isLoaded(pon: PageObjectNumber): boolean;
|
|
56
|
+
/** Is a content-space point on (or near) text? Drives the I-beam vs pointer cursor. */
|
|
57
|
+
isOverText(pon: PageObjectNumber, point: Point): boolean;
|
|
58
|
+
/** Begin a caret selection at a page point. Returns false if not near any text. */
|
|
59
|
+
beginAt(pon: PageObjectNumber, point: Point): boolean;
|
|
60
|
+
/** Double-click: select the word around the point. */
|
|
61
|
+
selectWord(pon: PageObjectNumber, point: Point): void;
|
|
62
|
+
/** Triple-click: select the whole visual line around the point. */
|
|
63
|
+
selectLine(pon: PageObjectNumber, point: Point): void;
|
|
64
|
+
/** Extend the current selection to a page point (drag). */
|
|
65
|
+
extendTo(pon: PageObjectNumber, point: Point): void;
|
|
66
|
+
end(): void;
|
|
67
|
+
clear(): void;
|
|
68
|
+
/** Coherent read-model for consumers that create annotations or selection UI. */
|
|
69
|
+
snapshot(): SelectionSnapshot;
|
|
70
|
+
/** Highlight rects for a page, in content space — the layer's only input. */
|
|
71
|
+
rectsForPage(pon: PageObjectNumber): Rect[];
|
|
72
|
+
hasSelection(): boolean;
|
|
73
|
+
/** The pages the current selection covers (those with at least one rect) — so a
|
|
74
|
+
* cross-page action (e.g. text-markup creation) can fan out per page. */
|
|
75
|
+
selectedPages(): PageObjectNumber[];
|
|
76
|
+
/** Fires whenever the selection rects change (e.g. drag-extend) — for live preview. */
|
|
77
|
+
onChange(cb: () => void): () => void;
|
|
78
|
+
/** Fires when a selection gesture ends (pointer-up) — the commit point. */
|
|
79
|
+
onCommit(cb: () => void): () => void;
|
|
80
|
+
/** Suppress / restore the default highlight visual (a consumer drawing its own). */
|
|
81
|
+
setHighlightVisible(visible: boolean): void;
|
|
82
|
+
highlightVisible(): boolean;
|
|
83
|
+
}
|
|
84
|
+
declare const SelectionToken: import("@embedpdf/core").CapabilityToken<SelectionCapability>;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/selection.plugin.d.ts
|
|
87
|
+
/**
|
|
88
|
+
* Text selection — document-scoped, requires the interaction hub. In `init` it
|
|
89
|
+
* registers ITS pointer handler with the hub; the hub owns the pointer stream
|
|
90
|
+
* and arbitration. Works with `<Stage>` or a standalone `<PageView>` — selection
|
|
91
|
+
* only needs the page coordinate context + the engine's text geometry.
|
|
92
|
+
*/
|
|
93
|
+
declare const selectionPlugin: () => import("@embedpdf/core").PluginDef<SelectionState, SelectionAction, SelectionCapability>;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/capability.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* The selection capability. The reducer state holds the selection range, the
|
|
98
|
+
* derived content-space rects (per page), and per-page loaded flags; the (large,
|
|
99
|
+
* non-serializable) per-page text geometry is cached HERE in the closure.
|
|
100
|
+
*
|
|
101
|
+
* Selection is cross-page: glyphs are ordered globally by (pageIndex, glyph), so
|
|
102
|
+
* a drag from page 2 into page 4 selects the tail of 2, all of 3, and the head of
|
|
103
|
+
* 4. `recompute` rebuilds the merged line rects for every loaded page in the span
|
|
104
|
+
* and re-runs whenever a mid-span page finishes loading.
|
|
105
|
+
*/
|
|
106
|
+
declare function createSelectionCapability(ctx: PluginContext<SelectionState, SelectionAction>): SelectionCapability;
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/handler.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* The text-selection pointer handler. It is live only under tools that enable the
|
|
111
|
+
* `'text-select'` tag (the built-in `pointer` tool does; `pan` does not — so
|
|
112
|
+
* switching to pan disables text selection with zero special-casing here).
|
|
113
|
+
*
|
|
114
|
+
* - single click → deselect; records an anchor but selects NOTHING until
|
|
115
|
+
* the pointer moves past the drag threshold (Chrome/Acrobat feel)
|
|
116
|
+
* - single-click + drag → caret selection from the anchor (extends across pages)
|
|
117
|
+
* - double-click → select the word
|
|
118
|
+
* - triple-click → select the visual line
|
|
119
|
+
* - down off-text → deselect, and DON'T capture (so it can't block)
|
|
120
|
+
* - hover → I-beam only when over text, else the pointer cursor
|
|
121
|
+
*/
|
|
122
|
+
declare function createTextSelectHandler(selection: SelectionCapability, interaction: InteractionCapability): InteractionHandler;
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/reducer.d.ts
|
|
125
|
+
declare const initialSelectionState: SelectionState;
|
|
126
|
+
declare const selectionReducer: (state: SelectionState, action: SelectionAction) => SelectionState;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/geometry.d.ts
|
|
129
|
+
/** One glyph in content space. `loose` builds selection rects; `tight` hit-tests. */
|
|
130
|
+
interface GlyphInfo {
|
|
131
|
+
loose: Rect;
|
|
132
|
+
tight?: Rect;
|
|
133
|
+
flags: number;
|
|
134
|
+
}
|
|
135
|
+
/** A contiguous run of glyphs (a text object). `rect` is its loose enclosing box. */
|
|
136
|
+
interface RunInfo {
|
|
137
|
+
start: number;
|
|
138
|
+
count: number;
|
|
139
|
+
rect: Rect;
|
|
140
|
+
fontSize?: number;
|
|
141
|
+
}
|
|
142
|
+
/** A page's text laid out in content space: a flat glyph list + the run structure. */
|
|
143
|
+
interface PageText {
|
|
144
|
+
glyphs: GlyphInfo[];
|
|
145
|
+
runs: RunInfo[];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Flatten a page's text geometry into content-space glyphs + runs. Rotation does
|
|
149
|
+
* NOT enter here — the overlay rides the page's CSS rotation, so glyphs stay in
|
|
150
|
+
* un-rotated content space (the crop-relative y-flip is the only conversion).
|
|
151
|
+
*/
|
|
152
|
+
declare function buildPageText(snapshot: PageGeometrySnapshot, crop: PdfRect, rotation: 0 | 90 | 180 | 270, userUnit: number): PageText;
|
|
153
|
+
/**
|
|
154
|
+
* The glyph index at a content-space point, or null when nothing is near (so the
|
|
155
|
+
* caller can show the pointer cursor off-text). PDFium `GetIndexAtPos`: exact
|
|
156
|
+
* tight-box containment first, then a tolerance pass (closest by Manhattan
|
|
157
|
+
* distance within `toleranceFactor × average glyph height`).
|
|
158
|
+
*/
|
|
159
|
+
declare function glyphAt(text: PageText, p: Point, toleranceFactor?: number): number | null;
|
|
160
|
+
/** Double-click: the word around `i` (walk to space/empty glyphs both ways). */
|
|
161
|
+
declare function expandToWord(text: PageText, i: number): [number, number];
|
|
162
|
+
/** Triple-click: the full visual line — runs whose vertical extent overlaps the anchor run's. */
|
|
163
|
+
declare function expandToLine(text: PageText, i: number): [number, number];
|
|
164
|
+
declare function rectsForRange(text: PageText, from: number, to: number): Rect[];
|
|
165
|
+
//#endregion
|
|
166
|
+
export { type GlyphInfo, type GlyphPointer, type PageText, type RunInfo, type SelectionAction, type SelectionCapability, type SelectionEndpoint, type SelectionRange, type SelectionSnapshot, type SelectionState, SelectionToken, buildPageText, createSelectionCapability, createTextSelectHandler, expandToLine, expandToWord, glyphAt, initialSelectionState, rectsForRange, selectionPlugin, selectionReducer };
|
|
167
|
+
//# sourceMappingURL=index.d.ts.map
|