@solidtv/solid 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/src/core/clickInspector.d.ts +1 -0
  2. package/dist/src/core/clickInspector.js +69 -0
  3. package/dist/src/core/clickInspector.js.map +1 -0
  4. package/dist/src/core/config.d.ts +1 -13
  5. package/dist/src/core/config.js +10 -2
  6. package/dist/src/core/config.js.map +1 -1
  7. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -1
  8. package/dist/src/core/dom-renderer/domRenderer.js +254 -67
  9. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  10. package/dist/src/core/elementNode.d.ts +20 -7
  11. package/dist/src/core/elementNode.js +54 -14
  12. package/dist/src/core/elementNode.js.map +1 -1
  13. package/dist/src/core/focusManager.js +5 -3
  14. package/dist/src/core/focusManager.js.map +1 -1
  15. package/dist/src/core/intrinsicTypes.d.ts +2 -0
  16. package/dist/src/core/lightningInit.d.ts +1 -1
  17. package/dist/src/core/lightningInit.js +6 -6
  18. package/dist/src/core/lightningInit.js.map +1 -1
  19. package/dist/src/core/utils.js +4 -4
  20. package/dist/src/core/utils.js.map +1 -1
  21. package/dist/src/primitives/FPSCounter.jsx +5 -5
  22. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  23. package/dist/src/primitives/Image.jsx +6 -1
  24. package/dist/src/primitives/Image.jsx.map +1 -1
  25. package/dist/src/primitives/KeepAlive.jsx +13 -3
  26. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  27. package/dist/src/primitives/LazyImport.js +4 -2
  28. package/dist/src/primitives/LazyImport.js.map +1 -1
  29. package/dist/src/primitives/Preserve.jsx +10 -4
  30. package/dist/src/primitives/Preserve.jsx.map +1 -1
  31. package/dist/src/primitives/Suspense.jsx +7 -7
  32. package/dist/src/primitives/Suspense.jsx.map +1 -1
  33. package/dist/src/primitives/Virtual.jsx.map +1 -1
  34. package/dist/src/primitives/announcer/announcer.js +3 -2
  35. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  36. package/dist/src/primitives/announcer/speech.js +2 -2
  37. package/dist/src/primitives/announcer/speech.js.map +1 -1
  38. package/dist/src/primitives/borderBox.jsx +2 -1
  39. package/dist/src/primitives/borderBox.jsx.map +1 -1
  40. package/dist/src/primitives/createTag.jsx +3 -3
  41. package/dist/src/primitives/createTag.jsx.map +1 -1
  42. package/dist/src/primitives/portal.jsx +4 -3
  43. package/dist/src/primitives/portal.jsx.map +1 -1
  44. package/dist/src/primitives/utils/chainFunctions.js +35 -9
  45. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  46. package/dist/src/primitives/utils/createBlurredImage.js +57 -37
  47. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -1
  48. package/dist/src/primitives/utils/handleNavigation.js +8 -6
  49. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  50. package/dist/src/primitives/utils/withScrolling.js +1 -3
  51. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  52. package/dist/src/render.d.ts +1 -1
  53. package/dist/src/render.js +2 -1
  54. package/dist/src/render.js.map +1 -1
  55. package/dist/src/solidOpts.d.ts +1 -1
  56. package/dist/src/solidOpts.js +4 -2
  57. package/dist/src/solidOpts.js.map +1 -1
  58. package/dist/src/utils.js +10 -5
  59. package/dist/src/utils.js.map +1 -1
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/docs/README.md +2 -2
  62. package/package.json +28 -29
  63. package/src/core/clickInspector.ts +77 -0
  64. package/src/core/config.ts +6 -20
  65. package/src/core/dom-renderer/domRenderer.ts +307 -89
  66. package/src/core/dom-renderer/domRendererTypes.ts +9 -6
  67. package/src/core/elementNode.ts +80 -26
  68. package/src/core/focusManager.ts +16 -8
  69. package/src/core/intrinsicTypes.ts +19 -7
  70. package/src/core/lightningInit.ts +20 -18
  71. package/src/core/utils.ts +4 -4
  72. package/src/primitives/FPSCounter.tsx +14 -10
  73. package/src/primitives/Image.tsx +18 -9
  74. package/src/primitives/KeepAlive.tsx +18 -10
  75. package/src/primitives/LazyImport.ts +8 -6
  76. package/src/primitives/Preserve.tsx +13 -8
  77. package/src/primitives/Suspense.tsx +10 -9
  78. package/src/primitives/Virtual.tsx +1 -8
  79. package/src/primitives/announcer/announcer.ts +3 -2
  80. package/src/primitives/announcer/speech.ts +2 -2
  81. package/src/primitives/borderBox.tsx +7 -3
  82. package/src/primitives/createTag.tsx +23 -17
  83. package/src/primitives/portal.tsx +20 -10
  84. package/src/primitives/utils/chainFunctions.ts +31 -11
  85. package/src/primitives/utils/createBlurredImage.ts +58 -40
  86. package/src/primitives/utils/handleNavigation.ts +9 -7
  87. package/src/primitives/utils/withScrolling.ts +3 -5
  88. package/src/render.ts +4 -4
  89. package/src/solidOpts.ts +9 -7
  90. package/src/types.ts +0 -1
  91. package/src/utils.ts +12 -10
