Files
001code-html--cocos/scratch-gui/src/lib/tw-polyfill.js
刘宇飞 6e0a1fbcbb Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:37:45 +08:00

55 lines
1.4 KiB
JavaScript

/* eslint-disable no-extend-native */
if (!Blob.prototype.text) {
Blob.prototype.text = function () {
return new Promise((resolve, reject) => {
const fr = new FileReader();
fr.onload = () => resolve(fr.result);
fr.onerror = () => reject(new Error('Cannot read blob as text'));
fr.readAsText(this);
});
};
}
if (!Array.prototype.flat) {
Array.prototype.flat = function (depth = 1) {
const result = [];
for (const i of this) {
if (Array.isArray(i)) {
if (depth < 1) {
result.push(i);
} else {
for (const j of i.flat(depth - 1)) {
result.push(j);
}
}
} else {
result.push(i);
}
}
return result;
};
}
if (!Array.prototype.flatMap) {
Array.prototype.flatMap = function (...args) {
return this.map(...args).flat();
};
}
if (typeof queueMicrotask !== 'function') {
window.queueMicrotask = callback => {
Promise.resolve().then(callback);
};
}
if (!Object.fromEntries) {
Object.fromEntries = function (entries) {
const object = {};
for (const entry of entries) {
object[entry[0]] = entry[1];
}
return object;
};
}