@embedpdf/plugin-tiling 1.3.16 → 1.4.1

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.
@@ -0,0 +1 @@
1
+ export * from './tiling-layer';
@@ -0,0 +1,9 @@
1
+ import { Tile } from '../../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 '../../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('../../index.ts').TilingCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
@@ -0,0 +1,3 @@
1
+ export * from './hooks';
2
+ export * from './components';
3
+ export * from '../index.ts';
@@ -0,0 +1,10 @@
1
+ import { Tile } from '../../lib/index.ts';
2
+ interface TileImgProps {
3
+ pageIndex: number;
4
+ tile: Tile;
5
+ dpr: number;
6
+ scale: number;
7
+ }
8
+ declare const TileImg: import('svelte', { with: { "resolution-mode": "import" } }).Component<TileImgProps, {}, "">;
9
+ type TileImg = ReturnType<typeof TileImg>;
10
+ export default TileImg;
@@ -0,0 +1,9 @@
1
+ import { HTMLAttributes } from 'svelte/elements';
2
+ type TilingLayoutProps = HTMLAttributes<HTMLDivElement> & {
3
+ pageIndex: number;
4
+ scale: number;
5
+ class?: string;
6
+ };
7
+ declare const TilingLayer: import('svelte', { with: { "resolution-mode": "import" } }).Component<TilingLayoutProps, {}, "">;
8
+ type TilingLayer = ReturnType<typeof TilingLayer>;
9
+ export default TilingLayer;
@@ -0,0 +1,2 @@
1
+ export { default as TileImg } from './TileImg.svelte';
2
+ export { default as TilingLayer } from './TilingLayer.svelte';
@@ -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,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),require("svelte/internal/disclose-version");const e=require("svelte/internal/client"),t=require("@embedpdf/plugin-tiling"),r=require("@embedpdf/core/svelte"),i=require("@embedpdf/models"),n=require("svelte");function l(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const s=l(e),o=()=>r.useCapability(t.TilingPlugin.id);var c=s.from_html('<img alt=""/>');function a(e,t){s.push(t,!0);const r=o();let l=s.state(""),a=null;const d=s.derived((()=>t.tile.id)),g=s.derived((()=>t.tile.srcScale)),p=s.derived((()=>t.tile.screenRect)),u=s.derived((()=>t.scale/s.get(g)));s.user_effect((()=>{var e;s.get(d);const o=t.pageIndex;if(a)return;if(!r)return;const c=n.untrack((()=>{return e=t.tile,{...e,pageRect:{origin:{x:e.pageRect.origin.x,y:e.pageRect.origin.y},size:{width:e.pageRect.size.width,height:e.pageRect.size.height}},screenRect:{origin:{x:e.screenRect.origin.x,y:e.screenRect.origin.y},size:{width:e.screenRect.size.width,height:e.screenRect.size.height}}};var e})),g=null==(e=r.provides)?void 0:e.renderTile({pageIndex:o,tile:c,dpr:t.dpr});return null==g||g.wait((e=>{const t=URL.createObjectURL(e);a=t,s.set(l,t,!0)}),i.ignore),()=>{a?(URL.revokeObjectURL(a),a=null):null==g||g.abort({code:i.PdfErrorCode.Cancelled,message:"canceled render task"})}}));const f=()=>{a&&(URL.revokeObjectURL(a),a=null)};var v=s.comment(),h=s.first_child(v),b=e=>{var t=c();let r;s.template_effect((e=>{s.set_attribute(t,"src",s.get(l)),r=s.set_style(t,"",r,e)}),[()=>({position:"absolute",left:s.get(p).origin.x*s.get(u)+"px",top:s.get(p).origin.y*s.get(u)+"px",width:s.get(p).size.width*s.get(u)+"px",height:s.get(p).size.height*s.get(u)+"px",display:"block"})]),s.event("load",t,f),s.replay_events(t),s.append(e,t)};s.if(h,(e=>{s.get(l)&&e(b)})),s.append(e,v),s.pop()}var d=s.from_html("<div></div>");exports.TileImg=a,exports.TilingLayer=function(e,t){s.push(t,!0);let i=s.rest_props(t,["$$slots","$$events","$$legacy","pageIndex","scale","class"]);const n=o();let l=s.state(s.proxy([]));const c=r.useCoreState();s.user_effect((()=>{if(n.provides)return n.provides.onTileRendering((e=>{s.set(l,e[t.pageIndex]??[],!0)}))}));var g=d();s.attribute_effect(g,(()=>({class:t.class,...i}))),s.each(g,21,(()=>s.get(l)),(e=>{var t,r;return`${null==(r=null==(t=c.coreState)?void 0:t.document)?void 0:r.id}-${e.id}`}),((e,r)=>{a(e,{get pageIndex(){return t.pageIndex},get tile(){return s.get(r)},dpr:window.devicePixelRatio,get scale(){return t.scale}})})),s.reset(g),s.append(e,g),s.pop()},exports.useTilingCapability=o,exports.useTilingPlugin=()=>r.usePlugin(t.TilingPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","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 (!tilingCapability) return;\n\n // Clone to avoid reactive proxies that Web Workers cannot clone\n const plainTile = untrack(() => createPlainTile(tile));\n const task = tilingCapability.provides?.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 { useCoreState } 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 pageIndex: number;\n scale: number;\n class?: string;\n };\n\n let { pageIndex, scale, class: propsClass, ...restProps }: TilingLayoutProps = $props();\n\n const tilingCapability = useTilingCapability();\n let tiles = $state<Tile[]>([]);\n\n const core = useCoreState();\n\n $effect(() => {\n if (!tilingCapability.provides) return;\n return tilingCapability.provides.onTileRendering((tilesMap) => {\n tiles = tilesMap[pageIndex] ?? [];\n });\n });\n</script>\n\n<div class={propsClass} {...restProps}>\n {#each tiles as tile (`${core.coreState?.document?.id}-${tile.id}`)}\n <TileImg {pageIndex} {tile} dpr={window.devicePixelRatio} {scale} />\n {/each}\n</div>\n"],"names":["useTilingCapability","useCapability","TilingPlugin","id","tilingCapability","url","urlRef","tileId","tileSrcScale","srcScale","tileScreenRect","screenRect","relativeScale","$","user_effect","_pageIndex","$$props","pageIndex","plainTile","untrack","createPlainTile","t","tile","pageRect","origin","x","y","size","width","height","task","_a","provides","renderTile","dpr","wait","blob","objectUrl","URL","createObjectURL","$__namespace","set","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","handleImageLoad","left","get","top","consequent","restProps","rest_props","tiles","state","proxy","core","useCoreState","onTileRendering","tilesMap","each","div","_b","coreState","document","window","devicePixelRatio","usePlugin"],"mappings":"wjBAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,oECU1E,MAAAC,EAAmBJ,IACrB,IAAAK,UAAqB,IAErBC,EAAwB,KAGtB,MAAAC,wBAAuBJ,KACvBK,wBAA6BC,WAC7BC,wBAA+BC,aAC/BC,+BAAiCJ,KAevCK,EAAAC,aAAc,iBAEIP,SACVQ,EAAUC,EAAAC,aAGZX,EAAM,WAELF,EAAgB,aAGfc,EAAYC,EAAAA,SAAO,KAAOC,OAxBTC,EAwBwBL,EAAAM,KAxBjB,IAC3BD,EACHE,SAAQ,CACNC,QAAUC,EAAGJ,EAAEE,SAASC,OAAOC,EAAGC,EAAGL,EAAEE,SAASC,OAAOE,GACvDC,MAAQC,MAAOP,EAAEE,SAASI,KAAKC,MAAOC,OAAQR,EAAEE,SAASI,KAAKE,SAEhElB,WAAU,CACRa,QAAUC,EAAGJ,EAAEV,WAAWa,OAAOC,EAAGC,EAAGL,EAAEV,WAAWa,OAAOE,GAC3DC,KAAI,CAAIC,MAAOP,EAAEV,WAAWgB,KAAKC,MAAOC,OAAQR,EAAEV,WAAWgB,KAAKE,cAR7CR,CAwBwB,IACzCS,EAAO,OAAAC,EAAA3B,EAAiB4B,eAAjB,EAAAD,EAA2BE,WAAU,CAChDhB,UAAWF,EACXO,KAAMJ,EACNgB,IAAGlB,EAAAkB,MAQQ,OANP,MAAAJ,GAAAA,EAA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';
2
+ export * from './hooks';
3
+ export * from '../lib/index.ts';
@@ -0,0 +1,150 @@
1
+ import "svelte/internal/disclose-version";
2
+ import * as $ from "svelte/internal/client";
3
+ import { TilingPlugin } from "@embedpdf/plugin-tiling";
4
+ export * from "@embedpdf/plugin-tiling";
5
+ import { useCapability, usePlugin, useCoreState } from "@embedpdf/core/svelte";
6
+ import { ignore, PdfErrorCode } from "@embedpdf/models";
7
+ import { untrack } from "svelte";
8
+ const useTilingPlugin = () => usePlugin(TilingPlugin.id);
9
+ const useTilingCapability = () => useCapability(TilingPlugin.id);
10
+ var root_1 = $.from_html(`<img alt=""/>`);
11
+ function TileImg($$anchor, $$props) {
12
+ $.push($$props, true);
13
+ const tilingCapability = useTilingCapability();
14
+ let url = $.state("");
15
+ let urlRef = null;
16
+ const tileId = $.derived(() => $$props.tile.id);
17
+ const tileSrcScale = $.derived(() => $$props.tile.srcScale);
18
+ const tileScreenRect = $.derived(() => $$props.tile.screenRect);
19
+ const relativeScale = $.derived(() => $$props.scale / $.get(tileSrcScale));
20
+ const createPlainTile = (t) => ({
21
+ ...t,
22
+ pageRect: {
23
+ origin: { x: t.pageRect.origin.x, y: t.pageRect.origin.y },
24
+ size: { width: t.pageRect.size.width, height: t.pageRect.size.height }
25
+ },
26
+ screenRect: {
27
+ origin: { x: t.screenRect.origin.x, y: t.screenRect.origin.y },
28
+ size: {
29
+ width: t.screenRect.size.width,
30
+ height: t.screenRect.size.height
31
+ }
32
+ }
33
+ });
34
+ $.user_effect(() => {
35
+ var _a;
36
+ $.get(tileId);
37
+ const _pageIndex = $$props.pageIndex;
38
+ if (urlRef) return;
39
+ if (!tilingCapability) return;
40
+ const plainTile = untrack(() => createPlainTile($$props.tile));
41
+ const task = (_a = tilingCapability.provides) == null ? void 0 : _a.renderTile({ pageIndex: _pageIndex, tile: plainTile, dpr: $$props.dpr });
42
+ task == null ? void 0 : task.wait(
43
+ (blob) => {
44
+ const objectUrl = URL.createObjectURL(blob);
45
+ urlRef = objectUrl;
46
+ $.set(url, objectUrl, true);
47
+ },
48
+ ignore
49
+ );
50
+ return () => {
51
+ if (urlRef) {
52
+ URL.revokeObjectURL(urlRef);
53
+ urlRef = null;
54
+ } else {
55
+ task == null ? void 0 : task.abort({
56
+ code: PdfErrorCode.Cancelled,
57
+ message: "canceled render task"
58
+ });
59
+ }
60
+ };
61
+ });
62
+ const handleImageLoad = () => {
63
+ if (urlRef) {
64
+ URL.revokeObjectURL(urlRef);
65
+ urlRef = null;
66
+ }
67
+ };
68
+ var fragment = $.comment();
69
+ var node = $.first_child(fragment);
70
+ {
71
+ var consequent = ($$anchor2) => {
72
+ var img = root_1();
73
+ let styles;
74
+ $.template_effect(
75
+ ($0) => {
76
+ $.set_attribute(img, "src", $.get(url));
77
+ styles = $.set_style(img, "", styles, $0);
78
+ },
79
+ [
80
+ () => ({
81
+ position: "absolute",
82
+ left: `${$.get(tileScreenRect).origin.x * $.get(relativeScale)}px`,
83
+ top: `${$.get(tileScreenRect).origin.y * $.get(relativeScale)}px`,
84
+ width: `${$.get(tileScreenRect).size.width * $.get(relativeScale)}px`,
85
+ height: `${$.get(tileScreenRect).size.height * $.get(relativeScale)}px`,
86
+ display: "block"
87
+ })
88
+ ]
89
+ );
90
+ $.event("load", img, handleImageLoad);
91
+ $.replay_events(img);
92
+ $.append($$anchor2, img);
93
+ };
94
+ $.if(node, ($$render) => {
95
+ if ($.get(url)) $$render(consequent);
96
+ });
97
+ }
98
+ $.append($$anchor, fragment);
99
+ $.pop();
100
+ }
101
+ var root = $.from_html(`<div></div>`);
102
+ function TilingLayer($$anchor, $$props) {
103
+ $.push($$props, true);
104
+ let restProps = $.rest_props($$props, [
105
+ "$$slots",
106
+ "$$events",
107
+ "$$legacy",
108
+ "pageIndex",
109
+ "scale",
110
+ "class"
111
+ ]);
112
+ const tilingCapability = useTilingCapability();
113
+ let tiles = $.state($.proxy([]));
114
+ const core = useCoreState();
115
+ $.user_effect(() => {
116
+ if (!tilingCapability.provides) return;
117
+ return tilingCapability.provides.onTileRendering((tilesMap) => {
118
+ $.set(tiles, tilesMap[$$props.pageIndex] ?? [], true);
119
+ });
120
+ });
121
+ var div = root();
122
+ $.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) => {
127
+ TileImg($$anchor2, {
128
+ get pageIndex() {
129
+ return $$props.pageIndex;
130
+ },
131
+ get tile() {
132
+ return $.get(tile);
133
+ },
134
+ dpr: window.devicePixelRatio,
135
+ get scale() {
136
+ return $$props.scale;
137
+ }
138
+ });
139
+ });
140
+ $.reset(div);
141
+ $.append($$anchor, div);
142
+ $.pop();
143
+ }
144
+ export {
145
+ TileImg,
146
+ TilingLayer,
147
+ useTilingCapability,
148
+ useTilingPlugin
149
+ };
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 (!tilingCapability) return;\n\n // Clone to avoid reactive proxies that Web Workers cannot clone\n const plainTile = untrack(() => createPlainTile(tile));\n const task = tilingCapability.provides?.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 { useCoreState } 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 pageIndex: number;\n scale: number;\n class?: string;\n };\n\n let { pageIndex, scale, class: propsClass, ...restProps }: TilingLayoutProps = $props();\n\n const tilingCapability = useTilingCapability();\n let tiles = $state<Tile[]>([]);\n\n const core = useCoreState();\n\n $effect(() => {\n if (!tilingCapability.provides) return;\n return tilingCapability.provides.onTileRendering((tilesMap) => {\n tiles = tilesMap[pageIndex] ?? [];\n });\n });\n</script>\n\n<div class={propsClass} {...restProps}>\n {#each tiles as tile (`${core.coreState?.document?.id}-${tile.id}`)}\n <TileImg {pageIndex} {tile} dpr={window.devicePixelRatio} {scale} />\n {/each}\n</div>\n"],"names":[],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;oCCJpF;;AAcQ,QAAA,mBAAmB,oBAAmB;AACxC,MAAA,cAAqB,EAAE;AAEvB,MAAA,SAAwB;AAGtB,QAAA,sCAAuB,EAAE;AACzB,QAAA,4CAA6B,QAAQ;AACrC,QAAA,8CAA+B,UAAU;AACzC,QAAA,sDAAiC,YAAY,CAAA;AAE7C,QAAA,mBAAmB,OAAO;AAAA,OAC3B;AAAA,IACH,UAAQ;AAAA,MACN,UAAU,GAAG,EAAE,SAAS,OAAO,GAAG,GAAG,EAAE,SAAS,OAAO,EAAC;AAAA,MACxD,QAAQ,OAAO,EAAE,SAAS,KAAK,OAAO,QAAQ,EAAE,SAAS,KAAK,OAAM;AAAA;IAEtE,YAAU;AAAA,MACR,UAAU,GAAG,EAAE,WAAW,OAAO,GAAG,GAAG,EAAE,WAAW,OAAO,EAAC;AAAA,MAC5D,MAAI;AAAA,QAAI,OAAO,EAAE,WAAW,KAAK;AAAA,QAAO,QAAQ,EAAE,WAAW,KAAK;AAAA;;;AAKtE,IAAA,YAAc,M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;AACP,QAAA,CAAA,iBAAiB,SAAQ;AACvB,WAAA,iBAAiB,SAAS,gBAAe,CAAE,aAAa;AAC7D,QAAA,IAAA,OAAQ,SAAQ,QAAA,SAAA,KAAA,CAAA,GAAA,IAAA;AAAA,KACjB;AAAA,GACF;;4DAGyB,UAAS,EAAA;AAC5B,IAAA,KAAA,KAAA,IAAA,MAAA,EAAA,IAAA,KAAK,GAAI,CAAA,SAAS;;AAAA,eAAA,gBAAK,cAAL,mBAAgB,aAAhB,mBAA0B,EAAE,IAAI,KAAK,EAAE;AAAA,iBAAhD,SAAI;;;;;;;;MACe,KAAA,OAAO;AAAA;;;;;;;;AAJ5C;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-tiling",
3
- "version": "1.3.16",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -26,29 +26,36 @@
26
26
  "types": "./dist/vue/index.d.ts",
