@embedpdf/plugin-scroll 1.0.26 → 1.1.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.
@@ -1 +1 @@
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\nexport interface 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,eAAeJ,EAAiB,GACrD,CAACN,IAEJS,EAAAA,WAAU,KACHP,GAELA,EAAaS,gBAAe,GAC3B,CAACT,KAECG,EAAuB,OAAA,KACxB,IAACF,EAAiB,OAAA,KAEtB,MAAMS,EAAYT,EAASU,WAAWC,WAGpC,OAAAC,EAAAC,KAAC,MAAA,IACKlB,EACJmB,MAAO,CACLC,MAAO,GAAGb,EAAec,eACzBC,OAAQ,GAAGf,EAAegB,gBAC1BC,SAAU,WACVC,UAAW,aACXC,OAAQ,YACJnB,EAAeoB,WAAaC,EAAAA,eAAeC,YAAc,CAC3DC,QAAS,OACTC,cAAe,QAInBC,SAAA,CAAAf,E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AAU,GACzB,GACA,CAACH,IAEG,IACFA,EACHC,cACAE,aACF"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-scroll.ts","../../src/shared/components/scroller.tsx"],"sourcesContent":["import { useState, useEffect } from '@framework';\nimport { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ScrollCapability, ScrollPlugin } from '@embedpdf/plugin-scroll';\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 // Deprecated properties (for backward compatibility)\n readonly currentPage: number;\n readonly totalPages: number;\n readonly scrollToPage: ScrollCapability['scrollToPage'] | undefined;\n readonly scrollToNextPage: ScrollCapability['scrollToNextPage'] | undefined;\n readonly scrollToPreviousPage: ScrollCapability['scrollToPreviousPage'] | undefined;\n readonly getMetrics: ScrollCapability['getMetrics'] | undefined;\n readonly onPageChange: ScrollCapability['onPageChange'] | undefined;\n readonly onScroll: ScrollCapability['onScroll'] | undefined;\n readonly onLayoutChange: ScrollCapability['onLayoutChange'] | undefined;\n readonly getCurrentPage: ScrollCapability['getCurrentPage'] | undefined;\n readonly getTotalPages: ScrollCapability['getTotalPages'] | undefined;\n}\n\nexport const useScroll = (): UseScrollReturn => {\n const { provides } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [provides]);\n\n return {\n // New format (preferred)\n provides,\n state: {\n currentPage,\n totalPages,\n },\n\n // Deprecated properties with getters that show warnings\n get currentPage() {\n console.warn(\n `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`,\n );\n return currentPage;\n },\n\n get totalPages() {\n console.warn(\n `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`,\n );\n return totalPages;\n },\n\n get scrollToPage() {\n if (provides?.scrollToPage) {\n console.warn(\n `Accessing 'scrollToPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPage instead.`,\n );\n }\n return provides?.scrollToPage;\n },\n\n get scrollToNextPage() {\n if (provides?.scrollToNextPage) {\n console.warn(\n `Accessing 'scrollToNextPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToNextPage instead.`,\n );\n }\n return provides?.scrollToNextPage;\n },\n\n get scrollToPreviousPage() {\n if (provides?.scrollToPreviousPage) {\n console.warn(\n `Accessing 'scrollToPreviousPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPreviousPage instead.`,\n );\n }\n return provides?.scrollToPreviousPage;\n },\n\n get getMetrics() {\n if (provides?.getMetrics) {\n console.warn(\n `Accessing 'getMetrics' directly on useScroll() is deprecated. Use useScroll().provides.getMetrics instead.`,\n );\n }\n return provides?.getMetrics;\n },\n\n get onPageChange() {\n if (provides?.onPageChange) {\n console.warn(\n `Accessing 'onPageChange' directly on useScroll() is deprecated. Use useScroll().provides.onPageChange instead.`,\n );\n }\n return provides?.onPageChange;\n },\n\n get onScroll() {\n if (provides?.onScroll) {\n console.warn(\n `Accessing 'onScroll' directly on useScroll() is deprecated. Use useScroll().provides.onScroll instead.`,\n );\n }\n return provides?.onScroll;\n },\n\n get onLayoutChange() {\n if (provides?.onLayoutChange) {\n console.warn(\n `Accessing 'onLayoutChange' directly on useScroll() is deprecated. Use useScroll().provides.onLayoutChange instead.`,\n );\n }\n return provides?.onLayoutChange;\n },\n\n get getCurrentPage() {\n if (provides?.getCurrentPage) {\n console.warn(\n `Accessing 'getCurrentPage' directly on useScroll() is deprecated. Use useScroll().provides.getCurrentPage instead.`,\n );\n }\n return provides?.getCurrentPage;\n },\n\n get getTotalPages() {\n if (provides?.getTotalPages) {\n console.warn(\n `Accessing 'getTotalPages' directly on useScroll() is deprecated. Use useScroll().provides.getTotalPages instead.`,\n );\n }\n return provides?.getTotalPages;\n },\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 { useScrollPlugin } from '../hooks';\n\nexport interface 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 { plugin: scrollPlugin } = useScrollPlugin();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollPlugin?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollPlugin) return;\n\n return scrollPlugin.onScrollerData(setScrollerLayout);\n }, [scrollPlugin]);\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","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","provides","currentPage","setCurrentPage","totalPages","setTotalPages","onPageChange","state","console","warn","scrollToPage","scrollToNextPage","scrollToPreviousPage","getMetrics","onScroll","onLayoutChange","getCurrentPage","getTotalPages"],"mappings":"+MAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EA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UK,eACJE,QAAAC,KACN,kHAGa,MAAVR,OAAU,EAAAA,EAAAK,YACnB,EAEA,YAAIQ,GAMF,aALIb,WAAUa,WACJN,QAAAC,KACN,0GAGa,MAAVR,OAAU,EAAAA,EAAAa,QACnB,EAEA,kBAAIC,GAMF,aALId,WAAUc,iBACJP,QAAAC,KACN,sHAGa,MAAVR,OAAU,EAAAA,EAAAc,cACnB,EAEA,kBAAIC,GAMF,aALIf,WAAUe,iBACJR,QAAAC,KACN,sHAGa,MAAVR,OAAU,EAAAA,EAAAe,cACnB,EAEA,iBAAIC,GAMF,aALIhB,WAAUgB,gBACJT,QAAAC,KACN,oHAGa,MAAVR,OAAU,EAAAA,EAAAgB,aAAA,EAErB"}
@@ -1,38 +1,125 @@
1
+ import { useState, useEffect } from "react";
1
2
  import { usePlugin, useCapability, useRegistry } from "@embedpdf/core/react";
