@embedpdf/plugin-selection 1.0.0 → 1.0.2
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/preact/index.cjs
CHANGED
|
@@ -21,8 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var preact_exports = {};
|
|
22
22
|
__export(preact_exports, {
|
|
23
23
|
SelectionLayer: () => SelectionLayer,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
useSelectionCapability: () => useSelectionCapability,
|
|
25
|
+
useSelectionPlugin: () => useSelectionPlugin
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(preact_exports);
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(preact_exports);
|
|
|
30
30
|
var import_preact = require("@embedpdf/core/preact");
|
|
31
31
|
var import_plugin_selection = require("@embedpdf/plugin-selection");
|
|
32
32
|
var useSelectionCapability = () => (0, import_preact.useCapability)(import_plugin_selection.SelectionPlugin.id);
|
|
33
|
-
var
|
|
33
|
+
var useSelectionPlugin = () => (0, import_preact.usePlugin)(import_plugin_selection.SelectionPlugin.id);
|
|
34
34
|
|
|
35
35
|
// src/preact/components/selection-layer.tsx
|
|
36
36
|
var import_hooks = require("preact/hooks");
|
|
@@ -107,7 +107,7 @@ function SelectionLayer({ pageIndex, scale }) {
|
|
|
107
107
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
108
|
0 && (module.exports = {
|
|
109
109
|
SelectionLayer,
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
useSelectionCapability,
|
|
111
|
+
useSelectionPlugin
|
|
112
112
|
});
|
|
113
113
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-selection.ts","../../src/preact/components/selection-layer.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-selection.ts","../../src/preact/components/selection-layer.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const useSelectionPlugin = () => usePlugin<SelectionPlugin>(SelectionPlugin.id);\n","/** @jsxImportSource preact */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';\nimport { useSelectionCapability } from '../hooks';\nimport { glyphAt } from '@embedpdf/plugin-selection';\nimport { PdfPageGeometry, Rect } from '@embedpdf/models';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\n\ntype Props = { pageIndex: number; scale: number };\n\nexport function SelectionLayer({ pageIndex, scale }: Props) {\n const { provides: sel } = useSelectionCapability();\n const { register } = usePointerHandlers({ modeId: 'default', pageIndex });\n const [rects, setRects] = useState<Array<Rect>>([]);\n const { setCursor, removeCursor } = useCursor();\n\n /* subscribe to rect updates */\n useEffect(() => {\n if (!sel) return;\n return sel.onSelectionChange(() => {\n setRects(sel.getHighlightRects(pageIndex));\n });\n }, [sel, pageIndex]);\n\n /* cheap glyphAt cache for the active page */\n let geoCache: PdfPageGeometry | undefined;\n const cachedGlyphAt = useCallback((pt: { x: number; y: number }) => {\n if (!geoCache) return -1;\n return glyphAt(geoCache, pt);\n }, []);\n\n // Initialize geometry cache\n useEffect(() => {\n if (!sel) return;\n sel.getGeometry(pageIndex).then((g) => (geoCache = g));\n }, [sel, pageIndex]);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (point) => {\n if (!sel) return;\n\n // clear the selection\n sel.clear();\n sel.getGeometry(pageIndex).then((geo) => {\n const g = glyphAt(geo, point);\n if (g !== -1) sel.begin(pageIndex, g);\n });\n },\n onPointerMove: (point) => {\n if (!sel) 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: () => {\n if (!sel) return;\n sel.end();\n },\n }),\n [sel, pageIndex, cachedGlyphAt],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return (\n <>\n {rects.map((b, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: b.origin.x * scale,\n top: b.origin.y * scale,\n width: b.size.width * scale,\n height: b.size.height * scale,\n background: 'rgba(33,150,243)',\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,8BAAgC;AAEzB,IAAM,yBAAyB,UAAM,6BAA+B,wCAAgB,EAAE;AACtF,IAAM,qBAAqB,UAAM,yBAA2B,wCAAgB,EAAE;;;ACHrF,mBAAkE;AAElE,IAAAA,2BAAwB;AAExB,IAAAC,iBAA8C;AAoE1C;AA/DG,SAAS,eAAe,EAAE,WAAW,MAAM,GAAU;AAC1D,QAAM,EAAE,UAAU,IAAI,IAAI,uBAAuB;AACjD,QAAM,EAAE,SAAS,QAAI,mCAAmB,EAAE,QAAQ,WAAW,UAAU,CAAC;AACxE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAsB,CAAC,CAAC;AAClD,QAAM,EAAE,WAAW,aAAa,QAAI,0BAAU;AAG9C,8BAAU,MAAM;AACd,QAAI,CAAC,IAAK;AACV,WAAO,IAAI,kBAAkB,MAAM;AACjC,eAAS,IAAI,kBAAkB,SAAS,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AAA,QACV,MAAM,EAAE,OAAO,IAAI;AAAA,QACnB,KAAK,EAAE,OAAO,IAAI;AAAA,QAClB,OAAO,EAAE,KAAK,QAAQ;AAAA,QACtB,QAAQ,EAAE,KAAK,SAAS;AAAA,QACxB,YAAY;AAAA,QACZ,eAAe;AAAA,MACjB;AAAA;AAAA,IATK;AAAA,EAUP,CACD,GACH;AAEJ;","names":["import_plugin_selection","import_preact"]}
|
package/dist/preact/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ declare const useSelectionCapability: () => {
|
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
ready: Promise<void>;
|
|
9
9
|
};
|
|
10
|
-
declare const
|
|
10
|
+
declare const useSelectionPlugin: () => {
|
|
11
11
|
plugin: SelectionPlugin | null;
|
|
12
12
|
isLoading: boolean;
|
|
13
13
|
ready: Promise<void>;
|
|
@@ -19,4 +19,4 @@ type Props = {
|
|
|
19
19
|
};
|
|
20
20
|
declare function SelectionLayer({ pageIndex, scale }: Props): preact.JSX.Element;
|
|
21
21
|
|
|
22
|
-
export { SelectionLayer,
|
|
22
|
+
export { SelectionLayer, useSelectionCapability, useSelectionPlugin };
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare const useSelectionCapability: () => {
|
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
ready: Promise<void>;
|
|
9
9
|
};
|
|
10
|
-
declare const
|
|
10
|
+
declare const useSelectionPlugin: () => {
|
|
11
11
|
plugin: SelectionPlugin | null;
|
|
12
12
|
isLoading: boolean;
|
|
13
13
|
ready: Promise<void>;
|
|
@@ -19,4 +19,4 @@ type Props = {
|
|
|
19
19
|
};
|
|
20
20
|
declare function SelectionLayer({ pageIndex, scale }: Props): preact.JSX.Element;
|
|
21
21
|
|
|
22
|
-
export { SelectionLayer,
|
|
22
|
+
export { SelectionLayer, useSelectionCapability, useSelectionPlugin };
|
package/dist/preact/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
3
|
import { SelectionPlugin } from "@embedpdf/plugin-selection";
|
|
4
4
|
var useSelectionCapability = () => useCapability(SelectionPlugin.id);
|
|
5
|
-
var
|
|
5
|
+
var useSelectionPlugin = () => usePlugin(SelectionPlugin.id);
|
|
6
6
|
|
|
7
7
|
// src/preact/components/selection-layer.tsx
|
|
8
8
|
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
|
|
@@ -78,7 +78,7 @@ function SelectionLayer({ pageIndex, scale }) {
|
|
|
78
78
|
}
|
|
79
79
|
export {
|
|
80
80
|
SelectionLayer,
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
useSelectionCapability,
|
|
82
|
+
useSelectionPlugin
|
|
83
83
|
};
|
|
84
84
|
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preact/hooks/use-selection.ts","../../src/preact/components/selection-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/preact/hooks/use-selection.ts","../../src/preact/components/selection-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SelectionPlugin } from '@embedpdf/plugin-selection';\n\nexport const useSelectionCapability = () => useCapability<SelectionPlugin>(SelectionPlugin.id);\nexport const useSelectionPlugin = () => usePlugin<SelectionPlugin>(SelectionPlugin.id);\n","/** @jsxImportSource preact */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';\nimport { useSelectionCapability } from '../hooks';\nimport { glyphAt } from '@embedpdf/plugin-selection';\nimport { PdfPageGeometry, Rect } from '@embedpdf/models';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\n\ntype Props = { pageIndex: number; scale: number };\n\nexport function SelectionLayer({ pageIndex, scale }: Props) {\n const { provides: sel } = useSelectionCapability();\n const { register } = usePointerHandlers({ modeId: 'default', pageIndex });\n const [rects, setRects] = useState<Array<Rect>>([]);\n const { setCursor, removeCursor } = useCursor();\n\n /* subscribe to rect updates */\n useEffect(() => {\n if (!sel) return;\n return sel.onSelectionChange(() => {\n setRects(sel.getHighlightRects(pageIndex));\n });\n }, [sel, pageIndex]);\n\n /* cheap glyphAt cache for the active page */\n let geoCache: PdfPageGeometry | undefined;\n const cachedGlyphAt = useCallback((pt: { x: number; y: number }) => {\n if (!geoCache) return -1;\n return glyphAt(geoCache, pt);\n }, []);\n\n // Initialize geometry cache\n useEffect(() => {\n if (!sel) return;\n sel.getGeometry(pageIndex).then((g) => (geoCache = g));\n }, [sel, pageIndex]);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (point) => {\n if (!sel) return;\n\n // clear the selection\n sel.clear();\n sel.getGeometry(pageIndex).then((geo) => {\n const g = glyphAt(geo, point);\n if (g !== -1) sel.begin(pageIndex, g);\n });\n },\n onPointerMove: (point) => {\n if (!sel) 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: () => {\n if (!sel) return;\n sel.end();\n },\n }),\n [sel, pageIndex, cachedGlyphAt],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return (\n <>\n {rects.map((b, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: b.origin.x * scale,\n top: b.origin.y * scale,\n width: b.size.width * scale,\n height: b.size.height * scale,\n background: 'rgba(33,150,243)',\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACz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e,CAAC,UAAU;AACxB,YAAI,CAAC,IAAK;AACV,cAAM,IAAI,cAAc,KAAK;AAC7B,YAAI,MAAM,IAAI;AACZ,oBAAU,kBAAkB,QAAQ,EAAE;AAAA,QACxC,OAAO;AACL,uBAAa,gBAAgB;AAAA,QAC/B;AACA,YAAI,MAAM,GAAI,KAAI,OAAO,WAAW,CAAC;AAAA,MACvC;AAAA,MACA,aAAa,MAAM;AACjB,YAAI,CAAC,IAAK;AACV,YAAI,IAAI;AAAA,MACV;AAAA,IACF;AAAA,IACA,CAAC,KAAK,WAAW,aAAa;AAAA,EAChC;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,WAAO,SAAS,QAAQ;AAAA,EAC1B,GAAG,CAAC,UAAU,QAAQ,CAAC;AAEvB,SACE,gCACG,gBAAM,IAAI,CAAC,GAAG,MACb;AAAA,IAAC;AAAA;AAAA,MAEC,OAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,EAAE,OAAO,IAAI;AAAA,QACnB,KAAK,EAAE,OAAO,IAAI;AAAA,QAClB,OAAO,EAAE,KAAK,QAAQ;AAAA,QACtB,QAAQ,EAAE,KAAK,SAAS;AAAA,QACxB,YAAY;AAAA,QACZ,eAAe;AAAA,MACjB;AAAA;AAAA,IATK;AAAA,EAUP,CACD,GACH;AAEJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-selection",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@embedpdf/models": "1.0.
|
|
21
|
+
"@embedpdf/models": "1.0.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/react": "^18.2.0",
|
|
25
25
|
"tsup": "^8.0.0",
|
|
26
26
|
"typescript": "^5.0.0",
|
|
27
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
28
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
27
|
+
"@embedpdf/plugin-viewport": "1.0.2",
|
|
28
|
+
"@embedpdf/plugin-interaction-manager": "1.0.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": ">=16.8.0",
|
|
32
32
|
"react-dom": ">=16.8.0",
|
|
33
33
|
"preact": "^10.26.4",
|
|
34
|
-
"@embedpdf/core": "1.0.
|
|
35
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
36
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
34
|
+
"@embedpdf/core": "1.0.2",
|
|
35
|
+
"@embedpdf/plugin-viewport": "1.0.2",
|
|
36
|
+
"@embedpdf/plugin-interaction-manager": "1.0.2"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist",
|