@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/vue/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { SelectionPlugin, SelectionPluginPackage as SelectionPluginPackage$1 } from "@embedpdf/plugin-selection";
|
|
3
|
+
export * from "@embedpdf/plugin-selection";
|
|
4
|
+
import { defineComponent, ref, onMounted, onUnmounted, createElementBlock, createCommentVNode, openBlock, normalizeStyle, Fragment, renderList, watchEffect } from "vue";
|
|
1
5
|
import { useCapability, usePlugin } from "@embedpdf/core/vue";
|
|
2
|
-
import { SelectionPlugin, glyphAt } from "@embedpdf/plugin-selection";
|
|
3
|
-
import { defineComponent, ref, watchEffect, computed, createElementBlock, createCommentVNode, openBlock, normalizeStyle, Fragment, renderList } from "vue";
|
|
4
|
-
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
5
|
-
import { useInteractionManagerCapability, usePointerHandlers, useCursor } from "@embedpdf/plugin-interaction-manager/vue";
|
|
6
6
|
const useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
7
7
|
const useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
8
8
|
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
@@ -15,76 +15,21 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
15
15
|
setup(__props) {
|
|
16
16
|
const props = __props;
|
|
17
17
|
const { provides: sel } = useSelectionCapability();
|
|
18
|
-
const { provides: im } = useInteractionManagerCapability();
|
|
19
|
-
const { register } = usePointerHandlers({ pageIndex: props.pageIndex });
|
|
20
|
-
const { setCursor, removeCursor } = useCursor();
|
|
21
18
|
const rects = ref([]);
|
|
22
19
|
const boundingRect = ref(null);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
rects.value = [];
|
|
33
|
-
boundingRect.value = null;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
onCleanup(unsubscribe);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
let geoCache;
|
|
40
|
-
watchEffect((onCleanup) => {
|
|
41
|
-
if (sel.value) {
|
|
42
|
-
const task = sel.value.getGeometry(props.pageIndex);
|
|
43
|
-
task.wait((g) => geoCache = g, ignore);
|
|
44
|
-
onCleanup(() => {
|
|
45
|
-
task.abort({
|
|
46
|
-
code: PdfErrorCode.Cancelled,
|
|
47
|
-
message: "SelectionLayer unmounted"
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const handlers = computed(
|
|
53
|
-
() => ({
|
|
54
|
-
onPointerDown: (point, _evt, modeId) => {
|
|
55
|
-
if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;
|
|
56
|
-
sel.value.clear();
|
|
57
|
-
const task = sel.value.getGeometry(props.pageIndex);
|
|
58
|
-
task.wait((geo) => {
|
|
59
|
-
const g = glyphAt(geo, point);
|
|
60
|
-
if (g !== -1) sel.value.begin(props.pageIndex, g);
|
|
61
|
-
}, ignore);
|
|
62
|
-
},
|
|
63
|
-
onPointerMove: (point, _evt, modeId) => {
|
|
64
|
-
if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;
|
|
65
|
-
const g = geoCache ? glyphAt(geoCache, point) : -1;
|
|
66
|
-
if (g !== -1) {
|
|
67
|
-
setCursor("selection-text", "text", 10);
|
|
68
|
-
sel.value.update(props.pageIndex, g);
|
|
69
|
-
} else {
|
|
70
|
-
removeCursor("selection-text");
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
onPointerUp: (_point, _evt, modeId) => {
|
|
74
|
-
if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;
|
|
75
|
-
sel.value.end();
|
|
76
|
-
},
|
|
77
|
-
onHandlerActiveEnd: (modeId) => {
|
|
78
|
-
if (!sel.value || !sel.value.isEnabledForMode(modeId)) return;
|
|
79
|
-
sel.value.clear();
|
|
20
|
+
let unregister;
|
|
21
|
+
onMounted(() => {
|
|
22
|
+
if (!sel.value) return;
|
|
23
|
+
unregister = sel.value.registerSelectionOnPage({
|
|
24
|
+
pageIndex: props.pageIndex,
|
|
25
|
+
onRectsChange: ({ rects: newRects, boundingRect: newBoundingRect }) => {
|
|
26
|
+
rects.value = newRects;
|
|
27
|
+
boundingRect.value = newBoundingRect;
|
|
80
28
|
}
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const cleanup = register(handlers.value);
|
|
86
|
-
if (cleanup) onCleanup(cleanup);
|
|
87
|
-
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
onUnmounted(() => {
|
|
32
|
+
unregister == null ? void 0 : unregister();
|
|
88
33
|
});
|
|
89
34
|
return (_ctx, _cache) => {
|
|
90
35
|
return boundingRect.value ? (openBlock(), createElementBlock("div", {
|
|
@@ -136,9 +81,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
136
81
|
};
|
|
137
82
|
}
|
|
138
83
|
});
|
|
84
|
+
const SelectionPluginPackage = createPluginPackage(SelectionPluginPackage$1).addUtility(_sfc_main).build();
|
|
139
85
|
export {
|
|
140
86
|
_sfc_main as CopyToClipboard,
|
|
141
87
|
_sfc_main$1 as SelectionLayer,
|
|
88
|
+
SelectionPluginPackage,
|
|
142
89
|
useSelectionCapability,
|
|
143
90
|
useSelectionPlugin
|
|
144
91
|
};
|
package/dist/vue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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.js","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":["_createElementBlock","_normalizeStyle","scale","_openBlock","_Fragment","_renderList","background","BaseSelectionPluginPackage","CopyToClipboard"],"mappings":";;;;;AAOO,MAAM,yBAAyB,MAAM,cAA+B,gBAAgB,EAAE;AAMtF,MAAM,qBAAqB,MAAM,UAA2B,gBAAgB,EAAE;;;;;;;;;AC2BrF,UAAM,QAAQ;AAId,UAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AAC3C,UAAA,QAAQ,IAAY,EAAE;AACtB,UAAA,eAAe,IAAiB,IAAI;AAEtC,QAAA;AAEJ,cAAU,MAAM;AACV,UAAA,CAAC,IAAI,MAAO;AAEH,mBAAA,IAAI,MAAM,wBAAwB;AAAA,QAC7C,WAAW,MAAM;AAAA,QACjB,eAAe,CAAC,EAAE,OAAO,UAAU,cAAc,sBAAsB;AACrE,gBAAM,QAAQ;AACd,uBAAa,QAAQ;AAAA,QAAA;AAAA,MACvB,CACD;AAAA,IAAA,CACF;AAED,gBAAY,MAAM;AACH;AAAA,IAAA,CACd;;aA9DS,aAAY,sBADpBA,mBAyBM,OAAA;AAAA;QAvBH,OAAKC,eAAA;AAAA;UAA+C,MAAA,GAAA,aAAA,MAAa,OAAO,IAAIC,KAAK,KAAA;AAAA,UAAoB,KAAA,GAAA,aAAA,MAAa,OAAO,IAAIA,KAAK,KAAA;AAAA,UAAsB,OAAA,GAAA,aAAA,MAAa,KAAK,QAAQA,KAAK,KAAA;AAAA,UAAuB,QAAA,GAAA,aAAA,MAAa,KAAK,SAASA,KAAK,KAAA;AAAA;;;;;SAW/OC,UAAA,IAAA,GAAAH,mBAWEI,UAVoB,MAAAC,WAAA,MAAA,OAAZ,CAAA,MAAM,MAAC;8BADjBL,mBAWE,OAAA;AAAA,YATC,KAAK;AAAA,YACL,OAAKC,eAAA;AAAA;wBAAoD,KAAK,OAAO,IAAI,aAAY,MAAC,OAAO,KAAKC,KAAK,KAAA;AAAA,uBAAuB,KAAK,OAAO,IAAI,aAAY,MAAC,OAAO,KAAKA,KAAK,KAAA;AAAA,cAAwB,OAAA,GAAA,KAAK,KAAK,QAAQA,KAAK,KAAA;AAAA,cAAyB,QAAA,GAAA,KAAK,KAAK,SAASA,KAAK,KAAA;AAAA,0BAA0BI,KAAU;AAAA;;;;;;;;;;ACbvT,UAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AAIjD,gBAAY,CAAC,cAAc;AACzB,UAAI,IAAI,OAAO;AACb,cAAM,cAAc,IAAI,MAAM,kBAAkB,CAAC,SAAS;AAExD,oBAAU,UAAU,UAAU,IAAI,EAAE,MAAM,CAAC,QAAQ;AACzC,oBAAA,MAAM,qCAAqC,GAAG;AAAA,UAAA,CACvD;AAAA,QAAA,CACF;AAGD,kBAAU,WAAW;AAAA,MAAA;AAAA,IACvB,CACD;;;;;;ACXM,MAAM,yBAAyB,oBAAoBC,wBAA0B,EACjF,WAAWC,SAAe,EAC1B,MAAM;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-selection",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,24 +28,24 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@embedpdf/models": "1.0.
|
|
31
|
+
"@embedpdf/models": "1.0.22"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/react": "^18.2.0",
|
|
35
35
|
"typescript": "^5.0.0",
|
|
36
|
-
"@embedpdf/core": "1.0.20",
|
|
37
36
|
"@embedpdf/build": "1.0.0",
|
|
38
|
-
"@embedpdf/
|
|
39
|
-
"@embedpdf/plugin-
|
|
37
|
+
"@embedpdf/core": "1.0.22",
|
|
38
|
+
"@embedpdf/plugin-viewport": "1.0.22",
|
|
39
|
+
"@embedpdf/plugin-interaction-manager": "1.0.22"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": ">=16.8.0",
|
|
43
43
|
"react-dom": ">=16.8.0",
|
|
44
44
|
"preact": "^10.26.4",
|
|
45
45
|
"vue": ">=3.2.0",
|
|
46
|
-
"@embedpdf/core": "1.0.
|
|
47
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
48
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
46
|
+
"@embedpdf/core": "1.0.22",
|
|
47
|
+
"@embedpdf/plugin-interaction-manager": "1.0.22",
|
|
48
|
+
"@embedpdf/plugin-viewport": "1.0.22"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"dist",
|