@solidtv/solid 1.0.3 → 1.1.1

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 (93) hide show
  1. package/dist/jsx-runtime.d.ts +0 -1
  2. package/dist/src/core/config.js.map +1 -1
  3. package/dist/src/core/dom-renderer/domRenderer.js +38 -36
  4. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  5. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +1 -0
  6. package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
  7. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
  8. package/dist/src/core/elementNode.d.ts +35 -17
  9. package/dist/src/core/elementNode.js +184 -56
  10. package/dist/src/core/elementNode.js.map +1 -1
  11. package/dist/src/core/flex.js +1 -1
  12. package/dist/src/core/flex.js.map +1 -1
  13. package/dist/src/core/flexLayout.js +5 -9
  14. package/dist/src/core/flexLayout.js.map +1 -1
  15. package/dist/src/core/focusManager.js.map +1 -1
  16. package/dist/src/core/intrinsicTypes.d.ts +2 -7
  17. package/dist/src/core/nodeTypes.d.ts +7 -0
  18. package/dist/src/core/nodeTypes.js +8 -0
  19. package/dist/src/core/nodeTypes.js.map +1 -1
  20. package/dist/src/core/shaders.js +1 -1
  21. package/dist/src/core/shaders.js.map +1 -1
  22. package/dist/src/core/states.js.map +1 -1
  23. package/dist/src/core/utils.d.ts +2 -1
  24. package/dist/src/core/utils.js +2 -1
  25. package/dist/src/core/utils.js.map +1 -1
  26. package/dist/src/devtools/hexColorTransform.d.ts +6 -0
  27. package/dist/src/devtools/hexColorTransform.js +42 -0
  28. package/dist/src/devtools/hexColorTransform.js.map +1 -0
  29. package/dist/src/devtools/index.d.ts +2 -0
  30. package/dist/src/devtools/index.js +3 -2
  31. package/dist/src/devtools/index.js.map +1 -1
  32. package/dist/src/primitives/Grid.jsx.map +1 -1
  33. package/dist/src/primitives/Image.jsx.map +1 -1
  34. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  35. package/dist/src/primitives/Lazy.d.ts +16 -0
  36. package/dist/src/primitives/Lazy.jsx +82 -38
  37. package/dist/src/primitives/Lazy.jsx.map +1 -1
  38. package/dist/src/primitives/LazyImport.js +14 -11
  39. package/dist/src/primitives/LazyImport.js.map +1 -1
  40. package/dist/src/primitives/Marquee.jsx +3 -3
  41. package/dist/src/primitives/Marquee.jsx.map +1 -1
  42. package/dist/src/primitives/Preserve.jsx +1 -1
  43. package/dist/src/primitives/Preserve.jsx.map +1 -1
  44. package/dist/src/primitives/Suspense.jsx +1 -1
  45. package/dist/src/primitives/Suspense.jsx.map +1 -1
  46. package/dist/src/primitives/Virtual.jsx +6 -5
  47. package/dist/src/primitives/Virtual.jsx.map +1 -1
  48. package/dist/src/primitives/borderBox.jsx.map +1 -1
  49. package/dist/src/primitives/index.d.ts +0 -2
  50. package/dist/src/primitives/index.js +0 -2
  51. package/dist/src/primitives/index.js.map +1 -1
  52. package/dist/src/primitives/routerIndex.d.ts +2 -0
  53. package/dist/src/primitives/routerIndex.js +3 -0
  54. package/dist/src/primitives/routerIndex.js.map +1 -0
  55. package/dist/src/primitives/useMouse.js +72 -82
  56. package/dist/src/primitives/useMouse.js.map +1 -1
  57. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
  58. package/dist/src/solidOpts.d.ts +1 -1
  59. package/dist/src/solidOpts.js +4 -14
  60. package/dist/src/solidOpts.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/jsx-runtime.d.ts +0 -1
  63. package/package.json +11 -3
  64. package/src/core/config.ts +2 -0
  65. package/src/core/dom-renderer/domRenderer.ts +48 -46
  66. package/src/core/dom-renderer/domRendererTypes.ts +1 -0
  67. package/src/core/dom-renderer/domRendererUtils.ts +2 -2
  68. package/src/core/elementNode.ts +213 -74
  69. package/src/core/flex.ts +3 -3
  70. package/src/core/flexLayout.ts +7 -11
  71. package/src/core/focusManager.ts +1 -1
  72. package/src/core/intrinsicTypes.ts +3 -7
  73. package/src/core/nodeTypes.ts +12 -0
  74. package/src/core/shaders.ts +1 -1
  75. package/src/core/states.ts +2 -2
  76. package/src/core/utils.ts +4 -3
  77. package/src/devtools/hexColorTransform.ts +56 -0
  78. package/src/devtools/index.ts +5 -2
  79. package/src/primitives/Grid.tsx +1 -1
  80. package/src/primitives/Image.tsx +1 -1
  81. package/src/primitives/KeepAlive.tsx +2 -2
  82. package/src/primitives/Lazy.tsx +106 -37
  83. package/src/primitives/LazyImport.ts +5 -4
  84. package/src/primitives/Marquee.tsx +3 -3
  85. package/src/primitives/Preserve.tsx +1 -1
  86. package/src/primitives/Suspense.tsx +1 -1
  87. package/src/primitives/Virtual.tsx +8 -7
  88. package/src/primitives/borderBox.tsx +1 -1
  89. package/src/primitives/index.ts +0 -2
  90. package/src/primitives/routerIndex.ts +2 -0
  91. package/src/primitives/useMouse.ts +97 -128
  92. package/src/primitives/utils/createSpriteMap.ts +1 -1
  93. package/src/solidOpts.ts +6 -17
