@embedpdf/plugin-selection 1.0.20 → 1.0.22
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +97 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/selection-plugin.d.ts +8 -4
- package/dist/lib/types.d.ts +10 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +12 -83
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +12 -83
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +18 -71
- package/dist/vue/index.js.map +1 -1
- package/package.json +8 -8
package/dist/lib/types.d.ts
CHANGED
|
@@ -28,6 +28,14 @@ export interface FormattedSelection {
|
|
|
28
28
|
rect: Rect;
|
|
29
29
|
segmentRects: Rect[];
|
|
30
30
|
}
|
|
31
|
+
export interface SelectionRectsCallback {
|
|
32
|
+
rects: Rect[];
|
|
33
|
+
boundingRect: Rect | null;
|
|
34
|
+
}
|
|
35
|
+
export interface RegisterSelectionOnPageOptions {
|
|
36
|
+
pageIndex: number;
|
|
37
|
+
onRectsChange: (data: SelectionRectsCallback) => void;
|
|
38
|
+
}
|
|
31
39
|
export interface SelectionCapability {
|
|
32
40
|
getGeometry(page: number): PdfTask<PdfPageGeometry>;
|
|
33
41
|
getFormattedSelection(): FormattedSelection[];
|
|
@@ -60,4 +68,6 @@ export interface SelectionCapability {
|
|
|
60
68
|
isEnabledForMode(modeId: string): boolean;
|
|
61
69
|
/** Get the current state of the selection plugin. */
|
|
62
70
|
getState(): SelectionState;
|
|
71
|
+
/** Register selection handlers for a specific page */
|
|
72
|
+
registerSelectionOnPage: (opts: RegisterSelectionOnPageOptions) => () => void;
|
|
63
73
|
}
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-selection"),i=require("preact/jsx-runtime");require("preact");const o=require("preact/hooks"),r=require("@embedpdf/core/preact"),n=()=>r.useCapability(t.SelectionPlugin.id);function l(){const{provides:e}=n();return o.useEffect((()=>{if(e)return e.onCopyToClipboard((e=>{navigator.clipboard.writeText(e)}))}),[e]),null}const s=e.createPluginPackage(t.SelectionPluginPackage).addUtility(l).build();exports.CopyToClipboard=l,exports.SelectionLayer=function({pageIndex:e,scale:t,background:r="rgba(33,150,243)"}){const{provides:l}=n(),[s,a]=o.useState([]),[u,c]=o.useState(null);return o.useEffect((()=>{if(l)return l.registerSelectionOnPage({pageIndex:e,onRectsChange:({rects:e,boundingRect:t})=>{a(e),c(t)}})}),[l,e]),u?i.jsx("div",{style:{position:"absolute",left:u.origin.x*t,top:u.origin.y*t,width:u.size.width*t,height:u.size.height*t,mixBlendMode:"multiply",isolation:"isolate"},children:s.map(((e,o)=>i.jsx("div",{style:{position:"absolute",left:(e.origin.x-u.origin.x)*t,top:(e.origin.y-u.origin.y)*t,width:e.size.width*t,height:e.size.height*t,background:r,pointerEvents:"none"}},o)))}):null},exports.SelectionPluginPackage=s,exports.useSelectionCapability=n,exports.useSelectionPlugin=()=>r.usePlugin(t.SelectionPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-selection.ts","../../src/shared/components/copy-to-clipboard.tsx","../../src/shared/index.ts","../../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 { createPluginPackage } from '@embedpdf/core';\nimport { SelectionPluginPackage as BaseSelectionPluginPackage } from '@embedpdf/plugin-selection';\n\nimport { CopyToClipboard } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-selection';\n\nexport const SelectionPluginPackage = createPluginPackage(BaseSelectionPluginPackage)\n .addUtility(CopyToClipboard)\n .build();\n","import { useEffect, useState } from '@framework';\nimport { Rect } from '@embedpdf/models';\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 [rects, setRects] = useState<Rect[]>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!sel) return;\n\n return sel.registerSelectionOnPage({\n pageIndex,\n onRectsChange: ({ rects, boundingRect }) => {\n setRects(rects);\n setBoundingRect(boundingRect);\n },\n });\n }, [sel, pageIndex]);\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","CopyToClipboard","provides","sel","useEffect","onCopyToClipboard","text","navigator","clipboard","writeText","SelectionPluginPackage","createPluginPackage","BaseSelectionPluginPackage","addUtility","build","pageIndex","scale","background","rects","setRects","useState","boundingRect","setBoundingRect","registerSelectionOnPage","onRectsChange","jsxRuntime","jsx","style","position","left","origin","x","top","y","width","size","height","mixBlendMode","isolation","children","map","b","i","pointerEvents","usePlugin"],"mappings":"+QAGaA,EAAyB,IAAMC,gBAA+BC,EAAAA,gBAAgBC,ICCpF,SAASC,IACd,MAAQC,SAAUC,GAAQN,IASnB,OAPPO,EAAAA,WAAU,KACR,GAAKD,EACE,OAAAA,EAAIE,mBAAmBC,IAClBC,UAAAC,UAAUC,UAAUH,EAAI,GACnC,GACA,CAACH,IAEG,IACT,CCNO,MAAMO,EAAyBC,EAAoBA,oBAAAC,EAA0BF,wBACjFG,WAAWZ,GACXa,yDCDI,UAAwBC,UAAEA,EAAAC,MAAWA,EAAOC,WAAAA,EAAa,qBAC9D,MAAQf,SAAUC,GAAQN,KACnBqB,EAAOC,GAAYC,EAAAA,SAAiB,KACpCC,EAAcC,GAAmBF,EAAAA,SAAsB,MAc1D,OAZJhB,EAAAA,WAAU,KACR,GAAKD,EAEL,OAAOA,EAAIoB,wBAAwB,CACjCR,YACAS,cAAe,EAAGN,MAAAA,EAAOG,aAAAA,MACvBF,EAASD,GACTI,EAAgBD,EAAY,GAE/B,GACA,CAAClB,EAAKY,IAEJM,EAGHI,EAAAC,IAAC,MAAA,CACCC,MAAO,CACLC,SAAU,WACVC,KAAMR,EAAaS,OAAOC,EAAIf,EAC9BgB,IAAKX,EAAaS,OAAOG,EAAIjB,EAC7BkB,MAAOb,EAAac,KAAKD,MAAQlB,EACjCoB,OAAQf,EAAac,KAAKC,OAASpB,EACnCqB,aAAc,WACdC,UAAW,WAGZC,SAAMrB,EAAAsB,KAAI,CAACC,EAAGC,IACbjB,EAAAC,IAAC,MAAA,CAECC,MAAO,CACLC,SAAU,WACVC,MAAOY,EAAEX,OAAOC,EAAIV,EAAaS,OAAOC,GAAKf,EAC7CgB,KAAMS,EAAEX,OAAOG,EAAIZ,EAAaS,OAAOG,GAAKjB,EAC5CkB,MAAOO,EAAEN,KAAKD,MAAQlB,EACtBoB,OAAQK,EAAEN,KAAKC,OAASpB,EACxBC,aACA0B,cAAe,SARZD,OAhBa,IA8B5B,+FHrDkC,IAAME,YAA2B7C,EAAAA,gBAAgBC"}
|
package/dist/preact/index.js
CHANGED
|
@@ -1,99 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SelectionPlugin,
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { SelectionPlugin, SelectionPluginPackage as SelectionPluginPackage$1 } from "@embedpdf/plugin-selection";
|
|
3
|
+
export * from "@embedpdf/plugin-selection";
|
|
3
4
|
import { jsx } from "preact/jsx-runtime";
|
|
4
5
|
import "preact";
|
|
5
|
-
import { useState,
|
|
6
|
-
import {
|
|
7
|
-
import { useInteractionManagerCapability, usePointerHandlers, useCursor } from "@embedpdf/plugin-interaction-manager/preact";
|
|
6
|
+
import { useState, useEffect } from "preact/hooks";
|
|
7
|
+
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
8
8
|
const useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
9
9
|
const useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
10
10
|
function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
11
11
|
const { provides: sel } = useSelectionCapability();
|
|
12
|
-
const { plugin: selectionPlugin } = useSelectionPlugin();
|
|
13
|
-
const { provides: im } = useInteractionManagerCapability();
|
|
14
|
-
const { register } = usePointerHandlers({ pageIndex });
|
|
15
12
|
const [rects, setRects] = useState([]);
|
|
16
13
|
const [boundingRect, setBoundingRect] = useState(null);
|
|
17
|
-
const { setCursor, removeCursor } = useCursor();
|
|
18
|
-
const geoCacheRef = useRef(null);
|
|
19
14
|
useEffect(() => {
|
|
20
15
|
if (!sel) return;
|
|
21
|
-
return sel.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setRects(
|
|
25
|
-
setBoundingRect(
|
|
26
|
-
} else {
|
|
27
|
-
setRects([]);
|
|
28
|
-
setBoundingRect(null);
|
|
16
|
+
return sel.registerSelectionOnPage({
|
|
17
|
+
pageIndex,
|
|
18
|
+
onRectsChange: ({ rects: rects2, boundingRect: boundingRect2 }) => {
|
|
19
|
+
setRects(rects2);
|
|
20
|
+
setBoundingRect(boundingRect2);
|
|
29
21
|
}
|
|
30
22
|
});
|
|
31
23
|
}, [sel, pageIndex]);
|
|
32
|
-
const cachedGlyphAt = useCallback((pt) => {
|
|
33
|
-
const geo = geoCacheRef.current;
|
|
34
|
-
return geo ? glyphAt(geo, pt) : -1;
|
|
35
|
-
}, []);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!sel) return;
|
|
38
|
-
const task = sel.getGeometry(pageIndex);
|
|
39
|
-
task.wait((g) => geoCacheRef.current = g, ignore);
|
|
40
|
-
return () => {
|
|
41
|
-
task.abort({
|
|
42
|
-
code: PdfErrorCode.Cancelled,
|
|
43
|
-
message: "Cancelled"
|
|
44
|
-
});
|
|
45
|
-
geoCacheRef.current = null;
|
|
46
|
-
};
|
|
47
|
-
}, [sel, pageIndex]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (!selectionPlugin || !sel) return;
|
|
50
|
-
return selectionPlugin.onRefreshPages((pages) => {
|
|
51
|
-
if (pages.includes(pageIndex)) {
|
|
52
|
-
const task = sel.getGeometry(pageIndex);
|
|
53
|
-
task.wait((g) => geoCacheRef.current = g, ignore);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}, [sel, selectionPlugin, pageIndex]);
|
|
57
|
-
const handlers = useMemo(
|
|
58
|
-
() => ({
|
|
59
|
-
onPointerDown: (point, _evt, modeId) => {
|
|
60
|
-
if (!sel) return;
|
|
61
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
62
|
-
sel.clear();
|
|
63
|
-
const task = sel.getGeometry(pageIndex);
|
|
64
|
-
task.wait((geo) => {
|
|
65
|
-
const g = glyphAt(geo, point);
|
|
66
|
-
if (g !== -1) sel.begin(pageIndex, g);
|
|
67
|
-
}, ignore);
|
|
68
|
-
},
|
|
69
|
-
onPointerMove: (point, _evt, modeId) => {
|
|
70
|
-
if (!sel) return;
|
|
71
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
72
|
-
const g = cachedGlyphAt(point);
|
|
73
|
-
if (g !== -1) {
|
|
74
|
-
setCursor("selection-text", "text", 10);
|
|
75
|
-
} else {
|
|
76
|
-
removeCursor("selection-text");
|
|
77
|
-
}
|
|
78
|
-
if (g !== -1) sel.update(pageIndex, g);
|
|
79
|
-
},
|
|
80
|
-
onPointerUp: (_point, _evt, modeId) => {
|
|
81
|
-
if (!sel) return;
|
|
82
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
83
|
-
sel.end();
|
|
84
|
-
},
|
|
85
|
-
onHandlerActiveEnd(modeId) {
|
|
86
|
-
if (!sel) return;
|
|
87
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
88
|
-
sel.clear();
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
[sel, pageIndex, cachedGlyphAt]
|
|
92
|
-
);
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
if (!register) return;
|
|
95
|
-
return register(handlers);
|
|
96
|
-
}, [register, handlers]);
|
|
97
24
|
if (!boundingRect) return null;
|
|
98
25
|
return /* @__PURE__ */ jsx(
|
|
99
26
|
"div",
|
|
@@ -135,9 +62,11 @@ function CopyToClipboard() {
|
|
|
135
62
|
}, [sel]);
|
|
136
63
|
return null;
|
|
137
64
|
}
|
|
65
|
+
const SelectionPluginPackage = createPluginPackage(SelectionPluginPackage$1).addUtility(CopyToClipboard).build();
|
|
138
66
|
export {
|
|
139
67
|
CopyToClipboard,
|
|
140
68
|
SelectionLayer,
|
|
69
|
+
SelectionPluginPackage,
|
|
141
70
|
useSelectionCapability,
|
|
142
71
|
useSelectionPlugin
|
|
143
72
|
};
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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","../../src/shared/index.ts"],"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, useState } from '@framework';\nimport { Rect } from '@embedpdf/models';\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 [rects, setRects] = useState<Rect[]>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!sel) return;\n\n return sel.registerSelectionOnPage({\n pageIndex,\n onRectsChange: ({ rects, boundingRect }) => {\n setRects(rects);\n setBoundingRect(boundingRect);\n },\n });\n }, [sel, pageIndex]);\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","import { createPluginPackage } from '@embedpdf/core';\nimport { SelectionPluginPackage as BaseSelectionPluginPackage } from '@embedpdf/plugin-selection';\n\nimport { CopyToClipboard } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-selection';\n\nexport const SelectionPluginPackage = createPluginPackage(BaseSelectionPluginPackage)\n .addUtility(CopyToClipboard)\n .build();\n"],"names":["rects","boundingRect","BaseSelectionPluginPackage"],"mappings":";;;;;;;AAGO,MAAM,yBAAyB,MAAM,cAA+B,gBAAgB,EAAE;AACtF,MAAM,qBAAqB,MAAM,UAA2B,gBAAgB,EAAE;ACM9E,SAAS,eAAe,EAAE,WAAW,OAAO,aAAa,sBAA6B;AAC3F,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AACjD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiB,CAAA,CAAE;AAC7C,QAAM,CAAC,cAAc,eAAe,IAAI,SAAsB,IAAI;AAElE,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AAEV,WAAO,IAAI,wBAAwB;AAAA,MACjC;AAAA,MACA,eAAe,CAAC,EAAE,OAAAA,QAAO,cAAAC,oBAAmB;AAC1C,iBAASD,MAAK;AACd,wBAAgBC,aAAY;AAAA,MAAA;AAAA,IAC9B,CACD;AAAA,EAAA,GACA,CAAC,KAAK,SAAS,CAAC;AAEf,MAAA,CAAC,aAAqB,QAAA;AAGxB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,aAAa,OAAO,IAAI;AAAA,QAC9B,KAAK,aAAa,OAAO,IAAI;AAAA,QAC7B,OAAO,aAAa,KAAK,QAAQ;AAAA,QACjC,QAAQ,aAAa,KAAK,SAAS;AAAA,QACnC,cAAc;AAAA,QACd,WAAW;AAAA,MACb;AAAA,MAEC,UAAM,MAAA,IAAI,CAAC,GAAG,MACb;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC,OAAO;AAAA,YACL,UAAU;AAAA,YACV,OAAO,EAAE,OAAO,IAAI,aAAa,OAAO,KAAK;AAAA,YAC7C,MAAM,EAAE,OAAO,IAAI,aAAa,OAAO,KAAK;AAAA,YAC5C,OAAO,EAAE,KAAK,QAAQ;AAAA,YACtB,QAAQ,EAAE,KAAK,SAAS;AAAA,YACxB;AAAA,YACA,eAAe;AAAA,UAAA;AAAA,QACjB;AAAA,QATK;AAAA,MAWR,CAAA;AAAA,IAAA;AAAA,EACH;AAEJ;ACrDO,SAAS,kBAAkB;AAChC,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AAEjD,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AACH,WAAA,IAAI,kBAAkB,CAAC,SAAS;AAC3B,gBAAA,UAAU,UAAU,IAAI;AAAA,IAAA,CACnC;AAAA,EAAA,GACA,CAAC,GAAG,CAAC;AAED,SAAA;AACT;ACNO,MAAM,yBAAyB,oBAAoBC,wBAA0B,EACjF,WAAW,eAAe,EAC1B,MAAM;"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-selection"),i=require("react/jsx-runtime"),o=require("react"),r=require("@embedpdf/core/react"),n=()=>r.useCapability(t.SelectionPlugin.id);function l(){const{provides:e}=n();return o.useEffect((()=>{if(e)return e.onCopyToClipboard((e=>{navigator.clipboard.writeText(e)}))}),[e]),null}const s=e.createPluginPackage(t.SelectionPluginPackage).addUtility(l).build();exports.CopyToClipboard=l,exports.SelectionLayer=function({pageIndex:e,scale:t,background:r="rgba(33,150,243)"}){const{provides:l}=n(),[s,a]=o.useState([]),[u,c]=o.useState(null);return o.useEffect((()=>{if(l)return l.registerSelectionOnPage({pageIndex:e,onRectsChange:({rects:e,boundingRect:t})=>{a(e),c(t)}})}),[l,e]),u?i.jsx("div",{style:{position:"absolute",left:u.origin.x*t,top:u.origin.y*t,width:u.size.width*t,height:u.size.height*t,mixBlendMode:"multiply",isolation:"isolate"},children:s.map(((e,o)=>i.jsx("div",{style:{position:"absolute",left:(e.origin.x-u.origin.x)*t,top:(e.origin.y-u.origin.y)*t,width:e.size.width*t,height:e.size.height*t,background:r,pointerEvents:"none"}},o)))}):null},exports.SelectionPluginPackage=s,exports.useSelectionCapability=n,exports.useSelectionPlugin=()=>r.usePlugin(t.SelectionPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 {
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-selection.ts","../../src/shared/components/copy-to-clipboard.tsx","../../src/shared/index.ts","../../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 { createPluginPackage } from '@embedpdf/core';\nimport { SelectionPluginPackage as BaseSelectionPluginPackage } from '@embedpdf/plugin-selection';\n\nimport { CopyToClipboard } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-selection';\n\nexport const SelectionPluginPackage = createPluginPackage(BaseSelectionPluginPackage)\n .addUtility(CopyToClipboard)\n .build();\n","import { useEffect, useState } from '@framework';\nimport { Rect } from '@embedpdf/models';\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 [rects, setRects] = useState<Rect[]>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!sel) return;\n\n return sel.registerSelectionOnPage({\n pageIndex,\n onRectsChange: ({ rects, boundingRect }) => {\n setRects(rects);\n setBoundingRect(boundingRect);\n },\n });\n }, [sel, pageIndex]);\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","CopyToClipboard","provides","sel","useEffect","onCopyToClipboard","text","navigator","clipboard","writeText","SelectionPluginPackage","createPluginPackage","BaseSelectionPluginPackage","addUtility","build","pageIndex","scale","background","rects","setRects","useState","boundingRect","setBoundingRect","registerSelectionOnPage","onRectsChange","jsxRuntime","jsx","style","position","left","origin","x","top","y","width","size","height","mixBlendMode","isolation","children","map","b","i","pointerEvents","usePlugin"],"mappings":"8OAGaA,EAAyB,IAAMC,gBAA+BC,EAAAA,gBAAgBC,ICCpF,SAASC,IACd,MAAQC,SAAUC,GAAQN,IASnB,OAPPO,EAAAA,WAAU,KACR,GAAKD,EACE,OAAAA,EAAIE,mBAAmBC,IAClBC,UAAAC,UAAUC,UAAUH,EAAI,GACnC,GACA,CAACH,IAEG,IACT,CCNO,MAAMO,EAAyBC,EAAoBA,oBAAAC,EAA0BF,wBACjFG,WAAWZ,GACXa,yDCDI,UAAwBC,UAAEA,EAAAC,MAAWA,EAAOC,WAAAA,EAAa,qBAC9D,MAAQf,SAAUC,GAAQN,KACnBqB,EAAOC,GAAYC,EAAAA,SAAiB,KACpCC,EAAcC,GAAmBF,EAAAA,SAAsB,MAc1D,OAZJhB,EAAAA,WAAU,KACR,GAAKD,EAEL,OAAOA,EAAIoB,wBAAwB,CACjCR,YACAS,cAAe,EAAGN,MAAAA,EAAOG,aAAAA,MACvBF,EAASD,GACTI,EAAgBD,EAAY,GAE/B,GACA,CAAClB,EAAKY,IAEJM,EAGHI,EAAAC,IAAC,MAAA,CACCC,MAAO,CACLC,SAAU,WACVC,KAAMR,EAAaS,OAAOC,EAAIf,EAC9BgB,IAAKX,EAAaS,OAAOG,EAAIjB,EAC7BkB,MAAOb,EAAac,KAAKD,MAAQlB,EACjCoB,OAAQf,EAAac,KAAKC,OAASpB,EACnCqB,aAAc,WACdC,UAAW,WAGZC,SAAMrB,EAAAsB,KAAI,CAACC,EAAGC,IACbjB,EAAAC,IAAC,MAAA,CAECC,MAAO,CACLC,SAAU,WACVC,MAAOY,EAAEX,OAAOC,EAAIV,EAAaS,OAAOC,GAAKf,EAC7CgB,KAAMS,EAAEX,OAAOG,EAAIZ,EAAaS,OAAOG,GAAKjB,EAC5CkB,MAAOO,EAAEN,KAAKD,MAAQlB,EACtBoB,OAAQK,EAAEN,KAAKC,OAASpB,EACxBC,aACA0B,cAAe,SARZD,OAhBa,IA8B5B,+FHrDkC,IAAME,YAA2B7C,EAAAA,gBAAgBC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,98 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SelectionPlugin,
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { SelectionPlugin, SelectionPluginPackage as SelectionPluginPackage$1 } from "@embedpdf/plugin-selection";
|
|
3
|
+
export * from "@embedpdf/plugin-selection";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import { useState,
|
|
5
|
-
import {
|
|
6
|
-
import { useInteractionManagerCapability, usePointerHandlers, useCursor } from "@embedpdf/plugin-interaction-manager/react";
|
|
5
|
+
import { useState, useEffect } from "react";
|
|
6
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
7
7
|
const useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
8
8
|
const useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
9
9
|
function SelectionLayer({ pageIndex, scale, background = "rgba(33,150,243)" }) {
|
|
10
10
|
const { provides: sel } = useSelectionCapability();
|
|
11
|
-
const { plugin: selectionPlugin } = useSelectionPlugin();
|
|
12
|
-
const { provides: im } = useInteractionManagerCapability();
|
|
13
|
-
const { register } = usePointerHandlers({ pageIndex });
|
|
14
11
|
const [rects, setRects] = useState([]);
|
|
15
12
|
const [boundingRect, setBoundingRect] = useState(null);
|
|
16
|
-
const { setCursor, removeCursor } = useCursor();
|
|
17
|
-
const geoCacheRef = useRef(null);
|
|
18
13
|
useEffect(() => {
|
|
19
14
|
if (!sel) return;
|
|
20
|
-
return sel.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
setRects(
|
|
24
|
-
setBoundingRect(
|
|
25
|
-
} else {
|
|
26
|
-
setRects([]);
|
|
27
|
-
setBoundingRect(null);
|
|
15
|
+
return sel.registerSelectionOnPage({
|
|
16
|
+
pageIndex,
|
|
17
|
+
onRectsChange: ({ rects: rects2, boundingRect: boundingRect2 }) => {
|
|
18
|
+
setRects(rects2);
|
|
19
|
+
setBoundingRect(boundingRect2);
|
|
28
20
|
}
|
|
29
21
|
});
|
|
30
22
|
}, [sel, pageIndex]);
|
|
31
|
-
const cachedGlyphAt = useCallback((pt) => {
|
|
32
|
-
const geo = geoCacheRef.current;
|
|
33
|
-
return geo ? glyphAt(geo, pt) : -1;
|
|
34
|
-
}, []);
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (!sel) return;
|
|
37
|
-
const task = sel.getGeometry(pageIndex);
|
|
38
|
-
task.wait((g) => geoCacheRef.current = g, ignore);
|
|
39
|
-
return () => {
|
|
40
|
-
task.abort({
|
|
41
|
-
code: PdfErrorCode.Cancelled,
|
|
42
|
-
message: "Cancelled"
|
|
43
|
-
});
|
|
44
|
-
geoCacheRef.current = null;
|
|
45
|
-
};
|
|
46
|
-
}, [sel, pageIndex]);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (!selectionPlugin || !sel) return;
|
|
49
|
-
return selectionPlugin.onRefreshPages((pages) => {
|
|
50
|
-
if (pages.includes(pageIndex)) {
|
|
51
|
-
const task = sel.getGeometry(pageIndex);
|
|
52
|
-
task.wait((g) => geoCacheRef.current = g, ignore);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}, [sel, selectionPlugin, pageIndex]);
|
|
56
|
-
const handlers = useMemo(
|
|
57
|
-
() => ({
|
|
58
|
-
onPointerDown: (point, _evt, modeId) => {
|
|
59
|
-
if (!sel) return;
|
|
60
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
61
|
-
sel.clear();
|
|
62
|
-
const task = sel.getGeometry(pageIndex);
|
|
63
|
-
task.wait((geo) => {
|
|
64
|
-
const g = glyphAt(geo, point);
|
|
65
|
-
if (g !== -1) sel.begin(pageIndex, g);
|
|
66
|
-
}, ignore);
|
|
67
|
-
},
|
|
68
|
-
onPointerMove: (point, _evt, modeId) => {
|
|
69
|
-
if (!sel) return;
|
|
70
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
71
|
-
const g = cachedGlyphAt(point);
|
|
72
|
-
if (g !== -1) {
|
|
73
|
-
setCursor("selection-text", "text", 10);
|
|
74
|
-
} else {
|
|
75
|
-
removeCursor("selection-text");
|
|
76
|
-
}
|
|
77
|
-
if (g !== -1) sel.update(pageIndex, g);
|
|
78
|
-
},
|
|
79
|
-
onPointerUp: (_point, _evt, modeId) => {
|
|
80
|
-
if (!sel) return;
|
|
81
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
82
|
-
sel.end();
|
|
83
|
-
},
|
|
84
|
-
onHandlerActiveEnd(modeId) {
|
|
85
|
-
if (!sel) return;
|
|
86
|
-
if (!sel.isEnabledForMode(modeId)) return;
|
|
87
|
-
sel.clear();
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
[sel, pageIndex, cachedGlyphAt]
|
|
91
|
-
);
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
if (!register) return;
|
|
94
|
-
return register(handlers);
|
|
95
|
-
}, [register, handlers]);
|
|
96
23
|
if (!boundingRect) return null;
|
|
97
24
|
return /* @__PURE__ */ jsx(
|
|
98
25
|
"div",
|
|
@@ -134,9 +61,11 @@ function CopyToClipboard() {
|
|
|
134
61
|
}, [sel]);
|
|
135
62
|
return null;
|
|
136
63
|
}
|
|
64
|
+
const SelectionPluginPackage = createPluginPackage(SelectionPluginPackage$1).addUtility(CopyToClipboard).build();
|
|
137
65
|
export {
|
|
138
66
|
CopyToClipboard,
|
|
139
67
|
SelectionLayer,
|
|
68
|
+
SelectionPluginPackage,
|
|
140
69
|
useSelectionCapability,
|
|
141
70
|
useSelectionPlugin
|
|
142
71
|
};
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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","../../src/shared/index.ts"],"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, useState } from '@framework';\nimport { Rect } from '@embedpdf/models';\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 [rects, setRects] = useState<Rect[]>([]);\n const [boundingRect, setBoundingRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!sel) return;\n\n return sel.registerSelectionOnPage({\n pageIndex,\n onRectsChange: ({ rects, boundingRect }) => {\n setRects(rects);\n setBoundingRect(boundingRect);\n },\n });\n }, [sel, pageIndex]);\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","import { createPluginPackage } from '@embedpdf/core';\nimport { SelectionPluginPackage as BaseSelectionPluginPackage } from '@embedpdf/plugin-selection';\n\nimport { CopyToClipboard } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-selection';\n\nexport const SelectionPluginPackage = createPluginPackage(BaseSelectionPluginPackage)\n .addUtility(CopyToClipboard)\n .build();\n"],"names":["rects","boundingRect","BaseSelectionPluginPackage"],"mappings":";;;;;;AAGO,MAAM,yBAAyB,MAAM,cAA+B,gBAAgB,EAAE;AACtF,MAAM,qBAAqB,MAAM,UAA2B,gBAAgB,EAAE;ACM9E,SAAS,eAAe,EAAE,WAAW,OAAO,aAAa,sBAA6B;AAC3F,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AACjD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiB,CAAA,CAAE;AAC7C,QAAM,CAAC,cAAc,eAAe,IAAI,SAAsB,IAAI;AAElE,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AAEV,WAAO,IAAI,wBAAwB;AAAA,MACjC;AAAA,MACA,eAAe,CAAC,EAAE,OAAAA,QAAO,cAAAC,oBAAmB;AAC1C,iBAASD,MAAK;AACd,wBAAgBC,aAAY;AAAA,MAAA;AAAA,IAC9B,CACD;AAAA,EAAA,GACA,CAAC,KAAK,SAAS,CAAC;AAEf,MAAA,CAAC,aAAqB,QAAA;AAGxB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,aAAa,OAAO,IAAI;AAAA,QAC9B,KAAK,aAAa,OAAO,IAAI;AAAA,QAC7B,OAAO,aAAa,KAAK,QAAQ;AAAA,QACjC,QAAQ,aAAa,KAAK,SAAS;AAAA,QACnC,cAAc;AAAA,QACd,WAAW;AAAA,MACb;AAAA,MAEC,UAAM,MAAA,IAAI,CAAC,GAAG,MACb;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC,OAAO;AAAA,YACL,UAAU;AAAA,YACV,OAAO,EAAE,OAAO,IAAI,aAAa,OAAO,KAAK;AAAA,YAC7C,MAAM,EAAE,OAAO,IAAI,aAAa,OAAO,KAAK;AAAA,YAC5C,OAAO,EAAE,KAAK,QAAQ;AAAA,YACtB,QAAQ,EAAE,KAAK,SAAS;AAAA,YACxB;AAAA,YACA,eAAe;AAAA,UAAA;AAAA,QACjB;AAAA,QATK;AAAA,MAWR,CAAA;AAAA,IAAA;AAAA,EACH;AAEJ;ACrDO,SAAS,kBAAkB;AAChC,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AAEjD,YAAU,MAAM;AACd,QAAI,CAAC,IAAK;AACH,WAAA,IAAI,kBAAkB,CAAC,SAAS;AAC3B,gBAAA,UAAU,UAAU,IAAI;AAAA,IAAA,CACnC;AAAA,EAAA,GACA,CAAC,GAAG,CAAC;AAED,SAAA;AACT;ACNO,MAAM,yBAAyB,oBAAoBC,wBAA0B,EACjF,WAAW,eAAe,EAC1B,MAAM;"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export * from './hooks';
|
|
2
2
|
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const SelectionPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').SelectionPlugin, import('../lib/index.ts').SelectionPluginConfig, import('../lib/index.ts').SelectionState, import('../lib/actions').SelectionAction>>;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export * from './hooks';
|
|
2
2
|
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const SelectionPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').SelectionPlugin, import('../lib/index.ts').SelectionPluginConfig, import('../lib/index.ts').SelectionState, import('../lib/actions').SelectionAction>>;
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-selection"),o=require("vue"),l=require("@embedpdf/core/vue"),i=()=>l.useCapability(t.SelectionPlugin.id),n=o.defineComponent({__name:"selection-layer",props:{pageIndex:{},scale:{},background:{default:"rgba(33, 150, 243)"}},setup(e){const t=e,{provides:l}=i(),n=o.ref([]),a=o.ref(null);let r;return o.onMounted((()=>{l.value&&(r=l.value.registerSelectionOnPage({pageIndex:t.pageIndex,onRectsChange:({rects:e,boundingRect:t})=>{n.value=e,a.value=t}}))})),o.onUnmounted((()=>{null==r||r()})),(e,t)=>a.value?(o.openBlock(),o.createElementBlock("div",{key:0,style:o.normalizeStyle({position:"absolute",left:a.value.origin.x*e.scale+"px",top:a.value.origin.y*e.scale+"px",width:a.value.size.width*e.scale+"px",height:a.value.size.height*e.scale+"px",mixBlendMode:"multiply",isolation:"isolate",pointerEvents:"none"})},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(n.value,((t,l)=>(o.openBlock(),o.createElementBlock("div",{key:l,style:o.normalizeStyle({position:"absolute",left:(t.origin.x-a.value.origin.x)*e.scale+"px",top:(t.origin.y-a.value.origin.y)*e.scale+"px",width:t.size.width*e.scale+"px",height:t.size.height*e.scale+"px",background:e.background})},null,4)))),128))],4)):o.createCommentVNode("",!0)}}),a=o.defineComponent({__name:"copy-to-clipboard",setup(e){const{provides:t}=i();return o.watchEffect((e=>{if(t.value){e(t.value.onCopyToClipboard((e=>{navigator.clipboard.writeText(e).catch((e=>{console.error("Failed to copy text to clipboard:",e)}))})))}})),(e,t)=>null}}),r=e.createPluginPackage(t.SelectionPluginPackage).addUtility(a).build();exports.CopyToClipboard=a,exports.SelectionLayer=n,exports.SelectionPluginPackage=r,exports.useSelectionCapability=i,exports.useSelectionPlugin=()=>l.usePlugin(t.SelectionPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/vue/index.cjs.map
CHANGED
|
@@ -1 +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","<
|
|
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","../../src/vue/index.ts"],"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","<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\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport type { Rect } from '@embedpdf/models';\nimport { useSelectionCapability } from '../hooks/use-selection';\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)',\n});\n\nconst { provides: sel } = useSelectionCapability();\nconst rects = ref<Rect[]>([]);\nconst boundingRect = ref<Rect | null>(null);\n\nlet unregister: (() => void) | undefined;\n\nonMounted(() => {\n if (!sel.value) return;\n\n unregister = sel.value.registerSelectionOnPage({\n pageIndex: props.pageIndex,\n onRectsChange: ({ rects: newRects, boundingRect: newBoundingRect }) => {\n rects.value = newRects;\n boundingRect.value = newBoundingRect;\n },\n });\n});\n\nonUnmounted(() => {\n unregister?.();\n});\n</script>\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","import { createPluginPackage } from '@embedpdf/core';\nimport { SelectionPluginPackage as BaseSelectionPluginPackage } from '@embedpdf/plugin-selection';\n\nimport { CopyToClipboard } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-selection';\n\nexport const SelectionPluginPackage = createPluginPackage(BaseSelectionPluginPackage)\n .addUtility(CopyToClipboard)\n .build();\n"],"names":["useSelectionCapability","useCapability","SelectionPlugin","id","props","__props","provides","sel","rects","ref","boundingRect","unregister","onMounted","value","registerSelectionOnPage","pageIndex","onRectsChange","newRects","newBoundingRect","onUnmounted","_createElementBlock","style","_normalizeStyle","left","origin","x","scale","top","y","width","size","height","_openBlock","createElementBlock","_Fragment","_renderList","renderList","rect","i","key","background","vue$1","watchEffect","onCleanup","onCopyToClipboard","text","navigator","clipboard","writeText","catch","err","console","error","SelectionPluginPackage","createPluginPackage","BaseSelectionPluginPackage","addUtility","CopyToClipboard","build","usePlugin"],"mappings":"2MAOaA,EAAyB,IAAMC,gBAA+BC,EAAAA,gBAAgBC,mICiC3F,MAAMC,EAAQC,GAINC,SAAUC,GAAQP,IACpBQ,EAAQC,EAAYA,IAAA,IACpBC,EAAeD,MAAiB,MAElC,IAAAE,SAEJC,EAAAA,WAAU,KACHL,EAAIM,QAEIF,EAAAJ,EAAIM,MAAMC,wBAAwB,CAC7CC,UAAWX,EAAMW,UACjBC,cAAe,EAAGR,MAAOS,EAAUP,aAAcQ,MAC/CV,EAAMK,MAAQI,EACdP,EAAaG,MAAQK,CAAA,IAExB,IAGHC,EAAAA,aAAY,KACG,MAAAR,GAAAA,GAAA,WA7DLD,EAAYG,qBADpBO,EAAAA,mBAyBM,MAAA,OAvBHC,MAAKC,EAAAA,eAAA,qBAA+CC,KAAAb,EAAAG,MAAaW,OAAOC,EAAIC,EAAKA,MAA7B,KAAiDC,IAAAjB,EAAAG,MAAaW,OAAOI,EAAIF,EAAKA,MAA7B,KAAmDG,MAAAnB,EAAAG,MAAaiB,KAAKD,MAAQH,EAAKA,MAA/B,KAAsDK,OAAArB,EAAAG,MAAaiB,KAAKC,OAASL,EAAKA,MAAhC,2EAW/MM,EAAAA,WAAA,GAAAZ,EAWEa,mBAAAC,WAVoB,KAAAC,EAAAC,WAAA5B,EAAAK,OAAZ,CAAAwB,EAAMC,mBADhBlB,EAAAa,mBAWE,MAAA,CATCM,IAAKD,EACLjB,MAAKC,EAAAA,eAAA,2BAAoDe,EAAKb,OAAOC,EAAIf,EAAYG,MAACW,OAAOC,GAAKC,EAAKA,gBAAuBW,EAAKb,OAAOI,EAAIlB,EAAYG,MAACW,OAAOI,GAAKF,EAAKA,WAAwBG,MAAAQ,EAAKP,KAAKD,MAAQH,EAAKA,MAAvB,KAAgDK,OAAAM,EAAKP,KAAKC,OAASL,EAAKA,MAAxB,gBAAkDc,EAAUA,4HCbvT,MAAQlC,SAAUC,GAAQP,WAI1ByC,EAAAC,aAAaC,IACX,GAAIpC,EAAIM,MAAO,CASb8B,EARoBpC,EAAIM,MAAM+B,mBAAmBC,IAE/CC,UAAUC,UAAUC,UAAUH,GAAMI,OAAOC,IACjCC,QAAAC,MAAM,oCAAqCF,EAAG,GACvD,IAIkB,oBCTZG,EAAyBC,EAAoBA,oBAAAC,EAA0BF,wBACjFG,WAAWC,GACXC,wJHE+B,IAAMC,YAA2BzD,EAAAA,gBAAgBC"}
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export * from './hooks';
|
|
2
2
|
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const SelectionPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').SelectionPlugin, import('../lib/index.ts').SelectionPluginConfig, import('../lib/index.ts').SelectionState, import('src/lib/actions').SelectionAction>>;
|