Skip to content

Commit 01db0d2

Browse files
authored
Display Text V2 -- Safari Fixes
1 parent 7408c35 commit 01db0d2

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

extension-code/Display-Text-V2.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// By: SharkPool
55
// License: MIT
66

7-
// Version V.1.0.01
7+
// Version V.1.0.02
88

99
(function (Scratch) {
1010
"use strict";
@@ -32,13 +32,28 @@
3232
textDiv.style.pointerEvents = "none";
3333
render.addOverlay(textDiv, "scale-centered");
3434

35+
const iteratorForEach = (iterator, func) => {
36+
if (typeof iterator.forEach === "function") {
37+
iterator.forEach((value) => func(value));
38+
} else {
39+
let value = iterator.next();
40+
while (!value.done) {
41+
func(value.value);
42+
value = iterator.next();
43+
}
44+
};
45+
}
46+
3547
const BUILT_IN_FONTS = [];
36-
document.fonts.keys().forEach((font) => {
37-
BUILT_IN_FONTS.push({
38-
text: Scratch.translate(font.family),
39-
value: font.family
40-
});
41-
});
48+
iteratorForEach(
49+
document.fonts.keys(),
50+
(font) => {
51+
BUILT_IN_FONTS.push({
52+
text: Scratch.translate(font.family),
53+
value: font.family
54+
});
55+
}
56+
);
4257

4358
// Slightly modified version of Markdown for svg
4459
const MARKDOWN_CONSTS = {
@@ -386,11 +401,14 @@
386401
}
387402

388403
if (isStyleUpdate) {
389-
this.styles.entries().forEach((entry) => {
390-
const oldValue = this._elementInner.getAttribute(entry[0]);
391-
if (oldValue === entry[1]) return;
392-
this._elementInner.setAttribute(entry[0], entry[1]);
393-
});
404+
iteratorForEach(
405+
this.styles.entries(),
406+
(entry) => {
407+
const oldValue = this._elementInner.getAttribute(entry[0]);
408+
if (oldValue === entry[1]) return;
409+
this._elementInner.setAttribute(entry[0], entry[1]);
410+
}
411+
);
394412
} else {
395413
this._elementInner.innerHTML = this.cleansedText;
396414
}
@@ -1019,10 +1037,11 @@
10191037
textObj.updateElement(true);
10201038
} else {
10211039
textObj.setAttribute("line-height", spacing, true);
1040+
if (!textObj._dirty) return;
10221041

10231042
// force a reflow if there is no margins
10241043
const wrapWidth = textObj.specialStyles.get("width");
1025-
if (textObj._dirty && (!wrapWidth || wrapWidth < 1)) {
1044+
if (!wrapWidth || wrapWidth < 1) {
10261045
const oldRawText = textObj.rawText;
10271046
textObj.rawText = undefined;
10281047
textObj.setText(oldRawText);
@@ -1317,11 +1336,14 @@
13171336
textObj2.styles = structuredClone(textObj1.styles);
13181337

13191338
// specialStyles has some non-cloneable stuff
1320-
textObj1.specialStyles.entries().forEach(([key, value]) => {
1321-
textObj2.specialStyles.set(
1322-
key, key === "curve" ? value.cloneNode(true) : value
1323-
);
1324-
});
1339+
iteratorForEach(
1340+
textObj1.specialStyles.entries(),
1341+
([key, value]) => {
1342+
textObj2.specialStyles.set(
1343+
key, key === "curve" ? value.cloneNode(true) : value
1344+
);
1345+
}
1346+
);
13251347

13261348
textObj2._dirty = true;
13271349
textObj2.updateElement(true, true);

0 commit comments

Comments
 (0)