@solidtv/solid 1.0.3 → 1.1.0

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 (42) hide show
  1. package/dist/src/core/dom-renderer/domRenderer.js +2 -0
  2. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  3. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +1 -0
  4. package/dist/src/core/elementNode.d.ts +16 -3
  5. package/dist/src/core/elementNode.js +143 -50
  6. package/dist/src/core/elementNode.js.map +1 -1
  7. package/dist/src/core/intrinsicTypes.d.ts +2 -7
  8. package/dist/src/core/nodeTypes.d.ts +7 -0
  9. package/dist/src/core/nodeTypes.js +8 -0
  10. package/dist/src/core/nodeTypes.js.map +1 -1
  11. package/dist/src/core/utils.d.ts +2 -1
  12. package/dist/src/core/utils.js.map +1 -1
  13. package/dist/src/devtools/hexColorTransform.d.ts +6 -0
  14. package/dist/src/devtools/hexColorTransform.js +42 -0
  15. package/dist/src/devtools/hexColorTransform.js.map +1 -0
  16. package/dist/src/devtools/index.d.ts +2 -0
  17. package/dist/src/devtools/index.js +1 -0
  18. package/dist/src/devtools/index.js.map +1 -1
  19. package/dist/src/primitives/index.d.ts +0 -2
  20. package/dist/src/primitives/index.js +0 -2
  21. package/dist/src/primitives/index.js.map +1 -1
  22. package/dist/src/primitives/routerIndex.d.ts +2 -0
  23. package/dist/src/primitives/routerIndex.js +3 -0
  24. package/dist/src/primitives/routerIndex.js.map +1 -0
  25. package/dist/src/primitives/useMouse.js.map +1 -1
  26. package/dist/src/solidOpts.d.ts +1 -1
  27. package/dist/src/solidOpts.js +3 -13
  28. package/dist/src/solidOpts.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +10 -3
  31. package/src/core/dom-renderer/domRenderer.ts +2 -0
  32. package/src/core/dom-renderer/domRendererTypes.ts +1 -0
  33. package/src/core/elementNode.ts +164 -55
  34. package/src/core/intrinsicTypes.ts +3 -7
  35. package/src/core/nodeTypes.ts +12 -0
  36. package/src/core/utils.ts +2 -2
  37. package/src/devtools/hexColorTransform.ts +56 -0
  38. package/src/devtools/index.ts +3 -0
  39. package/src/primitives/index.ts +0 -2
  40. package/src/primitives/routerIndex.ts +2 -0
  41. package/src/primitives/useMouse.ts +3 -3
  42. package/src/solidOpts.ts +5 -16
