@solidtv/solid 1.1.1 → 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 (99) 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/Column.jsx +1 -1
  22. package/dist/src/primitives/Column.jsx.map +1 -1
  23. package/dist/src/primitives/FPSCounter.jsx +5 -5
  24. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  25. package/dist/src/primitives/Image.jsx +6 -1
  26. package/dist/src/primitives/Image.jsx.map +1 -1
  27. package/dist/src/primitives/KeepAlive.d.ts +4 -3
  28. package/dist/src/primitives/KeepAlive.jsx +60 -23
  29. package/dist/src/primitives/KeepAlive.jsx.map +1 -1
  30. package/dist/src/primitives/LazyImport.js +4 -2
  31. package/dist/src/primitives/LazyImport.js.map +1 -1
  32. package/dist/src/primitives/Preserve.jsx +10 -4
  33. package/dist/src/primitives/Preserve.jsx.map +1 -1
  34. package/dist/src/primitives/Row.jsx +1 -1
  35. package/dist/src/primitives/Row.jsx.map +1 -1
  36. package/dist/src/primitives/Suspense.jsx +7 -7
  37. package/dist/src/primitives/Suspense.jsx.map +1 -1
  38. package/dist/src/primitives/Virtual.jsx +1 -1
  39. package/dist/src/primitives/Virtual.jsx.map +1 -1
  40. package/dist/src/primitives/announcer/announcer.js +3 -2
  41. package/dist/src/primitives/announcer/announcer.js.map +1 -1
  42. package/dist/src/primitives/announcer/speech.js +2 -2
  43. package/dist/src/primitives/announcer/speech.js.map +1 -1
  44. package/dist/src/primitives/borderBox.jsx +2 -1
  45. package/dist/src/primitives/borderBox.jsx.map +1 -1
  46. package/dist/src/primitives/createTag.jsx +3 -3
  47. package/dist/src/primitives/createTag.jsx.map +1 -1
  48. package/dist/src/primitives/portal.jsx +4 -3
  49. package/dist/src/primitives/portal.jsx.map +1 -1
  50. package/dist/src/primitives/utils/chainFunctions.js +35 -9
  51. package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
  52. package/dist/src/primitives/utils/createBlurredImage.js +57 -37
  53. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -1
  54. package/dist/src/primitives/utils/handleNavigation.js +21 -16
  55. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  56. package/dist/src/primitives/utils/withScrolling.js +1 -3
  57. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  58. package/dist/src/render.d.ts +1 -1
  59. package/dist/src/render.js +2 -1
  60. package/dist/src/render.js.map +1 -1
  61. package/dist/src/solidOpts.d.ts +1 -1
  62. package/dist/src/solidOpts.js +4 -2
  63. package/dist/src/solidOpts.js.map +1 -1
  64. package/dist/src/utils.js +10 -5
  65. package/dist/src/utils.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/docs/README.md +2 -2
  68. package/package.json +28 -29
  69. package/src/core/clickInspector.ts +77 -0
  70. package/src/core/config.ts +6 -20
  71. package/src/core/dom-renderer/domRenderer.ts +307 -89
  72. package/src/core/dom-renderer/domRendererTypes.ts +9 -6
  73. package/src/core/elementNode.ts +80 -26
  74. package/src/core/focusManager.ts +16 -8
  75. package/src/core/intrinsicTypes.ts +19 -7
  76. package/src/core/lightningInit.ts +20 -18
  77. package/src/core/utils.ts +4 -4
  78. package/src/primitives/Column.tsx +0 -1
  79. package/src/primitives/FPSCounter.tsx +14 -10
  80. package/src/primitives/Image.tsx +18 -9
  81. package/src/primitives/KeepAlive.tsx +88 -44
  82. package/src/primitives/LazyImport.ts +8 -6
  83. package/src/primitives/Preserve.tsx +13 -8
  84. package/src/primitives/Row.tsx +0 -1
  85. package/src/primitives/Suspense.tsx +10 -9
  86. package/src/primitives/Virtual.tsx +1 -9
  87. package/src/primitives/announcer/announcer.ts +3 -2
  88. package/src/primitives/announcer/speech.ts +2 -2
  89. package/src/primitives/borderBox.tsx +7 -3
  90. package/src/primitives/createTag.tsx +23 -17
  91. package/src/primitives/portal.tsx +20 -10
  92. package/src/primitives/utils/chainFunctions.ts +31 -11
  93. package/src/primitives/utils/createBlurredImage.ts +58 -40
  94. package/src/primitives/utils/handleNavigation.ts +29 -18
  95. package/src/primitives/utils/withScrolling.ts +3 -5
  96. package/src/render.ts +4 -4
  97. package/src/solidOpts.ts +9 -7
  98. package/src/types.ts +0 -1
  99. package/src/utils.ts +12 -10
