@embedpdf/plugin-scroll 1.3.16 → 1.4.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.
@@ -0,0 +1 @@
1
+ export * from './scroller';
@@ -0,0 +1,14 @@
1
+ import { ReactNode, HTMLAttributes } from '../../react/adapter.ts';
2
+ import { PageLayout } from '../../index.ts';
3
+ import { PdfDocumentObject, Rotation } from '@embedpdf/models';
4
+ export interface RenderPageProps extends PageLayout {
5
+ rotation: Rotation;
6
+ scale: number;
7
+ document: PdfDocumentObject | null;
8
+ }
9
+ type ScrollerProps = HTMLAttributes<HTMLDivElement> & {
10
+ renderPage: (props: RenderPageProps) => ReactNode;
11
+ overlayElements?: ReactNode[];
12
+ };
13
+ export declare function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps): import("react/jsx-runtime").JSX.Element | null;
14
+ export {};
@@ -0,0 +1 @@
1
+ export * from './use-scroll';
@@ -0,0 +1,31 @@
1
+ import { ScrollCapability, ScrollPlugin } from '../../index.ts';
2
+ export declare const useScrollPlugin: () => {
3
+ plugin: ScrollPlugin | null;
4
+ isLoading: boolean;
5
+ ready: Promise<void>;
6
+ };
7
+ export declare const useScrollCapability: () => {
8
+ provides: Readonly<ScrollCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
12
+ interface UseScrollReturn {
13
+ provides: ScrollCapability | null;
14
+ state: {
15
+ currentPage: number;
16
+ totalPages: number;
17
+ };
18
+ readonly currentPage: number;
19
+ readonly totalPages: number;
20
+ readonly scrollToPage: ScrollCapability['scrollToPage'] | undefined;
21
+ readonly scrollToNextPage: ScrollCapability['scrollToNextPage'] | undefined;
22
+ readonly scrollToPreviousPage: ScrollCapability['scrollToPreviousPage'] | undefined;
23
+ readonly getMetrics: ScrollCapability['getMetrics'] | undefined;
24
+ readonly onPageChange: ScrollCapability['onPageChange'] | undefined;
25
+ readonly onScroll: ScrollCapability['onScroll'] | undefined;
26
+ readonly onLayoutChange: ScrollCapability['onLayoutChange'] | undefined;
27
+ readonly getCurrentPage: ScrollCapability['getCurrentPage'] | undefined;
28
+ readonly getTotalPages: ScrollCapability['getTotalPages'] | undefined;
29
+ }
30
+ export declare const useScroll: () => UseScrollReturn;
31
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './hooks';
2
+ export * from './components';
3
+ export * from '../index.ts';
@@ -0,0 +1,16 @@
1
+ import { HTMLAttributes } from 'svelte/elements';
2
+ import { PageLayout } from '../../lib/index.ts';
3
+ import { PdfDocumentObject, Rotation } from '@embedpdf/models';
4
+ import { Snippet } from 'svelte';
5
+ export interface RenderPageProps extends PageLayout {
6
+ rotation: Rotation;
7
+ scale: number;
8
+ document: PdfDocumentObject | null;
9
+ }
10
+ type ScrollerProps = HTMLAttributes<HTMLDivElement> & {
11
+ RenderPageSnippet: Snippet<RenderPageProps>;
12
+ overlayElements?: Snippet[];
13
+ };
14
+ declare const Scroller: import('svelte', { with: { "resolution-mode": "import" } }).Component<ScrollerProps, {}, "">;
15
+ type Scroller = ReturnType<typeof Scroller>;
16
+ export default Scroller;
@@ -0,0 +1 @@
1
+ export { default as Scroller } from './Scroller.svelte';
@@ -0,0 +1 @@
1
+ export * from './use-scroll.svelte';
@@ -0,0 +1,20 @@
1
+ import { ScrollCapability, ScrollPlugin } from '../../lib/index.ts';
2
+ export declare const useScrollPlugin: () => {
3
+ plugin: ScrollPlugin | null;
4
+ isLoading: boolean;
5
+ ready: Promise<void>;
6
+ };
7
+ export declare const useScrollCapability: () => {
8
+ provides: Readonly<ScrollCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
12
+ interface UseScrollReturn {
13
+ provides: ScrollCapability | null;
14
+ state: {
15
+ currentPage: number;
16
+ totalPages: number;
17
+ };
18
+ }
19
+ export declare const useScroll: () => UseScrollReturn;
20
+ export {};
@@ -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-scroll"),r=require("@embedpdf/core/svelte");function l(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const l=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const i=l(e),a=()=>r.usePlugin(t.ScrollPlugin.id),o=()=>r.useCapability(t.ScrollPlugin.id);var n=i.from_html("<div><!></div>"),g=i.from_html("<div></div>"),s=i.from_html("<div><div></div> <div></div> <div></div> <!></div>");exports.Scroller=function(e,l){i.push(l,!0);const o=i.derived(a),d=i.derived((()=>i.get(o).plugin)),p=i.derived(r.useRegistry),c=i.derived((()=>i.get(p).registry));let u=i.derived(r.useCoreState),v=i.derived((()=>i.get(u).coreState)),f=i.derived((()=>{var e;return(null==(e=i.get(d))?void 0:e.getScrollerLayout())??null})),y=i.rest_props(l,["$$slots","$$events","$$legacy","RenderPageSnippet","overlayElements"]);i.user_effect((()=>{if(i.get(d))return i.get(d).onScrollerData((e=>i.set(f,e)))})),i.user_effect((()=>{i.get(d)&&i.get(d).setLayoutReady()}));var S=i.comment(),h=i.first_child(S),m=e=>{var r=s();i.attribute_effect(r,(e=>({...y,[i.STYLE]:e})),[()=>({width:`${i.get(f).totalWidth}px`,height:`${i.get(f).totalHeight}px`,position:"relative","box-sizing":"border-box",margin:"0 auto",display:i.get(f).strategy===t.ScrollStrategy.Horizontal?"flex":null,"flex-direction":i.get(f).strategy===t.ScrollStrategy.Horizontal?"row":null})]);var a=i.child(r);let o;var d=i.sibling(a,2);let p;i.each(d,21,(()=>i.get(f).items),(e=>e.pageNumbers[0]),((e,t)=>{var r=g();let a;i.each(r,21,(()=>i.get(t).pageLayouts),(e=>e.pageNumber),((e,t)=>{var r=n();let a;var o=i.child(r);{let e=i.derived((()=>({...i.get(t),rotation:i.get(v).rotation,scale:i.get(v).scale,document:i.get(v).document})));i.snippet(o,(()=>l.RenderPageSnippet??i.noop),(()=>i.get(e)))}i.reset(r),i.template_effect((e=>a=i.set_style(r,"",a,e)),[()=>({width:`${i.get(t).rotatedWidth}px`,height:`${i.get(t).rotatedHeight}px`})]),i.append(e,r)})),i.reset(r),i.template_effect((e=>a=i.set_style(r,"",a,e)),[()=>({display:"flex","justify-content":"center",gap:`${i.get(f).pageGap}px`})]),i.append(e,r)})),i.reset(d);var c=i.sibling(d,2);let u;var S=i.sibling(c,2),h=e=>{var t=i.comment(),r=i.first_child(t);i.each(r,17,(()=>l.overlayElements),i.index,((e,t)=>{var r=i.comment(),l=i.first_child(r);i.snippet(l,(()=>i.get(t)??i.noop)),i.append(e,r)})),i.append(e,t)};i.if(S,(e=>{l.overlayElements&&l.overlayElements.length>0&&e(h)})),i.reset(r),i.template_effect(((e,t,r)=>{o=i.set_style(a,"",o,e),p=i.set_style(d,"",p,t),u=i.set_style(c,"",u,r)}),[()=>({width:i.get(f).strategy===t.ScrollStrategy.Horizontal?`${i.get(f).startSpacing}px`:"100%",height:i.get(f).strategy===t.ScrollStrategy.Horizontal?"100%":`${i.get(f).startSpacing}px`,"flex-shrink":"0"}),()=>({gap:`${i.get(f).pageGap}px`,display:"flex","align-items":"center",position:"relative","box-sizing":"border-box","flex-direction":i.get(f).strategy===t.ScrollStrategy.Horizontal?"row":"column","min-width":i.get(f).strategy===t.ScrollStrategy.Horizontal?"100%":"fit-content"}),()=>({width:i.get(f).strategy===t.ScrollStrategy.Horizontal?`${i.get(f).endSpacing}px`:"100%",height:i.get(f).strategy===t.ScrollStrategy.Horizontal?"100%":`${i.get(f).endSpacing}px`,"flex-shrink":"0"})]),i.append(e,r)};i.if(h,(e=>{i.get(f)&&i.get(c)&&i.get(v)&&e(m)})),i.append(e,S),i.pop()},exports.useScroll=()=>{const e=i.derived(o),t=i.derived((()=>i.get(e).provides)),r=i.proxy({currentPage:1,totalPages:1});return i.user_effect((()=>{if(i.get(t))return i.get(t).onPageChange((({pageNumber:e,totalPages:t})=>{r.currentPage=e,r.totalPages=t}))})),{get provides(){return i.get(t)},get state(){return r}}},exports.useScrollCapability=o,exports.useScrollPlugin=a,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-scroll.svelte.ts","../../src/svelte/components/Scroller.svelte"],"sourcesContent":["import { ScrollCapability, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useCapability, usePlugin } from '@embedpdf/core/svelte';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseScrollReturn {\n provides: ScrollCapability | null;\n state: {\n currentPage: number;\n totalPages: number;\n };\n}\n\ninterface SimpleScrollState {\n currentPage: number;\n totalPages: number;\n}\n\nexport const useScroll = (): UseScrollReturn => {\n const { provides } = $derived(useScrollCapability());\n const state = $state<SimpleScrollState>({ currentPage: 1, totalPages: 1 });\n\n $effect(() => {\n if (!provides) return;\n return provides.onPageChange(({ pageNumber, totalPages }) => {\n state.currentPage = pageNumber;\n state.totalPages = totalPages;\n });\n });\n\n return {\n get provides() {\n return provides;\n },\n get state() {\n return state;\n },\n };\n};\n","<script lang=\"ts\">\n import { useScrollPlugin } from '../hooks';\n import type { HTMLAttributes } from 'svelte/elements';\n import { type PageLayout, type ScrollerLayout, ScrollStrategy } from '@embedpdf/plugin-scroll';\n import type { PdfDocumentObject, Rotation } from '@embedpdf/models';\n import { useRegistry, useCoreState } from '@embedpdf/core/svelte';\n import { type Snippet } from 'svelte';\n\n export interface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n }\n\n type ScrollerProps = HTMLAttributes<HTMLDivElement> & {\n RenderPageSnippet: Snippet<RenderPageProps>;\n overlayElements?: Snippet[];\n };\n\n const { plugin: scrollPlugin } = $derived(useScrollPlugin());\n const { registry } = $derived(useRegistry());\n let { coreState } = $derived(useCoreState());\n let scrollerLayout = $derived<ScrollerLayout | null>(scrollPlugin?.getScrollerLayout() ?? null);\n\n let { RenderPageSnippet, overlayElements, ...restProps }: ScrollerProps = $props();\n\n\n $effect(() => {\n if (!scrollPlugin) return;\n return scrollPlugin.onScrollerData((layout) => (scrollerLayout = layout));\n });\n\n $effect(() => {\n if (!scrollPlugin) return;\n scrollPlugin.setLayoutReady();\n });\n</script>\n\n{#if scrollerLayout && registry && coreState}\n <div\n {...restProps}\n style:width={`${scrollerLayout.totalWidth}px`}\n style:height={`${scrollerLayout.totalHeight}px`}\n style:position=\"relative\"\n style:box-sizing=\"border-box\"\n style:margin=\"0 auto\"\n style:display={scrollerLayout.strategy === ScrollStrategy.Horizontal ? 'flex' : null}\n style:flex-direction={scrollerLayout.strategy === ScrollStrategy.Horizontal ? 'row' : null}\n >\n <div\n style:width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? `${scrollerLayout.startSpacing}px`\n : '100%'}\n style:height={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : `${scrollerLayout.startSpacing}px`}\n style:flex-shrink=\"0\"\n ></div>\n <div\n style:gap={`${scrollerLayout.pageGap}px`}\n style:display=\"flex\"\n style:align-items=\"center\"\n style:position=\"relative\"\n style:box-sizing=\"border-box\"\n style:flex-direction={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? 'row'\n : 'column'}\n style:min-width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : 'fit-content'}\n >\n {#each scrollerLayout.items as item (item.pageNumbers[0])}\n <div\n style:display=\"flex\"\n style:justify-content=\"center\"\n style:gap={`${scrollerLayout.pageGap}px`}\n >\n {#each item.pageLayouts as layout (layout.pageNumber)}\n <div\n style:width={`${layout.rotatedWidth}px`}\n style:height={`${layout.rotatedHeight}px`}\n >\n {@render RenderPageSnippet?.({\n ...layout,\n rotation: coreState.rotation,\n scale: coreState.scale,\n document: coreState.document,\n })}\n </div>\n {/each}\n </div>\n {/each}\n </div>\n <div\n style:width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? `${scrollerLayout.endSpacing}px`\n : '100%'}\n style:height={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : `${scrollerLayout.endSpacing}px`}\n style:flex-shrink=\"0\"\n ></div>\n {#if overlayElements && overlayElements.length > 0}\n {#each overlayElements as OverLay}\n {@render OverLay?.()}\n {/each}\n {/if}\n </div>\n{/if}\n"],"names":["useScrollPlugin","usePlugin","ScrollPlugin","id","useScrollCapability","useCapability","scrollPlugin","plugin","useRegistry","registry","useCoreState","coreState","scrollerLayout","$","derived","get","getScrollerLayout","restProps","rest_props","$$props","user_effect","onScrollerData","layout","set","$__namespace","setLayoutReady","STYLE","$0","width","totalWidth","height","totalHeight","strategy","ScrollStrategy","Horizontal","items","item","pageNumbers","$$anchor","pageLayouts","pageNumber","rotation","scale","document","rotatedWidth","rotatedHeight","gap","pageGap","OverLay","noop","overlayElements","length","consequent","startSpacing","endSpacing","consequent_1","provides","state","currentPage","totalPages","onPageChange"],"mappings":"sgBAGaA,EAAwB,IAAAC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAA4B,IAAAC,gBAA4BH,EAAAA,aAAaC,uMCetCH,GAA1BM,0BAARC,qBACsBC,eAAtBC,0BAAAA,2BACqBC,gBAAvBC,0BAAAA,YACFC,EAAiDC,EAAAC,SAAA,WAAAD,OAAAA,OAAAA,EAAAA,EAAAE,IAAAT,SAAAO,EAAAA,EAAcG,sBAAuB,IAAA,IAE7CC,EAASJ,EAAAK,WAAAC,EAAA,yEAGtDN,EAAAO,aAAc,cACPd,GACEO,OAAAA,EAAAE,IAAAT,GAAae,gBAAgBC,GAAYT,EAAAU,IAAAX,EAAiBU,IAAM,IAGzET,EAAAO,aAAc,W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0C,sEA7DvB1C,IAAcC,EAAAE,IAAIN,IAAQI,EAAAE,IAAIJ,MAAS4C,EAAA,yBAF5C,2CDfgCnD,GAAtBoD,0BAAAA,WACFC,WAAoCC,YAAa,EAAGC,WAAY,WAEtE9C,EAAAO,2BACOoC,GACE3C,OAAAA,EAAAE,IAAAyC,GAASI,cAAa,EAAGpB,aAAYmB,iBAC1CF,EAAMC,YAAclB,EACpBiB,EAAME,WAAaA,CAAA,GACpB,KAIG,YAAAH,gBACKA,EACT,EACI,SAAAC,GACK,OAAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from '../lib/index.ts';
@@ -0,0 +1,173 @@
1
+ import "svelte/internal/disclose-version";
2
+ import * as $ from "svelte/internal/client";
3
+ import { ScrollPlugin, ScrollStrategy } from "@embedpdf/plugin-scroll";
4
+ export * from "@embedpdf/plugin-scroll";
5
+ import { usePlugin, useCapability, useRegistry, useCoreState } from "@embedpdf/core/svelte";
6
+ const useScrollPlugin = () => usePlugin(ScrollPlugin.id);
7
+ const useScrollCapability = () => useCapability(ScrollPlugin.id);
8
+ const useScroll = () => {
9
+ const $$d = $.derived(useScrollCapability), provides = $.derived(() => $.get($$d).provides);
10
+ const state = $.proxy({ currentPage: 1, totalPages: 1 });
11
+ $.user_effect(() => {
12
+ if (!$.get(provides)) return;
13
+ return $.get(provides).onPageChange(({ pageNumber, totalPages }) => {
14
+ state.currentPage = pageNumber;
15
+ state.totalPages = totalPages;
16
+ });
17
+ });
18
+ return {
19
+ get provides() {
20
+ return $.get(provides);
21
+ },
22
+ get state() {
23
+ return state;
24
+ }
25
+ };
26
+ };
27
+ var root_3 = $.from_html(`<div><!></div>`);
28
+ var root_2 = $.from_html(`<div></div>`);
29
+ var root_1 = $.from_html(`<div><div></div> <div></div> <div></div> <!></div>`);
30
+ function Scroller($$anchor, $$props) {
31
+ $.push($$props, true);
32
+ const $$d = $.derived(useScrollPlugin), scrollPlugin = $.derived(() => $.get($$d).plugin);
33
+ const $$d_1 = $.derived(useRegistry), registry = $.derived(() => $.get($$d_1).registry);
34
+ let $$d_2 = $.derived(useCoreState), coreState = $.derived(() => $.get($$d_2).coreState);
35
+ let scrollerLayout = $.derived(() => {
36
+ var _a;
37
+ return ((_a = $.get(scrollPlugin)) == null ? void 0 : _a.getScrollerLayout()) ?? null;
38
+ });
39
+ let restProps = $.rest_props($$props, [
40
+ "$$slots",
41
+ "$$events",
42
+ "$$legacy",
43
+ "RenderPageSnippet",
44
+ "overlayElements"
45
+ ]);
46
+ $.user_effect(() => {
47
+ if (!$.get(scrollPlugin)) return;
48
+ return $.get(scrollPlugin).onScrollerData((layout) => $.set(scrollerLayout, layout));
49
+ });
50
+ $.user_effect(() => {
51
+ if (!$.get(scrollPlugin)) return;
52
+ $.get(scrollPlugin).setLayoutReady();
53
+ });
54
+ var fragment = $.comment();
55
+ var node = $.first_child(fragment);
56
+ {
57
+ var consequent_1 = ($$anchor2) => {
58
+ var div = root_1();
59
+ $.attribute_effect(div, ($0) => ({ ...restProps, [$.STYLE]: $0 }), [
60
+ () => ({
61
+ width: `${$.get(scrollerLayout).totalWidth}px`,
62
+ height: `${$.get(scrollerLayout).totalHeight}px`,
63
+ position: "relative",
64
+ "box-sizing": "border-box",
65
+ margin: "0 auto",
66
+ display: $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "flex" : null,
67
+ "flex-direction": $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "row" : null
68
+ })
69
+ ]);
70
+ var div_1 = $.child(div);
71
+ let styles;
72
+ var div_2 = $.sibling(div_1, 2);
73
+ let styles_1;
74
+ $.each(div_2, 21, () => $.get(scrollerLayout).items, (item) => item.pageNumbers[0], ($$anchor3, item) => {
75
+ var div_3 = root_2();
76
+ let styles_2;
77
+ $.each(div_3, 21, () => $.get(item).pageLayouts, (layout) => layout.pageNumber, ($$anchor4, layout) => {
78
+ var div_4 = root_3();
79
+ let styles_3;
80
+ var node_1 = $.child(div_4);
81
+ {
82
+ let $0 = $.derived(() => ({
83
+ ...$.get(layout),
84
+ rotation: $.get(coreState).rotation,
85
+ scale: $.get(coreState).scale,
86
+ document: $.get(coreState).document
87
+ }));
88
+ $.snippet(node_1, () => $$props.RenderPageSnippet ?? $.noop, () => $.get($0));
89
+ }
90
+ $.reset(div_4);
91
+ $.template_effect(($0) => styles_3 = $.set_style(div_4, "", styles_3, $0), [
92
+ () => ({
93
+ width: `${$.get(layout).rotatedWidth}px`,
94
+ height: `${$.get(layout).rotatedHeight}px`
95
+ })
96
+ ]);
97
+ $.append($$anchor4, div_4);
98
+ });
99
+ $.reset(div_3);
100
+ $.template_effect(($0) => styles_2 = $.set_style(div_3, "", styles_2, $0), [
101
+ () => ({
102
+ display: "flex",
103
+ "justify-content": "center",
104
+ gap: `${$.get(scrollerLayout).pageGap}px`
105
+ })
106
+ ]);
107
+ $.append($$anchor3, div_3);
108
+ });
109
+ $.reset(div_2);
110
+ var div_5 = $.sibling(div_2, 2);
111
+ let styles_4;
112
+ var node_2 = $.sibling(div_5, 2);
113
+ {
114
+ var consequent = ($$anchor3) => {
115
+ var fragment_1 = $.comment();
116
+ var node_3 = $.first_child(fragment_1);
117
+ $.each(node_3, 17, () => $$props.overlayElements, $.index, ($$anchor4, OverLay) => {
118
+ var fragment_2 = $.comment();
119
+ var node_4 = $.first_child(fragment_2);
120
+ $.snippet(node_4, () => $.get(OverLay) ?? $.noop);
121
+ $.append($$anchor4, fragment_2);
122
+ });
123
+ $.append($$anchor3, fragment_1);
124
+ };
125
+ $.if(node_2, ($$render) => {
126
+ if ($$props.overlayElements && $$props.overlayElements.length > 0) $$render(consequent);
127
+ });
128
+ }
129
+ $.reset(div);
130
+ $.template_effect(
131
+ ($0, $1, $2) => {
132
+ styles = $.set_style(div_1, "", styles, $0);
133
+ styles_1 = $.set_style(div_2, "", styles_1, $1);
134
+ styles_4 = $.set_style(div_5, "", styles_4, $2);
135
+ },
136
+ [
137
+ () => ({
138
+ width: $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? `${$.get(scrollerLayout).startSpacing}px` : "100%",
139
+ height: $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "100%" : `${$.get(scrollerLayout).startSpacing}px`,
140
+ "flex-shrink": "0"
141
+ }),
142
+ () => ({
143
+ gap: `${$.get(scrollerLayout).pageGap}px`,
144
+ display: "flex",
145
+ "align-items": "center",
146
+ position: "relative",
147
+ "box-sizing": "border-box",
148
+ "flex-direction": $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "row" : "column",
149
+ "min-width": $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "100%" : "fit-content"
150
+ }),
151
+ () => ({
152
+ width: $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? `${$.get(scrollerLayout).endSpacing}px` : "100%",
153
+ height: $.get(scrollerLayout).strategy === ScrollStrategy.Horizontal ? "100%" : `${$.get(scrollerLayout).endSpacing}px`,
154
+ "flex-shrink": "0"
155
+ })
156
+ ]
157
+ );
158
+ $.append($$anchor2, div);
159
+ };
160
+ $.if(node, ($$render) => {
161
+ if ($.get(scrollerLayout) && $.get(registry) && $.get(coreState)) $$render(consequent_1);
162
+ });
163
+ }
164
+ $.append($$anchor, fragment);
165
+ $.pop();
166
+ }
167
+ export {
168
+ Scroller,
169
+ useScroll,
170
+ useScrollCapability,
171
+ useScrollPlugin
172
+ };
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-scroll.svelte.ts","../../src/svelte/components/Scroller.svelte"],"sourcesContent":["import { ScrollCapability, ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useCapability, usePlugin } from '@embedpdf/core/svelte';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseScrollReturn {\n provides: ScrollCapability | null;\n state: {\n currentPage: number;\n totalPages: number;\n };\n}\n\ninterface SimpleScrollState {\n currentPage: number;\n totalPages: number;\n}\n\nexport const useScroll = (): UseScrollReturn => {\n const { provides } = $derived(useScrollCapability());\n const state = $state<SimpleScrollState>({ currentPage: 1, totalPages: 1 });\n\n $effect(() => {\n if (!provides) return;\n return provides.onPageChange(({ pageNumber, totalPages }) => {\n state.currentPage = pageNumber;\n state.totalPages = totalPages;\n });\n });\n\n return {\n get provides() {\n return provides;\n },\n get state() {\n return state;\n },\n };\n};\n","<script lang=\"ts\">\n import { useScrollPlugin } from '../hooks';\n import type { HTMLAttributes } from 'svelte/elements';\n import { type PageLayout, type ScrollerLayout, ScrollStrategy } from '@embedpdf/plugin-scroll';\n import type { PdfDocumentObject, Rotation } from '@embedpdf/models';\n import { useRegistry, useCoreState } from '@embedpdf/core/svelte';\n import { type Snippet } from 'svelte';\n\n export interface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n }\n\n type ScrollerProps = HTMLAttributes<HTMLDivElement> & {\n RenderPageSnippet: Snippet<RenderPageProps>;\n overlayElements?: Snippet[];\n };\n\n const { plugin: scrollPlugin } = $derived(useScrollPlugin());\n const { registry } = $derived(useRegistry());\n let { coreState } = $derived(useCoreState());\n let scrollerLayout = $derived<ScrollerLayout | null>(scrollPlugin?.getScrollerLayout() ?? null);\n\n let { RenderPageSnippet, overlayElements, ...restProps }: ScrollerProps = $props();\n\n\n $effect(() => {\n if (!scrollPlugin) return;\n return scrollPlugin.onScrollerData((layout) => (scrollerLayout = layout));\n });\n\n $effect(() => {\n if (!scrollPlugin) return;\n scrollPlugin.setLayoutReady();\n });\n</script>\n\n{#if scrollerLayout && registry && coreState}\n <div\n {...restProps}\n style:width={`${scrollerLayout.totalWidth}px`}\n style:height={`${scrollerLayout.totalHeight}px`}\n style:position=\"relative\"\n style:box-sizing=\"border-box\"\n style:margin=\"0 auto\"\n style:display={scrollerLayout.strategy === ScrollStrategy.Horizontal ? 'flex' : null}\n style:flex-direction={scrollerLayout.strategy === ScrollStrategy.Horizontal ? 'row' : null}\n >\n <div\n style:width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? `${scrollerLayout.startSpacing}px`\n : '100%'}\n style:height={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : `${scrollerLayout.startSpacing}px`}\n style:flex-shrink=\"0\"\n ></div>\n <div\n style:gap={`${scrollerLayout.pageGap}px`}\n style:display=\"flex\"\n style:align-items=\"center\"\n style:position=\"relative\"\n style:box-sizing=\"border-box\"\n style:flex-direction={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? 'row'\n : 'column'}\n style:min-width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : 'fit-content'}\n >\n {#each scrollerLayout.items as item (item.pageNumbers[0])}\n <div\n style:display=\"flex\"\n style:justify-content=\"center\"\n style:gap={`${scrollerLayout.pageGap}px`}\n >\n {#each item.pageLayouts as layout (layout.pageNumber)}\n <div\n style:width={`${layout.rotatedWidth}px`}\n style:height={`${layout.rotatedHeight}px`}\n >\n {@render RenderPageSnippet?.({\n ...layout,\n rotation: coreState.rotation,\n scale: coreState.scale,\n document: coreState.document,\n })}\n </div>\n {/each}\n </div>\n {/each}\n </div>\n <div\n style:width={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? `${scrollerLayout.endSpacing}px`\n : '100%'}\n style:height={scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? '100%'\n : `${scrollerLayout.endSpacing}px`}\n style:flex-shrink=\"0\"\n ></div>\n {#if overlayElements && overlayElements.length > 0}\n {#each overlayElements as OverLay}\n {@render OverLay?.()}\n {/each}\n {/if}\n </div>\n{/if}\n"],"names":["$$anchor"],"mappings":";;;;;AAGa,MAAA,kBAAwB,MAAA,UAAwB,aAAa,EAAE;AAC/D,MAAA,sBAA4B,MAAA,cAA4B,aAAa,EAAE;AAgBvE,MAAA,kBAAmC;wBAChB,sBAAtB,sCAAA,Q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js",
@@ -26,25 +26,32 @@
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.0"
33
39
  },