2
3
  import { ScrollPlugin, ScrollStrategy } from "@embedpdf/plugin-scroll";
3
4
  export * from "@embedpdf/plugin-scroll";
4
- import { useState, useEffect } from "react";
5
5
  import { jsxs, jsx } from "react/jsx-runtime";
6
6
  const useScrollPlugin = () => usePlugin(ScrollPlugin.id);
7
7
  const useScrollCapability = () => useCapability(ScrollPlugin.id);
8
8
  const useScroll = () => {
9
- const { provides: scroll } = useScrollCapability();
9
+ const { provides } = useScrollCapability();
10
10
  const [currentPage, setCurrentPage] = useState(1);
11
11
  const [totalPages, setTotalPages] = useState(1);
12
12
  useEffect(() => {
13
- if (!scroll) return;
14
- return scroll.onPageChange(({ pageNumber, totalPages: totalPages2 }) => {
13
+ if (!provides) return;
14
+ return provides.onPageChange(({ pageNumber, totalPages: totalPages2 }) => {
15
15
  setCurrentPage(pageNumber);
16
16
  setTotalPages(totalPages2);
17
17
  });
18
- }, [scroll]);
18
+ }, [provides]);
19
19
  return {
20
- ...scroll,
21
- currentPage,
22
- totalPages
20
+ // New format (preferred)
21
+ provides,
22
+ state: {
23
+ currentPage,
24
+ totalPages
25
+ },
26
+ // Deprecated properties with getters that show warnings
27
+ get currentPage() {
28
+ console.warn(
29
+ `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`
30
+ );
31
+ return currentPage;
32
+ },
33
+ get totalPages() {
34
+ console.warn(
35
+ `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`
36
+ );
37
+ return totalPages;
38
+ },
39
+ get scrollToPage() {
40
+ if (provides == null ? void 0 : provides.scrollToPage) {
41
+ console.warn(
42
+ `Accessing 'scrollToPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPage instead.`
43
+ );
44
+ }
45
+ return provides == null ? void 0 : provides.scrollToPage;
46
+ },
47
+ get scrollToNextPage() {
48
+ if (provides == null ? void 0 : provides.scrollToNextPage) {
49
+ console.warn(
50
+ `Accessing 'scrollToNextPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToNextPage instead.`
51
+ );
52
+ }
53
+ return provides == null ? void 0 : provides.scrollToNextPage;
54
+ },
55
+ get scrollToPreviousPage() {
56
+ if (provides == null ? void 0 : provides.scrollToPreviousPage) {
57
+ console.warn(
58
+ `Accessing 'scrollToPreviousPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPreviousPage instead.`
59
+ );
60
+ }
61
+ return provides == null ? void 0 : provides.scrollToPreviousPage;
62
+ },
63
+ get getMetrics() {
64
+ if (provides == null ? void 0 : provides.getMetrics) {
65
+ console.warn(
66
+ `Accessing 'getMetrics' directly on useScroll() is deprecated. Use useScroll().provides.getMetrics instead.`
67
+ );
68
+ }
69
+ return provides == null ? void 0 : provides.getMetrics;
70
+ },
71
+ get onPageChange() {
72
+ if (provides == null ? void 0 : provides.onPageChange) {
73
+ console.warn(
74
+ `Accessing 'onPageChange' directly on useScroll() is deprecated. Use useScroll().provides.onPageChange instead.`
75
+ );
76
+ }
77
+ return provides == null ? void 0 : provides.onPageChange;
78
+ },
79
+ get onScroll() {
80
+ if (provides == null ? void 0 : provides.onScroll) {
81
+ console.warn(
82
+ `Accessing 'onScroll' directly on useScroll() is deprecated. Use useScroll().provides.onScroll instead.`
83
+ );
84
+ }
85
+ return provides == null ? void 0 : provides.onScroll;
86
+ },
87
+ get onLayoutChange() {
88
+ if (provides == null ? void 0 : provides.onLayoutChange) {
89
+ console.warn(
90
+ `Accessing 'onLayoutChange' directly on useScroll() is deprecated. Use useScroll().provides.onLayoutChange instead.`
91
+ );
92
+ }
93
+ return provides == null ? void 0 : provides.onLayoutChange;
94
+ },
95
+ get getCurrentPage() {
96
+ if (provides == null ? void 0 : provides.getCurrentPage) {
97
+ console.warn(
98
+ `Accessing 'getCurrentPage' directly on useScroll() is deprecated. Use useScroll().provides.getCurrentPage instead.`
99
+ );
100
+ }
101
+ return provides == null ? void 0 : provides.getCurrentPage;
102
+ },
103
+ get getTotalPages() {
104
+ if (provides == null ? void 0 : provides.getTotalPages) {
105
+ console.warn(
106
+ `Accessing 'getTotalPages' directly on useScroll() is deprecated. Use useScroll().provides.getTotalPages instead.`
107
+ );
108
+ }
109
+ return provides == null ? void 0 : provides.getTotalPages;
110
+ }
23
111
  };
24
112
  };
