@atlaskit/media-document-viewer 0.6.10 → 0.6.11
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/CHANGELOG.md +6 -0
- package/dist/cjs/documentViewer.js +1 -5
- package/dist/cjs/page.js +2 -5
- package/dist/cjs/utils/useCachedGetImage.js +14 -34
- package/dist/es2019/documentViewer.js +1 -4
- package/dist/es2019/page.js +2 -5
- package/dist/es2019/utils/useCachedGetImage.js +4 -23
- package/dist/esm/documentViewer.js +1 -5
- package/dist/esm/page.js +2 -5
- package/dist/esm/utils/useCachedGetImage.js +14 -33
- package/dist/types/documentViewer.d.ts +1 -1
- package/dist/types/page.d.ts +1 -2
- package/dist/types/utils/useCachedGetImage.d.ts +1 -11
- package/dist/types-ts4.5/documentViewer.d.ts +1 -1
- package/dist/types-ts4.5/page.d.ts +1 -2
- package/dist/types-ts4.5/utils/useCachedGetImage.d.ts +1 -11
- package/package.json +3 -9
package/CHANGELOG.md
CHANGED
|
@@ -20,7 +20,6 @@ var _useCachedGetImage = require("./utils/useCachedGetImage");
|
|
|
20
20
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
21
21
|
var documentViewerStyles = null;
|
|
22
22
|
var DEFAULT_PAGINATION_SIZE = 50;
|
|
23
|
-
var DEFAULT_MAX_PAGE_IMAGE_ZOOM = 6;
|
|
24
23
|
var DocumentViewer = exports.DocumentViewer = function DocumentViewer(_ref) {
|
|
25
24
|
var _documentMetadata$pag;
|
|
26
25
|
var onSuccess = _ref.onSuccess,
|
|
@@ -28,14 +27,12 @@ var DocumentViewer = exports.DocumentViewer = function DocumentViewer(_ref) {
|
|
|
28
27
|
getPageImageUrl = _ref.getPageImageUrl,
|
|
29
28
|
_ref$paginationSize = _ref.paginationSize,
|
|
30
29
|
paginationSize = _ref$paginationSize === void 0 ? DEFAULT_PAGINATION_SIZE : _ref$paginationSize,
|
|
31
|
-
_ref$maxPageImageZoom = _ref.maxPageImageZoom,
|
|
32
|
-
maxPageImageZoom = _ref$maxPageImageZoom === void 0 ? DEFAULT_MAX_PAGE_IMAGE_ZOOM : _ref$maxPageImageZoom,
|
|
33
30
|
zoom = _ref.zoom;
|
|
34
31
|
var _usePageContent = (0, _usePageContent2.usePageContent)(getContent, paginationSize),
|
|
35
32
|
getPageContent = _usePageContent.getPageContent,
|
|
36
33
|
loadPageContent = _usePageContent.loadPageContent,
|
|
37
34
|
documentMetadata = _usePageContent.documentMetadata;
|
|
38
|
-
var getImageUrl = (0, _useCachedGetImage.useCachedGetImage)(getPageImageUrl
|
|
35
|
+
var getImageUrl = (0, _useCachedGetImage.useCachedGetImage)(getPageImageUrl);
|
|
39
36
|
var style = {
|
|
40
37
|
'--document-viewer-zoom': zoom
|
|
41
38
|
};
|
|
@@ -119,7 +116,6 @@ var DocumentViewer = exports.DocumentViewer = function DocumentViewer(_ref) {
|
|
|
119
116
|
return /*#__PURE__*/React.createElement(_page.Page, {
|
|
120
117
|
key: i,
|
|
121
118
|
getPageSrc: getImageUrl,
|
|
122
|
-
maxPageImageZoom: maxPageImageZoom,
|
|
123
119
|
pageIndex: i,
|
|
124
120
|
zoom: zoom,
|
|
125
121
|
defaultDimensions: documentMetadata.defaultDimensions,
|
package/dist/cjs/page.js
CHANGED
|
@@ -14,12 +14,10 @@ var _runtime = require("@compiled/react/runtime");
|
|
|
14
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
16
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
17
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
17
|
var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
|
|
19
18
|
var _annotations = require("./annotations");
|
|
20
19
|
var _documentLinks = require("./documentLinks");
|
|
21
20
|
var _getDocumentRoot = require("./utils/getDocumentRoot");
|
|
22
|
-
var _useCachedGetImage = require("./utils/useCachedGetImage");
|
|
23
21
|
var _useIntersectionObserver = require("./utils/useIntersectionObserver");
|
|
24
22
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
25
23
|
var Span = function Span(_ref) {
|
|
@@ -115,7 +113,7 @@ var PageView = /*#__PURE__*/(0, _react.forwardRef)(function (_ref4, ref) {
|
|
|
115
113
|
src: imageSrc,
|
|
116
114
|
alt: "",
|
|
117
115
|
onLoad: onImageLoad,
|
|
118
|
-
className: (0, _runtime.ax)(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw",
|
|
116
|
+
className: (0, _runtime.ax)(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw", "_1kemd8h4"])
|
|
119
117
|
}), content && /*#__PURE__*/React.createElement("svg", {
|
|
120
118
|
"data-testid": "page-".concat(pageIndex, "-text-layer"),
|
|
121
119
|
style: style,
|
|
@@ -138,7 +136,6 @@ var PageView = /*#__PURE__*/(0, _react.forwardRef)(function (_ref4, ref) {
|
|
|
138
136
|
var Page = exports.Page = function Page(_ref5) {
|
|
139
137
|
var _ref6;
|
|
140
138
|
var getPageSrc = _ref5.getPageSrc,
|
|
141
|
-
maxPageImageZoom = _ref5.maxPageImageZoom,
|
|
142
139
|
content = _ref5.content,
|
|
143
140
|
fonts = _ref5.fonts,
|
|
144
141
|
pageIndex = _ref5.pageIndex,
|
|
@@ -171,7 +168,7 @@ var Page = exports.Page = function Page(_ref5) {
|
|
|
171
168
|
onLoad === null || onLoad === void 0 || onLoad();
|
|
172
169
|
if (!content) {
|
|
173
170
|
var _zoom = image.dataset.zoom ? Number(image.dataset.zoom) : 1;
|
|
174
|
-
var imageZoom =
|
|
171
|
+
var imageZoom = _zoom;
|
|
175
172
|
var contentWidth = image.naturalWidth / imageZoom;
|
|
176
173
|
var contentHeight = image.naturalHeight / imageZoom;
|
|
177
174
|
setDimensions({
|
|
@@ -4,14 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.getImageZoom = getImageZoom;
|
|
8
7
|
exports.useCachedGetImage = void 0;
|
|
9
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
10
|
var _react = require("react");
|
|
12
11
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
13
|
-
var
|
|
14
|
-
var useCachedGetImage = exports.useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPageImageZoom) {
|
|
12
|
+
var useCachedGetImage = exports.useCachedGetImage = function useCachedGetImage(getPageImageUrl) {
|
|
15
13
|
var imageUrlRefs = (0, _react.useRef)({});
|
|
16
14
|
(0, _react.useEffect)(function () {
|
|
17
15
|
return function () {
|
|
@@ -24,38 +22,37 @@ var useCachedGetImage = exports.useCachedGetImage = function useCachedGetImage(g
|
|
|
24
22
|
}, []);
|
|
25
23
|
var getImageUrl = (0, _mediaCommon.useStaticCallback)( /*#__PURE__*/function () {
|
|
26
24
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(pageNumber, zoom) {
|
|
27
|
-
var
|
|
25
|
+
var key, url, isBlobUrl, blob;
|
|
28
26
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
29
27
|
while (1) switch (_context.prev = _context.next) {
|
|
30
28
|
case 0:
|
|
31
|
-
|
|
32
|
-
key = "".concat(pageNumber, "-").concat(imageZoom);
|
|
29
|
+
key = "".concat(pageNumber, "-").concat(zoom);
|
|
33
30
|
if (!imageUrlRefs.current[key]) {
|
|
34
|
-
_context.next =
|
|
31
|
+
_context.next = 3;
|
|
35
32
|
break;
|
|
36
33
|
}
|
|
37
34
|
return _context.abrupt("return", imageUrlRefs.current[key]);
|
|
38
|
-
case
|
|
39
|
-
_context.next =
|
|
40
|
-
return getPageImageUrl(pageNumber,
|
|
41
|
-
case
|
|
35
|
+
case 3:
|
|
36
|
+
_context.next = 5;
|
|
37
|
+
return getPageImageUrl(pageNumber, zoom);
|
|
38
|
+
case 5:
|
|
42
39
|
url = _context.sent;
|
|
43
40
|
isBlobUrl = url.startsWith('blob:');
|
|
44
41
|
if (isBlobUrl) {
|
|
45
|
-
_context.next =
|
|
42
|
+
_context.next = 12;
|
|
46
43
|
break;
|
|
47
44
|
}
|
|
48
|
-
_context.next =
|
|
45
|
+
_context.next = 10;
|
|
49
46
|
return fetch(url).then(function (res) {
|
|
50
47
|
return res.blob();
|
|
51
48
|
});
|
|
52
|
-
case
|
|
49
|
+
case 10:
|
|
53
50
|
blob = _context.sent;
|
|
54
51
|
url = URL.createObjectURL(blob);
|
|
55
|
-
case
|
|
52
|
+
case 12:
|
|
56
53
|
imageUrlRefs.current[key] = url;
|
|
57
54
|
return _context.abrupt("return", url);
|
|
58
|
-
case
|
|
55
|
+
case 14:
|
|
59
56
|
case "end":
|
|
60
57
|
return _context.stop();
|
|
61
58
|
}
|
|
@@ -66,21 +63,4 @@ var useCachedGetImage = exports.useCachedGetImage = function useCachedGetImage(g
|
|
|
66
63
|
};
|
|
67
64
|
}());
|
|
68
65
|
return getImageUrl;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The actual zoom that will be requested from the image service.
|
|
73
|
-
*
|
|
74
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
75
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
76
|
-
*
|
|
77
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
78
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
79
|
-
*/
|
|
80
|
-
function getImageZoom(zoom, maxPageImageZoom) {
|
|
81
|
-
if (!(0, _platformFeatureFlags.fg)('media-document-viewer-clear-render')) {
|
|
82
|
-
return zoom;
|
|
83
|
-
}
|
|
84
|
-
var dpiAdjustedZoom = zoom * (window.devicePixelRatio || 1);
|
|
85
|
-
return Math.min(dpiAdjustedZoom, maxPageImageZoom);
|
|
86
|
-
}
|
|
66
|
+
};
|
|
@@ -10,13 +10,11 @@ import { getScrollElement } from './utils/getDocumentRoot';
|
|
|
10
10
|
import { useCachedGetImage } from './utils/useCachedGetImage';
|
|
11
11
|
const documentViewerStyles = null;
|
|
12
12
|
const DEFAULT_PAGINATION_SIZE = 50;
|
|
13
|
-
const DEFAULT_MAX_PAGE_IMAGE_ZOOM = 6;
|
|
14
13
|
export const DocumentViewer = ({
|
|
15
14
|
onSuccess,
|
|
16
15
|
getContent,
|
|
17
16
|
getPageImageUrl,
|
|
18
17
|
paginationSize = DEFAULT_PAGINATION_SIZE,
|
|
19
|
-
maxPageImageZoom = DEFAULT_MAX_PAGE_IMAGE_ZOOM,
|
|
20
18
|
zoom
|
|
21
19
|
}) => {
|
|
22
20
|
var _documentMetadata$pag;
|
|
@@ -25,7 +23,7 @@ export const DocumentViewer = ({
|
|
|
25
23
|
loadPageContent,
|
|
26
24
|
documentMetadata
|
|
27
25
|
} = usePageContent(getContent, paginationSize);
|
|
28
|
-
const getImageUrl = useCachedGetImage(getPageImageUrl
|
|
26
|
+
const getImageUrl = useCachedGetImage(getPageImageUrl);
|
|
29
27
|
const style = {
|
|
30
28
|
'--document-viewer-zoom': zoom
|
|
31
29
|
};
|
|
@@ -110,7 +108,6 @@ export const DocumentViewer = ({
|
|
|
110
108
|
return /*#__PURE__*/React.createElement(Page, {
|
|
111
109
|
key: i,
|
|
112
110
|
getPageSrc: getImageUrl,
|
|
113
|
-
maxPageImageZoom: maxPageImageZoom,
|
|
114
111
|
pageIndex: i,
|
|
115
112
|
zoom: zoom,
|
|
116
113
|
defaultDimensions: documentMetadata.defaultDimensions,
|
package/dist/es2019/page.js
CHANGED
|
@@ -4,12 +4,10 @@ import * as React from 'react';
|
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
5
|
import { forwardRef, useEffect, useState } from 'react';
|
|
6
6
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
7
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
7
|
import Spinner from '@atlaskit/spinner';
|
|
9
8
|
import { Annotations } from './annotations';
|
|
10
9
|
import { DocumentLinks } from './documentLinks';
|
|
11
10
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
12
|
-
import { getImageZoom } from './utils/useCachedGetImage';
|
|
13
11
|
import { useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
14
12
|
const Span = ({
|
|
15
13
|
span,
|
|
@@ -105,7 +103,7 @@ const PageView = /*#__PURE__*/forwardRef(({
|
|
|
105
103
|
src: imageSrc,
|
|
106
104
|
alt: "",
|
|
107
105
|
onLoad: onImageLoad,
|
|
108
|
-
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw",
|
|
106
|
+
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw", "_1kemd8h4"])
|
|
109
107
|
}), content && /*#__PURE__*/React.createElement("svg", {
|
|
110
108
|
"data-testid": `page-${pageIndex}-text-layer`,
|
|
111
109
|
style: style,
|
|
@@ -125,7 +123,6 @@ const PageView = /*#__PURE__*/forwardRef(({
|
|
|
125
123
|
});
|
|
126
124
|
export const Page = ({
|
|
127
125
|
getPageSrc,
|
|
128
|
-
maxPageImageZoom,
|
|
129
126
|
content,
|
|
130
127
|
fonts,
|
|
131
128
|
pageIndex,
|
|
@@ -155,7 +152,7 @@ export const Page = ({
|
|
|
155
152
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad();
|
|
156
153
|
if (!content) {
|
|
157
154
|
const zoom = image.dataset.zoom ? Number(image.dataset.zoom) : 1;
|
|
158
|
-
const imageZoom =
|
|
155
|
+
const imageZoom = zoom;
|
|
159
156
|
const contentWidth = image.naturalWidth / imageZoom;
|
|
160
157
|
const contentHeight = image.naturalHeight / imageZoom;
|
|
161
158
|
setDimensions({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
3
|
-
|
|
4
|
-
export const useCachedGetImage = (getPageImageUrl, maxPageImageZoom) => {
|
|
3
|
+
export const useCachedGetImage = getPageImageUrl => {
|
|
5
4
|
const imageUrlRefs = useRef({});
|
|
6
5
|
useEffect(() => {
|
|
7
6
|
return () => {
|
|
@@ -12,12 +11,11 @@ export const useCachedGetImage = (getPageImageUrl, maxPageImageZoom) => {
|
|
|
12
11
|
};
|
|
13
12
|
}, []);
|
|
14
13
|
const getImageUrl = useStaticCallback(async (pageNumber, zoom) => {
|
|
15
|
-
const
|
|
16
|
-
const key = `${pageNumber}-${imageZoom}`;
|
|
14
|
+
const key = `${pageNumber}-${zoom}`;
|
|
17
15
|
if (imageUrlRefs.current[key]) {
|
|
18
16
|
return imageUrlRefs.current[key];
|
|
19
17
|
}
|
|
20
|
-
let url = await getPageImageUrl(pageNumber,
|
|
18
|
+
let url = await getPageImageUrl(pageNumber, zoom);
|
|
21
19
|
const isBlobUrl = url.startsWith('blob:');
|
|
22
20
|
if (!isBlobUrl) {
|
|
23
21
|
const blob = await fetch(url).then(res => res.blob());
|
|
@@ -27,21 +25,4 @@ export const useCachedGetImage = (getPageImageUrl, maxPageImageZoom) => {
|
|
|
27
25
|
return url;
|
|
28
26
|
});
|
|
29
27
|
return getImageUrl;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The actual zoom that will be requested from the image service.
|
|
34
|
-
*
|
|
35
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
36
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
37
|
-
*
|
|
38
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
39
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
40
|
-
*/
|
|
41
|
-
export function getImageZoom(zoom, maxPageImageZoom) {
|
|
42
|
-
if (!fg('media-document-viewer-clear-render')) {
|
|
43
|
-
return zoom;
|
|
44
|
-
}
|
|
45
|
-
const dpiAdjustedZoom = zoom * (window.devicePixelRatio || 1);
|
|
46
|
-
return Math.min(dpiAdjustedZoom, maxPageImageZoom);
|
|
47
|
-
}
|
|
28
|
+
};
|
|
@@ -11,7 +11,6 @@ import { getScrollElement } from './utils/getDocumentRoot';
|
|
|
11
11
|
import { useCachedGetImage } from './utils/useCachedGetImage';
|
|
12
12
|
var documentViewerStyles = null;
|
|
13
13
|
var DEFAULT_PAGINATION_SIZE = 50;
|
|
14
|
-
var DEFAULT_MAX_PAGE_IMAGE_ZOOM = 6;
|
|
15
14
|
export var DocumentViewer = function DocumentViewer(_ref) {
|
|
16
15
|
var _documentMetadata$pag;
|
|
17
16
|
var onSuccess = _ref.onSuccess,
|
|
@@ -19,14 +18,12 @@ export var DocumentViewer = function DocumentViewer(_ref) {
|
|
|
19
18
|
getPageImageUrl = _ref.getPageImageUrl,
|
|
20
19
|
_ref$paginationSize = _ref.paginationSize,
|
|
21
20
|
paginationSize = _ref$paginationSize === void 0 ? DEFAULT_PAGINATION_SIZE : _ref$paginationSize,
|
|
22
|
-
_ref$maxPageImageZoom = _ref.maxPageImageZoom,
|
|
23
|
-
maxPageImageZoom = _ref$maxPageImageZoom === void 0 ? DEFAULT_MAX_PAGE_IMAGE_ZOOM : _ref$maxPageImageZoom,
|
|
24
21
|
zoom = _ref.zoom;
|
|
25
22
|
var _usePageContent = usePageContent(getContent, paginationSize),
|
|
26
23
|
getPageContent = _usePageContent.getPageContent,
|
|
27
24
|
loadPageContent = _usePageContent.loadPageContent,
|
|
28
25
|
documentMetadata = _usePageContent.documentMetadata;
|
|
29
|
-
var getImageUrl = useCachedGetImage(getPageImageUrl
|
|
26
|
+
var getImageUrl = useCachedGetImage(getPageImageUrl);
|
|
30
27
|
var style = {
|
|
31
28
|
'--document-viewer-zoom': zoom
|
|
32
29
|
};
|
|
@@ -110,7 +107,6 @@ export var DocumentViewer = function DocumentViewer(_ref) {
|
|
|
110
107
|
return /*#__PURE__*/React.createElement(Page, {
|
|
111
108
|
key: i,
|
|
112
109
|
getPageSrc: getImageUrl,
|
|
113
|
-
maxPageImageZoom: maxPageImageZoom,
|
|
114
110
|
pageIndex: i,
|
|
115
111
|
zoom: zoom,
|
|
116
112
|
defaultDimensions: documentMetadata.defaultDimensions,
|
package/dist/esm/page.js
CHANGED
|
@@ -6,12 +6,10 @@ import * as React from 'react';
|
|
|
6
6
|
import { ax, ix } from "@compiled/react/runtime";
|
|
7
7
|
import { forwardRef, useEffect, useState } from 'react';
|
|
8
8
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
9
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
9
|
import Spinner from '@atlaskit/spinner';
|
|
11
10
|
import { Annotations } from './annotations';
|
|
12
11
|
import { DocumentLinks } from './documentLinks';
|
|
13
12
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
14
|
-
import { getImageZoom } from './utils/useCachedGetImage';
|
|
15
13
|
import { useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
16
14
|
var Span = function Span(_ref) {
|
|
17
15
|
var span = _ref.span,
|
|
@@ -106,7 +104,7 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
106
104
|
src: imageSrc,
|
|
107
105
|
alt: "",
|
|
108
106
|
onLoad: onImageLoad,
|
|
109
|
-
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw",
|
|
107
|
+
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw", "_1kemd8h4"])
|
|
110
108
|
}), content && /*#__PURE__*/React.createElement("svg", {
|
|
111
109
|
"data-testid": "page-".concat(pageIndex, "-text-layer"),
|
|
112
110
|
style: style,
|
|
@@ -129,7 +127,6 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
129
127
|
export var Page = function Page(_ref5) {
|
|
130
128
|
var _ref6;
|
|
131
129
|
var getPageSrc = _ref5.getPageSrc,
|
|
132
|
-
maxPageImageZoom = _ref5.maxPageImageZoom,
|
|
133
130
|
content = _ref5.content,
|
|
134
131
|
fonts = _ref5.fonts,
|
|
135
132
|
pageIndex = _ref5.pageIndex,
|
|
@@ -162,7 +159,7 @@ export var Page = function Page(_ref5) {
|
|
|
162
159
|
onLoad === null || onLoad === void 0 || onLoad();
|
|
163
160
|
if (!content) {
|
|
164
161
|
var _zoom = image.dataset.zoom ? Number(image.dataset.zoom) : 1;
|
|
165
|
-
var imageZoom =
|
|
162
|
+
var imageZoom = _zoom;
|
|
166
163
|
var contentWidth = image.naturalWidth / imageZoom;
|
|
167
164
|
var contentHeight = image.naturalHeight / imageZoom;
|
|
168
165
|
setDimensions({
|
|
@@ -2,8 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
5
|
-
|
|
6
|
-
export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPageImageZoom) {
|
|
5
|
+
export var useCachedGetImage = function useCachedGetImage(getPageImageUrl) {
|
|
7
6
|
var imageUrlRefs = useRef({});
|
|
8
7
|
useEffect(function () {
|
|
9
8
|
return function () {
|
|
@@ -16,38 +15,37 @@ export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPa
|
|
|
16
15
|
}, []);
|
|
17
16
|
var getImageUrl = useStaticCallback( /*#__PURE__*/function () {
|
|
18
17
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageNumber, zoom) {
|
|
19
|
-
var
|
|
18
|
+
var key, url, isBlobUrl, blob;
|
|
20
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
20
|
while (1) switch (_context.prev = _context.next) {
|
|
22
21
|
case 0:
|
|
23
|
-
|
|
24
|
-
key = "".concat(pageNumber, "-").concat(imageZoom);
|
|
22
|
+
key = "".concat(pageNumber, "-").concat(zoom);
|
|
25
23
|
if (!imageUrlRefs.current[key]) {
|
|
26
|
-
_context.next =
|
|
24
|
+
_context.next = 3;
|
|
27
25
|
break;
|
|
28
26
|
}
|
|
29
27
|
return _context.abrupt("return", imageUrlRefs.current[key]);
|
|
30
|
-
case
|
|
31
|
-
_context.next =
|
|
32
|
-
return getPageImageUrl(pageNumber,
|
|
33
|
-
case
|
|
28
|
+
case 3:
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
return getPageImageUrl(pageNumber, zoom);
|
|
31
|
+
case 5:
|
|
34
32
|
url = _context.sent;
|
|
35
33
|
isBlobUrl = url.startsWith('blob:');
|
|
36
34
|
if (isBlobUrl) {
|
|
37
|
-
_context.next =
|
|
35
|
+
_context.next = 12;
|
|
38
36
|
break;
|
|
39
37
|
}
|
|
40
|
-
_context.next =
|
|
38
|
+
_context.next = 10;
|
|
41
39
|
return fetch(url).then(function (res) {
|
|
42
40
|
return res.blob();
|
|
43
41
|
});
|
|
44
|
-
case
|
|
42
|
+
case 10:
|
|
45
43
|
blob = _context.sent;
|
|
46
44
|
url = URL.createObjectURL(blob);
|
|
47
|
-
case
|
|
45
|
+
case 12:
|
|
48
46
|
imageUrlRefs.current[key] = url;
|
|
49
47
|
return _context.abrupt("return", url);
|
|
50
|
-
case
|
|
48
|
+
case 14:
|
|
51
49
|
case "end":
|
|
52
50
|
return _context.stop();
|
|
53
51
|
}
|
|
@@ -58,21 +56,4 @@ export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPa
|
|
|
58
56
|
};
|
|
59
57
|
}());
|
|
60
58
|
return getImageUrl;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The actual zoom that will be requested from the image service.
|
|
65
|
-
*
|
|
66
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
67
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
68
|
-
*
|
|
69
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
70
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
71
|
-
*/
|
|
72
|
-
export function getImageZoom(zoom, maxPageImageZoom) {
|
|
73
|
-
if (!fg('media-document-viewer-clear-render')) {
|
|
74
|
-
return zoom;
|
|
75
|
-
}
|
|
76
|
-
var dpiAdjustedZoom = zoom * (window.devicePixelRatio || 1);
|
|
77
|
-
return Math.min(dpiAdjustedZoom, maxPageImageZoom);
|
|
78
|
-
}
|
|
59
|
+
};
|
|
@@ -14,4 +14,4 @@ export type DocumentViewerProps = {
|
|
|
14
14
|
zoom: number;
|
|
15
15
|
onSuccess?: () => void;
|
|
16
16
|
};
|
|
17
|
-
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize,
|
|
17
|
+
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize, zoom, }: DocumentViewerProps) => JSX.Element;
|
package/dist/types/page.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Font, type PageContent } from './types';
|
|
2
2
|
type PageProps = {
|
|
3
3
|
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
4
|
-
maxPageImageZoom: number;
|
|
5
4
|
content?: PageContent;
|
|
6
5
|
fonts: readonly Font[];
|
|
7
6
|
pageIndex: number;
|
|
@@ -13,5 +12,5 @@ type PageProps = {
|
|
|
13
12
|
onVisible: () => void;
|
|
14
13
|
onLoad?: () => void;
|
|
15
14
|
};
|
|
16
|
-
export declare const Page: ({ getPageSrc,
|
|
15
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible, onLoad, }: PageProps) => JSX.Element;
|
|
17
16
|
export {};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string
|
|
2
|
-
/**
|
|
3
|
-
* The actual zoom that will be requested from the image service.
|
|
4
|
-
*
|
|
5
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
6
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
7
|
-
*
|
|
8
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
9
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getImageZoom(zoom: number, maxPageImageZoom: number): number;
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => ((pageNumber: number, zoom: number) => Promise<string>);
|
|
@@ -14,4 +14,4 @@ export type DocumentViewerProps = {
|
|
|
14
14
|
zoom: number;
|
|
15
15
|
onSuccess?: () => void;
|
|
16
16
|
};
|
|
17
|
-
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize,
|
|
17
|
+
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize, zoom, }: DocumentViewerProps) => JSX.Element;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Font, type PageContent } from './types';
|
|
2
2
|
type PageProps = {
|
|
3
3
|
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
4
|
-
maxPageImageZoom: number;
|
|
5
4
|
content?: PageContent;
|
|
6
5
|
fonts: readonly Font[];
|
|
7
6
|
pageIndex: number;
|
|
@@ -13,5 +12,5 @@ type PageProps = {
|
|
|
13
12
|
onVisible: () => void;
|
|
14
13
|
onLoad?: () => void;
|
|
15
14
|
};
|
|
16
|
-
export declare const Page: ({ getPageSrc,
|
|
15
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible, onLoad, }: PageProps) => JSX.Element;
|
|
17
16
|
export {};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string
|
|
2
|
-
/**
|
|
3
|
-
* The actual zoom that will be requested from the image service.
|
|
4
|
-
*
|
|
5
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
6
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
7
|
-
*
|
|
8
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
9
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getImageZoom(zoom: number, maxPageImageZoom: number): number;
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => ((pageNumber: number, zoom: number) => Promise<string>);
|
package/package.json
CHANGED
|
@@ -27,10 +27,9 @@
|
|
|
27
27
|
"@atlaskit/browser-apis": "^0.0.1",
|
|
28
28
|
"@atlaskit/css": "^0.19.0",
|
|
29
29
|
"@atlaskit/media-common": "^13.0.0",
|
|
30
|
-
"@atlaskit/
|
|
31
|
-
"@atlaskit/primitives": "^18.1.0",
|
|
30
|
+
"@atlaskit/primitives": "^19.0.0",
|
|
32
31
|
"@atlaskit/spinner": "^19.1.0",
|
|
33
|
-
"@atlaskit/tokens": "^
|
|
32
|
+
"@atlaskit/tokens": "^13.0.0",
|
|
34
33
|
"@babel/runtime": "^7.0.0",
|
|
35
34
|
"@compiled/react": "^0.20.0"
|
|
36
35
|
},
|
|
@@ -47,11 +46,6 @@
|
|
|
47
46
|
"@testing-library/user-event": "^14.4.3",
|
|
48
47
|
"react-dom": "^18.2.0"
|
|
49
48
|
},
|
|
50
|
-
"platform-feature-flags": {
|
|
51
|
-
"media-document-viewer-clear-render": {
|
|
52
|
-
"type": "boolean"
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
49
|
"techstack": {
|
|
56
50
|
"@atlassian/frontend": {
|
|
57
51
|
"import-structure": [
|
|
@@ -88,7 +82,7 @@
|
|
|
88
82
|
}
|
|
89
83
|
},
|
|
90
84
|
"name": "@atlaskit/media-document-viewer",
|
|
91
|
-
"version": "0.6.
|
|
85
|
+
"version": "0.6.11",
|
|
92
86
|
"description": "Modern and fast document viewer",
|
|
93
87
|
"author": "Atlassian Pty Ltd",
|
|
94
88
|
"license": "Apache-2.0",
|