@embedpdf/plugin-tiling 1.0.11 → 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 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -86
- package/dist/index.js +21 -35
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +18 -0
- package/dist/lib/index.d.ts +8 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/tiling-plugin.d.ts +17 -0
- package/dist/lib/types.d.ts +46 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -128
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -23
- package/dist/preact/index.js +11 -19
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -128
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -23
- package/dist/react/index.js +10 -19
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/tile-img.d.ts +9 -0
- package/dist/shared-preact/components/tiling-layer.d.ts +8 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-tiling.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/tile-img.d.ts +9 -0
- package/dist/shared-react/components/tiling-layer.d.ts +8 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-tiling.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/tile-img.vue.d.ts +13 -0
- package/dist/vue/components/tiling-layer.vue.d.ts +8 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-tiling.d.ts +5 -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 +118 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +25 -14
- package/dist/index.d.cts +0 -86
- package/dist/preact/index.d.cts +0 -23
- package/dist/react/index.d.cts +0 -23
package/dist/react/index.cjs
CHANGED
|
@@ -1,128 +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
|
-
TilingLayer: () => TilingLayer,
|
|
24
|
-
useTilingCapability: () => useTilingCapability,
|
|
25
|
-
useTilingPlugin: () => useTilingPlugin
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(react_exports);
|
|
28
|
-
|
|
29
|
-
// src/react/hooks/use-tiling.ts
|
|
30
|
-
var import_react = require("@embedpdf/core/react");
|
|
31
|
-
var import_plugin_tiling = require("@embedpdf/plugin-tiling");
|
|
32
|
-
var useTilingPlugin = () => (0, import_react.usePlugin)(import_plugin_tiling.TilingPlugin.id);
|
|
33
|
-
var useTilingCapability = () => (0, import_react.useCapability)(import_plugin_tiling.TilingPlugin.id);
|
|
34
|
-
|
|
35
|
-
// src/react/components/tiling-layer.tsx
|
|
36
|
-
var import_react3 = require("react");
|
|
37
|
-
|
|
38
|
-
// src/react/components/tile-img.tsx
|
|
39
|
-
var import_models = require("@embedpdf/models");
|
|
40
|
-
var import_react2 = require("react");
|
|
41
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
-
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
43
|
-
const { provides: tilingCapability } = useTilingCapability();
|
|
44
|
-
const [url, setUrl] = (0, import_react2.useState)();
|
|
45
|
-
const urlRef = (0, import_react2.useRef)(null);
|
|
46
|
-
const relativeScale = scale / tile.srcScale;
|
|
47
|
-
(0, import_react2.useEffect)(() => {
|
|
48
|
-
if (tile.status === "ready" && urlRef.current) return;
|
|
49
|
-
if (!tilingCapability) return;
|
|
50
|
-
const task = tilingCapability.renderTile({ pageIndex, tile, dpr });
|
|
51
|
-
task.wait((blob) => {
|
|
52
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
53
|
-
urlRef.current = objectUrl;
|
|
54
|
-
setUrl(objectUrl);
|
|
55
|
-
}, import_models.ignore);
|
|
56
|
-
return () => {
|
|
57
|
-
if (urlRef.current) {
|
|
58
|
-
URL.revokeObjectURL(urlRef.current);
|
|
59
|
-
urlRef.current = null;
|
|
60
|
-
} else {
|
|
61
|
-
task.abort({
|
|
62
|
-
code: import_models.PdfErrorCode.Cancelled,
|
|
63
|
-
message: "canceled render task"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}, [pageIndex, tile.id]);
|
|
68
|
-
const handleImageLoad = () => {
|
|
69
|
-
if (urlRef.current) {
|
|
70
|
-
URL.revokeObjectURL(urlRef.current);
|
|
71
|
-
urlRef.current = null;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
if (!url) return null;
|
|
75
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
-
"img",
|
|
77
|
-
{
|
|
78
|
-
src: url,
|
|
79
|
-
onLoad: handleImageLoad,
|
|
80
|
-
style: {
|
|
81
|
-
position: "absolute",
|
|
82
|
-
left: tile.screenRect.origin.x * relativeScale,
|
|
83
|
-
top: tile.screenRect.origin.y * relativeScale,
|
|
84
|
-
width: tile.screenRect.size.width * relativeScale,
|
|
85
|
-
height: tile.screenRect.size.height * relativeScale,
|
|
86
|
-
display: "block"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/react/components/tiling-layer.tsx
|
|
93
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
94
|
-
function TilingLayer({ pageIndex, scale, style, ...props }) {
|
|
95
|
-
const { provides: tilingProvides } = useTilingCapability();
|
|
96
|
-
const [tiles, setTiles] = (0, import_react3.useState)([]);
|
|
97
|
-
(0, import_react3.useEffect)(() => {
|
|
98
|
-
if (tilingProvides) {
|
|
99
|
-
return tilingProvides.onTileRendering((tiles2) => setTiles(tiles2[pageIndex]));
|
|
100
|
-
}
|
|
101
|
-
}, [tilingProvides]);
|
|
102
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
103
|
-
"div",
|
|
104
|
-
{
|
|
105
|
-
style: {
|
|
106
|
-
...style
|
|
107
|
-
},
|
|
108
|
-
...props,
|
|
109
|
-
children: tiles?.map((tile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
110
|
-
TileImg,
|
|
111
|
-
{
|
|
112
|
-
pageIndex,
|
|
113
|
-
tile,
|
|
114
|
-
dpr: window.devicePixelRatio,
|
|
115
|
-
scale
|
|
116
|
-
},
|
|
117
|
-
tile.id
|
|
118
|
-
))
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
-
0 && (module.exports = {
|
|
124
|
-
TilingLayer,
|
|
125
|
-
useTilingCapability,
|
|
126
|
-
useTilingPlugin
|
|
127
|
-
});
|
|
128
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-tiling"),t=require("react/jsx-runtime"),i=require("react"),n=require("@embedpdf/models"),s=()=>e.useCapability(r.TilingPlugin.id);function c({pageIndex:e,tile:r,dpr:c,scale:l}){const{provides:u}=s(),[d,o]=i.useState(),a=i.useRef(null),g=l/r.srcScale;i.useEffect((()=>{if("ready"===r.status&&a.current)return;if(!u)return;const t=u.renderTile({pageIndex:e,tile:r,dpr:c});return t.wait((e=>{const r=URL.createObjectURL(e);a.current=r,o(r)}),n.ignore),()=>{a.current?(URL.revokeObjectURL(a.current),a.current=null):t.abort({code:n.PdfErrorCode.Cancelled,message:"canceled render task"})}}),[e,r.id]);return d?t.jsx("img",{src:d,onLoad:()=>{a.current&&(URL.revokeObjectURL(a.current),a.current=null)},style:{position:"absolute",left:r.screenRect.origin.x*g,top:r.screenRect.origin.y*g,width:r.screenRect.size.width*g,height:r.screenRect.size.height*g,display:"block"}}):null}exports.TilingLayer=function({pageIndex:e,scale:r,style:n,...l}){const{provides:u}=s(),[d,o]=i.useState([]);return i.useEffect((()=>{if(u)return u.onTileRendering((r=>o(r[e])))}),[u]),t.jsx("div",{style:{...n},...l,children:null==d?void 0:d.map((i=>t.jsx(c,{pageIndex:e,tile:i,dpr:window.devicePixelRatio,scale:r},i.id)))})},exports.useTilingCapability=s,exports.useTilingPlugin=()=>e.usePlugin(r.TilingPlugin.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-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["useTilingCapability","useCapability","TilingPlugin","id","TileImg","pageIndex","tile","dpr","scale","provides","tilingCapability","url","setUrl","useState","urlRef","useRef","relativeScale","srcScale","useEffect","status","current","task","renderTile","wait","blob","objectUrl","URL","createObjectURL","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","jsxRuntime","jsx","src","onLoad","style","position","left","screenRect","origin","x","top","y","width","size","height","display","props","tilingProvides","tiles","setTiles","onTileRendering","children","map","window","devicePixelRatio","usePlugin"],"mappings":"6OAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,ICS3E,SAASC,GAAQC,UAAEA,EAAAC,KAAWA,EAAMC,IAAAA,EAAAC,MAAKA,IAC9C,MAAQC,SAAUC,GAAqBV,KAChCW,EAAKC,GAAUC,aAChBC,EAASC,SAAsB,MAE/BC,EAAgBR,EAAQF,EAAKW,SAGnCC,EAAAA,WAAU,KACR,GAAoB,UAAhBZ,EAAKa,QAAsBL,EAAOM,QAAS,OAC/C,IAAKV,EAAkB,OACvB,MAAMW,EAAOX,EAAiBY,WAAW,CAAEjB,YAAWC,OAAMC,QAO5D,OANKc,EAAAE,MAAMC,IACH,MAAAC,EAAYC,IAAIC,gBAAgBH,GACtCV,EAAOM,QAAUK,EACjBb,EAAOa,EAAS,GACfG,UAEI,KACDd,EAAOM,SACLM,IAAAG,gBAAgBf,EAAOM,SAC3BN,EAAOM,QAAU,MAEjBC,EAAKS,MAAM,CACTC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,wBACV,CAEL,GACC,CAAC7B,EAAWC,EAAKH,KAShB,OAACQ,EAEHwB,EAAAC,IAAC,MAAA,CACCC,IAAK1B,EACL2B,OAXoB,KAClBxB,EAAOM,UACLM,IAAAG,gBAAgBf,EAAOM,SAC3BN,EAAOM,QAAU,KAAA,EASjBmB,MAAO,CACLC,SAAU,WACVC,KAAMnC,EAAKoC,WAAWC,OAAOC,EAAI5B,EACjC6B,IAAKvC,EAAKoC,WAAWC,OAAOG,EAAI9B,EAChC+B,MAAOzC,EAAKoC,WAAWM,KAAKD,MAAQ/B,EACpCiC,OAAQ3C,EAAKoC,WAAWM,KAAKC,OAASjC,EACtCkC,QAAS,WAXE,IAenB,qBCtDO,UAAqB7C,UAAEA,EAAAG,MAAWA,QAAO+B,KAAUY,IACxD,MAAQ1C,SAAU2C,GAAmBpD,KAC9BqD,EAAOC,GAAYzC,EAAAA,SAAiB,IASzC,OAPFK,EAAAA,WAAU,KACR,GAAIkC,EACK,OAAAA,EAAeG,iBAAiBF,GAAUC,EAASD,EAAMhD,KAAW,GAE5E,CAAC+C,IAGFjB,EAAAC,IAAC,MAAA,CACCG,MAAO,IACFA,MAEDY,EAEHK,SAAA,MAAAH,OAAA,EAAAA,EAAOI,KAAKnD,GACX6B,EAAAC,IAAChC,EAAA,CAECC,YACAC,OACAC,IAAKmD,OAAOC,iBACZnD,SAJKF,EAAKH,OASpB,wDFrC+B,IAAMyD,YAAwB1D,EAAAA,aAAaC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { TilingPlugin } from '@embedpdf/plugin-tiling';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
declare const useTilingPlugin: () => {
|
|
6
|
-
plugin: TilingPlugin | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
ready: Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
declare const useTilingCapability: () => {
|
|
11
|
-
provides: Readonly<_embedpdf_plugin_tiling.TilingCapability> | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type TilingLayoutProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'style'> & {
|
|
17
|
-
pageIndex: number;
|
|
18
|
-
scale: number;
|
|
19
|
-
style?: React.CSSProperties;
|
|
20
|
-
};
|
|
21
|
-
declare function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps): react_jsx_runtime.JSX.Element;
|
|
22
|
-
|
|
23
|
-
export { TilingLayer, useTilingCapability, useTilingPlugin };
|
|
1
|
+
export * from '../shared-react';
|
package/dist/react/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
1
|
+
import { usePlugin, useCapability } from "@embedpdf/core/react";
|
|
3
2
|
import { TilingPlugin } from "@embedpdf/plugin-tiling";
|
|
4
|
-
var useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
5
|
-
var useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
6
|
-
|
|
7
|
-
// src/react/components/tiling-layer.tsx
|
|
8
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
9
|
-
|
|
10
|
-
// src/react/components/tile-img.tsx
|
|
11
|
-
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
12
|
-
import { useEffect, useRef, useState } from "react";
|
|
13
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useState, useRef, useEffect } from "react";
|
|
5
|
+
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
6
|
+
const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
7
|
+
const useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
14
8
|
function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
15
9
|
const { provides: tilingCapability } = useTilingCapability();
|
|
16
10
|
const [url, setUrl] = useState();
|
|
@@ -60,25 +54,22 @@ function TileImg({ pageIndex, tile, dpr, scale }) {
|
|
|
60
54
|
}
|
|
61
55
|
);
|
|
62
56
|
}
|
|
63
|
-
|
|
64
|
-
// src/react/components/tiling-layer.tsx
|
|
65
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
66
57
|
function TilingLayer({ pageIndex, scale, style, ...props }) {
|
|
67
58
|
const { provides: tilingProvides } = useTilingCapability();
|
|
68
|
-
const [tiles, setTiles] =
|
|
69
|
-
|
|
59
|
+
const [tiles, setTiles] = useState([]);
|
|
60
|
+
useEffect(() => {
|
|
70
61
|
if (tilingProvides) {
|
|
71
62
|
return tilingProvides.onTileRendering((tiles2) => setTiles(tiles2[pageIndex]));
|
|
72
63
|
}
|
|
73
64
|
}, [tilingProvides]);
|
|
74
|
-
return /* @__PURE__ */
|
|
65
|
+
return /* @__PURE__ */ jsx(
|
|
75
66
|
"div",
|
|
76
67
|
{
|
|
77
68
|
style: {
|
|
78
69
|
...style
|
|
79
70
|
},
|
|
80
71
|
...props,
|
|
81
|
-
children: tiles
|
|
72
|
+
children: tiles == null ? void 0 : tiles.map((tile) => /* @__PURE__ */ jsx(
|
|
82
73
|
TileImg,
|
|
83
74
|
{
|
|
84
75
|
pageIndex,
|
|
@@ -96,4 +87,4 @@ export {
|
|
|
96
87
|
useTilingCapability,
|
|
97
88
|
useTilingPlugin
|
|
98
89
|
};
|
|
99
|
-
//# sourceMappingURL=index.js.map
|
|
90
|
+
//# 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-tiling.ts","../../src/shared/components/tile-img.tsx","../../src/shared/components/tiling-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","import { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useRef, useState } from '@framework';\n\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ninterface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n}\n\nexport function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps) {\n const { provides: tilingCapability } = useTilingCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n const relativeScale = scale / tile.srcScale;\n\n /* kick off render exactly once per tile */\n useEffect(() => {\n if (tile.status === 'ready' && urlRef.current) return; // already done\n if (!tilingCapability) return;\n const task = tilingCapability.renderTile({ pageIndex, tile, dpr });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n }, [pageIndex, tile.id]); // id includes scale, so unique\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n if (!url) return null; // could render a placeholder\n return (\n <img\n src={url}\n onLoad={handleImageLoad}\n style={{\n position: 'absolute',\n left: tile.screenRect.origin.x * relativeScale,\n top: tile.screenRect.origin.y * relativeScale,\n width: tile.screenRect.size.width * relativeScale,\n height: tile.screenRect.size.height * relativeScale,\n display: 'block',\n }}\n />\n );\n}\n","import { Tile } from '@embedpdf/plugin-tiling';\nimport { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\n\nimport { TileImg } from './tile-img';\nimport { useTilingCapability } from '../hooks/use-tiling';\n\ntype TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: CSSProperties;\n};\n\nexport function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps) {\n const { provides: tilingProvides } = useTilingCapability();\n const [tiles, setTiles] = useState<Tile[]>([]);\n\n useEffect(() => {\n if (tilingProvides) {\n return tilingProvides.onTileRendering((tiles) => setTiles(tiles[pageIndex]));\n }\n }, [tilingProvides]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {tiles?.map((tile) => (\n <TileImg\n key={tile.id}\n pageIndex={pageIndex}\n tile={tile}\n dpr={window.devicePixelRatio}\n scale={scale}\n />\n ))}\n </div>\n );\n}\n"],"names":["tiles"],"mappings":";;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACS7E,SAAS,QAAQ,EAAE,WAAW,MAAM,KAAK,SAAuB;AACrE,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,CAAC,KAAK,MAAM,IAAI,SAAiB;AACjC,QAAA,SAAS,OAAsB,IAAI;AAEnC,QAAA,gBAAgB,QAAQ,KAAK;AAGnC,YAAU,MAAM;AACd,QAAI,KAAK,WAAW,WAAW,OAAO,QAAS;AAC/C,QAAI,CAAC,iBAAkB;AACvB,UAAM,OAAO,iBAAiB,WAAW,EAAE,WAAW,MAAM,KAAK;AAC5D,SAAA,KAAK,CAAC,SAAS;AACZ,YAAA,YAAY,IAAI,gBAAgB,IAAI;AAC1C,aAAO,UAAU;AACjB,aAAO,SAAS;AAAA,OACf,MAAM;AAET,WAAO,MAAM;AACX,UAAI,OAAO,SAAS;AACd,YAAA,gBAAgB,OAAO,OAAO;AAClC,eAAO,UAAU;AAAA,MAAA,OACZ;AACL,aAAK,MAAM;AAAA,UACT,MAAM,aAAa;AAAA,UACnB,SAAS;AAAA,QAAA,CACV;AAAA,MAAA;AAAA,IAEL;AAAA,EACC,GAAA,CAAC,WAAW,KAAK,EAAE,CAAC;AAEvB,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AACd,UAAA,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IAAA;AAAA,EAErB;AAEI,MAAA,CAAC,IAAY,QAAA;AAEf,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,KAAK,WAAW,OAAO,IAAI;AAAA,QACjC,KAAK,KAAK,WAAW,OAAO,IAAI;AAAA,QAChC,OAAO,KAAK,WAAW,KAAK,QAAQ;AAAA,QACpC,QAAQ,KAAK,WAAW,KAAK,SAAS;AAAA,QACtC,SAAS;AAAA,MAAA;AAAA,IACX;AAAA,EACF;AAEJ;ACtDO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO,GAAG,SAA4B;AACpF,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAiB,CAAA,CAAE;AAE7C,YAAU,MAAM;AACd,QAAI,gBAAgB;AACX,aAAA,eAAe,gBAAgB,CAACA,WAAU,SAASA,OAAM,SAAS,CAAC,CAAC;AAAA,IAAA;AAAA,EAC7E,GACC,CAAC,cAAc,CAAC;AAGjB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA,+BAAO,IAAI,CAAC,SACX;AAAA,QAAC;AAAA,QAAA;AAAA,UAEC;AAAA,UACA;AAAA,UACA,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAAA,QAJK,KAAK;AAAA,MAMb;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tiling-layer';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Tile } from '../../lib/index.ts';
|
|
2
|
+
interface TileImgProps {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
tile: Tile;
|
|
5
|
+
dpr: number;
|
|
6
|
+
scale: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps): import("preact").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HTMLAttributes, CSSProperties } from '../../preact/adapter.ts';
|
|
2
|
+
type TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
};
|
|
7
|
+
export declare function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps): import("preact").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-tiling';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TilingPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useTilingPlugin: () => {
|
|
3
|
+
plugin: TilingPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useTilingCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').TilingCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tiling-layer';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Tile } from '../../lib/index.ts';
|
|
2
|
+
interface TileImgProps {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
tile: Tile;
|
|
5
|
+
dpr: number;
|
|
6
|
+
scale: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function TileImg({ pageIndex, tile, dpr, scale }: TileImgProps): import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
|
|
2
|
+
type TilingLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
};
|
|
7
|
+
export declare function TilingLayer({ pageIndex, scale, style, ...props }: TilingLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-tiling';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TilingPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useTilingPlugin: () => {
|
|
3
|
+
plugin: TilingPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useTilingCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').TilingCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StyleValue } from 'vue';
|
|
2
|
+
import { Tile } from '../../lib/index.ts';
|
|
3
|
+
interface Props {
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
tile: Tile;
|
|
6
|
+
scale: number;
|
|
7
|
+
dpr?: number;
|
|
8
|
+
style?: StyleValue;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
11
|
+
dpr: number;
|
|
12
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StyleValue } from 'vue';
|
|
2
|
+
interface Props {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
style?: StyleValue;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-tiling';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TilingPlugin } from '../../lib/index.ts';
|
|
2
|
+
/** Get the plugin instance itself (e.g. to read config) */
|
|
3
|
+
export declare const useTilingPlugin: () => import('@embedpdf/core/vue').PluginState<TilingPlugin>;
|
|
4
|
+
/** Get the *capability* the plugin exposes (renderTile, onTileRendering) */
|
|
5
|
+
export declare const useTilingCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').TilingCapability>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),l=require("@embedpdf/models"),n=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-tiling"),i=()=>n.useCapability(t.TilingPlugin.id),r=["src"],o=e.defineComponent({__name:"tile-img",props:{pageIndex:{},tile:{},scale:{},dpr:{default:()=>window.devicePixelRatio},style:{type:[Boolean,null,String,Object,Array]}},setup(n){const t=n,{provides:o}=i(),a=e.ref();let s=null,c=null;function u(){s&&(URL.revokeObjectURL(s),s=null)}e.onMounted((()=>{if(!o.value)return;const n=o.value.renderTile({pageIndex:t.pageIndex,tile:e.toRaw(t.tile),dpr:t.dpr});c=n,n.wait((e=>{s=URL.createObjectURL(e),a.value=s,c=null}),l.ignore)})),e.onBeforeUnmount((()=>{c&&!s&&c.abort({code:l.PdfErrorCode.Cancelled,message:"canceled tile render"}),u()}));const d=t.scale/t.tile.srcScale;return(l,n)=>a.value?(e.openBlock(),e.createElementBlock("img",{key:0,src:a.value,style:e.normalizeStyle([{position:"absolute",left:l.tile.screenRect.origin.x*d+"px",top:l.tile.screenRect.origin.y*d+"px",width:l.tile.screenRect.size.width*d+"px",height:l.tile.screenRect.size.height*d+"px",display:"block"},t.style]),onLoad:u},null,44,r)):e.createCommentVNode("",!0)}}),a=e.defineComponent({__name:"tiling-layer",props:{pageIndex:{},scale:{},style:{type:[Boolean,null,String,Object,Array]}},setup(l){const n=l,t=e.ref([]),{provides:r}=i();let a;return e.onMounted((()=>{r.value&&(a=r.value.onTileRendering((e=>{t.value=e[n.pageIndex]??[]})))})),e.onBeforeUnmount((()=>{null==a||a()})),(l,n)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({style:l.style},l.$attrs),[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,(n=>(e.openBlock(),e.createBlock(o,{key:n.id,pageIndex:l.pageIndex,tile:n,scale:l.scale},null,8,["pageIndex","tile","scale"])))),128))],16))}});exports.TileImg=o,exports.TilingLayer=a,exports.useTilingCapability=i,exports.useTilingPlugin=()=>n.usePlugin(t.TilingPlugin.id);
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-tiling.ts","../../src/vue/components/tile-img.vue","../../src/vue/components/tiling-layer.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\n/** Get the plugin instance itself (e.g. to read config) */\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\n/** Get the *capability* the plugin exposes (renderTile, onTileRendering) */\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode, PdfErrorReason, Task } from '@embedpdf/models';\nimport type { StyleValue } from 'vue';\n\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { useTilingCapability } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n tile: Tile;\n scale: number;\n dpr?: number;\n style?: StyleValue;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => window.devicePixelRatio,\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\n\nconst url = ref<string>();\nlet blobUrl: string | null = null;\nlet renderTask: Task<Blob, PdfErrorReason> | null = null;\n\n/* -------------------------------------------------- */\n/* Helper functions */\n/* -------------------------------------------------- */\nfunction revoke() {\n if (blobUrl) {\n URL.revokeObjectURL(blobUrl);\n blobUrl = null;\n }\n}\n\nfunction abortCurrentTask() {\n if (renderTask && !blobUrl) {\n renderTask.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled tile render',\n });\n }\n}\n\n/* -------------------------------------------------- */\n/* start one render task when component mounts */\n/* -------------------------------------------------- */\nonMounted(() => {\n if (!tilingCapability.value) return;\n\n const task = tilingCapability.value.renderTile({\n pageIndex: props.pageIndex,\n tile: toRaw(props.tile),\n dpr: props.dpr,\n });\n\n renderTask = task;\n task.wait((blob) => {\n blobUrl = URL.createObjectURL(blob);\n url.value = blobUrl;\n renderTask = null; // Task completed\n }, ignore);\n});\n\n/* -------------------------------------------------- */\n/* cleanup */\n/* -------------------------------------------------- */\nonBeforeUnmount(() => {\n abortCurrentTask();\n revoke();\n});\n\n/* -------------------------------------------------- */\n/* helpers */\n/* -------------------------------------------------- */\nconst relScale = props.scale / props.tile.srcScale;\n</script>\n\n<template>\n <img\n v-if=\"url\"\n :src=\"url\"\n :style=\"[\n {\n position: 'absolute',\n left: tile.screenRect.origin.x * relScale + 'px',\n top: tile.screenRect.origin.y * relScale + 'px',\n width: tile.screenRect.size.width * relScale + 'px',\n height: tile.screenRect.size.height * relScale + 'px',\n display: 'block',\n },\n props.style,\n ]\"\n @load=\"revoke\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { ref, onMounted, onBeforeUnmount } from 'vue';\nimport type { StyleValue } from 'vue';\n\nimport { useTilingCapability } from '../hooks';\nimport TileImg from './tile-img.vue';\n\ninterface Props {\n pageIndex: number;\n scale: number;\n style?: StyleValue;\n}\n\nconst props = defineProps<Props>();\n\nconst tiles = ref<Tile[]>([]);\nconst { provides: tilingProvides } = useTilingCapability();\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (tilingProvides.value) {\n unsubscribe = tilingProvides.value.onTileRendering((tilesMap) => {\n tiles.value = tilesMap[props.pageIndex] ?? [];\n });\n }\n});\n\nonBeforeUnmount(() => {\n unsubscribe?.();\n});\n</script>\n\n<template>\n <div :style=\"style\" v-bind=\"$attrs\">\n <TileImg\n v-for=\"tile in tiles\"\n :key=\"tile.id\"\n :pageIndex=\"pageIndex\"\n :tile=\"tile\"\n :scale=\"scale\"\n />\n </div>\n</template>\n"],"names":["useTilingCapability","useCapability","TilingPlugin","id","props","__props","provides","tilingCapability","url","ref","blobUrl","renderTask","revoke","URL","revokeObjectURL","onMounted","value","task","renderTile","pageIndex","tile","toRaw","dpr","wait","blob","createObjectURL","ignore","onBeforeUnmount","abort","code","PdfErrorCode","Cancelled","message","relScale","scale","srcScale","_createElementBlock","src","style","_normalizeStyle","screenRect","origin","x","y","size","width","height","onLoad","tiles","tilingProvides","unsubscribe","onTileRendering","tilesMap","_openBlock","_mergeProps","$attrs","_Fragment","Fragment","_renderList","_createBlock","createBlock","TileImg","key","usePlugin"],"mappings":"0MAMaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,8LCUlF,MAAMC,EAAQC,GAINC,SAAUC,GAAqBP,IAEjCQ,EAAMC,EAAAA,MACZ,IAAIC,EAAyB,KACzBC,EAAgD,KAKpD,SAASC,IACHF,IACFG,IAAIC,gBAAgBJ,GACVA,EAAA,KACZ,CAeFK,EAAAA,WAAU,KACJ,IAACR,EAAiBS,MAAO,OAEvB,MAAAC,EAAOV,EAAiBS,MAAME,WAAW,CAC7CC,UAAWf,EAAMe,UACjBC,KAAMC,EAAAA,MAAMjB,EAAMgB,MAClBE,IAAKlB,EAAMkB,MAGAX,EAAAM,EACRA,EAAAM,MAAMC,IACCd,EAAAG,IAAIY,gBAAgBD,GAC9BhB,EAAIQ,MAAQN,EACCC,EAAA,IAAA,GACZe,SAAM,IAMXC,EAAAA,iBAAgB,KA/BVhB,IAAeD,GACjBC,EAAWiB,MAAM,CACfC,KAAMC,EAAaA,aAAAC,UACnBC,QAAS,yBA8BNpB,GAAA,IAMT,MAAMqB,EAAW7B,EAAM8B,MAAQ9B,EAAMgB,KAAKe,sBAKhC3B,EAAGQ,qBADXoB,EAAAA,mBAeE,MAAA,OAbCC,IAAK7B,EAAGQ,MACRsB,MAAKC,EAAAA,eAAA,sBAAwDnB,KAAAA,EAAAA,KAAKoB,WAAWC,OAAOC,EAAIT,EAAQ,KAAsBb,IAAAA,EAAAA,KAAKoB,WAAWC,OAAOE,EAAIV,EAAQ,KAAwBb,MAAAA,EAAAA,KAAKoB,WAAWI,KAAKC,MAAQZ,EAAQ,KAAyBb,OAAAA,EAAAA,KAAKoB,WAAWI,KAAKE,OAASb,EAAQ,sBAAkD7B,EAAMkC,QAW7US,OAAMnC,gLChFX,MAAMR,EAAQC,EAER2C,EAAQvC,EAAYA,IAAA,KAClBH,SAAU2C,GAAmBjD,IAEjC,IAAAkD,SAEJnC,EAAAA,WAAU,KACJkC,EAAejC,QACjBkC,EAAcD,EAAejC,MAAMmC,iBAAiBC,IAClDJ,EAAMhC,MAAQoC,EAAShD,EAAMe,YAAc,EAAC,IAC7C,IAILQ,EAAAA,iBAAgB,KACA,MAAAuB,GAAAA,GAAA,YAKdG,cAAAjB,qBAQM,MARNkB,EAAAA,WAQM,CARAhB,MAAOA,EAAAA,OAAeiB,EAAMA,QAAA,kBAChCnB,EAAAA,mBAMEoB,EAAAC,SAAA,KAAAC,EAAAA,WALeV,EAAKhC,OAAbI,kBADTuC,EAAAC,YAMEC,EAAA,CAJCC,IAAK1C,EAAKjB,GACVgB,UAAWA,EAASA,UACpBC,OACAc,MAAOA,EAAKA,4JFrCY,IAAM6B,YAAwB7D,EAAAA,aAAaC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { defineComponent, ref, onMounted, toRaw, onBeforeUnmount, createElementBlock, createCommentVNode, openBlock, normalizeStyle, mergeProps, Fragment, renderList, createBlock } from "vue";
|
|
2
|
+
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
3
|
+
import { useCapability, usePlugin } from "@embedpdf/core/vue";
|
|
4
|
+
import { TilingPlugin } from "@embedpdf/plugin-tiling";
|
|
5
|
+
const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
6
|
+
const useTilingCapability = () => useCapability(TilingPlugin.id);
|
|
7
|
+
const _hoisted_1 = ["src"];
|
|
8
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
9
|
+
__name: "tile-img",
|
|
10
|
+
props: {
|
|
11
|
+
pageIndex: {},
|
|
12
|
+
tile: {},
|
|
13
|
+
scale: {},
|
|
14
|
+
dpr: { default: () => window.devicePixelRatio },
|
|
15
|
+
style: { type: [Boolean, null, String, Object, Array] }
|
|
16
|
+
},
|
|
17
|
+
setup(__props) {
|
|
18
|
+
const props = __props;
|
|
19
|
+
const { provides: tilingCapability } = useTilingCapability();
|
|
20
|
+
const url = ref();
|
|
21
|
+
let blobUrl = null;
|
|
22
|
+
let renderTask = null;
|
|
23
|
+
function revoke() {
|
|
24
|
+
if (blobUrl) {
|
|
25
|
+
URL.revokeObjectURL(blobUrl);
|
|
26
|
+
blobUrl = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function abortCurrentTask() {
|
|
30
|
+
if (renderTask && !blobUrl) {
|
|
31
|
+
renderTask.abort({
|
|
32
|
+
code: PdfErrorCode.Cancelled,
|
|
33
|
+
message: "canceled tile render"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
onMounted(() => {
|
|
38
|
+
if (!tilingCapability.value) return;
|
|
39
|
+
const task = tilingCapability.value.renderTile({
|
|
40
|
+
pageIndex: props.pageIndex,
|
|
41
|
+
tile: toRaw(props.tile),
|
|
42
|
+
dpr: props.dpr
|
|
43
|
+
});
|
|
44
|
+
renderTask = task;
|
|
45
|
+
task.wait((blob) => {
|
|
46
|
+
blobUrl = URL.createObjectURL(blob);
|
|
47
|
+
url.value = blobUrl;
|
|
48
|
+
renderTask = null;
|
|
49
|
+
}, ignore);
|
|
50
|
+
});
|
|
51
|
+
onBeforeUnmount(() => {
|
|
52
|
+
abortCurrentTask();
|
|
53
|
+
revoke();
|
|
54
|
+
});
|
|
55
|
+
const relScale = props.scale / props.tile.srcScale;
|
|
56
|
+
return (_ctx, _cache) => {
|
|
57
|
+
return url.value ? (openBlock(), createElementBlock("img", {
|
|
58
|
+
key: 0,
|
|
59
|
+
src: url.value,
|
|
60
|
+
style: normalizeStyle([
|
|
61
|
+
{
|
|
62
|
+
position: "absolute",
|
|
63
|
+
left: _ctx.tile.screenRect.origin.x * relScale + "px",
|
|
64
|
+
top: _ctx.tile.screenRect.origin.y * relScale + "px",
|
|
65
|
+
width: _ctx.tile.screenRect.size.width * relScale + "px",
|
|
66
|
+
height: _ctx.tile.screenRect.size.height * relScale + "px",
|
|
67
|
+
display: "block"
|
|
68
|
+
},
|
|
69
|
+
props.style
|
|
70
|
+
]),
|
|
71
|
+
onLoad: revoke
|
|
72
|
+
}, null, 44, _hoisted_1)) : createCommentVNode("", true);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
77
|
+
__name: "tiling-layer",
|
|
78
|
+
props: {
|
|
79
|
+
pageIndex: {},
|
|
80
|
+
scale: {},
|
|
81
|
+
style: { type: [Boolean, null, String, Object, Array] }
|
|
82
|
+
},
|
|
83
|
+
setup(__props) {
|
|
84
|
+
const props = __props;
|
|
85
|
+
const tiles = ref([]);
|
|
86
|
+
const { provides: tilingProvides } = useTilingCapability();
|
|
87
|
+
let unsubscribe;
|
|
88
|
+
onMounted(() => {
|
|
89
|
+
if (tilingProvides.value) {
|
|
90
|
+
unsubscribe = tilingProvides.value.onTileRendering((tilesMap) => {
|
|
91
|
+
tiles.value = tilesMap[props.pageIndex] ?? [];
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
onBeforeUnmount(() => {
|
|
96
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
97
|
+
});
|
|
98
|
+
return (_ctx, _cache) => {
|
|
99
|
+
return openBlock(), createElementBlock("div", mergeProps({ style: _ctx.style }, _ctx.$attrs), [
|
|
100
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(tiles.value, (tile) => {
|
|
101
|
+
return openBlock(), createBlock(_sfc_main$1, {
|
|
102
|
+
key: tile.id,
|
|
103
|
+
pageIndex: _ctx.pageIndex,
|
|
104
|
+
tile,
|
|
105
|
+
scale: _ctx.scale
|
|
106
|
+
}, null, 8, ["pageIndex", "tile", "scale"]);
|
|
107
|
+
}), 128))
|
|
108
|
+
], 16);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
export {
|
|
113
|
+
_sfc_main$1 as TileImg,
|
|
114
|
+
_sfc_main as TilingLayer,
|
|
115
|
+
useTilingCapability,
|
|
116
|
+
useTilingPlugin
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-tiling.ts","../../src/vue/components/tile-img.vue","../../src/vue/components/tiling-layer.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { TilingPlugin } from '@embedpdf/plugin-tiling';\n\n/** Get the plugin instance itself (e.g. to read config) */\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\n/** Get the *capability* the plugin exposes (renderTile, onTileRendering) */\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode, PdfErrorReason, Task } from '@embedpdf/models';\nimport type { StyleValue } from 'vue';\n\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { useTilingCapability } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n tile: Tile;\n scale: number;\n dpr?: number;\n style?: StyleValue;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => window.devicePixelRatio,\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\n\nconst url = ref<string>();\nlet blobUrl: string | null = null;\nlet renderTask: Task<Blob, PdfErrorReason> | null = null;\n\n/* -------------------------------------------------- */\n/* Helper functions */\n/* -------------------------------------------------- */\nfunction revoke() {\n if (blobUrl) {\n URL.revokeObjectURL(blobUrl);\n blobUrl = null;\n }\n}\n\nfunction abortCurrentTask() {\n if (renderTask && !blobUrl) {\n renderTask.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled tile render',\n });\n }\n}\n\n/* -------------------------------------------------- */\n/* start one render task when component mounts */\n/* -------------------------------------------------- */\nonMounted(() => {\n if (!tilingCapability.value) return;\n\n const task = tilingCapability.value.renderTile({\n pageIndex: props.pageIndex,\n tile: toRaw(props.tile),\n dpr: props.dpr,\n });\n\n renderTask = task;\n task.wait((blob) => {\n blobUrl = URL.createObjectURL(blob);\n url.value = blobUrl;\n renderTask = null; // Task completed\n }, ignore);\n});\n\n/* -------------------------------------------------- */\n/* cleanup */\n/* -------------------------------------------------- */\nonBeforeUnmount(() => {\n abortCurrentTask();\n revoke();\n});\n\n/* -------------------------------------------------- */\n/* helpers */\n/* -------------------------------------------------- */\nconst relScale = props.scale / props.tile.srcScale;\n</script>\n\n<template>\n <img\n v-if=\"url\"\n :src=\"url\"\n :style=\"[\n {\n position: 'absolute',\n left: tile.screenRect.origin.x * relScale + 'px',\n top: tile.screenRect.origin.y * relScale + 'px',\n width: tile.screenRect.size.width * relScale + 'px',\n height: tile.screenRect.size.height * relScale + 'px',\n display: 'block',\n },\n props.style,\n ]\"\n @load=\"revoke\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { ref, onMounted, onBeforeUnmount } from 'vue';\nimport type { StyleValue } from 'vue';\n\nimport { useTilingCapability } from '../hooks';\nimport TileImg from './tile-img.vue';\n\ninterface Props {\n pageIndex: number;\n scale: number;\n style?: StyleValue;\n}\n\nconst props = defineProps<Props>();\n\nconst tiles = ref<Tile[]>([]);\nconst { provides: tilingProvides } = useTilingCapability();\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (tilingProvides.value) {\n unsubscribe = tilingProvides.value.onTileRendering((tilesMap) => {\n tiles.value = tilesMap[props.pageIndex] ?? [];\n });\n }\n});\n\nonBeforeUnmount(() => {\n unsubscribe?.();\n});\n</script>\n\n<template>\n <div :style=\"style\" v-bind=\"$attrs\">\n <TileImg\n v-for=\"tile in tiles\"\n :key=\"tile.id\"\n :pageIndex=\"pageIndex\"\n :tile=\"tile\"\n :scale=\"scale\"\n />\n </div>\n</template>\n"],"names":["_createElementBlock","_normalizeStyle","tile","_openBlock","_mergeProps","style","$attrs","_Fragment","_renderList","_createBlock","TileImg","pageIndex","scale"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AAErE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;;;;;;;;;;ACUpF,UAAM,QAAQ;AAId,UAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAE3D,UAAM,MAAM,IAAY;AACxB,QAAI,UAAyB;AAC7B,QAAI,aAAgD;AAKpD,aAAS,SAAS;AAChB,UAAI,SAAS;AACX,YAAI,gBAAgB,OAAO;AACjB,kBAAA;AAAA,MAAA;AAAA,IACZ;AAGF,aAAS,mBAAmB;AACtB,UAAA,cAAc,CAAC,SAAS;AAC1B,mBAAW,MAAM;AAAA,UACf,MAAM,aAAa;AAAA,UACnB,SAAS;AAAA,QAAA,CACV;AAAA,MAAA;AAAA,IACH;AAMF,cAAU,MAAM;AACV,UAAA,CAAC,iBAAiB,MAAO;AAEvB,YAAA,OAAO,iBAAiB,MAAM,WAAW;AAAA,QAC7C,WAAW,MAAM;AAAA,QACjB,MAAM,MAAM,MAAM,IAAI;AAAA,QACtB,KAAK,MAAM;AAAA,MAAA,CACZ;AAEY,mBAAA;AACR,WAAA,KAAK,CAAC,SAAS;AACR,kBAAA,IAAI,gBAAgB,IAAI;AAClC,YAAI,QAAQ;AACC,qBAAA;AAAA,SACZ,MAAM;AAAA,IAAA,CACV;AAKD,oBAAgB,MAAM;AACH,uBAAA;AACV,aAAA;AAAA,IAAA,CACR;AAKD,UAAM,WAAW,MAAM,QAAQ,MAAM,KAAK;;aAKhC,IAAG,sBADXA,mBAeE,OAAA;AAAA;QAbC,KAAK,IAAG;AAAA,QACR,OAAKC,eAAA;AAAA;;YAAwDC,MAAAA,KAAAA,KAAK,WAAW,OAAO,IAAI,WAAQ;AAAA,YAAsBA,KAAAA,KAAAA,KAAK,WAAW,OAAO,IAAI,WAAQ;AAAA,YAAwBA,OAAAA,KAAAA,KAAK,WAAW,KAAK,QAAQ,WAAQ;AAAA,YAAyBA,QAAAA,KAAAA,KAAK,WAAW,KAAK,SAAS,WAAQ;AAAA;;UAAkD,MAAM;AAAA,QAAA;QAW7U,QAAM;AAAA,MAAA;;;;;;;;;;;;AChFX,UAAM,QAAQ;AAER,UAAA,QAAQ,IAAY,EAAE;AAC5B,UAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AAErD,QAAA;AAEJ,cAAU,MAAM;AACd,UAAI,eAAe,OAAO;AACxB,sBAAc,eAAe,MAAM,gBAAgB,CAAC,aAAa;AAC/D,gBAAM,QAAQ,SAAS,MAAM,SAAS,KAAK,CAAC;AAAA,QAAA,CAC7C;AAAA,MAAA;AAAA,IACH,CACD;AAED,oBAAgB,MAAM;AACN;AAAA,IAAA,CACf;;AAIC,aAAAC,UAAA,GAAAH,mBAQM,OARNI,WAQM,EARA,OAAOC,KAAAA,SAAeC,KAAM,MAAA,GAAA;AAAA,0BAChCN,mBAMEO,UAAA,MAAAC,WALe,MAAK,OAAA,CAAb,SAAI;8BADbC,YAMEC,aAAA;AAAA,YAJC,KAAK,KAAK;AAAA,YACV,WAAWC,KAAS;AAAA,YACpB;AAAA,YACA,OAAOC,KAAK;AAAA,UAAA;;;;;;"}
|