@@ -230,51 +230,119 @@ function updateNodeParent(node: DOMNode | DOMText) {
230
230
  const parent = node.props.parent;
231
231
  if (parent instanceof DOMNode) {
232
232
  elMap.get(parent)!.appendChild(node.div);
233
+ } else {
234
+ node.div.parentNode?.removeChild(node.div);
233
235
  }
234
236
  }
235
237
 
236
- function updateNodeStyles(node: DOMNode | DOMText) {
237
- const { props } = node;
238
+ /**
239
+ * Builds the CSS transform string from node props (x, y, rotation, scale, mount).
240
+ * Returns an empty string if no transform is needed.
241
+ */
242
+ function buildTransformCSS(props: IRendererNodeProps): string {
243
+ const transforms: string[] = [];
238
244
 
239
- let style = `position: absolute; z-index: ${props.zIndex}; opacity: ${props.alpha ?? 1};`;
245
+ const { x, y } = props;
246
+ const hasMountX = props.mountX != null && props.mountX !== 0;
247
+ const hasMountY = props.mountY != null && props.mountY !== 0;
240
248
 
241
- if (props.clipping) {
242
- style += `overflow: hidden;`;
243
- }
249
+ if (x !== 0) transforms.push(`translateX(${x}px)`);
250
+ if (hasMountX) transforms.push(`translateX(${-props.mountX * 100}%)`);
244
251
 
245
- // Transform
246
- {
247
- let transform = '';
252
+ if (y !== 0) transforms.push(`translateY(${y}px)`);
253
+ if (hasMountY) transforms.push(`translateY(${-props.mountY * 100}%)`);
248
254
 
249
- const { x, y } = props;
255
+ if (props.rotation !== 0) transforms.push(`rotate(${props.rotation}rad)`);
250
256
 
251
- const hasMountX = props.mountX != null && props.mountX !== 0;
252
- const hasMountY = props.mountY != null && props.mountY !== 0;
257
+ if (props.scale !== 1 && props.scale != null) {
258
+ transforms.push(`scale(${props.scale})`);
259
+ } else {
260
+ if (props.scaleX !== 1) transforms.push(`scaleX(${props.scaleX})`);
261
+ if (props.scaleY !== 1) transforms.push(`scaleY(${props.scaleY})`);
262
+ }
253
263
 
254
- if (x !== 0) transform += `translateX(${x}px)`;
255
- if (hasMountX) transform += `translateX(${-props.mountX * 100}%)`;
264
+ return transforms.join(' ');
265
+ }
256
266
 
257
- if (y !== 0) transform += `translateY(${y}px)`;
258
- if (hasMountY) transform += `translateY(${-props.mountY * 100}%)`;
267
+ /**
268
+ * Fast path for transform-only updates (x, y, rotation, scale, mount).
269
+ * Skips full style rebuild but still re-evaluates viewport bounds for nodes
270
+ * with a texture source to drive lazy image load/unload during scroll.
271
+ */
272
+ function updateTransformOnly(node: DOMNode | DOMText): void {
273
+ const transform = buildTransformCSS(node.props);
274
+ const s = node.div.style;
275
+
276
+ if (transform.length > 0) {
277
+ s.transform = `${transform}`;
278
+ } else {
279
+ s.transform = '';
280
+ }
259
281
 
260
- if (props.rotation !== 0) transform += `rotate(${props.rotation}rad)`;
282
+ updateRenderStateIfNeeded(node);
283
+ }
261
284
 
262
- if (props.scale !== 1 && props.scale != null) {
263
- transform += `scale(${props.scale})`;
264
- } else {
265
- if (props.scaleX !== 1) transform += `scaleX(${props.scaleX})`;
266
- if (props.scaleY !== 1) transform += `scaleY(${props.scaleY})`;
285
+ /**
286
+ * Recomputes the viewport bounds state for a node with a texture source and,
287
+ * if changed, triggers lazy image load or unload via updateRenderState.
288
+ */
289
+ function updateRenderStateIfNeeded(node: DOMNode | DOMText): void {
290
+ if (!(node instanceof DOMNode) || node === node.stage.root) return;
291
+ const hasTextureSrc = nodeHasTextureSource(node);
292
+ if (hasTextureSrc && node.boundsDirty) {
293
+ const next = computeRenderStateForNode(node);
294
+ if (next != null) {
295
+ node.updateRenderState(next);
267
296
  }
297
+ node.boundsDirty = false;
298
+ } else if (!hasTextureSrc) {
299
+ node.boundsDirty = false;
300
+ }
301
+ }
268
302
 
303
+ function applyLegacyObjectFit(
304
+ node: DOMNode,
305
+ img: HTMLImageElement,
306
+ srcPos: InstanceType<lng.TextureMap['SubTexture']>['props'] | null,
307
+ ): void {
308
+ const resizeMode = node.props.textureOptions?.resizeMode;
309
+ const clipX =
310
+ resizeMode?.type !== 'contain' && resizeMode?.clipX
311
+ ? resizeMode?.clipX
312
+ : 0.5;
313
+ const clipY =
314
+ resizeMode?.type !== 'contain' && resizeMode?.clipY
315
+ ? resizeMode?.clipY
316
+ : 0.5;
317
+ computeLegacyObjectFit(
318
+ node,
319
+ img,
320
+ resizeMode,
321
+ clipX,
322
+ clipY,
323
+ srcPos,
324
+ supportsObjectFit,
325
+ supportsObjectPosition,
326
+ );
327
+ }
328
+
329
+ function updateNodeStyles(node: DOMNode | DOMText) {
330
+ const { props } = node;
331
+
332
+ let style = `position: absolute; z-index: ${props.zIndex};`;
333
+
334
+ if (props.alpha !== 1) style += `opacity: ${props.alpha};`;
335
+
336
+ if (props.clipping) {
337
+ style += `overflow: hidden;`;
338
+ }
339
+
340
+ // Transform
341
+ {
342
+ const transform = buildTransformCSS(props);
269
343
  if (transform.length > 0) {
270
344
  style += `transform: ${transform};`;
271
345
  }
272
-
273
- const pivotX = props.pivotX ?? props.pivot ?? 0.5;
274
- const pivotY = props.pivotY ?? props.pivot ?? 0.5;
275
- if (pivotX !== 0.5 || pivotY !== 0.5) {
276
- style += `transform-origin: ${pivotX * 100}% ${pivotY * 100}%;`;
277
- }
278
346
  }
279
347
 
280
348
  // <Text>
@@ -436,10 +504,9 @@ function updateNodeStyles(node: DOMNode | DOMText) {
436
504
  let imgStyle = '';
437
505
  let hasDivBgTint = false;
438
506
 
507
+ let hasTint = false;
439
508
  if (rawImgSrc) {
440
- needsBackgroundLayer = true;
441
-
442
- const hasTint = props.color !== 0xffffffff && props.color !== 0x00000000;
509
+ hasTint = props.color !== 0xffffffff && props.color !== 0x00000000;
443
510
 
444
511
  if (hasTint) {
445
512
  bgStyle += `background-color: ${colorToRgba(props.color)};`;
@@ -465,6 +532,8 @@ function updateNodeStyles(node: DOMNode | DOMText) {
465
532
  'bottom: 0',
466
533
  'display: block',
467
534
  'pointer-events: none',
535
+ `opacity: ${node.imageLoading ? 0 : 1}`,
536
+ 'transition: opacity 100ms linear',
468
537
  ];
469
538
 
470
539
  if (props.textureOptions.resizeMode?.type) {
@@ -497,7 +566,7 @@ function updateNodeStyles(node: DOMNode | DOMText) {
497
566
  if (supportsMixBlendMode) {
498
567
  imgStyleParts.push('mix-blend-mode: multiply');
499
568
  } else {
500
- imgStyleParts.push('opacity: 0.9');
569
+ imgStyleParts.push('opacity: 1');
501
570
  }
502
571
  }
503
572
 
@@ -693,6 +762,16 @@ function updateNodeStyles(node: DOMNode | DOMText) {
693
762
  }
694
763
  }
695
764
 
765
+ // If there's still no reason to use divBg, check out tint/gradient/subtexture/radius/bgStyle
766
+ if (!needsBackgroundLayer && rawImgSrc) {
767
+ needsBackgroundLayer =
768
+ hasTint ||
769
+ !!gradient ||
770
+ srcPos !== null ||
771
+ radiusStyle !== '' ||
772
+ bgStyle !== '';
773
+ }
774
+
696
775
  style += radiusStyle;
697
776
 
698
777
  if (needsBackgroundLayer) {
@@ -703,14 +782,34 @@ function updateNodeStyles(node: DOMNode | DOMText) {
703
782
  node.div.insertBefore(node.divBg, node.div.firstChild);
704
783
  }
705
784
 
785
+ const isSyncSubtextureUpdate =
786
+ rawImgSrc != null &&
787
+ srcPos != null &&
788
+ !!node.imgEl &&
789
+ node.imgEl.complete &&
790
+ node.imgEl.dataset.rawSrc === rawImgSrc;
791
+ if (isSyncSubtextureUpdate) {
792
+ node.imageLoading = true;
793
+ }
794
+
706
795
  let bgLayerStyle =
707
- 'position: absolute; top:0; left:0; right:0; bottom:0; z-index: -1; pointer-events: none; overflow: hidden;';
796
+ 'position: absolute; top:0; left:0; right:0; bottom:0; z-index: -1; pointer-events: none;';
797
+ // overflow:hidden clips the transformed imgEl to prevent sprite bleed-through
798
+ // for non-tinted subtextures. NOT applied when hasDivBgTint because
799
+ // overflow:hidden + CSS mask-image causes a 1px white border artifact on WebKit.
800
+ // Tinted nodes use mask-image for visual clipping, so overflow:hidden is unnecessary.
801
+ if (srcPos !== null && !hasDivBgTint) {
802
+ bgLayerStyle += 'overflow: hidden;';
803
+ }
708
804
  if (bgStyle) {
709
805
  bgLayerStyle += bgStyle;
710
806
  }
711
807
  if (maskStyle) {
712
808
  bgLayerStyle += maskStyle;
713
809
  }
810
+ if (hasDivBgTint && srcPos != null && node.imageLoading) {
811
+ bgLayerStyle += 'opacity: 0;';
812
+ }
714
813
 
715
814
  node.divBg.setAttribute('style', bgLayerStyle + radiusStyle);
716
815
 
@@ -738,23 +837,22 @@ function updateNodeStyles(node: DOMNode | DOMText) {
738
837
  node.lazyImageSubTextureProps,
739
838
  );
740
839
 
741
- const resizeMode = (node.props.textureOptions as any)?.resizeMode;
742
- const clipX = resizeMode?.clipX ?? 0.5;
743
- const clipY = resizeMode?.clipY ?? 0.5;
744
- computeLegacyObjectFit(
745
- node,
746
- node.imgEl!,
747
- resizeMode,
748
- clipX,
749
- clipY,
750
- node.lazyImageSubTextureProps,
751
- supportsObjectFit,
752
- supportsObjectPosition,
753
- );
840
+ if (!node.lazyImageSubTextureProps) {
841
+ applyLegacyObjectFit(node, node.imgEl!, null);
842
+ }
843
+
844
+ // Reveal only after final fit/positioning is applied
845
+ if (node.imgEl) {
846
+ node.imageLoading = false;
847
+ node.imgEl.style.opacity = '1';
848
+ }
849
+ node.showBackgroundLayer();
754
850
  node.emit('loaded', payload);
755
851
  });
756
852
 
757
853
  node.imgEl.addEventListener('error', () => {
854
+ node.imageLoading = false;
855
+ node.showBackgroundLayer();
758
856
  if (node.imgEl) {
759
857
  node.imgEl.removeAttribute('src');
760
858
  node.imgEl.style.display = 'none';
@@ -780,7 +878,7 @@ function updateNodeStyles(node: DOMNode | DOMText) {
780
878
  node.divBg.appendChild(node.imgEl);
781
879
  }
782
880
 
783
- node.imgEl.setAttribute('style', imgStyle);
881
+ node.imgEl.setAttribute('style', imgStyle + radiusStyle);
784
882
 
785
883
  if (hasDivBgTint) {
786
884
  node.imgEl.style.visibility = 'hidden';
@@ -798,6 +896,11 @@ function updateNodeStyles(node: DOMNode | DOMText) {
798
896
  node.imgEl.dataset.rawSrc === rawImgSrc
799
897
  ) {
800
898
  applySubTextureScaling(node, node.imgEl, srcPos);
899
+ if (node.imageLoading) {
900
+ node.imageLoading = false;
901
+ node.imgEl.style.opacity = '1';
902
+ node.showBackgroundLayer();
903
+ }
801
904
  }
802
905
  if (
803
906
  !srcPos &&
@@ -805,19 +908,7 @@ function updateNodeStyles(node: DOMNode | DOMText) {
805
908
  (!supportsObjectFit || !supportsObjectPosition) &&
806
909
  node.imgEl.dataset.rawSrc === rawImgSrc
807
910
  ) {
808
- const resizeMode = (node.props.textureOptions as any)?.resizeMode;
809
- const clipX = resizeMode?.clipX ?? 0.5;
810
- const clipY = resizeMode?.clipY ?? 0.5;
811
- computeLegacyObjectFit(
812
- node,
813
- node.imgEl,
814
- resizeMode,
815
- clipX,
816
- clipY,
817
- srcPos,
818
- supportsObjectFit,
819
- supportsObjectPosition,
820
- );
911
+ applyLegacyObjectFit(node, node.imgEl, srcPos);
821
912
  }
822
913
  } else {
823
914
  node.lazyImagePendingSrc = null;
@@ -827,6 +918,112 @@ function updateNodeStyles(node: DOMNode | DOMText) {
827
918
  node.imgEl = undefined;
828
919
  }
829
920
  }
921
+ } else if (rawImgSrc) {
922
+ // Image directly in node.div (without divBg) when there is no tint/gradient
923
+
924
+ // Cleanup divBg
925
+ if (node.divBg) {
926
+ node.divBg.remove();
927
+ node.divBg = undefined;
928
+ }
929
+
930
+ const isSyncSubtextureUpdate =
931
+ srcPos != null &&
932
+ !!node.imgEl &&
933
+ node.imgEl.complete &&
934
+ node.imgEl.dataset.rawSrc === rawImgSrc;
935
+ if (isSyncSubtextureUpdate) {
936
+ node.imageLoading = true;
937
+ }
938
+
939
+ if (!node.imgEl) {
940
+ node.imgEl = document.createElement('img');
941
+ node.imgEl.alt = '';
942
+ node.imgEl.crossOrigin = 'anonymous';
943
+ node.imgEl.setAttribute('aria-hidden', 'true');
944
+ node.imgEl.setAttribute('loading', 'lazy');
945
+ node.imgEl.removeAttribute('src');
946
+
947
+ node.imgEl.addEventListener('load', () => {
948
+ const payload: lng.NodeTextureLoadedPayload = {
949
+ type: 'texture',
950
+ dimensions: {
951
+ w: node.imgEl!.naturalWidth,
952
+ h: node.imgEl!.naturalHeight,
953
+ },
954
+ };
955
+ node.imgEl!.style.display = '';
956
+ applySubTextureScaling(
957
+ node,
958
+ node.imgEl!,
959
+ node.lazyImageSubTextureProps,
960
+ );
961
+
962
+ if (!node.lazyImageSubTextureProps) {
963
+ applyLegacyObjectFit(node, node.imgEl!, null);
964
+ }
965
+
966
+ if (node.imgEl) {
967
+ node.imageLoading = false;
968
+ node.imgEl.style.opacity = '1';
969
+ }
970
+ node.emit('loaded', payload);
971
+ });
972
+
973
+ node.imgEl.addEventListener('error', () => {
974
+ node.imageLoading = false;
975
+ if (node.imgEl) {
976
+ node.imgEl.removeAttribute('src');
977
+ node.imgEl.style.display = 'none';
978
+ node.imgEl.removeAttribute('data-rawSrc');
979
+ }
980
+
981
+ const failedSrc =
982
+ node.imgEl?.dataset.pendingSrc || node.lazyImagePendingSrc || '';
983
+
984
+ const payload: lng.NodeTextureFailedPayload = {
985
+ type: 'texture',
986
+ error: new Error(`Failed to load image: ${failedSrc}`),
987
+ };
988
+ node.emit('failed', payload);
989
+ });
990
+ }
991
+
992
+ node.lazyImagePendingSrc = rawImgSrc;
993
+ node.lazyImageSubTextureProps = srcPos;
994
+ node.imgEl.dataset.pendingSrc = rawImgSrc;
995
+
996
+ if (node.imgEl.parentElement !== node.div) {
997
+ node.div.appendChild(node.imgEl);
998
+ }
999
+
1000
+ node.imgEl.setAttribute('style', imgStyle + radiusStyle);
1001
+
1002
+ if (isRenderStateInBounds(node.renderState)) {
1003
+ node.applyPendingImageSrc();
1004
+ } else if (!node.imgEl.dataset.rawSrc) {
1005
+ node.imgEl.removeAttribute('src');
1006
+ }
1007
+
1008
+ if (
1009
+ srcPos &&
1010
+ node.imgEl.complete &&
1011
+ node.imgEl.dataset.rawSrc === rawImgSrc
1012
+ ) {
1013
+ applySubTextureScaling(node, node.imgEl, srcPos);
1014
+ if (node.imageLoading) {
1015
+ node.imageLoading = false;
1016
+ node.imgEl.style.opacity = '1';
1017
+ }
1018
+ }
1019
+ if (
1020
+ !srcPos &&
1021
+ node.imgEl.complete &&
1022
+ (!supportsObjectFit || !supportsObjectPosition) &&
1023
+ node.imgEl.dataset.rawSrc === rawImgSrc
1024
+ ) {
1025
+ applyLegacyObjectFit(node, node.imgEl, srcPos);
1026
+ }
830
1027
  } else {
831
1028
  node.lazyImagePendingSrc = null;
832
1029
  node.lazyImageSubTextureProps = null;
@@ -863,20 +1060,13 @@ function updateNodeStyles(node: DOMNode | DOMText) {
863
1060
  }
864
1061
  }
865
1062
 
866
- node.div.setAttribute('style', compactString(style));
867
-
868
- if (node instanceof DOMNode && node !== node.stage.root) {
869
- const hasTextureSrc = nodeHasTextureSource(node);
870
- if (hasTextureSrc && node.boundsDirty) {
871
- const next = computeRenderStateForNode(node);
872
- if (next != null) {
873
- node.updateRenderState(next);
874
- }
875
- node.boundsDirty = false;
876
- } else if (!hasTextureSrc) {
877
- node.boundsDirty = false;
878
- }
1063
+ const newStyle = compactString(style);
1064
+ if (node._lastStyleStr !== newStyle) {
1065
+ node._lastStyleStr = newStyle;
1066
+ node.div.setAttribute('style', newStyle);
879
1067
  }
1068
+
1069
+ updateRenderStateIfNeeded(node);
880
1070
  }
881
1071
 
882
1072
  const textNodesToMeasure = new Set<DOMText>();
@@ -1013,12 +1203,16 @@ function scheduleUpdateDOMTextMeasurement(node: DOMText) {
1013
1203
  const fonts = document.fonts;
1014
1204
  if (fonts.status === 'loaded') {
1015
1205
  setTimeout(updateDOMTextMeasurements);
1016
- } else if (fonts.ready && typeof fonts.ready.then === 'function') {
1017
- fonts.ready.then(updateDOMTextMeasurements);
1206
+ } else if (
1207
+ fonts.ready != null &&
1208
+ typeof fonts.ready.then === 'function'
1209
+ ) {
1210
+ void fonts.ready.then(updateDOMTextMeasurements);
1018
1211
  } else {
1019
1212
  setTimeout(updateDOMTextMeasurements, 500);
1020
1213
  }
1021
1214
  } else {
1215
+ // Fallback for devices without FontFaceSet.ready()
1022
1216
  setTimeout(updateDOMTextMeasurements, 500);
1023
1217
  }
1024
1218
  }
@@ -1134,12 +1328,15 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1134
1328
  divBg: HTMLElement | undefined;
1135
1329
  divBorder: HTMLElement | undefined;
1136
1330
  imgEl: HTMLImageElement | undefined;
1331
+ imageLoading = false;
1137
1332
  lazyImagePendingSrc: string | null = null;
1138
1333
  lazyImageSubTextureProps:
1139
1334
  | InstanceType<lng.TextureMap['SubTexture']>['props']
1140
1335
  | null = null;
1141
1336
  boundsDirty = true;
1142
1337
  children = new Set<DOMNode>();
1338
+ /** Cached result of the last updateNodeStyles call — avoids redundant setAttribute writes. */
1339
+ _lastStyleStr: string = '';
1143
1340
 
1144
1341
  id = ++lastNodeId;
1145
1342
 
@@ -1174,7 +1371,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1174
1371
  if (parent instanceof DOMNode) {
1175
1372
  parent.children.delete(this);
1176
1373
  }
1177
- this.div.parentNode!.removeChild(this.div);
1374
+ this.div.parentNode?.removeChild(this.div);
1178
1375
  }
1179
1376
 
1180
1377
  get parent() {
@@ -1238,11 +1435,30 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1238
1435
  }
1239
1436
  }
1240
1437
 
1438
+ showBackgroundLayer() {
1439
+ if (this.divBg) {
1440
+ this.divBg.style.opacity = '1';
1441
+ }
1442
+ }
1443
+
1444
+ hideMaskedBackgroundLayer() {
1445
+ if (
1446
+ this.divBg &&
1447
+ (this.divBg.style.maskImage || this.divBg.style.webkitMaskImage)
1448
+ ) {
1449
+ this.divBg.style.opacity = '0';
1450
+ }
1451
+ }
1452
+
1241
1453
  applyPendingImageSrc() {
1242
1454
  if (!this.imgEl) return;
1243
1455
  const pendingSrc = this.lazyImagePendingSrc;
1244
1456
  if (!pendingSrc) return;
1245
1457
  if (this.imgEl.dataset.rawSrc === pendingSrc) return;
1458
+ // Hide transient frame while source is loading and being fitted.
1459
+ this.imageLoading = true;
1460
+ this.imgEl.style.opacity = '0';
1461
+ this.hideMaskedBackgroundLayer();
1246
1462
  this.imgEl.style.display = '';
1247
1463
  this.imgEl.dataset.pendingSrc = pendingSrc;
1248
1464
  this.imgEl.src = pendingSrc;
@@ -1258,7 +1474,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1258
1474
  this.props.x = v;
1259
1475
  this.boundsDirty = true;
1260
1476
  this.markChildrenBoundsDirty();
1261
- updateNodeStyles(this);
1477
+ updateTransformOnly(this);
1262
1478
  }
1263
1479
  get y() {
1264
1480
  return this.props.y;
@@ -1268,7 +1484,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1268
1484
  this.props.y = v;
1269
1485
  this.boundsDirty = true;
1270
1486
  this.markChildrenBoundsDirty();
1271
- updateNodeStyles(this);
1487
+ updateTransformOnly(this);
1272
1488
  }
1273
1489
  get w() {
1274
1490
  return this.props.w;
@@ -1435,7 +1651,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1435
1651
  this.props.scale = v;
1436
1652
  this.boundsDirty = true;
1437
1653
  this.markChildrenBoundsDirty();
1438
- updateNodeStyles(this);
1654
+ updateTransformOnly(this);
1439
1655
  }
1440
1656
  get scaleX() {
1441
1657
  return this.props.scaleX;
@@ -1445,7 +1661,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1445
1661
  this.props.scaleX = v;
1446
1662
  this.boundsDirty = true;
1447
1663
  this.markChildrenBoundsDirty();
1448
- updateNodeStyles(this);
1664
+ updateTransformOnly(this);
1449
1665
  }
1450
1666
  get scaleY() {
1451
1667
  return this.props.scaleY;
@@ -1455,7 +1671,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1455
1671
  this.props.scaleY = v;
1456
1672
  this.boundsDirty = true;
1457
1673
  this.markChildrenBoundsDirty();
1458
- updateNodeStyles(this);
1674
+ updateTransformOnly(this);
1459
1675
  }
1460
1676
  get mount() {
1461
1677
  return this.props.mount;
@@ -1465,7 +1681,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1465
1681
  this.props.mount = v;
1466
1682
  this.boundsDirty = true;
1467
1683
  this.markChildrenBoundsDirty();
1468
- updateNodeStyles(this);
1684
+ updateTransformOnly(this);
1469
1685
  }
1470
1686
  get mountX() {
1471
1687
  return this.props.mountX;
@@ -1475,7 +1691,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1475
1691
  this.props.mountX = v;
1476
1692
  this.boundsDirty = true;
1477
1693
  this.markChildrenBoundsDirty();
1478
- updateNodeStyles(this);
1694
+ updateTransformOnly(this);
1479
1695
  }
1480
1696
  get mountY() {
1481
1697
  return this.props.mountY;
@@ -1485,7 +1701,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1485
1701
  this.props.mountY = v;
1486
1702
  this.boundsDirty = true;
1487
1703
  this.markChildrenBoundsDirty();
1488
- updateNodeStyles(this);
1704
+ updateTransformOnly(this);
1489
1705
  }
1490
1706
  get pivot() {
1491
1707
  return this.props.pivot;
@@ -1525,7 +1741,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1525
1741
  this.props.rotation = v;
1526
1742
  this.boundsDirty = true;
1527
1743
  this.markChildrenBoundsDirty();
1528
- updateNodeStyles(this);
1744
+ updateTransformOnly(this);
1529
1745
  }
1530
1746
  get rtt() {
1531
1747
  return this.props.rtt;
@@ -1816,8 +2032,10 @@ export class DOMRendererMain implements IRendererMain {
1816
2032
  root: DOMNode;
1817
2033
  canvas: HTMLCanvasElement;
1818
2034
  stage: IRendererStage;
1819
- private eventListeners: Map<string, Set<(target: any, data: any) => void>> =
1820
- new Map();
2035
+ private eventListeners: Map<
2036
+ string,
2037
+ Set<(target: unknown, data: unknown) => void>
2038
+ > = new Map();
1821
2039
 
1822
2040
  constructor(
1823
2041
  public settings: DomRendererMainSettings,
@@ -1951,12 +2169,12 @@ export class DOMRendererMain implements IRendererMain {
1951
2169
  ): void;
1952
2170
  emit<K extends string | number>(
1953
2171
  event: Extract<K, string>,
1954
- target: any,
2172
+ target: unknown,
1955
2173
  data: Parameters<any>[1],
1956
2174
  ): void;
1957
2175
  emit<K extends string | number>(
1958
2176
  event: Extract<K, string>,
1959
- targetOrData: any,
2177
+ targetOrData: unknown,
1960
2178
  maybeData?: Parameters<any>[1],
1961
2179
  ): void {
1962
2180
  const listeners = this.eventListeners.get(event);
@@ -83,8 +83,10 @@ export interface IRendererNodeShaded extends EventEmitter {
83
83
  }
84
84
 
85
85
  /** Based on {@link lng.INodeProps} */
86
- export interface IRendererNodeProps
87
- extends Omit<lng.INodeProps, 'shader' | 'parent'> {
86
+ export interface IRendererNodeProps extends Omit<
87
+ lng.INodeProps,
88
+ 'shader' | 'parent'
89
+ > {
88
90
  shader: IRendererShader | null;
89
91
  parent: IRendererNode | null;
90
92
  }
@@ -97,8 +99,10 @@ export interface IRendererNode extends IRendererNodeShaded, IRendererNodeProps {
97
99
  }
98
100
 
99
101
  /** Based on {@link lng.ITextNodeProps} */
100
- export interface IRendererTextNodeProps
101
- extends Omit<lng.ITextNodeProps, 'shader' | 'parent'> {
102
+ export interface IRendererTextNodeProps extends Omit<
103
+ lng.ITextNodeProps,
104
+ 'shader' | 'parent'
105
+ > {
102
106
  shader: IRendererShader | null;
103
107
  parent: IRendererNode | null;
104
108
  fontWeight?: string;
@@ -107,8 +111,7 @@ export interface IRendererTextNodeProps
107
111
 
108
112
  /** Based on {@link lng.ITextNode} */
109
113
  export interface IRendererTextNode
110
- extends IRendererNodeShaded,
111
- IRendererTextNodeProps {
114
+ extends IRendererNodeShaded, IRendererTextNodeProps {
112
115
  div?: HTMLElement;
113
116
  props: IRendererTextNodeProps;
114
117
  renderState: lng.CoreNodeRenderState;