iglooform 3.6.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.js +44 -20
- package/lib/media/preview.js +44 -20
- package/package.json +1 -1
package/es/media/preview.js
CHANGED
|
@@ -79,6 +79,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
79
79
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
80
80
|
needPassword = _useState8[0],
|
|
81
81
|
setNeedPassword = _useState8[1];
|
|
82
|
+
var _useState9 = useState(undefined),
|
|
83
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
84
|
+
pdfOriginalWidth = _useState10[0],
|
|
85
|
+
setPdfOriginalWidth = _useState10[1];
|
|
82
86
|
var _useBreakpoint = useBreakpoint(),
|
|
83
87
|
md = _useBreakpoint.md;
|
|
84
88
|
var _useReducer = useReducer(function (a) {
|
|
@@ -102,6 +106,22 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
102
106
|
setPageSize(numPages);
|
|
103
107
|
}
|
|
104
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
|
+
};
|
|
105
125
|
var handleCancelLoad = function handleCancelLoad() {
|
|
106
126
|
var current = documentRef === null || documentRef === void 0 ? void 0 : documentRef.current;
|
|
107
127
|
if (current) {
|
|
@@ -168,6 +188,7 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
168
188
|
style: {
|
|
169
189
|
display: 'flex',
|
|
170
190
|
flexDirection: 'column',
|
|
191
|
+
alignItems: 'center',
|
|
171
192
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
172
193
|
width: autoWidth ? '100%' : undefined,
|
|
173
194
|
maxHeight: '100%',
|
|
@@ -185,8 +206,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
185
206
|
}).map(function (_, index) {
|
|
186
207
|
return /*#__PURE__*/_jsx(Page, {
|
|
187
208
|
pageNumber: index + 1,
|
|
188
|
-
width: autoWidth ?
|
|
189
|
-
scale: !autoWidth ? scale : undefined
|
|
209
|
+
width: autoWidth ? getOptimalPdfWidth(1) : undefined,
|
|
210
|
+
scale: !autoWidth ? scale : undefined,
|
|
211
|
+
onLoadSuccess: index === 0 ? handlePageLoadSuccess : undefined
|
|
190
212
|
}, index);
|
|
191
213
|
})
|
|
192
214
|
})
|
|
@@ -197,6 +219,7 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
197
219
|
ref: autoWidth ? containerRef : undefined,
|
|
198
220
|
style: {
|
|
199
221
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
222
|
+
width: autoWidth ? '100%' : undefined,
|
|
200
223
|
maxHeight: '100%',
|
|
201
224
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
202
225
|
position: 'absolute',
|
|
@@ -209,8 +232,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
209
232
|
onPassword: onPassword,
|
|
210
233
|
children: /*#__PURE__*/_jsx(Page, {
|
|
211
234
|
pageNumber: page,
|
|
212
|
-
width: autoWidth
|
|
213
|
-
scale: !autoWidth ? scale : undefined
|
|
235
|
+
width: autoWidth ? getOptimalPdfWidth(scale) : undefined,
|
|
236
|
+
scale: !autoWidth ? scale : undefined,
|
|
237
|
+
onLoadSuccess: handlePageLoadSuccess
|
|
214
238
|
})
|
|
215
239
|
})
|
|
216
240
|
}, index), isCurrent && Boolean(pageSize > 1) && /*#__PURE__*/_jsxs("div", {
|
|
@@ -313,31 +337,31 @@ var Media = function Media(_ref4) {
|
|
|
313
337
|
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages,
|
|
314
338
|
_ref4$autoWidth = _ref4.autoWidth,
|
|
315
339
|
autoWidth = _ref4$autoWidth === void 0 ? false : _ref4$autoWidth;
|
|
316
|
-
var
|
|
317
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
318
|
-
isDrag = _useState10[0],
|
|
319
|
-
setIsDrag = _useState10[1];
|
|
320
|
-
var _useState11 = useState({
|
|
321
|
-
startX: 0,
|
|
322
|
-
startY: 0
|
|
323
|
-
}),
|
|
340
|
+
var _useState11 = useState(false),
|
|
324
341
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
325
|
-
|
|
326
|
-
|
|
342
|
+
isDrag = _useState12[0],
|
|
343
|
+
setIsDrag = _useState12[1];
|
|
327
344
|
var _useState13 = useState({
|
|
328
|
-
|
|
329
|
-
|
|
345
|
+
startX: 0,
|
|
346
|
+
startY: 0
|
|
330
347
|
}),
|
|
331
348
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
332
|
-
|
|
333
|
-
|
|
349
|
+
startPos = _useState14[0],
|
|
350
|
+
setStartPos = _useState14[1];
|
|
334
351
|
var _useState15 = useState({
|
|
335
352
|
top: 0,
|
|
336
353
|
left: 0
|
|
337
354
|
}),
|
|
338
355
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
339
|
-
|
|
340
|
-
|
|
356
|
+
offset = _useState16[0],
|
|
357
|
+
setOffset = _useState16[1];
|
|
358
|
+
var _useState17 = useState({
|
|
359
|
+
top: 0,
|
|
360
|
+
left: 0
|
|
361
|
+
}),
|
|
362
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
363
|
+
lastOffset = _useState18[0],
|
|
364
|
+
setLastOffset = _useState18[1];
|
|
341
365
|
var handleMouseUp = function handleMouseUp(e) {
|
|
342
366
|
e.preventDefault();
|
|
343
367
|
var button = e.button;
|
package/lib/media/preview.js
CHANGED
|
@@ -85,6 +85,10 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
85
85
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
86
86
|
needPassword = _useState8[0],
|
|
87
87
|
setNeedPassword = _useState8[1];
|
|
88
|
+
var _useState9 = (0, _react.useState)(undefined),
|
|
89
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
90
|
+
pdfOriginalWidth = _useState10[0],
|
|
91
|
+
setPdfOriginalWidth = _useState10[1];
|
|
88
92
|
var _useBreakpoint = useBreakpoint(),
|
|
89
93
|
md = _useBreakpoint.md;
|
|
90
94
|
var _useReducer = (0, _react.useReducer)(function (a) {
|
|
@@ -108,6 +112,22 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
108
112
|
setPageSize(numPages);
|
|
109
113
|
}
|
|
110
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
|
+
};
|
|
111
131
|
var handleCancelLoad = function handleCancelLoad() {
|
|
112
132
|
var current = documentRef === null || documentRef === void 0 ? void 0 : documentRef.current;
|
|
113
133
|
if (current) {
|
|
@@ -174,6 +194,7 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
174
194
|
style: {
|
|
175
195
|
display: 'flex',
|
|
176
196
|
flexDirection: 'column',
|
|
197
|
+
alignItems: 'center',
|
|
177
198
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
178
199
|
width: autoWidth ? '100%' : undefined,
|
|
179
200
|
maxHeight: '100%',
|
|
@@ -191,8 +212,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
191
212
|
}).map(function (_, index) {
|
|
192
213
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_entry.Page, {
|
|
193
214
|
pageNumber: index + 1,
|
|
194
|
-
width: autoWidth ?
|
|
195
|
-
scale: !autoWidth ? scale : undefined
|
|
215
|
+
width: autoWidth ? getOptimalPdfWidth(1) : undefined,
|
|
216
|
+
scale: !autoWidth ? scale : undefined,
|
|
217
|
+
onLoadSuccess: index === 0 ? handlePageLoadSuccess : undefined
|
|
196
218
|
}, index);
|
|
197
219
|
})
|
|
198
220
|
})
|
|
@@ -203,6 +225,7 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
203
225
|
ref: autoWidth ? containerRef : undefined,
|
|
204
226
|
style: {
|
|
205
227
|
maxWidth: "calc(100vw - ".concat(md ? 64 : 32, "px)"),
|
|
228
|
+
width: autoWidth ? '100%' : undefined,
|
|
206
229
|
maxHeight: '100%',
|
|
207
230
|
transform: "translate(".concat(left, "px, ").concat(top, "px)"),
|
|
208
231
|
position: 'absolute',
|
|
@@ -215,8 +238,9 @@ var PdfViewer = function PdfViewer(_ref) {
|
|
|
215
238
|
onPassword: onPassword,
|
|
216
239
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_entry.Page, {
|
|
217
240
|
pageNumber: page,
|
|
218
|
-
width: autoWidth
|
|
219
|
-
scale: !autoWidth ? scale : undefined
|
|
241
|
+
width: autoWidth ? getOptimalPdfWidth(scale) : undefined,
|
|
242
|
+
scale: !autoWidth ? scale : undefined,
|
|
243
|
+
onLoadSuccess: handlePageLoadSuccess
|
|
220
244
|
})
|
|
221
245
|
})
|
|
222
246
|
}, index), isCurrent && Boolean(pageSize > 1) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -319,31 +343,31 @@ var Media = function Media(_ref4) {
|
|
|
319
343
|
showAllPages = _ref4$showAllPages === void 0 ? true : _ref4$showAllPages,
|
|
320
344
|
_ref4$autoWidth = _ref4.autoWidth,
|
|
321
345
|
autoWidth = _ref4$autoWidth === void 0 ? false : _ref4$autoWidth;
|
|
322
|
-
var
|
|
323
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
324
|
-
isDrag = _useState10[0],
|
|
325
|
-
setIsDrag = _useState10[1];
|
|
326
|
-
var _useState11 = (0, _react.useState)({
|
|
327
|
-
startX: 0,
|
|
328
|
-
startY: 0
|
|
329
|
-
}),
|
|
346
|
+
var _useState11 = (0, _react.useState)(false),
|
|
330
347
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
331
|
-
|
|
332
|
-
|
|
348
|
+
isDrag = _useState12[0],
|
|
349
|
+
setIsDrag = _useState12[1];
|
|
333
350
|
var _useState13 = (0, _react.useState)({
|
|
334
|
-
|
|
335
|
-
|
|
351
|
+
startX: 0,
|
|
352
|
+
startY: 0
|
|
336
353
|
}),
|
|
337
354
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
338
|
-
|
|
339
|
-
|
|
355
|
+
startPos = _useState14[0],
|
|
356
|
+
setStartPos = _useState14[1];
|
|
340
357
|
var _useState15 = (0, _react.useState)({
|
|
341
358
|
top: 0,
|
|
342
359
|
left: 0
|
|
343
360
|
}),
|
|
344
361
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
345
|
-
|
|
346
|
-
|
|
362
|
+
offset = _useState16[0],
|
|
363
|
+
setOffset = _useState16[1];
|
|
364
|
+
var _useState17 = (0, _react.useState)({
|
|
365
|
+
top: 0,
|
|
366
|
+
left: 0
|
|
367
|
+
}),
|
|
368
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
369
|
+
lastOffset = _useState18[0],
|
|
370
|
+
setLastOffset = _useState18[1];
|
|
347
371
|
var handleMouseUp = function handleMouseUp(e) {
|
|
348
372
|
e.preventDefault();
|
|
349
373
|
var button = e.button;
|