@zync/zync-screnplay-player 0.1.252 → 0.1.253
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/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +24 -0
- package/dist/screenplay/RemotionRenderer/RemotionRenderer.js +9 -1
- package/dist/screenplay/RemotionRenderer/assets/wordObjects/emojiCatalog.json +1 -0
- package/dist/screenplay/RemotionRenderer/components/effects/CaptionWordObjectOverlay.js +36 -4
- package/dist/screenplay/RemotionRenderer/helpers/captionWordObjectGeometry.js +12 -8
- package/dist/screenplay/RemotionRenderer/helpers/captionWordObjects.js +42 -11
- package/dist/screenplay/RemotionRenderer/helpers/emojiCatalog.js +17 -0
- package/dist/screenplay/RemotionRenderer/helpers/loadWordObjectArtwork.js +56 -0
- package/package.json +1 -1
|
@@ -10,7 +10,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
10
10
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11
11
|
import React from "react";
|
|
12
12
|
import { AbsoluteFill, Img, Sequence, continueRender, delayRender, useCurrentFrame, useCurrentScale, useVideoConfig } from "remotion";
|
|
13
|
-
import {
|
|
13
|
+
import { getWordObjectArtwork } from "../../helpers/emojiCatalog.js";
|
|
14
|
+
import { loadWordObjectArtwork } from "../../helpers/loadWordObjectArtwork.js";
|
|
14
15
|
import { isEnabledWordObject } from "../../helpers/captionWordObjects.js";
|
|
15
16
|
import { getWordObjectMotion, placeCaptionWordObject, projectFaceRects } from "../../helpers/captionWordObjectGeometry.js";
|
|
16
17
|
import { cleanFacemetadata } from "../../helpers/cleanFacemetadata.js";
|
|
@@ -36,6 +37,32 @@ var WordObject = function WordObject(_ref) {
|
|
|
36
37
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
37
38
|
measurement = _React$useState2[0],
|
|
38
39
|
setMeasurement = _React$useState2[1];
|
|
40
|
+
var _React$useState3 = React.useState(null),
|
|
41
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
42
|
+
artwork = _React$useState4[0],
|
|
43
|
+
setArtwork = _React$useState4[1];
|
|
44
|
+
var _React$useState5 = React.useState(false),
|
|
45
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
46
|
+
imageFailed = _React$useState6[0],
|
|
47
|
+
setImageFailed = _React$useState6[1];
|
|
48
|
+
var source = event.punctuation.__wordObjectImageUrl || getWordObjectArtwork(event.punctuation.wordObject.assetId);
|
|
49
|
+
React.useEffect(function () {
|
|
50
|
+
var handle = delayRender("Load caption emoji");
|
|
51
|
+
var cancelled = false;
|
|
52
|
+
setArtwork(null);
|
|
53
|
+
setImageFailed(false);
|
|
54
|
+
loadWordObjectArtwork(source).then(function (result) {
|
|
55
|
+
if (!cancelled) setArtwork(result);
|
|
56
|
+
// Allow React to commit the loaded image before releasing this frame.
|
|
57
|
+
requestAnimationFrame(function () {
|
|
58
|
+
return continueRender(handle);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return function () {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
continueRender(handle);
|
|
64
|
+
};
|
|
65
|
+
}, [source]);
|
|
39
66
|
var orientation = (props === null || props === void 0 ? void 0 : (_props$output = props.output) === null || _props$output === void 0 ? void 0 : _props$output.orientation) || (width === height ? "square" : "portrait");
|
|
40
67
|
React.useEffect(function () {
|
|
41
68
|
var _document$fonts;
|
|
@@ -91,6 +118,7 @@ var WordObject = function WordObject(_ref) {
|
|
|
91
118
|
} : translation === null || translation === void 0 ? void 0 : translation.projection;
|
|
92
119
|
var faceRects = projectFaceRects({
|
|
93
120
|
boxes: rawBoxes,
|
|
121
|
+
hasFaceMetadata: (geometry === null || geometry === void 0 ? void 0 : geometry.faceMetadata) != null,
|
|
94
122
|
projection: projection,
|
|
95
123
|
width: width,
|
|
96
124
|
height: height,
|
|
@@ -160,7 +188,7 @@ var WordObject = function WordObject(_ref) {
|
|
|
160
188
|
}, renderSource(transcript, 0, (_transcript$punctuati = (_transcript$punctuati2 = transcript.punctuations) === null || _transcript$punctuati2 === void 0 ? void 0 : (_transcript$punctuati3 = _transcript$punctuati2[0]) === null || _transcript$punctuati3 === void 0 ? void 0 : _transcript$punctuati3.start) !== null && _transcript$punctuati !== void 0 ? _transcript$punctuati : transcript.from, {
|
|
161
189
|
current: null
|
|
162
190
|
}));
|
|
163
|
-
})), placement ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
191
|
+
})), placement && artwork && !imageFailed ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
164
192
|
"data-word-object-copy": true,
|
|
165
193
|
style: {
|
|
166
194
|
position: "absolute",
|
|
@@ -182,7 +210,11 @@ var WordObject = function WordObject(_ref) {
|
|
|
182
210
|
}
|
|
183
211
|
}, event.word), /*#__PURE__*/React.createElement(Img, {
|
|
184
212
|
"data-word-object": event.punctuation.wordObject.assetId,
|
|
185
|
-
src:
|
|
213
|
+
src: artwork,
|
|
214
|
+
maxRetries: 0,
|
|
215
|
+
onError: function onError() {
|
|
216
|
+
return setImageFailed(true);
|
|
217
|
+
},
|
|
186
218
|
style: {
|
|
187
219
|
position: "absolute",
|
|
188
220
|
left: placement.x,
|
|
@@ -209,7 +241,7 @@ export var CaptionWordObjectOverlay = function CaptionWordObjectOverlay(_ref2) {
|
|
|
209
241
|
var events = React.useMemo(function () {
|
|
210
242
|
return transcripts.flatMap(function (transcript) {
|
|
211
243
|
return (transcript.punctuations || []).filter(function (p) {
|
|
212
|
-
return isEnabledWordObject(p.wordObject) && !p.__wordObjectSuppressed && !p.__wordObjectOnsetClipped && Number.isInteger(p.__wordObjectDurationInFrames) && p.__wordObjectDurationInFrames > 0 && Number.isFinite(p.start);
|
|
244
|
+
return isEnabledWordObject(p.wordObject) && !p.__wordObjectSuppressed && !p.__wordObjectOnsetClipped && !p.__wordObjectImageUnavailable && Number.isInteger(p.__wordObjectDurationInFrames) && p.__wordObjectDurationInFrames > 0 && Number.isFinite(p.start);
|
|
213
245
|
}).map(function (punctuation) {
|
|
214
246
|
return {
|
|
215
247
|
transcript: transcript,
|
|
@@ -9,10 +9,14 @@ export var projectFaceRects = function projectFaceRects(_ref) {
|
|
|
9
9
|
projection = _ref.projection,
|
|
10
10
|
width = _ref.width,
|
|
11
11
|
height = _ref.height,
|
|
12
|
+
_ref$hasFaceMetadata = _ref.hasFaceMetadata,
|
|
13
|
+
hasFaceMetadata = _ref$hasFaceMetadata === void 0 ? false : _ref$hasFaceMetadata,
|
|
12
14
|
_ref$videoZoom = _ref.videoZoom,
|
|
13
15
|
videoZoom = _ref$videoZoom === void 0 ? 1 : _ref$videoZoom,
|
|
14
16
|
_ref$framePadding = _ref.framePadding,
|
|
15
17
|
framePadding = _ref$framePadding === void 0 ? 0 : _ref$framePadding;
|
|
18
|
+
// Missing face metadata must not hide otherwise valid caption objects.
|
|
19
|
+
if (!(boxes !== null && boxes !== void 0 && boxes.length) && !hasFaceMetadata) return [];
|
|
16
20
|
if (!projection || !(boxes !== null && boxes !== void 0 && boxes.length) || ![projection.scale, projection.translateX, projection.translateY, projection.originX, projection.originY, videoZoom, framePadding].every(Number.isFinite) || projection.scale <= 0) return [{
|
|
17
21
|
left: 0,
|
|
18
22
|
top: 0,
|
|
@@ -71,12 +75,7 @@ export var placeCaptionWordObject = function placeCaptionWordObject(_ref2) {
|
|
|
71
75
|
var startX = (anchor.left + anchor.right) / 2;
|
|
72
76
|
var startY = (anchor.top + anchor.bottom) / 2;
|
|
73
77
|
if (![width, height, captionTop, startX, startY].every(Number.isFinite)) return null;
|
|
74
|
-
var protectedRects = faceRects || [
|
|
75
|
-
left: 0,
|
|
76
|
-
top: 0,
|
|
77
|
-
right: width,
|
|
78
|
-
bottom: height * 2 / 3
|
|
79
|
-
}];
|
|
78
|
+
var protectedRects = faceRects || [];
|
|
80
79
|
var _loop = function _loop() {
|
|
81
80
|
// Includes rotation, entry overshoot, hover and shadow.
|
|
82
81
|
var halfEnvelope = size * 0.62 + 12 * scale;
|
|
@@ -121,6 +120,11 @@ export var getWordObjectMotion = function getWordObjectMotion(_ref3) {
|
|
|
121
120
|
fps = _ref3.fps,
|
|
122
121
|
durationInFrames = _ref3.durationInFrames,
|
|
123
122
|
assetId = _ref3.assetId;
|
|
123
|
+
var motionAsset = {
|
|
124
|
+
"fluent3d_v1:2708-fe0f": "plane",
|
|
125
|
+
"fluent3d_v1:23f0": "clock",
|
|
126
|
+
"fluent3d_v1:1f4a1": "light_bulb"
|
|
127
|
+
}[assetId] || assetId;
|
|
124
128
|
var seconds = frame / fps;
|
|
125
129
|
var rise = Math.max(0, Math.min(1, seconds / 0.35));
|
|
126
130
|
var easedRise = 1 - Math.pow(1 - rise, 3);
|
|
@@ -133,7 +137,7 @@ export var getWordObjectMotion = function getWordObjectMotion(_ref3) {
|
|
|
133
137
|
opacity: opacity,
|
|
134
138
|
scale: (0.55 + 0.45 * rise + Math.sin(Math.PI * rise) * 0.12) * (0.8 + 0.2 * exit),
|
|
135
139
|
hover: Math.sin(seconds * 3) * 6 * hoverStrength,
|
|
136
|
-
rotation: Math.sin(seconds * 2.5) * (
|
|
137
|
-
glow:
|
|
140
|
+
rotation: Math.sin(seconds * 2.5) * (motionAsset === "plane" ? 6 : motionAsset === "clock" ? 5 : 3) * hoverStrength,
|
|
141
|
+
glow: motionAsset === "light_bulb" ? (0.5 + Math.sin(seconds * 4) * 0.2) * opacity : 0
|
|
138
142
|
};
|
|
139
143
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import timing from "../../../timing.cjs";
|
|
2
2
|
import { toFrames } from "../main/lib/Sequence.js";
|
|
3
|
+
import { isKnownWordObject, isCatalogEmoji } from "./emojiCatalog.js";
|
|
3
4
|
export var WORD_OBJECT_ASSET_IDS = Object.freeze(["plane", "clock", "light_bulb", "money", "rocket", "target", "phone", "computer", "book", "key", "globe", "chart"]);
|
|
4
5
|
export var WORD_OBJECT_CAPTION_TYPES = Object.freeze(["caption_word_boom", "caption_punctuated", "caption_word_bubble"]);
|
|
5
6
|
export var isEnabledWordObject = function isEnabledWordObject(object) {
|
|
6
|
-
return !!object && object.disabled !== true && (object.disabled === undefined || object.disabled === false) &&
|
|
7
|
+
return !!object && object.disabled !== true && (object.disabled === undefined || object.disabled === false) && isKnownWordObject(object.assetId) && object.preset === "emerge_v1" && Number.isFinite(object.duration) && object.duration >= 1.5 && object.duration <= 2.6;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
// Operates on the renderer's private normalized screenplay, never on saved input.
|
|
@@ -55,21 +56,40 @@ export var prepareCaptionWordObjects = function prepareCaptionWordObjects(screen
|
|
|
55
56
|
_ref$trimRight = _ref.trimRight,
|
|
56
57
|
trimRight = _ref$trimRight === void 0 ? 0 : _ref$trimRight;
|
|
57
58
|
var durationInFrames = toFrames(fps * (duration - trimLeft - trimRight));
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
// Prepared layout fields do not prove a treatment is visible. Caption
|
|
60
|
+
// objects work with any layout that displays the supported caption effect.
|
|
61
|
+
var hasHookHeadline = (layout === null || layout === void 0 ? void 0 : layout.type) === "hook_video" && !!((_layout$data = layout.data) !== null && _layout$data !== void 0 && _layout$data.hookText || (_layout$data2 = layout.data) !== null && _layout$data2 !== void 0 && _layout$data2.hookAccentText);
|
|
62
|
+
var localBlocked = effects.filter(function (effect) {
|
|
63
|
+
var _screenplay$input;
|
|
64
|
+
return effect.type === "handoff_nametag" || ["title", "nametag"].includes(effect.type) && (effect.theme || ((_screenplay$input = screenplay.input) === null || _screenplay$input === void 0 ? void 0 : _screenplay$input.theme)) !== "none";
|
|
65
|
+
}).map(function (effect) {
|
|
66
|
+
var _effect$data, _effect$data2;
|
|
67
|
+
var start = fps * (Number(((_effect$data = effect.data) === null || _effect$data === void 0 ? void 0 : _effect$data.offset) || 0) - trimLeft);
|
|
68
|
+
return {
|
|
69
|
+
start: start,
|
|
70
|
+
end: start + toFrames(fps * Number(((_effect$data2 = effect.data) === null || _effect$data2 === void 0 ? void 0 : _effect$data2.duration) || 0))
|
|
71
|
+
};
|
|
72
|
+
}).filter(function (range) {
|
|
73
|
+
return Number.isFinite(range.start) && Number.isFinite(range.end) && range.end > range.start;
|
|
74
|
+
});
|
|
75
|
+
var competingEffect = hasHookHeadline || effects.some(function (effect) {
|
|
60
76
|
var _effect$type;
|
|
61
|
-
return (_effect$type = effect.type)
|
|
77
|
+
return !((_effect$type = effect.type) !== null && _effect$type !== void 0 && _effect$type.includes("caption")) && /keyword|sentence|broll|hook/i.test(effect.type);
|
|
78
|
+
});
|
|
79
|
+
effects.filter(function (effect) {
|
|
80
|
+
var _effect$type2;
|
|
81
|
+
return (_effect$type2 = effect.type) === null || _effect$type2 === void 0 ? void 0 : _effect$type2.includes("caption");
|
|
62
82
|
}).forEach(function (effect) {
|
|
63
|
-
var _effect$
|
|
64
|
-
(((_effect$
|
|
83
|
+
var _effect$data3;
|
|
84
|
+
(((_effect$data3 = effect.data) === null || _effect$data3 === void 0 ? void 0 : _effect$data3.transcript_text) || []).forEach(function (transcript) {
|
|
65
85
|
var words = typeof transcript.text === "string" ? transcript.text.split(" ") : [];
|
|
66
86
|
(transcript.punctuations || []).forEach(function (p) {
|
|
67
|
-
var _effect$
|
|
87
|
+
var _effect$data4, _screenplay$output;
|
|
68
88
|
if (!p.wordObject) return;
|
|
69
89
|
delete p.__wordObjectSuppressed;
|
|
70
90
|
delete p.__wordObjectDurationInFrames;
|
|
71
91
|
var localStart = toFrames(fps * (p.start - trimLeft));
|
|
72
|
-
var effectFrom = Number.isFinite(Number((_effect$
|
|
92
|
+
var effectFrom = Number.isFinite(Number((_effect$data4 = effect.data) === null || _effect$data4 === void 0 ? void 0 : _effect$data4.offset)) ? fps * (Number(effect.data.offset) + trimLeft) : 0;
|
|
73
93
|
var at = localStart + effectFrom;
|
|
74
94
|
var available = durationInFrames - at;
|
|
75
95
|
if (p.wordObject.disabled === true) {
|
|
@@ -77,15 +97,23 @@ export var prepareCaptionWordObjects = function prepareCaptionWordObjects(screen
|
|
|
77
97
|
stats.disabled++;
|
|
78
98
|
return;
|
|
79
99
|
}
|
|
80
|
-
if (
|
|
100
|
+
if (competingEffect || !["portrait", "square"].includes((_screenplay$output = screenplay.output) === null || _screenplay$output === void 0 ? void 0 : _screenplay$output.orientation) || !WORD_OBJECT_CAPTION_TYPES.includes(effect.type) || transcript.disabled === true || p.__wordObjectOnsetClipped || !Number.isFinite(p.start) || !Number.isFinite(p.end) || p.end <= p.start || p.start < trimLeft || !Number.isInteger(p.index) || !words[p.index] || !isEnabledWordObject(p.wordObject) || !Number.isFinite(at) || at < 0 || available < Math.ceil(1.5 * fps)) {
|
|
81
101
|
p.__wordObjectSuppressed = "ineligible";
|
|
82
102
|
stats.suppressed++;
|
|
83
103
|
return;
|
|
84
104
|
}
|
|
105
|
+
var objectDurationInFrames = Math.min(Math.round(p.wordObject.duration * fps), available);
|
|
106
|
+
if (localBlocked.some(function (range) {
|
|
107
|
+
return at < range.end && at + objectDurationInFrames > range.start;
|
|
108
|
+
})) {
|
|
109
|
+
p.__wordObjectSuppressed = "overlay";
|
|
110
|
+
stats.suppressed++;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
85
113
|
candidates.push({
|
|
86
114
|
p: p,
|
|
87
115
|
at: cursor + at,
|
|
88
|
-
durationInFrames:
|
|
116
|
+
durationInFrames: objectDurationInFrames
|
|
89
117
|
});
|
|
90
118
|
});
|
|
91
119
|
});
|
|
@@ -95,11 +123,13 @@ export var prepareCaptionWordObjects = function prepareCaptionWordObjects(screen
|
|
|
95
123
|
return a.at - b.at;
|
|
96
124
|
});
|
|
97
125
|
var lastStart = -Infinity;
|
|
126
|
+
var lastWasLegacy = false;
|
|
98
127
|
candidates.forEach(function (_ref2) {
|
|
99
128
|
var p = _ref2.p,
|
|
100
129
|
at = _ref2.at,
|
|
101
130
|
durationInFrames = _ref2.durationInFrames;
|
|
102
|
-
|
|
131
|
+
var legacy = !isCatalogEmoji(p.wordObject.assetId);
|
|
132
|
+
if (at - lastStart < (legacy || lastWasLegacy ? 15 : 10) * fps) {
|
|
103
133
|
p.__wordObjectSuppressed = "cooldown";
|
|
104
134
|
stats.suppressed++;
|
|
105
135
|
return;
|
|
@@ -107,6 +137,7 @@ export var prepareCaptionWordObjects = function prepareCaptionWordObjects(screen
|
|
|
107
137
|
p.__wordObjectDurationInFrames = durationInFrames;
|
|
108
138
|
stats.selected++;
|
|
109
139
|
lastStart = at;
|
|
140
|
+
lastWasLegacy = legacy;
|
|
110
141
|
});
|
|
111
142
|
return stats;
|
|
112
143
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import catalog from "../assets/wordObjects/emojiCatalog.json";
|
|
2
|
+
import { WORD_OBJECT_IMAGES } from "../assets/wordObjects/images.js";
|
|
3
|
+
var prefix = "".concat(catalog.version, ":");
|
|
4
|
+
var assets = new Map(catalog.assets.map(function (asset) {
|
|
5
|
+
return [prefix + asset.id, asset];
|
|
6
|
+
}));
|
|
7
|
+
export var isCatalogEmoji = function isCatalogEmoji(assetId) {
|
|
8
|
+
return assets.has(assetId);
|
|
9
|
+
};
|
|
10
|
+
export var isKnownWordObject = function isKnownWordObject(assetId) {
|
|
11
|
+
return isCatalogEmoji(assetId) || Object.hasOwn(WORD_OBJECT_IMAGES, assetId);
|
|
12
|
+
};
|
|
13
|
+
export var getWordObjectArtwork = function getWordObjectArtwork(assetId) {
|
|
14
|
+
var asset = assets.get(assetId);
|
|
15
|
+
if (!asset) return Object.hasOwn(WORD_OBJECT_IMAGES, assetId) ? WORD_OBJECT_IMAGES[assetId] : null;
|
|
16
|
+
return "https://cdn.jsdelivr.net/gh/microsoft/fluentui-emoji@".concat(catalog.commit, "/").concat(asset.path.split("/").map(encodeURIComponent).join("/"));
|
|
17
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
5
|
+
// One immutable result per source in each browser, independent of frame order.
|
|
6
|
+
var loads = new Map();
|
|
7
|
+
export var loadWordObjectArtwork = function loadWordObjectArtwork(source) {
|
|
8
|
+
var fetchImage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fetch;
|
|
9
|
+
var timeoutMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10000;
|
|
10
|
+
if (!source) return Promise.resolve(null);
|
|
11
|
+
if (source.startsWith("data:")) return Promise.resolve(source);
|
|
12
|
+
if (!loads.has(source)) {
|
|
13
|
+
loads.set(source, _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
14
|
+
var controller, timeout, _response$headers$get, response, blob;
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
controller = new AbortController();
|
|
19
|
+
timeout = setTimeout(function () {
|
|
20
|
+
return controller.abort();
|
|
21
|
+
}, timeoutMs);
|
|
22
|
+
_context.prev = 2;
|
|
23
|
+
_context.next = 5;
|
|
24
|
+
return fetchImage(source, {
|
|
25
|
+
signal: controller.signal
|
|
26
|
+
});
|
|
27
|
+
case 5:
|
|
28
|
+
response = _context.sent;
|
|
29
|
+
if (!(!response.ok || !((_response$headers$get = response.headers.get("content-type")) !== null && _response$headers$get !== void 0 && _response$headers$get.startsWith("image/")))) {
|
|
30
|
+
_context.next = 8;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
return _context.abrupt("return", null);
|
|
34
|
+
case 8:
|
|
35
|
+
_context.next = 10;
|
|
36
|
+
return response.blob();
|
|
37
|
+
case 10:
|
|
38
|
+
blob = _context.sent;
|
|
39
|
+
return _context.abrupt("return", URL.createObjectURL(blob));
|
|
40
|
+
case 14:
|
|
41
|
+
_context.prev = 14;
|
|
42
|
+
_context.t0 = _context["catch"](2);
|
|
43
|
+
return _context.abrupt("return", null);
|
|
44
|
+
case 17:
|
|
45
|
+
_context.prev = 17;
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
return _context.finish(17);
|
|
48
|
+
case 20:
|
|
49
|
+
case "end":
|
|
50
|
+
return _context.stop();
|
|
51
|
+
}
|
|
52
|
+
}, _callee, null, [[2, 14, 17, 20]]);
|
|
53
|
+
}))());
|
|
54
|
+
}
|
|
55
|
+
return loads.get(source);
|
|
56
|
+
};
|