@embedpdf/plugin-selection 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -450
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -213
- package/dist/index.js +27 -53
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +57 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +4 -0
- package/dist/lib/selection-plugin.d.ts +29 -0
- package/dist/lib/selectors.d.ts +14 -0
- package/dist/lib/types.d.ts +63 -0
- package/dist/lib/utils.d.ts +70 -0
- package/dist/preact/adapter.d.ts +4 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -169
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -25
- package/dist/preact/index.js +15 -24
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/interaction-manager.d.ts +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -169
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -25
- package/dist/react/index.js +14 -24
- package/dist/react/index.js.map +1 -1
- package/dist/react/interaction-manager.d.ts +1 -0
- package/dist/shared-preact/components/copy-to-clipboard.d.ts +1 -0
- package/dist/shared-preact/components/index.d.ts +2 -0
- package/dist/shared-preact/components/selection-layer.d.ts +7 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-selection.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/copy-to-clipboard.d.ts +1 -0
- package/dist/shared-react/components/index.d.ts +2 -0
- package/dist/shared-react/components/selection-layer.d.ts +7 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-selection.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/copy-to-clipboard.vue.d.ts +2 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/selection-layer.vue.d.ts +9 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-selection.d.ts +11 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +145 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +23 -14
- package/dist/index.d.cts +0 -213
- package/dist/preact/index.d.cts +0 -25
- package/dist/react/index.d.cts +0 -25
package/dist/react/index.cjs
CHANGED
|
@@ -1,169 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/react/index.ts
|
|
21
|
-
var react_exports = {};
|
|
22
|
-
__export(react_exports, {
|
|
23
|
-
CopyToClipboard: () => CopyToClipboard,
|
|
24
|
-
SelectionLayer: () => SelectionLayer,
|
|
25
|
-
useSelectionCapability: () => useSelectionCapability,
|
|
26
|
-
useSelectionPlugin: () => useSelectionPlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(react_exports);
|
|
29
|
-
|
|
30
|
-
// src/react/hooks/use-selection.ts
|
|
31
|
-
var import_react = require("@embedpdf/core/react");
|
|
32
|
-
var import_plugin_selection = require("@embedpdf/plugin-selection");
|
|
33
|
-
var useSelectionCapability = () => (0, import_react.useCapability)(import_plugin_selection.SelectionPlugin.id);
|
|
34
|
-
var useSelectionPlugin = () => (0, import_react.usePlugin)(import_plugin_selection.SelectionPlugin.id);
|
|
35
|
-
|
|
36
|
-
// src/react/components/selection-layer.tsx
|
|
37
|
-
var import_react2 = require("react");
|
|
38
|
-
var import_models = require("@embedpdf/models");
|
|
39
|
-
var import_react3 = require("@embedpdf/plugin-interaction-manager/react");
|
|
40
|
-
var import_plugin_selection2 = require("@embedpdf/plugin-selection");
|
|
41
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
-
function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
43
|
-
const { provides: sel } = useSelectionCapability();
|
|
44
|
-
const { provides: im } = (0, import_react3.useInteractionManagerCapability)();
|
|
45
|
-
const { register } = (0, import_react3.usePointerHandlers)({ pageIndex });
|
|
46
|
-
const [rects, setRects] = (0, import_react2.useState)([]);
|
|
47
|
-
const [boundingRect, setBoundingRect] = (0, import_react2.useState)(null);
|
|
48
|
-
const { setCursor, removeCursor } = (0, import_react3.useCursor)();
|
|
49
|
-
(0, import_react2.useEffect)(() => {
|
|
50
|
-
if (!sel) return;
|
|
51
|
-
return sel.onSelectionChange(() => {
|
|
52
|
-
const mode = im?.getActiveMode();
|
|
53
|
-
if (mode === "default") {
|
|
54
|
-
setRects(sel.getHighlightRectsForPage(pageIndex));
|
|
55
|
-
setBoundingRect(sel.getBoundingRectForPage(pageIndex));
|
|
56
|
-
} else {
|
|
57
|
-
setRects([]);
|
|
58
|
-
setBoundingRect(null);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}, [sel, pageIndex]);
|
|
62
|
-
let geoCache;
|
|
63
|
-
const cachedGlyphAt = (0, import_react2.useCallback)((pt) => {
|
|
64
|
-
if (!geoCache) return -1;
|
|
65
|
-
return (0, import_plugin_selection2.glyphAt)(geoCache, pt);
|
|
66
|
-
}, []);
|
|
67
|
-
(0, import_react2.useEffect)(() => {
|
|
68
|
-
if (!sel) return;
|
|
69
|
-
const task = sel.getGeometry(pageIndex);
|
|
70
|
-
task.wait((g) => geoCache = g, import_models.ignore);
|
|
71
|
-
return () => {
|
|
72
|
-
task.abort({
|
|
73
|
-
code: import_models.PdfErrorCode.Cancelled,
|
|
74
|
-
message: "Cancelled"
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
}, [sel, pageIndex]);
|
|
78
|
-
const handlers = (0, import_react2.useMemo)(
|
|
79
|
-
() => ({
|
|
80
|
-
onPointerDown: (point, _evt, modeId) => {
|
|
81
|
-
if (!sel) return;
|
|
82
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
83
|
-
sel.clear();
|
|
84
|
-
const task = sel.getGeometry(pageIndex);
|
|
85
|
-
task.wait((geo) => {
|
|
86
|
-
const g = (0, import_plugin_selection2.glyphAt)(geo, point);
|
|
87
|
-
if (g !== -1) sel.begin(pageIndex, g);
|
|
88
|
-
}, import_models.ignore);
|
|
89
|
-
},
|
|
90
|
-
onPointerMove: (point, _evt, modeId) => {
|
|
91
|
-
if (!sel) return;
|
|
92
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
93
|
-
const g = cachedGlyphAt(point);
|
|
94
|
-
if (g !== -1) {
|
|
95
|
-
setCursor("selection-text", "text", 10);
|
|
96
|
-
} else {
|
|
97
|
-
removeCursor("selection-text");
|
|
98
|
-
}
|
|
99
|
-
if (g !== -1) sel.update(pageIndex, g);
|
|
100
|
-
},
|
|
101
|
-
onPointerUp: (_point, _evt, modeId) => {
|
|
102
|
-
if (!sel) return;
|
|
103
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
104
|
-
sel.end();
|
|
105
|
-
},
|
|
106
|
-
onHandlerActiveEnd(modeId) {
|
|
107
|
-
if (!sel) return;
|
|
108
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
109
|
-
sel.clear();
|
|
110
|
-
}
|
|
111
|
-
}),
|
|
112
|
-
[sel, pageIndex, cachedGlyphAt]
|
|
113
|
-
);
|
|
114
|
-
(0, import_react2.useEffect)(() => {
|
|
115
|
-
if (!register) return;
|
|
116
|
-
return register(handlers);
|
|
117
|
-
}, [register, handlers]);
|
|
118
|
-
if (!boundingRect) return null;
|
|
119
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
120
|
-
"div",
|
|
121
|
-
{
|
|
122
|
-
style: {
|
|
123
|
-
position: "absolute",
|
|
124
|
-
left: boundingRect.origin.x * scale,
|
|
125
|
-
top: boundingRect.origin.y * scale,
|
|
126
|
-
width: boundingRect.size.width * scale,
|
|
127
|
-
height: boundingRect.size.height * scale,
|
|
128
|
-
mixBlendMode: "multiply",
|
|
129
|
-
isolation: "isolate"
|
|
130
|
-
},
|
|
131
|
-
children: rects.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
-
"div",
|
|
133
|
-
{
|
|
134
|
-
style: {
|
|
135
|
-
position: "absolute",
|
|
136
|
-
left: (b.origin.x - boundingRect.origin.x) * scale,
|
|
137
|
-
top: (b.origin.y - boundingRect.origin.y) * scale,
|
|
138
|
-
width: b.size.width * scale,
|
|
139
|
-
height: b.size.height * scale,
|
|
140
|
-
background,
|
|
141
|
-
pointerEvents: "none"
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
i
|
|
145
|
-
))
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// src/react/components/copy-to-clipboard.tsx
|
|
151
|
-
var import_react4 = require("react");
|
|
152
|
-
function CopyToClipboard() {
|
|
153
|
-
const { provides: sel } = useSelectionCapability();
|
|
154
|
-
(0, import_react4.useEffect)(() => {
|
|
155
|
-
if (!sel) return;
|
|
156
|
-
return sel.onCopyToClipboard((text) => {
|
|
157
|
-
navigator.clipboard.writeText(text);
|
|
158
|
-
});
|
|
159
|
-
}, [sel]);
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
-
0 && (module.exports = {
|
|
164
|
-
CopyToClipboard,
|
|
165
|
-
SelectionLayer,
|
|
166
|
-
useSelectionCapability,
|
|
167
|
-
useSelectionPlugin
|
|
168
|
-
});
|
|
169
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-selection"),r=require("react/jsx-runtime"),i=require("react"),n=require("@embedpdf/models"),o=require("@embedpdf/plugin-interaction-manager/react"),l=()=>e.useCapability(t.SelectionPlugin.id);exports.CopyToClipboard=function(){const{provides:e}=l();return i.useEffect((()=>{if(e)return e.onCopyToClipboard((e=>{navigator.clipboard.writeText(e)}))}),[e]),null},exports.SelectionLayer=function({pageIndex:e,scale:s,background:u="rgba(33,150,243)"}){const{provides:a}=l(),{provides:d}=o.useInteractionManagerCapability(),{register:c}=o.usePointerHandlers({pageIndex:e}),[g,p]=i.useState([]),[f,b]=i.useState(null),{setCursor:h,removeCursor:x}=o.useCursor(),y=i.useRef(null);i.useEffect((()=>{if(a)return a.onSelectionChange((()=>{"default"===(null==d?void 0:d.getActiveMode())?(p(a.getHighlightRectsForPage(e)),b(a.getBoundingRectForPage(e))):(p([]),b(null))}))}),[a,e]);const m=i.useCallback((e=>{const r=y.current;return r?t.glyphAt(r,e):-1}),[]);i.useEffect((()=>{if(!a)return;const t=a.getGeometry(e);return t.wait((e=>y.current=e),n.ignore),()=>{t.abort({code:n.PdfErrorCode.Cancelled,message:"Cancelled"}),y.current=null}}),[a,e]);const C=i.useMemo((()=>({onPointerDown:(r,i,o)=>{if(!a)return;if(!a.isEnabledForMode(o))return;a.clear();a.getGeometry(e).wait((i=>{const n=t.glyphAt(i,r);-1!==n&&a.begin(e,n)}),n.ignore)},onPointerMove:(t,r,i)=>{if(!a)return;if(!a.isEnabledForMode(i))return;const n=m(t);-1!==n?h("selection-text","text",10):x("selection-text"),-1!==n&&a.update(e,n)},onPointerUp:(e,t,r)=>{a&&a.isEnabledForMode(r)&&a.end()},onHandlerActiveEnd(e){a&&a.isEnabledForMode(e)&&a.clear()}})),[a,e,m]);return i.useEffect((()=>{if(c)return c(C)}),[c,C]),f?r.jsx("div",{style:{position:"absolute",left:f.origin.x*s,top:f.origin.y*s,width:f.size.width*s,height:f.size.height*s,mixBlendMode:"multiply",isolation:"isolate"},children:g.map(((e,t)=>r.jsx("div",{style:{position:"absolute",left:(e.origin.x-f.origin.x)*s,top:(e.origin.y-f.origin.y)*s,width:e.size.width*s,height:e.size.height*s,background:u,pointerEvents:"none"}},t)))}):null},exports.useSelectionCapability=l,exports.useSelectionPlugin=()=>e.usePlugin(t.SelectionPlugin.id);
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-selection.ts","../../src/shared/components/copy-to-clipboard.tsx","../../src/shared/components/selection-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const useSelectionPlugin = () => usePlugin<SelectionPlugin>(SelectionPlugin.id);\n","import { useEffect } from '@framework';\n\nimport { useSelectionCapability } from '../hooks';\n\nexport function CopyToClipboard() {\n const { provides: sel } = useSelectionCapability();\n\n useEffect(() => {\n if (!sel) return;\n return sel.onCopyToClipboard((text) => {\n navigator.clipboard.writeText(text);\n });\n }, [sel]);\n\n return null;\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from '@framework';\nimport { ignore, PdfErrorCode, PdfPageGeometry, Position, Rect } from '@embedpdf/models';\nimport {\n useCursor,\n useInteractionManagerCapability,\n usePointerHandlers,\n} from '@embedpdf/plugin-interaction-manager/@framework';\nimport { PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';\nimport { glyphAt } from '@embedpdf/plugin-selection';\n\nimport { useSelectionCapability } from '../hooks';\n\ntype Props = {\n pageIndex: number;\n scale: number;\n background?: string;\n};\n\nexport function SelectionLayer({ pageIndex, scale, background = 'rgba(33,150,243)' }: Props) {\n const { provides: sel } = useSelectionCapability();\n const { provides: im } = useInteractionManagerCapability();\n const { register } = usePointerHandlers({ pageIndex });\n const [rects, setRects] = useState<Array<Rect>>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n const { setCursor, removeCursor } = useCursor();\n const geoCacheRef = useRef<PdfPageGeometry | null>(null);\n\n /* subscribe to rect updates */\n useEffect(() => {\n if (!sel) return;\n return sel.onSelectionChange(() => {\n const mode = im?.getActiveMode();\n if (mode === 'default') {\n setRects(sel.getHighlightRectsForPage(pageIndex));\n setBoundingRect(sel.getBoundingRectForPage(pageIndex));\n } else {\n setRects([]);\n setBoundingRect(null);\n }\n });\n }, [sel, pageIndex]);\n\n /* cheap glyphAt cache for the active page */\n const cachedGlyphAt = useCallback((pt: Position) => {\n const geo = geoCacheRef.current;\n return geo ? glyphAt(geo, pt) : -1;\n }, []);\n\n // Initialize geometry cache\n useEffect(() => {\n if (!sel) return;\n const task = sel.getGeometry(pageIndex);\n task.wait((g) => (geoCacheRef.current = g), ignore);\n\n return () => {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'Cancelled',\n });\n geoCacheRef.current = null;\n };\n }, [sel, pageIndex]);\n\n const handlers = useMemo(\n (): PointerEventHandlersWithLifecycle<PointerEvent> => ({\n onPointerDown: (point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n // clear the selection\n sel.clear();\n const task = sel.getGeometry(pageIndex);\n task.wait((geo) => {\n const g = glyphAt(geo, point);\n if (g !== -1) sel.begin(pageIndex, g);\n }, ignore);\n },\n onPointerMove: (point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n const g = cachedGlyphAt(point);\n if (g !== -1) {\n setCursor('selection-text', 'text', 10);\n } else {\n removeCursor('selection-text');\n }\n if (g !== -1) sel.update(pageIndex, g);\n },\n onPointerUp: (_point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n sel.end();\n },\n onHandlerActiveEnd(modeId) {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n\n sel.clear();\n },\n }),\n [sel, pageIndex, cachedGlyphAt],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n if (!boundingRect) return null;\n\n return (\n <div\n style={{\n position: 'absolute',\n left: boundingRect.origin.x * scale,\n top: boundingRect.origin.y * scale,\n width: boundingRect.size.width * scale,\n height: boundingRect.size.height * scale,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n }}\n >\n {rects.map((b, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: (b.origin.x - boundingRect.origin.x) * scale,\n top: (b.origin.y - boundingRect.origin.y) * scale,\n width: b.size.width * scale,\n height: b.size.height * scale,\n background,\n pointerEvents: 'none',\n }}\n />\n ))}\n </div>\n );\n}\n"],"names":["useSelectionCapability","useCapability","SelectionPlugin","id","provides","sel","useEffect","onCopyToClipboard","text","navigator","clipboard","writeText","pageIndex","scale","background","im","useInteractionManagerCapability","register","usePointerHandlers","rects","setRects","useState","boundingRect","setBoundingRect","setCursor","removeCursor","useCursor","geoCacheRef","useRef","onSelectionChange","getActiveMode","getHighlightRectsForPage","getBoundingRectForPage","cachedGlyphAt","useCallback","pt","geo","current","glyphAt","task","getGeometry","wait","g","ignore","abort","code","PdfErrorCode","Cancelled","message","handlers","useMemo","onPointerDown","point","_evt","modeId","isEnabledForMode","clear","begin","onPointerMove","update","onPointerUp","_point","end","onHandlerActiveEnd","jsxRuntime","jsx","style","position","left","origin","x","top","y","width","size","height","mixBlendMode","isolation","children","map","b","i","pointerEvents","usePlugin"],"mappings":"wSAGaA,EAAyB,IAAMC,gBAA+BC,EAAAA,gBAAgBC,4BCCpF,WACL,MAAQC,SAAUC,GAAQL,IASnB,OAPPM,EAAAA,WAAU,KACR,GAAKD,EACE,OAAAA,EAAIE,mBAAmBC,IAClBC,UAAAC,UAAUC,UAAUH,EAAI,GACnC,GACA,CAACH,IAEG,IACT,yBCGO,UAAwBO,UAAEA,EAAAC,MAAWA,EAAOC,WAAAA,EAAa,qBAC9D,MAAQV,SAAUC,GAAQL,KAClBI,SAAUW,GAAOC,qCACnBC,SAAEA,GAAaC,qBAAmB,CAAEN,eACnCO,EAAOC,GAAYC,EAAAA,SAAsB,KACzCC,EAAcC,GAAmBF,EAAAA,SAAsB,OACxDG,UAAEA,EAAAC,aAAWA,GAAiBC,cAC9BC,EAAcC,SAA+B,MAGnDtB,EAAAA,WAAU,KACR,GAAKD,EACE,OAAAA,EAAIwB,mBAAkB,KAEd,aADI,MAAJd,OAAI,EAAAA,EAAAe,kBAENV,EAAAf,EAAI0B,yBAAyBnB,IACtBW,EAAAlB,EAAI2B,uBAAuBpB,MAE3CQ,EAAS,IACTG,EAAgB,MAAI,GAEvB,GACA,CAAClB,EAAKO,IAGH,MAAAqB,EAAgBC,eAAaC,IACjC,MAAMC,EAAMT,EAAYU,QACxB,OAAOD,EAAME,EAAAA,QAAQF,EAAKD,IAAM,CAAA,GAC/B,IAGH7B,EAAAA,WAAU,KACR,IAAKD,EAAK,OACJ,MAAAkC,EAAOlC,EAAImC,YAAY5B,GAG7B,OAFA2B,EAAKE,MAAMC,GAAOf,EAAYU,QAAUK,GAAIC,UAErC,KACLJ,EAAK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,CAECC,MAAO,CACLC,SAAU,WACVC,MAAOY,EAAEX,OAAOC,EAAIhD,EAAa+C,OAAOC,GAAKzD,EAC7C0D,KAAMS,EAAEX,OAAOG,EAAIlD,EAAa+C,OAAOG,GAAK3D,EAC5C4D,MAAOO,EAAEN,KAAKD,MAAQ5D,EACtB8D,OAAQK,EAAEN,KAAKC,OAAS9D,EACxBC,aACAoE,cAAe,SARZD,OAhBa,IA8B5B,8DFrIkC,IAAME,YAA2BjF,EAAAA,gBAAgBC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { SelectionPlugin } from '@embedpdf/plugin-selection';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
declare const useSelectionCapability: () => {
|
|
6
|
-
provides: Readonly<_embedpdf_plugin_selection.SelectionCapability> | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
ready: Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
declare const useSelectionPlugin: () => {
|
|
11
|
-
plugin: SelectionPlugin | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type Props = {
|
|
17
|
-
pageIndex: number;
|
|
18
|
-
scale: number;
|
|
19
|
-
background?: string;
|
|
20
|
-
};
|
|
21
|
-
declare function SelectionLayer({ pageIndex, scale, background }: Props): react_jsx_runtime.JSX.Element | null;
|
|
22
|
-
|
|
23
|
-
declare function CopyToClipboard(): null;
|
|
24
|
-
|
|
25
|
-
export { CopyToClipboard, SelectionLayer, useSelectionCapability, useSelectionPlugin };
|
|
1
|
+
export * from '../shared-react';
|
package/dist/react/index.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
// src/react/hooks/use-selection.ts
|
|
2
1
|
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
3
|
-
import { SelectionPlugin } from "@embedpdf/plugin-selection";
|
|
4
|
-
var useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
5
|
-
var useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
6
|
-
|
|
7
|
-
// src/react/components/selection-layer.tsx
|
|
8
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
9
|
-
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
10
|
-
import {
|
|
11
|
-
useCursor,
|
|
12
|
-
useInteractionManagerCapability,
|
|
13
|
-
usePointerHandlers
|
|
14
|
-
} from "@embedpdf/plugin-interaction-manager/react";
|
|
15
|
-
import { glyphAt } from "@embedpdf/plugin-selection";
|
|
2
|
+
import { SelectionPlugin, glyphAt } from "@embedpdf/plugin-selection";
|
|
16
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useState, useRef, useEffect, useCallback, useMemo } from "react";
|
|
5
|
+
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
6
|
+
import { useInteractionManagerCapability, usePointerHandlers, useCursor } from "@embedpdf/plugin-interaction-manager/react";
|
|
7
|
+
const useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
8
|
+
const useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
17
9
|
function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
18
10
|
const { provides: sel } = useSelectionCapability();
|
|
19
11
|
const { provides: im } = useInteractionManagerCapability();
|
|
@@ -21,10 +13,11 @@ function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
|
21
13
|
const [rects, setRects] = useState([]);
|
|
22
14
|
const [boundingRect, setBoundingRect] = useState(null);
|
|
23
15
|
const { setCursor, removeCursor } = useCursor();
|
|
16
|
+
const geoCacheRef = useRef(null);
|
|
24
17
|
useEffect(() => {
|
|
25
18
|
if (!sel) return;
|
|
26
19
|
return sel.onSelectionChange(() => {
|
|
27
|
-
const mode = im
|
|
20
|
+
const mode = im == null ? void 0 : im.getActiveMode();
|
|
28
21
|
if (mode === "default") {
|
|
29
22
|
setRects(sel.getHighlightRectsForPage(pageIndex));
|
|
30
23
|
setBoundingRect(sel.getBoundingRectForPage(pageIndex));
|
|
@@ -34,20 +27,20 @@ function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
|
34
27
|
}
|
|
35
28
|
});
|
|
36
29
|
}, [sel, pageIndex]);
|
|
37
|
-
let geoCache;
|
|
38
30
|
const cachedGlyphAt = useCallback((pt) => {
|
|
39
|
-
|
|
40
|
-
return glyphAt(
|
|
31
|
+
const geo = geoCacheRef.current;
|
|
32
|
+
return geo ? glyphAt(geo, pt) : -1;
|
|
41
33
|
}, []);
|
|
42
34
|
useEffect(() => {
|
|
43
35
|
if (!sel) return;
|
|
44
36
|
const task = sel.getGeometry(pageIndex);
|
|
45
|
-
task.wait((g) =>
|
|
37
|
+
task.wait((g) => geoCacheRef.current = g, ignore);
|
|
46
38
|
return () => {
|
|
47
39
|
task.abort({
|
|
48
40
|
code: PdfErrorCode.Cancelled,
|
|
49
41
|
message: "Cancelled"
|
|
50
42
|
});
|
|
43
|
+
geoCacheRef.current = null;
|
|
51
44
|
};
|
|
52
45
|
}, [sel, pageIndex]);
|
|
53
46
|
const handlers = useMemo(
|
|
@@ -121,12 +114,9 @@ function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
|
121
114
|
}
|
|
122
115
|
);
|
|
123
116
|
}
|
|
124
|
-
|
|
125
|
-
// src/react/components/copy-to-clipboard.tsx
|
|
126
|
-
import { useEffect as useEffect2 } from "react";
|
|
127
117
|
function CopyToClipboard() {
|
|
128
118
|
const { provides: sel } = useSelectionCapability();
|
|
129
|
-
|
|
119
|
+
useEffect(() => {
|
|
130
120
|
if (!sel) return;
|
|
131
121
|
return sel.onCopyToClipboard((text) => {
|
|
132
122
|
navigator.clipboard.writeText(text);
|
|
@@ -140,4 +130,4 @@ export {
|
|
|
140
130
|
useSelectionCapability,
|
|
141
131
|
useSelectionPlugin
|
|
142
132
|
};
|
|
143
|
-
//# sourceMappingURL=index.js.map
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-selection.ts","../../src/shared/components/selection-layer.tsx","../../src/shared/components/copy-to-clipboard.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const useSelectionPlugin = () => usePlugin<SelectionPlugin>(SelectionPlugin.id);\n","import { useCallback, useEffect, useMemo, useRef, useState } from '@framework';\nimport { ignore, PdfErrorCode, PdfPageGeometry, Position, Rect } from '@embedpdf/models';\nimport {\n useCursor,\n useInteractionManagerCapability,\n usePointerHandlers,\n} from '@embedpdf/plugin-interaction-manager/@framework';\nimport { PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';\nimport { glyphAt } from '@embedpdf/plugin-selection';\n\nimport { useSelectionCapability } from '../hooks';\n\ntype Props = {\n pageIndex: number;\n scale: number;\n background?: string;\n};\n\nexport function SelectionLayer({ pageIndex, scale, background = 'rgba(33,150,243)' }: Props) {\n const { provides: sel } = useSelectionCapability();\n const { provides: im } = useInteractionManagerCapability();\n const { register } = usePointerHandlers({ pageIndex });\n const [rects, setRects] = useState<Array<Rect>>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n const { setCursor, removeCursor } = useCursor();\n const geoCacheRef = useRef<PdfPageGeometry | null>(null);\n\n /* subscribe to rect updates */\n useEffect(() => {\n if (!sel) return;\n return sel.onSelectionChange(() => {\n const mode = im?.getActiveMode();\n if (mode === 'default') {\n setRects(sel.getHighlightRectsForPage(pageIndex));\n setBoundingRect(sel.getBoundingRectForPage(pageIndex));\n } else {\n setRects([]);\n setBoundingRect(null);\n }\n });\n }, [sel, pageIndex]);\n\n /* cheap glyphAt cache for the active page */\n const cachedGlyphAt = useCallback((pt: Position) => {\n const geo = geoCacheRef.current;\n return geo ? glyphAt(geo, pt) : -1;\n }, []);\n\n // Initialize geometry cache\n useEffect(() => {\n if (!sel) return;\n const task = sel.getGeometry(pageIndex);\n task.wait((g) => (geoCacheRef.current = g), ignore);\n\n return () => {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'Cancelled',\n });\n geoCacheRef.current = null;\n };\n }, [sel, pageIndex]);\n\n const handlers = useMemo(\n (): PointerEventHandlersWithLifecycle<PointerEvent> => ({\n onPointerDown: (point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n // clear the selection\n sel.clear();\n const task = sel.getGeometry(pageIndex);\n task.wait((geo) => {\n const g = glyphAt(geo, point);\n if (g !== -1) sel.begin(pageIndex, g);\n }, ignore);\n },\n onPointerMove: (point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n const g = cachedGlyphAt(point);\n if (g !== -1) {\n setCursor('selection-text', 'text', 10);\n } else {\n removeCursor('selection-text');\n }\n if (g !== -1) sel.update(pageIndex, g);\n },\n onPointerUp: (_point, _evt, modeId) => {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n sel.end();\n },\n onHandlerActiveEnd(modeId) {\n if (!sel) return;\n if (!sel.isEnabledForMode(modeId)) return;\n\n sel.clear();\n },\n }),\n [sel, pageIndex, cachedGlyphAt],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n if (!boundingRect) return null;\n\n return (\n <div\n style={{\n position: 'absolute',\n left: boundingRect.origin.x * scale,\n top: boundingRect.origin.y * scale,\n width: boundingRect.size.width * scale,\n height: boundingRect.size.height * scale,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n }}\n >\n {rects.map((b, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: (b.origin.x - boundingRect.origin.x) * scale,\n top: (b.origin.y - boundingRect.origin.y) * scale,\n width: b.size.width * scale,\n height: b.size.height * scale,\n background,\n pointerEvents: 'none',\n }}\n />\n ))}\n </div>\n );\n}\n","import { useEffect } from '@framework';\n\nimport { useSelectionCapability } from '../hooks';\n\nexport function CopyToClipboard() {\n const { provides: sel } = useSelectionCapability();\n\n useEffect(() => {\n if (!sel) return;\n return sel.onCopyToClipboard((text) => {\n navigator.clipboard.writeText(text);\n });\n }, [sel]);\n\n return null;\n}\n"],"names":[],"mappings":";;;;;;AAGO,MAAM,yBAAyB,MAAM,cAA+B,gBAAgB,EAAE;AACtF,MAAM,qBAAqB,MAAM,UAA2B,gBAAgB,EAAE;ACc9E,SAAS,eAAe,EAAE,WAAW,OAAO,aAAa,sBAA6B;AAC3F,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AACjD,QAAM,EAAE,UAAU,GAAG,IAAI,gCAAgC;AACzD,QAAM,EAAE,SAAS,IAAI,mBAAmB,EAAE,WAAW;AACrD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAsB,CAAA,CAAE;AAClD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAsB,IAAI;AAClE,QAAM,EAAE,WAAW,aAAa,IAAI,UAAU;AACxC,QAAA,cAAc,OAA+B,IAAI;AAGvD,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AACH,WAAA,IAAI,kBAAkB,MAAM;AAC3B,YAAA,OAAO,yBAAI;AACjB,UAAI,SAAS,WAAW;AACb,iBAAA,IAAI,yBAAyB,SAAS,CAAC;AAChC,wBAAA,IAAI,uBAAuB,SAAS,CAAC;AAAA,MAAA,OAChD;AACL,iBAAS,CAAA,CAAE;AACX,wBAAgB,IAAI;AAAA,MAAA;AAAA,IACtB,CACD;AAAA,EAAA,GACA,CAAC,KAAK,SAAS,CAAC;AAGb,QAAA,gBAAgB,YAAY,CAAC,OAAiB;AAClD,UAAM,MAAM,YAAY;AACxB,WAAO,MAAM,Q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0 +1 @@
|
|
|
1
|
+
export declare function CopyToClipboard(): null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-selection';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SelectionPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useSelectionCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').SelectionCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useSelectionPlugin: () => {
|
|
8
|
+
plugin: SelectionPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CopyToClipboard(): null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-selection';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SelectionPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useSelectionCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').SelectionCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useSelectionPlugin: () => {
|
|
8
|
+
plugin: SelectionPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
pageIndex: number;
|
|
3
|
+
scale: number;
|
|
4
|
+
background?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
7
|
+
background: string;
|
|
8
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-selection';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SelectionPlugin } from '../../lib/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get the selection plugin's capability API.
|
|
4
|
+
* This provides methods for controlling and listening to selection events.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useSelectionCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').SelectionCapability>>;
|
|
7
|
+
/**
|
|
8
|
+
* Hook to get the raw selection plugin instance.
|
|
9
|
+
* Useful for accessing plugin-specific properties or methods not exposed in the capability.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useSelectionPlugin: () => import('@embedpdf/core/vue').PluginState<SelectionPlugin>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-selection"),t=require("vue"),l=require("@embedpdf/models"),a=require("@embedpdf/plugin-interaction-manager/vue"),n=()=>e.useCapability(o.SelectionPlugin.id),i=t.defineComponent({__name:"selection-layer",props:{pageIndex:{},scale:{},background:{default:"rgba(33, 150, 243)"}},setup(e){const i=e,{provides:r}=n(),{provides:u}=a.useInteractionManagerCapability(),{register:c}=a.usePointerHandlers({pageIndex:i.pageIndex}),{setCursor:d,removeCursor:s}=a.useCursor(),p=t.ref([]),g=t.ref(null);let v;t.watchEffect((e=>{if(r.value){e(r.value.onSelectionChange((()=>{var e;"default"===(null==(e=u.value)?void 0:e.getActiveMode())?(p.value=r.value.getHighlightRectsForPage(i.pageIndex),g.value=r.value.getBoundingRectForPage(i.pageIndex)):(p.value=[],g.value=null)})))}})),t.watchEffect((e=>{if(r.value){const o=r.value.getGeometry(i.pageIndex);o.wait((e=>v=e),l.ignore),e((()=>{o.abort({code:l.PdfErrorCode.Cancelled,message:"SelectionLayer unmounted"})}))}}));const x=t.computed((()=>({onPointerDown:(e,t,a)=>{if(!r.value||!r.value.isEnabledForMode(a))return;r.value.clear();r.value.getGeometry(i.pageIndex).wait((t=>{const l=o.glyphAt(t,e);-1!==l&&r.value.begin(i.pageIndex,l)}),l.ignore)},onPointerMove:(e,t,l)=>{if(!r.value||!r.value.isEnabledForMode(l))return;const a=v?o.glyphAt(v,e):-1;-1!==a?(d("selection-text","text",10),r.value.update(i.pageIndex,a)):s("selection-text")},onPointerUp:(e,o,t)=>{r.value&&r.value.isEnabledForMode(t)&&r.value.end()},onHandlerActiveEnd:e=>{r.value&&r.value.isEnabledForMode(e)&&r.value.clear()}})));return t.watchEffect((e=>{if(c){const o=c(x.value);o&&e(o)}})),(e,o)=>g.value?(t.openBlock(),t.createElementBlock("div",{key:0,style:t.normalizeStyle({position:"absolute",left:g.value.origin.x*e.scale+"px",top:g.value.origin.y*e.scale+"px",width:g.value.size.width*e.scale+"px",height:g.value.size.height*e.scale+"px",mixBlendMode:"multiply",isolation:"isolate",pointerEvents:"none"})},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(p.value,((o,l)=>(t.openBlock(),t.createElementBlock("div",{key:l,style:t.normalizeStyle({position:"absolute",left:(o.origin.x-g.value.origin.x)*e.scale+"px",top:(o.origin.y-g.value.origin.y)*e.scale+"px",width:o.size.width*e.scale+"px",height:o.size.height*e.scale+"px",background:e.background})},null,4)))),128))],4)):t.createCommentVNode("",!0)}}),r=t.defineComponent({__name:"copy-to-clipboard",setup(e){const{provides:o}=n();return t.watchEffect((e=>{if(o.value){e(o.value.onCopyToClipboard((e=>{navigator.clipboard.writeText(e).catch((e=>{console.error("Failed to copy text to clipboard:",e)}))})))}})),(e,o)=>null}});exports.CopyToClipboard=r,exports.SelectionLayer=i,exports.useSelectionCapability=n,exports.useSelectionPlugin=()=>e.usePlugin(o.SelectionPlugin.id);
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-selection.ts","../../src/vue/components/selection-layer.vue","../../src/vue/components/copy-to-clipboard.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\n/**\n * Hook to get the selection plugin's capability API.\n * This provides methods for controlling and listening to selection events.\n */\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\n\n/**\n * Hook to get the raw selection plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const useSelectionPlugin = () => usePlugin<SelectionPlugin>(SelectionPlugin.id);\n","<script setup lang=\"ts\">\nimport { ref, watchEffect, computed } from 'vue';\nimport { ignore, PdfErrorCode, PdfPageGeometry, Rect } from '@embedpdf/models';\nimport {\n useCursor,\n useInteractionManagerCapability,\n usePointerHandlers,\n} from '@embedpdf/plugin-interaction-manager/vue';\nimport { PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';\nimport { glyphAt } from '@embedpdf/plugin-selection';\nimport { useSelectionCapability } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n scale: number;\n background?: string;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n background: 'rgba(33, 150, 243)', // Default selection color\n});\n\nconst { provides: sel } = useSelectionCapability();\nconst { provides: im } = useInteractionManagerCapability();\nconst { register } = usePointerHandlers({ pageIndex: props.pageIndex });\nconst { setCursor, removeCursor } = useCursor();\n\nconst rects = ref<Rect[]>([]);\nconst boundingRect = ref<Rect | null>(null);\n\n// Subscribe to selection changes and update the rendered rectangles\nwatchEffect((onCleanup) => {\n if (sel.value) {\n const unsubscribe = sel.value.onSelectionChange(() => {\n const mode = im.value?.getActiveMode();\n if (mode === 'default') {\n rects.value = sel.value!.getHighlightRectsForPage(props.pageIndex);\n boundingRect.value = sel.value!.getBoundingRectForPage(props.pageIndex);\n } else {\n rects.value = [];\n boundingRect.value = null;\n }\n });\n onCleanup(unsubscribe);\n }\n});\n\n// Cache page geometry for faster hit-testing during pointer moves\nlet geoCache: PdfPageGeometry | undefined;\nwatchEffect((onCleanup) => {\n if (sel.value) {\n const task = sel.value.getGeometry(props.pageIndex);\n task.wait((g) => (geoCache = g), ignore);\n\n onCleanup(() => {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'SelectionLayer unmounted',\n });\n });\n }\n});\n\nconst handlers = computed(\n (): PointerEventHandlersWithLifecycle<PointerEvent> => ({\n onPointerDown: (point, _evt, modeId) => {\n if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;\n sel.value.clear();\n const task = sel.value.getGeometry(props.pageIndex);\n task.wait((geo) => {\n const g = glyphAt(geo, point);\n if (g !== -1) sel.value!.begin(props.pageIndex, g);\n }, ignore);\n },\n onPointerMove: (point, _evt, modeId) => {\n if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;\n const g = geoCache ? glyphAt(geoCache, point) : -1;\n if (g !== -1) {\n setCursor('selection-text', 'text', 10);\n sel.value.update(props.pageIndex, g);\n } else {\n removeCursor('selection-text');\n }\n },\n onPointerUp: (_point, _evt, modeId) => {\n if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;\n sel.value.end();\n },\n onHandlerActiveEnd: (modeId) => {\n if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;\n sel.value.clear();\n },\n }),\n);\n\n// Register the pointer handlers with the interaction manager\nwatchEffect((onCleanup) => {\n if (register) {\n const cleanup = register(handlers.value);\n if (cleanup) onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div\n v-if=\"boundingRect\"\n :style=\"{\n position: 'absolute',\n left: `${boundingRect.origin.x * scale}px`,\n top: `${boundingRect.origin.y * scale}px`,\n width: `${boundingRect.size.width * scale}px`,\n height: `${boundingRect.size.height * scale}px`,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n pointerEvents: 'none',\n }\"\n >\n <div\n v-for=\"(rect, i) in rects\"\n :key=\"i\"\n :style=\"{\n position: 'absolute',\n left: `${(rect.origin.x - boundingRect.origin.x) * scale}px`,\n top: `${(rect.origin.y - boundingRect.origin.y) * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n background: background,\n }\"\n />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { watchEffect } from 'vue';\nimport { useSelectionCapability } from '../hooks';\n\nconst { provides: sel } = useSelectionCapability();\n\n// This effect runs when the component is mounted and the capability is available.\n// It automatically handles unsubscribing when the component is unmounted.\nwatchEffect((onCleanup) => {\n if (sel.value) {\n const unsubscribe = sel.value.onCopyToClipboard((text) => {\n // Use the Clipboard API to write the text\n navigator.clipboard.writeText(text).catch((err) => {\n console.error('Failed to copy text to clipboard:', err);\n });\n });\n\n // Register the cleanup function to run on unmount or re-run\n onCleanup(unsubscribe);\n }\n});\n</script>\n\n<template>\n <!-- This component renders nothing to the DOM -->\n</template>\n"],"names":["useSelectionCapability","useCapability","SelectionPlugin","id","props","__props","provides","sel","im","useInteractionManagerCapability","register","usePointerHandlers","pageIndex","setCursor","removeCursor","useCursor","rects","ref","boundingRect","geoCache","vue$1","watchEffect","onCleanup","value","onSelectionChange","_a","getActiveMode","getHighlightRectsForPage","getBoundingRectForPage","task","getGeometry","wait","g","ignore","abort","code","PdfErrorCode","Cancelled","message","handlers","computed","onPointerDown","point","_evt","modeId","isEnabledForMode","clear","geo","glyphAt","begin","onPointerMove","update","onPointerUp","_point","end","onHandlerActiveEnd","cleanup","_createElementBlock","style","_normalizeStyle","left","origin","x","scale","top","y","width","size","height","_openBlock","createElementBlock","_Fragment","_renderList","renderList","rect","i","key","background","onCopyToClipboard","text","navigator","clipboard","writeText","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