@pdfme/ui 6.1.13-dev.4 → 6.1.13-dev.7
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/constants.d.ts +1 -0
- package/dist/helper.d.ts +6 -0
- package/dist/index.js +55 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export declare const LEFT_SIDEBAR_WIDTH = 45;
|
|
|
7
7
|
export declare const RIGHT_SIDEBAR_WIDTH = 400;
|
|
8
8
|
export declare const BACKGROUND_COLOR = "rgb(74, 74, 74)";
|
|
9
9
|
export declare const DEFAULT_MAX_ZOOM = 2;
|
|
10
|
+
export declare const PAGE_SWITCH_REMAINING_RATIO = 0.25;
|
|
10
11
|
export declare const DESIGNER_CLASSNAME = "pdfme-designer-";
|
|
11
12
|
export declare const UI_CLASSNAME = "pdfme-ui-";
|
package/dist/helper.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export declare const moveCommandToChangeSchemasArg: (props: {
|
|
|
55
55
|
schemaId: string;
|
|
56
56
|
}[];
|
|
57
57
|
export declare const getPagesScrollTopByIndex: (pageSizes: Size[], index: number, scale: number) => number;
|
|
58
|
+
export declare const getVisibleOverlap: (containerRect: DOMRect, elementRect: DOMRect) => {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
area: number;
|
|
62
|
+
};
|
|
63
|
+
export declare const getStickyScrollPageIndex: (container: HTMLElement, papers: Array<HTMLElement | null | undefined>, pageCursor: number) => number;
|
|
58
64
|
export type ZoomMode = 'manual' | 'fit-width' | 'fit-height';
|
|
59
65
|
export type ZoomAnchor = {
|
|
60
66
|
pageIndex: number;
|
package/dist/index.js
CHANGED
|
@@ -56104,6 +56104,7 @@ var import_client = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
56104
56104
|
var DESTROYED_ERR_MSG = "[@pdfme/ui] this instance is already destroyed";
|
|
56105
56105
|
var SELECTABLE_CLASSNAME = "selectable";
|
|
56106
56106
|
var BACKGROUND_COLOR = "rgb(74, 74, 74)";
|
|
56107
|
+
var PAGE_SWITCH_REMAINING_RATIO = .25;
|
|
56107
56108
|
var DESIGNER_CLASSNAME = "pdfme-designer-";
|
|
56108
56109
|
var UI_CLASSNAME = "pdfme-ui-";
|
|
56109
56110
|
//#endregion
|
|
@@ -77335,6 +77336,44 @@ var moveCommandToChangeSchemasArg = (props) => {
|
|
|
77335
77336
|
var getPagesScrollTopByIndex = (pageSizes, index, scale) => {
|
|
77336
77337
|
return pageSizes.slice(0, index).reduce((acc, cur) => acc + (cur.height * ZOOM + 30 * scale) * scale, 0);
|
|
77337
77338
|
};
|
|
77339
|
+
var getVisibleOverlap = (containerRect, elementRect) => {
|
|
77340
|
+
const width = Math.max(0, Math.min(containerRect.right, elementRect.right) - Math.max(containerRect.left, elementRect.left));
|
|
77341
|
+
const height = Math.max(0, Math.min(containerRect.bottom, elementRect.bottom) - Math.max(containerRect.top, elementRect.top));
|
|
77342
|
+
return {
|
|
77343
|
+
width,
|
|
77344
|
+
height,
|
|
77345
|
+
area: width * height
|
|
77346
|
+
};
|
|
77347
|
+
};
|
|
77348
|
+
var VERTICAL_SCROLL_EDGE_EPSILON = 1;
|
|
77349
|
+
var isAtVerticalScrollEdge = (container) => {
|
|
77350
|
+
const maxScrollTop = container.scrollHeight - container.clientHeight;
|
|
77351
|
+
if (maxScrollTop <= 0) return false;
|
|
77352
|
+
const { scrollTop } = container;
|
|
77353
|
+
return scrollTop <= VERTICAL_SCROLL_EDGE_EPSILON || scrollTop >= maxScrollTop - VERTICAL_SCROLL_EDGE_EPSILON;
|
|
77354
|
+
};
|
|
77355
|
+
var getStickyScrollPageIndex = (container, papers, pageCursor) => {
|
|
77356
|
+
const containerRect = container.getBoundingClientRect();
|
|
77357
|
+
const stickyHeight = containerRect.height * PAGE_SWITCH_REMAINING_RATIO;
|
|
77358
|
+
let bestPageIndex = pageCursor;
|
|
77359
|
+
let bestVisibleArea = 0;
|
|
77360
|
+
let currentVisibleHeight = 0;
|
|
77361
|
+
let currentVisibleArea = 0;
|
|
77362
|
+
papers.forEach((paper, pageIndex) => {
|
|
77363
|
+
if (!paper) return;
|
|
77364
|
+
const { height, area } = getVisibleOverlap(containerRect, paper.getBoundingClientRect());
|
|
77365
|
+
if (pageIndex === pageCursor) {
|
|
77366
|
+
currentVisibleHeight = height;
|
|
77367
|
+
currentVisibleArea = area;
|
|
77368
|
+
}
|
|
77369
|
+
if (area > bestVisibleArea) {
|
|
77370
|
+
bestVisibleArea = area;
|
|
77371
|
+
bestPageIndex = pageIndex;
|
|
77372
|
+
}
|
|
77373
|
+
});
|
|
77374
|
+
if (bestVisibleArea <= 0) return pageCursor;
|
|
77375
|
+
return !isAtVerticalScrollEdge(container) && currentVisibleArea > 0 && currentVisibleHeight >= stickyHeight ? pageCursor : bestPageIndex;
|
|
77376
|
+
};
|
|
77338
77377
|
var MIN_ZOOM = .25;
|
|
77339
77378
|
var FIT_GUTTER = 40;
|
|
77340
77379
|
var clampZoomLevel = (zoomLevel, maxZoom, minZoom = MIN_ZOOM) => Math.min(Math.max(zoomLevel, minZoom), maxZoom);
|
|
@@ -88044,7 +88083,7 @@ function getPxValue$5(val) {
|
|
|
88044
88083
|
/**
|
|
88045
88084
|
* Get visible area of element
|
|
88046
88085
|
*/
|
|
88047
|
-
function getVisibleArea$
|
|
88086
|
+
function getVisibleArea$5(initArea, scrollerList) {
|
|
88048
88087
|
const visibleArea = { ...initArea };
|
|
88049
88088
|
(scrollerList || []).forEach((ele) => {
|
|
88050
88089
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) return;
|
|
@@ -88222,8 +88261,8 @@ function useAlign$5(open, popupEle, target, placement, builtinPlacements, popupA
|
|
|
88222
88261
|
const VISIBLE_FIRST = "visibleFirst";
|
|
88223
88262
|
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) htmlRegion = VISIBLE;
|
|
88224
88263
|
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
88225
|
-
const scrollRegionArea = getVisibleArea$
|
|
88226
|
-
const visibleRegionArea = getVisibleArea$
|
|
88264
|
+
const scrollRegionArea = getVisibleArea$5(scrollRegion, scrollerList);
|
|
88265
|
+
const visibleRegionArea = getVisibleArea$5(visibleRegion, scrollerList);
|
|
88227
88266
|
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
88228
88267
|
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
88229
88268
|
popupElement.style.left = "auto";
|
|
@@ -95520,7 +95559,7 @@ function getPxValue$4(val) {
|
|
|
95520
95559
|
/**
|
|
95521
95560
|
* Get visible area of element
|
|
95522
95561
|
*/
|
|
95523
|
-
function getVisibleArea$
|
|
95562
|
+
function getVisibleArea$4(initArea, scrollerList) {
|
|
95524
95563
|
const visibleArea = { ...initArea };
|
|
95525
95564
|
(scrollerList || []).forEach((ele) => {
|
|
95526
95565
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) return;
|
|
@@ -95698,8 +95737,8 @@ function useAlign$4(open, popupEle, target, placement, builtinPlacements, popupA
|
|
|
95698
95737
|
const VISIBLE_FIRST = "visibleFirst";
|
|
95699
95738
|
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) htmlRegion = VISIBLE;
|
|
95700
95739
|
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
95701
|
-
const scrollRegionArea = getVisibleArea$
|
|
95702
|
-
const visibleRegionArea = getVisibleArea$
|
|
95740
|
+
const scrollRegionArea = getVisibleArea$4(scrollRegion, scrollerList);
|
|
95741
|
+
const visibleRegionArea = getVisibleArea$4(visibleRegion, scrollerList);
|
|
95703
95742
|
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
95704
95743
|
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
95705
95744
|
popupElement.style.left = "auto";
|
|
@@ -101646,7 +101685,7 @@ function getPxValue$3(val) {
|
|
|
101646
101685
|
/**
|
|
101647
101686
|
* Get visible area of element
|
|
101648
101687
|
*/
|
|
101649
|
-
function getVisibleArea$
|
|
101688
|
+
function getVisibleArea$3(initArea, scrollerList) {
|
|
101650
101689
|
const visibleArea = { ...initArea };
|
|
101651
101690
|
(scrollerList || []).forEach((ele) => {
|
|
101652
101691
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) return;
|
|
@@ -101824,8 +101863,8 @@ function useAlign$3(open, popupEle, target, placement, builtinPlacements, popupA
|
|
|
101824
101863
|
const VISIBLE_FIRST = "visibleFirst";
|
|
101825
101864
|
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) htmlRegion = VISIBLE;
|
|
101826
101865
|
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
101827
|
-
const scrollRegionArea = getVisibleArea$
|
|
101828
|
-
const visibleRegionArea = getVisibleArea$
|
|
101866
|
+
const scrollRegionArea = getVisibleArea$3(scrollRegion, scrollerList);
|
|
101867
|
+
const visibleRegionArea = getVisibleArea$3(visibleRegion, scrollerList);
|
|
101829
101868
|
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
101830
101869
|
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
101831
101870
|
popupElement.style.left = "auto";
|
|
@@ -104012,7 +104051,7 @@ function getPxValue$2(val) {
|
|
|
104012
104051
|
/**
|
|
104013
104052
|
* Get visible area of element
|
|
104014
104053
|
*/
|
|
104015
|
-
function getVisibleArea$
|
|
104054
|
+
function getVisibleArea$2(initArea, scrollerList) {
|
|
104016
104055
|
const visibleArea = { ...initArea };
|
|
104017
104056
|
(scrollerList || []).forEach((ele) => {
|
|
104018
104057
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) return;
|
|
@@ -104190,8 +104229,8 @@ function useAlign$2(open, popupEle, target, placement, builtinPlacements, popupA
|
|
|
104190
104229
|
const VISIBLE_FIRST = "visibleFirst";
|
|
104191
104230
|
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) htmlRegion = VISIBLE;
|
|
104192
104231
|
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
104193
|
-
const scrollRegionArea = getVisibleArea$
|
|
104194
|
-
const visibleRegionArea = getVisibleArea$
|
|
104232
|
+
const scrollRegionArea = getVisibleArea$2(scrollRegion, scrollerList);
|
|
104233
|
+
const visibleRegionArea = getVisibleArea$2(visibleRegion, scrollerList);
|
|
104195
104234
|
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
104196
104235
|
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
104197
104236
|
popupElement.style.left = "auto";
|
|
@@ -106068,7 +106107,7 @@ function getPxValue$1(val) {
|
|
|
106068
106107
|
/**
|
|
106069
106108
|
* Get visible area of element
|
|
106070
106109
|
*/
|
|
106071
|
-
function getVisibleArea$
|
|
106110
|
+
function getVisibleArea$1(initArea, scrollerList) {
|
|
106072
106111
|
const visibleArea = { ...initArea };
|
|
106073
106112
|
(scrollerList || []).forEach((ele) => {
|
|
106074
106113
|
if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) return;
|
|
@@ -106246,8 +106285,8 @@ function useAlign$1(open, popupEle, target, placement, builtinPlacements, popupA
|
|
|
106246
106285
|
const VISIBLE_FIRST = "visibleFirst";
|
|
106247
106286
|
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) htmlRegion = VISIBLE;
|
|
106248
106287
|
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
106249
|
-
const scrollRegionArea = getVisibleArea$
|
|
106250
|
-
const visibleRegionArea = getVisibleArea$
|
|
106288
|
+
const scrollRegionArea = getVisibleArea$1(scrollRegion, scrollerList);
|
|
106289
|
+
const visibleRegionArea = getVisibleArea$1(visibleRegion, scrollerList);
|
|
106251
106290
|
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
106252
106291
|
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
106253
106292
|
popupElement.style.left = "auto";
|
|
@@ -122383,27 +122422,10 @@ var useZoom = ({ baseScale, maxZoom, pageCursor, pageSizes, containerRef, paperR
|
|
|
122383
122422
|
fitHeight: () => fitZoom("fit-height")
|
|
122384
122423
|
};
|
|
122385
122424
|
};
|
|
122386
|
-
var getVisibleArea$1 = (containerRect, elementRect) => {
|
|
122387
|
-
return Math.max(0, Math.min(containerRect.right, elementRect.right) - Math.max(containerRect.left, elementRect.left)) * Math.max(0, Math.min(containerRect.bottom, elementRect.bottom) - Math.max(containerRect.top, elementRect.top));
|
|
122388
|
-
};
|
|
122389
|
-
var getMostVisiblePageIndex = (container, paperRefs, pageCursor) => {
|
|
122390
|
-
const containerRect = container.getBoundingClientRect();
|
|
122391
|
-
let bestPageIndex = pageCursor;
|
|
122392
|
-
let bestVisibleArea = 0;
|
|
122393
|
-
paperRefs.current.forEach((paper, pageIndex) => {
|
|
122394
|
-
if (!paper) return;
|
|
122395
|
-
const visibleArea = getVisibleArea$1(containerRect, paper.getBoundingClientRect());
|
|
122396
|
-
if (visibleArea > bestVisibleArea) {
|
|
122397
|
-
bestVisibleArea = visibleArea;
|
|
122398
|
-
bestPageIndex = pageIndex;
|
|
122399
|
-
}
|
|
122400
|
-
});
|
|
122401
|
-
return bestVisibleArea > 0 ? bestPageIndex : pageCursor;
|
|
122402
|
-
};
|
|
122403
122425
|
var useScrollPageCursor = ({ ref, paperRefs, pageSizes, scale, pageCursor, onChangePageCursor }) => {
|
|
122404
122426
|
const onScroll = (0, import_react$9.useCallback)(() => {
|
|
122405
122427
|
if (!pageSizes[0] || !ref.current) return;
|
|
122406
|
-
const _pageCursor =
|
|
122428
|
+
const _pageCursor = getStickyScrollPageIndex(ref.current, paperRefs.current, pageCursor);
|
|
122407
122429
|
if (_pageCursor !== pageCursor) onChangePageCursor(_pageCursor);
|
|
122408
122430
|
}, [
|
|
122409
122431
|
onChangePageCursor,
|