34
40
  "devDependencies": {
35
41
  "@types/react": "^18.2.0",
36
42
  "typescript": "^5.0.0",
37
- "@embedpdf/build": "1.0.1",
38
- "@embedpdf/plugin-viewport": "1.3.16",
39
- "@embedpdf/core": "1.3.16"
43
+ "@embedpdf/build": "1.1.0",
44
+ "@embedpdf/core": "1.4.0",
45
+ "@embedpdf/plugin-viewport": "1.4.0"
40
46
  },
41
47
  "peerDependencies": {
42
48
  "preact": "^10.26.4",
43
49
  "react": ">=16.8.0",
44
50
  "react-dom": ">=16.8.0",
45
51
  "vue": ">=3.2.0",
46
- "@embedpdf/core": "1.3.16",
47
- "@embedpdf/plugin-viewport": "1.3.16"
52
+ "svelte": ">=5 <6",
53
+ "@embedpdf/core": "1.4.0",
54
+ "@embedpdf/plugin-viewport": "1.4.0"
48
55
  },
49
56
  "files": [
50
57
  "dist",
@@ -67,7 +74,8 @@
67
74
  "build:react": "vite build --mode react",
68
75
  "build:preact": "vite build --mode preact",
69
76
  "build:vue": "vite build --mode vue",
70
- "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\"",
77
+ "build:svelte": "vite build --mode svelte",
78
+ "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\"",
71
79
  "clean": "rimraf dist",
72
80
  "lint": "eslint src --color",
73
81
  "lint:fix": "eslint src --color --fix"