@embedpdf/plugin-tiling 1.4.1 → 2.0.0-next.0
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 +137 -47
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +27 -7
- package/dist/lib/reducer.d.ts +2 -1
- package/dist/lib/tiling-plugin.d.ts +10 -5
- package/dist/lib/types.d.ts +14 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +30 -10
- 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 +30 -10
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/tile-img.d.ts +2 -1
- package/dist/shared/components/tiling-layer.d.ts +3 -2
- package/dist/shared-preact/components/tile-img.d.ts +2 -1
- package/dist/shared-preact/components/tiling-layer.d.ts +3 -2
- package/dist/shared-react/components/tile-img.d.ts +2 -1
- package/dist/shared-react/components/tiling-layer.d.ts +3 -2
- package/dist/svelte/components/TileImg.svelte.d.ts +1 -0
- package/dist/svelte/components/TilingLayer.svelte.d.ts +2 -1
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +35 -30
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/tile-img.vue.d.ts +3 -1
- package/dist/vue/components/tiling-layer.vue.d.ts +5 -3
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +50 -24
- package/dist/vue/index.js.map +1 -1
- package/package.json +10 -10
package/dist/svelte/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import "svelte/internal/disclose-version";
|
|
|
2
2
|
import * as $ from "svelte/internal/client";
|
|
3
3
|
import { TilingPlugin } from "@embedpdf/plugin-tiling";
|
|
4
4
|
export * from "@embedpdf/plugin-tiling";
|
|
5
|
-
import { useCapability, usePlugin,
|
|
5
|
+
import { useCapability, usePlugin, useDocumentState } from "@embedpdf/core/svelte";
|
|
6
6
|
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
7
7
|
import { untrack } from "svelte";
|
|
8
8
|
const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
@@ -11,6 +11,10 @@ var root_1 = $.from_html(`<img alt=""/>`);
|
|
|
11
11
|
function TileImg($$anchor, $$props) {
|
|
12
12
|
$.push($$props, true);
|
|
13
13
|
const tilingCapability = useTilingCapability();
|
|
14
|
+
const scope = $.derived(() => {
|
|
15
|
+
var _a;
|
|
16
|
+
return ((_a = tilingCapability.provides) == null ? void 0 : _a.forDocument($$props.documentId)) ?? null;
|
|
17
|
+
});
|
|
14
18
|
let url = $.state("");
|
|
15
19
|
let urlRef = null;
|
|
16
20
|
const tileId = $.derived(() => $$props.tile.id);
|
|
@@ -32,14 +36,13 @@ function TileImg($$anchor, $$props) {
|
|
|
32
36
|
}
|
|
33
37
|
});
|
|
34
38
|
$.user_effect(() => {
|
|
35
|
-
var _a;
|
|
36
39
|
$.get(tileId);
|
|
37
40
|
const _pageIndex = $$props.pageIndex;
|
|
38
41
|
if (urlRef) return;
|
|
39
|
-
if (
|
|
42
|
+
if (!$.get(scope)) return;
|
|
40
43
|
const plainTile = untrack(() => createPlainTile($$props.tile));
|
|
41
|
-
const task = (
|
|
42
|
-
task
|
|
44
|
+
const task = $.get(scope).renderTile({ pageIndex: _pageIndex, tile: plainTile, dpr: $$props.dpr });
|
|
45
|
+
task.wait(
|
|
43
46
|
(blob) => {
|
|
44
47
|
const objectUrl = URL.createObjectURL(blob);
|
|
45
48
|
urlRef = objectUrl;
|
|
@@ -52,7 +55,7 @@ function TileImg($$anchor, $$props) {
|
|
|
52
55
|
URL.revokeObjectURL(urlRef);
|
|
53
56
|
urlRef = null;
|
|
54
57
|
} else {
|
|
55
|
-
task
|
|
58
|
+
task.abort({
|
|
56
59
|
code: PdfErrorCode.Cancelled,
|
|
57
60
|
message: "canceled render task"
|
|
58
61
|
});
|
|
@@ -71,22 +74,17 @@ function TileImg($$anchor, $$props) {
|
|
|
71
74
|
var consequent = ($$anchor2) => {
|
|
72
75
|
var img = root_1();
|
|
73
76
|
let styles;
|
|
74
|
-
$.template_effect(
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
()
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
height: `${$.get(tileScreenRect).size.height * $.get(relativeScale)}px`,
|
|
86
|
-
display: "block"
|
|
87
|
-
})
|
|
88
|
-
]
|
|
89
|
-
);
|
|
77
|
+
$.template_effect(() => {
|
|
78
|
+
$.set_attribute(img, "src", $.get(url));
|
|
79
|
+
styles = $.set_style(img, "", styles, {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
left: `${$.get(tileScreenRect).origin.x * $.get(relativeScale)}px`,
|
|
82
|
+
top: `${$.get(tileScreenRect).origin.y * $.get(relativeScale)}px`,
|
|
83
|
+
width: `${$.get(tileScreenRect).size.width * $.get(relativeScale)}px`,
|
|
84
|
+
height: `${$.get(tileScreenRect).size.height * $.get(relativeScale)}px`,
|
|
85
|
+
display: "block"
|
|
86
|
+
});
|
|
87
|
+
});
|
|
90
88
|
$.event("load", img, handleImageLoad);
|
|
91
89
|
$.replay_events(img);
|
|
92
90
|
$.append($$anchor2, img);
|
|
@@ -105,26 +103,33 @@ function TilingLayer($$anchor, $$props) {
|
|
|
105
103
|
"$$slots",
|
|
106
104
|
"$$events",
|
|
107
105
|
"$$legacy",
|
|
106
|
+
"documentId",
|
|
108
107
|
"pageIndex",
|
|
109
108
|
"scale",
|
|
110
109
|
"class"
|
|
111
110
|
]);
|
|
112
111
|
const tilingCapability = useTilingCapability();
|
|
112
|
+
const documentState = useDocumentState(() => $$props.documentId);
|
|
113
113
|
let tiles = $.state($.proxy([]));
|
|
114
|
-
const
|
|
114
|
+
const actualScale = $.derived(() => {
|
|
115
|
+
var _a;
|
|
116
|
+
return $$props.scale !== void 0 ? $$props.scale : ((_a = documentState.current) == null ? void 0 : _a.scale) ?? 1;
|
|
117
|
+
});
|
|
115
118
|
$.user_effect(() => {
|
|
116
119
|
if (!tilingCapability.provides) return;
|
|
117
|
-
return tilingCapability.provides.onTileRendering((
|
|
118
|
-
|
|
120
|
+
return tilingCapability.provides.onTileRendering((event) => {
|
|
121
|
+
if (event.documentId === $$props.documentId) {
|
|
122
|
+
$.set(tiles, event.tiles[$$props.pageIndex] ?? [], true);
|
|
123
|
+
}
|
|
119
124
|
});
|
|
120
125
|
});
|
|
121
126
|
var div = root();
|
|
122
127
|
$.attribute_effect(div, () => ({ class: $$props.class, ...restProps }));
|
|
123
|
-
$.each(div, 21, () => $.get(tiles), (tile) => {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
return `${(_b = (_a = core.coreState) == null ? void 0 : _a.document) == null ? void 0 : _b.id}-${tile.id}`;
|
|
126
|
-
}, ($$anchor2, tile) => {
|
|
128
|
+
$.each(div, 21, () => $.get(tiles), (tile) => tile.id, ($$anchor2, tile) => {
|
|
127
129
|
TileImg($$anchor2, {
|
|
130
|
+
get documentId() {
|
|
131
|
+
return $$props.documentId;
|
|
132
|
+
},
|
|
128
133
|
get pageIndex() {
|
|
129
134
|
return $$props.pageIndex;
|
|
130
135
|
},
|
|
@@ -133,7 +138,7 @@ function TilingLayer($$anchor, $$props) {
|
|
|
133
138
|
},
|
|
134
139
|
dpr: window.devicePixelRatio,
|
|
135
140
|
get scale() {
|
|
136
|
-
return
|
|
141
|
+
return $.get(actualScale);
|
|
137
142
|
}
|
|
138
143
|
});
|
|
139
144
|
});
|
package/dist/svelte/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-tiling.ts","../../src/svelte/components/TileImg.svelte","../../src/svelte/components/TilingLayer.svelte"],"sourcesContent":["import { TilingPlugin } from '@embedpdf/plugin-tiling';\nimport { useCapability, usePlugin } from '@embedpdf/core/svelte';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","<script lang=\"ts\">\n import type { Tile } from '@embedpdf/plugin-tiling';\n import { useTilingCapability } from '../hooks';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { untrack } from 'svelte';\n\n interface TileImgProps {\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n }\n\n let { pageIndex, tile, dpr, scale }: TileImgProps = $props();\n const tilingCapability = useTilingCapability();\n let url = $state<string>('');\n // urlRef is NOT reactive - similar to React's useRef\n let urlRef: string | null = null;\n\n // Capture these values once per tile change\n const tileId = $derived(tile.id);\n const tileSrcScale = $derived(tile.srcScale);\n const tileScreenRect = $derived(tile.screenRect);\n const relativeScale = $derived(scale / tileSrcScale);\n\n const createPlainTile = (t: Tile): Tile => ({\n ...t,\n pageRect: {\n origin: { x: t.pageRect.origin.x, y: t.pageRect.origin.y },\n size: { width: t.pageRect.size.width, height: t.pageRect.size.height },\n },\n screenRect: {\n origin: { x: t.screenRect.origin.x, y: t.screenRect.origin.y },\n size: { width: t.screenRect.size.width, height: t.screenRect.size.height },\n },\n });\n\n /* kick off render exactly once per tile */\n $effect(() => {\n // Track only tileId and pageIndex as dependencies (like React's [pageIndex, tile.id])\n const _tileId = tileId;\n const _pageIndex = pageIndex;\n\n // Check if we already have a URL for this tile (already rendered)\n if (urlRef) return;\n\n if (!
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-tiling.ts","../../src/svelte/components/TileImg.svelte","../../src/svelte/components/TilingLayer.svelte"],"sourcesContent":["import { TilingPlugin } from '@embedpdf/plugin-tiling';\nimport { useCapability, usePlugin } from '@embedpdf/core/svelte';\n\nexport const useTilingPlugin = () => usePlugin<TilingPlugin>(TilingPlugin.id);\nexport const useTilingCapability = () => useCapability<TilingPlugin>(TilingPlugin.id);\n","<script lang=\"ts\">\n import type { Tile } from '@embedpdf/plugin-tiling';\n import { useTilingCapability } from '../hooks';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { untrack } from 'svelte';\n\n interface TileImgProps {\n documentId: string;\n pageIndex: number;\n tile: Tile;\n dpr: number;\n scale: number;\n }\n\n let { documentId, pageIndex, tile, dpr, scale }: TileImgProps = $props();\n const tilingCapability = useTilingCapability();\n\n // Derived scoped capability for the specific document\n const scope = $derived(tilingCapability.provides?.forDocument(documentId) ?? null);\n\n let url = $state<string>('');\n // urlRef is NOT reactive - similar to React's useRef\n let urlRef: string | null = null;\n\n // Capture these values once per tile change\n const tileId = $derived(tile.id);\n const tileSrcScale = $derived(tile.srcScale);\n const tileScreenRect = $derived(tile.screenRect);\n const relativeScale = $derived(scale / tileSrcScale);\n\n const createPlainTile = (t: Tile): Tile => ({\n ...t,\n pageRect: {\n origin: { x: t.pageRect.origin.x, y: t.pageRect.origin.y },\n size: { width: t.pageRect.size.width, height: t.pageRect.size.height },\n },\n screenRect: {\n origin: { x: t.screenRect.origin.x, y: t.screenRect.origin.y },\n size: { width: t.screenRect.size.width, height: t.screenRect.size.height },\n },\n });\n\n /* kick off render exactly once per tile */\n $effect(() => {\n // Track only tileId and pageIndex as dependencies (like React's [pageIndex, tile.id])\n const _tileId = tileId;\n const _pageIndex = pageIndex;\n\n // Check if we already have a URL for this tile (already rendered)\n if (urlRef) return;\n\n if (!scope) return;\n\n // Clone to avoid reactive proxies that Web Workers cannot clone\n const plainTile = untrack(() => createPlainTile(tile));\n const task = scope.renderTile({\n pageIndex: _pageIndex,\n tile: plainTile,\n dpr,\n });\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef = objectUrl;\n url = objectUrl;\n }, ignore);\n\n return () => {\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n });\n\n const handleImageLoad = () => {\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n</script>\n\n{#if url}\n <img\n src={url}\n alt=\"\"\n onload={handleImageLoad}\n style:position=\"absolute\"\n style:left={`${tileScreenRect.origin.x * relativeScale}px`}\n style:top={`${tileScreenRect.origin.y * relativeScale}px`}\n style:width={`${tileScreenRect.size.width * relativeScale}px`}\n style:height={`${tileScreenRect.size.height * relativeScale}px`}\n style:display=\"block\"\n />\n{/if}\n","<script lang=\"ts\">\n import type { Tile } from '@embedpdf/plugin-tiling';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import TileImg from './TileImg.svelte';\n import { useTilingCapability } from '../hooks';\n\n type TilingLayoutProps = HTMLAttributes<HTMLDivElement> & {\n documentId: string;\n pageIndex: number;\n scale?: number;\n class?: string;\n };\n\n let {\n documentId,\n pageIndex,\n scale: scaleOverride,\n class: propsClass,\n ...restProps\n }: TilingLayoutProps = $props();\n\n const tilingCapability = useTilingCapability();\n const documentState = useDocumentState(() => documentId);\n\n let tiles = $state<Tile[]>([]);\n\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n $effect(() => {\n if (!tilingCapability.provides) return;\n return tilingCapability.provides.onTileRendering((event) => {\n if (event.documentId === documentId) {\n tiles = event.tiles[pageIndex] ?? [];\n }\n });\n });\n</script>\n\n<div class={propsClass} {...restProps}>\n {#each tiles as tile (tile.id)}\n <TileImg {documentId} {pageIndex} {tile} dpr={window.devicePixelRatio} scale={actualScale} />\n {/each}\n</div>\n"],"names":[],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;oCCJpF;;AAeQ,QAAA,mBAAmB,oBAAmB;AAGtC,QAAA;;AAAiB,mCAAiB,aAAjB,mBA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2
2
|
interface Props {
|
|
3
|
+
documentId: string;
|
|
3
4
|
pageIndex: number;
|
|
4
5
|
tile: Tile;
|
|
5
6
|
scale: number;
|
|
6
7
|
dpr?: number;
|
|
7
8
|
}
|
|
8
|
-
declare const
|
|
9
|
+
declare const __VLS_export: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
9
10
|
dpr: number;
|
|
10
11
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
11
13
|
export default _default;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface TilingLayerProps {
|
|
2
|
+
documentId: string;
|
|
2
3
|
pageIndex: number;
|
|
3
|
-
scale
|
|
4
|
+
scale?: number;
|
|
4
5
|
}
|
|
5
|
-
declare const
|
|
6
|
+
declare const __VLS_export: import('vue').DefineComponent<TilingLayerProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<TilingLayerProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const _default: typeof __VLS_export;
|
|
6
8
|
export default _default;
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/models"),l=require("@embedpdf/core/vue"),i=require("@embedpdf/plugin-tiling"),o=()=>l.useCapability(i.TilingPlugin.id),n=["src"],r=e.defineComponent({__name:"tile-img",props:{documentId:{},pageIndex:{},tile:{},scale:{},dpr:{default:()=>"undefined"!=typeof window?window.devicePixelRatio:1}},setup(l){const i=l,{provides:r}=o(),d=e.ref(),a=e.computed(()=>i.scale/i.tile.srcScale);let c,u=null;return e.watch([()=>i.tile.id,()=>i.documentId,r],([l,o,n],[r,a])=>{if(!n)return;const s=n.forDocument(o);void 0!==a&&a!==o&&(d.value&&(URL.revokeObjectURL(d.value),d.value=void 0),u&&(u.abort({code:t.PdfErrorCode.Cancelled,message:"switching documents"}),u=null),c=void 0),c===l&&a===o||(u&&(u.abort({code:t.PdfErrorCode.Cancelled,message:"switching tiles"}),u=null),d.value&&(URL.revokeObjectURL(d.value),d.value=void 0),c=l,u=s.renderTile({pageIndex:i.pageIndex,tile:e.toRaw(i.tile),dpr:i.dpr}),u.wait(e=>{d.value=URL.createObjectURL(e),u=null},t.ignore))},{immediate:!0}),e.onBeforeUnmount(()=>{u&&u.abort({code:t.PdfErrorCode.Cancelled,message:"unmounting"}),d.value&&URL.revokeObjectURL(d.value)}),(t,i)=>d.value?(e.openBlock(),e.createElementBlock("img",{key:0,src:d.value,style:e.normalizeStyle({position:"absolute",left:l.tile.screenRect.origin.x*a.value+"px",top:l.tile.screenRect.origin.y*a.value+"px",width:l.tile.screenRect.size.width*a.value+"px",height:l.tile.screenRect.size.height*a.value+"px",display:"block"})},null,12,n)):e.createCommentVNode("",!0)}}),d=e.defineComponent({__name:"tiling-layer",props:{documentId:{},pageIndex:{},scale:{}},setup(t){const i=t,{provides:n}=o(),d=l.useDocumentState(()=>i.documentId),a=e.ref([]),c=e.computed(()=>{var e;return void 0!==i.scale?i.scale:(null==(e=d.value)?void 0:e.scale)??1});return e.watch([n,()=>i.documentId,()=>i.pageIndex],([e,t,l],i,o)=>{if(!e)return void(a.value=[]);o(e.onTileRendering(e=>{e.documentId===t&&(a.value=e.tiles[l]??[])}))},{immediate:!0}),(l,i)=>(e.openBlock(),e.createElementBlock("div",e.normalizeProps(e.guardReactiveProps(l.$attrs)),[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,l=>(e.openBlock(),e.createBlock(r,{key:l.id,documentId:t.documentId,pageIndex:t.pageIndex,tile:l,scale:c.value},null,8,["documentId","pageIndex","tile","scale"]))),128))],16))}});exports.TileImg=r,exports.TilingLayer=d,exports.useTilingCapability=o,exports.useTilingPlugin=()=>l.usePlugin(i.TilingPlugin.id),Object.keys(i).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>i[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-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, computed, watch, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\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}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => (typeof window !== 'undefined' ? window.devicePixelRatio : 1),\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\nconst url = ref<string>();\nconst relScale = computed(() => props.scale / props.tile.srcScale);\n\n// Track last rendered tile ID to prevent duplicates\nlet lastRenderedId: string | undefined;\nlet currentTask: any = null;\n\nwatch(\n [() => props.tile.id, tilingCapability],\n ([tileId, capability]) => {\n if (!capability) return;\n\n // Already rendered this exact tile\n if (lastRenderedId === tileId) return;\n\n // Cancel previous task if any\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching tiles' });\n currentTask = null;\n }\n\n // Clean up old URL\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n\n lastRenderedId = tileId;\n\n currentTask =
|
|
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, computed, watch, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { useTilingCapability } from '../hooks';\n\ninterface Props {\n documentId: string;\n pageIndex: number;\n tile: Tile;\n scale: number;\n dpr?: number;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => (typeof window !== 'undefined' ? window.devicePixelRatio : 1),\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\nconst url = ref<string>();\nconst relScale = computed(() => props.scale / props.tile.srcScale);\n\n// Track last rendered tile ID to prevent duplicates\nlet lastRenderedId: string | undefined;\nlet currentTask: any = null;\n\nwatch(\n [() => props.tile.id, () => props.documentId, tilingCapability],\n ([tileId, docId, capability], [prevTileId, prevDocId]) => {\n if (!capability) return;\n\n const scope = capability.forDocument(docId);\n\n // CRITICAL: Clear image immediately when documentId changes\n if (prevDocId !== undefined && prevDocId !== docId) {\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching documents' });\n currentTask = null;\n }\n lastRenderedId = undefined; // Reset so new document tiles render\n }\n\n // Already rendered this exact tile (for same document)\n if (lastRenderedId === tileId && prevDocId === docId) return;\n\n // Cancel previous task if any\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching tiles' });\n currentTask = null;\n }\n\n // Clean up old URL\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n\n lastRenderedId = tileId;\n\n currentTask = scope.renderTile({\n pageIndex: props.pageIndex,\n tile: toRaw(props.tile),\n dpr: props.dpr,\n });\n\n currentTask.wait((blob: Blob) => {\n url.value = URL.createObjectURL(blob);\n currentTask = null;\n }, ignore);\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'unmounting' });\n }\n if (url.value) {\n URL.revokeObjectURL(url.value);\n }\n});\n</script>\n\n<template>\n <img\n v-if=\"url\"\n :src=\"url\"\n :style=\"{\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 />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch, computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { Tile } from '@embedpdf/plugin-tiling';\n\nimport { useTilingCapability } from '../hooks';\nimport TileImg from './tile-img.vue';\n\ninterface TilingLayerProps {\n documentId: string;\n pageIndex: number;\n scale?: number;\n}\n\nconst props = defineProps<TilingLayerProps>();\n\nconst { provides: tilingProvides } = useTilingCapability();\nconst documentState = useDocumentState(() => props.documentId);\nconst tiles = ref<Tile[]>([]);\n\nconst actualScale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nwatch(\n [tilingProvides, () => props.documentId, () => props.pageIndex],\n ([provides, docId, pageIdx], _, onCleanup) => {\n if (!provides) {\n tiles.value = [];\n return;\n }\n\n const unsubscribe = provides.onTileRendering((event) => {\n if (event.documentId === docId) {\n tiles.value = event.tiles[pageIdx] ?? [];\n }\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n</script>\n\n<template>\n <div v-bind=\"$attrs\">\n <TileImg\n v-for=\"tile in tiles\"\n :key=\"tile.id\"\n :documentId=\"documentId\"\n :pageIndex=\"pageIndex\"\n :tile=\"tile\"\n :scale=\"actualScale\"\n />\n </div>\n</template>\n"],"names":["useTilingCapability","useCapability","TilingPlugin","id","props","__props","provides","tilingCapability","url","ref","relScale","computed","scale","tile","srcScale","lastRenderedId","currentTask","watch","documentId","tileId","docId","capability","prevTileId","prevDocId","scope","forDocument","value","URL","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","renderTile","pageIndex","toRaw","dpr","wait","blob","createObjectURL","ignore","immediate","onBeforeUnmount","_createElementBlock","src","style","_normalizeStyle","left","screenRect","origin","x","top","y","width","size","height","tilingProvides","documentState","useDocumentState","tiles","actualScale","_a","pageIdx","_","onCleanup","onTileRendering","event","_openBlock","$attrs","_Fragment","_renderList","_createBlock","TileImg","key","usePlugin"],"mappings":"0MAMaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,yLCSlF,MAAMC,EAAQC,GAINC,SAAUC,GAAqBP,IACjCQ,EAAMC,EAAAA,MACNC,EAAWC,EAAAA,SAAS,IAAMP,EAAMQ,MAAQR,EAAMS,KAAKC,UAGzD,IAAIC,EACAC,EAAmB,YAEvBC,EAAAA,MACE,CAAC,IAAMb,EAAMS,KAAKV,GAAI,IAAMC,EAAMc,WAAYX,GAC9C,EAAEY,EAAQC,EAAOC,IAAcC,EAAYC,MACzC,IAAKF,EAAY,OAEjB,MAAMG,EAAQH,EAAWI,YAAYL,QAGnB,IAAdG,GAA2BA,IAAcH,IACvCZ,EAAIkB,QACNC,IAAIC,gB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,EAAAA,IAAY,IAEpBoD,EAAclD,EAAAA,SAAS,WAC3B,YAAoB,IAAhBP,EAAMQ,MAA4BR,EAAMQ,OACrC,OAAAkD,EAAAJ,EAAchC,YAAd,EAAAoC,EAAqBlD,QAAS,WAGvCK,EAAAA,MACE,CAACwC,EAAgB,IAAMrD,EAAMc,WAAY,IAAMd,EAAM+B,WACrD,EAAE7B,EAAUc,EAAO2C,GAAUC,EAAGC,KAC9B,IAAK3D,EAEH,YADAsD,EAAMlC,MAAQ,IAUhBuC,EANoB3D,EAAS4D,gBAAiBC,IACxCA,EAAMjD,aAAeE,IACvBwC,EAAMlC,MAAQyC,EAAMP,MAAMG,IAAY,QAM5C,CAAErB,WAAW,YAKb0B,EAAAA,YAAAxB,EAAAA,mBASM,4CATOyB,EAAAA,SAAM,kBACjBzB,EAAAA,mBAOE0B,EAAAA,SAAA,KAAAC,EAAAA,WANeX,EAAAlC,MAARb,kBADT2D,EAAAA,YAOEC,EAAA,CALCC,IAAK7D,EAAKV,GACVe,WAAYb,EAAAa,WACZiB,UAAW9B,EAAA8B,UACXtB,OACAD,MAAOiD,EAAAnC,wKFjDiB,IAAMiD,YAAwBzE,EAAAA,aAAaC"}
|
package/dist/vue/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent, ref, computed, watch, toRaw, onBeforeUnmount, createElementBlock, createCommentVNode, openBlock, normalizeStyle,
|
|
1
|
+
import { defineComponent, ref, computed, watch, toRaw, onBeforeUnmount, createElementBlock, createCommentVNode, openBlock, normalizeStyle, normalizeProps, guardReactiveProps, Fragment, renderList, createBlock } from "vue";
|
|
2
2
|
import { ignore, PdfErrorCode } from "@embedpdf/models";
|
|
3
|
-
import { useCapability, usePlugin } from "@embedpdf/core/vue";
|
|
3
|
+
import { useCapability, usePlugin, useDocumentState } from "@embedpdf/core/vue";
|
|
4
4
|
import { TilingPlugin } from "@embedpdf/plugin-tiling";
|
|
5
5
|
export * from "@embedpdf/plugin-tiling";
|
|
6
6
|
const useTilingPlugin = () => usePlugin(TilingPlugin.id);
|
|
@@ -9,6 +9,7 @@ const _hoisted_1 = ["src"];
|
|
|
9
9
|
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
10
10
|
__name: "tile-img",
|
|
11
11
|
props: {
|
|
12
|
+
documentId: {},
|
|
12
13
|
pageIndex: {},
|
|
13
14
|
tile: {},
|
|
14
15
|
scale: {},
|
|
@@ -22,10 +23,22 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
22
23
|
let lastRenderedId;
|
|
23
24
|
let currentTask = null;
|
|
24
25
|
watch(
|
|
25
|
-
[() => props.tile.id, tilingCapability],
|
|
26
|
-
([tileId, capability]) => {
|
|
26
|
+
[() => props.tile.id, () => props.documentId, tilingCapability],
|
|
27
|
+
([tileId, docId, capability], [prevTileId, prevDocId]) => {
|
|
27
28
|
if (!capability) return;
|
|
28
|
-
|
|
29
|
+
const scope = capability.forDocument(docId);
|
|
30
|
+
if (prevDocId !== void 0 && prevDocId !== docId) {
|
|
31
|
+
if (url.value) {
|
|
32
|
+
URL.revokeObjectURL(url.value);
|
|
33
|
+
url.value = void 0;
|
|
34
|
+
}
|
|
35
|
+
if (currentTask) {
|
|
36
|
+
currentTask.abort({ code: PdfErrorCode.Cancelled, message: "switching documents" });
|
|
37
|
+
currentTask = null;
|
|
38
|
+
}
|
|
39
|
+
lastRenderedId = void 0;
|
|
40
|
+
}
|
|
41
|
+
if (lastRenderedId === tileId && prevDocId === docId) return;
|
|
29
42
|
if (currentTask) {
|
|
30
43
|
currentTask.abort({ code: PdfErrorCode.Cancelled, message: "switching tiles" });
|
|
31
44
|
currentTask = null;
|
|
@@ -35,7 +48,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
35
48
|
url.value = void 0;
|
|
36
49
|
}
|
|
37
50
|
lastRenderedId = tileId;
|
|
38
|
-
currentTask =
|
|
51
|
+
currentTask = scope.renderTile({
|
|
39
52
|
pageIndex: props.pageIndex,
|
|
40
53
|
tile: toRaw(props.tile),
|
|
41
54
|
dpr: props.dpr
|
|
@@ -61,10 +74,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
61
74
|
src: url.value,
|
|
62
75
|
style: normalizeStyle({
|
|
63
76
|
position: "absolute",
|
|
64
|
-
left: `${
|
|
65
|
-
top: `${
|
|
66
|
-
width: `${
|
|
67
|
-
height: `${
|
|
77
|
+
left: `${__props.tile.screenRect.origin.x * relScale.value}px`,
|
|
78
|
+
top: `${__props.tile.screenRect.origin.y * relScale.value}px`,
|
|
79
|
+
width: `${__props.tile.screenRect.size.width * relScale.value}px`,
|
|
80
|
+
height: `${__props.tile.screenRect.size.height * relScale.value}px`,
|
|
68
81
|
display: "block"
|
|
69
82
|
})
|
|
70
83
|
}, null, 12, _hoisted_1)) : createCommentVNode("", true);
|
|
@@ -74,33 +87,46 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
74
87
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
75
88
|
__name: "tiling-layer",
|
|
76
89
|
props: {
|
|
90
|
+
documentId: {},
|
|
77
91
|
pageIndex: {},
|
|
78
92
|
scale: {}
|
|
79
93
|
},
|
|
80
94
|
setup(__props) {
|
|
81
95
|
const props = __props;
|
|
82
|
-
const tiles = ref([]);
|
|
83
96
|
const { provides: tilingProvides } = useTilingCapability();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
onBeforeUnmount(() => {
|
|
93
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
97
|
+
const documentState = useDocumentState(() => props.documentId);
|
|
98
|
+
const tiles = ref([]);
|
|
99
|
+
const actualScale = computed(() => {
|
|
100
|
+
var _a;
|
|
101
|
+
if (props.scale !== void 0) return props.scale;
|
|
102
|
+
return ((_a = documentState.value) == null ? void 0 : _a.scale) ?? 1;
|
|
94
103
|
});
|
|
104
|
+
watch(
|
|
105
|
+
[tilingProvides, () => props.documentId, () => props.pageIndex],
|
|
106
|
+
([provides, docId, pageIdx], _, onCleanup) => {
|
|
107
|
+
if (!provides) {
|
|
108
|
+
tiles.value = [];
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const unsubscribe = provides.onTileRendering((event) => {
|
|
112
|
+
if (event.documentId === docId) {
|
|
113
|
+
tiles.value = event.tiles[pageIdx] ?? [];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
onCleanup(unsubscribe);
|
|
117
|
+
},
|
|
118
|
+
{ immediate: true }
|
|
119
|
+
);
|
|
95
120
|
return (_ctx, _cache) => {
|
|
96
121
|
return openBlock(), createElementBlock("div", normalizeProps(guardReactiveProps(_ctx.$attrs)), [
|
|
97
122
|
(openBlock(true), createElementBlock(Fragment, null, renderList(tiles.value, (tile) => {
|
|
98
123
|
return openBlock(), createBlock(_sfc_main$1, {
|
|
99
124
|
key: tile.id,
|
|
100
|
-
|
|
125
|
+
documentId: __props.documentId,
|
|
126
|
+
pageIndex: __props.pageIndex,
|
|
101
127
|
tile,
|
|
102
|
-
scale:
|
|
103
|
-
}, null, 8, ["pageIndex", "tile", "scale"]);
|
|
128
|
+
scale: actualScale.value
|
|
129
|
+
}, null, 8, ["documentId", "pageIndex", "tile", "scale"]);
|
|
104
130
|
}), 128))
|
|
105
131
|
], 16);
|
|
106
132
|
};
|
package/dist/vue/index.js.map
CHANGED
|
@@ -1 +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, computed, watch, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\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}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => (typeof window !== 'undefined' ? window.devicePixelRatio : 1),\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\nconst url = ref<string>();\nconst relScale = computed(() => props.scale / props.tile.srcScale);\n\n// Track last rendered tile ID to prevent duplicates\nlet lastRenderedId: string | undefined;\nlet currentTask: any = null;\n\nwatch(\n [() => props.tile.id, tilingCapability],\n ([tileId, capability]) => {\n if (!capability) return;\n\n // Already rendered this exact tile\n if (lastRenderedId === tileId) return;\n\n // Cancel previous task if any\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching tiles' });\n currentTask = null;\n }\n\n // Clean up old URL\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n\n lastRenderedId = tileId;\n\n currentTask =
|
|
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, computed, watch, onBeforeUnmount, toRaw } from 'vue';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\n\nimport type { Tile } from '@embedpdf/plugin-tiling';\nimport { useTilingCapability } from '../hooks';\n\ninterface Props {\n documentId: string;\n pageIndex: number;\n tile: Tile;\n scale: number;\n dpr?: number;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n dpr: () => (typeof window !== 'undefined' ? window.devicePixelRatio : 1),\n});\n\nconst { provides: tilingCapability } = useTilingCapability();\nconst url = ref<string>();\nconst relScale = computed(() => props.scale / props.tile.srcScale);\n\n// Track last rendered tile ID to prevent duplicates\nlet lastRenderedId: string | undefined;\nlet currentTask: any = null;\n\nwatch(\n [() => props.tile.id, () => props.documentId, tilingCapability],\n ([tileId, docId, capability], [prevTileId, prevDocId]) => {\n if (!capability) return;\n\n const scope = capability.forDocument(docId);\n\n // CRITICAL: Clear image immediately when documentId changes\n if (prevDocId !== undefined && prevDocId !== docId) {\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching documents' });\n currentTask = null;\n }\n lastRenderedId = undefined; // Reset so new document tiles render\n }\n\n // Already rendered this exact tile (for same document)\n if (lastRenderedId === tileId && prevDocId === docId) return;\n\n // Cancel previous task if any\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'switching tiles' });\n currentTask = null;\n }\n\n // Clean up old URL\n if (url.value) {\n URL.revokeObjectURL(url.value);\n url.value = undefined;\n }\n\n lastRenderedId = tileId;\n\n currentTask = scope.renderTile({\n pageIndex: props.pageIndex,\n tile: toRaw(props.tile),\n dpr: props.dpr,\n });\n\n currentTask.wait((blob: Blob) => {\n url.value = URL.createObjectURL(blob);\n currentTask = null;\n }, ignore);\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n if (currentTask) {\n currentTask.abort({ code: PdfErrorCode.Cancelled, message: 'unmounting' });\n }\n if (url.value) {\n URL.revokeObjectURL(url.value);\n }\n});\n</script>\n\n<template>\n <img\n v-if=\"url\"\n :src=\"url\"\n :style=\"{\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 />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watch, computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport type { Tile } from '@embedpdf/plugin-tiling';\n\nimport { useTilingCapability } from '../hooks';\nimport TileImg from './tile-img.vue';\n\ninterface TilingLayerProps {\n documentId: string;\n pageIndex: number;\n scale?: number;\n}\n\nconst props = defineProps<TilingLayerProps>();\n\nconst { provides: tilingProvides } = useTilingCapability();\nconst documentState = useDocumentState(() => props.documentId);\nconst tiles = ref<Tile[]>([]);\n\nconst actualScale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nwatch(\n [tilingProvides, () => props.documentId, () => props.pageIndex],\n ([provides, docId, pageIdx], _, onCleanup) => {\n if (!provides) {\n tiles.value = [];\n return;\n }\n\n const unsubscribe = provides.onTileRendering((event) => {\n if (event.documentId === docId) {\n tiles.value = event.tiles[pageIdx] ?? [];\n }\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n);\n</script>\n\n<template>\n <div v-bind=\"$attrs\">\n <TileImg\n v-for=\"tile in tiles\"\n :key=\"tile.id\"\n :documentId=\"documentId\"\n :pageIndex=\"pageIndex\"\n :tile=\"tile\"\n :scale=\"actualScale\"\n />\n </div>\n</template>\n"],"names":["_createElementBlock","_normalizeStyle","_openBlock","$attrs","_Fragment","_renderList","_createBlock","TileImg"],"mappings":";;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AAErE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;;;;;;;;;;ACSpF,UAAM,QAAQ;AAId,UAAM,EAAE,UAAU,iBAAA,IAAqB,oBAAA;AACvC,UAAM,MAAM,IAAA;AACZ,UAAM,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K,CAAb,SAAI;8BADbC,YAOEC,aAAA;AAAA,YALC,KAAK,KAAK;AAAA,YACV,YAAY,QAAA;AAAA,YACZ,WAAW,QAAA;AAAA,YACX;AAAA,YACA,OAAO,YAAA;AAAA,UAAA;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-tiling",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@embedpdf/models": "
|
|
38
|
+
"@embedpdf/models": "2.0.0-next.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/react": "^18.2.0",
|
|
42
42
|
"typescript": "^5.0.0",
|
|
43
|
-
"@embedpdf/core": "
|
|
43
|
+
"@embedpdf/core": "2.0.0-next.0",
|
|
44
44
|
"@embedpdf/build": "1.1.0",
|
|
45
|
-
"@embedpdf/plugin-
|
|
46
|
-
"@embedpdf/plugin-
|
|
47
|
-
"@embedpdf/plugin-
|
|
45
|
+
"@embedpdf/plugin-render": "2.0.0-next.0",
|
|
46
|
+
"@embedpdf/plugin-scroll": "2.0.0-next.0",
|
|
47
|
+
"@embedpdf/plugin-viewport": "2.0.0-next.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=16.8.0",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"preact": "^10.26.4",
|
|
53
53
|
"vue": ">=3.2.0",
|
|
54
54
|
"svelte": ">=5 <6",
|
|
55
|
-
"@embedpdf/plugin-render": "
|
|
56
|
-
"@embedpdf/plugin-
|
|
57
|
-
"@embedpdf/
|
|
58
|
-
"@embedpdf/
|
|
55
|
+
"@embedpdf/plugin-render": "2.0.0-next.0",
|
|
56
|
+
"@embedpdf/plugin-viewport": "2.0.0-next.0",
|
|
57
|
+
"@embedpdf/core": "2.0.0-next.0",
|
|
58
|
+
"@embedpdf/plugin-scroll": "2.0.0-next.0"
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
61
61
|
"dist",
|