@embedpdf/plugin-scroll 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/index.cjs +2 -651
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -200
  4. package/dist/index.js +43 -67
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +27 -0
  7. package/dist/lib/index.d.ts +9 -0
  8. package/dist/lib/manifest.d.ts +4 -0
  9. package/dist/lib/reducer.d.ts +6 -0
  10. package/dist/lib/scroll-plugin.d.ts +45 -0
  11. package/dist/lib/selectors.d.ts +2 -0
  12. package/dist/lib/strategies/base-strategy.d.ts +35 -0
  13. package/dist/lib/strategies/horizontal-strategy.d.ts +14 -0
  14. package/dist/lib/strategies/vertical-strategy.d.ts +14 -0
  15. package/dist/lib/types/virtual-item.d.ts +21 -0
  16. package/dist/lib/types.d.ts +112 -0
  17. package/dist/preact/adapter.d.ts +4 -0
  18. package/dist/preact/core.d.ts +1 -0
  19. package/dist/preact/index.cjs +2 -176
  20. package/dist/preact/index.cjs.map +1 -1
  21. package/dist/preact/index.d.ts +1 -53
  22. package/dist/preact/index.js +17 -17
  23. package/dist/preact/index.js.map +1 -1
  24. package/dist/react/adapter.d.ts +2 -0
  25. package/dist/react/core.d.ts +1 -0
  26. package/dist/react/index.cjs +2 -176
  27. package/dist/react/index.cjs.map +1 -1
  28. package/dist/react/index.d.ts +1 -52
  29. package/dist/react/index.js +16 -17
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/shared-preact/components/index.d.ts +1 -0
  32. package/dist/shared-preact/components/scroller.d.ts +14 -0
  33. package/dist/shared-preact/hooks/index.d.ts +1 -0
  34. package/dist/shared-preact/hooks/use-scroll.d.ts +32 -0
  35. package/dist/shared-preact/index.d.ts +2 -0
  36. package/dist/shared-react/components/index.d.ts +1 -0
  37. package/dist/shared-react/components/scroller.d.ts +14 -0
  38. package/dist/shared-react/hooks/index.d.ts +1 -0
  39. package/dist/shared-react/hooks/use-scroll.d.ts +32 -0
  40. package/dist/shared-react/index.d.ts +2 -0
  41. package/dist/vue/components/index.d.ts +1 -0
  42. package/dist/vue/components/scroller.vue.d.ts +28 -0
  43. package/dist/vue/hooks/index.d.ts +1 -0
  44. package/dist/vue/hooks/use-scroll.d.ts +11 -0
  45. package/dist/vue/index.cjs +2 -0
  46. package/dist/vue/index.cjs.map +1 -0
  47. package/dist/vue/index.d.ts +2 -0
  48. package/dist/vue/index.js +136 -0
  49. package/dist/vue/index.js.map +1 -0
  50. package/package.json +22 -13
  51. package/dist/index.d.cts +0 -200
  52. package/dist/preact/index.d.cts +0 -53
  53. package/dist/react/index.d.cts +0 -52
