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>
This commit is contained in:
54
scratch-gui/src/lib/tw-polyfill.js
Normal file
54
scratch-gui/src/lib/tw-polyfill.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/* 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user