@embedpdf/plugin-scroll 1.5.0 → 2.0.0-next.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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +522 -266
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +30 -27
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/reducer.d.ts +3 -4
- package/dist/lib/scroll-plugin.d.ts +40 -27
- package/dist/lib/selectors.d.ts +2 -2
- package/dist/lib/types.d.ts +65 -30
- package/dist/preact/adapter.d.ts +1 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +33 -114
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +33 -114
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/scroller.d.ts +4 -4
- package/dist/shared/hooks/use-scroll.d.ts +4 -15
- package/dist/shared-preact/components/scroller.d.ts +4 -4
- package/dist/shared-preact/hooks/use-scroll.d.ts +4 -15
- package/dist/shared-react/components/scroller.d.ts +4 -4
- package/dist/shared-react/hooks/use-scroll.d.ts +4 -15
- package/dist/svelte/components/Scroller.svelte.d.ts +4 -4
- package/dist/svelte/hooks/use-scroll.svelte.d.ts +11 -5
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +90 -102
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/scroller.vue.d.ts +6 -9
- package/dist/vue/hooks/use-scroll.d.ts +12 -8
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +115 -115
- package/dist/vue/index.js.map +1 -1
- package/package.json +7 -6
package/dist/vue/index.js
CHANGED
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
import { ref,
|
|
2
|
-
import { usePlugin, useCapability
|
|
1
|
+
import { ref, watch, toValue, computed, defineComponent, createElementBlock, createCommentVNode, openBlock, mergeProps, unref, createElementVNode, normalizeStyle, Fragment, renderList, renderSlot } from "vue";
|
|
2
|
+
import { usePlugin, useCapability } 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
|
-
function useScroll() {
|
|
7
|
+
function useScroll(documentId) {
|
|
8
8
|
const { provides } = useScrollCapability();
|
|
9
9
|
const currentPage = ref(1);
|
|
10
10
|
const totalPages = ref(1);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
watch(
|
|
12
|
+
[provides, () => toValue(documentId)],
|
|
13
|
+
([providesValue, docId], _, onCleanup) => {
|
|
14
|
+
if (!providesValue || !docId) {
|
|
15
|
+
currentPage.value = 1;
|
|
16
|
+
totalPages.value = 1;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const scope = providesValue.forDocument(docId);
|
|
20
|
+
currentPage.value = scope.getCurrentPage();
|
|
21
|
+
totalPages.value = scope.getTotalPages();
|
|
22
|
+
const unsubscribe = providesValue.onPageChange((event) => {
|
|
23
|
+
if (event.documentId === docId) {
|
|
24
|
+
currentPage.value = event.pageNumber;
|
|
25
|
+
totalPages.value = event.totalPages;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
onCleanup(unsubscribe);
|
|
29
|
+
},
|
|
30
|
+
{ immediate: true }
|
|
31
|
+
);
|
|
19
32
|
const state = computed(() => ({
|
|
20
33
|
currentPage: currentPage.value,
|
|
21
34
|
totalPages: totalPages.value
|
|
22
35
|
}));
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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;
|
|
36
|
+
const scopedProvides = computed(() => {
|
|
37
|
+
var _a;
|
|
38
|
+
const docId = toValue(documentId);
|
|
39
|
+
return ((_a = provides.value) == null ? void 0 : _a.forDocument(docId)) ?? null;
|
|
52
40
|
});
|
|
53
41
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
state,
|
|
57
|
-
// Deprecated properties (for backward compatibility)
|
|
58
|
-
currentPage: deprecatedCurrentPage,
|
|
59
|
-
totalPages: deprecatedTotalPages,
|
|
60
|
-
scroll: deprecatedScroll
|
|
42
|
+
provides: scopedProvides,
|
|
43
|
+
state
|
|
61
44
|
};
|
|
62
45
|
}
|
|
63
46
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
64
47
|
__name: "scroller",
|
|
65
48
|
props: {
|
|
66
|
-
|
|
67
|
-
overlayElements: { default: () => [] }
|
|
49
|
+
documentId: {}
|
|
68
50
|
},
|
|
69
51
|
setup(__props) {
|
|
70
52
|
const props = __props;
|
|
71
|
-
const attrs = useAttrs();
|
|
72
53
|
const { plugin: scrollPlugin } = useScrollPlugin();
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
54
|
+
const layoutData = ref({ layout: null, docId: null });
|
|
55
|
+
watch(
|
|
56
|
+
[scrollPlugin, () => props.documentId],
|
|
57
|
+
([plugin, docId], _, onCleanup) => {
|
|
58
|
+
if (!plugin || !docId) {
|
|
59
|
+
layoutData.value = { layout: null, docId: null };
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const unsubscribe = plugin.onScrollerData(docId, (newLayout) => {
|
|
63
|
+
layoutData.value = { layout: newLayout, docId };
|
|
64
|
+
});
|
|
65
|
+
onCleanup(() => {
|
|
66
|
+
unsubscribe();
|
|
67
|
+
layoutData.value = { layout: null, docId: null };
|
|
68
|
+
plugin.clearLayoutReady(docId);
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
immediate: true
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
const scrollerLayout = computed(() => {
|
|
76
|
+
return layoutData.value.docId === props.documentId ? layoutData.value.layout : null;
|
|
84
77
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
width: `${layout.value.totalWidth}px`,
|
|
101
|
-
height: `${layout.value.totalHeight}px`,
|
|
78
|
+
watch(
|
|
79
|
+
[scrollPlugin, () => props.documentId, scrollerLayout],
|
|
80
|
+
([plugin, docId, layout]) => {
|
|
81
|
+
if (!plugin || !docId || !layout) return;
|
|
82
|
+
plugin.setLayoutReady(docId);
|
|
83
|
+
},
|
|
84
|
+
{ immediate: true }
|
|
85
|
+
);
|
|
86
|
+
return (_ctx, _cache) => {
|
|
87
|
+
return scrollerLayout.value ? (openBlock(), createElementBlock("div", mergeProps({
|
|
88
|
+
key: 0,
|
|
89
|
+
style: {
|
|
90
|
+
width: `${scrollerLayout.value.totalWidth}px`,
|
|
91
|
+
height: `${scrollerLayout.value.totalHeight}px`,
|
|
102
92
|
position: "relative",
|
|
103
93
|
boxSizing: "border-box",
|
|
104
94
|
margin: "0 auto",
|
|
105
|
-
...
|
|
95
|
+
...scrollerLayout.value.strategy === unref(ScrollStrategy).Horizontal && {
|
|
106
96
|
display: "flex",
|
|
107
97
|
flexDirection: "row"
|
|
108
98
|
}
|
|
109
99
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}, null, 4)),
|
|
100
|
+
}, _ctx.$attrs), [
|
|
101
|
+
createElementVNode("div", {
|
|
102
|
+
style: normalizeStyle(
|
|
103
|
+
scrollerLayout.value.strategy === unref(ScrollStrategy).Horizontal ? {
|
|
104
|
+
width: `${scrollerLayout.value.startSpacing}px`,
|
|
105
|
+
height: "100%",
|
|
106
|
+
flexShrink: 0
|
|
107
|
+
} : {
|
|
108
|
+
height: `${scrollerLayout.value.startSpacing}px`,
|
|
109
|
+
width: "100%"
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
}, null, 4),
|
|
124
113
|
createElementVNode("div", {
|
|
125
114
|
style: normalizeStyle({
|
|
126
|
-
gap:
|
|
115
|
+
gap: `${scrollerLayout.value.pageGap}px`,
|
|
127
116
|
display: "flex",
|
|
128
117
|
alignItems: "center",
|
|
129
118
|
position: "relative",
|
|
130
119
|
boxSizing: "border-box",
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
120
|
+
...scrollerLayout.value.strategy === unref(ScrollStrategy).Horizontal ? {
|
|
121
|
+
flexDirection: "row",
|
|
122
|
+
minHeight: "100%"
|
|
123
|
+
} : {
|
|
124
|
+
flexDirection: "column",
|
|
125
|
+
minWidth: "fit-content"
|
|
126
|
+
}
|
|
134
127
|
})
|
|
135
128
|
}, [
|
|
136
|
-
(openBlock(true), createElementBlock(Fragment, null, renderList(
|
|
129
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(scrollerLayout.value.items, (item) => {
|
|
137
130
|
return openBlock(), createElementBlock("div", {
|
|
138
131
|
key: item.pageNumbers[0],
|
|
139
|
-
style: normalizeStyle({
|
|
132
|
+
style: normalizeStyle({
|
|
133
|
+
display: "flex",
|
|
134
|
+
justifyContent: "center",
|
|
135
|
+
gap: `${scrollerLayout.value.pageGap}px`
|
|
136
|
+
})
|
|
140
137
|
}, [
|
|
141
|
-
(openBlock(true), createElementBlock(Fragment, null, renderList(item.pageLayouts, (
|
|
138
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(item.pageLayouts, (layout) => {
|
|
142
139
|
return openBlock(), createElementBlock("div", {
|
|
143
|
-
key:
|
|
144
|
-
style: normalizeStyle({
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
page: pageSlotProps(pl)
|
|
140
|
+
key: layout.pageNumber,
|
|
141
|
+
style: normalizeStyle({
|
|
142
|
+
width: `${layout.rotatedWidth}px`,
|
|
143
|
+
height: `${layout.rotatedHeight}px`
|
|
148
144
|
})
|
|
145
|
+
}, [
|
|
146
|
+
renderSlot(_ctx.$slots, "default", { page: layout })
|
|
149
147
|
], 4);
|
|
150
148
|
}), 128))
|
|
151
149
|
], 4);
|
|
152
150
|
}), 128))
|
|
153
151
|
], 4),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
createElementVNode("div", {
|
|
153
|
+
style: normalizeStyle(
|
|
154
|
+
scrollerLayout.value.strategy === unref(ScrollStrategy).Horizontal ? {
|
|
155
|
+
width: `${scrollerLayout.value.endSpacing}px`,
|
|
156
|
+
height: "100%",
|
|
157
|
+
flexShrink: 0
|
|
158
|
+
} : {
|
|
159
|
+
height: `${scrollerLayout.value.endSpacing}px`,
|
|
160
|
+
width: "100%"
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
}, null, 4)
|
|
164
164
|
], 16)) : createCommentVNode("", true);
|
|
165
165
|
};
|
|
166
166
|
}
|
package/dist/vue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { RenderPageProps } from '../../shared/types';\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/** Build the prop object that we’ll forward into the default slot */\nfunction pageSlotProps(pl: PageLayout): RenderPageProps {\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;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Q7B,OAAA,MAAO,aAAQ,6BADvBN,mBAGE,OAAA;AAAA;UADC,OAAKE,eAAA,EAAA,OAAW,OAAM,MAAC,aAAU,MAAA,QAAA,QAAA,YAAA,EAAA,CAAA;AAAA,QAAA,6BAEpCF,mBAA2E,OAAA;AAAA;UAA9D,OAAKE,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, watch, computed, toValue, type MaybeRefOrGetter, type ComputedRef } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ScrollPlugin, ScrollScope } 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: ComputedRef<ScrollScope | null>;\n state: ComputedRef<{\n currentPage: number;\n totalPages: number;\n }>;\n}\n\n/**\n * Hook for scroll state for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport function useScroll(documentId: MaybeRefOrGetter<string>): UseScrollReturn {\n const { provides } = useScrollCapability();\n\n const currentPage = ref(1);\n const totalPages = ref(1);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue || !docId) {\n currentPage.value = 1;\n totalPages.value = 1;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Get initial state\n currentPage.value = scope.getCurrentPage();\n totalPages.value = scope.getTotalPages();\n\n const unsubscribe = providesValue.onPageChange((event) => {\n if (event.documentId === docId) {\n currentPage.value = event.pageNumber;\n totalPages.value = event.totalPages;\n }\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n const state = computed(() => ({\n currentPage: currentPage.value,\n totalPages: totalPages.value,\n }));\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n state,\n };\n}\n","<script setup lang=\"ts\">\nimport { ref, watch, computed } from 'vue';\nimport { useScrollPlugin } from '../hooks';\nimport { ScrollStrategy, type ScrollerLayout } from '@embedpdf/plugin-scroll';\n\ninterface ScrollerProps {\n documentId: string;\n}\n\nconst props = defineProps<ScrollerProps>();\n\nconst { plugin: scrollPlugin } = useScrollPlugin();\n\nconst layoutData = ref<{\n layout: ScrollerLayout | null;\n docId: string | null;\n}>({ layout: null, docId: null });\n\nwatch(\n [scrollPlugin, () => props.documentId],\n ([plugin, docId], _, onCleanup) => {\n if (!plugin || !docId) {\n layoutData.value = { layout: null, docId: null };\n return;\n }\n\n // Subscribe to the new document\n const unsubscribe = plugin.onScrollerData(docId, (newLayout) => {\n layoutData.value = { layout: newLayout, docId };\n });\n\n onCleanup(() => {\n unsubscribe();\n layoutData.value = { layout: null, docId: null };\n plugin.clearLayoutReady(docId);\n });\n },\n {\n immediate: true,\n },\n);\n\n// Only use layout if it matches the current documentId (prevents stale data)\nconst scrollerLayout = computed(() => {\n return layoutData.value.docId === props.documentId ? layoutData.value.layout : null;\n});\n\n// Call setLayoutReady after layout is rendered (Vue's equivalent to useLayoutEffect)\nwatch(\n [scrollPlugin, () => props.documentId, scrollerLayout],\n ([plugin, docId, layout]) => {\n if (!plugin || !docId || !layout) return;\n\n plugin.setLayoutReady(docId);\n },\n { immediate: true },\n);\n</script>\n\n<template>\n <div\n v-if=\"scrollerLayout\"\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 v-bind=\"$attrs\"\n >\n <!-- Leading spacer -->\n <div\n :style=\"\n scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: `${scrollerLayout.startSpacing}px`,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: `${scrollerLayout.startSpacing}px`,\n width: '100%',\n }\n \"\n />\n\n <!-- Page grid -->\n <div\n :style=\"{\n gap: `${scrollerLayout.pageGap}px`,\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 <div\n v-for=\"item in scrollerLayout.items\"\n :key=\"item.pageNumbers[0]\"\n :style=\"{\n display: 'flex',\n justifyContent: 'center',\n gap: `${scrollerLayout.pageGap}px`,\n }\"\n >\n <div\n v-for=\"layout in item.pageLayouts\"\n :key=\"layout.pageNumber\"\n :style=\"{\n width: `${layout.rotatedWidth}px`,\n height: `${layout.rotatedHeight}px`,\n }\"\n >\n <slot :page=\"layout\" />\n </div>\n </div>\n </div>\n\n <!-- Trailing spacer -->\n <div\n :style=\"\n scrollerLayout.strategy === ScrollStrategy.Horizontal\n ? {\n width: `${scrollerLayout.endSpacing}px`,\n height: '100%',\n flexShrink: 0,\n }\n : {\n height: `${scrollerLayout.endSpacing}px`,\n width: '100%',\n }\n \"\n />\n </div>\n</template>\n"],"names":["_openBlock","_createElementBlock","_mergeProps","_unref","$attrs","_createElementVNode","_normalizeStyle","_Fragment","_renderList","_renderSlot"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAA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AA,GAAA,eAAA,MAAe,OAAO;AAAA;;;;YAAwI,GAAA,eAAA,MAAe,aAAaH,MAAA,cAAA,EAAe;;;;;;;;;WAiBnOH,UAAA,IAAA,GAAAC,mBAmBMM,UAAA,MAAAC,WAlBW,eAAA,MAAe,QAAvB,SAAI;gCADbP,mBAmBM,OAAA;AAAA,cAjBH,KAAK,KAAK,YAAW,CAAA;AAAA,cACrB,OAAKK,eAAA;AAAA;;gBAAqF,KAAA,GAAA,eAAA,MAAe,OAAO;AAAA,cAAA;;eAMjHN,UAAA,IAAA,GAAAC,mBASMM,UAAA,MAAAC,WARa,KAAK,cAAf,WAAM;oCADfP,mBASM,OAAA;AAAA,kBAPH,KAAK,OAAO;AAAA,kBACZ,OAAKK,eAAA;AAAA,oBAA0B,OAAA,GAAA,OAAO,YAAY;AAAA,oBAA6B,QAAA,GAAA,OAAO,aAAa;AAAA,kBAAA;;kBAKpGG,WAAuB,KAAA,QAAA,WAAA,EAAhB,MAAM,QAAM;AAAA,gBAAA;;;;;QAMzBJ,mBAaE,OAAA;AAAA,UAZC,OAAKC;AAAAA,YAAW,eAAA,MAAe,aAAaH,MAAA,cAAA,EAAe;cAAiD,OAAA,GAAA,eAAA,MAAe,UAAU;AAAA;;;cAAsH,QAAA,GAAA,eAAA,MAAe,UAAU;AAAA;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-scroll",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -35,14 +35,15 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@embedpdf/models": "
|
|
38
|
+
"@embedpdf/models": "2.0.0-next.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/react": "^18.2.0",
|
|
42
42
|
"typescript": "^5.0.0",
|
|
43
43
|
"@embedpdf/build": "1.1.0",
|
|
44
|
-
"@embedpdf/core": "
|
|
45
|
-
"@embedpdf/plugin-
|
|
44
|
+
"@embedpdf/core": "2.0.0-next.1",
|
|
45
|
+
"@embedpdf/plugin-spread": "2.0.0-next.1",
|
|
46
|
+
"@embedpdf/plugin-viewport": "2.0.0-next.1"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"preact": "^10.26.4",
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
"react-dom": ">=16.8.0",
|
|
51
52
|
"vue": ">=3.2.0",
|
|
52
53
|
"svelte": ">=5 <6",
|
|
53
|
-
"@embedpdf/
|
|
54
|
-
"@embedpdf/
|
|
54
|
+
"@embedpdf/core": "2.0.0-next.1",
|
|
55
|
+
"@embedpdf/plugin-viewport": "2.0.0-next.1"
|
|
55
56
|
},
|
|
56
57
|
"files": [
|
|
57
58
|
"dist",
|