@@ -1,176 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/react/index.ts
21
- var react_exports = {};
22
- __export(react_exports, {
23
- Scroller: () => Scroller,
24
- useScroll: () => useScroll,
25
- useScrollCapability: () => useScrollCapability,
26
- useScrollPlugin: () => useScrollPlugin
27
- });
28
- module.exports = __toCommonJS(react_exports);
29
-
30
- // src/react/hooks/use-scroll.ts
31
- var import_react = require("@embedpdf/core/react");
32
- var import_plugin_scroll = require("@embedpdf/plugin-scroll");
33
- var import_react2 = require("react");
34
- var useScrollPlugin = () => (0, import_react.usePlugin)(import_plugin_scroll.ScrollPlugin.id);
35
- var useScrollCapability = () => (0, import_react.useCapability)(import_plugin_scroll.ScrollPlugin.id);
36
- var useScroll = () => {
37
- const { provides: scroll } = useScrollCapability();
38
- const [currentPage, setCurrentPage] = (0, import_react2.useState)(1);
39
- const [totalPages, setTotalPages] = (0, import_react2.useState)(1);
40
- (0, import_react2.useEffect)(() => {
41
- if (!scroll) return;
42
- return scroll.onPageChange(({ pageNumber, totalPages: totalPages2 }) => {
43
- setCurrentPage(pageNumber);
44
- setTotalPages(totalPages2);
45
- });
46
- }, [scroll]);
47
- return {
48
- ...scroll,
49
- currentPage,
50
- totalPages
51
- };
52
- };
53
-
54
- // src/react/components/scroller.tsx
55
- var import_react3 = require("react");
56
- var import_plugin_scroll2 = require("@embedpdf/plugin-scroll");
57
- var import_react4 = require("@embedpdf/core/react");
58
- var import_jsx_runtime = require("react/jsx-runtime");
59
- function Scroller({ renderPage, overlayElements, ...props }) {
60
- const { provides: scrollProvides } = useScrollCapability();
61
- const { registry } = (0, import_react4.useRegistry)();
62
- const [scrollerLayout, setScrollerLayout] = (0, import_react3.useState)(
63
- () => scrollProvides?.getScrollerLayout() ?? null
64
- );
65
- (0, import_react3.useEffect)(() => {
66
- if (!scrollProvides) return;
67
- return scrollProvides.onScrollerData(setScrollerLayout);
68
- }, [scrollProvides]);
69
- if (!scrollerLayout) return null;
70
- if (!registry) return null;
71
- const coreState = registry.getStore().getState();
72
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
73
- "div",
74
- {
75
- ...props,
76
- style: {
77
- width: `${scrollerLayout.totalWidth}px`,
78
- height: `${scrollerLayout.totalHeight}px`,
79
- position: "relative",
80
- boxSizing: "border-box",
81
- margin: "0 auto",
82
- ...scrollerLayout.strategy === import_plugin_scroll2.ScrollStrategy.Horizontal && {
83
- display: "flex",
84
- flexDirection: "row"
85
- }
86
- },
87
- children: [
88
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
- "div",
90
- {
91
- style: {
92
- ...scrollerLayout.strategy === import_plugin_scroll2.ScrollStrategy.Horizontal ? {
93
- width: scrollerLayout.startSpacing,
94
- height: "100%",
95
- flexShrink: 0
96
- } : {
97
- height: scrollerLayout.startSpacing,
98
- width: "100%"
99
- }
100
- }
101
- }
102
- ),
103
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
- "div",
105
- {
106
- style: {
107
- gap: scrollerLayout.pageGap,
108
- display: "flex",
109
- alignItems: "center",
110
- position: "relative",
111
- boxSizing: "border-box",
112
- ...scrollerLayout.strategy === import_plugin_scroll2.ScrollStrategy.Horizontal ? {
113
- flexDirection: "row",
114
- minHeight: "100%"
115
- } : {
116
- flexDirection: "column",
117
- minWidth: "fit-content"
118
- }
119
- },
120
- children: scrollerLayout.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
121
- "div",
122
- {
123
- style: {
124
- display: "flex",
125
- justifyContent: "center",
126
- gap: scrollerLayout.pageGap
127
- },
128
- children: item.pageLayouts.map((layout) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
- "div",
130
- {
131
- style: {
132
- width: `${layout.rotatedWidth}px`,
133
- height: `${layout.rotatedHeight}px`
134
- },
135
- children: renderPage({
136
- ...layout,
137
- rotation: coreState.core.rotation,
138
- scale: coreState.core.scale,
139
- document: coreState.core.document
140
- })
141
- },
142
- layout.pageNumber
143
- ))
144
- },
145
- item.pageNumbers[0]
146
- ))
147
- }
148
- ),
149
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
- "div",
151
- {
152
- style: {
153
- ...scrollerLayout.strategy === import_plugin_scroll2.ScrollStrategy.Horizontal ? {
154
- width: scrollerLayout.endSpacing,
155
- height: "100%",
156
- flexShrink: 0
157
- } : {
158
- height: scrollerLayout.endSpacing,
159
- width: "100%"
160
- }
161
- }
162
- }
163
- ),
164
- overlayElements
165
- ]
166
- }
167
- );
168
- }
169
- // Annotate the CommonJS export names for ESM import in node:
170
- 0 && (module.exports = {
171
- Scroller,
172
- useScroll,
173
- useScrollCapability,
174
- useScrollPlugin
175
- });
176
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-scroll"),r=require("react"),i=require("react/jsx-runtime"),l=()=>e.usePlugin(t.ScrollPlugin.id),o=()=>e.useCapability(t.ScrollPlugin.id);exports.Scroller=function({renderPage:a,overlayElements:n,...s}){const{provides:g}=o(),{plugin:c}=l(),{registry:u}=e.useRegistry(),[d,p]=r.useState((()=>(null==g?void 0:g.getScrollerLayout())??null));if(r.useEffect((()=>{if(g)return g.onScrollerData(p)}),[g]),r.useEffect((()=>{c&&c.setLayoutReady()}),[c]),!d)return null;if(!u)return null;const h=u.getStore().getState();return i.jsxs("div",{...s,style:{width:`${d.totalWidth}px`,height:`${d.totalHeight}px`,position:"relative",boxSizing:"border-box",margin:"0 auto",...d.strategy===t.ScrollStrategy.Horizontal&&{display:"flex",flexDirection:"row"}},children:[i.jsx("div",{style:{...d.strategy===t.ScrollStrategy.Horizontal?{width:d.startSpacing,height:"100%",flexShrink:0}:{height:d.startSpacing,width:"100%"}}}),i.jsx("div",{style:{gap:d.pageGap,display:"flex",alignItems:"center",position:"relative",boxSizing:"border-box",...d.strategy===t.ScrollStrategy.Horizontal?{flexDirection:"row",minHeight:"100%"}:{flexDirection:"column",minWidth:"fit-content"}},children:d.items.map((e=>i.jsx("div",{style:{display:"flex",justifyContent:"center",gap:d.pageGap},children:e.pageLayouts.map((e=>i.jsx("div",{style:{width:`${e.rotatedWidth}px`,height:`${e.rotatedHeight}px`},children:a({...e,rotation:h.core.rotation,scale:h.core.scale,document:h.core.document})},e.pageNumber)))},e.pageNumbers[0])))}),i.jsx("div",{style:{...d.strategy===t.ScrollStrategy.Horizontal?{width:d.endSpacing,height:"100%",flexShrink:0}:{height:d.endSpacing,width:"100%"}}}),n]})},exports.useScroll=()=>{const{provides:e}=o(),[t,i]=r.useState(1),[l,a]=r.useState(1);return r.useEffect((()=>{if(e)return e.onPageChange((({pageNumber:e,totalPages:t})=>{i(e),a(t)}))}),[e]),{...e,currentPage:t,totalPages:l}},exports.useScrollCapability=o,exports.useScrollPlugin=l;
2
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-scroll.ts","../../src/react/components/scroller.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useEffect, useState } from 'react';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\nexport const useScroll = () => {\n const { provides: scroll } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!scroll) return;\n return scroll.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [scroll]);\n\n return {\n ...scroll,\n currentPage,\n totalPages,\n };\n};\n","import React, { ReactNode, useEffect, useState } from 'react';\nimport { ScrollStrategy, ScrollerLayout, PageLayout } from '@embedpdf/plugin-scroll';\nimport { useRegistry } from '@embedpdf/core/react';\nimport { PdfDocumentObject, Rotation } from '@embedpdf/models';\n\nimport { useScrollCapability } from '../hooks';\n\ninterface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n}\n\ntype ScrollerProps = React.HTMLAttributes<HTMLDivElement> & {\n renderPage: (props: RenderPageProps) => ReactNode;\n overlayElements?: ReactNode[];\n};\n\nexport function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps) {\n const { provides: scrollProvides } = useScrollCapability();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollProvides?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollProvides) return;\n\n return scrollProvides.onScrollerData(setScrollerLayout);\n }, [scrollProvides]);\n\n if (!scrollerLayout) return null;\n if (!registry) return null;\n\n const coreState = registry.getStore().getState();\n\n return (\n <div\n {...props}\n style={{\n width: `${scrollerLayout.totalWidth}px`,\n height: `${scrollerLayout.totalHeight}px`,\n position: 'relative',\n boxSizing: 'border-box',\n margin: '0 auto',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal && {\n display: 'flex',\n flexDirection: 'row',\n }),\n }}\n >\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.startSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.startSpacing,\n width: '100%',\n }),\n }}\n />\n <div\n style={{\n gap: scrollerLayout.pageGap,\n display: 'flex',\n alignItems: 'center',\n position: 'relative',\n boxSizing: 'border-box',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n flexDirection: 'row',\n minHeight: '100%',\n }\n : {\n flexDirection: 'column',\n minWidth: 'fit-content',\n }),\n }}\n >\n {scrollerLayout.items.map((item) => (\n <div\n key={item.pageNumbers[0]}\n style={{\n display: 'flex',\n justifyContent: 'center',\n gap: scrollerLayout.pageGap,\n }}\n >\n {item.pageLayouts.map((layout) => (\n <div\n key={layout.pageNumber}\n style={{\n width: `${layout.rotatedWidth}px`,\n height: `${layout.rotatedHeight}px`,\n }}\n >\n {renderPage({\n ...layout,\n rotation: coreState.core.rotation,\n scale: coreState.core.scale,\n document: coreState.core.document,\n })}\n </div>\n ))}\n </div>\n ))}\n </div>\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.endSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.endSpacing,\n width: '100%',\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,UAAU,KAAK;AAAA,sBACzB,OAAO,UAAU,KAAK;AAAA,sBACtB,UAAU,UAAU,KAAK;AAAA,oBAC3B,CAAC;AAAA;AAAA,kBAXI,OAAO;AAAA,gBAYd,CACD;AAAA;AAAA,cAtBI,KAAK,YAAY,CAAC;AAAA,YAuBzB,CACD;AAAA;AAAA,QACH;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,OAAO;AAAA,cACL,GAAI,eAAe,aAAa,qCAAe,aAC3C;AAAA,gBACE,OAAO,eAAe;AAAA,gBACtB,QAAQ;AAAA,gBACR,YAAY;AAAA,cACd,IACA;AAAA,gBACE,QAAQ,eAAe;AAAA,gBACvB,OAAO;AAAA,cACT;AAAA,YACN;AAAA;AAAA,QACF;AAAA,QACC;AAAA;AAAA;AAAA,EACH;AAEJ;","names":["import_react","totalPages","import_react","import_plugin_scroll"]}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-scroll.ts","../../src/shared/components/scroller.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useEffect, useState } from '@framework';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\nexport const useScroll = () => {\n const { provides: scroll } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!scroll) return;\n return scroll.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [scroll]);\n\n return {\n ...scroll,\n currentPage,\n totalPages,\n };\n};\n","import { ReactNode, useEffect, useState, HTMLAttributes } from '@framework';\nimport { ScrollStrategy, ScrollerLayout, PageLayout } from '@embedpdf/plugin-scroll';\nimport { useRegistry } from '@embedpdf/core/@framework';\nimport { PdfDocumentObject, Rotation } from '@embedpdf/models';\n\nimport { useScrollCapability, useScrollPlugin } from '../hooks';\n\ninterface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n}\n\ntype ScrollerProps = HTMLAttributes<HTMLDivElement> & {\n renderPage: (props: RenderPageProps) => ReactNode;\n overlayElements?: ReactNode[];\n};\n\nexport function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps) {\n const { provides: scrollProvides } = useScrollCapability();\n const { plugin: scrollPlugin } = useScrollPlugin();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollProvides?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollProvides) return;\n\n return scrollProvides.onScrollerData(setScrollerLayout);\n }, [scrollProvides]);\n\n useEffect(() => {\n if (!scrollPlugin) return;\n\n scrollPlugin.setLayoutReady();\n }, [scrollPlugin]);\n\n if (!scrollerLayout) return null;\n if (!registry) return null;\n\n const coreState = registry.getStore().getState();\n\n return (\n <div\n {...props}\n style={{\n width: `${scrollerLayout.totalWidth}px`,\n height: `${scrollerLayout.totalHeight}px`,\n position: 'relative',\n boxSizing: 'border-box',\n margin: '0 auto',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal && {\n display: 'flex',\n flexDirection: 'row',\n }),\n }}\n >\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.startSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.startSpacing,\n width: '100%',\n }),\n }}\n />\n <div\n style={{\n gap: scrollerLayout.pageGap,\n display: 'flex',\n alignItems: 'center',\n position: 'relative',\n boxSizing: 'border-box',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n flexDirection: 'row',\n minHeight: '100%',\n }\n : {\n flexDirection: 'column',\n minWidth: 'fit-content',\n }),\n }}\n >\n {scrollerLayout.items.map((item) => (\n <div\n key={item.pageNumbers[0]}\n style={{\n display: 'flex',\n justifyContent: 'center',\n gap: scrollerLayout.pageGap,\n }}\n >\n {item.pageLayouts.map((layout) => (\n <div\n key={layout.pageNumber}\n style={{\n width: `${layout.rotatedWidth}px`,\n height: `${layout.rotatedHeight}px`,\n }}\n >\n {renderPage({\n ...layout,\n rotation: coreState.core.rotation,\n scale: coreState.core.scale,\n document: coreState.core.document,\n })}\n </div>\n ))}\n </div>\n ))}\n </div>\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.endSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.endSpacing,\n width: '100%',\n }),\n }}\n />\n {overlayElements}\n </div>\n );\n}\n"],"names":["useScrollPlugin","usePlugin","ScrollPlugin","id","useScrollCapability","useCapability","renderPage","overlayElements","props","provides","scrollProvides","plugin","scrollPlugin","registry","useRegistry","scrollerLayout","setScrollerLayout","useState","getScrollerLayout","useEffect","onScrollerData","setLayoutReady","coreState","getStore","getState","jsxRuntime","jsxs","style","width","totalWidth","height","totalHeight","position","boxSizing","margin","strategy","ScrollStrategy","Horizontal","display","flexDirection","children","jsx","startSpacing","flexShrink","gap","pageGap","alignItems","minHeight","minWidth","items","map","item","justifyContent","pageLayouts","layout","rotatedWidth","rotatedHeight","rotation","core","scale","document","pageNumber","pageNumbers","endSpacing","scroll","currentPage","setCurrentPage","totalPages","setTotalPages","onPageChange"],"mappings":"+MAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,qBCa3E,UAAkBG,WAAEA,EAAAC,gBAAYA,KAAoBC,IACzD,MAAQC,SAAUC,GAAmBN,KAC7BO,OAAQC,GAAiBZ,KAC3Ba,SAAEA,GAAaC,iBACdC,EAAgBC,GAAqBC,EAAAA,UAC1C,WAAMP,WAAgBQ,sBAAuB,OAe3C,GAZJC,EAAAA,WAAU,KACR,GAAKT,EAEE,OAAAA,EAAeU,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gB,IAAC,MAAA,CACCd,MAAO,IACDZ,EAAeoB,WAAaC,EAAAA,eAAeC,WAC3C,CACET,MAAOb,EAAegD,WACtBjC,OAAQ,OACRa,WAAY,GAEd,CACEb,OAAQf,EAAegD,WACvBnC,MAAO,WAIhBrB,IAGP,oBDhIyB,KACvB,MAAQE,SAAUuD,GAAW5D,KACtB6D,EAAaC,GAAkBjD,EAAAA,SAAS,IACxCkD,EAAYC,GAAiBnD,EAAAA,SAAS,GAUtC,OARPE,EAAAA,WAAU,KACR,GAAK6C,EACL,OAAOA,EAAOK,cAAa,EAAGR,aAAYM,WAAAA,MACxCD,EAAeL,GACfO,EAAcD,EAAU,GACzB,GACA,CAACH,IAEG,IACFA,EACHC,cACAE,aACF"}
@@ -1,52 +1 @@
1
- import * as _embedpdf_models from '@embedpdf/models';
2
- import { Rotation, PdfDocumentObject } from '@embedpdf/models';
3
- import * as _embedpdf_plugin_viewport from '@embedpdf/plugin-viewport';
4
- import * as _embedpdf_core from '@embedpdf/core';
5
- import * as _embedpdf_plugin_scroll from '@embedpdf/plugin-scroll';
6
- import { ScrollPlugin, PageLayout } from '@embedpdf/plugin-scroll';
7
- import * as react_jsx_runtime from 'react/jsx-runtime';
8
- import React, { ReactNode } from 'react';
9
-
10
- declare const useScrollPlugin: () => {
11
- plugin: ScrollPlugin | null;
12
- isLoading: boolean;
13
- ready: Promise<void>;
14
- };
15
- declare const useScrollCapability: () => {
16
- provides: Readonly<_embedpdf_plugin_scroll.ScrollCapability> | null;
17
- isLoading: boolean;
18
- ready: Promise<void>;
19
- };
20
- declare const useScroll: () => {
21
- currentPage: number;
22
- totalPages: number;
23
- onScrollerData?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollerLayout> | undefined;
24
- onStateChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollState> | undefined;
25
- onScroll?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollMetrics> | undefined;
26
- getCurrentPage?: (() => number) | undefined;
27
- getTotalPages?: (() => number) | undefined;
28
- onPageChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.PageChangePayload> | undefined;
29
- onLayoutChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.LayoutChangePayload> | undefined;
30
- scrollToPage?: ((options: _embedpdf_plugin_scroll.ScrollToPageOptions) => void) | undefined;
31
- scrollToNextPage?: ((behavior?: ScrollBehavior) => void) | undefined;
32
- scrollToPreviousPage?: ((behavior?: ScrollBehavior) => void) | undefined;
33
- getMetrics?: ((viewport?: _embedpdf_plugin_viewport.ViewportMetrics) => _embedpdf_plugin_scroll.ScrollMetrics) | undefined;
34
- getLayout?: (() => _embedpdf_plugin_scroll.LayoutChangePayload) | undefined;
35
- getScrollerLayout?: (() => _embedpdf_plugin_scroll.ScrollerLayout) | undefined;
36
- getRectPositionForPage?: ((page: number, rect: _embedpdf_models.Rect, scale?: number, rotation?: _embedpdf_models.Rotation) => _embedpdf_models.Rect | null) | undefined;
37
- setScrollStrategy?: ((strategy: _embedpdf_plugin_scroll.ScrollStrategy) => void) | undefined;
38
- getPageGap?: (() => number) | undefined;
39
- };
40
-
41
- interface RenderPageProps extends PageLayout {
42
- rotation: Rotation;
43
- scale: number;
44
- document: PdfDocumentObject | null;
45
- }
46
- type ScrollerProps = React.HTMLAttributes<HTMLDivElement> & {
47
- renderPage: (props: RenderPageProps) => ReactNode;
48
- overlayElements?: ReactNode[];
49
- };
50
- declare function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps): react_jsx_runtime.JSX.Element | null;
51
-
52
- export { Scroller, useScroll, useScrollCapability, useScrollPlugin };
1
+ export * from '../shared-react';
@@ -1,10 +1,10 @@
1
- // src/react/hooks/use-scroll.ts
2
- import { useCapability, usePlugin } from "@embedpdf/core/react";
3
- import { ScrollPlugin } from "@embedpdf/plugin-scroll";
4
- import { useEffect, useState } from "react";
5
- var useScrollPlugin = () => usePlugin(ScrollPlugin.id);
6
- var useScrollCapability = () => useCapability(ScrollPlugin.id);
7
- var useScroll = () => {
1
+ import { usePlugin, useCapability, useRegistry } from "@embedpdf/core/react";
2
+ import { ScrollPlugin, ScrollStrategy } from "@embedpdf/plugin-scroll";
3
+ import { useState, useEffect } from "react";
4
+ import { jsxs, jsx } from "react/jsx-runtime";
5
+ const useScrollPlugin = () => usePlugin(ScrollPlugin.id);
6
+ const useScrollCapability = () => useCapability(ScrollPlugin.id);
7
+ const useScroll = () => {
8
8
  const { provides: scroll } = useScrollCapability();
9
9
  const [currentPage, setCurrentPage] = useState(1);
10
10
  const [totalPages, setTotalPages] = useState(1);
@@ -21,22 +21,21 @@ var useScroll = () => {
21
21
  totalPages
22
22
  };
23
23
  };
24
-
25
- // src/react/components/scroller.tsx
26
- import { useEffect as useEffect2, useState as useState2 } from "react";
27
- import { ScrollStrategy } from "@embedpdf/plugin-scroll";
28
- import { useRegistry } from "@embedpdf/core/react";
29
- import { jsx, jsxs } from "react/jsx-runtime";
30
24
  function Scroller({ renderPage, overlayElements, ...props }) {
31
25
  const { provides: scrollProvides } = useScrollCapability();
26
+ const { plugin: scrollPlugin } = useScrollPlugin();
32
27
  const { registry } = useRegistry();
33
- const [scrollerLayout, setScrollerLayout] = useState2(
34
- () => scrollProvides?.getScrollerLayout() ?? null
28
+ const [scrollerLayout, setScrollerLayout] = useState(
29
+ () => (scrollProvides == null ? void 0 : scrollProvides.getScrollerLayout()) ?? null
35
30
  );
36
- useEffect2(() => {
31
+ useEffect(() => {
37
32
  if (!scrollProvides) return;
38
33
  return scrollProvides.onScrollerData(setScrollerLayout);
39
34
  }, [scrollProvides]);
35
+ useEffect(() => {
36
+ if (!scrollPlugin) return;
37
+ scrollPlugin.setLayoutReady();
38
+ }, [scrollPlugin]);
40
39
  if (!scrollerLayout) return null;
41
40
  if (!registry) return null;
42
41
  const coreState = registry.getStore().getState();
@@ -143,4 +142,4 @@ export {
143
142
  useScrollCapability,
144
143
  useScrollPlugin
145
144
  };
146
- //# sourceMappingURL=index.js.map
145
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/hooks/use-scroll.ts","../../src/react/components/scroller.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useEffect, useState } from 'react';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\nexport const useScroll = () => {\n const { provides: scroll } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!scroll) return;\n return scroll.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [scroll]);\n\n return {\n ...scroll,\n currentPage,\n totalPages,\n };\n};\n","import React, { ReactNode, useEffect, useState } from 'react';\nimport { ScrollStrategy, ScrollerLayout, PageLayout } from '@embedpdf/plugin-scroll';\nimport { useRegistry } from '@embedpdf/core/react';\nimport { PdfDocumentObject, Rotation } from '@embedpdf/models';\n\nimport { useScrollCapability } from '../hooks';\n\ninterface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n}\n\ntype ScrollerProps = React.HTMLAttributes<HTMLDivElement> & {\n renderPage: (props: RenderPageProps) => ReactNode;\n overlayElements?: ReactNode[];\n};\n\nexport function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps) {\n const { provides: scrollProvides } = useScrollCapability();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollProvides?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollProvides) return;\n\n return scrollProvides.onScrollerData(setScrollerLayout);\n }, [scrollProvides]);\n\n if (!scrollerLayout) return null;\n if (!registry) return null;\n\n const coreState = registry.getStore().getState();\n\n return (\n <div\n {...props}\n style={{\n width: `${scrollerLayout.totalWidth}px`,\n height: `${scrollerLayout.totalHeight}px`,\n position: 'relative',\n boxSizing: 'border-box',\n margin: '0 auto',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal && {\n display: 'flex',\n flexDirection: 'row',\n }),\n }}\n >\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.startSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.startSpacing,\n width: '100%',\n }),\n }}\n />\n <div\n style={{\n gap: scrollerLayout.pageGap,\n display: 'flex',\n alignItems: 'center',\n position: 'relative',\n boxSizing: 'border-box',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n flexDirection: 'row',\n minHeight: '100%',\n }\n : {\n flexDirection: 'column',\n minWidth: 'fit-content',\n }),\n }}\n >\n {scrollerLayout.items.map((item) => (\n <div\n key={item.pageNumbers[0]}\n style={{\n display: 'flex',\n justifyContent: 'center',\n gap: scrollerLayout.pageGap,\n }}\n >\n {item.pageLayouts.map((layout) => (\n <div\n key={layout.pageNumber}\n style={{\n width: `${layout.rotatedWidth}px`,\n height: `${layout.rotatedHeight}px`,\n }}\n >\n {renderPage({\n ...layout,\n rotation: coreState.core.rotation,\n scale: coreState.core.scale,\n document: coreState.core.document,\n })}\n </div>\n ))}\n </div>\n ))}\n </div>\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.endSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.endSpacing,\n width: '100%',\n }),\n }}\n />\n {overlayElements}\n </div>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAC7B,SAAS,WAAW,gBAAgB;AAE7B,IAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,IAAM,YAAY,MAAM;AAC7B,QAAM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e,aAAa,eAAe,aAC3C;AAAA,gBACE,OAAO,eAAe;AAAA,gBACtB,QAAQ;AAAA,gBACR,YAAY;AAAA,cACd,IACA;AAAA,gBACE,QAAQ,eAAe;AAAA,gBACvB,OAAO;AAAA,cACT;AAAA,YACN;AAAA;AAAA,QACF;AAAA,QACC;AAAA;AAAA;AAAA,EACH;AAEJ;","names":["totalPages","useEffect","useState","useState","useEffect"]}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-scroll.ts","../../src/shared/components/scroller.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ScrollPlugin } from '@embedpdf/plugin-scroll';\nimport { useEffect, useState } from '@framework';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\nexport const useScroll = () => {\n const { provides: scroll } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!scroll) return;\n return scroll.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [scroll]);\n\n return {\n ...scroll,\n currentPage,\n totalPages,\n };\n};\n","import { ReactNode, useEffect, useState, HTMLAttributes } from '@framework';\nimport { ScrollStrategy, ScrollerLayout, PageLayout } from '@embedpdf/plugin-scroll';\nimport { useRegistry } from '@embedpdf/core/@framework';\nimport { PdfDocumentObject, Rotation } from '@embedpdf/models';\n\nimport { useScrollCapability, useScrollPlugin } from '../hooks';\n\ninterface RenderPageProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n}\n\ntype ScrollerProps = HTMLAttributes<HTMLDivElement> & {\n renderPage: (props: RenderPageProps) => ReactNode;\n overlayElements?: ReactNode[];\n};\n\nexport function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps) {\n const { provides: scrollProvides } = useScrollCapability();\n const { plugin: scrollPlugin } = useScrollPlugin();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollProvides?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollProvides) return;\n\n return scrollProvides.onScrollerData(setScrollerLayout);\n }, [scrollProvides]);\n\n useEffect(() => {\n if (!scrollPlugin) return;\n\n scrollPlugin.setLayoutReady();\n }, [scrollPlugin]);\n\n if (!scrollerLayout) return null;\n if (!registry) return null;\n\n const coreState = registry.getStore().getState();\n\n return (\n <div\n {...props}\n style={{\n width: `${scrollerLayout.totalWidth}px`,\n height: `${scrollerLayout.totalHeight}px`,\n position: 'relative',\n boxSizing: 'border-box',\n margin: '0 auto',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal && {\n display: 'flex',\n flexDirection: 'row',\n }),\n }}\n >\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.startSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.startSpacing,\n width: '100%',\n }),\n }}\n />\n <div\n style={{\n gap: scrollerLayout.pageGap,\n display: 'flex',\n alignItems: 'center',\n position: 'relative',\n boxSizing: 'border-box',\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n flexDirection: 'row',\n minHeight: '100%',\n }\n : {\n flexDirection: 'column',\n minWidth: 'fit-content',\n }),\n }}\n >\n {scrollerLayout.items.map((item) => (\n <div\n key={item.pageNumbers[0]}\n style={{\n display: 'flex',\n justifyContent: 'center',\n gap: scrollerLayout.pageGap,\n }}\n >\n {item.pageLayouts.map((layout) => (\n <div\n key={layout.pageNumber}\n style={{\n width: `${layout.rotatedWidth}px`,\n height: `${layout.rotatedHeight}px`,\n }}\n >\n {renderPage({\n ...layout,\n rotation: coreState.core.rotation,\n scale: coreState.core.scale,\n document: coreState.core.document,\n })}\n </div>\n ))}\n </div>\n ))}\n </div>\n <div\n style={{\n ...(scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: scrollerLayout.endSpacing,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: scrollerLayout.endSpacing,\n width: '100%',\n }),\n }}\n />\n {overlayElements}\n </div>\n );\n}\n"],"names":["totalPages"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,UAAU,OAAO,IAAI,oBAAoB;AACjD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AAChD,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC;AAE9C,YAAU,MAAM;AACd,QAAI,CAAC,OAAQ;AACb,WAAO,OAAO,aAAa,CAAC,EAAE,YAAY,YAAAA,kBAAiB;AACzD,qBAAe,UAAU;AACzB,oBAAcA,WAAU;AAAA,IAAA,CACzB;AAAA,EAAA,GACA,CAAC,MAAM,CAAC;AAEJ,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;ACPO,SAAS,SAAS,EAAE,YAAY,iBAAiB,GAAG,SAAwB;AACjF,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAC3C,QAAA,EAAE,SAAS,IAAI,YAAY;AAC3B,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAM,iDAAgB,wBAAuB;AAAA,EAC/C;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,eAAgB;AAEd,WAAA,eAAe,eAAe,iBAAiB;AAAA,EAAA,GACrD,CAAC,cAAc,CAAC;AAEnB,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AAEnB,iBAAa,eAAe;AAAA,EAAA,GAC3B,CAAC,YAAY,CAAC;AAEb,MAAA,CAAC,eAAuB,QAAA;AACxB,MAAA,CAA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AO,YAAY;AAAA,sBAC7B,QAAQ,GAAG,OAAO,aAAa;AAAA,oBACjC;AAAA,oBAEC,UAAW,WAAA;AAAA,sBACV,GAAG;AAAA,sBACH,UAAU,UAAU,KAAK;AAAA,sBACzB,OAAO,UAAU,KAAK;AAAA,sBACtB,UAAU,UAAU,KAAK;AAAA,oBAC1B,CAAA;AAAA,kBAAA;AAAA,kBAXI,OAAO;AAAA,gBAaf,CAAA;AAAA,cAAA;AAAA,cAtBI,KAAK,YAAY,CAAC;AAAA,YAwB1B,CAAA;AAAA,UAAA;AAAA,QACH;AAAA,QACA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,GAAI,eAAe,aAAa,eAAe,aAC3C;AAAA,gBACE,OAAO,eAAe;AAAA,gBACtB,QAAQ;AAAA,gBACR,YAAY;AAAA,cAAA,IAEd;AAAA,gBACE,QAAQ,eAAe;AAAA,gBACvB,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UACN;AAAA,QACF;AAAA,QACC;AAAA,MAAA;AAAA,IAAA;AAAA,EACH;AAEJ;"}
@@ -0,0 +1 @@
1
+ export * from './scroller';
@@ -0,0 +1,14 @@
1
+ import { ReactNode, HTMLAttributes } from '../../preact/adapter.ts';
2
+ import { PageLayout } from '../../lib/index.ts';
3
+ import { PdfDocumentObject, Rotation } from '@embedpdf/models';
4
+ 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("preact").JSX.Element | null;
14
+ export {};
@@ -0,0 +1 @@
1
+ export * from './use-scroll';
@@ -0,0 +1,32 @@
1
+ import { 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<import('../../lib/index.ts').ScrollCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
12
+ export declare const useScroll: () => {
13
+ currentPage: number;
14
+ totalPages: number;
15
+ onScrollerData?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollerLayout> | undefined;
16
+ onStateChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollState> | undefined;
17
+ onScroll?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollMetrics> | undefined;
18
+ getCurrentPage?: (() => number) | undefined;
19
+ getTotalPages?: (() => number) | undefined;
20
+ onPageChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').PageChangePayload> | undefined;
21
+ onLayoutChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').LayoutChangePayload> | undefined;
22
+ onLayoutReady?: import('@embedpdf/core').EventHook<boolean> | undefined;
23
+ scrollToPage?: ((options: import('../../lib/index.ts').ScrollToPageOptions) => void) | undefined;
24
+ scrollToNextPage?: ((behavior?: ScrollBehavior) => void) | undefined;
25
+ scrollToPreviousPage?: ((behavior?: ScrollBehavior) => void) | undefined;
26
+ getMetrics?: ((viewport?: import('@embedpdf/plugin-viewport').ViewportMetrics) => import('../../lib/index.ts').ScrollMetrics) | undefined;
27
+ getLayout?: (() => import('../../lib/index.ts').LayoutChangePayload) | undefined;
28
+ getScrollerLayout?: (() => import('../../lib/index.ts').ScrollerLayout) | undefined;
29
+ getRectPositionForPage?: ((page: number, rect: import('@embedpdf/models').Rect, scale?: number, rotation?: import('@embedpdf/models').Rotation) => import('@embedpdf/models').Rect | null) | undefined;
30
+ setScrollStrategy?: ((strategy: import('../../lib/index.ts').ScrollStrategy) => void) | undefined;
31
+ getPageGap?: (() => number) | undefined;
32
+ };
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from './components';
@@ -0,0 +1 @@
1
+ export * from './scroller';
@@ -0,0 +1,14 @@
1
+ import { ReactNode, HTMLAttributes } from '../../react/adapter.ts';
2
+ import { PageLayout } from '../../lib/index.ts';
3
+ import { PdfDocumentObject, Rotation } from '@embedpdf/models';
4
+ 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,32 @@
1
+ import { 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<import('../../lib/index.ts').ScrollCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
12
+ export declare const useScroll: () => {
13
+ currentPage: number;
14
+ totalPages: number;
15
+ onScrollerData?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollerLayout> | undefined;
16
+ onStateChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollState> | undefined;
17
+ onScroll?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').ScrollMetrics> | undefined;
18
+ getCurrentPage?: (() => number) | undefined;
19
+ getTotalPages?: (() => number) | undefined;
20
+ onPageChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').PageChangePayload> | undefined;
21
+ onLayoutChange?: import('@embedpdf/core').EventHook<import('../../lib/index.ts').LayoutChangePayload> | undefined;
22
+ onLayoutReady?: import('@embedpdf/core').EventHook<boolean> | undefined;
23
+ scrollToPage?: ((options: import('../../lib/index.ts').ScrollToPageOptions) => void) | undefined;
24
+ scrollToNextPage?: ((behavior?: ScrollBehavior) => void) | undefined;
25
+ scrollToPreviousPage?: ((behavior?: ScrollBehavior) => void) | undefined;
26
+ getMetrics?: ((viewport?: import('@embedpdf/plugin-viewport').ViewportMetrics) => import('../../lib/index.ts').ScrollMetrics) | undefined;
27
+ getLayout?: (() => import('../../lib/index.ts').LayoutChangePayload) | undefined;
28
+ getScrollerLayout?: (() => import('../../lib/index.ts').ScrollerLayout) | undefined;
29
+ getRectPositionForPage?: ((page: number, rect: import('@embedpdf/models').Rect, scale?: number, rotation?: import('@embedpdf/models').Rotation) => import('@embedpdf/models').Rect | null) | undefined;
30
+ setScrollStrategy?: ((strategy: import('../../lib/index.ts').ScrollStrategy) => void) | undefined;
31
+ getPageGap?: (() => number) | undefined;
32
+ };
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from './components';
@@ -0,0 +1 @@
1
+ export { default as Scroller } from './scroller.vue';
@@ -0,0 +1,28 @@
1
+ import { StyleValue } from 'vue';
2
+ import { PageLayout } from '../../lib/index.ts';
3
+ import { PdfDocumentObject, Rotation } from '@embedpdf/models';
4
+ type __VLS_Props = {
5
+ style?: StyleValue;
6
+ overlayElements?: any[];
7
+ };
8
+ interface PageSlotProps extends PageLayout {
9
+ rotation: Rotation;
10
+ scale: number;
11
+ document: PdfDocumentObject | null;
12
+ }
13
+ declare var __VLS_1: {
14
+ page: PageSlotProps;
15
+ };
16
+ type __VLS_Slots = {} & {
17
+ default?: (props: typeof __VLS_1) => any;
18
+ };
19
+ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
20
+ overlayElements: any[];
21
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
22
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
23
+ export default _default;
24
+ type __VLS_WithSlots<T, S> = T & {
25
+ new (): {
26
+ $slots: S;
27
+ };
28
+ };
@@ -0,0 +1 @@
1
+ export * from './use-scroll';
@@ -0,0 +1,11 @@
1
+ import { ScrollPlugin } from '../../lib/index.ts';
2
+ export declare const useScrollPlugin: () => import('@embedpdf/core/vue').PluginState<ScrollPlugin>;
3
+ export declare const useScrollCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').ScrollCapability>>;
4
+ /**
5
+ * Convenience hook that also tracks current / total page.
6
+ */
7
+ export declare function useScroll(): {
8
+ scroll: import('vue').Ref<Readonly<import('../../lib/index.ts').ScrollCapability> | null, Readonly<import('../../lib/index.ts').ScrollCapability> | null>;
9
+ currentPage: import('vue').Ref<number, number>;
10
+ totalPages: import('vue').Ref<number, number>;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),l=require("@embedpdf/plugin-scroll"),r=()=>t.usePlugin(l.ScrollPlugin.id),o=()=>t.useCapability(l.ScrollPlugin.id);const a=e.defineComponent({__name:"scroller",props:{style:{type:[Boolean,null,String,Object,Array]},overlayElements:{default:()=>[]}},setup(a){const n=a,i=e.useAttrs(),{provides:u}=o(),{plugin:c}=r(),{registry:s}=t.useRegistry(),p=e.ref(null);function y(e){const t=s.value.getStore().getState().core;return{...e,rotation:t.rotation,scale:t.scale,document:t.document}}e.watchEffect((e=>{if(!u.value)return;p.value=u.value.getScrollerLayout();e(u.value.onScrollerData((e=>p.value=e)))})),e.onMounted((()=>{var e;null==(e=c.value)||e.setLayoutReady()}));const g=e.computed((()=>{if(!p.value)return n.style;return["object"!=typeof n.style||Array.isArray(n.style)?n.style??{}:{...n.style},{width:`${p.value.totalWidth}px`,height:`${p.value.totalHeight}px`,position:"relative",boxSizing:"border-box",margin:"0 auto",...p.value.strategy===l.ScrollStrategy.Horizontal&&{display:"flex",flexDirection:"row"}}]}));return(t,l)=>p.value&&e.unref(s)?(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:0,style:g.value},e.unref(i)),["horizontal"===p.value.strategy?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle({width:p.value.startSpacing+"px",height:"100%",flexShrink:0})},null,4)):(e.openBlock(),e.createElementBlock("div",{key:1,style:e.normalizeStyle({height:p.value.startSpacing+"px",width:"100%"})},null,4)),e.createElementVNode("div",{style:e.normalizeStyle({gap:p.value.pageGap+"px",display:"flex",alignItems:"center",position:"relative",boxSizing:"border-box",flexDirection:"horizontal"===p.value.strategy?"row":"column",minHeight:"horizontal"===p.value.strategy?"100%":void 0,minWidth:"vertical"===p.value.strategy?"fit-content":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value.items,(l=>(e.openBlock(),e.createElementBlock("div",{key:l.pageNumbers[0],style:e.normalizeStyle({display:"flex",justifyContent:"center",gap:p.value.pageGap+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.pageLayouts,(l=>(e.openBlock(),e.createElementBlock("div",{key:l.pageNumber,style:e.normalizeStyle({width:l.rotatedWidth+"px",height:l.rotatedHeight+"px"})},[e.renderSlot(t.$slots,"default",{page:y(l)})],4)))),128))],4)))),128))],4),"horizontal"===p.value.strategy?(e.openBlock(),e.createElementBlock("div",{key:2,style:e.normalizeStyle({width:p.value.endSpacing+"px",height:"100%",flexShrink:0})},null,4)):(e.openBlock(),e.createElementBlock("div",{key:3,style:e.normalizeStyle({height:p.value.endSpacing+"px",width:"100%"})},null,4)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.overlayElements,((t,l)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t),{key:l})))),128))],16)):e.createCommentVNode("",!0)}});exports.Scroller=a,exports.useScroll=function(){const{provides:t}=o(),l=e.ref(1),r=e.ref(1);return e.watchEffect((e=>{if(!t.value)return;e(t.value.onPageChange((({pageNumber:e,totalPages:t})=>{l.value=e,r.value=t})))})),{scroll:t,currentPage:l,totalPages:r}},exports.useScrollCapability=o,exports.useScrollPlugin=r;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-scroll.ts","../../src/vue/components/scroller.vue"],"sourcesContent":["import { ref, watchEffect } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ScrollPlugin } from '@embedpdf/plugin-scroll';\n\nexport const useScrollPlugin = () => usePlugin<ScrollPlugin>(ScrollPlugin.id);\nexport const useScrollCapability = () => useCapability<ScrollPlugin>(ScrollPlugin.id);\n\n/**\n * Convenience hook that also tracks current / total page.\n */\nexport function useScroll() {\n const { provides: scroll } = useScrollCapability();\n\n const currentPage = ref(1);\n const totalPages = ref(1);\n\n watchEffect((onCleanup) => {\n if (!scroll.value) return;\n\n const off = scroll.value.onPageChange(({ pageNumber, totalPages: tp }) => {\n currentPage.value = pageNumber;\n totalPages.value = tp;\n });\n onCleanup(off);\n });\n\n return {\n scroll,\n currentPage,\n totalPages,\n };\n}\n","<script setup lang=\"ts\">\n/* ------------------------------------------------------------------ */\n/* imports */\n/* ------------------------------------------------------------------ */\nimport { computed, onMounted, ref, watchEffect, useAttrs } from 'vue';\nimport type { StyleValue } from 'vue';\n\nimport { useScrollCapability, useScrollPlugin } from '../hooks';\nimport { ScrollStrategy, type ScrollerLayout, type PageLayout } from '@embedpdf/plugin-scroll';\nimport { useRegistry } from '@embedpdf/core/vue';\nimport type { PdfDocumentObject, Rotation } from '@embedpdf/models';\n\n/* ------------------------------------------------------------------ */\n/* props – pure layout; page content comes from the *slot* */\n/* ------------------------------------------------------------------ */\nconst props = withDefaults(\n defineProps<{\n style?: StyleValue;\n overlayElements?: any[];\n }>(),\n { overlayElements: () => [] },\n);\n\nconst attrs = useAttrs();\n\n/* ------------------------------------------------------------------ */\n/* plugin + reactive state */\n/* ------------------------------------------------------------------ */\nconst { provides: scrollProvides } = useScrollCapability();\nconst { plugin: scrollPlugin } = useScrollPlugin();\nconst { registry } = useRegistry(); // shallowRef<PluginRegistry|null>\n\nconst layout = ref<ScrollerLayout | null>(null);\n\n/* subscribe to scroller‑layout updates */\nwatchEffect((onCleanup) => {\n if (!scrollProvides.value) return;\n\n layout.value = scrollProvides.value.getScrollerLayout();\n const off = scrollProvides.value.onScrollerData((l) => (layout.value = l));\n onCleanup(off);\n});\n\n/* inform plugin once the DOM is ready */\nonMounted(() => {\n scrollPlugin.value?.setLayoutReady();\n});\n\n/* ------------------------------------------------------------------ */\n/* helpers */\n/* ------------------------------------------------------------------ */\ninterface PageSlotProps extends PageLayout {\n rotation: Rotation;\n scale: number;\n document: PdfDocumentObject | null;\n}\n\n/** Build the prop object that we’ll forward into the default slot */\nfunction pageSlotProps(pl: PageLayout): PageSlotProps {\n const core = registry.value!.getStore().getState().core;\n return {\n ...pl,\n rotation: core.rotation,\n scale: core.scale,\n document: core.document,\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* computed root style */\n/* ------------------------------------------------------------------ */\nconst rootStyle = computed<StyleValue>(() => {\n if (!layout.value) return props.style;\n\n const base =\n typeof props.style === 'object' && !Array.isArray(props.style)\n ? { ...props.style }\n : (props.style ?? {});\n\n return [\n base,\n {\n width: `${layout.value.totalWidth}px`,\n height: `${layout.value.totalHeight}px`,\n position: 'relative',\n boxSizing: 'border-box',\n margin: '0 auto',\n ...(layout.value.strategy === ScrollStrategy.Horizontal && {\n display: 'flex',\n flexDirection: 'row',\n }),\n },\n ];\n});\n</script>\n\n<template>\n <!-- render nothing until both layout + registry exist -->\n <div v-if=\"layout && registry\" :style=\"rootStyle\" v-bind=\"attrs\">\n <!-- leading spacer -->\n <div\n v-if=\"layout.strategy === 'horizontal'\"\n :style=\"{ width: layout.startSpacing + 'px', height: '100%', flexShrink: 0 }\"\n />\n <div v-else :style=\"{ height: layout.startSpacing + 'px', width: '100%' }\" />\n\n <!-- actual page grid -->\n <div\n :style=\"{\n gap: layout.pageGap + 'px',\n display: 'flex',\n alignItems: 'center',\n position: 'relative',\n boxSizing: 'border-box',\n flexDirection: layout.strategy === 'horizontal' ? 'row' : 'column',\n minHeight: layout.strategy === 'horizontal' ? '100%' : undefined,\n minWidth: layout.strategy === 'vertical' ? 'fit-content' : undefined,\n }\"\n >\n <template v-for=\"item in layout.items\" :key=\"item.pageNumbers[0]\">\n <div :style=\"{ display: 'flex', justifyContent: 'center', gap: layout.pageGap + 'px' }\">\n <div\n v-for=\"pl in item.pageLayouts\"\n :key=\"pl.pageNumber\"\n :style=\"{ width: pl.rotatedWidth + 'px', height: pl.rotatedHeight + 'px' }\"\n >\n <!-- 🔑 give the host app full control over page content -->\n <slot :page=\"pageSlotProps(pl)\" />\n </div>\n </div>\n </template>\n </div>\n\n <!-- trailing spacer -->\n <div\n v-if=\"layout.strategy === 'horizontal'\"\n :style=\"{ width: layout.endSpacing + 'px', height: '100%', flexShrink: 0 }\"\n />\n <div v-else :style=\"{ height: layout.endSpacing + 'px', width: '100%' }\" />\n\n <!-- optional overlay components -->\n <component v-for=\"(el, i) in props.overlayElements\" :is=\"el\" :key=\"i\" />\n </div>\n</template>\n"],"names":["useScrollPlugin","usePlugin","ScrollPlugin","id","useScrollCapability","useCapability","props","__props","attrs","useAttrs","provides","scrollProvides","plugin","scrollPlugin","registry","useRegistry","layout","ref","pageSlotProps","pl","core","value","getStore","getState","rotation","scale","document","vue$1","watchEffect","onCleanup","getScrollerLayout","onScrollerData","l","onMounted","_a","setLayoutReady","rootStyle","computed","style","Array","isArray","width","totalWidth","height","totalHeight","position","boxSizing","margin","strategy","ScrollStrategy","Horizontal","display","flexDirection","_unref","_openBlock","_createElementBlock","_mergeProps","unref","_normalizeStyle","normalizeStyle","startSpacing","flexShrink","_createElementVNode","gap","pageGap","createElementBlock","_Fragment","_renderList","renderList","items","item","key","pageNumbers","justifyContent","Fragment","pageLayouts","pageNumber","rotatedWidth","rotatedHeight","_renderSlot","_ctx","$slots","page","endSpacing","overlayElements","el","i","openBlock","_createBlock","_resolveDynamicComponent","resolveDynamicComponent","scroll","currentPage","totalPages","onPageChange","tp"],"mappings":"4KAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,mJCUlF,MAAMG,EAAQC,EAQRC,EAAQC,EAAAA,YAKNC,SAAUC,GAAmBP,KAC7BQ,OAAQC,GAAiBb,KAC3Bc,SAAEA,GAAaC,gBAEfC,EAASC,MAA2B,MA0B1C,SAASC,EAAcC,GACrB,MAAMC,EAAON,EAASO,MAAOC,WAAWC,WAAWH,KAC5C,MAAA,IACFD,EACHK,SAAUJ,EAAKI,SACfC,MAAOL,EAAKK,MACZC,SAAUN,EAAKM,SACjB,CA9BFC,EAAAC,aAAaC,IACP,IAAClB,EAAeU,MAAO,OAEpBL,EAAAK,MAAQV,EAAeU,MAAMS,oBAEpCD,EADYlB,EAAeU,MAAMU,gBAAgBC,GAAOhB,EAAOK,MAAQW,IAC1D,IAIfC,EAAAA,WAAU,WACR,OAAAC,EAAArB,EAAaQ,QAAOa,EAAAC,gBAAA,IA0BhB,MAAAC,EAAYC,EAAAA,UAAqB,KACrC,IAAKrB,EAAOK,MAAO,OAAOf,EAAMgC,MAOzB,MAAA,CAJkB,iBAAhBhC,EAAMgC,OAAuBC,MAAMC,QAAQlC,EAAMgC,OAEnDhC,EAAMgC,OAAS,CAAC,EADjB,IAAKhC,EAAMgC,OAKf,CACEG,MAAO,GAAGzB,EAAOK,MAAMqB,eACvBC,OAAQ,GAAG3B,EAAOK,MAAMuB,gBACxBC,SAAU,WACVC,UAAW,aACXC,OAAQ,YACJ/B,EAAOK,MAAM2B,WAAaC,EAAAA,eAAeC,YAAc,CACzDC,QAAS,OACTC,cAAe,QAGrB,iBAMWpC,EAAAK,OAAUgC,EAAAA,MAAQvC,IAA7BwC,EAAAA,YAAAC,EAAAA,mBA4CM,MA5CNC,aA4CM,OA5C0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