@atlaskit/media-card 78.0.7 → 78.0.9

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/card/card.js +3 -4
  3. package/dist/cjs/card/externalImageCard.js +4 -2
  4. package/dist/cjs/card/fileCard.js +5 -3
  5. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  6. package/dist/cjs/card/svgView/svgView.js +2 -1
  7. package/dist/cjs/inline/loader.js +1 -1
  8. package/dist/cjs/types.js +16 -1
  9. package/dist/cjs/utils/ufoExperiences.js +1 -1
  10. package/dist/es2019/card/card.js +3 -4
  11. package/dist/es2019/card/externalImageCard.js +5 -2
  12. package/dist/es2019/card/fileCard.js +5 -2
  13. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  14. package/dist/es2019/card/svgView/svgView.js +2 -1
  15. package/dist/es2019/inline/loader.js +1 -1
  16. package/dist/es2019/types.js +10 -0
  17. package/dist/es2019/utils/ufoExperiences.js +1 -1
  18. package/dist/esm/card/card.js +3 -4
  19. package/dist/esm/card/externalImageCard.js +4 -2
  20. package/dist/esm/card/fileCard.js +4 -2
  21. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  22. package/dist/esm/card/svgView/svgView.js +2 -1
  23. package/dist/esm/inline/loader.js +1 -1
  24. package/dist/esm/types.js +14 -0
  25. package/dist/esm/utils/ufoExperiences.js +1 -1
  26. package/dist/types/card/card.d.ts +1 -2
  27. package/dist/types/card/externalImageCard.d.ts +1 -3
  28. package/dist/types/card/fileCard.d.ts +1 -3
  29. package/dist/types/types.d.ts +4 -0
  30. package/dist/types-ts4.5/card/card.d.ts +1 -2
  31. package/dist/types-ts4.5/card/externalImageCard.d.ts +1 -3
  32. package/dist/types-ts4.5/card/fileCard.d.ts +1 -3
  33. package/dist/types-ts4.5/types.d.ts +4 -0
  34. package/example-helpers/index.tsx +4 -2
  35. package/package.json +3 -3
  36. package/dist/cjs/card/cardState.js +0 -37
  37. package/dist/cjs/card/getCardPreview/cache.js +0 -39
  38. package/dist/cjs/card/getCardPreview/filePreviewStatus.js +0 -45
  39. package/dist/cjs/card/getCardPreview/helpers.js +0 -165
  40. package/dist/cjs/card/getCardPreview/index.js +0 -245
  41. package/dist/es2019/card/cardState.js +0 -30
  42. package/dist/es2019/card/getCardPreview/cache.js +0 -33
  43. package/dist/es2019/card/getCardPreview/filePreviewStatus.js +0 -43
  44. package/dist/es2019/card/getCardPreview/helpers.js +0 -74
  45. package/dist/es2019/card/getCardPreview/index.js +0 -170
  46. package/dist/esm/card/cardState.js +0 -32
  47. package/dist/esm/card/getCardPreview/cache.js +0 -35
  48. package/dist/esm/card/getCardPreview/filePreviewStatus.js +0 -40
  49. package/dist/esm/card/getCardPreview/helpers.js +0 -158
  50. package/dist/esm/card/getCardPreview/index.js +0 -213
  51. package/dist/types/card/cardState.d.ts +0 -9
  52. package/dist/types/card/getCardPreview/cache.d.ts +0 -21
  53. package/dist/types/card/getCardPreview/filePreviewStatus.d.ts +0 -4
  54. package/dist/types/card/getCardPreview/helpers.d.ts +0 -10
  55. package/dist/types/card/getCardPreview/index.d.ts +0 -53
  56. package/dist/types-ts4.5/card/cardState.d.ts +0 -9
  57. package/dist/types-ts4.5/card/getCardPreview/cache.d.ts +0 -21
  58. package/dist/types-ts4.5/card/getCardPreview/filePreviewStatus.d.ts +0 -4
  59. package/dist/types-ts4.5/card/getCardPreview/helpers.d.ts +0 -10
  60. package/dist/types-ts4.5/card/getCardPreview/index.d.ts +0 -53
