@lightningjs/renderer 3.0.0-beta11 → 3.0.0-beta12

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 (132) hide show
  1. package/dist/src/common/CommonTypes.d.ts +2 -2
  2. package/dist/src/core/CoreNode.d.ts +8 -7
  3. package/dist/src/core/CoreNode.js +57 -61
  4. package/dist/src/core/CoreNode.js.map +1 -1
  5. package/dist/src/core/CoreTextNode.js +9 -9
  6. package/dist/src/core/CoreTextNode.js.map +1 -1
  7. package/dist/src/core/Stage.js +4 -4
  8. package/dist/src/core/Stage.js.map +1 -1
  9. package/dist/src/core/lib/textureCompression.js +4 -4
  10. package/dist/src/core/lib/textureCompression.js.map +1 -1
  11. package/dist/src/core/renderers/CoreShaderNode.js +2 -2
  12. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  13. package/dist/src/core/renderers/canvas/CanvasRenderer.js +1 -1
  14. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  15. package/dist/src/core/renderers/canvas/CanvasTexture.js +5 -5
  16. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -1
  17. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +5 -6
  18. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -1
  19. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +13 -0
  20. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +34 -5
  21. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -1
  22. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +21 -21
  23. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
  24. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +1 -1
  25. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
  26. package/dist/src/core/renderers/webgl/WebGlRenderer.js +12 -11
  27. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  28. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +2 -2
  29. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  30. package/dist/src/core/shaders/canvas/Border.js +4 -4
  31. package/dist/src/core/shaders/canvas/Border.js.map +1 -1
  32. package/dist/src/core/shaders/canvas/HolePunch.js +3 -3
  33. package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -1
  34. package/dist/src/core/shaders/canvas/LinearGradient.js +2 -2
  35. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -1
  36. package/dist/src/core/shaders/canvas/RadialGradient.js +4 -4
  37. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -1
  38. package/dist/src/core/shaders/canvas/Rounded.js +1 -1
  39. package/dist/src/core/shaders/canvas/Rounded.js.map +1 -1
  40. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +3 -3
  41. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -1
  42. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +3 -3
  43. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -1
  44. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +1 -1
  45. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -1
  46. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +1 -1
  47. package/dist/src/core/shaders/templates/BorderTemplate.js +10 -10
  48. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -1
  49. package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +2 -2
  50. package/dist/src/core/shaders/templates/HolePunchTemplate.js +2 -2
  51. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -1
  52. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +2 -2
  53. package/dist/src/core/shaders/templates/RadialGradientTemplate.js +2 -2
  54. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -1
  55. package/dist/src/core/shaders/webgl/Border.js +1 -1
  56. package/dist/src/core/shaders/webgl/Border.js.map +1 -1
  57. package/dist/src/core/shaders/webgl/HolePunch.js +2 -2
  58. package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -1
  59. package/dist/src/core/shaders/webgl/RadialGradient.js +2 -2
  60. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -1
  61. package/dist/src/core/shaders/webgl/Rounded.js +1 -1
  62. package/dist/src/core/shaders/webgl/Rounded.js.map +1 -1
  63. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +2 -2
  64. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
  65. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +2 -2
  66. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
  67. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +1 -1
  68. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -1
  69. package/dist/src/core/textures/ColorTexture.js +1 -1
  70. package/dist/src/core/textures/ColorTexture.js.map +1 -1
  71. package/dist/src/core/textures/ImageTexture.d.ts +2 -2
  72. package/dist/src/core/textures/ImageTexture.js +11 -11
  73. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  74. package/dist/src/core/textures/NoiseTexture.d.ts +2 -2
  75. package/dist/src/core/textures/NoiseTexture.js +6 -6
  76. package/dist/src/core/textures/NoiseTexture.js.map +1 -1
  77. package/dist/src/core/textures/RenderTexture.d.ts +6 -6
  78. package/dist/src/core/textures/RenderTexture.js +10 -10
  79. package/dist/src/core/textures/RenderTexture.js.map +1 -1
  80. package/dist/src/core/textures/SubTexture.d.ts +4 -4
  81. package/dist/src/core/textures/SubTexture.js +8 -8
  82. package/dist/src/core/textures/SubTexture.js.map +1 -1
  83. package/dist/src/core/textures/Texture.d.ts +3 -4
  84. package/dist/src/core/textures/Texture.js +4 -4
  85. package/dist/src/core/textures/Texture.js.map +1 -1
  86. package/dist/src/main-api/Inspector.js +7 -7
  87. package/dist/src/main-api/Inspector.js.map +1 -1
  88. package/dist/src/main-api/Renderer.js +2 -2
  89. package/dist/src/main-api/Renderer.js.map +1 -1
  90. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  91. package/package.json +1 -1
  92. package/src/common/CommonTypes.ts +2 -2
  93. package/src/core/CoreNode.test.ts +12 -12
  94. package/src/core/CoreNode.ts +67 -77
  95. package/src/core/CoreTextNode.ts +9 -9
  96. package/src/core/Stage.ts +4 -4
  97. package/src/core/lib/textureCompression.ts +4 -4
  98. package/src/core/renderers/CoreShaderNode.ts +2 -2
  99. package/src/core/renderers/canvas/CanvasRenderer.ts +2 -2
  100. package/src/core/renderers/canvas/CanvasTexture.ts +5 -5
  101. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +5 -15
  102. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +50 -5
  103. package/src/core/renderers/webgl/WebGlCtxTexture.ts +21 -30
  104. package/src/core/renderers/webgl/WebGlRenderOp.ts +1 -1
  105. package/src/core/renderers/webgl/WebGlRenderer.ts +12 -13
  106. package/src/core/renderers/webgl/WebGlShaderProgram.ts +2 -2
  107. package/src/core/shaders/canvas/Border.ts +4 -4
  108. package/src/core/shaders/canvas/HolePunch.ts +4 -11
  109. package/src/core/shaders/canvas/LinearGradient.ts +2 -2
  110. package/src/core/shaders/canvas/RadialGradient.ts +4 -4
  111. package/src/core/shaders/canvas/Rounded.ts +2 -2
  112. package/src/core/shaders/canvas/RoundedWithBorder.ts +4 -6
  113. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +4 -6
  114. package/src/core/shaders/canvas/RoundedWithShadow.ts +2 -2
  115. package/src/core/shaders/templates/BorderTemplate.ts +11 -11
  116. package/src/core/shaders/templates/HolePunchTemplate.ts +4 -4
  117. package/src/core/shaders/templates/RadialGradientTemplate.ts +4 -4
  118. package/src/core/shaders/webgl/Border.ts +1 -1
  119. package/src/core/shaders/webgl/HolePunch.ts +2 -2
  120. package/src/core/shaders/webgl/RadialGradient.ts +3 -3
  121. package/src/core/shaders/webgl/Rounded.ts +1 -5
  122. package/src/core/shaders/webgl/RoundedWithBorder.ts +2 -6
  123. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +2 -2
  124. package/src/core/shaders/webgl/RoundedWithShadow.ts +1 -5
  125. package/src/core/textures/ColorTexture.ts +1 -1
  126. package/src/core/textures/ImageTexture.ts +15 -15
  127. package/src/core/textures/NoiseTexture.ts +8 -8
  128. package/src/core/textures/RenderTexture.ts +12 -12
  129. package/src/core/textures/SubTexture.ts +10 -10
  130. package/src/core/textures/Texture.ts +7 -7
  131. package/src/main-api/Inspector.ts +8 -8
  132. package/src/main-api/Renderer.ts +2 -2
