@embedpdf/plugin-scroll 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -651
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -200
- package/dist/index.js +43 -67
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +27 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +6 -0
- package/dist/lib/scroll-plugin.d.ts +45 -0
- package/dist/lib/selectors.d.ts +2 -0
- package/dist/lib/strategies/base-strategy.d.ts +35 -0
- package/dist/lib/strategies/horizontal-strategy.d.ts +14 -0
- package/dist/lib/strategies/vertical-strategy.d.ts +14 -0
- package/dist/lib/types/virtual-item.d.ts +21 -0
- package/dist/lib/types.d.ts +112 -0
- package/dist/preact/adapter.d.ts +4 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -176
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -53
- package/dist/preact/index.js +17 -17
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -176
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -52
- package/dist/react/index.js +16 -17
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/scroller.d.ts +14 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-scroll.d.ts +32 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/scroller.d.ts +14 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-scroll.d.ts +32 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/scroller.vue.d.ts +28 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-scroll.d.ts +11 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +136 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +22 -13
- package/dist/index.d.cts +0 -200
- package/dist/preact/index.d.cts +0 -53
- package/dist/react/index.d.cts +0 -52
|
@@ -0,0 +1,136 @@
|
|
|
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";
|
|
3
|
+
import { ScrollPlugin, ScrollStrategy } from "@embedpdf/plugin-scroll";
|
|
4
|
+
const useScrollPlugin = () => usePlugin(ScrollPlugin.id);
|
|
5
|
+
const useScrollCapability = () => useCapability(ScrollPlugin.id);
|
|
6
|
+
function useScroll() {
|
|
7
|
+
const { provides: scroll } = useScrollCapability();
|
|
8
|
+
const currentPage = ref(1);
|
|
9
|
+
const totalPages = ref(1);
|
|
10
|
+
watchEffect((onCleanup) => {
|
|
11
|
+
if (!scroll.value) return;
|
|
12
|
+
const off = scroll.value.onPageChange(({ pageNumber, totalPages: tp }) => {
|
|
13
|
+
currentPage.value = pageNumber;
|
|
14
|
+
totalPages.value = tp;
|
|
15
|
+
});
|
|
16
|
+
onCleanup(off);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
scroll,
|
|
20
|
+
currentPage,
|
|
21
|
+
totalPages
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
25
|
+
__name: "scroller",
|
|
26
|
+
props: {
|
|
27
|
+
style: { type: [Boolean, null, String, Object, Array] },
|
|
28
|
+
overlayElements: { default: () => [] }
|
|
29
|
+
},
|
|
30
|
+
setup(__props) {
|
|
31
|
+
const props = __props;
|
|
32
|
+
const attrs = useAttrs();
|
|
33
|
+
const { provides: scrollProvides } = useScrollCapability();
|
|
34
|
+
const { plugin: scrollPlugin } = useScrollPlugin();
|
|
35
|
+
const { registry } = useRegistry();
|
|
36
|
+
const layout = ref(null);
|
|
37
|
+
watchEffect((onCleanup) => {
|
|
38
|
+
if (!scrollProvides.value) return;
|
|
39
|
+
layout.value = scrollProvides.value.getScrollerLayout();
|
|
40
|
+
const off = scrollProvides.value.onScrollerData((l) => layout.value = l);
|
|
41
|
+
onCleanup(off);
|
|
42
|
+
});
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = scrollPlugin.value) == null ? void 0 : _a.setLayoutReady();
|
|
46
|
+
});
|
|
47
|
+
function pageSlotProps(pl) {
|
|
48
|
+
const core = registry.value.getStore().getState().core;
|
|
49
|
+
return {
|
|
50
|
+
...pl,
|
|
51
|
+
rotation: core.rotation,
|
|
52
|
+
scale: core.scale,
|
|
53
|
+
document: core.document
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const rootStyle = computed(() => {
|
|
57
|
+
if (!layout.value) return props.style;
|
|
58
|
+
const base = typeof props.style === "object" && !Array.isArray(props.style) ? { ...props.style } : props.style ?? {};
|
|
59
|
+
return [
|
|
60
|
+
base,
|
|
61
|
+
{
|
|
62
|
+
width: `${layout.value.totalWidth}px`,
|
|
63
|
+
height: `${layout.value.totalHeight}px`,
|
|
64
|
+
position: "relative",
|
|
65
|
+
boxSizing: "border-box",
|
|
66
|
+
margin: "0 auto",
|
|
67
|
+
...layout.value.strategy === ScrollStrategy.Horizontal && {
|
|
68
|
+
display: "flex",
|
|
69
|
+
flexDirection: "row"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
});
|
|
74
|
+
return (_ctx, _cache) => {
|
|
75
|
+
return layout.value && unref(registry) ? (openBlock(), createElementBlock("div", mergeProps({
|
|
76
|
+
key: 0,
|
|
77
|
+
style: rootStyle.value
|
|
78
|
+
}, unref(attrs)), [
|
|
79
|
+
layout.value.strategy === "horizontal" ? (openBlock(), createElementBlock("div", {
|
|
80
|
+
key: 0,
|
|
81
|
+
style: normalizeStyle({ width: layout.value.startSpacing + "px", height: "100%", flexShrink: 0 })
|
|
82
|
+
}, null, 4)) : (openBlock(), createElementBlock("div", {
|
|
83
|
+
key: 1,
|
|
84
|
+
style: normalizeStyle({ height: layout.value.startSpacing + "px", width: "100%" })
|
|
85
|
+
}, null, 4)),
|
|
86
|
+
createElementVNode("div", {
|
|
87
|
+
style: normalizeStyle({
|
|
88
|
+
gap: layout.value.pageGap + "px",
|
|
89
|
+
display: "flex",
|
|
90
|
+
alignItems: "center",
|
|
91
|
+
position: "relative",
|
|
92
|
+
boxSizing: "border-box",
|
|
93
|
+
flexDirection: layout.value.strategy === "horizontal" ? "row" : "column",
|
|
94
|
+
minHeight: layout.value.strategy === "horizontal" ? "100%" : void 0,
|
|
95
|
+
minWidth: layout.value.strategy === "vertical" ? "fit-content" : void 0
|
|
96
|
+
})
|
|
97
|
+
}, [
|
|
98
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(layout.value.items, (item) => {
|
|
99
|
+
return openBlock(), createElementBlock("div", {
|
|
100
|
+
key: item.pageNumbers[0],
|
|
101
|
+
style: normalizeStyle({ display: "flex", justifyContent: "center", gap: layout.value.pageGap + "px" })
|
|
102
|
+
}, [
|
|
103
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(item.pageLayouts, (pl) => {
|
|
104
|
+
return openBlock(), createElementBlock("div", {
|
|
105
|
+
key: pl.pageNumber,
|
|
106
|
+
style: normalizeStyle({ width: pl.rotatedWidth + "px", height: pl.rotatedHeight + "px" })
|
|
107
|
+
}, [
|
|
108
|
+
renderSlot(_ctx.$slots, "default", {
|
|
109
|
+
page: pageSlotProps(pl)
|
|
110
|
+
})
|
|
111
|
+
], 4);
|
|
112
|
+
}), 128))
|
|
113
|
+
], 4);
|
|
114
|
+
}), 128))
|
|
115
|
+
], 4),
|
|
116
|
+
layout.value.strategy === "horizontal" ? (openBlock(), createElementBlock("div", {
|
|
117
|
+
key: 2,
|
|
118
|
+
style: normalizeStyle({ width: layout.value.endSpacing + "px", height: "100%", flexShrink: 0 })
|
|
119
|
+
}, null, 4)) : (openBlock(), createElementBlock("div", {
|
|
120
|
+
key: 3,
|
|
121
|
+
style: normalizeStyle({ height: layout.value.endSpacing + "px", width: "100%" })
|
|
122
|
+
}, null, 4)),
|
|
123
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(props.overlayElements, (el, i) => {
|
|
124
|
+
return openBlock(), createBlock(resolveDynamicComponent(el), { key: i });
|
|
125
|
+
}), 128))
|
|
126
|
+
], 16)) : createCommentVNode("", true);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
export {
|
|
131
|
+
_sfc_main as Scroller,
|
|
132
|
+
useScroll,
|
|
133
|
+
useScrollCapability,
|
|
134
|
+
useScrollPlugin
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,oBAAoB;AACzD,UAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAC3C,UAAA,EAAE,SAAS,IAAI,YAAY;AAE3B,UAAA,SAAS,IAA2B,IAAI;AAG9C,gBAAY,CAAC,cAAc;AACrB,UAAA,CAAC,eAAe,MAAO;AAEpB,aAAA,QAAQ,eAAe,MAAM,kBAAkB;AAChD,YAAA,MAAM,eAAe,MAAM,eAAe,CAAC,MAAO,OAAO,QAAQ,CAAE;AACzE,gBAAU,GAAG;AAAA,IAAA,CACd;AAGD,cAAU,MAAM;;AACd,yBAAa,UAAb,mBAAoB;AAAA,IAAe,CACpC;A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",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,23 +20,30 @@
|
|
|
20
20
|
"types": "./dist/react/index.d.ts",
|
|
21
21
|
"import": "./dist/react/index.js",
|
|
22
22
|
"require": "./dist/react/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./vue": {
|
|
25
|
+
"types": "./dist/vue/index.d.ts",
|
|
26
|
+
"import": "./dist/vue/index.js",
|
|
27
|
+
"require": "./dist/vue/index.cjs"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"@embedpdf/models": "1.0.
|
|
31
|
+
"@embedpdf/models": "1.0.12"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"@types/react": "^18.2.0",
|
|
30
|
-
"tsup": "^8.0.0",
|
|
31
35
|
"typescript": "^5.0.0",
|
|
32
|
-
"@embedpdf/
|
|
36
|
+
"@embedpdf/core": "1.0.12",
|
|
37
|
+
"@embedpdf/build": "1.0.0",
|
|
38
|
+
"@embedpdf/plugin-viewport": "1.0.12"
|
|
33
39
|
},
|
|
34
40
|
"peerDependencies": {
|
|
41
|
+
"preact": "^10.26.4",
|
|
35
42
|
"react": ">=16.8.0",
|
|
36
43
|
"react-dom": ">=16.8.0",
|
|
37
|
-
"
|
|
38
|
-
"@embedpdf/core": "1.0.
|
|
39
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
44
|
+
"vue": ">=3.2.0",
|
|
45
|
+
"@embedpdf/core": "1.0.12",
|
|
46
|
+
"@embedpdf/plugin-viewport": "1.0.12"
|
|
40
47
|
},
|
|
41
48
|
"files": [
|
|
42
49
|
"dist",
|
|
@@ -55,11 +62,13 @@
|
|
|
55
62
|
"access": "public"
|
|
56
63
|
},
|
|
57
64
|
"scripts": {
|
|
58
|
-
"build": "
|
|
59
|
-
"build:
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
65
|
+
"build:base": "vite build --mode base",
|
|
66
|
+
"build:react": "vite build --mode react",
|
|
67
|
+
"build:preact": "vite build --mode preact",
|
|
68
|
+
"build:vue": "vite build --mode vue",
|
|
69
|
+
"build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
|
|
70
|
+
"clean": "rimraf dist",
|
|
71
|
+
"lint": "eslint src --color",
|
|
72
|
+
"lint:fix": "eslint src --color --fix"
|
|
64
73
|
}
|
|
65
74
|
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { BasePluginConfig, EventHook, Action, BasePlugin, PluginRegistry, StoreState, CoreState, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
-
import { Rect, Rotation, PdfPageObject } from '@embedpdf/models';
|
|
3
|
-
import { ViewportMetrics } from '@embedpdf/plugin-viewport';
|
|
4
|
-
|
|
5
|
-
interface PageLayout {
|
|
6
|
-
pageNumber: number;
|
|
7
|
-
pageIndex: number;
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
width: number;
|
|
11
|
-
height: number;
|
|
12
|
-
rotatedWidth: number;
|
|
13
|
-
rotatedHeight: number;
|
|
14
|
-
}
|
|
15
|
-
interface VirtualItem {
|
|
16
|
-
id: string;
|
|
17
|
-
x: number;
|
|
18
|
-
y: number;
|
|
19
|
-
offset: number;
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
pageLayouts: PageLayout[];
|
|
23
|
-
pageNumbers: number[];
|
|
24
|
-
index: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface ScrollState extends ScrollMetrics {
|
|
28
|
-
virtualItems: VirtualItem[];
|
|
29
|
-
totalPages: number;
|
|
30
|
-
totalContentSize: {
|
|
31
|
-
width: number;
|
|
32
|
-
height: number;
|
|
33
|
-
};
|
|
34
|
-
desiredScrollPosition: {
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
};
|
|
38
|
-
strategy: ScrollStrategy;
|
|
39
|
-
pageGap: number;
|
|
40
|
-
scale: number;
|
|
41
|
-
}
|
|
42
|
-
interface ScrollerLayout {
|
|
43
|
-
startSpacing: number;
|
|
44
|
-
endSpacing: number;
|
|
45
|
-
totalWidth: number;
|
|
46
|
-
totalHeight: number;
|
|
47
|
-
pageGap: number;
|
|
48
|
-
strategy: ScrollState['strategy'];
|
|
49
|
-
items: VirtualItem[];
|
|
50
|
-
}
|
|
51
|
-
declare enum ScrollStrategy {
|
|
52
|
-
Vertical = "vertical",
|
|
53
|
-
Horizontal = "horizontal"
|
|
54
|
-
}
|
|
55
|
-
interface PageVisibilityMetrics {
|
|
56
|
-
pageNumber: number;
|
|
57
|
-
viewportX: number;
|
|
58
|
-
viewportY: number;
|
|
59
|
-
visiblePercentage: number;
|
|
60
|
-
original: {
|
|
61
|
-
pageX: number;
|
|
62
|
-
pageY: number;
|
|
63
|
-
visibleWidth: number;
|
|
64
|
-
visibleHeight: number;
|
|
65
|
-
scale: number;
|
|
66
|
-
};
|
|
67
|
-
scaled: {
|
|
68
|
-
pageX: number;
|
|
69
|
-
pageY: number;
|
|
70
|
-
visibleWidth: number;
|
|
71
|
-
visibleHeight: number;
|
|
72
|
-
scale: number;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
interface ScrollMetrics {
|
|
76
|
-
currentPage: number;
|
|
77
|
-
visiblePages: number[];
|
|
78
|
-
pageVisibilityMetrics: PageVisibilityMetrics[];
|
|
79
|
-
renderedPageIndexes: number[];
|
|
80
|
-
scrollOffset: {
|
|
81
|
-
x: number;
|
|
82
|
-
y: number;
|
|
83
|
-
};
|
|
84
|
-
startSpacing: number;
|
|
85
|
-
endSpacing: number;
|
|
86
|
-
}
|
|
87
|
-
interface ScrollStrategyInterface {
|
|
88
|
-
initialize(container: HTMLElement, innerDiv: HTMLElement): void;
|
|
89
|
-
destroy(): void;
|
|
90
|
-
updateLayout(viewport: ViewportMetrics, pdfPageObject: PdfPageObject[][]): void;
|
|
91
|
-
handleScroll(viewport: ViewportMetrics): void;
|
|
92
|
-
getVirtualItems(): VirtualItem[];
|
|
93
|
-
scrollToPage(pageNumber: number, behavior?: ScrollBehavior): void;
|
|
94
|
-
calculateDimensions(pdfPageObject: PdfPageObject[][]): void;
|
|
95
|
-
}
|
|
96
|
-
interface ScrollPluginConfig extends BasePluginConfig {
|
|
97
|
-
strategy?: ScrollStrategy;
|
|
98
|
-
initialPage?: number;
|
|
99
|
-
bufferSize?: number;
|
|
100
|
-
pageGap?: number;
|
|
101
|
-
}
|
|
102
|
-
type LayoutChangePayload = Pick<ScrollState, 'virtualItems' | 'totalContentSize'>;
|
|
103
|
-
interface ScrollToPageOptions {
|
|
104
|
-
pageNumber: number;
|
|
105
|
-
pageCoordinates?: {
|
|
106
|
-
x: number;
|
|
107
|
-
y: number;
|
|
108
|
-
};
|
|
109
|
-
behavior?: ScrollBehavior;
|
|
110
|
-
center?: boolean;
|
|
111
|
-
}
|
|
112
|
-
interface PageChangePayload {
|
|
113
|
-
pageNumber: number;
|
|
114
|
-
totalPages: number;
|
|
115
|
-
}
|
|
116
|
-
interface ScrollCapability {
|
|
117
|
-
onScrollerData: EventHook<ScrollerLayout>;
|
|
118
|
-
onStateChange: EventHook<ScrollState>;
|
|
119
|
-
onScroll: EventHook<ScrollMetrics>;
|
|
120
|
-
getCurrentPage(): number;
|
|
121
|
-
getTotalPages(): number;
|
|
122
|
-
onPageChange: EventHook<PageChangePayload>;
|
|
123
|
-
onLayoutChange: EventHook<LayoutChangePayload>;
|
|
124
|
-
scrollToPage(options: ScrollToPageOptions): void;
|
|
125
|
-
scrollToNextPage(behavior?: ScrollBehavior): void;
|
|
126
|
-
scrollToPreviousPage(behavior?: ScrollBehavior): void;
|
|
127
|
-
getMetrics(viewport?: ViewportMetrics): ScrollMetrics;
|
|
128
|
-
getLayout(): LayoutChangePayload;
|
|
129
|
-
getScrollerLayout(): ScrollerLayout;
|
|
130
|
-
getRectPositionForPage(page: number, rect: Rect, scale?: number, rotation?: Rotation): Rect | null;
|
|
131
|
-
setScrollStrategy(strategy: ScrollStrategy): void;
|
|
132
|
-
getPageGap(): number;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
declare const UPDATE_SCROLL_STATE = "UPDATE_SCROLL_STATE";
|
|
136
|
-
declare const SET_DESIRED_SCROLL_POSITION = "SET_DESIRED_SCROLL_POSITION";
|
|
137
|
-
declare const UPDATE_TOTAL_PAGES = "UPDATE_TOTAL_PAGES";
|
|
138
|
-
interface UpdateScrollStateAction extends Action {
|
|
139
|
-
type: typeof UPDATE_SCROLL_STATE;
|
|
140
|
-
payload: Partial<ScrollState>;
|
|
141
|
-
}
|
|
142
|
-
interface SetDesiredScrollPositionAction extends Action {
|
|
143
|
-
type: typeof SET_DESIRED_SCROLL_POSITION;
|
|
144
|
-
payload: {
|
|
145
|
-
x: number;
|
|
146
|
-
y: number;
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
interface UpdateTotalPagesAction extends Action {
|
|
150
|
-
type: typeof UPDATE_TOTAL_PAGES;
|
|
151
|
-
payload: number;
|
|
152
|
-
}
|
|
153
|
-
type ScrollAction = UpdateScrollStateAction | SetDesiredScrollPositionAction | UpdateTotalPagesAction;
|
|
154
|
-
|
|
155
|
-
declare class ScrollPlugin extends BasePlugin<ScrollPluginConfig, ScrollCapability, ScrollState, ScrollAction> {
|
|
156
|
-
readonly id: string;
|
|
157
|
-
private config?;
|
|
158
|
-
static readonly id: "scroll";
|
|
159
|
-
private viewport;
|
|
160
|
-
private strategy;
|
|
161
|
-
private strategyConfig;
|
|
162
|
-
private currentScale;
|
|
163
|
-
private currentRotation;
|
|
164
|
-
private initialPage?;
|
|
165
|
-
private currentPage;
|
|
166
|
-
private readonly layout$;
|
|
167
|
-
private readonly scroll$;
|
|
168
|
-
private readonly state$;
|
|
169
|
-
private readonly scrollerLayout$;
|
|
170
|
-
private readonly pageChange$;
|
|
171
|
-
constructor(id: string, registry: PluginRegistry, config?: ScrollPluginConfig | undefined);
|
|
172
|
-
private computeLayout;
|
|
173
|
-
private computeMetrics;
|
|
174
|
-
private commit;
|
|
175
|
-
private commitMetrics;
|
|
176
|
-
private refreshAll;
|
|
177
|
-
private getVirtualItemsFromState;
|
|
178
|
-
private getScrollerLayoutFromState;
|
|
179
|
-
private pushScrollLayout;
|
|
180
|
-
onStoreUpdated(_prevState: ScrollState, _newState: ScrollState): void;
|
|
181
|
-
onCoreStoreUpdated(prevState: StoreState<CoreState>, newState: StoreState<CoreState>): void;
|
|
182
|
-
/**
|
|
183
|
-
* Change the scroll strategy at runtime (e.g., vertical <-> horizontal)
|
|
184
|
-
* @param newStrategy ScrollStrategy.Horizontal or ScrollStrategy.Vertical
|
|
185
|
-
*/
|
|
186
|
-
private setScrollStrategy;
|
|
187
|
-
protected buildCapability(): ScrollCapability;
|
|
188
|
-
private getMetrics;
|
|
189
|
-
private getLayout;
|
|
190
|
-
private getRectPositionForPage;
|
|
191
|
-
initialize(): Promise<void>;
|
|
192
|
-
destroy(): Promise<void>;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
declare const SCROLL_PLUGIN_ID = "scroll";
|
|
196
|
-
declare const manifest: PluginManifest<ScrollPluginConfig>;
|
|
197
|
-
|
|
198
|
-
declare const ScrollPluginPackage: PluginPackage<ScrollPlugin, ScrollPluginConfig, ScrollState, ScrollAction>;
|
|
199
|
-
|
|
200
|
-
export { type LayoutChangePayload, type PageChangePayload, type PageLayout, type PageVisibilityMetrics, SCROLL_PLUGIN_ID, type ScrollCapability, type ScrollMetrics, ScrollPlugin, type ScrollPluginConfig, ScrollPluginPackage, type ScrollState, ScrollStrategy, type ScrollStrategyInterface, type ScrollToPageOptions, type ScrollerLayout, type VirtualItem, manifest };
|
package/dist/preact/index.d.cts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as _embedpdf_models from '@embedpdf/models';
|
|
2
|
-
import { Rotation, PdfDocumentObject } from '@embedpdf/models';
|
|
3
|
-
import * as _embedpdf_plugin_viewport from '@embedpdf/plugin-viewport';
|
|
4
|
-
import * as _embedpdf_core from '@embedpdf/core';
|
|
5
|
-
import * as _embedpdf_plugin_scroll from '@embedpdf/plugin-scroll';
|
|
6
|
-
import { ScrollPlugin, PageLayout } from '@embedpdf/plugin-scroll';
|
|
7
|
-
import { JSX } from 'preact';
|
|
8
|
-
|
|
9
|
-
declare const useScrollPlugin: () => {
|
|
10
|
-
plugin: ScrollPlugin | null;
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
ready: Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
declare const useScrollCapability: () => {
|
|
15
|
-
provides: Readonly<_embedpdf_plugin_scroll.ScrollCapability> | null;
|
|
16
|
-
isLoading: boolean;
|
|
17
|
-
ready: Promise<void>;
|
|
18
|
-
};
|
|
19
|
-
declare const useScroll: () => {
|
|
20
|
-
currentPage: number;
|
|
21
|
-
totalPages: number;
|
|
22
|
-
onScrollerData?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollerLayout> | undefined;
|
|
23
|
-
onStateChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollState> | undefined;
|
|
24
|
-
onScroll?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollMetrics> | undefined;
|
|
25
|
-
getCurrentPage?: (() => number) | undefined;
|
|
26
|
-
getTotalPages?: (() => number) | undefined;
|
|
27
|
-
onPageChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.PageChangePayload> | undefined;
|
|
28
|
-
onLayoutChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.LayoutChangePayload> | undefined;
|
|
29
|
-
scrollToPage?: ((options: _embedpdf_plugin_scroll.ScrollToPageOptions) => void) | undefined;
|
|
30
|
-
scrollToNextPage?: ((behavior?: ScrollBehavior) => void) | undefined;
|
|
31
|
-
scrollToPreviousPage?: ((behavior?: ScrollBehavior) => void) | undefined;
|
|
32
|
-
getMetrics?: ((viewport?: _embedpdf_plugin_viewport.ViewportMetrics) => _embedpdf_plugin_scroll.ScrollMetrics) | undefined;
|
|
33
|
-
getLayout?: (() => _embedpdf_plugin_scroll.LayoutChangePayload) | undefined;
|
|
34
|
-
getScrollerLayout?: (() => _embedpdf_plugin_scroll.ScrollerLayout) | undefined;
|
|
35
|
-
getRectPositionForPage?: ((page: number, rect: _embedpdf_models.Rect, scale?: number, rotation?: _embedpdf_models.Rotation) => _embedpdf_models.Rect | null) | undefined;
|
|
36
|
-
setScrollStrategy?: ((strategy: _embedpdf_plugin_scroll.ScrollStrategy) => void) | undefined;
|
|
37
|
-
getPageGap?: (() => number) | undefined;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/** @jsxImportSource preact */
|
|
41
|
-
|
|
42
|
-
interface RenderPageProps extends PageLayout {
|
|
43
|
-
rotation: Rotation;
|
|
44
|
-
scale: number;
|
|
45
|
-
document: PdfDocumentObject | null;
|
|
46
|
-
}
|
|
47
|
-
type ScrollerProps = JSX.HTMLAttributes<HTMLDivElement> & {
|
|
48
|
-
renderPage: (props: RenderPageProps) => JSX.Element;
|
|
49
|
-
overlayElements?: JSX.Element[];
|
|
50
|
-
};
|
|
51
|
-
declare function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps): JSX.Element | null;
|
|
52
|
-
|
|
53
|
-
export { Scroller, useScroll, useScrollCapability, useScrollPlugin };
|
package/dist/react/index.d.cts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as _embedpdf_models from '@embedpdf/models';
|
|
2
|
-
import { Rotation, PdfDocumentObject } from '@embedpdf/models';
|
|
3
|
-
import * as _embedpdf_plugin_viewport from '@embedpdf/plugin-viewport';
|
|
4
|
-
import * as _embedpdf_core from '@embedpdf/core';
|
|
5
|
-
import * as _embedpdf_plugin_scroll from '@embedpdf/plugin-scroll';
|
|
6
|
-
import { ScrollPlugin, PageLayout } from '@embedpdf/plugin-scroll';
|
|
7
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
|
-
import React, { ReactNode } from 'react';
|
|
9
|
-
|
|
10
|
-
declare const useScrollPlugin: () => {
|
|
11
|
-
plugin: ScrollPlugin | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
declare const useScrollCapability: () => {
|
|
16
|
-
provides: Readonly<_embedpdf_plugin_scroll.ScrollCapability> | null;
|
|
17
|
-
isLoading: boolean;
|
|
18
|
-
ready: Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
declare const useScroll: () => {
|
|
21
|
-
currentPage: number;
|
|
22
|
-
totalPages: number;
|
|
23
|
-
onScrollerData?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollerLayout> | undefined;
|
|
24
|
-
onStateChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollState> | undefined;
|
|
25
|
-
onScroll?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.ScrollMetrics> | undefined;
|
|
26
|
-
getCurrentPage?: (() => number) | undefined;
|
|
27
|
-
getTotalPages?: (() => number) | undefined;
|
|
28
|
-
onPageChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.PageChangePayload> | undefined;
|
|
29
|
-
onLayoutChange?: _embedpdf_core.EventHook<_embedpdf_plugin_scroll.LayoutChangePayload> | undefined;
|
|
30
|
-
scrollToPage?: ((options: _embedpdf_plugin_scroll.ScrollToPageOptions) => void) | undefined;
|
|
31
|
-
scrollToNextPage?: ((behavior?: ScrollBehavior) => void) | undefined;
|
|
32
|
-
scrollToPreviousPage?: ((behavior?: ScrollBehavior) => void) | undefined;
|
|
33
|
-
getMetrics?: ((viewport?: _embedpdf_plugin_viewport.ViewportMetrics) => _embedpdf_plugin_scroll.ScrollMetrics) | undefined;
|
|
34
|
-
getLayout?: (() => _embedpdf_plugin_scroll.LayoutChangePayload) | undefined;
|
|
35
|
-
getScrollerLayout?: (() => _embedpdf_plugin_scroll.ScrollerLayout) | undefined;
|
|
36
|
-
getRectPositionForPage?: ((page: number, rect: _embedpdf_models.Rect, scale?: number, rotation?: _embedpdf_models.Rotation) => _embedpdf_models.Rect | null) | undefined;
|
|
37
|
-
setScrollStrategy?: ((strategy: _embedpdf_plugin_scroll.ScrollStrategy) => void) | undefined;
|
|
38
|
-
getPageGap?: (() => number) | undefined;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
interface RenderPageProps extends PageLayout {
|
|
42
|
-
rotation: Rotation;
|
|
43
|
-
scale: number;
|
|
44
|
-
document: PdfDocumentObject | null;
|
|
45
|
-
}
|
|
46
|
-
type ScrollerProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
47
|
-
renderPage: (props: RenderPageProps) => ReactNode;
|
|
48
|
-
overlayElements?: ReactNode[];
|
|
49
|
-
};
|
|
50
|
-
declare function Scroller({ renderPage, overlayElements, ...props }: ScrollerProps): react_jsx_runtime.JSX.Element | null;
|
|
51
|
-
|
|
52
|
-
export { Scroller, useScroll, useScrollCapability, useScrollPlugin };
|