@@ -8,7 +8,6 @@ import {
8
8
  type Styles,
9
9
  AddColorString,
10
10
  TextProps,
11
- TextNode,
12
11
  type OnEvent,
13
12
  NewOmit,
14
13
  SingleBorderStyle,
@@ -47,7 +46,7 @@ import type {
47
46
  INodeProps,
48
47
  } from '@solidtv/renderer';
49
48
  import { assertTruthy } from '@solidtv/renderer/utils';
50
- import { NodeType } from './nodeTypes.js';
49
+ import { NodeType, TextNode } from './nodeTypes.js';
51
50
  import {
52
51
  ForwardFocusHandler,
53
52
  setActiveElement,
@@ -63,27 +62,45 @@ import {
63
62
  IRendererTextNodeProps,
64
63
  } from './dom-renderer/domRendererTypes.js';
65
64
 
65
+ // Unified post-mutation scheduler.
66
+ //
67
+ // Three phases run in one microtask (or one renderer-tick callback):
68
+ // 1. delete-flush — destroy nodes that were removed and not re-inserted
69
+ // 2. layout — recompute flex layout for any dirty subtree
70
+ // 3. focus — resolve forwardFocus on deferred elements, then apply
71
+ //
72
+ // Order matters: layout reads the rendered tree (so destroyed nodes must be
73
+ // gone), and focus reads the laid-out tree.
74
+ let postMutationQueued = false;
66
75
  let nextActiveElement: ElementNode | null = null;
67
- let focusQueued: boolean = false;
68
- let layoutRunQueued = false;
76
+ let deferredFocusElement: ElementNode | null = null;
69
77
  const layoutQueue = new Set<ElementNode>();
78
+ export const elementDeleteQueue: ElementNode[] = [];
70
79
 
71
- function addToLayoutQueue(node: ElementNode) {
72
- layoutQueue.add(node);
73
- if (!layoutRunQueued) {
74
- layoutRunQueued = true;
75
- if (
76
- 'reprocessUpdates' in renderer.stage &&
77
- renderer.stage.reprocessUpdates
78
- ) {
79
- renderer.stage.reprocessUpdates(runLayout);
80
- } else {
81
- queueMicrotask(runLayout);
82
- }
80
+ export function schedulePostMutation() {
81
+ if (postMutationQueued) return;
82
+ postMutationQueued = true;
83
+ if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) {
84
+ renderer.stage.reprocessUpdates(runPostMutation);
83
85
  }
86
+ queueMicrotask(runPostMutation);
84
87
  }
85
88
 
86
- function runLayout() {
89
+ function runPostMutation() {
90
+ postMutationQueued = false;
91
+
92
+ // Phase 1: delete-flush
93
+ if (elementDeleteQueue.length > 0) {
94
+ for (const el of elementDeleteQueue) {
95
+ if (Number(el._queueDelete) < 0) {
96
+ el.destroy();
97
+ }
98
+ el._queueDelete = undefined;
99
+ }
100
+ elementDeleteQueue.length = 0;
101
+ }
102
+
103
+ // Phase 2: layout
87
104
  while (layoutQueue.size > 0) {
88
105
  const queue = [...layoutQueue];
89
106
  layoutQueue.clear();
@@ -92,7 +109,45 @@ function runLayout() {
92
109
  node.updateLayout();
93
110
  }
94
111
  }
95
- layoutRunQueued = false;
112
+
113
+ // Phase 3: focus. setFocus() may have evaluated forwardFocus pre-render
114
+ // (when no children existed yet); deferredFocusElement re-runs setFocus
115
+ // here once the subtree has rendered, then setActiveElement is applied.
116
+ if (deferredFocusElement !== null) {
117
+ const el = deferredFocusElement;
118
+ deferredFocusElement = null;
119
+ el.setFocus();
120
+ } else if (nextActiveElement !== null) {
121
+ const element = nextActiveElement;
122
+ nextActiveElement = null;
123
+ setActiveElement(element);
124
+ }
125
+ }
126
+
127
+ function addToLayoutQueue(node: ElementNode) {
128
+ layoutQueue.add(node);
129
+ schedulePostMutation();
130
+ }
131
+
132
+ // Text-default template, built once on first use. Config.fontSettings is
133
+ // expected to be set at app startup and not change afterwards.
134
+ let _fontTemplate: Array<[string, any]> | undefined;
135
+ let _fontFamilyIdx = -1;
136
+ let _fontFamilyWithWeight: string | undefined;
137
+
138
+ function buildFontTemplate() {
139
+ const tpl: Array<[string, any]> = [];
140
+ const fs = Config.fontSettings;
141
+ if (fs) {
142
+ for (const key in fs) {
143
+ if (key === 'fontFamily') {
144
+ _fontFamilyIdx = tpl.length;
145
+ _fontFamilyWithWeight = `${fs.fontFamily}${fs.fontWeight || ''}`;
146
+ }
147
+ tpl.push([key, (fs as any)[key]]);
148
+ }
149
+ }
150
+ _fontTemplate = tpl;
96
151
  }
97
152
 
98
153
  const parseAndAssignShaderProps = (
@@ -262,7 +317,20 @@ export interface ElementNode extends RendererNode, FocusNode {
262
317
  _lastAnyKeyPressTime?: number;
263
318
  _type: 'element' | 'textNode';
264
319
  _undoStyles?: string[];
320
+ _display?: 'flex' | 'block';
321
+ _onLayout?: (this: ElementNode, target: ElementNode) => void;
322
+ _requiresLayout: boolean;
265
323
  autosize?: boolean;
324
+ /**
325
+ * Optional component name for inspector / dev tooling — emitted by the
326
+ * Babel devtools plugin (see `devtools/jsx-locator.js`).
327
+ */
328
+ componentName?: string;
329
+ /**
330
+ * Optional source-location string for inspector / dev tooling — emitted by
331
+ * the Babel devtools plugin.
332
+ */
333
+ componentLocation?: string;
266
334
  /**
267
335
  * The distance from the bottom edge of the parent element.
268
336
  * When `bottom` is set, `mountY` is automatically set to 1.
@@ -439,13 +507,6 @@ export interface ElementNode extends RendererNode, FocusNode {
439
507
  * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
440
508
  */
441
509
  direction?: 'ltr' | 'rtl';
442
- /**
443
- * Specifies the display behavior of an element. 'flex' enables flexbox layout.
444
- *
445
- * @default 'block'
446
- * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
447
- */
448
- display?: 'flex' | 'block';
449
510
  /**
450
511
  * Defines how the flex container's size is determined. 'contain' allows it to grow with its content, 'fixed' keeps it at its specified size.
451
512
  *
@@ -658,13 +719,6 @@ export interface ElementNode extends RendererNode, FocusNode {
658
719
  */
659
720
  onEvent?: OnEvent;
660
721
 
661
- /**
662
- * Callback run after flex layout is calculated on flex elements
663
- *
664
- * @see https://lightning-tv.github.io/solid/#/flow/layout
665
- */
666
- onLayout?: (this: ElementNode, target: ElementNode) => void;
667
-
668
722
  /**
669
723
  * The individual padding on each side of an element, acting as an override to the `padding` array property.
670
724
  * `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`.
@@ -683,13 +737,51 @@ export interface ElementNode extends RendererNode, FocusNode {
683
737
  stateOrder?: DollarString[];
684
738
  }
685
739
 
686
- export class ElementNode extends Object {
740
+ export class ElementNode {
687
741
  constructor(name: string) {
688
- super();
689
742
  this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
690
743
  this.rendered = false;
691
- this.lng = {};
744
+ // initialize lng with standard properties for v8 optimization
745
+ this.lng = {
746
+ w: undefined,
747
+ h: undefined,
748
+ x: undefined,
749
+ y: undefined,
750
+ alpha: undefined,
751
+ color: undefined,
752
+ shader: undefined,
753
+ clipping: undefined,
754
+ text: undefined,
755
+ };
692
756
  this.children = [];
757
+
758
+ // Initialize lazy underscore fields explicitly in a fixed order. This
759
+ // gives every ElementNode the same hidden class on construction; later
760
+ // assignments transition predictably instead of forking shapes by
761
+ // first-touch order.
762
+ this._queueDelete = undefined;
763
+ this._animationQueue = undefined;
764
+ this._animationQueueSettings = undefined;
765
+ this._animationRunning = undefined;
766
+ this._animationSettings = undefined;
767
+ this._autofocus = undefined;
768
+ this._calcWidth = undefined;
769
+ this._calcHeight = undefined;
770
+ this._containsFlexGrow = undefined;
771
+ this._hasRenderedChildren = undefined;
772
+ this._effects = undefined;
773
+ this._fontFamily = undefined;
774
+ this._fontWeight = undefined;
775
+ this._id = undefined;
776
+ this._parent = undefined;
777
+ this._states = undefined;
778
+ this._style = undefined;
779
+ this._theme = undefined;
780
+ this._lastAnyKeyPressTime = undefined;
781
+ this._undoStyles = undefined;
782
+ this._display = undefined;
783
+ this._onLayout = undefined;
784
+ this._requiresLayout = false;
693
785
  }
694
786
 
695
787
  get effects(): StyleEffects | undefined {
@@ -719,7 +811,8 @@ export class ElementNode extends Object {
719
811
  if (!this.lng.shader) {
720
812
  this.lng.shader = Config.convertToShader(this, target);
721
813
  } else if (DOM_RENDERING && Config.domRendererEnabled) {
722
- this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
814
+ // eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
815
+ this.lng.shader = this.lng.shader;
723
816
  }
724
817
  } else {
725
818
  this.lng.shader = target;
@@ -826,7 +919,10 @@ export class ElementNode extends Object {
826
919
 
827
920
  removeChild(node: ElementNode | ElementText | TextNode) {
828
921
  if (spliceItem(this.children, node, 1) > -1) {
829
- node.onRemove?.call(node, node);
922
+ if (isElementNode(node) && node.onRemove) {
923
+ node.onRemove.call(node, node);
924
+ }
925
+
830
926
  if (this.requiresLayout()) {
831
927
  addToLayoutQueue(this);
832
928
  }
@@ -857,8 +953,8 @@ export class ElementNode extends Object {
857
953
 
858
954
  _sendToLightningAnimatable(name: string, value: number) {
859
955
  if (
860
- this.transition &&
861
956
  this.rendered &&
957
+ this.transition &&
862
958
  Config.animationsEnabled &&
863
959
  (this.transition === true ||
864
960
  this.transition[name] ||
@@ -872,6 +968,16 @@ export class ElementNode extends Object {
872
968
  | undefined
873
969
  | AnimationSettings);
874
970
 
971
+ // If the renderer doesn't support animateProp,
972
+ // keep backwards compatible with LightningRenderer
973
+ if (!('animateProp' in this.lng)) {
974
+ const animationController = this.animate(
975
+ { [name]: value },
976
+ animationSettings,
977
+ );
978
+ return animationController.start();
979
+ }
980
+
875
981
  return (this.lng as any).animateProp(
876
982
  name,
877
983
  value,
@@ -964,19 +1070,10 @@ export class ElementNode extends Object {
964
1070
  }
965
1071
  }
966
1072
  }
967
- // Delay setting focus so children can render (useful for Row + Column)
1073
+ // Delay setting focus so children can render (useful for Row + Column).
1074
+ // The post-mutation scheduler applies setActiveElement in its focus phase.
968
1075
  nextActiveElement = this;
969
- if (focusQueued === false) {
970
- focusQueued = true;
971
- queueMicrotask(() => {
972
- focusQueued = false;
973
- if (nextActiveElement) {
974
- const element = nextActiveElement;
975
- nextActiveElement = null;
976
- setActiveElement(element);
977
- }
978
- });
979
- }
1076
+ schedulePostMutation();
980
1077
  } else {
981
1078
  this._autofocus = true;
982
1079
  }
@@ -984,19 +1081,17 @@ export class ElementNode extends Object {
984
1081
 
985
1082
  _layoutOnLoad() {
986
1083
  (this.lng as IRendererNode).on('loaded', () => {
987
- if (
988
- 'reprocessUpdates' in renderer.stage &&
989
- renderer.stage.reprocessUpdates
990
- ) {
991
- renderer.stage.reprocessUpdates(runLayout);
992
- }
1084
+ schedulePostMutation();
993
1085
  this.parent!.updateLayout();
994
1086
  });
995
1087
  }
996
1088
 
997
1089
  getText(this: ElementText) {
1090
+ const len = this.children.length;
1091
+ if (len === 1) return this.children[0]!.text;
1092
+ if (len === 0) return '';
998
1093
  let result = '';
999
- for (let i = 0; i < this.children.length; i++) {
1094
+ for (let i = 0; i < len; i++) {
1000
1095
  result += this.children[i]!.text;
1001
1096
  }
1002
1097
  return result;
@@ -1150,17 +1245,53 @@ export class ElementNode extends Object {
1150
1245
  */
1151
1246
  set autofocus(val: any) {
1152
1247
  this._autofocus = val;
1153
- // Delay setting focus so children can render (useful for Row + Column)
1154
- // which now uses forwardFocus
1155
- val && queueMicrotask(() => this.setFocus());
1248
+ // Defer setFocus so children render first (forwardFocus needs them).
1249
+ // The post-mutation focus phase calls setFocus on this element.
1250
+ if (val) {
1251
+ deferredFocusElement = this;
1252
+ schedulePostMutation();
1253
+ }
1156
1254
  }
1157
1255
 
1158
1256
  get autofocus() {
1159
1257
  return this._autofocus;
1160
1258
  }
1161
1259
 
1260
+ /**
1261
+ * Specifies the display behavior of an element. 'flex' enables flexbox layout.
1262
+ *
1263
+ * @default 'block'
1264
+ * @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
1265
+ */
1266
+ get display(): 'flex' | 'block' | undefined {
1267
+ return this._display;
1268
+ }
1269
+
1270
+ set display(v: 'flex' | 'block' | undefined) {
1271
+ this._display = v;
1272
+ this._requiresLayout = v === 'flex' || this._onLayout !== undefined;
1273
+ }
1274
+
1275
+ /**
1276
+ * Callback run after flex layout is calculated on flex elements.
1277
+ *
1278
+ * @see https://lightning-tv.github.io/solid/#/flow/layout
1279
+ */
1280
+ get onLayout():
1281
+ | ((this: ElementNode, target: ElementNode) => void)
1282
+ | undefined {
1283
+ return this._onLayout;
1284
+ }
1285
+
1286
+ set onLayout(
1287
+ fn: ((this: ElementNode, target: ElementNode) => void) | undefined,
1288
+ ) {
1289
+ this._onLayout = fn;
1290
+ this._requiresLayout = this._display === 'flex' || fn !== undefined;
1291
+ }
1292
+
1162
1293
  requiresLayout() {
1163
- return this.display === 'flex' || this.onLayout;
1294
+ return this._requiresLayout;
1164
1295
  }
1165
1296
 
1166
1297
  set updateLayoutOn(v: any) {
@@ -1351,14 +1482,22 @@ export class ElementNode extends Object {
1351
1482
 
1352
1483
  if (isElementText(node)) {
1353
1484
  const textProps = props as TextProps;
1354
- if (Config.fontSettings) {
1355
- for (const key in Config.fontSettings) {
1485
+ if (_fontTemplate === undefined) buildFontTemplate();
1486
+ const tpl = _fontTemplate!;
1487
+ if (tpl.length > 0) {
1488
+ const familyIdx = _fontFamilyIdx;
1489
+ const familyWithWeight =
1490
+ textProps['fontWeight'] === undefined
1491
+ ? _fontFamilyWithWeight
1492
+ : undefined;
1493
+ for (let i = 0; i < tpl.length; i++) {
1494
+ const entry = tpl[i]!;
1495
+ const key = entry[0];
1356
1496
  if (textProps[key] === undefined) {
1357
- let value = Config.fontSettings[key];
1358
- if (key === 'fontFamily' && textProps['fontWeight'] === undefined) {
1359
- value = `${value}${Config.fontSettings.fontWeight || ''}`;
1360
- }
1361
- textProps[key] = value;
1497
+ textProps[key] =
1498
+ i === familyIdx && familyWithWeight !== undefined
1499
+ ? familyWithWeight
1500
+ : entry[1];
1362
1501
  }
1363
1502
  }
1364
1503
  }
@@ -1496,11 +1635,10 @@ export class ElementNode extends Object {
1496
1635
  }
1497
1636
  }
1498
1637
  }
1499
- if (topNode && !layoutRunQueued) {
1500
- //Do one pass of layout, then another with Text loads
1501
- layoutRunQueued = true;
1502
- // We use queue because <For> loop will add children one at a time, causing lots of layout
1503
- queueMicrotask(runLayout);
1638
+ if (topNode) {
1639
+ // Schedule one post-mutation pass; <For> may add many children in one
1640
+ // tick, but the scheduler dedupes and runs everything once.
1641
+ schedulePostMutation();
1504
1642
  }
1505
1643
 
1506
1644
  node._autofocus && node.setFocus();
@@ -1586,7 +1724,8 @@ export function shaderAccessor<T extends Record<string, any> | number>(
1586
1724
  if (!this.lng.shader) {
1587
1725
  this.lng.shader = Config.convertToShader(this, target);
1588
1726
  } else if (DOM_RENDERING && Config.domRendererEnabled) {
1589
- this.lng.shader = this.lng.shader; // lng.shader is a setter, force style update
1727
+ // eslint-disable-next-line no-self-assign -- lng.shader is a setter, force style update
1728
+ this.lng.shader = this.lng.shader;
1590
1729
  }
1591
1730
  } else {
1592
1731
  this.lng.shader = target;
package/src/core/flex.ts CHANGED
@@ -22,7 +22,7 @@ export default function (node: ElementNode): boolean {
22
22
  return false;
23
23
  }
24
24
 
25
- let processableChildrenIndices: number[] = [];
25
+ const processableChildrenIndices: number[] = [];
26
26
  let hasOrder = false;
27
27
  let totalFlexGrow = 0;
28
28
 
@@ -46,13 +46,13 @@ export default function (node: ElementNode): boolean {
46
46
  totalFlexGrow += flexGrow;
47
47
  }
48
48
 
49
- if (c[minDimension] && (c[dimension] || 0) < c[minDimension]!) {
49
+ if (c[minDimension] && (c[dimension] || 0) < c[minDimension]) {
50
50
  c[dimension] = c[minDimension]!;
51
51
  }
52
52
 
53
53
  if (
54
54
  c[crossMinDimension] &&
55
- (c[crossDimension] || 0) < c[crossMinDimension]!
55
+ (c[crossDimension] || 0) < c[crossMinDimension]
56
56
  ) {
57
57
  c[crossDimension] = c[crossMinDimension]!;
58
58
  }
@@ -31,14 +31,10 @@ export default function (node: ElementNode): boolean {
31
31
 
32
32
  // padding order: Top, Right, Bottom, Left
33
33
  const nodePadding = node.padding;
34
- const paddingTop = (node.paddingTop ??
35
- getArrayValue(nodePadding, 0)) as number;
36
- const paddingRight = (node.paddingRight ??
37
- getArrayValue(nodePadding, 1)) as number;
38
- const paddingBottom = (node.paddingBottom ??
39
- getArrayValue(nodePadding, 2)) as number;
40
- const paddingLeft = (node.paddingLeft ??
41
- getArrayValue(nodePadding, 3)) as number;
34
+ const paddingTop = node.paddingTop ?? getArrayValue(nodePadding, 0);
35
+ const paddingRight = node.paddingRight ?? getArrayValue(nodePadding, 1);
36
+ const paddingBottom = node.paddingBottom ?? getArrayValue(nodePadding, 2);
37
+ const paddingLeft = node.paddingLeft ?? getArrayValue(nodePadding, 3);
42
38
 
43
39
  const paddingStart = isRow ? paddingLeft : paddingTop;
44
40
  const paddingEnd = isRow ? paddingRight : paddingBottom;
@@ -57,7 +53,7 @@ export default function (node: ElementNode): boolean {
57
53
  }
58
54
 
59
55
  // Optimize arrays caching
60
- let processableChildrenIndices: number[] = [];
56
+ const processableChildrenIndices: number[] = [];
61
57
  let hasOrder = false;
62
58
  let totalFlexGrow = 0;
63
59
  let totalFlexShrink = 0;
@@ -87,13 +83,13 @@ export default function (node: ElementNode): boolean {
87
83
  totalFlexShrink += flexShrink;
88
84
  }
89
85
 
90
- if (c[minDimension] && (c[dimension] || 0) < c[minDimension]!) {
86
+ if (c[minDimension] && (c[dimension] || 0) < c[minDimension]) {
91
87
  c[dimension] = c[minDimension]!;
92
88
  }
93
89
 
94
90
  if (
95
91
  c[crossMinDimension] &&
96
- (c[crossDimension] || 0) < c[crossMinDimension]!
92
+ (c[crossDimension] || 0) < c[crossMinDimension]
97
93
  ) {
98
94
  c[crossDimension] = c[crossMinDimension]!;
99
95
  }
@@ -296,7 +296,7 @@ const propagateKeyPress = (
296
296
 
297
297
  let handlerAvailable: ElementNode | undefined;
298
298
  const finalFocusElm = focusPath[0]!;
299
- const keyBase = mappedEvent || (e.key as string);
299
+ const keyBase = mappedEvent || e.key;
300
300
  const captureEvent = `onCapture${keyBase}${isUp ? 'Release' : ''}`;
301
301
  const captureKey = isUp ? 'onCaptureKeyRelease' : 'onCaptureKey';
302
302
 
@@ -1,5 +1,6 @@
1
1
  import * as lngr from '@solidtv/renderer';
2
2
  import { ElementNode, type RendererNode } from './elementNode.js';
3
+ import type { TextNode } from './nodeTypes.js';
3
4
  import { NodeStates } from './states.js';
4
5
  import {
5
6
  ShaderBorderProps,
@@ -115,13 +116,6 @@ export interface ElementText
115
116
  style: TextStyles;
116
117
  }
117
118
 
118
- export interface TextNode {
119
- _type: 'text';
120
- parent?: ElementText;
121
- text: string;
122
- [key: string]: any;
123
- }
124
-
125
119
  export interface NodeProps
126
120
  extends RendererNode,
127
121
  EventHandlers<DefaultKeyMap>,
@@ -140,6 +134,8 @@ export interface NodeProps
140
134
  | 'preFlexheight'
141
135
  | 'width'
142
136
  | 'height'
137
+ | 'componentName'
138
+ | 'componentLocation'
143
139
  >
144
140
  > {
145
141
  states?: NodeStates;
@@ -1,6 +1,18 @@
1
+ import type { ElementText } from './intrinsicTypes.js';
2
+
1
3
  export const NodeType = {
2
4
  Element: 'element',
3
5
  TextNode: 'textNode',
4
6
  Text: 'text',
5
7
  } as const;
6
8
  export type NodeTypes = (typeof NodeType)[keyof typeof NodeType];
9
+
10
+ export class TextNode {
11
+ readonly _type = 'text' as const;
12
+ parent: ElementText | undefined = undefined;
13
+ text: string;
14
+
15
+ constructor(text: string) {
16
+ this.text = text;
17
+ }
18
+ }
@@ -83,7 +83,7 @@ function calcFactoredRadiusArray(
83
83
  out: Vec4 = [0, 0, 0, 0],
84
84
  ): Vec4 {
85
85
  [out[0], out[1], out[2], out[3]] = radius;
86
- let factor = Math.min(
86
+ const factor = Math.min(
87
87
  width / Math.max(width, radius[0] + radius[1]),
88
88
  width / Math.max(width, radius[2] + radius[3]),
89
89
  height / Math.max(height, radius[0] + radius[3]),
@@ -12,7 +12,7 @@ export default class States extends Array<DollarString> {
12
12
  if (isArray(initialState)) {
13
13
  super(...initialState);
14
14
  } else if (isString(initialState)) {
15
- super(initialState as DollarString); // Assert as DollarString
15
+ super(initialState); // Assert as DollarString
16
16
  } else {
17
17
  super(
18
18
  ...Object.entries(initialState)
@@ -62,7 +62,7 @@ export default class States extends Array<DollarString> {
62
62
  this.push(...newStates);
63
63
  } else if (isString(newStates)) {
64
64
  this.length = 0; // Clear the current states
65
- this.push(newStates as DollarString); // Assert as DollarString
65
+ this.push(newStates); // Assert as DollarString
66
66
  } else {
67
67
  for (const state in newStates) {
68
68
  const value = newStates[state as DollarString];
package/src/core/utils.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { type INode, type Point } from '@solidtv/renderer';
2
2
  import { Config, isDev } from './config.js';
3
- import type { Styles, ElementText, TextNode } from './intrinsicTypes.js';
3
+ import type { Styles, ElementText } from './intrinsicTypes.js';
4
4
  import { ElementNode } from './elementNode.js';
5
- import { NodeType } from './nodeTypes.js';
5
+ import { NodeType, TextNode } from './nodeTypes.js';
6
6
 
7
7
  function hasDebug(node: any) {
8
8
  return isObject(node) && node.debug;
@@ -23,6 +23,7 @@ export function log(
23
23
  export const isFunc = (obj: unknown): obj is CallableFunction =>
24
24
  obj instanceof Function;
25
25
 
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
26
27
  export const isFunction = (obj: unknown): obj is Function =>
27
28
  typeof obj === 'function';
28
29
 
@@ -200,7 +201,7 @@ export function getElementScreenRect(
200
201
  }
201
202
 
202
203
  if (Config.rendererOptions != null) {
203
- let dpr = Config.rendererOptions.deviceLogicalPixelRatio;
204
+ const dpr = Config.rendererOptions.deviceLogicalPixelRatio;
204
205
  if (dpr != null) {
205
206
  out.x *= dpr;
206
207
  out.y *= dpr;
@@ -0,0 +1,56 @@
1
+ import { createFilter, type Plugin } from 'vite';
2
+
3
+ export interface HexColorTransformOptions {
4
+ include?: string | string[];
5
+ exclude?: string | string[];
6
+ }
7
+
8
+ export default function hexColorTransform(
9
+ options: HexColorTransformOptions = {},
10
+ ): Plugin {
11
+ const filter = createFilter(options.include, options.exclude);
12
+
13
+ return {
14
+ name: 'vite-plugin-hex-color-transform',
15
+
16
+ transform(code, id) {
17
+ if (!filter(id)) {
18
+ return null;
19
+ }
20
+
21
+ const hexColorRegex =
22
+ /["']#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})["']/g;
23
+
24
+ const convertHexTo0x = (_match: string, p1: string) => {
25
+ let hex = p1;
26
+
27
+ if (hex.length === 3) {
28
+ hex =
29
+ hex
30
+ .split('')
31
+ .map((char) => char + char)
32
+ .join('') + 'FF';
33
+ } else if (hex.length === 4) {
34
+ const alpha = hex[3]! + hex[3]!;
35
+ hex =
36
+ hex
37
+ .slice(0, 3)
38
+ .split('')
39
+ .map((char) => char + char)
40
+ .join('') + alpha;
41
+ } else if (hex.length === 6) {
42
+ hex += 'FF';
43
+ }
44
+
45
+ return `0x${hex.toUpperCase()}`;
46
+ };
47
+
48
+ const transformedCode = code.replace(hexColorRegex, convertHexTo0x);
49
+
50
+ return {
51
+ code: transformedCode,
52
+ map: null,
53
+ };
54
+ },
55
+ };
56
+ }