@embedpdf/plugin-viewport 1.0.11 → 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 -247
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -107
- package/dist/index.js +20 -32
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +27 -0
- package/dist/lib/index.d.ts +8 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/types.d.ts +52 -0
- package/dist/lib/viewport-plugin.d.ts +27 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -123
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -23
- package/dist/preact/index.js +9 -15
- 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 -125
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -25
- package/dist/react/index.js +6 -14
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/viewport.d.ts +6 -0
- package/dist/shared-preact/hooks/index.d.ts +2 -0
- package/dist/shared-preact/hooks/use-viewport-ref.d.ts +1 -0
- package/dist/shared-preact/hooks/use-viewport.d.ts +11 -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/viewport.d.ts +6 -0
- package/dist/shared-react/hooks/index.d.ts +2 -0
- package/dist/shared-react/hooks/use-viewport-ref.d.ts +1 -0
- package/dist/shared-react/hooks/use-viewport.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/viewport.vue.d.ts +12 -0
- package/dist/vue/hooks/index.d.ts +2 -0
- package/dist/vue/hooks/use-viewport-ref.d.ts +1 -0
- package/dist/vue/hooks/use-viewport.d.ts +3 -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 +89 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +21 -12
- package/dist/index.d.cts +0 -107
- package/dist/preact/index.d.cts +0 -23
- package/dist/react/index.d.cts +0 -25
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
+
import { Rect } from '@embedpdf/models';
|
|
3
|
+
export interface ViewportState {
|
|
4
|
+
viewportGap: number;
|
|
5
|
+
viewportMetrics: ViewportMetrics;
|
|
6
|
+
isScrolling: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ViewportPluginConfig extends BasePluginConfig {
|
|
9
|
+
viewportGap?: number;
|
|
10
|
+
scrollEndDelay?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ViewportInputMetrics {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
scrollTop: number;
|
|
16
|
+
scrollLeft: number;
|
|
17
|
+
clientWidth: number;
|
|
18
|
+
clientHeight: number;
|
|
19
|
+
scrollWidth: number;
|
|
20
|
+
scrollHeight: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ViewportMetrics extends ViewportInputMetrics {
|
|
23
|
+
relativePosition: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface ViewportScrollMetrics {
|
|
29
|
+
scrollTop: number;
|
|
30
|
+
scrollLeft: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ScrollControlOptions {
|
|
33
|
+
mode: 'debounce' | 'throttle';
|
|
34
|
+
wait: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ScrollToPayload {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
behavior?: ScrollBehavior;
|
|
40
|
+
center?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ViewportCapability {
|
|
43
|
+
getViewportGap: () => number;
|
|
44
|
+
getMetrics: () => ViewportMetrics;
|
|
45
|
+
scrollTo(position: ScrollToPayload): void;
|
|
46
|
+
onViewportChange: EventHook<ViewportMetrics>;
|
|
47
|
+
onViewportResize: EventHook<ViewportMetrics>;
|
|
48
|
+
onScrollChange: EventHook<ViewportScrollMetrics>;
|
|
49
|
+
onScrollActivity: EventHook<boolean>;
|
|
50
|
+
isScrolling: () => boolean;
|
|
51
|
+
getBoundingRect(): Rect;
|
|
52
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BasePlugin, PluginRegistry, Listener } from '@embedpdf/core';
|
|
2
|
+
import { ViewportAction } from './actions';
|
|
3
|
+
import { ViewportPluginConfig, ViewportState, ViewportCapability, ViewportScrollMetrics, ViewportInputMetrics, ScrollToPayload } from './types';
|
|
4
|
+
import { Rect } from '@embedpdf/models';
|
|
5
|
+
export declare class ViewportPlugin extends BasePlugin<ViewportPluginConfig, ViewportCapability, ViewportState, ViewportAction> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
static readonly id: "viewport";
|
|
8
|
+
private readonly viewportResize$;
|
|
9
|
+
private readonly viewportMetrics$;
|
|
10
|
+
private readonly scrollMetrics$;
|
|
11
|
+
private readonly scrollReq$;
|
|
12
|
+
private readonly scrollActivity$;
|
|
13
|
+
private rectProvider;
|
|
14
|
+
private scrollEndTimer?;
|
|
15
|
+
private readonly scrollEndDelay;
|
|
16
|
+
constructor(id: string, registry: PluginRegistry, config: ViewportPluginConfig);
|
|
17
|
+
protected buildCapability(): ViewportCapability;
|
|
18
|
+
setViewportResizeMetrics(viewportMetrics: ViewportInputMetrics): void;
|
|
19
|
+
setViewportScrollMetrics(scrollMetrics: ViewportScrollMetrics): void;
|
|
20
|
+
onScrollRequest(listener: Listener<ScrollToPayload>): import('@embedpdf/core').Unsubscribe;
|
|
21
|
+
registerBoundingRectProvider(provider: (() => Rect) | null): void;
|
|
22
|
+
private bumpScrollActivity;
|
|
23
|
+
private scrollTo;
|
|
24
|
+
onStoreUpdated(prevState: ViewportState, newState: ViewportState): void;
|
|
25
|
+
initialize(_config: ViewportPluginConfig): Promise<void>;
|
|
26
|
+
destroy(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Fragment } from 'preact';
|
|
2
|
+
export { useEffect, useRef, useState, useCallback, useMemo, useLayoutEffect } from 'preact/hooks';
|
|
3
|
+
export type { ComponentChildren as ReactNode } from 'preact';
|
|
4
|
+
export type CSSProperties = import('preact').JSX.CSSProperties;
|
|
5
|
+
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/preact';
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,123 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/preact/index.ts
|
|
21
|
-
var preact_exports = {};
|
|
22
|
-
__export(preact_exports, {
|
|
23
|
-
Viewport: () => Viewport,
|
|
24
|
-
useViewportCapability: () => useViewportCapability,
|
|
25
|
-
useViewportPlugin: () => useViewportPlugin
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(preact_exports);
|
|
28
|
-
|
|
29
|
-
// src/preact/hooks/use-viewport.ts
|
|
30
|
-
var import_preact = require("@embedpdf/core/preact");
|
|
31
|
-
var import_plugin_viewport = require("@embedpdf/plugin-viewport");
|
|
32
|
-
var useViewportPlugin = () => (0, import_preact.usePlugin)(import_plugin_viewport.ViewportPlugin.id);
|
|
33
|
-
var useViewportCapability = () => (0, import_preact.useCapability)(import_plugin_viewport.ViewportPlugin.id);
|
|
34
|
-
|
|
35
|
-
// src/preact/components/viewport.tsx
|
|
36
|
-
var import_hooks2 = require("preact/hooks");
|
|
37
|
-
|
|
38
|
-
// src/preact/hooks/use-viewport-ref.ts
|
|
39
|
-
var import_hooks = require("preact/hooks");
|
|
40
|
-
function useViewportRef() {
|
|
41
|
-
const { plugin: viewportPlugin } = useViewportPlugin();
|
|
42
|
-
const containerRef = (0, import_hooks.useRef)(null);
|
|
43
|
-
(0, import_hooks.useLayoutEffect)(() => {
|
|
44
|
-
if (!viewportPlugin) return;
|
|
45
|
-
const container = containerRef.current;
|
|
46
|
-
if (!container) return;
|
|
47
|
-
const provideRect = () => {
|
|
48
|
-
const r = container.getBoundingClientRect();
|
|
49
|
-
return {
|
|
50
|
-
origin: { x: r.left, y: r.top },
|
|
51
|
-
size: { width: r.width, height: r.height }
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
viewportPlugin.registerBoundingRectProvider(provideRect);
|
|
55
|
-
const onScroll = () => {
|
|
56
|
-
viewportPlugin.setViewportScrollMetrics({
|
|
57
|
-
scrollTop: container.scrollTop,
|
|
58
|
-
scrollLeft: container.scrollLeft
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
container.addEventListener("scroll", onScroll);
|
|
62
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
63
|
-
viewportPlugin.setViewportResizeMetrics({
|
|
64
|
-
width: container.offsetWidth,
|
|
65
|
-
height: container.offsetHeight,
|
|
66
|
-
clientWidth: container.clientWidth,
|
|
67
|
-
clientHeight: container.clientHeight,
|
|
68
|
-
scrollTop: container.scrollTop,
|
|
69
|
-
scrollLeft: container.scrollLeft,
|
|
70
|
-
scrollWidth: container.scrollWidth,
|
|
71
|
-
scrollHeight: container.scrollHeight
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
resizeObserver.observe(container);
|
|
75
|
-
const unsubscribeScrollRequest = viewportPlugin.onScrollRequest(
|
|
76
|
-
({ x, y, behavior = "auto" }) => {
|
|
77
|
-
requestAnimationFrame(() => {
|
|
78
|
-
container.scrollTo({ left: x, top: y, behavior });
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
return () => {
|
|
83
|
-
viewportPlugin.registerBoundingRectProvider(null);
|
|
84
|
-
container.removeEventListener("scroll", onScroll);
|
|
85
|
-
resizeObserver.disconnect();
|
|
86
|
-
unsubscribeScrollRequest();
|
|
87
|
-
};
|
|
88
|
-
}, [viewportPlugin]);
|
|
89
|
-
return containerRef;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/preact/components/viewport.tsx
|
|
93
|
-
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
94
|
-
function Viewport({ children, ...props }) {
|
|
95
|
-
const [viewportGap, setViewportGap] = (0, import_hooks2.useState)(0);
|
|
96
|
-
const viewportRef = useViewportRef();
|
|
97
|
-
const { provides: viewportProvides } = useViewportCapability();
|
|
98
|
-
(0, import_hooks2.useEffect)(() => {
|
|
99
|
-
if (viewportProvides) {
|
|
100
|
-
setViewportGap(viewportProvides.getViewportGap());
|
|
101
|
-
}
|
|
102
|
-
}, [viewportProvides]);
|
|
103
|
-
const { style, ...restProps } = props;
|
|
104
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
105
|
-
"div",
|
|
106
|
-
{
|
|
107
|
-
...restProps,
|
|
108
|
-
ref: viewportRef,
|
|
109
|
-
style: {
|
|
110
|
-
...typeof style === "object" ? style : {},
|
|
111
|
-
padding: `${viewportGap}px`
|
|
112
|
-
},
|
|
113
|
-
children
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
-
0 && (module.exports = {
|
|
119
|
-
Viewport,
|
|
120
|
-
useViewportCapability,
|
|
121
|
-
useViewportPlugin
|
|
122
|
-
});
|
|
123
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact/jsx-runtime");require("preact");const t=require("preact/hooks"),r=require("@embedpdf/core/preact"),i=require("@embedpdf/plugin-viewport"),o=()=>r.usePlugin(i.ViewportPlugin.id),s=()=>r.useCapability(i.ViewportPlugin.id);function l(){const{plugin:e}=o(),r=t.useRef(null);return t.useLayoutEffect((()=>{if(!e)return;const t=r.current;if(!t)return;e.registerBoundingRectProvider((()=>{const e=t.getBoundingClientRect();return{origin:{x:e.left,y:e.top},size:{width:e.width,height:e.height}}}));const i=()=>{e.setViewportScrollMetrics({scrollTop:t.scrollTop,scrollLeft:t.scrollLeft})};t.addEventListener("scroll",i);const o=new ResizeObserver((()=>{e.setViewportResizeMetrics({width:t.offsetWidth,height:t.offsetHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight})}));o.observe(t);const s=e.onScrollRequest((({x:e,y:r,behavior:i="auto"})=>{requestAnimationFrame((()=>{t.scrollTo({left:e,top:r,behavior:i})}))}));return()=>{e.registerBoundingRectProvider(null),t.removeEventListener("scroll",i),o.disconnect(),s()}}),[e]),r}exports.Viewport=function({children:r,...i}){const[o,n]=t.useState(0),c=l(),{provides:u}=s();t.useEffect((()=>{u&&n(u.getViewportGap())}),[u]);const{style:p,...d}=i;return e.jsx("div",{...d,ref:c,style:{..."object"==typeof p?p:{},padding:`${o}px`},children:r})},exports.useViewportCapability=s,exports.useViewportPlugin=o,exports.useViewportRef=l;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-viewport.ts","../../src/shared/hooks/use-viewport-ref.ts","../../src/shared/components/viewport.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nexport const useViewportPlugin = () => usePlugin<ViewportPlugin>(ViewportPlugin.id);\nexport const useViewportCapability = () => useCapability<ViewportPlugin>(ViewportPlugin.id);\n","import { Rect } from '@embedpdf/models';\nimport { useLayoutEffect, useRef } from '@framework';\n\nimport { useViewportPlugin } from './use-viewport';\n\nexport function useViewportRef() {\n const { plugin: viewportPlugin } = useViewportPlugin();\n const containerRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n if (!viewportPlugin) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n /* ---------- live rect provider --------------------------------- */\n const provideRect = (): Rect => {\n const r = container.getBoundingClientRect();\n return {\n origin: { x: r.left, y: r.top },\n size: { width: r.width, height: r.height },\n };\n };\n viewportPlugin.registerBoundingRectProvider(provideRect);\n\n // Example: On scroll, call setMetrics\n const onScroll = () => {\n viewportPlugin.setViewportScrollMetrics({\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n });\n };\n container.addEventListener('scroll', onScroll);\n\n // Example: On resize, call setMetrics\n const resizeObserver = new ResizeObserver(() => {\n viewportPlugin.setViewportResizeMetrics({\n width: container.offsetWidth,\n height: container.offsetHeight,\n clientWidth: container.clientWidth,\n clientHeight: container.clientHeight,\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n scrollWidth: container.scrollWidth,\n scrollHeight: container.scrollHeight,\n });\n });\n resizeObserver.observe(container);\n\n const unsubscribeScrollRequest = viewportPlugin.onScrollRequest(\n ({ x, y, behavior = 'auto' }) => {\n requestAnimationFrame(() => {\n container.scrollTo({ left: x, top: y, behavior });\n });\n },\n );\n\n // Cleanup\n return () => {\n viewportPlugin.registerBoundingRectProvider(null);\n container.removeEventListener('scroll', onScroll);\n resizeObserver.disconnect();\n unsubscribeScrollRequest();\n };\n }, [viewportPlugin]);\n\n // Return the ref so your React code can attach it to a div\n return containerRef;\n}\n","import { ReactNode, useEffect, useState, HTMLAttributes } from '@framework';\n\nimport { useViewportCapability } from '../hooks';\nimport { useViewportRef } from '../hooks/use-viewport-ref';\n\ntype ViewportProps = HTMLAttributes<HTMLDivElement> & {\n children: ReactNode;\n};\n\nexport function Viewport({ children, ...props }: ViewportProps) {\n const [viewportGap, setViewportGap] = useState(0);\n const viewportRef = useViewportRef();\n const { provides: viewportProvides } = useViewportCapability();\n\n useEffect(() => {\n if (viewportProvides) {\n setViewportGap(viewportProvides.getViewportGap());\n }\n }, [viewportProvides]);\n\n const { style, ...restProps } = props;\n return (\n <div\n {...restProps}\n ref={viewportRef}\n style={{\n ...(typeof style === 'object' ? style : {}),\n padding: `${viewportGap}px`,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useViewportPlugin","usePlugin","ViewportPlugin","id","useViewportCapability","useCapability","useViewportRef","plugin","viewportPlugin","containerRef","useRef","useLayoutEffect","container","current","registerBoundingRectProvider","r","getBoundingClientRect","origin","x","left","y","top","size","width","height","onScroll","setViewportScrollMetrics","scrollTop","scrollLeft","addEventListener","resizeObserver","ResizeObserver","setViewportResizeMetrics","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","observe","unsubscribeScrollRequest","onScrollRequest","behavior","requestAnimationFrame","scrollTo","removeEventListener","disconnect","children","props","viewportGap","setViewportGap","useState","viewportRef","provides","viewportProvides","useEffect","getViewportGap","style","restProps","jsxRuntime","jsx","ref","padding"],"mappings":"kPAGaA,EAAoB,IAAMC,YAA0BC,EAAAA,eAAeC,IACnEC,EAAwB,IAAMC,gBAA8BH,EAAAA,eAAeC,ICCjF,SAASG,IACd,MAAQC,OAAQC,GAAmBR,IAC7BS,EAAeC,SAAuB,MA4DrC,OA1DPC,EAAAA,iBAAgB,KACd,IAAKH,EAAgB,OAErB,MAAMI,EAAYH,EAAaI,QAC/B,IAAKD,EAAW,OAUhBJ,EAAeM,8BAPK,KACZ,MAAAC,EAAIH,EAAUI,wBACb,MAAA,CACLC,OAAQ,CAAEC,EAAGH,EAAEI,KAAMC,EAAGL,EAAEM,KAC1BC,KAAM,CAAEC,MAAOR,EAAEQ,MAAOC,OAAQT,EAAES,QACpC,IAKF,MAAMC,EAAW,KACfjB,EAAekB,yBAAyB,CACtCC,UAAWf,EAAUe,UACrBC,WAAYhB,EAAUgB,YACvB,EAEOhB,EAAAiB,iBAAiB,SAAUJ,GAG/B,MAAAK,EAAiB,IAAIC,gBAAe,KACxCvB,EAAewB,yBAAyB,CACtCT,MAAOX,EAAUqB,YACjBT,OAAQZ,EAAUsB,aAClBC,YAAavB,EAAUuB,YACvBC,aAAcxB,EAAUwB,aACxBT,UAAWf,EAAUe,UACrBC,WAAYhB,EAAUgB,WACtBS,YAAazB,EAAUyB,YACvBC,aAAc1B,EAAU0B,cACzB,IAEHR,EAAeS,QAAQ3B,GAEvB,MAAM4B,EAA2BhC,EAAeiC,iBAC9C,EAAGvB,IAAGE,IAAGsB,WAAW,WAClBC,uBAAsB,KACpB/B,EAAUgC,SAAS,CAAEzB,KAAMD,EAAGG,IAAKD,EAAGsB,YAAU,GACjD,IAKL,MAAO,KACLlC,EAAeM,6BAA6B,MAClCF,EAAAiC,oBAAoB,SAAUpB,GACxCK,EAAegB,aACUN,GAAA,CAC3B,GACC,CAAChC,IAGGC,CACT,kBC3DO,UAAkBsC,SAAEA,KAAaC,IACtC,MAAOC,EAAaC,GAAkBC,EAAAA,SAAS,GACzCC,EAAc9C,KACZ+C,SAAUC,GAAqBlD,IAEvCmD,EAAAA,WAAU,KACJD,GACaJ,EAAAI,EAAiBE,iBAAgB,GAEjD,CAACF,IAEJ,MAAMG,MAAEA,KAAUC,GAAcV,EAE9B,OAAAW,EAAAC,IAAC,MAAA,IACKF,EACJG,IAAKT,EACLK,MAAO,IACgB,iBAAVA,EAAqBA,EAAQ,CAAC,EACzCK,QAAS,GAAGb,OAGbF,YAGP"}
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ViewportPlugin } from '@embedpdf/plugin-viewport';
|
|
3
|
-
import { JSX, ComponentChildren } from 'preact';
|
|
4
|
-
|
|
5
|
-
declare const useViewportPlugin: () => {
|
|
6
|
-
plugin: ViewportPlugin | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
ready: Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
declare const useViewportCapability: () => {
|
|
11
|
-
provides: Readonly<_embedpdf_plugin_viewport.ViewportCapability> | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** @jsxImportSource preact */
|
|
17
|
-
|
|
18
|
-
type ViewportProps = JSX.HTMLAttributes<HTMLDivElement> & {
|
|
19
|
-
children: ComponentChildren;
|
|
20
|
-
};
|
|
21
|
-
declare function Viewport({ children, ...props }: ViewportProps): JSX.Element;
|
|
22
|
-
|
|
23
|
-
export { Viewport, useViewportCapability, useViewportPlugin };
|
|
1
|
+
export * from '../shared-preact';
|
package/dist/preact/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { jsx } from "preact/jsx-runtime";
|
|
2
|
+
import "preact";
|
|
3
|
+
import { useRef, useLayoutEffect, useState, useEffect } from "preact/hooks";
|
|
4
|
+
import { usePlugin, useCapability } from "@embedpdf/core/preact";
|
|
3
5
|
import { ViewportPlugin } from "@embedpdf/plugin-viewport";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// src/preact/components/viewport.tsx
|
|
8
|
-
import { useEffect, useState } from "preact/hooks";
|
|
9
|
-
|
|
10
|
-
// src/preact/hooks/use-viewport-ref.ts
|
|
11
|
-
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
6
|
+
const useViewportPlugin = () => usePlugin(ViewportPlugin.id);
|
|
7
|
+
const useViewportCapability = () => useCapability(ViewportPlugin.id);
|
|
12
8
|
function useViewportRef() {
|
|
13
9
|
const { plugin: viewportPlugin } = useViewportPlugin();
|
|
14
10
|
const containerRef = useRef(null);
|
|
@@ -60,9 +56,6 @@ function useViewportRef() {
|
|
|
60
56
|
}, [viewportPlugin]);
|
|
61
57
|
return containerRef;
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
// src/preact/components/viewport.tsx
|
|
65
|
-
import { jsx } from "preact/jsx-runtime";
|
|
66
59
|
function Viewport({ children, ...props }) {
|
|
67
60
|
const [viewportGap, setViewportGap] = useState(0);
|
|
68
61
|
const viewportRef = useViewportRef();
|
|
@@ -89,6 +82,7 @@ function Viewport({ children, ...props }) {
|
|
|
89
82
|
export {
|
|
90
83
|
Viewport,
|
|
91
84
|
useViewportCapability,
|
|
92
|
-
useViewportPlugin
|
|
85
|
+
useViewportPlugin,
|
|
86
|
+
useViewportRef
|
|
93
87
|
};
|
|
94
|
-
//# sourceMappingURL=index.js.map
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-viewport.ts","../../src/shared/hooks/use-viewport-ref.ts","../../src/shared/components/viewport.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nexport const useViewportPlugin = () => usePlugin<ViewportPlugin>(ViewportPlugin.id);\nexport const useViewportCapability = () => useCapability<ViewportPlugin>(ViewportPlugin.id);\n","import { Rect } from '@embedpdf/models';\nimport { useLayoutEffect, useRef } from '@framework';\n\nimport { useViewportPlugin } from './use-viewport';\n\nexport function useViewportRef() {\n const { plugin: viewportPlugin } = useViewportPlugin();\n const containerRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n if (!viewportPlugin) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n /* ---------- live rect provider --------------------------------- */\n const provideRect = (): Rect => {\n const r = container.getBoundingClientRect();\n return {\n origin: { x: r.left, y: r.top },\n size: { width: r.width, height: r.height },\n };\n };\n viewportPlugin.registerBoundingRectProvider(provideRect);\n\n // Example: On scroll, call setMetrics\n const onScroll = () => {\n viewportPlugin.setViewportScrollMetrics({\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n });\n };\n container.addEventListener('scroll', onScroll);\n\n // Example: On resize, call setMetrics\n const resizeObserver = new ResizeObserver(() => {\n viewportPlugin.setViewportResizeMetrics({\n width: container.offsetWidth,\n height: container.offsetHeight,\n clientWidth: container.clientWidth,\n clientHeight: container.clientHeight,\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n scrollWidth: container.scrollWidth,\n scrollHeight: container.scrollHeight,\n });\n });\n resizeObserver.observe(container);\n\n const unsubscribeScrollRequest = viewportPlugin.onScrollRequest(\n ({ x, y, behavior = 'auto' }) => {\n requestAnimationFrame(() => {\n container.scrollTo({ left: x, top: y, behavior });\n });\n },\n );\n\n // Cleanup\n return () => {\n viewportPlugin.registerBoundingRectProvider(null);\n container.removeEventListener('scroll', onScroll);\n resizeObserver.disconnect();\n unsubscribeScrollRequest();\n };\n }, [viewportPlugin]);\n\n // Return the ref so your React code can attach it to a div\n return containerRef;\n}\n","import { ReactNode, useEffect, useState, HTMLAttributes } from '@framework';\n\nimport { useViewportCapability } from '../hooks';\nimport { useViewportRef } from '../hooks/use-viewport-ref';\n\ntype ViewportProps = HTMLAttributes<HTMLDivElement> & {\n children: ReactNode;\n};\n\nexport function Viewport({ children, ...props }: ViewportProps) {\n const [viewportGap, setViewportGap] = useState(0);\n const viewportRef = useViewportRef();\n const { provides: viewportProvides } = useViewportCapability();\n\n useEffect(() => {\n if (viewportProvides) {\n setViewportGap(viewportProvides.getViewportGap());\n }\n }, [viewportProvides]);\n\n const { style, ...restProps } = props;\n return (\n <div\n {...restProps}\n ref={viewportRef}\n style={{\n ...(typeof style === 'object' ? style : {}),\n padding: `${viewportGap}px`,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAGO,MAAM,oBAAoB,MAAM,UAA0B,eAAe,EAAE;AAC3E,MAAM,wBAAwB,MAAM,cAA8B,eAAe,EAAE;ACCnF,SAAS,iBAAiB;AAC/B,QAAM,EAAE,QAAQ,eAAe,IAAI,kBAAkB;AAC/C,QAAA,eAAe,OAAuB,IAAI;AAEhD,kBAAgB,MAAM;AACpB,QAAI,CAAC,eAAgB;AAErB,UAAM,YAAY,aAAa;AAC/B,QAAI,CAAC,UAAW;AAGhB,UAAM,cAAc,MAAY;AACxB,YAAA,IAAI,UAAU,sBAAsB;AACnC,aAAA;AAAA,QACL,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,IAAI;AAAA,QAC9B,MAAM,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAAA,MAC3C;AAAA,IACF;AACA,mBAAe,6BAA6B,WAAW;AAGvD,UAAM,WAAW,MAAM;AACrB,qBAAe,yBAAyB;AAAA,QACtC,WAAW,UAAU;AAAA,QACrB,YAAY,UAAU;AAAA,MAAA,CACvB;AAAA,IACH;AACU,cAAA,iBAAiB,UAAU,QAAQ;AAGvC,UAAA,iBAAiB,IAAI,eAAe,MAAM;AAC9C,qBAAe,yBAAyB;AAAA,QACtC,OAAO,UAAU;AAAA,QACjB,QAAQ,UAAU;AAAA,QAClB,aAAa,UAAU;AAAA,QACvB,cAAc,UAAU;AAAA,QACxB,WAAW,UAAU;AAAA,QACrB,YAAY,UAAU;AAAA,QACtB,aAAa,UAAU;AAAA,QACvB,cAAc,UAAU;AAAA,MAAA,CACzB;AAAA,IAAA,CACF;AACD,mBAAe,QAAQ,SAAS;AAEhC,UAAM,2BAA2B,eAAe;AAAA,MAC9C,CAAC,EAAE,GAAG,GAAG,WAAW,aAAa;AAC/B,8BAAsB,MAAM;AAC1B,oBAAU,SAAS,EAAE,MAAM,GAAG,KAAK,GAAG,UAAU;AAAA,QAAA,CACjD;AAAA,MAAA;AAAA,IAEL;AAGA,WAAO,MAAM;AACX,qBAAe,6BAA6B,IAAI;AACtC,gBAAA,oBAAoB,UAAU,QAAQ;AAChD,qBAAe,WAAW;AACD,+BAAA;AAAA,IAC3B;AAAA,EAAA,GACC,CAAC,cAAc,CAAC;AAGZ,SAAA;AACT;AC3DO,SAAS,SAAS,EAAE,UAAU,GAAG,SAAwB;AAC9D,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,CAAC;AAChD,QAAM,cAAc,eAAe;AACnC,QAAM,EAAE,UAAU,iBAAiB,IAAI,sBAAsB;AAE7D,YAAU,MAAM;AACd,QAAI,kBAAkB;AACL,qBAAA,iBAAiB,gBAAgB;AAAA,IAAA;AAAA,EAClD,GACC,CAAC,gBAAgB,CAAC;AAErB,QAAM,EAAE,OAAO,GAAG,UAAA,IAAc;AAE9B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,KAAK;AAAA,MACL,OAAO;AAAA,QACL,GAAI,OAAO,UAAU,WAAW,QAAQ,CAAC;AAAA,QACzC,SAAS,GAAG,WAAW;AAAA,MACzB;AAAA,MAEC;AAAA,IAAA;AAAA,EACH;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/react';
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,125 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/react/index.ts
|
|
21
|
-
var react_exports = {};
|
|
22
|
-
__export(react_exports, {
|
|
23
|
-
Viewport: () => Viewport,
|
|
24
|
-
useViewportCapability: () => useViewportCapability,
|
|
25
|
-
useViewportPlugin: () => useViewportPlugin,
|
|
26
|
-
useViewportRef: () => useViewportRef
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(react_exports);
|
|
29
|
-
|
|
30
|
-
// src/react/components/viewport.tsx
|
|
31
|
-
var import_react3 = require("react");
|
|
32
|
-
|
|
33
|
-
// src/react/hooks/use-viewport.ts
|
|
34
|
-
var import_react = require("@embedpdf/core/react");
|
|
35
|
-
var import_plugin_viewport = require("@embedpdf/plugin-viewport");
|
|
36
|
-
var useViewportPlugin = () => (0, import_react.usePlugin)(import_plugin_viewport.ViewportPlugin.id);
|
|
37
|
-
var useViewportCapability = () => (0, import_react.useCapability)(import_plugin_viewport.ViewportPlugin.id);
|
|
38
|
-
|
|
39
|
-
// src/react/hooks/use-viewport-ref.ts
|
|
40
|
-
var import_react2 = require("react");
|
|
41
|
-
function useViewportRef() {
|
|
42
|
-
const { plugin: viewportPlugin } = useViewportPlugin();
|
|
43
|
-
const containerRef = (0, import_react2.useRef)(null);
|
|
44
|
-
(0, import_react2.useLayoutEffect)(() => {
|
|
45
|
-
if (!viewportPlugin) return;
|
|
46
|
-
const container = containerRef.current;
|
|
47
|
-
if (!container) return;
|
|
48
|
-
const provideRect = () => {
|
|
49
|
-
const r = container.getBoundingClientRect();
|
|
50
|
-
return {
|
|
51
|
-
origin: { x: r.left, y: r.top },
|
|
52
|
-
size: { width: r.width, height: r.height }
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
viewportPlugin.registerBoundingRectProvider(provideRect);
|
|
56
|
-
const onScroll = () => {
|
|
57
|
-
viewportPlugin.setViewportScrollMetrics({
|
|
58
|
-
scrollTop: container.scrollTop,
|
|
59
|
-
scrollLeft: container.scrollLeft
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
container.addEventListener("scroll", onScroll);
|
|
63
|
-
const resizeObserver = new ResizeObserver(() => {
|
|
64
|
-
viewportPlugin.setViewportResizeMetrics({
|
|
65
|
-
width: container.offsetWidth,
|
|
66
|
-
height: container.offsetHeight,
|
|
67
|
-
clientWidth: container.clientWidth,
|
|
68
|
-
clientHeight: container.clientHeight,
|
|
69
|
-
scrollTop: container.scrollTop,
|
|
70
|
-
scrollLeft: container.scrollLeft,
|
|
71
|
-
scrollWidth: container.scrollWidth,
|
|
72
|
-
scrollHeight: container.scrollHeight
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
resizeObserver.observe(container);
|
|
76
|
-
const unsubscribeScrollRequest = viewportPlugin.onScrollRequest(
|
|
77
|
-
({ x, y, behavior = "auto" }) => {
|
|
78
|
-
requestAnimationFrame(() => {
|
|
79
|
-
container.scrollTo({ left: x, top: y, behavior });
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
return () => {
|
|
84
|
-
viewportPlugin.registerBoundingRectProvider(null);
|
|
85
|
-
container.removeEventListener("scroll", onScroll);
|
|
86
|
-
resizeObserver.disconnect();
|
|
87
|
-
unsubscribeScrollRequest();
|
|
88
|
-
};
|
|
89
|
-
}, [viewportPlugin]);
|
|
90
|
-
return containerRef;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/react/components/viewport.tsx
|
|
94
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
95
|
-
function Viewport({ children, ...props }) {
|
|
96
|
-
const [viewportGap, setViewportGap] = (0, import_react3.useState)(0);
|
|
97
|
-
const viewportRef = useViewportRef();
|
|
98
|
-
const { provides: viewportProvides } = useViewportCapability();
|
|
99
|
-
(0, import_react3.useEffect)(() => {
|
|
100
|
-
if (viewportProvides) {
|
|
101
|
-
setViewportGap(viewportProvides.getViewportGap());
|
|
102
|
-
}
|
|
103
|
-
}, [viewportProvides]);
|
|
104
|
-
const { style, ...restProps } = props;
|
|
105
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
106
|
-
"div",
|
|
107
|
-
{
|
|
108
|
-
...restProps,
|
|
109
|
-
ref: viewportRef,
|
|
110
|
-
style: {
|
|
111
|
-
...typeof style === "object" ? style : {},
|
|
112
|
-
padding: `${viewportGap}px`
|
|
113
|
-
},
|
|
114
|
-
children
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
-
0 && (module.exports = {
|
|
120
|
-
Viewport,
|
|
121
|
-
useViewportCapability,
|
|
122
|
-
useViewportPlugin,
|
|
123
|
-
useViewportRef
|
|
124
|
-
});
|
|
125
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),r=require("@embedpdf/core/react"),i=require("@embedpdf/plugin-viewport"),o=()=>r.usePlugin(i.ViewportPlugin.id),s=()=>r.useCapability(i.ViewportPlugin.id);function l(){const{plugin:e}=o(),r=t.useRef(null);return t.useLayoutEffect((()=>{if(!e)return;const t=r.current;if(!t)return;e.registerBoundingRectProvider((()=>{const e=t.getBoundingClientRect();return{origin:{x:e.left,y:e.top},size:{width:e.width,height:e.height}}}));const i=()=>{e.setViewportScrollMetrics({scrollTop:t.scrollTop,scrollLeft:t.scrollLeft})};t.addEventListener("scroll",i);const o=new ResizeObserver((()=>{e.setViewportResizeMetrics({width:t.offsetWidth,height:t.offsetHeight,clientWidth:t.clientWidth,clientHeight:t.clientHeight,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight})}));o.observe(t);const s=e.onScrollRequest((({x:e,y:r,behavior:i="auto"})=>{requestAnimationFrame((()=>{t.scrollTo({left:e,top:r,behavior:i})}))}));return()=>{e.registerBoundingRectProvider(null),t.removeEventListener("scroll",i),o.disconnect(),s()}}),[e]),r}exports.Viewport=function({children:r,...i}){const[o,n]=t.useState(0),c=l(),{provides:u}=s();t.useEffect((()=>{u&&n(u.getViewportGap())}),[u]);const{style:p,...d}=i;return e.jsx("div",{...d,ref:c,style:{..."object"==typeof p?p:{},padding:`${o}px`},children:r})},exports.useViewportCapability=s,exports.useViewportPlugin=o,exports.useViewportRef=l;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-viewport.ts","../../src/shared/hooks/use-viewport-ref.ts","../../src/shared/components/viewport.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nexport const useViewportPlugin = () => usePlugin<ViewportPlugin>(ViewportPlugin.id);\nexport const useViewportCapability = () => useCapability<ViewportPlugin>(ViewportPlugin.id);\n","import { Rect } from '@embedpdf/models';\nimport { useLayoutEffect, useRef } from '@framework';\n\nimport { useViewportPlugin } from './use-viewport';\n\nexport function useViewportRef() {\n const { plugin: viewportPlugin } = useViewportPlugin();\n const containerRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n if (!viewportPlugin) return;\n\n const container = containerRef.current;\n if (!container) return;\n\n /* ---------- live rect provider --------------------------------- */\n const provideRect = (): Rect => {\n const r = container.getBoundingClientRect();\n return {\n origin: { x: r.left, y: r.top },\n size: { width: r.width, height: r.height },\n };\n };\n viewportPlugin.registerBoundingRectProvider(provideRect);\n\n // Example: On scroll, call setMetrics\n const onScroll = () => {\n viewportPlugin.setViewportScrollMetrics({\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n });\n };\n container.addEventListener('scroll', onScroll);\n\n // Example: On resize, call setMetrics\n const resizeObserver = new ResizeObserver(() => {\n viewportPlugin.setViewportResizeMetrics({\n width: container.offsetWidth,\n height: container.offsetHeight,\n clientWidth: container.clientWidth,\n clientHeight: container.clientHeight,\n scrollTop: container.scrollTop,\n scrollLeft: container.scrollLeft,\n scrollWidth: container.scrollWidth,\n scrollHeight: container.scrollHeight,\n });\n });\n resizeObserver.observe(container);\n\n const unsubscribeScrollRequest = viewportPlugin.onScrollRequest(\n ({ x, y, behavior = 'auto' }) => {\n requestAnimationFrame(() => {\n container.scrollTo({ left: x, top: y, behavior });\n });\n },\n );\n\n // Cleanup\n return () => {\n viewportPlugin.registerBoundingRectProvider(null);\n container.removeEventListener('scroll', onScroll);\n resizeObserver.disconnect();\n unsubscribeScrollRequest();\n };\n }, [viewportPlugin]);\n\n // Return the ref so your React code can attach it to a div\n return containerRef;\n}\n","import { ReactNode, useEffect, useState, HTMLAttributes } from '@framework';\n\nimport { useViewportCapability } from '../hooks';\nimport { useViewportRef } from '../hooks/use-viewport-ref';\n\ntype ViewportProps = HTMLAttributes<HTMLDivElement> & {\n children: ReactNode;\n};\n\nexport function Viewport({ children, ...props }: ViewportProps) {\n const [viewportGap, setViewportGap] = useState(0);\n const viewportRef = useViewportRef();\n const { provides: viewportProvides } = useViewportCapability();\n\n useEffect(() => {\n if (viewportProvides) {\n setViewportGap(viewportProvides.getViewportGap());\n }\n }, [viewportProvides]);\n\n const { style, ...restProps } = props;\n return (\n <div\n {...restProps}\n ref={viewportRef}\n style={{\n ...(typeof style === 'object' ? style : {}),\n padding: `${viewportGap}px`,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useViewportPlugin","usePlugin","ViewportPlugin","id","useViewportCapability","useCapability","useViewportRef","plugin","viewportPlugin","containerRef","useRef","useLayoutEffect","container","current","registerBoundingRectProvider","r","getBoundingClientRect","origin","x","left","y","top","size","width","height","onScroll","setViewportScrollMetrics","scrollTop","scrollLeft","addEventListener","resizeObserver","ResizeObserver","setViewportResizeMetrics","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","observe","unsubscribeScrollRequest","onScrollRequest","behavior","requestAnimationFrame","scrollTo","removeEventListener","disconnect","children","props","viewportGap","setViewportGap","useState","viewportRef","provides","viewportProvides","useEffect","getViewportGap","style","restProps","jsxRuntime","jsx","ref","padding"],"mappings":"iNAGaA,EAAoB,IAAMC,YAA0BC,EAAAA,eAAeC,IACnEC,EAAwB,IAAMC,gBAA8BH,EAAAA,eAAeC,ICCjF,SAASG,IACd,MAAQC,OAAQC,GAAmBR,IAC7BS,EAAeC,SAAuB,MA4DrC,OA1DPC,EAAAA,iBAAgB,KACd,IAAKH,EAAgB,OAErB,MAAMI,EAAYH,EAAaI,QAC/B,IAAKD,EAAW,OAUhBJ,EAAeM,8BAPK,KACZ,MAAAC,EAAIH,EAAUI,wBACb,MAAA,CACLC,OAAQ,CAAEC,EAAGH,EAAEI,KAAMC,EAAGL,EAAEM,KAC1BC,KAAM,CAAEC,MAAOR,EAAEQ,MAAOC,OAAQT,EAAES,QACpC,IAKF,MAAMC,EAAW,KACfjB,EAAekB,yBAAyB,CACtCC,UAAWf,EAAUe,UACrBC,WAAYhB,EAAUgB,YACvB,EAEOhB,EAAAiB,iBAAiB,SAAUJ,GAG/B,MAAAK,EAAiB,IAAIC,gBAAe,KACxCvB,EAAewB,yBAAyB,CACtCT,MAAOX,EAAUqB,YACjBT,OAAQZ,EAAUsB,aAClBC,YAAavB,EAAUuB,YACvBC,aAAcxB,EAAUwB,aACxBT,UAAWf,EAAUe,UACrBC,WAAYhB,EAAUgB,WACtBS,YAAazB,EAAUyB,YACvBC,aAAc1B,EAAU0B,cACzB,IAEHR,EAAeS,QAAQ3B,GAEvB,MAAM4B,EAA2BhC,EAAeiC,iBAC9C,EAAGvB,IAAGE,IAAGsB,WAAW,WAClBC,uBAAsB,KACpB/B,EAAUgC,SAAS,CAAEzB,KAAMD,EAAGG,IAAKD,EAAGsB,YAAU,GACjD,IAKL,MAAO,KACLlC,EAAeM,6BAA6B,MAClCF,EAAAiC,oBAAoB,SAAUpB,GACxCK,EAAegB,aACUN,GAAA,CAC3B,GACC,CAAChC,IAGGC,CACT,kBC3DO,UAAkBsC,SAAEA,KAAaC,IACtC,MAAOC,EAAaC,GAAkBC,EAAAA,SAAS,GACzCC,EAAc9C,KACZ+C,SAAUC,GAAqBlD,IAEvCmD,EAAAA,WAAU,KACJD,GACaJ,EAAAI,EAAiBE,iBAAgB,GAEjD,CAACF,IAEJ,MAAMG,MAAEA,KAAUC,GAAcV,EAE9B,OAAAW,EAAAC,IAAC,MAAA,IACKF,EACJG,IAAKT,EACLK,MAAO,IACgB,iBAAVA,EAAqBA,EAAQ,CAAC,EACzCK,QAAS,GAAGb,OAGbF,YAGP"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import React__default, { ReactNode } from 'react';
|
|
4
|
-
import * as _embedpdf_plugin_viewport from '@embedpdf/plugin-viewport';
|
|
5
|
-
import { ViewportPlugin } from '@embedpdf/plugin-viewport';
|
|
6
|
-
|
|
7
|
-
type ViewportProps = React__default.HTMLAttributes<HTMLDivElement> & {
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
};
|
|
10
|
-
declare function Viewport({ children, ...props }: ViewportProps): react_jsx_runtime.JSX.Element;
|
|
11
|
-
|
|
12
|
-
declare const useViewportPlugin: () => {
|
|
13
|
-
plugin: ViewportPlugin | null;
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
ready: Promise<void>;
|
|
16
|
-
};
|
|
17
|
-
declare const useViewportCapability: () => {
|
|
18
|
-
provides: Readonly<_embedpdf_plugin_viewport.ViewportCapability> | null;
|
|
19
|
-
isLoading: boolean;
|
|
20
|
-
ready: Promise<void>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
declare function useViewportRef(): React.RefObject<HTMLDivElement>;
|
|
24
|
-
|
|
25
|
-
export { Viewport, useViewportCapability, useViewportPlugin, useViewportRef };
|
|
1
|
+
export * from '../shared-react';
|
package/dist/react/index.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// src/react/hooks/use-viewport.ts
|
|
5
|
-
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useLayoutEffect, useState, useEffect } from "react";
|
|
3
|
+
import { usePlugin, useCapability } from "@embedpdf/core/react";
|
|
6
4
|
import { ViewportPlugin } from "@embedpdf/plugin-viewport";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/react/hooks/use-viewport-ref.ts
|
|
11
|
-
import { useLayoutEffect, useRef } from "react";
|
|
5
|
+
const useViewportPlugin = () => usePlugin(ViewportPlugin.id);
|
|
6
|
+
const useViewportCapability = () => useCapability(ViewportPlugin.id);
|
|
12
7
|
function useViewportRef() {
|
|
13
8
|
const { plugin: viewportPlugin } = useViewportPlugin();
|
|
14
9
|
const containerRef = useRef(null);
|
|
@@ -60,9 +55,6 @@ function useViewportRef() {
|
|
|
60
55
|
}, [viewportPlugin]);
|
|
61
56
|
return containerRef;
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
// src/react/components/viewport.tsx
|
|
65
|
-
import { jsx } from "react/jsx-runtime";
|
|
66
58
|
function Viewport({ children, ...props }) {
|
|
67
59
|
const [viewportGap, setViewportGap] = useState(0);
|
|
68
60
|
const viewportRef = useViewportRef();
|
|
@@ -92,4 +84,4 @@ export {
|
|
|
92
84
|
useViewportPlugin,
|
|
93
85
|
useViewportRef
|
|
94
86
|
};
|
|
95
|
-
//# sourceMappingURL=index.js.map
|
|
87
|
+
//# sourceMappingURL=index.js.map
|