27
27
  "import": "./dist/vue/index.js",
28
28
  "require": "./dist/vue/index.cjs"
29
+ },
30
+ "./svelte": {
31
+ "types": "./dist/svelte/index.d.ts",
32
+ "svelte": "./dist/svelte/index.js",
33
+ "import": "./dist/svelte/index.js",
34
+ "require": "./dist/svelte/index.cjs"
29
35
  }
30
36
  },
31
37
  "dependencies": {
32
- "@embedpdf/models": "1.3.16"
38
+ "@embedpdf/models": "1.4.1"
33
39
  },
34
40
  "devDependencies": {
35
41
  "@types/react": "^18.2.0",
36
42
  "typescript": "^5.0.0",
37
- "@embedpdf/core": "1.3.16",
38
- "@embedpdf/build": "1.0.1",
39
- "@embedpdf/plugin-render": "1.3.16",
40
- "@embedpdf/plugin-scroll": "1.3.16",
41
- "@embedpdf/plugin-viewport": "1.3.16"
43
+ "@embedpdf/core": "1.4.1",
44
+ "@embedpdf/build": "1.1.0",
45
+ "@embedpdf/plugin-scroll": "1.4.1",
46
+ "@embedpdf/plugin-viewport": "1.4.1",
47
+ "@embedpdf/plugin-render": "1.4.1"
42
48
  },
