iglooform 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/media/preview.d.ts +13 -0
- package/es/media/preview.js +99 -34
- package/lib/media/preview.d.ts +13 -0
- package/lib/media/preview.js +98 -33
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FC, CSSProperties } from 'react';
|
|
2
|
+
interface MediaProps {
|
|
3
|
+
src: string;
|
|
4
|
+
type: string;
|
|
5
|
+
scale?: number;
|
|
6
|
+
isCurrent?: boolean;
|
|
7
|
+
className?: any;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
showAllPages?: boolean;
|
|
10
|
+
autoWidth?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const Media: FC<MediaProps>;
|
|
13
|
+
export default Media;
|
package/es/media/preview.js
CHANGED
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { useState, useRef, useContext, useReducer } from 'react';
|
|
13
|
+
import React, { useState, useRef, useContext, useReducer, useEffect } from 'react';
|
|
14
14
|
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
|
|
15
15
|
import classnames from 'classnames';
|
|
16
16
|
import { ArrowLeftOutlined, ArrowRightOutlined } from 'iglooicon';
|
|
@@ -29,6 +29,31 @@ var PasswordResponses = {
|
|
|
29
29
|
NEED_PASSWORD: 1,
|
|
30
30
|
INCORRECT_PASSWORD: 2
|
|
31
31
|
};
|
|
32
|
+
var useContainerWidth = function useContainerWidth() {
|
|
33
|
+
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
34
|
+
var containerRef = useRef(null);
|
|
35
|
+
var _useState = useState(undefined),
|
|
36
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
+
containerWidth = _useState2[0],
|
|
38
|
+
setContainerWidth = _useState2[1];
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
if (!enabled) return;
|
|
41
|
+
var updateWidth = function updateWidth() {
|
|
42
|
+
if (containerRef.current) {
|
|
43
|
+
setContainerWidth(containerRef.current.offsetWidth);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
updateWidth();
|
|
47
|
+
var resizeObserver = new ResizeObserver(updateWidth);
|
|
48
|
+
if (containerRef.current) {
|
|
49
|
+
resizeObserver.observe(containerRef.current);
|
|
50
|
+
}
|
|
51
|
+
return function () {
|
|
52
|
+
resizeObserver.disconnect();
|
|
53
|
+
};
|
|
54
|
+
}, [enabled]);
|
|
55
|
+
return [containerRef, containerWidth];
|
|
56
|
+
};
|
|
32
57
|
var PdfViewer = function PdfViewer(_ref) {
|
|
33
58
|
var src = _ref.src,
|
|
34
59
|
left = _ref.left,
|
|
@@ -36,22 +61,28 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
36
61
|
scale = _ref.scale,
|
|
37
62
|
isCurrent = _ref.isCurrent,
|
|
38
63
|
_ref$showAllPages = _ref.showAllPages,
|
|
39
|
-
showAllPages = _ref$showAllPages === void 0 ? true : _ref$showAllPages
|
|
64
|
+
showAllPages = _ref$showAllPages === void 0 ? true : _ref$showAllPages,
|
|
65
|
+
_ref$autoWidth = _ref.autoWidth,
|
|
66
|
+
autoWidth = _ref$autoWidth === void 0 ? false : _ref$autoWidth;
|
|
40
67
|
var _useContext = useContext(LocaleContext),
|
|
41
68
|
formatMessage = _useContext.formatMessage;
|
|
42
|
-
var _useState = useState(1),
|
|
43
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
-
pageSize = _useState2[0],
|
|
45
|
-
setPageSize = _useState2[1];
|
|
46
69
|
var _useState3 = useState(1),
|
|
47
70
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
var _useState5 = useState(false),
|
|
71
|
+
pageSize = _useState4[0],
|
|
72
|
+
setPageSize = _useState4[1];
|
|
73
|
+
var _useState5 = useState(1),
|
|
52
74
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
page = _useState6[0],
|
|
76
|
+
setPage = _useState6[1];
|
|
77
|
+
var documentRef = useRef(null);
|
|
78
|
+
var _useState7 = useState(false),
|
|
79
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
80
|
+
needPassword = _useState8[0],
|
|
81
|
+
setNeedPassword = _useState8[1];
|
|
82
|
+
var _useState9 = useState(undefined),
|
|
83
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
84
|
+
pdfOriginalWidth = _useState10[0],
|
|
85
|
+
setPdfOriginalWidth = _useState10[1];
|
|
55
86
|
var _useBreakpoint = useBreakpoint(),
|
|
56
87
|
md = _useBreakpoint.md;
|
|
57
88
|
var _useReducer = useReducer(function (a) {
|
|
@@ -64,6 +95,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
64
95
|
_Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
|
|
65
96
|
modal = _Modal$useModal2[0],
|
|
66
97
|
modalHolder = _Modal$useModal2[1];
|
|
98
|
+
var _useContainerWidth = useContainerWidth(autoWidth),
|
|
99
|
+
_useContainerWidth2 = _slicedToArray(_useContainerWidth, 2),
|
|
100
|
+
containerRef = _useContainerWidth2[0],
|
|
101
|
+
containerWidth = _useContainerWidth2[1];
|
|
67
102
|
var handlePageInit = function handlePageInit(document) {
|
|
68
103
|
var _ref2 = document || {},
|
|
69
104
|
numPages = _ref2.numPages;
|
|
@@ -71,6 +106,22 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
71
106
|
setPageSize(numPages);
|
|
72
107
|
}
|
|
73
108
|
};
|
|
109
|
+
var handlePageLoadSuccess = function handlePageLoadSuccess(pageData) {
|
|
110
|
+
if (autoWidth && !pdfOriginalWidth) {
|
|
111
|
+
var originalWidth = pageData.originalWidth;
|
|
112
|
+
if (originalWidth) {
|
|
113
|
+
setPdfOriginalWidth(originalWidth);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var getOptimalPdfWidth = function getOptimalPdfWidth() {
|
|
118
|
+
var scale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
119
|
+
if (!autoWidth || !containerWidth) return undefined;
|
|
120
|
+
if (pdfOriginalWidth) {
|
|
121
|
+
return Math.min(containerWidth, pdfOriginalWidth);
|
|
122
|
+
}
|
|
123
|
+
return containerWidth * scale;
|
|
124
|
+
};
|
|
74
125
|
var handleCancelLoad = function handleCancelLoad() {
|
|
75
126
|
var current = documentRef === null || documentRef === void 0 ? void 0 : documentRef.current;
|
|
76
127
|
if (current) {
|
|
@@ -133,10 +184,13 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
133
184
|
}
|
|
134
185
|
if (showAllPages) {
|
|
135
186
|
return /*#__PURE__*/_jsx("div", {
|
|
187
|
+
ref: autoWidth ? containerRef : undefined,
|
|
136
188
|
style: {
|
|
137
189
|
display: 'flex',
|
|
138
190
|
flexDirection: 'column',
|
|
191
|
+
alignItems: 'center',
|
|
139
192
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
193
|
+
width: autoWidth ? '100%' : undefined,
|
|
140
194
|
maxHeight: '100%',
|
|
141
195
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
142
196
|
position: 'absolute',
|
|
@@ -152,7 +206,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
152
206
|
}).map(function (_, index) {
|
|
153
207
|
return /*#__PURE__*/_jsx(Page, {
|
|
154
208
|
pageNumber: index + 1,
|
|
155
|
-
|
|
209
|
+
width: autoWidth ? getOptimalPdfWidth(1) : undefined,
|
|
210
|
+
scale: !autoWidth ? scale : undefined,
|
|
211
|
+
onLoadSuccess: index === 0 ? handlePageLoadSuccess : undefined
|
|
156
212
|
}, index);
|
|
157
213
|
})
|
|
158
214
|
})
|
|
@@ -160,8 +216,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
160
216
|
}
|
|
161
217
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
162
218
|
children: [modalHolder, /*#__PURE__*/_jsx("div", {
|
|
219
|
+
ref: autoWidth ? containerRef : undefined,
|
|
163
220
|
style: {
|
|
164
221
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
222
|
+
width: autoWidth ? '100%' : undefined,
|
|
165
223
|
maxHeight: '100%',
|
|
166
224
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
167
225
|
position: 'absolute',
|
|
@@ -174,7 +232,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
174
232
|
onPassword: onPassword,
|
|
175
233
|
children: /*#__PURE__*/_jsx(Page, {
|
|
176
234
|
pageNumber: page,
|
|
177
|
-
scale:
|
|
235
|
+
width: autoWidth ? getOptimalPdfWidth(scale) : undefined,
|
|
236
|
+
scale: !autoWidth ? scale : undefined,
|
|
237
|
+
onLoadSuccess: handlePageLoadSuccess
|
|
178
238
|
})
|
|
179
239
|
})
|
|
180
240
|
}, index), isCurrent && Boolean(pageSize > 1) && /*#__PURE__*/_jsxs("div", {
|
|
@@ -213,7 +273,8 @@ var MediaItem = function MediaItem(_ref3) {
|
|
|
213
273
|
scale = _ref3.scale,
|
|
214
274
|
offset = _ref3.offset,
|
|
215
275
|
isCurrent = _ref3.isCurrent,
|
|
216
|
-
showAllPages = _ref3.showAllPages
|
|
276
|
+
showAllPages = _ref3.showAllPages,
|
|
277
|
+
autoWidth = _ref3.autoWidth;
|
|
217
278
|
var top = offset.top,
|
|
218
279
|
left = offset.left;
|
|
219
280
|
var _useContext2 = useContext(LocaleContext),
|
|
@@ -235,7 +296,8 @@ var MediaItem = function MediaItem(_ref3) {
|
|
|
235
296
|
left: left,
|
|
236
297
|
scale: scale,
|
|
237
298
|
isCurrent: isCurrent,
|
|
238
|
-
showAllPages: showAllPages
|
|
299
|
+
showAllPages: showAllPages,
|
|
300
|
+
autoWidth: autoWidth
|
|
239
301
|
});
|
|
240
302
|
case 'image':
|
|
241
303
|
return /*#__PURE__*/_jsx("img", {
|
|
@@ -272,32 +334,34 @@ var Media = function Media(_ref4) {
|
|
|
272
334
|
_ref4$isCurrent = _ref4.isCurrent,
|
|
273
335
|
isCurrent = _ref4$isCurrent === void 0 ? false : _ref4$isCurrent,
|
|
274
336
|
_ref4$showAllPages = _ref4.showAllPages,
|
|
275
|
-
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
337
|
+
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages,
|
|
338
|
+
_ref4$autoWidth = _ref4.autoWidth,
|
|
339
|
+
autoWidth = _ref4$autoWidth === void 0 ? false : _ref4$autoWidth;
|
|
340
|
+
var _useState11 = useState(false),
|
|
341
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
342
|
+
isDrag = _useState12[0],
|
|
343
|
+
setIsDrag = _useState12[1];
|
|
344
|
+
var _useState13 = useState({
|
|
281
345
|
startX: 0,
|
|
282
346
|
startY: 0
|
|
283
347
|
}),
|
|
284
|
-
|
|
285
|
-
startPos =
|
|
286
|
-
setStartPos =
|
|
287
|
-
var
|
|
348
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
349
|
+
startPos = _useState14[0],
|
|
350
|
+
setStartPos = _useState14[1];
|
|
351
|
+
var _useState15 = useState({
|
|
288
352
|
top: 0,
|
|
289
353
|
left: 0
|
|
290
354
|
}),
|
|
291
|
-
|
|
292
|
-
offset =
|
|
293
|
-
setOffset =
|
|
294
|
-
var
|
|
355
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
356
|
+
offset = _useState16[0],
|
|
357
|
+
setOffset = _useState16[1];
|
|
358
|
+
var _useState17 = useState({
|
|
295
359
|
top: 0,
|
|
296
360
|
left: 0
|
|
297
361
|
}),
|
|
298
|
-
|
|
299
|
-
lastOffset =
|
|
300
|
-
setLastOffset =
|
|
362
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
363
|
+
lastOffset = _useState18[0],
|
|
364
|
+
setLastOffset = _useState18[1];
|
|
301
365
|
var handleMouseUp = function handleMouseUp(e) {
|
|
302
366
|
e.preventDefault();
|
|
303
367
|
var button = e.button;
|
|
@@ -358,7 +422,8 @@ var Media = function Media(_ref4) {
|
|
|
358
422
|
scale: scale,
|
|
359
423
|
offset: offset,
|
|
360
424
|
isCurrent: isCurrent,
|
|
361
|
-
showAllPages: showAllPages
|
|
425
|
+
showAllPages: showAllPages,
|
|
426
|
+
autoWidth: autoWidth
|
|
362
427
|
})
|
|
363
428
|
});
|
|
364
429
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FC, CSSProperties } from 'react';
|
|
2
|
+
interface MediaProps {
|
|
3
|
+
src: string;
|
|
4
|
+
type: string;
|
|
5
|
+
scale?: number;
|
|
6
|
+
isCurrent?: boolean;
|
|
7
|
+
className?: any;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
showAllPages?: boolean;
|
|
10
|
+
autoWidth?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const Media: FC<MediaProps>;
|
|
13
|
+
export default Media;
|
package/lib/media/preview.js
CHANGED
|
@@ -35,6 +35,31 @@ var PasswordResponses = {
|
|
|
35
35
|
NEED_PASSWORD: 1,
|
|
36
36
|
INCORRECT_PASSWORD: 2
|
|
37
37
|
};
|
|
38
|
+
var useContainerWidth = function useContainerWidth() {
|
|
39
|
+
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
40
|
+
var containerRef = (0, _react.useRef)(null);
|
|
41
|
+
var _useState = (0, _react.useState)(undefined),
|
|
42
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
+
containerWidth = _useState2[0],
|
|
44
|
+
setContainerWidth = _useState2[1];
|
|
45
|
+
(0, _react.useEffect)(function () {
|
|
46
|
+
if (!enabled) return;
|
|
47
|
+
var updateWidth = function updateWidth() {
|
|
48
|
+
if (containerRef.current) {
|
|
49
|
+
setContainerWidth(containerRef.current.offsetWidth);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
updateWidth();
|
|
53
|
+
var resizeObserver = new ResizeObserver(updateWidth);
|
|
54
|
+
if (containerRef.current) {
|
|
55
|
+
resizeObserver.observe(containerRef.current);
|
|
56
|
+
}
|
|
57
|
+
return function () {
|
|
58
|
+
resizeObserver.disconnect();
|
|
59
|
+
};
|
|
60
|
+
}, [enabled]);
|
|
61
|
+
return [containerRef, containerWidth];
|
|
62
|
+
};
|
|
38
63
|
var PdfViewer = function PdfViewer(_ref) {
|
|
39
64
|
var src = _ref.src,
|
|
40
65
|
left = _ref.left,
|
|
@@ -42,22 +67,28 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
42
67
|
scale = _ref.scale,
|
|
43
68
|
isCurrent = _ref.isCurrent,
|
|
44
69
|
_ref$showAllPages = _ref.showAllPages,
|
|
45
|
-
showAllPages = _ref$showAllPages === void 0 ? true : _ref$showAllPages
|
|
70
|
+
showAllPages = _ref$showAllPages === void 0 ? true : _ref$showAllPages,
|
|
71
|
+
_ref$autoWidth = _ref.autoWidth,
|
|
72
|
+
autoWidth = _ref$autoWidth === void 0 ? false : _ref$autoWidth;
|
|
46
73
|
var _useContext = (0, _react.useContext)(_locale.LocaleContext),
|
|
47
74
|
formatMessage = _useContext.formatMessage;
|
|
48
|
-
var _useState = (0, _react.useState)(1),
|
|
49
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
50
|
-
pageSize = _useState2[0],
|
|
51
|
-
setPageSize = _useState2[1];
|
|
52
75
|
var _useState3 = (0, _react.useState)(1),
|
|
53
76
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
var _useState5 = (0, _react.useState)(false),
|
|
77
|
+
pageSize = _useState4[0],
|
|
78
|
+
setPageSize = _useState4[1];
|
|
79
|
+
var _useState5 = (0, _react.useState)(1),
|
|
58
80
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
page = _useState6[0],
|
|
82
|
+
setPage = _useState6[1];
|
|
83
|
+
var documentRef = (0, _react.useRef)(null);
|
|
84
|
+
var _useState7 = (0, _react.useState)(false),
|
|
85
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
86
|
+
needPassword = _useState8[0],
|
|
87
|
+
setNeedPassword = _useState8[1];
|
|
88
|
+
var _useState9 = (0, _react.useState)(undefined),
|
|
89
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
90
|
+
pdfOriginalWidth = _useState10[0],
|
|
91
|
+
setPdfOriginalWidth = _useState10[1];
|
|
61
92
|
var _useBreakpoint = useBreakpoint(),
|
|
62
93
|
md = _useBreakpoint.md;
|
|
63
94
|
var _useReducer = (0, _react.useReducer)(function (a) {
|
|
@@ -70,6 +101,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
70
101
|
_Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
|
|
71
102
|
modal = _Modal$useModal2[0],
|
|
72
103
|
modalHolder = _Modal$useModal2[1];
|
|
104
|
+
var _useContainerWidth = useContainerWidth(autoWidth),
|
|
105
|
+
_useContainerWidth2 = _slicedToArray(_useContainerWidth, 2),
|
|
106
|
+
containerRef = _useContainerWidth2[0],
|
|
107
|
+
containerWidth = _useContainerWidth2[1];
|
|
73
108
|
var handlePageInit = function handlePageInit(document) {
|
|
74
109
|
var _ref2 = document || {},
|
|
75
110
|
numPages = _ref2.numPages;
|
|
@@ -77,6 +112,22 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
77
112
|
setPageSize(numPages);
|
|
78
113
|
}
|
|
79
114
|
};
|
|
115
|
+
var handlePageLoadSuccess = function handlePageLoadSuccess(pageData) {
|
|
116
|
+
if (autoWidth && !pdfOriginalWidth) {
|
|
117
|
+
var originalWidth = pageData.originalWidth;
|
|
118
|
+
if (originalWidth) {
|
|
119
|
+
setPdfOriginalWidth(originalWidth);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var getOptimalPdfWidth = function getOptimalPdfWidth() {
|
|
124
|
+
var scale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
125
|
+
if (!autoWidth || !containerWidth) return undefined;
|
|
126
|
+
if (pdfOriginalWidth) {
|
|
127
|
+
return Math.min(containerWidth, pdfOriginalWidth);
|
|
128
|
+
}
|
|
129
|
+
return containerWidth * scale;
|
|
130
|
+
};
|
|
80
131
|
var handleCancelLoad = function handleCancelLoad() {
|
|
81
132
|
var current = documentRef === null || documentRef === void 0 ? void 0 : documentRef.current;
|
|
82
133
|
if (current) {
|
|
@@ -139,10 +190,13 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
139
190
|
}
|
|
140
191
|
if (showAllPages) {
|
|
141
192
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
193
|
+
ref: autoWidth ? containerRef : undefined,
|
|
142
194
|
style: {
|
|
143
195
|
display: 'flex',
|
|
144
196
|
flexDirection: 'column',
|
|
197
|
+
alignItems: 'center',
|
|
145
198
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
199
|
+
width: autoWidth ? '100%' : undefined,
|
|
146
200
|
maxHeight: '100%',
|
|
147
201
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
148
202
|
position: 'absolute',
|
|
@@ -158,7 +212,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
158
212
|
}).map(function (_, index) {
|
|
159
213
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_entry.Page, {
|
|
160
214
|
pageNumber: index + 1,
|
|
161
|
-
|
|
215
|
+
width: autoWidth ? getOptimalPdfWidth(1) : undefined,
|
|
216
|
+
scale: !autoWidth ? scale : undefined,
|
|
217
|
+
onLoadSuccess: index === 0 ? handlePageLoadSuccess : undefined
|
|
162
218
|
}, index);
|
|
163
219
|
})
|
|
164
220
|
})
|
|
@@ -166,8 +222,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
166
222
|
}
|
|
167
223
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
168
224
|
children: [modalHolder, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
225
|
+
ref: autoWidth ? containerRef : undefined,
|
|
169
226
|
style: {
|
|
170
227
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
228
|
+
width: autoWidth ? '100%' : undefined,
|
|
171
229
|
maxHeight: '100%',
|
|
172
230
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
173
231
|
position: 'absolute',
|
|
@@ -180,7 +238,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
180
238
|
onPassword: onPassword,
|
|
181
239
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_entry.Page, {
|
|
182
240
|
pageNumber: page,
|
|
183
|
-
scale:
|
|
241
|
+
width: autoWidth ? getOptimalPdfWidth(scale) : undefined,
|
|
242
|
+
scale: !autoWidth ? scale : undefined,
|
|
243
|
+
onLoadSuccess: handlePageLoadSuccess
|
|
184
244
|
})
|
|
185
245
|
})
|
|
186
246
|
}, index), isCurrent && Boolean(pageSize > 1) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -219,7 +279,8 @@ var MediaItem = function MediaItem(_ref3) {
|
|
|
219
279
|
scale = _ref3.scale,
|
|
220
280
|
offset = _ref3.offset,
|
|
221
281
|
isCurrent = _ref3.isCurrent,
|
|
222
|
-
showAllPages = _ref3.showAllPages
|
|
282
|
+
showAllPages = _ref3.showAllPages,
|
|
283
|
+
autoWidth = _ref3.autoWidth;
|
|
223
284
|
var top = offset.top,
|
|
224
285
|
left = offset.left;
|
|
225
286
|
var _useContext2 = (0, _react.useContext)(_locale.LocaleContext),
|
|
@@ -241,7 +302,8 @@ var MediaItem = function MediaItem(_ref3) {
|
|
|
241
302
|
left: left,
|
|
242
303
|
scale: scale,
|
|
243
304
|
isCurrent: isCurrent,
|
|
244
|
-
showAllPages: showAllPages
|
|
305
|
+
showAllPages: showAllPages,
|
|
306
|
+
autoWidth: autoWidth
|
|
245
307
|
});
|
|
246
308
|
case 'image':
|
|
247
309
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
@@ -278,32 +340,34 @@ var Media = function Media(_ref4) {
|
|
|
278
340
|
_ref4$isCurrent = _ref4.isCurrent,
|
|
279
341
|
isCurrent = _ref4$isCurrent === void 0 ? false : _ref4$isCurrent,
|
|
280
342
|
_ref4$showAllPages = _ref4.showAllPages,
|
|
281
|
-
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
343
|
+
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages,
|
|
344
|
+
_ref4$autoWidth = _ref4.autoWidth,
|
|
345
|
+
autoWidth = _ref4$autoWidth === void 0 ? false : _ref4$autoWidth;
|
|
346
|
+
var _useState11 = (0, _react.useState)(false),
|
|
347
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
348
|
+
isDrag = _useState12[0],
|
|
349
|
+
setIsDrag = _useState12[1];
|
|
350
|
+
var _useState13 = (0, _react.useState)({
|
|
287
351
|
startX: 0,
|
|
288
352
|
startY: 0
|
|
289
353
|
}),
|
|
290
|
-
|
|
291
|
-
startPos =
|
|
292
|
-
setStartPos =
|
|
293
|
-
var
|
|
354
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
355
|
+
startPos = _useState14[0],
|
|
356
|
+
setStartPos = _useState14[1];
|
|
357
|
+
var _useState15 = (0, _react.useState)({
|
|
294
358
|
top: 0,
|
|
295
359
|
left: 0
|
|
296
360
|
}),
|
|
297
|
-
|
|
298
|
-
offset =
|
|
299
|
-
setOffset =
|
|
300
|
-
var
|
|
361
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
362
|
+
offset = _useState16[0],
|
|
363
|
+
setOffset = _useState16[1];
|
|
364
|
+
var _useState17 = (0, _react.useState)({
|
|
301
365
|
top: 0,
|
|
302
366
|
left: 0
|
|
303
367
|
}),
|
|
304
|
-
|
|
305
|
-
lastOffset =
|
|
306
|
-
setLastOffset =
|
|
368
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
369
|
+
lastOffset = _useState18[0],
|
|
370
|
+
setLastOffset = _useState18[1];
|
|
307
371
|
var handleMouseUp = function handleMouseUp(e) {
|
|
308
372
|
e.preventDefault();
|
|
309
373
|
var button = e.button;
|
|
@@ -364,7 +428,8 @@ var Media = function Media(_ref4) {
|
|
|
364
428
|
scale: scale,
|
|
365
429
|
offset: offset,
|
|
366
430
|
isCurrent: isCurrent,
|
|
367
|
-
showAllPages: showAllPages
|
|
431
|
+
showAllPages: showAllPages,
|
|
432
|
+
autoWidth: autoWidth
|
|
368
433
|
})
|
|
369
434
|
});
|
|
370
435
|
};
|