25
113
  function Scroller({ renderPage, overlayElements, ...props }) {
26
- const { provides: scrollProvides } = useScrollCapability();
27
114
  const { plugin: scrollPlugin } = useScrollPlugin();
28
115
  const { registry } = useRegistry();
29
116
  const [scrollerLayout, setScrollerLayout] = useState(
30
- () => (scrollProvides == null ? void 0 : scrollProvides.getScrollerLayout()) ?? null
117
+ () => (scrollPlugin == null ? void 0 : scrollPlugin.getScrollerLayout()) ?? null
31
118
  );
32
119
  useEffect(() => {
33
- if (!scrollProvides) return;
34
- return scrollProvides.onScrollerData(setScrollerLayout);
35
- }, [scrollProvides]);
120
+ if (!scrollPlugin) return;
121
+ return scrollPlugin.onScrollerData(setScrollerLayout);
122
+ }, [scrollPlugin]);
36
123
  useEffect(() => {
37
124
  if (!scrollPlugin) return;
38
125
  scrollPlugin.setLayoutReady();
@@ -1 +1 @@
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\nexport interface 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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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;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-scroll.ts","../../src/shared/components/scroller.tsx"],"sourcesContent":["import { useState, useEffect } from '@framework';\nimport { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ScrollCapability, ScrollPlugin } from '@embedpdf/plugin-scroll';\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 // Deprecated properties (for backward compatibility)\n readonly currentPage: number;\n readonly totalPages: number;\n readonly scrollToPage: ScrollCapability['scrollToPage'] | undefined;\n readonly scrollToNextPage: ScrollCapability['scrollToNextPage'] | undefined;\n readonly scrollToPreviousPage: ScrollCapability['scrollToPreviousPage'] | undefined;\n readonly getMetrics: ScrollCapability['getMetrics'] | undefined;\n readonly onPageChange: ScrollCapability['onPageChange'] | undefined;\n readonly onScroll: ScrollCapability['onScroll'] | undefined;\n readonly onLayoutChange: ScrollCapability['onLayoutChange'] | undefined;\n readonly getCurrentPage: ScrollCapability['getCurrentPage'] | undefined;\n readonly getTotalPages: ScrollCapability['getTotalPages'] | undefined;\n}\n\nexport const useScroll = (): UseScrollReturn => {\n const { provides } = useScrollCapability();\n const [currentPage, setCurrentPage] = useState(1);\n const [totalPages, setTotalPages] = useState(1);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onPageChange(({ pageNumber, totalPages }) => {\n setCurrentPage(pageNumber);\n setTotalPages(totalPages);\n });\n }, [provides]);\n\n return {\n // New format (preferred)\n provides,\n state: {\n currentPage,\n totalPages,\n },\n\n // Deprecated properties with getters that show warnings\n get currentPage() {\n console.warn(\n `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`,\n );\n return currentPage;\n },\n\n get totalPages() {\n console.warn(\n `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`,\n );\n return totalPages;\n },\n\n get scrollToPage() {\n if (provides?.scrollToPage) {\n console.warn(\n `Accessing 'scrollToPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPage instead.`,\n );\n }\n return provides?.scrollToPage;\n },\n\n get scrollToNextPage() {\n if (provides?.scrollToNextPage) {\n console.warn(\n `Accessing 'scrollToNextPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToNextPage instead.`,\n );\n }\n return provides?.scrollToNextPage;\n },\n\n get scrollToPreviousPage() {\n if (provides?.scrollToPreviousPage) {\n console.warn(\n `Accessing 'scrollToPreviousPage' directly on useScroll() is deprecated. Use useScroll().provides.scrollToPreviousPage instead.`,\n );\n }\n return provides?.scrollToPreviousPage;\n },\n\n get getMetrics() {\n if (provides?.getMetrics) {\n console.warn(\n `Accessing 'getMetrics' directly on useScroll() is deprecated. Use useScroll().provides.getMetrics instead.`,\n );\n }\n return provides?.getMetrics;\n },\n\n get onPageChange() {\n if (provides?.onPageChange) {\n console.warn(\n `Accessing 'onPageChange' directly on useScroll() is deprecated. Use useScroll().provides.onPageChange instead.`,\n );\n }\n return provides?.onPageChange;\n },\n\n get onScroll() {\n if (provides?.onScroll) {\n console.warn(\n `Accessing 'onScroll' directly on useScroll() is deprecated. Use useScroll().provides.onScroll instead.`,\n );\n }\n return provides?.onScroll;\n },\n\n get onLayoutChange() {\n if (provides?.onLayoutChange) {\n console.warn(\n `Accessing 'onLayoutChange' directly on useScroll() is deprecated. Use useScroll().provides.onLayoutChange instead.`,\n );\n }\n return provides?.onLayoutChange;\n },\n\n get getCurrentPage() {\n if (provides?.getCurrentPage) {\n console.warn(\n `Accessing 'getCurrentPage' directly on useScroll() is deprecated. Use useScroll().provides.getCurrentPage instead.`,\n );\n }\n return provides?.getCurrentPage;\n },\n\n get getTotalPages() {\n if (provides?.getTotalPages) {\n console.warn(\n `Accessing 'getTotalPages' directly on useScroll() is deprecated. Use useScroll().provides.getTotalPages instead.`,\n );\n }\n return provides?.getTotalPages;\n },\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 { useScrollPlugin } from '../hooks';\n\nexport interface 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 { plugin: scrollPlugin } = useScrollPlugin();\n const { registry } = useRegistry();\n const [scrollerLayout, setScrollerLayout] = useState<ScrollerLayout | null>(\n () => scrollPlugin?.getScrollerLayout() ?? null,\n );\n\n useEffect(() => {\n if (!scrollPlugin) return;\n\n return scrollPlugin.onScrollerData(setScrollerLayout);\n }, [scrollPlugin]);\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;AAuB7E,MAAM,YAAY,MAAuB;AACxC,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AACh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AA,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;"}
@@ -1,32 +1,31 @@
1
- import { ScrollPlugin } from '../../lib/index.ts';
1
+ import { ScrollCapability, ScrollPlugin } from '../../lib/index.ts';
2
2
  export declare const useScrollPlugin: () => {
3
3
  plugin: ScrollPlugin | null;
4
4
  isLoading: boolean;
5
5
  ready: Promise<void>;
6
6
  };
7
7
  export declare const useScrollCapability: () => {
8
- provides: Readonly<import('../../lib/index.ts').ScrollCapability> | null;
8
+ provides: Readonly<ScrollCapability> | null;
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
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
- };
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 {};
@@ -1,32 +1,31 @@
1
- import { ScrollPlugin } from '../../lib/index.ts';
1
+ import { ScrollCapability, ScrollPlugin } from '../../lib/index.ts';
2
2
  export declare const useScrollPlugin: () => {
3
3
  plugin: ScrollPlugin | null;
4
4
  isLoading: boolean;
5
5
  ready: Promise<void>;
6
6
  };
7
7
  export declare const useScrollCapability: () => {
8
- provides: Readonly<import('../../lib/index.ts').ScrollCapability> | null;
8
+ provides: Readonly<ScrollCapability> | null;
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
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
- };
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 {};
@@ -1,11 +1,13 @@
1
1
  import { ScrollPlugin } from '../../lib/index.ts';
2
2
  export declare const useScrollPlugin: () => import('@embedpdf/core/vue').PluginState<ScrollPlugin>;
3
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
4
  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>;
5
+ provides: import('vue').Ref<Readonly<import('../../lib/index.ts').ScrollCapability> | null, Readonly<import('../../lib/index.ts').ScrollCapability> | null>;
6
+ state: import('vue').ComputedRef<{
7
+ currentPage: number;
8
+ totalPages: number;
9
+ }>;
10
+ currentPage: import('vue').WritableComputedRef<number, number>;
11
+ totalPages: import('vue').WritableComputedRef<number, number>;
12
+ scroll: import('vue').ComputedRef<Readonly<import('../../lib/index.ts').ScrollCapability> | null>;
11
13
  };
@@ -1,2 +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,Object.keys(l).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>l[e]})}));
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(o){const a=o,n=e.useAttrs(),{plugin:i}=r(),{registry:c}=t.useRegistry(),s=e.ref(null);function u(e){const t=c.value.getStore().getState().core;return{...e,rotation:t.rotation,scale:t.scale,document:t.document}}e.watchEffect((e=>{if(!i.value)return;s.value=i.value.getScrollerLayout();e(i.value.onScrollerData((e=>s.value=e)))})),e.onMounted((()=>{var e;null==(e=i.value)||e.setLayoutReady()}));const p=e.computed((()=>{if(!s.value)return a.style;return["object"!=typeof a.style||Array.isArray(a.style)?a.style??{}:{...a.style},{width:`${s.value.totalWidth}px`,height:`${s.value.totalHeight}px`,position:"relative",boxSizing:"border-box",margin:"0 auto",...s.value.strategy===l.ScrollStrategy.Horizontal&&{display:"flex",flexDirection:"row"}}]}));return(t,l)=>s.value&&e.unref(c)?(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:0,style:p.value},e.unref(n)),["horizontal"===s.value.strategy?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle({width:s.value.startSpacing+"px",height:"100%",flexShrink:0})},null,4)):(e.openBlock(),e.createElementBlock("div",{key:1,style:e.normalizeStyle({height:s.value.startSpacing+"px",width:"100%"})},null,4)),e.createElementVNode("div",{style:e.normalizeStyle({gap:s.value.pageGap+"px",display:"flex",alignItems:"center",position:"relative",boxSizing:"border-box",flexDirection:"horizontal"===s.value.strategy?"row":"column",minHeight:"horizontal"===s.value.strategy?"100%":void 0,minWidth:"vertical"===s.value.strategy?"fit-content":void 0})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value.items,(l=>(e.openBlock(),e.createElementBlock("div",{key:l.pageNumbers[0],style:e.normalizeStyle({display:"flex",justifyContent:"center",gap:s.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:u(l)})],4)))),128))],4)))),128))],4),"horizontal"===s.value.strategy?(e.openBlock(),e.createElementBlock("div",{key:2,style:e.normalizeStyle({width:s.value.endSpacing+"px",height:"100%",flexShrink:0})},null,4)):(e.openBlock(),e.createElementBlock("div",{key:3,style:e.normalizeStyle({height:s.value.endSpacing+"px",width:"100%"})},null,4)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.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);e.watchEffect((e=>{if(!t.value)return;e(t.value.onPageChange((({pageNumber:e,totalPages:t})=>{l.value=e,r.value=t})))}));const a=e.computed((()=>({currentPage:l.value,totalPages:r.value}))),n=e.computed({get:()=>(console.warn("Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead."),l.value),set(e){l.value=e}}),i=e.computed({get:()=>(console.warn("Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead."),r.value),set(e){r.value=e}}),c=e.computed((()=>(t.value&&console.warn("Accessing 'scroll' directly on useScroll() is deprecated. Use useScroll().provides instead."),t.value)));return{provides:t,state:a,currentPage:n,totalPages:i,scroll:c}},exports.useScrollCapability=o,exports.useScrollPlugin=r,Object.keys(l).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>l[e]})}));
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +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,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ACAC,aAEJ"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-scroll.ts","../../src/vue/components/scroller.vue"],"sourcesContent":["import { ref, watchEffect, computed } 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\nexport function useScroll() {\n const { provides } = useScrollCapability();\n\n const currentPage = ref(1);\n const totalPages = ref(1);\n\n watchEffect((onCleanup) => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onPageChange(({ pageNumber, totalPages: tp }) => {\n currentPage.value = pageNumber;\n totalPages.value = tp;\n });\n onCleanup(unsubscribe);\n });\n\n // New format\n const state = computed(() => ({\n currentPage: currentPage.value,\n totalPages: totalPages.value,\n }));\n\n // Create deprecated properties with warnings\n const deprecatedCurrentPage = computed({\n get() {\n console.warn(\n `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`,\n );\n return currentPage.value;\n },\n set(value) {\n currentPage.value = value;\n },\n });\n\n const deprecatedTotalPages = computed({\n get() {\n console.warn(\n `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`,\n );\n return totalPages.value;\n },\n set(value) {\n totalPages.value = value;\n },\n });\n\n const deprecatedScroll = computed(() => {\n if (provides.value) {\n console.warn(\n `Accessing 'scroll' directly on useScroll() is deprecated. Use useScroll().provides instead.`,\n );\n }\n return provides.value;\n });\n\n return {\n // New format (preferred)\n provides,\n state,\n\n // Deprecated properties (for backward compatibility)\n currentPage: deprecatedCurrentPage,\n totalPages: deprecatedTotalPages,\n scroll: deprecatedScroll,\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 { 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 { 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 (!scrollPlugin.value) return;\n\n layout.value = scrollPlugin.value.getScrollerLayout();\n const off = scrollPlugin.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","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","provides","currentPage","totalPages","onPageChange","tp","state","deprecatedCurrentPage","get","console","warn","set","deprecatedTotalPages","deprecatedScroll","scroll"],"mappings":"4KAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,mJCUlF,MAAMG,EAAQC,EAQRC,EAAQC,EAAAA,YAKNC,OAAQC,GAAiBX,KAC3BY,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,IAAChB,EAAaQ,MAAO,OAElBL,EAAAK,MAAQR,EAAaQ,MAAMS,oBAElCD,EADYhB,EAAaQ,MAAMU,gBAAgBC,GAAOhB,EAAOK,MAAQW,IACxD,IAIfC,EAAAA,WAAU,WACR,OAAAC,EAAArB,EAAaQ,QAAOa,EAAAC,gBAAA,IA0BhB,MAAAC,EAAYC,EAAAA,UAAqB,KACrC,IAAKrB,EAAOK,MAAO,OAAOb,EAAM8B,MAOzB,MAAA,CAJkB,iBAAhB9B,EAAM8B,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AgF,CAAIhF,GACFwE,EAAWxE,MAAQA,CAAA,IAIjBkF,EAAmBlE,EAAAA,UAAS,KAC5BsD,EAAStE,OACH8E,QAAAC,KACN,+FAGGT,EAAStE,SAGX,MAAA,CAELsE,WACAK,QAGAJ,YAAaK,EACbJ,WAAYS,EACZE,OAAQD,EAEZ"}
package/dist/vue/index.js CHANGED
@@ -1,25 +1,63 @@
1
- import { ref, watchEffect, defineComponent, useAttrs, onMounted, computed, createElementBlock, createCommentVNode, unref, openBlock, mergeProps, createElementVNode, normalizeStyle, Fragment, renderList, renderSlot, createBlock, resolveDynamicComponent } from "vue";
2
- import { useCapability, usePlugin, useRegistry } from "@embedpdf/core/vue";
1
+ import { ref, watchEffect, computed, defineComponent, useAttrs, onMounted, createElementBlock, createCommentVNode, unref, openBlock, mergeProps, createElementVNode, normalizeStyle, Fragment, renderList, renderSlot, createBlock, resolveDynamicComponent } from "vue";
2
+ import { usePlugin, useCapability, useRegistry } from "@embedpdf/core/vue";
3
3
  import { ScrollPlugin, ScrollStrategy } from "@embedpdf/plugin-scroll";