@@ -6,6 +6,8 @@ import {
6
6
  type AnimationSettings,
7
7
  type ElementText,
8
8
  type Styles,
9
+ type AnimationEvents,
10
+ type AnimationEventHandler,
9
11
  AddColorString,
10
12
  TextProps,
11
13
  type OnEvent,
@@ -17,7 +19,7 @@ import States, { type NodeStates } from './states.js';
17
19
  import calculateFlexOld from './flex.js';
18
20
  import calculateFlexNew from './flexLayout.js';
19
21
 
20
- const calculateFlex = (import.meta as any).env?.VITE_USE_NEW_FLEX
22
+ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
21
23
  ? calculateFlexNew
22
24
  : calculateFlexOld;
23
25
  import {
@@ -52,6 +54,7 @@ import {
52
54
  setActiveElement,
53
55
  FocusNode,
54
56
  } from './focusManager.js';
57
+ import { initClickInspector } from './clickInspector.js';
55
58
 
56
59
  import {
57
60
  IRendererNode,
@@ -144,7 +147,7 @@ function buildFontTemplate() {
144
147
  _fontFamilyIdx = tpl.length;
145
148
  _fontFamilyWithWeight = `${fs.fontFamily}${fs.fontWeight || ''}`;
146
149
  }
147
- tpl.push([key, (fs as any)[key]]);
150
+ tpl.push([key, fs[key]]);
148
151
  }
149
152
  }
150
153
  _fontTemplate = tpl;
@@ -152,8 +155,8 @@ function buildFontTemplate() {
152
155
 
153
156
  const parseAndAssignShaderProps = (
154
157
  prefix: string,
155
- obj: Record<string, any>,
156
- props: Record<string, any> = {},
158
+ obj: Record<string, unknown>,
159
+ props: Record<string, unknown> = {},
157
160
  ) => {
158
161
  if (!obj) return;
159
162
 
@@ -279,6 +282,8 @@ declare global {
279
282
  }
280
283
  }
281
284
 
285
+ initClickInspector();
286
+
282
287
  export type RendererNode = AddColorString<
283
288
  Partial<
284
289
  NewOmit<
@@ -287,6 +292,7 @@ export type RendererNode = AddColorString<
287
292
  >
288
293
  >
289
294
  >;
295
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
290
296
  export interface ElementNode extends RendererNode, FocusNode {
291
297
  [key: string]: unknown;
292
298
 
@@ -672,7 +678,18 @@ export interface ElementNode extends RendererNode, FocusNode {
672
678
  | Record<string, AnimationSettings | undefined | true | false>
673
679
  | true
674
680
  | false;
675
-
681
+ /**
682
+ * Optional handlers for animation events.
683
+ *
684
+ * Available animation events:
685
+ * - 'animating': Fired when the animation starts.
686
+ * - 'stopped': Fired (via setTimeout for the animation duration) when the animation completes.
687
+ *
688
+ * Each event handler is optional and maps to a corresponding event.
689
+ *
690
+ * @see https://lightning-tv.github.io/solid/#/essentials/transitions?id=animation-callbacks
691
+ */
692
+ onAnimation?: Partial<Record<AnimationEvents, AnimationEventHandler>>;
676
693
  /** Optional handler for when the element is created and rendered.
677
694
  *
678
695
  * @see https://lightning-tv.github.io/solid/#/flow/ondestroy
@@ -684,7 +701,7 @@ export interface ElementNode extends RendererNode, FocusNode {
684
701
  *
685
702
  * @see https://lightning-tv.github.io/solid/#/flow/ondestroy
686
703
  */
687
- onDestroy?: (this: ElementNode, el: ElementNode) => Promise<any> | void;
704
+ onDestroy?: (this: ElementNode, el: ElementNode) => Promise<void> | void;
688
705
  /**
689
706
  * Optional handlers for when the element is rendered—after creation and when switching parents.
690
707
  *
@@ -737,6 +754,7 @@ export interface ElementNode extends RendererNode, FocusNode {
737
754
  stateOrder?: DollarString[];
738
755
  }
739
756
 
757
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
740
758
  export class ElementNode {
741
759
  constructor(name: string) {
742
760
  this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
@@ -871,7 +889,7 @@ export class ElementNode {
871
889
  (Config.fontWeightAlias &&
872
890
  (Config.fontWeightAlias[v as string] as number | string)) ??
873
891
  v;
874
- (this.lng as any).fontFamily =
892
+ (this.lng as ElementNode).fontFamily =
875
893
  `${this.fontFamily || Config.fontSettings?.fontFamily}${weight}`;
876
894
  }
877
895
 
@@ -881,7 +899,7 @@ export class ElementNode {
881
899
 
882
900
  set fontFamily(v) {
883
901
  this._fontFamily = v;
884
- (this.lng as any).fontFamily = v;
902
+ (this.lng as ElementNode).fontFamily = v;
885
903
  }
886
904
 
887
905
  get fontFamily() {
@@ -975,26 +993,47 @@ export class ElementNode {
975
993
  { [name]: value },
976
994
  animationSettings,
977
995
  );
996
+ this._fireAnimationEvents(name, value, animationSettings);
978
997
  return animationController.start();
979
998
  }
980
999
 
981
- return (this.lng as any).animateProp(
1000
+ const result = (this.lng as INode).animateProp(
982
1001
  name,
983
1002
  value,
984
1003
  animationSettings || this.animationSettings || {},
985
1004
  );
1005
+ this._fireAnimationEvents(name, value, animationSettings);
1006
+ return result;
986
1007
  }
987
1008
 
988
1009
  (this.lng[name as keyof (IRendererNode | INode)] as number | string) =
989
1010
  value;
990
1011
  }
991
1012
 
1013
+ _fireAnimationEvents(
1014
+ name: string,
1015
+ value: number,
1016
+ animationSettings?: AnimationSettings,
1017
+ ) {
1018
+ if (!this.onAnimation) return;
1019
+ const settings = animationSettings || this.animationSettings;
1020
+ const { animating, stopped } = this.onAnimation;
1021
+ if (animating) {
1022
+ animating.call(this, name, value);
1023
+ }
1024
+ if (stopped) {
1025
+ const total = (settings?.duration ?? 0) + (settings?.delay ?? 0);
1026
+ setTimeout(() => stopped.call(this, name, value), total);
1027
+ }
1028
+ }
1029
+
992
1030
  animate(
993
1031
  props: Partial<INodeAnimateProps<CoreShaderNode>>,
994
1032
  animationSettings?: AnimationSettings,
995
1033
  ): IAnimationController {
996
- isDev &&
1034
+ if (isDev) {
997
1035
  assertTruthy(this.rendered, 'Node must be rendered before animating');
1036
+ }
998
1037
  return (this.lng as IRendererNode).animate(
999
1038
  props,
1000
1039
  animationSettings || this.animationSettings || {},
@@ -1104,7 +1143,7 @@ export class ElementNode {
1104
1143
  // If onDestroy returns a promise, wait for it to resolve before destroying
1105
1144
  // Useful with animations waitUntilStopped method which returns promise
1106
1145
  if (destroyPromise instanceof Promise) {
1107
- destroyPromise.then(() => this._destroy());
1146
+ void destroyPromise.then(() => this._destroy());
1108
1147
  } else {
1109
1148
  this._destroy();
1110
1149
  }
@@ -1243,7 +1282,7 @@ export class ElementNode {
1243
1282
  * @param val - A value to determine if the element should autofocus.
1244
1283
  * A truthy value enables autofocus, otherwise disables it.
1245
1284
  */
1246
- set autofocus(val: any) {
1285
+ set autofocus(val: boolean | undefined) {
1247
1286
  this._autofocus = val;
1248
1287
  // Defer setFocus so children render first (forwardFocus needs them).
1249
1288
  // The post-mutation focus phase calls setFocus on this element.
@@ -1294,7 +1333,7 @@ export class ElementNode {
1294
1333
  return this._requiresLayout;
1295
1334
  }
1296
1335
 
1297
- set updateLayoutOn(v: any) {
1336
+ set updateLayoutOn(_v: unknown) {
1298
1337
  this.updateLayout();
1299
1338
  }
1300
1339
 
@@ -1304,7 +1343,7 @@ export class ElementNode {
1304
1343
 
1305
1344
  updateLayout() {
1306
1345
  if (this.hasChildren) {
1307
- isDev && log('Layout: ', this);
1346
+ if (isDev) log('Layout: ', this);
1308
1347
 
1309
1348
  if (this.display === 'flex' && this.flexGrow && this.width === 0) {
1310
1349
  return;
@@ -1334,7 +1373,18 @@ export class ElementNode {
1334
1373
  }
1335
1374
 
1336
1375
  _stateChanged() {
1337
- isDev && log('State Changed: ', this, this.states);
1376
+ if (isDev) log('State Changed: ', this, this.states);
1377
+
1378
+ if (isDev) {
1379
+ const div = (this.lng as IRendererNode)?.div;
1380
+ if (div) {
1381
+ if (this.states.length > 0) {
1382
+ div.dataset.states = this.states.join(' ');
1383
+ } else {
1384
+ delete div.dataset.states;
1385
+ }
1386
+ }
1387
+ }
1338
1388
 
1339
1389
  if (this.forwardStates) {
1340
1390
  // apply states to children first
@@ -1406,7 +1456,7 @@ export class ElementNode {
1406
1456
  this._undoStyles = Object.keys(newStyles);
1407
1457
  // Apply transition first
1408
1458
  if (newStyles.transition !== undefined) {
1409
- this.transition = newStyles.transition as Styles['transition'];
1459
+ this.transition = newStyles.transition;
1410
1460
  }
1411
1461
 
1412
1462
  // Apply the styles
@@ -1529,9 +1579,8 @@ export class ElementNode {
1529
1579
  textProps.maxHeight =
1530
1580
  parentHeight - textProps.y! - (textProps.marginBottom || 0);
1531
1581
  } else if (textProps.maxLines === 1) {
1532
- textProps.maxHeight = (textProps.maxHeight ||
1533
- textProps.lineHeight ||
1534
- textProps.fontSize) as number;
1582
+ textProps.maxHeight =
1583
+ textProps.maxHeight || textProps.lineHeight || textProps.fontSize;
1535
1584
  }
1536
1585
  // textProps.w = textProps.h = 0;
1537
1586
  }
@@ -1541,7 +1590,7 @@ export class ElementNode {
1541
1590
  props.shader = Config.convertToShader(node, props.shader);
1542
1591
  }
1543
1592
 
1544
- isDev && log('Rendering: ', this, props);
1593
+ if (isDev) log('Rendering: ', this, props);
1545
1594
 
1546
1595
  node.lng = renderer.createTextNode(
1547
1596
  props as Partial<ITextNodeProps> & Partial<IRendererTextNodeProps>,
@@ -1581,7 +1630,7 @@ export class ElementNode {
1581
1630
  props.shader = Config.convertToShader(node, props.shader);
1582
1631
  }
1583
1632
 
1584
- isDev && log('Rendering: ', this, props);
1633
+ if (isDev) log('Rendering: ', this, props);
1585
1634
 
1586
1635
  node.lng = renderer.createNode(
1587
1636
  props as Partial<INodeProps<any>> & Partial<IRendererNodeProps>,
@@ -1592,7 +1641,7 @@ export class ElementNode {
1592
1641
 
1593
1642
  for (const child of node.children) {
1594
1643
  if (isElementNode(child) && isINode(child.lng)) {
1595
- child.lng.parent = node.lng as any;
1644
+ child.lng.parent = node.lng as INode;
1596
1645
  }
1597
1646
  }
1598
1647
  }
@@ -1620,15 +1669,20 @@ export class ElementNode {
1620
1669
  }
1621
1670
 
1622
1671
  // L3 Inspector adds div to the lng object
1623
- const div: HTMLElement | undefined = (node.lng as any)?.div;
1624
- if (div) div.element = node;
1672
+ const div: HTMLElement | undefined = (node.lng as IRendererNode)?.div;
1673
+ if (isDev && div) {
1674
+ div.element = node;
1675
+ if (node._states && node._states.length > 0) {
1676
+ div.dataset.states = node._states.join(' ');
1677
+ }
1678
+ }
1625
1679
 
1626
1680
  if (node._type === NodeType.Element) {
1627
1681
  // only element nodes will have children that need rendering
1628
1682
  const numChildren = node.children.length;
1629
1683
  for (let i = 0; i < numChildren; i++) {
1630
1684
  const c = node.children[i];
1631
- isDev && assertTruthy(c, 'Child is undefined');
1685
+ if (isDev) assertTruthy(c, 'Child is undefined');
1632
1686
  // Text elements sneak in from Solid creating tracked nodes
1633
1687
  if (isElementNode(c)) {
1634
1688
  c.render();
@@ -1641,7 +1695,7 @@ export class ElementNode {
1641
1695
  schedulePostMutation();
1642
1696
  }
1643
1697
 
1644
- node._autofocus && node.setFocus();
1698
+ if (node._autofocus) node.setFocus();
1645
1699
  }
1646
1700
  }
1647
1701
 
@@ -1,4 +1,5 @@
1
1
  import { Config, isDev } from './config.js';
2
+ import { IRendererNode } from './dom-renderer/domRendererTypes.js';
2
3
  export type * from './focusKeyTypes.js';
3
4
  import { ElementNode } from './elementNode.js';
4
5
  import type {
@@ -8,7 +9,9 @@ import type {
8
9
  } from './focusKeyTypes.js';
9
10
  import { isFunction } from './utils.js';
10
11
 
11
- const keyMapEntries: Record<KeyNameOrKeyCode, string> = {
12
+ type KeyMapEntries = Record<KeyNameOrKeyCode, string>;
13
+
14
+ const keyMapEntries: KeyMapEntries = {
12
15
  ArrowLeft: 'Left',
13
16
  ArrowRight: 'Right',
14
17
  ArrowUp: 'Up',
@@ -24,18 +27,23 @@ const keyHoldMapEntries: Record<KeyNameOrKeyCode, string> = {
24
27
  // Enter: 'EnterHold',
25
28
  };
26
29
 
27
- const flattenKeyMap = (keyMap: any, targetMap: any): void => {
30
+ const flattenKeyMap = (
31
+ keyMap: Partial<KeyMap>,
32
+ targetMap: KeyMapEntries,
33
+ ): KeyMapEntries => {
34
+ const newTargetMap = targetMap;
28
35
  for (const [key, value] of Object.entries(keyMap)) {
29
36
  if (Array.isArray(value)) {
30
37
  value.forEach((v) => {
31
- targetMap[v] = key;
38
+ newTargetMap[v] = key;
32
39
  });
33
40
  } else if (value === null) {
34
- delete targetMap[key];
41
+ delete newTargetMap[key];
35
42
  } else {
36
- targetMap[value as keyof any] = key;
43
+ newTargetMap[value as KeyNameOrKeyCode] = key;
37
44
  }
38
45
  }
46
+ return newTargetMap;
39
47
  };
40
48
 
41
49
  let needFocusDebugStyles = true;
@@ -117,7 +125,7 @@ let _pendingHistoryKey: {
117
125
  const getElementLabel = (elm: ElementNode | undefined): string => {
118
126
  if (!elm) return 'None';
119
127
  // ElementNode exposes _id internally; componentName comes from the Babel devtools plugin
120
- const id = (elm as any).id ?? elm._id;
128
+ const id = elm.id ?? elm._id;
121
129
  return id ?? elm.componentName ?? 'Unknown';
122
130
  };
123
131
 
@@ -173,14 +181,14 @@ export const printFocusHistory = (count: number): void => {
173
181
  key: e.mappedKey ?? e.keyPressed ?? '—',
174
182
  next: getElementLabel(e.next),
175
183
  nextElm: e.next,
176
- nextDiv: (e.next.lng as any).div as HTMLDivElement,
184
+ nextDiv: (e.next.lng as IRendererNode).div,
177
185
  })),
178
186
  );
179
187
 
180
188
  // 2. Expose the most recent element for easy inspection
181
189
  const lastEntry = entries[entries.length - 1];
182
190
  if (lastEntry) {
183
- const lastElm = (lastEntry.next.lng as any)?.div;
191
+ const lastElm = (lastEntry.next.lng as IRendererNode)?.div;
184
192
  if (lastElm) {
185
193
  (window as any).$f = lastElm;
186
194
  }
@@ -24,16 +24,18 @@ export type AddColorString<T> = {
24
24
  [K in keyof T]: K extends `color${string}` ? string | number : T[K];
25
25
  };
26
26
 
27
- export interface BorderStyleObject
28
- extends AddColorString<Partial<lngr.BorderProps>> {
27
+ export interface BorderStyleObject extends AddColorString<
28
+ Partial<lngr.BorderProps>
29
+ > {
29
30
  width?: number | [number, number, number, number];
30
31
  gap?: number;
31
32
  align?: 'inside' | 'outside' | 'center';
32
33
  fill?: number | string;
33
34
  }
34
35
 
35
- export interface SingleBorderStyleObject
36
- extends AddColorString<Partial<lngr.BorderProps>> {
36
+ export interface SingleBorderStyleObject extends AddColorString<
37
+ Partial<lngr.BorderProps>
38
+ > {
37
39
  width?: number;
38
40
  w?: number;
39
41
  gap?: number;
@@ -104,7 +106,8 @@ type CleanElementNode = NewOmit<
104
106
  >;
105
107
  /** Node text, children of a ElementNode of type TextNode */
106
108
  export interface ElementText
107
- extends NewOmit<
109
+ extends
110
+ NewOmit<
108
111
  ElementNode,
109
112
  '_type' | 'parent' | 'children' | 'src' | 'scale' | 'fontFamily'
110
113
  >,
@@ -117,7 +120,8 @@ export interface ElementText
117
120
  }
118
121
 
119
122
  export interface NodeProps
120
- extends RendererNode,
123
+ extends
124
+ RendererNode,
121
125
  EventHandlers<DefaultKeyMap>,
122
126
  EventHandlers<KeyHoldMap>,
123
127
  FocusNode,
@@ -147,7 +151,8 @@ export interface NodeStyles extends NewOmit<NodeProps, 'style'> {
147
151
  }
148
152
 
149
153
  export interface TextProps
150
- extends RendererText,
154
+ extends
155
+ RendererText,
151
156
  Partial<
152
157
  NewOmit<
153
158
  CleanElementNode,
@@ -190,6 +195,13 @@ export interface IntrinsicNodeProps extends NodeProps {}
190
195
  export interface IntrinsicNodeStyleProps extends NodeStyles {}
191
196
  export interface IntrinsicTextNodeStyleProps extends TextStyles {}
192
197
 
198
+ export type AnimationEvents = 'animating' | 'stopped';
199
+ export type AnimationEventHandler = (
200
+ this: ElementNode,
201
+ name: string,
202
+ endValue: number,
203
+ ) => void;
204
+
193
205
  type EventPayloadMap = {
194
206
  loaded: lngr.NodeLoadedPayload;
195
207
  failed: lngr.NodeFailedPayload;
@@ -22,24 +22,26 @@ export function startLightningRenderer(
22
22
  return renderer;
23
23
  }
24
24
 
25
- export function loadFonts(fonts: FontLoadOptions[]) {
25
+ export async function loadFonts(fonts: FontLoadOptions[]) {
26
26
  const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
27
- for (const font of fonts) {
28
- // WebGL — SDF
29
- if (
30
- renderer.stage.renderer.mode === 'webgl' &&
31
- 'type' in font &&
32
- (font.type === 'msdf' || font.type === 'ssdf')
33
- ) {
34
- renderer.stage.loadFont('sdf', font);
35
- }
36
- // Canvas — Web
37
- else if ('fontUrl' in font) {
38
- if (enableDomRenderer) {
39
- loadFontToDom(font);
40
- } else if (renderer.stage.renderer.mode !== 'webgl') {
41
- renderer.stage.loadFont('canvas', font);
27
+ await Promise.all(
28
+ fonts.map((font) => {
29
+ // WebGL — SDF
30
+ if (
31
+ renderer.stage.renderer.mode === 'webgl' &&
32
+ 'type' in font &&
33
+ (font.type === 'msdf' || font.type === 'ssdf')
34
+ ) {
35
+ return renderer.stage.loadFont('sdf', font);
42
36
  }
43
- }
44
- }
37
+ // Canvas — Web
38
+ if ('fontUrl' in font) {
39
+ if (enableDomRenderer) {
40
+ loadFontToDom(font);
41
+ } else if (renderer.stage.renderer.mode !== 'webgl') {
42
+ return renderer.stage.loadFont('canvas', font);
43
+ }
44
+ }
45
+ }),
46
+ );
45
47
  }
package/src/core/utils.ts CHANGED
@@ -30,7 +30,7 @@ export const isFunction = (obj: unknown): obj is Function =>
30
30
  export function isObject(
31
31
  item: unknown,
32
32
  ): item is Record<string | number | symbol, unknown> {
33
- return typeof item === 'object';
33
+ return item !== null && typeof item === 'object';
34
34
  }
35
35
 
36
36
  export function isArray(item: unknown): item is any[] {
@@ -99,9 +99,9 @@ export function flattenStyles(
99
99
  result: Styles = {},
100
100
  ): Styles {
101
101
  if (isArray(obj)) {
102
- obj.forEach((item) => {
103
- flattenStyles(item, result);
104
- });
102
+ for (let i = 0; i < obj.length; i++) {
103
+ flattenStyles(obj[i], result);
104
+ }
105
105
  } else if (obj) {
106
106
  // handle the case where the object is not an array
107
107
  for (const key in obj) {
@@ -34,7 +34,6 @@ export const Column: Component<ColumnProps> = (props) => {
34
34
  <view
35
35
  transitionUp={defaultTransitionUp}
36
36
  transitionDown={defaultTransitionDown}
37
- transition={/* @once */ {}}
38
37
  {...props}
39
38
  onUp={/* @once */ chainFunctions(props.onUp, onUp)}
40
39
  onDown={/* @once */ chainFunctions(props.onDown, onDown)}
@@ -9,18 +9,18 @@ const fpsStyle = {
9
9
  y: 6,
10
10
  mountX: 1,
11
11
  alpha: 1,
12
- zIndex: 100
12
+ zIndex: 100,
13
13
  };
14
14
 
15
15
  const fpsLabel = {
16
16
  x: 10,
17
17
  fontSize: 20,
18
- textColor: 0xf6f6f6ff
18
+ textColor: 0xf6f6f6ff,
19
19
  };
20
20
 
21
21
  const fpsValue = {
22
22
  fontSize: 22,
23
- textColor: 0xf6f6f6ff
23
+ textColor: 0xf6f6f6ff,
24
24
  };
25
25
 
26
26
  const [fps, setFps] = createSignal(0);
@@ -32,7 +32,8 @@ const [criticalThresholdSignal, setCriticalThresholdSignal] = createSignal('');
32
32
  const [targetThresholdSignal, setTargetThresholdSignal] = createSignal('');
33
33
  const [renderableMemUsedSignal, setRenderableMemUsedSignal] = createSignal('');
34
34
  const [memUsedSignal, setMemUsedSignal] = createSignal('');
35
- const [renderableTexturesLoadedSignal, setRenderableTexturesLoadedSignal] = createSignal(0);
35
+ const [renderableTexturesLoadedSignal, setRenderableTexturesLoadedSignal] =
36
+ createSignal(0);
36
37
  const [loadedTexturesSignal, setLoadedTexturesSignal] = createSignal(0);
37
38
  const [renderOps, setRenderOps] = createSignal(0);
38
39
 
@@ -60,8 +61,8 @@ const calcFps = (fps: number) => {
60
61
  if (!fps) return;
61
62
 
62
63
  setFps(fps);
63
- setMinFps(prev => Math.min(fps, prev));
64
- setMaxFps(prev => Math.max(fps, prev));
64
+ setMinFps((prev) => Math.min(fps, prev));
65
+ setMaxFps((prev) => Math.max(fps, prev));
65
66
 
66
67
  totalFps += fps;
67
68
  count++;
@@ -94,10 +95,13 @@ export function setupFPS(root: any) {
94
95
  }
95
96
  });
96
97
 
97
- root.renderer.on('renderUpdate', (target: RendererMain, quadsData: RenderUpdatePayload) => {
98
- setQuads(quadsData.quads);
99
- setRenderOps(quadsData.renderOps);
100
- });
98
+ root.renderer.on(
99
+ 'renderUpdate',
100
+ (target: RendererMain, quadsData: RenderUpdatePayload) => {
101
+ setQuads(quadsData.quads);
102
+ setRenderOps(quadsData.renderOps);
103
+ },
104
+ );
101
105
  }
102
106
 
103
107
  export const FPSCounter = (props: NodeProps) => {
@@ -1,5 +1,5 @@
1
1
  import { type Component, createRenderEffect, createSignal } from 'solid-js';
2
- import { renderer, type NodeProps, type ImageTexture} from '@solidtv/solid';
2
+ import { ImageTexture, renderer, type NodeProps } from '@solidtv/solid';
3
3
  import { Config } from '../core/config.js';
4
4
 
5
5
  export interface ImageProps extends NodeProps {
@@ -10,7 +10,7 @@ export interface ImageProps extends NodeProps {
10
10
  }
11
11
 
12
12
  export const Image: Component<ImageProps> = (props) => {
13
- const [texture, setTexture] = createSignal<any>(null);
13
+ const [texture, setTexture] = createSignal<ImageTexture | null>(null);
14
14
  const [src, setSrc] = createSignal<string | null>(props.placeholder || null);
15
15
 
16
16
  createRenderEffect(() => {
@@ -43,14 +43,23 @@ export const Image: Component<ImageProps> = (props) => {
43
43
  });
44
44
  }
45
45
 
46
- srcTexture.getTextureData().then(resp => {
47
- // if texture fails to load, this is still called after the failed handler
48
- if (resp.data)
49
- setTexture(srcTexture);
50
- })
51
- })
46
+ srcTexture
47
+ .getTextureData()
48
+ .then((resp) => {
49
+ // if texture fails to load, this is still called after the failed handler
50
+ if (resp.data) setTexture(srcTexture);
51
+ })
52
+ .catch(() => {
53
+ // handle potential errors from getTextureData
54
+ });
55
+ });
52
56
 
53
57
  return (
54
- <view {...props} src={src()} color={props.color || 0xffffffff} texture={texture()} />
58
+ <view
59
+ {...props}
60
+ src={src()}
61
+ color={props.color || 0xffffffff}
62
+ texture={texture()}
63
+ />
55
64
  );
56
65
  };