@@ -1,74 +0,0 @@
1
- import { takeSnapshot } from '../../utils/videoSnapshot';
2
- import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
3
- import { getOrientation } from '@atlaskit/media-ui';
4
- import { LocalPreviewError, RemotePreviewError } from '../../errors';
5
- /**
6
- * This method tells the support for the media
7
- * types covered in getCardPreviewFromFilePreview
8
- */
9
- export const isSupportedLocalPreview = mediaType => mediaType === 'image' || mediaType === 'video';
10
- const getImageLocalPreview = async value => {
11
- try {
12
- const orientation = await getOrientation(value);
13
- const dataURI = URL.createObjectURL(value);
14
- return {
15
- dataURI,
16
- orientation,
17
- source: 'local'
18
- };
19
- } catch (e) {
20
- throw new LocalPreviewError('local-preview-image', e instanceof Error ? e : undefined);
21
- }
22
- };
23
- const getVideoLocalPreview = async value => {
24
- try {
25
- const dataURI = await takeSnapshot(value);
26
- return {
27
- dataURI,
28
- orientation: 1,
29
- source: 'local'
30
- };
31
- } catch (e) {
32
- throw new LocalPreviewError('local-preview-video', e instanceof Error ? e : undefined);
33
- }
34
- };
35
- export const getCardPreviewFromFilePreview = async filePreview => {
36
- let value;
37
- try {
38
- const resolvedFilePreview = await filePreview;
39
- value = resolvedFilePreview.value;
40
- } catch (e) {
41
- throw new LocalPreviewError('local-preview-rejected', e instanceof Error ? e : undefined);
42
- }
43
- if (typeof value === 'string') {
44
- return {
45
- dataURI: value,
46
- orientation: 1,
47
- source: 'local'
48
- };
49
- } else if (value instanceof Blob) {
50
- const {
51
- type
52
- } = value;
53
- const mediaType = getMediaTypeFromMimeType(type);
54
- switch (mediaType) {
55
- case 'image':
56
- return getImageLocalPreview(value);
57
- case 'video':
58
- return getVideoLocalPreview(value);
59
- }
60
- }
61
- throw new LocalPreviewError('local-preview-unsupported');
62
- };
63
- export const getCardPreviewFromBackend = async (mediaClient, id, params, traceContext) => {
64
- try {
65
- const blob = await mediaClient.getImage(id, params, undefined, undefined, traceContext);
66
- return {
67
- dataURI: URL.createObjectURL(blob),
68
- orientation: 1,
69
- source: 'remote'
70
- };
71
- } catch (e) {
72
- throw new RemotePreviewError('remote-preview-fetch', e instanceof Error ? e : undefined);
73
- }
74
- };
@@ -1,170 +0,0 @@
1
- import { isPreviewableFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
2
- import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
3
- import cardPreviewCache from './cache';
4
- import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
5
- import { MediaCardError, SsrPreviewError, isUnsupportedLocalPreviewError } from '../../errors';
6
- import { isBigger } from '../../utils/dimensionComparer';
7
- import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
8
- export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
9
- export { extractFilePreviewStatus } from './filePreviewStatus';
10
- export const getCardPreviewFromCache = cardPreviewCache.get;
11
- export const removeCardPreviewFromCache = cardPreviewCache.remove;
12
-
13
- /**
14
- * Will return the preview if available and supported by the browser
15
- * See extractFilePreviewStatus "hasLocalPreview" logic
16
- */
17
- export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
18
- const extendAndCachePreview = (id, mode, preview, mediaBlobUrlAttrs) => {
19
- let source;
20
- switch (preview.source) {
21
- case 'local':
22
- source = 'cache-local';
23
- break;
24
- case 'remote':
25
- source = 'cache-remote';
26
- break;
27
- case 'ssr-server':
28
- source = 'cache-ssr-server';
29
- break;
30
- case 'ssr-client':
31
- source = 'cache-ssr-client';
32
- break;
33
- default:
34
- source = preview.source;
35
- }
36
- // We want to embed some meta context into dataURI for Copy/Paste to work.
37
- const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
38
- // We store new cardPreview into cache
39
- cardPreviewCache.set(id, mode, {
40
- ...preview,
41
- source,
42
- dataURI
43
- });
44
- return {
45
- ...preview,
46
- dataURI
47
- };
48
- };
49
-
50
- /**
51
- * This function will try to return a Card preview, either from cache, local preview or remote preview.
52
- * It should only be called if there is a chance to get either a remote or a local preview, or both.
53
- * This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
54
- * It is worth noting that local preview failures break the process if there is no remote preview available.
55
- * In that case we throw an error immediately.
56
- * Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
57
- * In that case, we still want to report the local preview error to the caller, for feature realiability track.
58
- * hence the use of the optional callback onLocalPreviewError
59
- */
60
- export const getCardPreview = async ({
61
- mediaClient,
62
- id,
63
- dimensions = {},
64
- filePreview,
65
- onLocalPreviewError,
66
- isRemotePreviewReady,
67
- imageUrlParams,
68
- mediaBlobUrlAttrs,
69
- traceContext
70
- }) => {
71
- const mode = imageUrlParams.mode;
72
- const cachedPreview = cardPreviewCache.get(id, mode);
73
- const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
74
- if (cachedPreview && !dimensionsAreBigger) {
75
- return cachedPreview;
76
- }
77
- try {
78
- if (filePreview) {
79
- const localPreview = await getCardPreviewFromFilePreview(filePreview);
80
- return extendAndCachePreview(id, mode, {
81
- ...localPreview,
82
- dimensions
83
- }, mediaBlobUrlAttrs);
84
- }
85
- } catch (e) {
86
- /**
87
- * We report the error if:
88
- * - local preview is supported and fails
89
- * - local preview is unsupported and remote preview is NOT READY
90
- * i.e. the function was called for "no reason".
91
- * We DON'T report the error if:
92
- * - local preview is unsupported and remote preview IS READY
93
- * i.e. local preview is available and not supported,
94
- * but we are after the remote preview instead.
95
- */
96
- if (!isUnsupportedLocalPreviewError(e) || isUnsupportedLocalPreviewError(e) && !isRemotePreviewReady) {
97
- onLocalPreviewError && onLocalPreviewError(e);
98
- }
99
- /**
100
- * No matter the reason why the local preview failed, we break the process
101
- * if there is no remote preview available
102
- */
103
- if (!isRemotePreviewReady) {
104
- throw e;
105
- }
106
- }
107
- if (!isRemotePreviewReady) {
108
- /**
109
- * We throw this in case this function has been called
110
- * without checking isRemotePreviewReady first.
111
- * If remote preview is not ready, the call to getCardPreviewFromBackend
112
- * will generate a console error due to a 404 code
113
- */
114
- throw new MediaCardError('remote-preview-not-ready');
115
- }
116
- const remotePreview = await fetchAndCacheRemotePreview(mediaClient, id, dimensions, imageUrlParams, mediaBlobUrlAttrs, traceContext);
117
- return remotePreview;
118
- };
119
- export const shouldResolvePreview = ({
120
- status,
121
- fileState,
122
- prevDimensions,
123
- dimensions,
124
- hasCardPreview,
125
- isBannedLocalPreview,
126
- wasResolvedUpfrontPreview
127
- }) => {
128
- const statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview));
129
- const dimensionsAreBigger = isBigger(prevDimensions, dimensions);
130
- // We should not fetch the preview if the upfront one hasn't been resolved yet (it could be resolving now), even if there are new dimensions.
131
- return wasResolvedUpfrontPreview && statusIsPreviewable && (!hasCardPreview || dimensionsAreBigger);
132
- };
133
- export const getSSRCardPreview = (ssr, mediaClient, id, params, mediaBlobUrlAttrs) => {
134
- let dataURI;
135
- try {
136
- const rawDataURI = mediaClient.getImageUrlSync(id, params);
137
- // We want to embed some meta context into dataURI for Copy/Paste to work.
138
- dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(rawDataURI, mediaBlobUrlAttrs) : rawDataURI;
139
- const source = ssr === 'client' ? 'ssr-client' : 'ssr-server';
140
- return {
141
- dataURI,
142
- source,
143
- orientation: 1
144
- };
145
- } catch (e) {
146
- const reason = ssr === 'server' ? 'ssr-server-uri' : 'ssr-client-uri';
147
- throw new SsrPreviewError(reason, e instanceof Error ? e : undefined);
148
- }
149
- };
150
- export const isLocalPreview = preview => {
151
- const localSources = ['local', 'cache-local'];
152
- return localSources.includes(preview.source);
153
- };
154
- export const isSSRPreview = preview => isSSRClientPreview(preview) || isSSRServerPreview(preview) || isSSRDataPreview(preview);
155
- export const isSSRServerPreview = preview => {
156
- const ssrClientSources = ['ssr-server', 'cache-ssr-server'];
157
- return ssrClientSources.includes(preview.source);
158
- };
159
- export const isSSRClientPreview = preview => {
160
- const ssrClientSources = ['ssr-client', 'cache-ssr-client'];
161
- return ssrClientSources.includes(preview.source);
162
- };
163
- export const isSSRDataPreview = preview => preview.source === 'ssr-data';
164
- export const fetchAndCacheRemotePreview = async (mediaClient, id, dimensions, params, mediaBlobUrlAttrs, traceContext) => {
165
- const remotePreview = await getCardPreviewFromBackend(mediaClient, id, params, traceContext);
166
- return extendAndCachePreview(id, params.mode, {
167
- ...remotePreview,
168
- dimensions
169
- }, mediaBlobUrlAttrs);
170
- };
@@ -1,32 +0,0 @@
1
- import { isErrorFileState } from '@atlaskit/media-client';
2
- import { MediaCardError } from '../errors';
3
- import { getCardStatus, isFinalCardStatus } from './getCardStatus';
4
- import { extractFilePreviewStatus } from './getCardPreview';
5
-
6
- /**
7
- * From docs: "Both state and props received by the updater function are guaranteed to be up-to-date.
8
- * The output of the updater is shallowly merged with state."
9
- */
10
- export var createStateUpdater = function createStateUpdater(newState, fireErrorEvent) {
11
- return function (prevState) {
12
- // Only override if previous status is non-final or new status is 'complete'
13
- if (!!newState.status && isFinalCardStatus(prevState.status) && newState.status !== 'complete') {
14
- // Log the error if the new state is not going to store it.
15
- // i.e. this is a non critical error
16
- !!newState.error && fireErrorEvent(newState.error);
17
- return prevState;
18
- }
19
- return newState;
20
- };
21
- };
22
- export var getCardStateFromFileState = function getCardStateFromFileState(fileState, isBannedLocalPreview) {
23
- var status = getCardStatus(fileState.status, extractFilePreviewStatus(fileState, isBannedLocalPreview));
24
- var error = status === 'error' && isErrorFileState(fileState) ? new MediaCardError('error-file-state', new Error(fileState.message)) : undefined;
25
- var progress = status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1;
26
- return {
27
- fileState: fileState,
28
- status: status,
29
- progress: progress,
30
- error: error
31
- };
32
- };
@@ -1,35 +0,0 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
- import { createObjectURLCache } from '../../utils/objectURLCache';
5
-
6
- // Dimensions are used to create a key.
7
- // Cache is invalidated when different dimensions are provided.
8
-
9
- export var getCacheKey = function getCacheKey(id, mode) {
10
- var resizeMode = mode || 'crop';
11
- return [id, resizeMode].join('-');
12
- };
13
- export var CardPreviewCacheImpl = /*#__PURE__*/_createClass(function CardPreviewCacheImpl(previewCache) {
14
- var _this = this;
15
- _classCallCheck(this, CardPreviewCacheImpl);
16
- _defineProperty(this, "get", function (id, mode) {
17
- var cacheKey = getCacheKey(id, mode);
18
- return _this.previewCache.get(cacheKey);
19
- });
20
- _defineProperty(this, "set", function (id, mode, cardPreview) {
21
- var cacheKey = getCacheKey(id, mode);
22
- _this.previewCache.set(cacheKey, cardPreview);
23
- });
24
- _defineProperty(this, "remove", function (id, mode) {
25
- var cacheKey = getCacheKey(id, mode);
26
- _this.previewCache.remove(cacheKey);
27
- });
28
- _defineProperty(this, "clear", function () {
29
- _this.previewCache.clear();
30
- });
31
- this.previewCache = previewCache;
32
- });
33
-
34
- // eslint-disable-next-line import/no-anonymous-default-export
35
- export default new CardPreviewCacheImpl(createObjectURLCache());
@@ -1,40 +0,0 @@
1
- import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
2
- import { isPreviewableFileState, isPreviewableType, isImageRepresentationReady } from '@atlaskit/media-client';
3
- import { isSupportedLocalPreview } from './helpers';
4
-
5
- // TODO: align these checks with helpers from Media Client
6
- // https://product-fabric.atlassian.net/browse/BMPT-1300
7
- export var extractFilePreviewStatus = function extractFilePreviewStatus(fileState, isBannedLocalPreview) {
8
- var hasFilesize = 'size' in fileState && !!fileState.size;
9
- var _ref = 'mediaType' in fileState && fileState || {},
10
- mediaType = _ref.mediaType;
11
- var _ref2 = 'mimeType' in fileState && fileState || {},
12
- mimeType = _ref2.mimeType;
13
- var isPreviewable = !!mediaType && isPreviewableType(mediaType);
14
-
15
- // Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
16
- // For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
17
- // Then, local Preview NOT available
18
- var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState(fileState) && isSupportedLocalPreview(mediaType) && !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
19
- var hasRemotePreview = isImageRepresentationReady(fileState);
20
- var hasPreview = hasLocalPreview || hasRemotePreview;
21
- var isSupportedByBrowser = !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
22
- return {
23
- hasFilesize: hasFilesize,
24
- isPreviewable: isPreviewable,
25
- hasPreview: hasPreview,
26
- isSupportedByBrowser: isSupportedByBrowser
27
- };
28
- };
29
-
30
- // CXP-2723 TODO: Review this in relation to removing status from the hook
31
- export var isPreviewableStatus = function isPreviewableStatus(cardStatus, _ref3) {
32
- var isPreviewable = _ref3.isPreviewable,
33
- hasPreview = _ref3.hasPreview,
34
- isSupportedByBrowser = _ref3.isSupportedByBrowser;
35
- return hasPreview && isPreviewable && (cardStatus === 'complete' || cardStatus === 'loading-preview' || cardStatus === 'uploading' ||
36
- // For Video, we can have local or remote preview while processing.
37
- // Then, we only want to show the thumbnail if the file is supported by the browser,
38
- // this way we prevent playing unsupported videos that are not procesed
39
- cardStatus === 'processing' && isSupportedByBrowser);
40
- };
@@ -1,158 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { takeSnapshot } from '../../utils/videoSnapshot';
4
- import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
5
- import { getOrientation } from '@atlaskit/media-ui';
6
- import { LocalPreviewError, RemotePreviewError } from '../../errors';
7
- /**
8
- * This method tells the support for the media
9
- * types covered in getCardPreviewFromFilePreview
10
- */
11
- export var isSupportedLocalPreview = function isSupportedLocalPreview(mediaType) {
12
- return mediaType === 'image' || mediaType === 'video';
13
- };
14
- var getImageLocalPreview = /*#__PURE__*/function () {
15
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
16
- var orientation, dataURI;
17
- return _regeneratorRuntime.wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
19
- case 0:
20
- _context.prev = 0;
21
- _context.next = 3;
22
- return getOrientation(value);
23
- case 3:
24
- orientation = _context.sent;
25
- dataURI = URL.createObjectURL(value);
26
- return _context.abrupt("return", {
27
- dataURI: dataURI,
28
- orientation: orientation,
29
- source: 'local'
30
- });
31
- case 8:
32
- _context.prev = 8;
33
- _context.t0 = _context["catch"](0);
34
- throw new LocalPreviewError('local-preview-image', _context.t0 instanceof Error ? _context.t0 : undefined);
35
- case 11:
36
- case "end":
37
- return _context.stop();
38
- }
39
- }, _callee, null, [[0, 8]]);
40
- }));
41
- return function getImageLocalPreview(_x) {
42
- return _ref.apply(this, arguments);
43
- };
44
- }();
45
- var getVideoLocalPreview = /*#__PURE__*/function () {
46
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(value) {
47
- var dataURI;
48
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
49
- while (1) switch (_context2.prev = _context2.next) {
50
- case 0:
51
- _context2.prev = 0;
52
- _context2.next = 3;
53
- return takeSnapshot(value);
54
- case 3:
55
- dataURI = _context2.sent;
56
- return _context2.abrupt("return", {
57
- dataURI: dataURI,
58
- orientation: 1,
59
- source: 'local'
60
- });
61
- case 7:
62
- _context2.prev = 7;
63
- _context2.t0 = _context2["catch"](0);
64
- throw new LocalPreviewError('local-preview-video', _context2.t0 instanceof Error ? _context2.t0 : undefined);
65
- case 10:
66
- case "end":
67
- return _context2.stop();
68
- }
69
- }, _callee2, null, [[0, 7]]);
70
- }));
71
- return function getVideoLocalPreview(_x2) {
72
- return _ref2.apply(this, arguments);
73
- };
74
- }();
75
- export var getCardPreviewFromFilePreview = /*#__PURE__*/function () {
76
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filePreview) {
77
- var value, resolvedFilePreview, _value, type, mediaType;
78
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
79
- while (1) switch (_context3.prev = _context3.next) {
80
- case 0:
81
- _context3.prev = 0;
82
- _context3.next = 3;
83
- return filePreview;
84
- case 3:
85
- resolvedFilePreview = _context3.sent;
86
- value = resolvedFilePreview.value;
87
- _context3.next = 10;
88
- break;
89
- case 7:
90
- _context3.prev = 7;
91
- _context3.t0 = _context3["catch"](0);
92
- throw new LocalPreviewError('local-preview-rejected', _context3.t0 instanceof Error ? _context3.t0 : undefined);
93
- case 10:
94
- if (!(typeof value === 'string')) {
95
- _context3.next = 14;
96
- break;
97
- }
98
- return _context3.abrupt("return", {
99
- dataURI: value,
100
- orientation: 1,
101
- source: 'local'
102
- });
103
- case 14:
104
- if (!(value instanceof Blob)) {
105
- _context3.next = 22;
106
- break;
107
- }
108
- _value = value, type = _value.type;
109
- mediaType = getMediaTypeFromMimeType(type);
110
- _context3.t1 = mediaType;
111
- _context3.next = _context3.t1 === 'image' ? 20 : _context3.t1 === 'video' ? 21 : 22;
112
- break;
113
- case 20:
114
- return _context3.abrupt("return", getImageLocalPreview(value));
115
- case 21:
116
- return _context3.abrupt("return", getVideoLocalPreview(value));
117
- case 22:
118
- throw new LocalPreviewError('local-preview-unsupported');
119
- case 23:
120
- case "end":
121
- return _context3.stop();
122
- }
123
- }, _callee3, null, [[0, 7]]);
124
- }));
125
- return function getCardPreviewFromFilePreview(_x3) {
126
- return _ref3.apply(this, arguments);
127
- };
128
- }();
129
- export var getCardPreviewFromBackend = /*#__PURE__*/function () {
130
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(mediaClient, id, params, traceContext) {
131
- var blob;
132
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
133
- while (1) switch (_context4.prev = _context4.next) {
134
- case 0:
135
- _context4.prev = 0;
136
- _context4.next = 3;
137
- return mediaClient.getImage(id, params, undefined, undefined, traceContext);
138
- case 3:
139
- blob = _context4.sent;
140
- return _context4.abrupt("return", {
141
- dataURI: URL.createObjectURL(blob),
142
- orientation: 1,
143
- source: 'remote'
144
- });
145
- case 7:
146
- _context4.prev = 7;
147
- _context4.t0 = _context4["catch"](0);
148
- throw new RemotePreviewError('remote-preview-fetch', _context4.t0 instanceof Error ? _context4.t0 : undefined);
149
- case 10:
150
- case "end":
151
- return _context4.stop();
152
- }
153
- }, _callee4, null, [[0, 7]]);
154
- }));
155
- return function getCardPreviewFromBackend(_x4, _x5, _x6, _x7) {
156
- return _ref4.apply(this, arguments);
157
- };
158
- }();