43
49
  "peerDependencies": {
44
50
  "react": ">=16.8.0",
45
51
  "react-dom": ">=16.8.0",
46
52
  "preact": "^10.26.4",
47
53
  "vue": ">=3.2.0",
48
- "@embedpdf/core": "1.3.16",
49
- "@embedpdf/plugin-scroll": "1.3.16",
50
- "@embedpdf/plugin-render": "1.3.16",
51
- "@embedpdf/plugin-viewport": "1.3.16"
54
+ "svelte": ">=5 <6",
55
+ "@embedpdf/plugin-render": "1.4.1",
56
+ "@embedpdf/plugin-scroll": "1.4.1",
57
+ "@embedpdf/plugin-viewport": "1.4.1",
58
+ "@embedpdf/core": "1.4.1"
52
59
  },
53
60
  "files": [
54
61
  "dist",
@@ -71,7 +78,8 @@
71
78
  "build:react": "vite build --mode react",
72
79
  "build:preact": "vite build --mode preact",
73
80
  "build:vue": "vite build --mode vue",
74
- "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
81
+ "build:svelte": "vite build --mode svelte",
82
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
75
83
  "clean": "rimraf dist",
76
84
  "lint": "eslint src --color",
77
85
  "lint:fix": "eslint src --color --fix"