@zync/zync-screnplay-player 0.1.251 → 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 +51 -42
- package/dist/screenplay/RemotionRenderer/assets/wordObjects/LICENSE +21 -0
- package/dist/screenplay/RemotionRenderer/assets/wordObjects/emojiCatalog.json +1 -0
- package/dist/screenplay/RemotionRenderer/assets/wordObjects/images.js +24 -0
- package/dist/screenplay/RemotionRenderer/assets/wordObjects/manifest.json +67 -0
- package/dist/screenplay/RemotionRenderer/components/effects/CaptionWordObjectOverlay.js +275 -0
- package/dist/screenplay/RemotionRenderer/components/effects/Sentence.js +10 -3
- package/dist/screenplay/RemotionRenderer/components/layouts/Keyword.js +7 -9
- package/dist/screenplay/RemotionRenderer/components/layouts/KeywordStudioBackdrop.js +5 -7
- package/dist/screenplay/RemotionRenderer/components/layouts/SimpleFrameSentence.js +3 -1
- package/dist/screenplay/RemotionRenderer/components/utils/FaceCenteredVideo.js +9 -0
- package/dist/screenplay/RemotionRenderer/helpers/captionWordObjectGeometry.js +143 -0
- package/dist/screenplay/RemotionRenderer/helpers/captionWordObjects.js +143 -0
- package/dist/screenplay/RemotionRenderer/helpers/emojiCatalog.js +17 -0
- package/dist/screenplay/RemotionRenderer/helpers/headingColors.js +12 -0
- package/dist/screenplay/RemotionRenderer/helpers/loadWordObjectArtwork.js +56 -0
- package/dist/screenplay/RemotionRenderer/helpers/normalizeDisabledTranscripts.js +3 -629
- package/dist/screenplay/RemotionRenderer/main/lib/layouts/LayoutFactory.js +0 -15
- package/dist/screenplay/RemotionRenderer/main/lib/layouts/SimpleFrameLayout.js +8 -3
- package/dist/screenplay/RemotionRenderer/theme/themes/default/CaptionPunctuated.js +29 -6
- package/dist/screenplay/RemotionRenderer/theme/themes/default/CaptionWordBoom.js +42 -47
- package/dist/screenplay/RemotionRenderer/theme/themes/default/CaptionWordBubble.js +30 -7
- package/dist/screenplay/RemotionRenderer/theme/themes/default/Sentence/AnimatedSentence.js +1 -0
- package/dist/screenplay/RemotionRenderer/theme/themes/default/Sentence.js +8 -4
- package/dist/screenplay/RemotionRenderer/theme/themes/fullcover/TextFullCover.js +10 -5
- package/dist/screenplay/RemotionRenderer/theme/themes/glassmorphism/Sentence.js +14 -4
- package/dist/screenplay/RemotionRenderer/tracks/LayoutVideoTrack.js +1 -1
- package/dist/screenplay/RemotionRenderer/tracks/Soundtrack.js +20 -3
- package/dist/timing.cjs +1050 -0
- package/package.json +8 -4
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import timing from "../../../timing.cjs";
|
|
2
|
+
import { toFrames } from "../main/lib/Sequence.js";
|
|
3
|
+
import { isKnownWordObject, isCatalogEmoji } from "./emojiCatalog.js";
|
|
4
|
+
export var WORD_OBJECT_ASSET_IDS = Object.freeze(["plane", "clock", "light_bulb", "money", "rocket", "target", "phone", "computer", "book", "key", "globe", "chart"]);
|
|
5
|
+
export var WORD_OBJECT_CAPTION_TYPES = Object.freeze(["caption_word_boom", "caption_punctuated", "caption_word_bubble"]);
|
|
6
|
+
export var isEnabledWordObject = function isEnabledWordObject(object) {
|
|
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;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// Operates on the renderer's private normalized screenplay, never on saved input.
|
|
11
|
+
export var prepareCaptionWordObjects = function prepareCaptionWordObjects(screenplay, fps) {
|
|
12
|
+
var _screenplay$tracks, _screenplay$tracks$fi;
|
|
13
|
+
var stats = {
|
|
14
|
+
selected: 0,
|
|
15
|
+
disabled: 0,
|
|
16
|
+
suppressed: 0
|
|
17
|
+
};
|
|
18
|
+
// Standalone captions have no speaker layout/segment boundary to validate.
|
|
19
|
+
// Preserve their captions and metadata, but never accept saved private approval.
|
|
20
|
+
(screenplay.tracks || []).filter(function (track) {
|
|
21
|
+
return track.type === "caption";
|
|
22
|
+
}).forEach(function (track) {
|
|
23
|
+
(track.segments || []).forEach(function (caption) {
|
|
24
|
+
var _caption$data;
|
|
25
|
+
(((_caption$data = caption.data) === null || _caption$data === void 0 ? void 0 : _caption$data.transcript_text) || []).forEach(function (transcript) {
|
|
26
|
+
(transcript.punctuations || []).forEach(function (p) {
|
|
27
|
+
delete p.__wordObjectDurationInFrames;
|
|
28
|
+
if (!p.wordObject) return;
|
|
29
|
+
var disabled = p.wordObject.disabled === true;
|
|
30
|
+
p.__wordObjectSuppressed = disabled ? "disabled" : "ineligible";
|
|
31
|
+
stats[disabled ? "disabled" : "suppressed"]++;
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
var segments = ((_screenplay$tracks = screenplay.tracks) === null || _screenplay$tracks === void 0 ? void 0 : (_screenplay$tracks$fi = _screenplay$tracks.find(function (track) {
|
|
37
|
+
return track.type === "segment";
|
|
38
|
+
})) === null || _screenplay$tracks$fi === void 0 ? void 0 : _screenplay$tracks$fi.segments) || [];
|
|
39
|
+
var candidates = [];
|
|
40
|
+
var _timing$getScreenplay = timing.getScreenplayTiming(screenplay, {
|
|
41
|
+
prepared: true
|
|
42
|
+
}),
|
|
43
|
+
sequences = _timing$getScreenplay.sequences;
|
|
44
|
+
segments.forEach(function (segment, segmentIndex) {
|
|
45
|
+
var _layout$data, _layout$data2;
|
|
46
|
+
var cursor = sequences[segmentIndex].startFrame;
|
|
47
|
+
var layout = segment.layout,
|
|
48
|
+
_segment$effects = segment.effects,
|
|
49
|
+
effects = _segment$effects === void 0 ? [] : _segment$effects;
|
|
50
|
+
if (layout !== null && layout !== void 0 && layout.removed) return;
|
|
51
|
+
var _ref = (layout === null || layout === void 0 ? void 0 : layout.data) || {},
|
|
52
|
+
_ref$duration = _ref.duration,
|
|
53
|
+
duration = _ref$duration === void 0 ? 0 : _ref$duration,
|
|
54
|
+
_ref$trimLeft = _ref.trimLeft,
|
|
55
|
+
trimLeft = _ref$trimLeft === void 0 ? 0 : _ref$trimLeft,
|
|
56
|
+
_ref$trimRight = _ref.trimRight,
|
|
57
|
+
trimRight = _ref$trimRight === void 0 ? 0 : _ref$trimRight;
|
|
58
|
+
var durationInFrames = toFrames(fps * (duration - trimLeft - trimRight));
|
|
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) {
|
|
76
|
+
var _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");
|
|
82
|
+
}).forEach(function (effect) {
|
|
83
|
+
var _effect$data3;
|
|
84
|
+
(((_effect$data3 = effect.data) === null || _effect$data3 === void 0 ? void 0 : _effect$data3.transcript_text) || []).forEach(function (transcript) {
|
|
85
|
+
var words = typeof transcript.text === "string" ? transcript.text.split(" ") : [];
|
|
86
|
+
(transcript.punctuations || []).forEach(function (p) {
|
|
87
|
+
var _effect$data4, _screenplay$output;
|
|
88
|
+
if (!p.wordObject) return;
|
|
89
|
+
delete p.__wordObjectSuppressed;
|
|
90
|
+
delete p.__wordObjectDurationInFrames;
|
|
91
|
+
var localStart = toFrames(fps * (p.start - trimLeft));
|
|
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;
|
|
93
|
+
var at = localStart + effectFrom;
|
|
94
|
+
var available = durationInFrames - at;
|
|
95
|
+
if (p.wordObject.disabled === true) {
|
|
96
|
+
p.__wordObjectSuppressed = "disabled";
|
|
97
|
+
stats.disabled++;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
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)) {
|
|
101
|
+
p.__wordObjectSuppressed = "ineligible";
|
|
102
|
+
stats.suppressed++;
|
|
103
|
+
return;
|
|
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
|
+
}
|
|
113
|
+
candidates.push({
|
|
114
|
+
p: p,
|
|
115
|
+
at: cursor + at,
|
|
116
|
+
durationInFrames: objectDurationInFrames
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
candidates.sort(function (a, b) {
|
|
123
|
+
return a.at - b.at;
|
|
124
|
+
});
|
|
125
|
+
var lastStart = -Infinity;
|
|
126
|
+
var lastWasLegacy = false;
|
|
127
|
+
candidates.forEach(function (_ref2) {
|
|
128
|
+
var p = _ref2.p,
|
|
129
|
+
at = _ref2.at,
|
|
130
|
+
durationInFrames = _ref2.durationInFrames;
|
|
131
|
+
var legacy = !isCatalogEmoji(p.wordObject.assetId);
|
|
132
|
+
if (at - lastStart < (legacy || lastWasLegacy ? 15 : 10) * fps) {
|
|
133
|
+
p.__wordObjectSuppressed = "cooldown";
|
|
134
|
+
stats.suppressed++;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
p.__wordObjectDurationInFrames = durationInFrames;
|
|
138
|
+
stats.selected++;
|
|
139
|
+
lastStart = at;
|
|
140
|
+
lastWasLegacy = legacy;
|
|
141
|
+
});
|
|
142
|
+
return stats;
|
|
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,12 @@
|
|
|
1
|
+
// Screenplay overrides are optional. Invalid values never become arbitrary CSS.
|
|
2
|
+
export var getHeadingColors = function getHeadingColors() {
|
|
3
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
var result = {};
|
|
5
|
+
for (var _i = 0, _arr = ["headingTextColor", "headingBackgroundColor"]; _i < _arr.length; _i++) {
|
|
6
|
+
var key = _arr[_i];
|
|
7
|
+
if (typeof props[key] === "string" && /^#[a-f\d]{3}([a-f\d]{3})?$/i.test(props[key])) {
|
|
8
|
+
result[key] = props[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
@@ -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
|
+
};
|