|
4 | 4 | // By: SharkPool |
5 | 5 | // License: MIT |
6 | 6 |
|
7 | | -// Version V.1.0.01 |
| 7 | +// Version V.1.0.02 |
8 | 8 |
|
9 | 9 | (function (Scratch) { |
10 | 10 | "use strict"; |
|
32 | 32 | textDiv.style.pointerEvents = "none"; |
33 | 33 | render.addOverlay(textDiv, "scale-centered"); |
34 | 34 |
|
| 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 | + |
35 | 47 | 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 | + ); |
42 | 57 |
|
43 | 58 | // Slightly modified version of Markdown for svg |
44 | 59 | const MARKDOWN_CONSTS = { |
|
386 | 401 | } |
387 | 402 |
|
388 | 403 | 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 | + ); |
394 | 412 | } else { |
395 | 413 | this._elementInner.innerHTML = this.cleansedText; |
396 | 414 | } |
|
1019 | 1037 | textObj.updateElement(true); |
1020 | 1038 | } else { |
1021 | 1039 | textObj.setAttribute("line-height", spacing, true); |
| 1040 | + if (!textObj._dirty) return; |
1022 | 1041 |
|
1023 | 1042 | // force a reflow if there is no margins |
1024 | 1043 | const wrapWidth = textObj.specialStyles.get("width"); |
1025 | | - if (textObj._dirty && (!wrapWidth || wrapWidth < 1)) { |
| 1044 | + if (!wrapWidth || wrapWidth < 1) { |
1026 | 1045 | const oldRawText = textObj.rawText; |
1027 | 1046 | textObj.rawText = undefined; |
1028 | 1047 | textObj.setText(oldRawText); |
|
1317 | 1336 | textObj2.styles = structuredClone(textObj1.styles); |
1318 | 1337 |
|
1319 | 1338 | // 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 | + ); |
1325 | 1347 |
|
1326 | 1348 | textObj2._dirty = true; |
1327 | 1349 | textObj2.updateElement(true, true); |
|
0 commit comments