4
4
  export * from "@embedpdf/plugin-scroll";
5
5
  const useScrollPlugin = () => usePlugin(ScrollPlugin.id);
6
6
  const useScrollCapability = () => useCapability(ScrollPlugin.id);
7
7
  function useScroll() {
8
- const { provides: scroll } = useScrollCapability();
8
+ const { provides } = useScrollCapability();
9
9
  const currentPage = ref(1);
10
10
  const totalPages = ref(1);
11
11
  watchEffect((onCleanup) => {
12
- if (!scroll.value) return;
13
- const off = scroll.value.onPageChange(({ pageNumber, totalPages: tp }) => {
12
+ if (!provides.value) return;
13
+ const unsubscribe = provides.value.onPageChange(({ pageNumber, totalPages: tp }) => {
14
14
  currentPage.value = pageNumber;
15
15
  totalPages.value = tp;
16
16
  });
17
- onCleanup(off);
17
+ onCleanup(unsubscribe);
18
+ });
19
+ const state = computed(() => ({
20
+ currentPage: currentPage.value,
21
+ totalPages: totalPages.value
22
+ }));
23
+ const deprecatedCurrentPage = computed({
24
+ get() {
25
+ console.warn(
26
+ `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`
27
+ );
28
+ return currentPage.value;
29
+ },
30
+ set(value) {
31
+ currentPage.value = value;
32
+ }
33
+ });
34
+ const deprecatedTotalPages = computed({
35
+ get() {
36
+ console.warn(
37
+ `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`
38
+ );
39
+ return totalPages.value;
40
+ },
41
+ set(value) {
42
+ totalPages.value = value;
43
+ }
44
+ });
45
+ const deprecatedScroll = computed(() => {
46
+ if (provides.value) {
47
+ console.warn(
48
+ `Accessing 'scroll' directly on useScroll() is deprecated. Use useScroll().provides instead.`
49
+ );
50
+ }
51
+ return provides.value;
18
52
  });
19
53
  return {
20
- scroll,
21
- currentPage,
22
- totalPages
54
+ // New format (preferred)
55
+ provides,
56
+ state,
57
+ // Deprecated properties (for backward compatibility)
58
+ currentPage: deprecatedCurrentPage,
59
+ totalPages: deprecatedTotalPages,
60
+ scroll: deprecatedScroll
23
61
  };
24
62
  }
25
63
  const _sfc_main = /* @__PURE__ */ defineComponent({
@@ -31,14 +69,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
31
69
  setup(__props) {
32
70
  const props = __props;
33
71
  const attrs = useAttrs();
34
- const { provides: scrollProvides } = useScrollCapability();
35
72
  const { plugin: scrollPlugin } = useScrollPlugin();
36
73
  const { registry } = useRegistry();
37
74
  const layout = ref(null);
38
75
  watchEffect((onCleanup) => {
39
- if (!scrollProvides.value) return;
40
- layout.value = scrollProvides.value.getScrollerLayout();
41
- const off = scrollProvides.value.onScrollerData((l) => layout.value = l);
76
+ if (!scrollPlugin.value) return;
77
+ layout.value = scrollPlugin.value.getScrollerLayout();
78
+ const off = scrollPlugin.value.onScrollerData((l) => layout.value = l);
42
79
  onCleanup(off);
43
80
  });
44
81
  onMounted(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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":["_unref","_openBlock","_createElementBlock","_mergeProps","_normalizeStyle","_createElementVNode","_Fragment","_renderList","_renderSlot","_createBlock","_resolveDynamicComponent"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAK7E,SAAS,YAAY;AAC1B,QAAM,EAAE,UAAU,OAAO,IAAI,oBAAoB;AAE3C,QAAA,cAAc,IAAI,CAAC;AACnB,QAAA,aAAa,IAAI,CAAC;AAExB,cAAY,CAAC,cAAc;AACrB,QAAA,CAAC,OAAO,MAAO;AAEb,UAAA,MAAM,OAAO,MAAM,aAAa,CAAC,EAAE,YAAY,YAAY,SAAS;AACxE,kBAAY,QAAQ;AACpB,iBAAW,QAAQ;AAAA,IAAA,CACpB;AACD,cAAU,GAAG;AAAA,EAAA,CACd;AAEM,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;;;;;;AChBA,UAAM,QAAQ;AAQd,UAAM,QAAQ,SAAS;AAKvB,UAAM,EAAE,UAAU,eAAe,IAAI,oBAAo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AAKE,eAAA,EAAA,QAAY,OAAM,MAAC,aAAU,MAAA,OAAA,OAAA,CAAA;AAAA,QAAA;SAG/CH,UAAA,IAAA,GAAAC,mBAAwEI,2BAA3C,MAAM,iBAAhB,CAAA,IAAI,MAAC;AAAxB,iBAAAL,UAAA,GAAAQ,YAAwEC,wBAAf,EAAE,GAAG,EAAA,KAAK,GAAC;AAAA;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-scroll.ts","../../src/vue/components/scroller.vue"],"sourcesContent":["import { ref, watchEffect, computed } 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\nexport function useScroll() {\n const { provides } = useScrollCapability();\n\n const currentPage = ref(1);\n const totalPages = ref(1);\n\n watchEffect((onCleanup) => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onPageChange(({ pageNumber, totalPages: tp }) => {\n currentPage.value = pageNumber;\n totalPages.value = tp;\n });\n onCleanup(unsubscribe);\n });\n\n // New format\n const state = computed(() => ({\n currentPage: currentPage.value,\n totalPages: totalPages.value,\n }));\n\n // Create deprecated properties with warnings\n const deprecatedCurrentPage = computed({\n get() {\n console.warn(\n `Accessing 'currentPage' directly on useScroll() is deprecated. Use useScroll().state.currentPage instead.`,\n );\n return currentPage.value;\n },\n set(value) {\n currentPage.value = value;\n },\n });\n\n const deprecatedTotalPages = computed({\n get() {\n console.warn(\n `Accessing 'totalPages' directly on useScroll() is deprecated. Use useScroll().state.totalPages instead.`,\n );\n return totalPages.value;\n },\n set(value) {\n totalPages.value = value;\n },\n });\n\n const deprecatedScroll = computed(() => {\n if (provides.value) {\n console.warn(\n `Accessing 'scroll' directly on useScroll() is deprecated. Use useScroll().provides instead.`,\n );\n }\n return provides.value;\n });\n\n return {\n // New format (preferred)\n provides,\n state,\n\n // Deprecated properties (for backward compatibility)\n currentPage: deprecatedCurrentPage,\n totalPages: deprecatedTotalPages,\n scroll: deprecatedScroll,\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 { 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 { 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 (!scrollPlugin.value) return;\n\n layout.value = scrollPlugin.value.getScrollerLayout();\n const off = scrollPlugin.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":["_unref","_openBlock","_createElementBlock","_mergeProps","_normalizeStyle","_createElementVNode","_Fragment","_renderList","_renderSlot","_createBlock","_resolveDynamicComponent"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,SAAS,YAAY;AACpB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AAEnC,QAAA,cAAc,IAAI,CAAC;AACnB,QAAA,aAAa,IAAI,CAAC;AAExB,cAAY,CAAC,cAAc;AACrB,QAAA,CAAC,SAAS,MAAO;AAEf,UAAA,cAAc,SAAS,MAAM,aAAa,CAAC,EAAE,YAAY,YAAY,SAAS;AAClF,kBAAY,QAAQ;AACpB,iBAAW,QAAQ;AAAA,IAAA,CACpB;AACD,cAAU,WAAW;AAAA,EAAA,CACtB;AAGK,QAAA,QAAQ,SAAS,OAAO;AAAA,IAC5B,aAAa,YAAY;AAAA,IACzB,YAAY,WAAW;AAAA,EAAA,EACvB;AAGF,QAAM,wBAAwB,SAAS;AAAA,IACrC,MAAM;AACI,cAAA;AAAA,QACN;AAAA,MACF;AACA,aAAO,YAAY;AAAA,IACrB;AAAA,IACA,IAAI,OAAO;AACT,kBAAY,QAAQ;AAAA,IAAA;AAAA,EACtB,CACD;AAED,QAAM,uBAAuB,SAAS;AAAA,IACpC,MAAM;AACI,cAAA;AAAA,QACN;AAAA,MACF;AACA,aAAO,WAAW;AAAA,IACpB;AAAA,IACA,IAAI,OAAO;AACT,iBAAW,QAAQ;AAAA,IAAA;AAAA,EACrB,CACD;AAEK,QAAA,mBAAmB,SAAS,MAAM;AACtC,QAAI,SAAS,OAAO;AACV,cAAA;AAAA,QACN;AAAA,MACF;AAAA,IAAA;AAEF,WAAO,SAAS;AAAA,EAAA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