@react-pdf-kit/viewer 2.8.0-beta.6 → 2.8.0-beta.8
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/README.md +44 -30
- package/dist/{AnnotationLayer-CAIvKf_O.js → AnnotationLayer-CyOYh0Tw.js} +2 -2
- package/dist/CanvasLayer-CJqCJ30J.js +111 -0
- package/dist/{LoadingIndicator-DiWoWs4Y.js → LoadingIndicator-B_Jsf8No.js} +7 -7
- package/dist/MenuItem-D-GflAAo.js +31 -0
- package/dist/PaginationContext-DIzsZhFd.js +194 -0
- package/dist/{PasswordModal-CB9Rd2zJ.js → PasswordModal-S0leMhEd.js} +11 -11
- package/dist/RPLayout.module-BH5r8dDc.js +14 -0
- package/dist/RPPages-BQw330_L.js +655 -0
- package/dist/{RPTooltip-ZZoFqP7C.js → RPTooltip-COLVx-C_.js} +123 -91
- package/dist/SearchTool.module-DY8Ucfb_.js +17 -0
- package/dist/{SkipLink-CdcjClGB.js → SkipLink-Dj83gZdk.js} +3 -3
- package/dist/{TextLayer-DWGFN9SF.js → TextLayer-D-V9kogG.js} +5 -5
- package/dist/{Thumbnail-CzclS3h_.js → Thumbnail-C6zkvwcs.js} +6 -6
- package/dist/{Thumbnails-DnAsrttK.js → Thumbnails-DKG6I7pb.js} +2 -2
- package/dist/assets/AnnotationLayer.css +1 -1
- package/dist/assets/CanvasLayer.css +1 -0
- package/dist/assets/LoadingIndicator.css +1 -1
- package/dist/assets/MenuItem.css +1 -1
- package/dist/assets/PasswordModal.css +1 -1
- package/dist/assets/RPLayout.css +1 -1
- package/dist/assets/RPPages.css +1 -1
- package/dist/assets/SearchTool.css +1 -1
- package/dist/assets/SkipLink.css +1 -1
- package/dist/assets/TextLayer.css +1 -1
- package/dist/assets/Thumbnail.css +1 -1
- package/dist/assets/style.js +1 -1
- package/dist/components/RPController.js +39 -39
- package/dist/components/RPPages.js +1 -1
- package/dist/components/RPProvider.js +1 -1
- package/dist/components/layout/LayoutContainer.js +6 -6
- package/dist/components/layout/LayoutWrapper.js +5 -5
- package/dist/components/layout/RPDefaultLayout.js +2 -2
- package/dist/components/layout/RPLayout.js +2 -2
- package/dist/components/layout/SkipLink.js +1 -1
- package/dist/components/layout/sidebar/RPSidebar.js +2 -2
- package/dist/components/layout/sidebar/Thumbnail.js +1 -1
- package/dist/components/layout/sidebar/Thumbnails.js +1 -1
- package/dist/components/layout/toolbar/DarkModeTool.js +1 -1
- package/dist/components/layout/toolbar/DocumentProperties.js +6 -6
- package/dist/components/layout/toolbar/FileDownloadTool.js +6 -6
- package/dist/components/layout/toolbar/FileUploadTool.js +6 -6
- package/dist/components/layout/toolbar/FullScreenTool.js +9 -8
- package/dist/components/layout/toolbar/MenuItem.js +1 -1
- package/dist/components/layout/toolbar/MostPageTool.js +23 -29
- package/dist/components/layout/toolbar/OtherTool.js +1 -1
- package/dist/components/layout/toolbar/Paginate.js +2 -2
- package/dist/components/layout/toolbar/PrintTool.js +6 -6
- package/dist/components/layout/toolbar/RPMenuItem.js +2 -2
- package/dist/components/layout/toolbar/RPMoreOptions.js +1 -1
- package/dist/components/layout/toolbar/RPToolbar.js +1 -1
- package/dist/components/layout/toolbar/RotateTool.js +10 -10
- package/dist/components/layout/toolbar/ScrollModeTool.js +17 -17
- package/dist/components/layout/toolbar/SearchCloseButton.js +2 -2
- package/dist/components/layout/toolbar/SearchResultNavigator.js +2 -2
- package/dist/components/layout/toolbar/SearchTool.js +133 -121
- package/dist/components/layout/toolbar/SelectionModeTool.js +10 -10
- package/dist/components/layout/toolbar/ThumbnailTool.js +1 -1
- package/dist/components/layout/toolbar/ToolbarCustom.js +2 -2
- package/dist/components/layout/toolbar/ToolbarDefault.js +2 -2
- package/dist/components/layout/toolbar/ViewModeTool.js +16 -16
- package/dist/components/layout/toolbar/ZoomTool.js +82 -80
- package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +1 -1
- package/dist/components/layout/toolbar/tools/DualPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FileDownloadTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FileUploadTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FullScreenTool.js +1 -1
- package/dist/components/layout/toolbar/tools/HorizontalScrollingTool.js +3 -3
- package/dist/components/layout/toolbar/tools/InputPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/LastPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/NextPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/PageScrollingTool.js +1 -1
- package/dist/components/layout/toolbar/tools/PreviousPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/PrintTool.js +1 -1
- package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +1 -1
- package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +1 -1
- package/dist/components/layout/toolbar/tools/SelectionModeSwitcherTool.js +1 -1
- package/dist/components/layout/toolbar/tools/SinglePageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/ThemeSwitcherTool.js +1 -1
- package/dist/components/layout/toolbar/tools/ThumbnailTool.js +1 -1
- package/dist/components/layout/toolbar/tools/VerticalScrollingTool.js +1 -1
- package/dist/components/layout/toolbar/tools/ZoomInTool.js +25 -23
- package/dist/components/layout/toolbar/tools/ZoomLevelDisplay.js +1 -1
- package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +2 -2
- package/dist/components/layout/toolbar/tools/ZoomOutTool.js +25 -23
- package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +3 -3
- package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +7 -7
- package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +2 -2
- package/dist/components/page/AnnotationLayer.js +1 -1
- package/dist/components/page/CanvasLayer.js +2 -48
- package/dist/components/page/DualPage.js +2 -2
- package/dist/components/page/DualPageWithCover.js +2 -2
- package/dist/components/page/RPPage.js +94 -2
- package/dist/components/page/SinglePage.js +2 -2
- package/dist/components/page/TextHighlightLayer.js +1 -1
- package/dist/components/page/TextLayer.js +1 -1
- package/dist/components/ui/LoadingIndicator.js +1 -1
- package/dist/components/ui/PasswordModal.js +1 -1
- package/dist/components/ui/RPTooltip.js +1 -1
- package/dist/contexts/DimensionPagesContext.js +38 -22
- package/dist/contexts/ElementPageContext.js +46 -39
- package/dist/contexts/ElementThumbnailContext.js +1 -1
- package/dist/contexts/PaginationContext.js +1 -1
- package/dist/contexts/RenderQueueProvider.js +24 -18
- package/dist/contexts/RenderedPagesCache.js +32 -13
- package/dist/contexts/VirtualScrollContext.js +10 -13
- package/dist/contexts/ZoomContext.js +119 -61
- package/dist/{de_DE-DwUvXUWH.js → de_DE-x4Z-jQrz.js} +30 -0
- package/dist/{main-CKr9unOk.js → main-7sMXtgRg.js} +2 -2
- package/dist/main.js +4 -4
- package/dist/style-CJtyyrJx.js +5 -0
- package/dist/types/components/page/CanvasLayer.d.ts +4 -1
- package/dist/types/components/ui/RPTooltip.d.ts +3 -2
- package/dist/types/contexts/RenderQueueProvider.d.ts +2 -0
- package/dist/types/contexts/RenderedPagesCache.d.ts +3 -0
- package/dist/types/contexts/VirtualScrollContext.d.ts +0 -3
- package/dist/types/locales/de_DE.json.d.ts +5 -0
- package/dist/types/locales/en_US.json.d.ts +5 -0
- package/dist/types/locales/it_IT.json.d.ts +5 -0
- package/dist/types/locales/pt_PT.json.d.ts +5 -0
- package/dist/types/locales/th_TH.json.d.ts +5 -0
- package/dist/types/locales/zh_CN.json.d.ts +5 -0
- package/dist/types/utils/Queue.d.ts +1 -0
- package/dist/types/utils/const.d.ts +3 -0
- package/dist/types/utils/constants.d.ts +9 -0
- package/dist/types/utils/documentLayout.d.ts +60 -0
- package/dist/types/utils/hooks/usePinch.d.ts +14 -1
- package/dist/types/utils/hooks/usePresentPage.d.ts +2 -2
- package/dist/types/utils/hooks/useZoomOrigin.d.ts +4 -0
- package/dist/types/utils/types.d.ts +21 -2
- package/dist/types/utils/zoom.d.ts +2 -0
- package/dist/utils/Queue.js +5 -0
- package/dist/utils/const.js +2 -2
- package/dist/utils/constants.js +2 -2
- package/dist/utils/documentLayout.js +141 -0
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/useLoadPdf.js +73 -63
- package/dist/utils/hooks/useLocalization.js +1 -1
- package/dist/utils/hooks/usePaginate.js +1 -1
- package/dist/utils/hooks/usePinch.js +109 -56
- package/dist/utils/hooks/usePresentPage.js +33 -57
- package/dist/utils/hooks/useScrollToPage.js +1 -1
- package/dist/utils/hooks/useSearch.js +66 -67
- package/dist/utils/hooks/useZoomOrigin.js +37 -0
- package/dist/utils/renderPage.js +21 -14
- package/dist/utils/types.js +3 -3
- package/dist/utils/zoom.js +8 -2
- package/package.json +1 -1
- package/dist/MenuItem-BJDWfzAw.js +0 -15
- package/dist/PaginationContext-Cwf8sCpK.js +0 -242
- package/dist/RPLayout.module-Vc3h4xxS.js +0 -14
- package/dist/RPPage-C_r8aeTc.js +0 -91
- package/dist/RPPages-CmXHTAqF.js +0 -1007
- package/dist/SearchTool.module-DUkVXfOn.js +0 -16
- package/dist/assets/RPPage.css +0 -1
- package/dist/contexts/VirtualGridContext.js +0 -18
- package/dist/style-C8T5x1fE.js +0 -5
- package/dist/types/contexts/VirtualGridContext.d.ts +0 -9
- package/dist/types/utils/calculatePage.d.ts +0 -12
- package/dist/types/utils/hooks/useVirtualReactWindow.d.ts +0 -17
- package/dist/utils/calculatePage.js +0 -30
- package/dist/utils/hooks/useVirtualReactWindow.js +0 -86
- /package/dist/{TextHighlightLayer-BSVgBxR3.js → TextHighlightLayer-3vIZbRyL.js} +0 -0
|
@@ -2,75 +2,83 @@
|
|
|
2
2
|
import { ErrorType as e } from "../types.js";
|
|
3
3
|
import { getThumbnailViewport as t } from "../getThumbnailViewport.js";
|
|
4
4
|
import { useConfigContext as n } from "../../contexts/ConfigContext.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
5
|
+
import { appConsole as r } from "../appConsole.js";
|
|
6
|
+
import { useDocumentPasswordContext as i } from "../../contexts/DocumentPasswordContext.js";
|
|
7
|
+
import { BROWSER_NOT_SUPPORTED_MESSAGE as a, INVALID_OR_CORRUPTED_PDF_MESSAGE as o, WASM_URL_REQUIRED_CONSOLE_MESSAGE as s, WASM_URL_REQUIRED_MESSAGE as c } from "../const.js";
|
|
8
|
+
import { useEffect as l, useRef as u, useState as d } from "react";
|
|
9
|
+
import * as f from "pdfjs-dist";
|
|
9
10
|
//#region lib/utils/hooks/useLoadPdf.ts
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
var p = new TextEncoder().encode("/JPXDecode");
|
|
12
|
+
function m(e) {
|
|
13
|
+
return e.some((t, n) => t === p[0] ? p.every((t, r) => e[n + r] === t) : !1);
|
|
14
|
+
}
|
|
15
|
+
function h(e) {
|
|
16
|
+
let t = Error(o);
|
|
12
17
|
return t.cause = e, t;
|
|
13
18
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
19
|
+
function g() {
|
|
20
|
+
return Error(c);
|
|
21
|
+
}
|
|
22
|
+
function _(e) {
|
|
23
|
+
let t = Error(a);
|
|
16
24
|
return t.cause = e, t;
|
|
17
25
|
}
|
|
18
|
-
var
|
|
19
|
-
let [p,
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
}, [
|
|
23
|
-
if (!
|
|
24
|
-
|
|
25
|
-
let t =
|
|
26
|
-
url:
|
|
27
|
-
cMapPacked:
|
|
28
|
-
...
|
|
29
|
-
...
|
|
30
|
-
...
|
|
31
|
-
...
|
|
32
|
-
...
|
|
33
|
-
...
|
|
34
|
-
...
|
|
35
|
-
...
|
|
36
|
-
verbosity:
|
|
26
|
+
var v = (a, o, c = {}) => {
|
|
27
|
+
let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b } = n(), [x, S] = d(/* @__PURE__ */ new Map()), C = u(), [w, T] = d(0), [E, D] = d(!1), [O, k] = d(), { password: A, passwordError: j, setPasswordError: M, passwordRequired: N, setPasswordRequired: P } = i(), { onLoadError: F, onLoaded: I, onLoadProgress: L, disableAutoFetch: R, disableStream: z, rangeChunkSize: B, withCredentials: V, httpHeaders: H } = c;
|
|
28
|
+
return l(() => {
|
|
29
|
+
L && L(w);
|
|
30
|
+
}, [w, L]), l(() => {
|
|
31
|
+
if (!y || !a) return;
|
|
32
|
+
T(0), k(void 0), C.current = Date.now();
|
|
33
|
+
let t = C.current, n = {
|
|
34
|
+
url: a,
|
|
35
|
+
cMapPacked: o?.isCompressed ?? !0,
|
|
36
|
+
...o?.url && { cMapUrl: o.url },
|
|
37
|
+
...A && { password: A },
|
|
38
|
+
...R !== void 0 && { disableAutoFetch: R },
|
|
39
|
+
...z !== void 0 && { disableStream: z },
|
|
40
|
+
...B !== void 0 && { rangeChunkSize: B },
|
|
41
|
+
...V !== void 0 && { withCredentials: V },
|
|
42
|
+
...H !== void 0 && { httpHeaders: H },
|
|
43
|
+
...b && { wasmUrl: b },
|
|
44
|
+
verbosity: f.VerbosityLevel.ERRORS
|
|
37
45
|
};
|
|
38
46
|
try {
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
if (t ===
|
|
47
|
+
let i = f.getDocument(n);
|
|
48
|
+
i.onProgress = (e) => {
|
|
49
|
+
if (t === C.current) {
|
|
42
50
|
let { loaded: t, total: n } = e;
|
|
43
|
-
|
|
51
|
+
T(n ? Math.min(100, Math.round(t / n * 100)) : 0);
|
|
44
52
|
}
|
|
45
|
-
},
|
|
46
|
-
let
|
|
53
|
+
}, D(!0), v(void 0);
|
|
54
|
+
let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === C.current && (v(void 0), k(e.WASM_URL_REQUIRED)), r.error(s), F?.(g()), n) : (t === C.current && (v(n), T(100)), I && I(n), P(!1), M(""), n)).catch((t) => {
|
|
47
55
|
if (t instanceof Error && t.name === "PasswordException") {
|
|
48
56
|
let e = t.code;
|
|
49
|
-
|
|
50
|
-
} else t instanceof Error && t.name === "InvalidPDFException" &&
|
|
57
|
+
P(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? M("Incorrect password") : M(void 0);
|
|
58
|
+
} else t instanceof Error && t.name === "InvalidPDFException" && A ? (P(!0), M("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t))) : F && F(t);
|
|
51
59
|
}).finally(() => {
|
|
52
|
-
|
|
60
|
+
D(!1);
|
|
53
61
|
});
|
|
54
62
|
return () => {
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
a.finally(() => {
|
|
64
|
+
i.destroy();
|
|
57
65
|
});
|
|
58
66
|
};
|
|
59
67
|
} catch (t) {
|
|
60
|
-
|
|
68
|
+
k(e.NOT_SUPPORTED), F?.(_(t));
|
|
61
69
|
}
|
|
62
70
|
}, [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
]),
|
|
70
|
-
if (
|
|
71
|
+
a,
|
|
72
|
+
y,
|
|
73
|
+
b,
|
|
74
|
+
A,
|
|
75
|
+
F,
|
|
76
|
+
I
|
|
77
|
+
]), l(() => {
|
|
78
|
+
if (N) return;
|
|
71
79
|
let n = /* @__PURE__ */ new Map();
|
|
72
|
-
if (!p ||
|
|
73
|
-
|
|
80
|
+
if (!p || E) {
|
|
81
|
+
S(n);
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
84
|
let r = p.numPages, i = [];
|
|
@@ -78,8 +86,10 @@ var f = (i, a, f = {}) => {
|
|
|
78
86
|
let t = p.getPage(e);
|
|
79
87
|
i.push(t);
|
|
80
88
|
}
|
|
81
|
-
Promise.
|
|
82
|
-
e.map((e) =>
|
|
89
|
+
Promise.allSettled(i).then((e) => {
|
|
90
|
+
let r = e.filter((e) => e.status === "fulfilled").map((e) => e.value);
|
|
91
|
+
if (!r.length) throw e.find((e) => e.status === "rejected")?.reason;
|
|
92
|
+
r.map((e) => {
|
|
83
93
|
let { thumbnailViewport: r, scale: i } = t(e), a = e.getViewport();
|
|
84
94
|
n.set(e.pageNumber, {
|
|
85
95
|
page: e,
|
|
@@ -87,24 +97,24 @@ var f = (i, a, f = {}) => {
|
|
|
87
97
|
thumbnailScale: i,
|
|
88
98
|
defaultRotation: a.rotation
|
|
89
99
|
});
|
|
90
|
-
}),
|
|
100
|
+
}), S(n);
|
|
91
101
|
}).catch((t) => {
|
|
92
|
-
|
|
102
|
+
v(void 0), k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t));
|
|
93
103
|
});
|
|
94
104
|
}, [
|
|
95
105
|
p,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
E,
|
|
107
|
+
N,
|
|
108
|
+
F
|
|
99
109
|
]), {
|
|
100
110
|
pdf: p,
|
|
101
|
-
pages:
|
|
102
|
-
loading:
|
|
103
|
-
error:
|
|
104
|
-
loadingProgress:
|
|
105
|
-
passwordRequired:
|
|
106
|
-
passwordError:
|
|
111
|
+
pages: x,
|
|
112
|
+
loading: E,
|
|
113
|
+
error: O,
|
|
114
|
+
loadingProgress: w,
|
|
115
|
+
passwordRequired: N,
|
|
116
|
+
passwordError: j
|
|
107
117
|
};
|
|
108
118
|
};
|
|
109
119
|
//#endregion
|
|
110
|
-
export {
|
|
120
|
+
export { v as useLoadPdf };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, i as t, n, o as r, r as i, t as a } from "../../de_DE-
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, t as a } from "../../de_DE-x4Z-jQrz.js";
|
|
2
2
|
import { useCallback as o, useMemo as s, useState as c } from "react";
|
|
3
3
|
//#region lib/utils/hooks/useLocalization.ts
|
|
4
4
|
var l = (l) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as e } from "../../PaginationContext-
|
|
1
|
+
import { i as e } from "../../PaginationContext-DIzsZhFd.js";
|
|
2
2
|
export { e as usePaginate };
|
|
@@ -1,66 +1,119 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_ZOOM_SCALE as e } from "../constants.js";
|
|
2
2
|
import { useZoomContext as t } from "../../contexts/ZoomContext.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getZoomOriginFromClientPoint as n } from "./useZoomOrigin.js";
|
|
4
|
+
import { useCallback as r, useEffect as i, useRef as a } from "react";
|
|
4
5
|
//#region lib/utils/hooks/usePinch.ts
|
|
5
|
-
var o = (
|
|
6
|
-
let {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
var o = () => 35 / (window.devicePixelRatio || 1), s = (s, c = {}) => {
|
|
7
|
+
let { targetZoom: l, zoomTo: u } = t(), { onBeforeZoom: d, onPinchEnd: f } = c, p = a(null), m = a(!1), h = a(!1), g = a(!1), _ = a(1), v = a(1), y = a(!1), b = a(!1), x = a(), S = a(l), C = a(null);
|
|
8
|
+
i(() => {
|
|
9
|
+
S.current = l;
|
|
10
|
+
}, [l]);
|
|
11
|
+
let w = r((e, t, n) => {
|
|
12
|
+
if (t === 1) return 1;
|
|
13
|
+
let r = n.current;
|
|
14
|
+
(r > 1 && t < 1 || r < 1 && t > 1) && (n.current = 1);
|
|
15
|
+
let i = Math.floor(e * t * n.current * 100) / (100 * e);
|
|
16
|
+
return n.current = t / i, i;
|
|
17
|
+
}, []), T = r((t, n, r) => {
|
|
18
|
+
let i = S.current || 1, a = 25 / 100, o = e / 100;
|
|
19
|
+
if (i >= o && t > 1 || i <= a && t < 1) return;
|
|
20
|
+
let s = Math.max(a, Math.min(o, Math.round(i * t * 100) / 100));
|
|
21
|
+
Math.abs(s - i) < 1e-10 || (d?.({
|
|
22
|
+
gesture: r,
|
|
23
|
+
previousScale: i,
|
|
24
|
+
nextScale: s,
|
|
25
|
+
origin: n
|
|
26
|
+
}), S.current = s, u(s * 100, {
|
|
27
|
+
origin: n,
|
|
28
|
+
gesture: r,
|
|
29
|
+
previousTargetZoom: i
|
|
30
|
+
}));
|
|
31
|
+
}, [d, u]), E = r((e, t) => n(s, e, t) ?? void 0, [s]), D = r(() => {
|
|
32
|
+
b.current || (y.current = !0, clearTimeout(x.current), x.current = setTimeout(() => {
|
|
33
|
+
y.current = !1;
|
|
34
|
+
}, 100));
|
|
35
|
+
}, []), O = r((e) => {
|
|
36
|
+
if (!e.ctrlKey) {
|
|
37
|
+
b.current = !1, g.current = !1;
|
|
38
|
+
return;
|
|
15
39
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
g.current || (v.current = 1), g.current = !0, b.current = !0, y.current = !1, clearTimeout(x.current), e.preventDefault();
|
|
41
|
+
let t = Math.exp(-e.deltaY / 100);
|
|
42
|
+
T(w(S.current || 1, t, v), E(e.clientX, e.clientY), "wheel");
|
|
43
|
+
}, [
|
|
44
|
+
w,
|
|
45
|
+
E,
|
|
46
|
+
T
|
|
47
|
+
]), k = (e) => Array.from(e.touches).sort((e, t) => e.identifier - t.identifier), A = r(() => {
|
|
48
|
+
!s || C.current || (C.current = {
|
|
49
|
+
touchAction: s.style.touchAction,
|
|
50
|
+
webkitUserSelect: s.style.webkitUserSelect,
|
|
51
|
+
overscrollBehavior: s.style.overscrollBehavior,
|
|
52
|
+
webkitOverflowScrolling: s.style.getPropertyValue("-webkit-overflow-scrolling")
|
|
53
|
+
}, s.style.touchAction = "none", s.style.webkitUserSelect = "none", s.style.overscrollBehavior = "contain", s.style.setProperty("-webkit-overflow-scrolling", "auto"));
|
|
54
|
+
}, [s]), j = r(() => {
|
|
55
|
+
!s || !C.current || (s.style.touchAction = C.current.touchAction, s.style.webkitUserSelect = C.current.webkitUserSelect, s.style.overscrollBehavior = C.current.overscrollBehavior, C.current.webkitOverflowScrolling ? s.style.setProperty("-webkit-overflow-scrolling", C.current.webkitOverflowScrolling) : s.style.removeProperty("-webkit-overflow-scrolling"), C.current = null);
|
|
56
|
+
}, [s]), M = r(() => {
|
|
57
|
+
if (!(m.current || p.current || h.current)) {
|
|
58
|
+
j();
|
|
34
59
|
return;
|
|
35
60
|
}
|
|
36
|
-
|
|
37
|
-
}, [f]), r(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
p.current = null, m.current = !1, h.current = !1, _.current = 1, j(), f?.();
|
|
62
|
+
}, [f, j]), N = r((e) => {
|
|
63
|
+
if (e.touches.length !== 2) {
|
|
64
|
+
M();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
A(), e.preventDefault(), e.stopPropagation();
|
|
68
|
+
let [t, n] = k(e);
|
|
69
|
+
m.current = !0, _.current = 1, p.current = {
|
|
70
|
+
touch0ScreenX: t.screenX,
|
|
71
|
+
touch0ScreenY: t.screenY,
|
|
72
|
+
touch1ScreenX: n.screenX,
|
|
73
|
+
touch1ScreenY: n.screenY
|
|
74
|
+
}, h.current = !1;
|
|
75
|
+
}, [A, M]), P = r((e) => {
|
|
76
|
+
let t = p.current;
|
|
77
|
+
if (!t || e.touches.length !== 2) {
|
|
78
|
+
M();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
e.preventDefault(), e.stopPropagation();
|
|
82
|
+
let [n, r] = k(e), i = t.touch1ScreenX - t.touch0ScreenX, a = t.touch1ScreenY - t.touch0ScreenY, s = r.screenX - n.screenX, c = r.screenY - n.screenY, l = Math.hypot(i, a) || 1, u = Math.hypot(s, c) || 1;
|
|
83
|
+
if (!h.current && Math.abs(l - u) <= o()) return;
|
|
84
|
+
if (t.touch0ScreenX = n.screenX, t.touch0ScreenY = n.screenY, t.touch1ScreenX = r.screenX, t.touch1ScreenY = r.screenY, !h.current) {
|
|
85
|
+
h.current = !0;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let d = u / l;
|
|
89
|
+
T(w(S.current || 1, d, _), E((n.clientX + r.clientX) / 2, (n.clientY + r.clientY) / 2), "touch");
|
|
90
|
+
}, [
|
|
91
|
+
w,
|
|
92
|
+
E,
|
|
93
|
+
M,
|
|
94
|
+
T
|
|
95
|
+
]), F = r((e) => {
|
|
96
|
+
e.touches.length >= 2 || (M(), v.current = 1);
|
|
97
|
+
}, [M]), I = r(() => {
|
|
98
|
+
M(), v.current = 1;
|
|
99
|
+
}, [M]), L = r(() => {
|
|
100
|
+
b.current = !1, g.current = !1, v.current = 1, y.current = !1, clearTimeout(x.current), M();
|
|
101
|
+
}, [M]);
|
|
102
|
+
i(() => {
|
|
103
|
+
if (s) return s.addEventListener("wheel", O, { passive: !1 }), s.addEventListener("scroll", D, { passive: !0 }), s.addEventListener("touchstart", N, { passive: !1 }), s.addEventListener("touchmove", P, { passive: !1 }), s.addEventListener("touchend", F, { passive: !1 }), s.addEventListener("touchcancel", I, { passive: !1 }), window.addEventListener("touchend", F, { passive: !1 }), window.addEventListener("touchcancel", I, { passive: !1 }), window.addEventListener("blur", L), () => {
|
|
104
|
+
j(), s.removeEventListener("wheel", O), s.removeEventListener("scroll", D), s.removeEventListener("touchstart", N), s.removeEventListener("touchmove", P), s.removeEventListener("touchend", F), s.removeEventListener("touchcancel", I), window.removeEventListener("touchend", F), window.removeEventListener("touchcancel", I), window.removeEventListener("blur", L), clearTimeout(x.current);
|
|
56
105
|
};
|
|
57
106
|
}, [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
107
|
+
s,
|
|
108
|
+
D,
|
|
109
|
+
I,
|
|
110
|
+
F,
|
|
111
|
+
P,
|
|
112
|
+
N,
|
|
113
|
+
O,
|
|
114
|
+
L,
|
|
115
|
+
j
|
|
63
116
|
]);
|
|
64
117
|
};
|
|
65
118
|
//#endregion
|
|
66
|
-
export {
|
|
119
|
+
export { s as usePinch };
|
|
@@ -1,70 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useSmoothScrollContext as i } from "../../contexts/SmoothScrollContext.js";
|
|
6
|
-
import { getGridDimension as a, getPositionFromPage as o } from "../calculatePage.js";
|
|
7
|
-
import { r as s } from "../../PaginationContext-Cwf8sCpK.js";
|
|
8
|
-
import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
1
|
+
import { useDebounce as e } from "./useDebounce.js";
|
|
2
|
+
import { useSmoothScrollContext as t } from "../../contexts/SmoothScrollContext.js";
|
|
3
|
+
import { r as n } from "../../PaginationContext-DIzsZhFd.js";
|
|
4
|
+
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
9
5
|
//#region lib/utils/hooks/usePresentPage.ts
|
|
10
|
-
var
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
let [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
startX: c,
|
|
26
|
-
startY: l,
|
|
27
|
-
endX: u,
|
|
28
|
-
endY: d
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
}, [
|
|
32
|
-
y,
|
|
33
|
-
b,
|
|
34
|
-
p,
|
|
35
|
-
m,
|
|
36
|
-
g
|
|
37
|
-
]);
|
|
38
|
-
l(() => {
|
|
39
|
-
E.length > 0 && !T.current && S.current(E[0].pageNumber), E[0]?.ratio && E.some((e) => e.pageNumber === T.current) && setTimeout(() => {
|
|
40
|
-
T.current = void 0;
|
|
41
|
-
}, 500);
|
|
42
|
-
}, [E]);
|
|
43
|
-
let O = c((e) => {
|
|
44
|
-
_.current && cancelAnimationFrame(_.current), _.current = requestAnimationFrame(() => {
|
|
6
|
+
var s = (s, c) => {
|
|
7
|
+
let l = a(), u = a(), { setFocusedPage: d } = n(), f = a(d);
|
|
8
|
+
f.current = d;
|
|
9
|
+
let [p, m] = o([]), { targetScrollPage: h } = t(), g = e(p, 0, 500);
|
|
10
|
+
i(() => {
|
|
11
|
+
g.length > 0 && !h.current && f.current(g[0].pageNumber);
|
|
12
|
+
let e = g[0]?.ratio, t = h.current;
|
|
13
|
+
e && g.some((e) => e.pageNumber === t) && (clearTimeout(u.current), u.current = setTimeout(() => {
|
|
14
|
+
h.current === t && (h.current = void 0);
|
|
15
|
+
}, 500));
|
|
16
|
+
}, [g, h]), i(() => () => {
|
|
17
|
+
clearTimeout(u.current), l.current && cancelAnimationFrame(l.current);
|
|
18
|
+
}, []);
|
|
19
|
+
let _ = r((e) => {
|
|
20
|
+
c && (l.current && cancelAnimationFrame(l.current), l.current = requestAnimationFrame(() => {
|
|
45
21
|
let t = e.target, n = {
|
|
46
|
-
startTop: t.scrollTop,
|
|
47
|
-
startLeft: t.scrollLeft,
|
|
48
|
-
endTop: t.scrollTop + t.clientHeight,
|
|
49
|
-
endLeft: t.scrollLeft + t.clientWidth
|
|
22
|
+
startTop: t.scrollTop - c.offsetTop,
|
|
23
|
+
startLeft: t.scrollLeft - c.offsetLeft,
|
|
24
|
+
endTop: t.scrollTop - c.offsetTop + t.clientHeight,
|
|
25
|
+
endLeft: t.scrollLeft - c.offsetLeft + t.clientWidth
|
|
50
26
|
};
|
|
51
|
-
|
|
52
|
-
let t = e.
|
|
27
|
+
m(c.pages.filter((e) => {
|
|
28
|
+
let t = e.left + e.width >= n.startLeft && e.top + e.height >= n.startTop, r = e.left <= n.endLeft && e.top <= n.endTop;
|
|
53
29
|
return t && r;
|
|
54
30
|
}).map((e) => {
|
|
55
|
-
let t =
|
|
31
|
+
let t = Math.max(n.startLeft, e.left), r = Math.max(n.startTop, e.top), i = Math.min(n.endLeft, e.left + e.width), a = Math.min(n.endTop, e.top + e.height), o = +(Math.max(0, i - t) * Math.max(0, a - r) / (e.width * e.height || 1) * 100).toFixed(2);
|
|
56
32
|
return {
|
|
57
33
|
pageNumber: e.pageNumber,
|
|
58
34
|
ratio: o
|
|
59
35
|
};
|
|
60
36
|
}).sort((e, t) => t.ratio - e.ratio));
|
|
61
|
-
});
|
|
62
|
-
}, [
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
37
|
+
}));
|
|
38
|
+
}, [c]);
|
|
39
|
+
i(() => {
|
|
40
|
+
if (s) return s?.addEventListener("scroll", _), _({ target: s }), () => {
|
|
41
|
+
s?.removeEventListener("scroll", _);
|
|
66
42
|
};
|
|
67
|
-
}, [
|
|
43
|
+
}, [s, _]);
|
|
68
44
|
};
|
|
69
45
|
//#endregion
|
|
70
|
-
export {
|
|
46
|
+
export { s as usePresentPage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e } from "../../PaginationContext-
|
|
1
|
+
import { a as e } from "../../PaginationContext-DIzsZhFd.js";
|
|
2
2
|
export { e as useScrollToPage };
|