@@ -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 (let 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 = (
@@ -263,6 +318,16 @@ export interface ElementNode extends RendererNode, FocusNode {
263
318
  _type: 'element' | 'textNode';
264
319
  _undoStyles?: string[];
265
320
  autosize?: boolean;
321
+ /**
322
+ * Optional component name for inspector / dev tooling — emitted by the
323
+ * Babel devtools plugin (see `devtools/jsx-locator.js`).
324
+ */
325
+ componentName?: string;
326
+ /**
327
+ * Optional source-location string for inspector / dev tooling — emitted by
328
+ * the Babel devtools plugin.
329
+ */
330
+ componentLocation?: string;
266
331
  /**
267
332
  * The distance from the bottom edge of the parent element.
268
333
  * When `bottom` is set, `mountY` is automatically set to 1.
@@ -683,13 +748,48 @@ export interface ElementNode extends RendererNode, FocusNode {
683
748
  stateOrder?: DollarString[];
684
749
  }
685
750
 
686
- export class ElementNode extends Object {
751
+ export class ElementNode {
687
752
  constructor(name: string) {
688
- super();
689
753
  this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
690
754
  this.rendered = false;
691
- this.lng = {};
755
+ // initialize lng with standard properties for v8 optimization
756
+ this.lng = {
757
+ w: undefined,
758
+ h: undefined,
759
+ x: undefined,
760
+ y: undefined,
761
+ alpha: undefined,
762
+ color: undefined,
763
+ shader: undefined,
764
+ clipping: undefined,
765
+ text: undefined,
766
+ };
692
767
  this.children = [];
768
+
769
+ // Initialize lazy underscore fields explicitly in a fixed order. This
770
+ // gives every ElementNode the same hidden class on construction; later
771
+ // assignments transition predictably instead of forking shapes by
772
+ // first-touch order.
773
+ this._queueDelete = undefined;
774
+ this._animationQueue = undefined;
775
+ this._animationQueueSettings = undefined;
776
+ this._animationRunning = undefined;
777
+ this._animationSettings = undefined;
778
+ this._autofocus = undefined;
779
+ this._calcWidth = undefined;
780
+ this._calcHeight = undefined;
781
+ this._containsFlexGrow = undefined;
782
+ this._hasRenderedChildren = undefined;
783
+ this._effects = undefined;
784
+ this._fontFamily = undefined;
785
+ this._fontWeight = undefined;
786
+ this._id = undefined;
787
+ this._parent = undefined;
788
+ this._states = undefined;
789
+ this._style = undefined;
790
+ this._theme = undefined;
791
+ this._lastAnyKeyPressTime = undefined;
792
+ this._undoStyles = undefined;
693
793
  }
694
794
 
695
795
  get effects(): StyleEffects | undefined {
@@ -826,7 +926,10 @@ export class ElementNode extends Object {
826
926
 
827
927
  removeChild(node: ElementNode | ElementText | TextNode) {
828
928
  if (spliceItem(this.children, node, 1) > -1) {
829
- node.onRemove?.call(node, node);
929
+ if (isElementNode(node) && node.onRemove) {
930
+ node.onRemove.call(node, node);
931
+ }
932
+
830
933
  if (this.requiresLayout()) {
831
934
  addToLayoutQueue(this);
832
935
  }
@@ -872,6 +975,16 @@ export class ElementNode extends Object {
872
975
  | undefined
873
976
  | AnimationSettings);
874
977
 
978
+ // If the renderer doesn't support animateProp,
979
+ // keep backwards compatible with LightningRenderer
980
+ if (!('animateProp' in this.lng)) {
981
+ const animationController = this.animate(
982
+ { [name]: value },
983
+ animationSettings,
984
+ );
985
+ return animationController.start();
986
+ }
987
+
875
988
  return (this.lng as any).animateProp(
876
989
  name,
877
990
  value,
@@ -964,19 +1077,10 @@ export class ElementNode extends Object {
964
1077
  }
965
1078
  }
966
1079
  }
967
- // Delay setting focus so children can render (useful for Row + Column)
1080
+ // Delay setting focus so children can render (useful for Row + Column).
1081
+ // The post-mutation scheduler applies setActiveElement in its focus phase.
968
1082
  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
- }
1083
+ schedulePostMutation();
980
1084
  } else {
981
1085
  this._autofocus = true;
982
1086
  }
@@ -984,12 +1088,7 @@ export class ElementNode extends Object {
984
1088
 
985
1089
  _layoutOnLoad() {
986
1090
  (this.lng as IRendererNode).on('loaded', () => {
987
- if (
988
- 'reprocessUpdates' in renderer.stage &&
989
- renderer.stage.reprocessUpdates
990
- ) {
991
- renderer.stage.reprocessUpdates(runLayout);
992
- }
1091
+ schedulePostMutation();
993
1092
  this.parent!.updateLayout();
994
1093
  });
995
1094
  }
@@ -1150,9 +1249,12 @@ export class ElementNode extends Object {
1150
1249
  */
1151
1250
  set autofocus(val: any) {
1152
1251
  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());
1252
+ // Defer setFocus so children render first (forwardFocus needs them).
1253
+ // The post-mutation focus phase calls setFocus on this element.
1254
+ if (val) {
1255
+ deferredFocusElement = this;
1256
+ schedulePostMutation();
1257
+ }
1156
1258
  }
1157
1259
 
1158
1260
  get autofocus() {
@@ -1351,14 +1453,22 @@ export class ElementNode extends Object {
1351
1453
 
1352
1454
  if (isElementText(node)) {
1353
1455
  const textProps = props as TextProps;
1354
- if (Config.fontSettings) {
1355
- for (const key in Config.fontSettings) {
1456
+ if (_fontTemplate === undefined) buildFontTemplate();
1457
+ const tpl = _fontTemplate!;
1458
+ if (tpl.length > 0) {
1459
+ const familyIdx = _fontFamilyIdx;
1460
+ const familyWithWeight =
1461
+ textProps['fontWeight'] === undefined
1462
+ ? _fontFamilyWithWeight
1463
+ : undefined;
1464
+ for (let i = 0; i < tpl.length; i++) {
1465
+ const entry = tpl[i]!;
1466
+ const key = entry[0];
1356
1467
  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;
1468
+ textProps[key] =
1469
+ i === familyIdx && familyWithWeight !== undefined
1470
+ ? familyWithWeight
1471
+ : entry[1];
1362
1472
  }
1363
1473
  }
1364
1474
  }
@@ -1496,11 +1606,10 @@ export class ElementNode extends Object {
1496
1606
  }
1497
1607
  }
1498
1608
  }
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);
1609
+ if (topNode) {
1610
+ // Schedule one post-mutation pass; <For> may add many children in one
1611
+ // tick, but the scheduler dedupes and runs everything once.
1612
+ schedulePostMutation();
1504
1613
  }
1505
1614
 
1506
1615
  node._autofocus && node.setFocus();
@@ -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' = 'text';
12
+ parent: ElementText | undefined = undefined;
13
+ text: string;
14
+
15
+ constructor(text: string) {
16
+ this.text = text;
17
+ }
18
+ }
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;
@@ -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
+ }
@@ -1,6 +1,9 @@
1
1
  import * as debug from '@solid-devtools/debugger/types';
2
2
  import * as lng from '../core/index.js';
3
3
 
4
+ export { default as hexColorTransform } from './hexColorTransform.js';
5
+ export type { HexColorTransformOptions } from './hexColorTransform.js';
6
+
4
7
  const EMPTY_CHILDREN: (lng.ElementNode | lng.ElementText)[] = [];
5
8
 
6
9
  /**
@@ -8,7 +8,6 @@ export * from './Lazy.jsx';
8
8
  export * from './LazyImport.js';
9
9
  export * from './Image.jsx';
10
10
  export * from './Visible.jsx';
11
- export * from './router.js';
12
11
  export * from './Column.jsx';
13
12
  export * from './Row.jsx';
14
13
  export * from './Grid.jsx';
@@ -19,7 +18,6 @@ export * from './Suspense.jsx';
19
18
  export * from './Marquee.jsx';
20
19
  export * from './createFocusStack.jsx';
21
20
  export * from './useHold.js';
22
- export * from './KeepAlive.jsx';
23
21
  export * from './VirtualGrid.jsx';
24
22
  export * from './Virtual.jsx';
25
23
  export * from './utils/withScrolling.js';
@@ -0,0 +1,2 @@
1
+ export * from './router.js';
2
+ export * from './KeepAlive.jsx';
@@ -30,21 +30,21 @@ export function addCustomStateToElement(
30
30
  element: RenderableNode,
31
31
  state: CustomState,
32
32
  ): void {
33
- element.states?.add(state);
33
+ (element as ElementNode).states?.add(state);
34
34
  }
35
35
 
36
36
  export function removeCustomStateFromElement(
37
37
  element: RenderableNode,
38
38
  state: CustomState,
39
39
  ): void {
40
- element?.states?.remove(state);
40
+ (element as ElementNode)?.states?.remove(state);
41
41
  }
42
42
 
43
43
  export function hasCustomState(
44
44
  element: RenderableNode,
45
45
  state: CustomState,
46
46
  ): boolean {
47
- return element.states?.has(state);
47
+ return (element as ElementNode).states?.has(state);
48
48
  }
49
49
 
50
50
  function createKeyboardEvent(
package/src/solidOpts.ts CHANGED
@@ -2,10 +2,11 @@ import {
2
2
  assertTruthy,
3
3
  isElementText,
4
4
  ElementNode,
5
- NodeType,
5
+ TextNode,
6
6
  log,
7
7
  type ElementText,
8
- type TextNode,
8
+ elementDeleteQueue,
9
+ schedulePostMutation,
9
10
  } from './core/index.js';
10
11
  import type { SolidNode, SolidRendererOptions } from './types.js';
11
12
 
@@ -18,23 +19,11 @@ Object.defineProperty(ElementNode.prototype, 'preserve', {
18
19
  },
19
20
  });
20
21
 
21
- let elementDeleteQueue: ElementNode[] = [];
22
-
23
- function flushDeleteQueue(): void {
24
- for (let el of elementDeleteQueue) {
25
- if (Number(el._queueDelete) < 0) {
26
- el.destroy();
27
- }
28
- el._queueDelete = undefined;
29
- }
30
- elementDeleteQueue.length = 0;
31
- }
32
-
33
22
  function pushDeleteQueue(node: ElementNode, n: number): void {
34
23
  if (node._queueDelete === undefined) {
35
24
  node._queueDelete = n;
36
25
  if (elementDeleteQueue.push(node) === 1) {
37
- queueMicrotask(flushDeleteQueue);
26
+ schedulePostMutation();
38
27
  }
39
28
  } else {
40
29
  node._queueDelete += n;
@@ -47,7 +36,7 @@ export default {
47
36
  },
48
37
  createTextNode(text: string): TextNode {
49
38
  // A text node is just a string - not the <text> node
50
- return { _type: NodeType.Text, text };
39
+ return new TextNode(text);
51
40
  },
52
41
  replaceText(node: TextNode, value: string): void {
53
42
  log('Replace Text: ', node, value);