46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
/* Compatibility helpers for Android WebView with ES2017 support. */
|
|
(function () {
|
|
'use strict';
|
|
if (typeof globalThis === 'undefined') { window.globalThis = window; }
|
|
// docx-preview waits for embedded images with allSettled (Chrome 76+).
|
|
// Keep rejected optional resources from rejecting the entire document render.
|
|
if (!Promise.allSettled) {
|
|
Object.defineProperty(Promise, 'allSettled', {
|
|
configurable: true,
|
|
writable: true,
|
|
value: function (values) {
|
|
var Constructor = this;
|
|
try {
|
|
var results = Array.from(values).map(function (value) {
|
|
return Constructor.resolve(value).then(function (result) {
|
|
return { status: 'fulfilled', value: result };
|
|
}, function (reason) {
|
|
return { status: 'rejected', reason: reason };
|
|
});
|
|
});
|
|
return Constructor.all(results);
|
|
} catch (error) { return Constructor.reject(error); }
|
|
}
|
|
});
|
|
}
|
|
if (!Array.prototype.flatMap) {
|
|
Object.defineProperty(Array.prototype, 'flatMap', {
|
|
configurable: true,
|
|
writable: true,
|
|
value: function (callback, receiver) {
|
|
var result = [];
|
|
for (var i = 0; i < this.length; i += 1) {
|
|
if (!(i in this)) { continue; }
|
|
var item = callback.call(receiver, this[i], i, this);
|
|
if (Array.isArray(item)) {
|
|
for (var j = 0; j < item.length; j += 1) {
|
|
if (j in item) { result.push(item[j]); }
|
|
}
|
|
} else { result.push(item); }
|
|
}
|
|
return result;
|
|
}
|
|
});
|
|
}
|
|
}());
|