@@ -231,16 +231,18 @@ export interface CoreNodeProps {
231
231
  y: number;
232
232
  /**
233
233
  * The width of the Node.
234
+ * @warning This will be deprecated in favor of `w` and `h` properties in the future.
234
235
  *
235
236
  * @default `0`
236
237
  */
237
- width: number;
238
+ w: number;
238
239
  /**
239
240
  * The height of the Node.
241
+ * @warning This will be deprecated in favor of `w` and `h` properties in the future.
240
242
  *
241
243
  * @default `0`
242
244
  */
243
- height: number;
245
+ h: number;
244
246
  /**
245
247
  * The alpha opacity of the Node.
246
248
  *
@@ -768,8 +770,8 @@ export class CoreNode extends EventEmitter {
768
770
  // Fast-path assign only known keys
769
771
  p.x = props.x;
770
772
  p.y = props.y;
771
- p.width = props.width;
772
- p.height = props.height;
773
+ p.w = props.w;
774
+ p.h = props.h;
773
775
  p.alpha = props.alpha;
774
776
  p.autosize = props.autosize;
775
777
  p.clipping = props.clipping;
@@ -888,15 +890,12 @@ export class CoreNode extends EventEmitter {
888
890
  texture.setRenderableOwner(this, false);
889
891
  }
890
892
 
891
- autosizeNode(dimensions: Dimensions) {
892
- if (this.autosize) {
893
- this.width = dimensions.width;
894
- this.height = dimensions.height;
893
+ protected onTextureLoaded: TextureLoadedEventHandler = (_, dimensions) => {
894
+ if (this.autosize === true) {
895
+ this.w = dimensions.w;
896
+ this.h = dimensions.h;
895
897
  }
896
- }
897
898
 
898
- protected onTextureLoaded: TextureLoadedEventHandler = (_, dimensions) => {
899
- this.autosizeNode(dimensions);
900
899
  this.setUpdateType(UpdateType.IsRenderable);
901
900
 
902
901
  // Texture was loaded. In case the RAF loop has already stopped, we request
@@ -909,7 +908,7 @@ export class CoreNode extends EventEmitter {
909
908
  }
910
909
 
911
910
  // ignore 1x1 pixel textures
912
- if (dimensions.width > 1 && dimensions.height > 1) {
911
+ if (dimensions.w > 1 && dimensions.h > 1) {
913
912
  this.emit('loaded', {
914
913
  type: 'texture',
915
914
  dimensions,
@@ -979,13 +978,13 @@ export class CoreNode extends EventEmitter {
979
978
 
980
979
  updateLocalTransform() {
981
980
  const p = this.props;
982
- const { x, y, width, height } = p;
983
- const mountTranslateX = p.mountX * width;
984
- const mountTranslateY = p.mountY * height;
981
+ const { x, y, w, h } = p;
982
+ const mountTranslateX = p.mountX * w;
983
+ const mountTranslateY = p.mountY * h;
985
984
 
986
985
  if (p.rotation !== 0 || p.scaleX !== 1 || p.scaleY !== 1) {
987
- const pivotTranslateX = p.pivotX * width;
988
- const pivotTranslateY = p.pivotY * height;
986
+ const pivotTranslateX = p.pivotX * w;
987
+ const pivotTranslateY = p.pivotY * h;
989
988
 
990
989
  this.localTransform = Matrix3d.translate(
991
990
  x - mountTranslateX + pivotTranslateX,
@@ -1014,25 +1013,25 @@ export class CoreNode extends EventEmitter {
1014
1013
  let resizeModeScaleY = 1;
1015
1014
  let extraX = 0;
1016
1015
  let extraY = 0;
1017
- const { width: tw, height: th } = texture.dimensions;
1016
+ const { w: tw, h: th } = texture.dimensions;
1018
1017
  const txAspectRatio = tw / th;
1019
- const nodeAspectRatio = width / height;
1018
+ const nodeAspectRatio = w / h;
1020
1019
  if (txAspectRatio > nodeAspectRatio) {
1021
1020
  // Texture is wider than node
1022
1021
  // Center the node vertically (shift down by extraY)
1023
1022
  // Scale the node vertically to maintain original aspect ratio
1024
- const scaleX = width / tw;
1023
+ const scaleX = w / tw;
1025
1024
  const scaledTxHeight = th * scaleX;
1026
- extraY = (height - scaledTxHeight) / 2;
1027
- resizeModeScaleY = scaledTxHeight / height;
1025
+ extraY = (h - scaledTxHeight) / 2;
1026
+ resizeModeScaleY = scaledTxHeight / h;
1028
1027
  } else {
1029
1028
  // Texture is taller than node (or equal)
1030
1029
  // Center the node horizontally (shift right by extraX)
1031
1030
  // Scale the node horizontally to maintain original aspect ratio
1032
- const scaleY = height / th;
1031
+ const scaleY = h / th;
1033
1032
  const scaledTxWidth = tw * scaleY;
1034
- extraX = (width - scaledTxWidth) / 2;
1035
- resizeModeScaleX = scaledTxWidth / width;
1033
+ extraX = (w - scaledTxWidth) / 2;
1034
+ resizeModeScaleX = scaledTxWidth / w;
1036
1035
  }
1037
1036
 
1038
1037
  // Apply the extra translation and scale to the local transform
@@ -1353,10 +1352,7 @@ export class CoreNode extends EventEmitter {
1353
1352
  }
1354
1353
 
1355
1354
  // check if we dont have dimensions, take our parent's render state
1356
- if (
1357
- this.parent !== null &&
1358
- (this.props.width === 0 || this.props.height === 0)
1359
- ) {
1355
+ if (this.parent !== null && (this.props.w === 0 || this.props.h === 0)) {
1360
1356
  return this.parent.renderState;
1361
1357
  }
1362
1358
 
@@ -1427,20 +1423,14 @@ export class CoreNode extends EventEmitter {
1427
1423
  }
1428
1424
 
1429
1425
  // clipping is enabled and we are in bounds create our own bounds
1430
- const { x, y, width, height } = this.props;
1426
+ const { x, y, w, h } = this.props;
1431
1427
 
1432
1428
  // Pick the global transform if available, otherwise use the local transform
1433
1429
  // global transform is only available if the node in an RTT chain
1434
1430
  const { tx, ty } = this.sceneGlobalTransform || this.globalTransform || {};
1435
1431
  const _x = tx ?? x;
1436
1432
  const _y = ty ?? y;
1437
- this.strictBound = createBound(
1438
- _x,
1439
- _y,
1440
- _x + width,
1441
- _y + height,
1442
- this.strictBound,
1443
- );
1433
+ this.strictBound = createBound(_x, _y, _x + w, _y + h, this.strictBound);
1444
1434
 
1445
1435
  this.preloadBound = createPreloadBounds(
1446
1436
  this.strictBound,
@@ -1489,7 +1479,7 @@ export class CoreNode extends EventEmitter {
1489
1479
  // check shader
1490
1480
  (this.props.shader !== null || this.hasColorProps === true) &&
1491
1481
  // check dimensions
1492
- (this.props.width !== 0 && this.props.height !== 0) === true
1482
+ (this.props.w !== 0 && this.props.h !== 0) === true
1493
1483
  ) {
1494
1484
  // This mean we have dimensions and a color set, so we can render a ColorTexture
1495
1485
  if (
@@ -1527,7 +1517,7 @@ export class CoreNode extends EventEmitter {
1527
1517
  }
1528
1518
 
1529
1519
  calculateRenderCoords() {
1530
- const { width, height } = this;
1520
+ const { w, h } = this.props;
1531
1521
 
1532
1522
  const g = this.globalTransform!;
1533
1523
  const tx = g.tx,
@@ -1538,9 +1528,9 @@ export class CoreNode extends EventEmitter {
1538
1528
  td = g.td;
1539
1529
  if (tb === 0 && tc === 0) {
1540
1530
  const minX = tx;
1541
- const maxX = tx + width * ta;
1531
+ const maxX = tx + w * ta;
1542
1532
  const minY = ty;
1543
- const maxY = ty + height * td;
1533
+ const maxY = ty + h * td;
1544
1534
  this.renderCoords = RenderCoords.translate(
1545
1535
  //top-left
1546
1536
  minX,
@@ -1562,14 +1552,14 @@ export class CoreNode extends EventEmitter {
1562
1552
  tx,
1563
1553
  ty,
1564
1554
  //top-right
1565
- tx + width * ta,
1566
- ty + width * tc,
1555
+ tx + w * ta,
1556
+ ty + w * tc,
1567
1557
  //bottom-right
1568
- tx + width * ta + height * tb,
1569
- ty + width * tc + height * td,
1558
+ tx + w * ta + h * tb,
1559
+ ty + w * tc + h * td,
1570
1560
  //bottom-left
1571
- tx + height * tb,
1572
- ty + height * td,
1561
+ tx + h * tb,
1562
+ ty + h * td,
1573
1563
  this.renderCoords,
1574
1564
  );
1575
1565
  }
@@ -1587,9 +1577,9 @@ export class CoreNode extends EventEmitter {
1587
1577
  } = this.sceneGlobalTransform;
1588
1578
  if (stb === 0 && stc === 0) {
1589
1579
  const minX = stx;
1590
- const maxX = stx + width * sta;
1580
+ const maxX = stx + w * sta;
1591
1581
  const minY = sty;
1592
- const maxY = sty + height * std;
1582
+ const maxY = sty + h * std;
1593
1583
  this.sceneRenderCoords = RenderCoords.translate(
1594
1584
  //top-left
1595
1585
  minX,
@@ -1611,14 +1601,14 @@ export class CoreNode extends EventEmitter {
1611
1601
  stx,
1612
1602
  sty,
1613
1603
  //top-right
1614
- stx + width * sta,
1615
- sty + width * stc,
1604
+ stx + w * sta,
1605
+ sty + w * stc,
1616
1606
  //bottom-right
1617
- stx + width * sta + height * stb,
1618
- sty + width * stc + height * std,
1607
+ stx + w * sta + h * stb,
1608
+ sty + w * stc + h * std,
1619
1609
  //bottom-left
1620
- stx + height * stb,
1621
- sty + height * std,
1610
+ stx + h * stb,
1611
+ sty + h * std,
1622
1612
  this.sceneRenderCoords,
1623
1613
  );
1624
1614
  }
@@ -1640,8 +1630,8 @@ export class CoreNode extends EventEmitter {
1640
1630
  if (clipping === true && isRotated === false) {
1641
1631
  clippingRect.x = gt!.tx;
1642
1632
  clippingRect.y = gt!.ty;
1643
- clippingRect.width = this.width * gt!.ta;
1644
- clippingRect.height = this.height * gt!.td;
1633
+ clippingRect.width = this.props.w * gt!.ta;
1634
+ clippingRect.height = this.props.h * gt!.td;
1645
1635
  clippingRect.valid = true;
1646
1636
  } else {
1647
1637
  clippingRect.valid = false;
@@ -1718,8 +1708,8 @@ export class CoreNode extends EventEmitter {
1718
1708
  const texture = p.texture || this.stage.defaultTexture;
1719
1709
 
1720
1710
  renderer.addQuad({
1721
- width: p.width,
1722
- height: p.height,
1711
+ width: p.w,
1712
+ height: p.h,
1723
1713
  colorTl: this.premultipliedColorTl,
1724
1714
  colorTr: this.premultipliedColorTr,
1725
1715
  colorBl: this.premultipliedColorBl,
@@ -1773,7 +1763,7 @@ export class CoreNode extends EventEmitter {
1773
1763
  get absX(): number {
1774
1764
  return (
1775
1765
  this.props.x +
1776
- -this.props.width * this.props.mountX +
1766
+ -this.props.w * this.props.mountX +
1777
1767
  (this.props.parent?.absX || this.props.parent?.globalTransform?.tx || 0)
1778
1768
  );
1779
1769
  }
@@ -1781,7 +1771,7 @@ export class CoreNode extends EventEmitter {
1781
1771
  get absY(): number {
1782
1772
  return (
1783
1773
  this.props.y +
1784
- -this.props.height * this.props.mountY +
1774
+ -this.props.h * this.props.mountY +
1785
1775
  (this.props.parent?.absY ?? 0)
1786
1776
  );
1787
1777
  }
@@ -1797,18 +1787,18 @@ export class CoreNode extends EventEmitter {
1797
1787
  }
1798
1788
  }
1799
1789
 
1800
- get width(): number {
1801
- return this.props.width;
1790
+ get w(): number {
1791
+ return this.props.w;
1802
1792
  }
1803
1793
 
1804
- set width(value: number) {
1805
- if (this.props.width !== value) {
1794
+ set w(value: number) {
1795
+ if (this.props.w !== value) {
1806
1796
  this.textureCoords = undefined;
1807
- this.props.width = value;
1797
+ this.props.w = value;
1808
1798
  this.setUpdateType(UpdateType.Local);
1809
1799
 
1810
1800
  if (this.props.rtt === true) {
1811
- this.framebufferDimensions!.width = value;
1801
+ this.framebufferDimensions!.w = value;
1812
1802
  this.texture = this.stage.txManager.createTexture(
1813
1803
  'RenderTexture',
1814
1804
  this.framebufferDimensions!,
@@ -1819,18 +1809,18 @@ export class CoreNode extends EventEmitter {
1819
1809
  }
1820
1810
  }
1821
1811
 
1822
- get height(): number {
1823
- return this.props.height;
1812
+ get h(): number {
1813
+ return this.props.h;
1824
1814
  }
1825
1815
 
1826
- set height(value: number) {
1827
- if (this.props.height !== value) {
1816
+ set h(value: number) {
1817
+ if (this.props.h !== value) {
1828
1818
  this.textureCoords = undefined;
1829
- this.props.height = value;
1819
+ this.props.h = value;
1830
1820
  this.setUpdateType(UpdateType.Local);
1831
1821
 
1832
1822
  if (this.props.rtt === true) {
1833
- this.framebufferDimensions!.height = value;
1823
+ this.framebufferDimensions!.h = value;
1834
1824
  this.texture = this.stage.txManager.createTexture(
1835
1825
  'RenderTexture',
1836
1826
  this.framebufferDimensions!,
@@ -2230,8 +2220,8 @@ export class CoreNode extends EventEmitter {
2230
2220
  }
2231
2221
  private initRenderTexture() {
2232
2222
  this.framebufferDimensions = {
2233
- width: this.width,
2234
- height: this.height,
2223
+ w: this.props.w,
2224
+ h: this.props.h,
2235
2225
  };
2236
2226
  this.texture = this.stage.txManager.createTexture(
2237
2227
  'RenderTexture',
@@ -2327,8 +2317,8 @@ export class CoreNode extends EventEmitter {
2327
2317
 
2328
2318
  this.texture = this.stage.txManager.createTexture('ImageTexture', {
2329
2319
  src: imageUrl,
2330
- width: this.props.width,
2331
- height: this.props.height,
2320
+ w: this.props.w,
2321
+ h: this.props.h,
2332
2322
  type: this.props.imageType,
2333
2323
  sx: this.props.srcX,
2334
2324
  sy: this.props.srcY,
@@ -95,15 +95,15 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
95
95
  }
96
96
 
97
97
  // ignore 1x1 pixel textures
98
- if (dimensions.width > 1 && dimensions.height > 1) {
98
+ if (dimensions.w > 1 && dimensions.h > 1) {
99
99
  this.emit('loaded', {
100
100
  type: 'texture',
101
101
  dimensions,
102
102
  } satisfies NodeTextureLoadedPayload);
103
103
  }
104
104
 
105
- this.width = this._renderInfo.width;
106
- this.height = this._renderInfo.height;
105
+ this.w = this._renderInfo.width;
106
+ this.h = this._renderInfo.height;
107
107
 
108
108
  // Texture was loaded. In case the RAF loop has already stopped, we request
109
109
  // a render to ensure the texture is rendered.
@@ -202,8 +202,8 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
202
202
  if (textRendererType === 'sdf') {
203
203
  this._cachedLayout = result.layout || null;
204
204
  this.setRenderable(true);
205
- this.props.width = width;
206
- this.props.height = height;
205
+ this.props.w = width;
206
+ this.props.h = height;
207
207
  this.setUpdateType(UpdateType.Local);
208
208
  }
209
209
 
@@ -211,8 +211,8 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
211
211
  this.emit('loaded', {
212
212
  type: 'text',
213
213
  dimensions: {
214
- width: width,
215
- height: height,
214
+ w: width,
215
+ h: height,
216
216
  },
217
217
  } satisfies NodeTextLoadedPayload);
218
218
  }
@@ -255,8 +255,8 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps {
255
255
  worldAlpha: this.worldAlpha,
256
256
  globalTransform: this.globalTransform!.getFloatArr(),
257
257
  clippingRect: this.clippingRect,
258
- width: this.props.width,
259
- height: this.props.height,
258
+ width: this.props.w,
259
+ height: this.props.h,
260
260
  parentHasRenderTexture: this.parentHasRenderTexture,
261
261
  framebufferDimensions:
262
262
  this.parentHasRenderTexture === true
package/src/core/Stage.ts CHANGED
@@ -321,8 +321,8 @@ export class Stage {
321
321
  const rootNode = new CoreNode(this, {
322
322
  x: 0,
323
323
  y: 0,
324
- width: appWidth,
325
- height: appHeight,
324
+ w: appWidth,
325
+ h: appHeight,
326
326
  alpha: 1,
327
327
  autosize: false,
328
328
  boundsMargin: null,
@@ -807,8 +807,8 @@ export class Stage {
807
807
  return {
808
808
  x: props.x ?? 0,
809
809
  y: props.y ?? 0,
810
- width: props.width ?? 0,
811
- height: props.height ?? 0,
810
+ w: props.w ?? 0,
811
+ h: props.h ?? 0,
812
812
  alpha: props.alpha ?? 1,
813
813
  autosize: props.autosize ?? false,
814
814
  boundsMargin: props.boundsMargin ?? null,
@@ -85,8 +85,8 @@ const loadKTXData = async (buffer: ArrayBuffer): Promise<TextureData> => {
85
85
  data: {
86
86
  glInternalFormat: data.glInternalFormat,
87
87
  mipmaps,
88
- width: data.pixelWidth || 0,
89
- height: data.pixelHeight || 0,
88
+ w: data.pixelWidth || 0,
89
+ h: data.pixelHeight || 0,
90
90
  type: 'ktx',
91
91
  },
92
92
  premultiplyAlpha: false,
@@ -143,8 +143,8 @@ const loadPVRData = async (buffer: ArrayBuffer): Promise<TextureData> => {
143
143
  data: {
144
144
  glInternalFormat: pvrFormatEtc1,
145
145
  mipmaps: mipmaps,
146
- width: data.pixelWidth || 0,
147
- height: data.pixelHeight || 0,
146
+ w: data.pixelWidth || 0,
147
+ h: data.pixelHeight || 0,
148
148
  type: 'pvr',
149
149
  },
150
150
  premultiplyAlpha: false,
@@ -155,8 +155,8 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
155
155
  for (const key in this.resolvedProps) {
156
156
  valueKey += `${key}:${this.resolvedProps[key]!};`;
157
157
  }
158
- valueKey += `node-width:${this.node!.width}`;
159
- valueKey += `node-height:${this.node!.height}`;
158
+ valueKey += `node-width:${this.node!.w}`;
159
+ valueKey += `node-height:${this.node!.h}`;
160
160
  return valueKey;
161
161
  }
162
162
 
@@ -168,8 +168,8 @@ export class CanvasRenderer extends CoreRenderer {
168
168
  image,
169
169
  (quad.texture as SubTexture).props.x,
170
170
  (quad.texture as SubTexture).props.y,
171
- (quad.texture as SubTexture).props.width,
172
- (quad.texture as SubTexture).props.height,
171
+ (quad.texture as SubTexture).props.w,
172
+ (quad.texture as SubTexture).props.h,
173
173
  quad.tx,
174
174
  quad.ty,
175
175
  quad.width,
@@ -65,8 +65,8 @@ export class CanvasTexture extends CoreContextTexture {
65
65
  const mult = this.tintCache ? 8 : 4;
66
66
  if (this.textureSource.dimensions) {
67
67
  this.setTextureMemUse(
68
- this.textureSource.dimensions.width *
69
- this.textureSource.dimensions.height *
68
+ this.textureSource.dimensions.w *
69
+ this.textureSource.dimensions.h *
70
70
  mult,
71
71
  );
72
72
  }
@@ -142,15 +142,15 @@ export class CanvasTexture extends CoreContextTexture {
142
142
  const ctx = canvas.getContext('2d');
143
143
  if (ctx) ctx.putImageData(data, 0, 0);
144
144
  this.image = canvas;
145
- return { width: data.width, height: data.height };
145
+ return { w: data.width, h: data.height };
146
146
  } else if (
147
147
  (typeof ImageBitmap !== 'undefined' && data instanceof ImageBitmap) ||
148
148
  data instanceof HTMLImageElement
149
149
  ) {
150
150
  this.image = data;
151
- return { width: data.width, height: data.height };
151
+ return { w: data.width, h: data.height };
152
152
  }
153
153
 
154
- return { width: 0, height: 0 };
154
+ return { w: 0, h: 0 };
155
155
  }
156
156
  }
@@ -18,7 +18,6 @@
18
18
  */
19
19
 
20
20
  import type { Dimensions } from '../../../common/CommonTypes.js';
21
- import { assertTruthy } from '../../../utils.js';
22
21
  import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
23
22
  import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
24
23
  import type { RenderTexture } from '../../textures/RenderTexture.js';
@@ -46,25 +45,16 @@ export class WebGlCtxRenderTexture extends WebGlCtxTexture {
46
45
  throw new Error('Failed to create native texture for RenderTexture');
47
46
  }
48
47
 
49
- const { width, height } = this.textureSource;
48
+ const { w, h } = this.textureSource;
50
49
 
51
50
  // Create Framebuffer object
52
51
  this.framebuffer = glw.createFramebuffer();
53
52
 
54
53
  // Set the dimensions of the render texture
55
- glw.texImage2D(
56
- 0,
57
- glw.RGBA,
58
- width,
59
- height,
60
- 0,
61
- glw.RGBA,
62
- glw.UNSIGNED_BYTE,
63
- null,
64
- );
54
+ glw.texImage2D(0, glw.RGBA, w, h, 0, glw.RGBA, glw.UNSIGNED_BYTE, null);
65
55
 
66
56
  // Update the texture memory manager
67
- this.setTextureMemUse(width * height * 4);
57
+ this.setTextureMemUse(w * h * 4);
68
58
 
69
59
  // Bind the framebuffer
70
60
  glw.bindFramebuffer(this.framebuffer);
@@ -76,8 +66,8 @@ export class WebGlCtxRenderTexture extends WebGlCtxTexture {
76
66
  glw.bindFramebuffer(null);
77
67
 
78
68
  return {
79
- width,
80
- height,
69
+ w,
70
+ h,
81
71
  };
82
72
  }
83
73
 
@@ -22,6 +22,8 @@ import { assertTruthy } from '../../../utils.js';
22
22
  import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
23
23
  import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
24
24
  import type { SubTexture } from '../../textures/SubTexture.js';
25
+ import type { SubTextureProps } from '../../textures/SubTexture.js';
26
+ import type { CompressedData } from '../../textures/Texture.js';
25
27
  import { WebGlCtxTexture } from './WebGlCtxTexture.js';
26
28
 
27
29
  export class WebGlCtxSubTexture extends WebGlCtxTexture {
@@ -39,12 +41,55 @@ export class WebGlCtxSubTexture extends WebGlCtxTexture {
39
41
 
40
42
  if (props.data instanceof Uint8Array) {
41
43
  // its a 1x1 Color Texture
42
- return { width: 1, height: 1 };
44
+ return { w: 1, h: 1 };
43
45
  }
44
46
 
45
- return {
46
- width: props.data?.width || 0,
47
- height: props.data?.height || 0,
48
- };
47
+ return this.extractDimensions(props.data);
48
+ }
49
+
50
+ /**
51
+ * Efficiently extracts width/height from polymorphic texture data
52
+ * Optimized for performance by using type guards and avoiding unnecessary property access
53
+ */
54
+ private extractDimensions(
55
+ data:
56
+ | ImageBitmap
57
+ | ImageData
58
+ | SubTextureProps
59
+ | CompressedData
60
+ | HTMLImageElement
61
+ | null,
62
+ ): Dimensions {
63
+ if (data === null) {
64
+ return { w: 0, h: 0 };
65
+ }
66
+
67
+ // Check for standard web API objects first (most common case)
68
+ // These use width/height properties: ImageBitmap, ImageData, HTMLImageElement
69
+ if (this.hasWidthHeight(data) === true) {
70
+ return { w: data.width, h: data.height };
71
+ }
72
+
73
+ // Check for internal objects that use w/h properties: SubTextureProps, CompressedData
74
+ if (this.hasWH(data) === true) {
75
+ return { w: data.w, h: data.h };
76
+ }
77
+
78
+ // Fallback
79
+ return { w: 0, h: 0 };
80
+ }
81
+
82
+ /**
83
+ * Type guard for objects with width/height properties
84
+ */
85
+ private hasWidthHeight(data: any): data is { width: number; height: number } {
86
+ return typeof data.width === 'number' && typeof data.height === 'number';
87
+ }
88
+
89
+ /**
90
+ * Type guard for objects with w/h properties
91
+ */
92
+ private hasWH(data: any): data is { w: number; h: number } {
93
+ return typeof data.w === 'number' && typeof data.h === 'number';
49
94
  }
50
95
  }