@solidtv/solid 1.7.0-0 → 1.7.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 (32) hide show
  1. package/dist/src/core/elementNode.d.ts +19 -1
  2. package/dist/src/core/elementNode.js +127 -26
  3. package/dist/src/core/elementNode.js.map +1 -1
  4. package/dist/src/core/focusManager.js +15 -4
  5. package/dist/src/core/focusManager.js.map +1 -1
  6. package/dist/src/core/lightningInit.js +65 -3
  7. package/dist/src/core/lightningInit.js.map +1 -1
  8. package/dist/src/core/nodeTypes.d.ts +1 -1
  9. package/dist/src/core/nodeTypes.js +2 -3
  10. package/dist/src/core/nodeTypes.js.map +1 -1
  11. package/dist/src/primitives/Lazy.jsx +7 -1
  12. package/dist/src/primitives/Lazy.jsx.map +1 -1
  13. package/dist/src/primitives/Virtual.d.ts +4 -0
  14. package/dist/src/primitives/Virtual.jsx +192 -106
  15. package/dist/src/primitives/Virtual.jsx.map +1 -1
  16. package/dist/src/primitives/VirtualGrid.jsx +87 -18
  17. package/dist/src/primitives/VirtualGrid.jsx.map +1 -1
  18. package/dist/src/primitives/utils/handleNavigation.js +12 -5
  19. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  20. package/dist/src/primitives/utils/withScrolling.js +63 -57
  21. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +12 -5
  24. package/src/core/elementNode.ts +143 -22
  25. package/src/core/focusManager.ts +12 -4
  26. package/src/core/lightningInit.ts +78 -4
  27. package/src/core/nodeTypes.ts +6 -3
  28. package/src/primitives/Lazy.tsx +8 -1
  29. package/src/primitives/Virtual.tsx +211 -117
  30. package/src/primitives/VirtualGrid.tsx +98 -21
  31. package/src/primitives/utils/handleNavigation.ts +12 -5
  32. package/src/primitives/utils/withScrolling.ts +63 -62
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.7.0-0",
3
+ "version": "1.7.0",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,10 +34,17 @@
34
34
  },
35
35
  "./devtools/jsx-locator": "./src/devtools/jsx-locator.js",
36
36
  "./shaders": {
37
- "@solidtv/source": "./src/shaders/index.ts",
37
+ "@solidtv/source": "./src/core/shaders.ts",
38
38
  "import": {
39
- "types": "./dist/src/shaders/index.d.ts",
40
- "default": "./dist/src/shaders/index.js"
39
+ "types": "./dist/src/core/shaders.d.ts",
40
+ "default": "./dist/src/core/shaders.js"
41
+ }
42
+ },
43
+ "./focusManager": {
44
+ "@solidtv/source": "./src/core/focusManager.ts",
45
+ "import": {
46
+ "types": "./dist/src/core/focusManager.d.ts",
47
+ "default": "./dist/src/core/focusManager.js"
41
48
  }
42
49
  },
43
50
  "./jsx-runtime": {
@@ -114,7 +121,7 @@
114
121
  },
115
122
  "peerDependencies": {
116
123
  "@solidjs/router": "^0.16.1",
117
- "@solidtv/renderer": "^2.0.0-alpha.3",
124
+ "@solidtv/renderer": "^2.0.6",
118
125
  "solid-js": "*"
119
126
  },
120
127
  "peerDependenciesMeta": {},
@@ -240,16 +240,74 @@ const parseAndAssignShaderProps = (
240
240
  }
241
241
  };
242
242
 
243
+ const assignEffects = (v: StyleEffects, props: Record<string, unknown>) => {
244
+ if (v.rounded) props.radius = v.rounded.radius;
245
+ if (v.borderRadius) props.radius = v.borderRadius;
246
+ for (const k of EFFECT_SHADER_KEYS) {
247
+ if (v[k]) parseAndAssignShaderProps(k, v[k], props);
248
+ }
249
+ };
250
+
251
+ const assignShaderProp = (
252
+ key: string,
253
+ value: unknown,
254
+ props: Record<string, unknown>,
255
+ ) => {
256
+ if (key === 'rounded' || typeof value === 'number') {
257
+ props.radius = value;
258
+ } else {
259
+ parseAndAssignShaderProps(key, value as Record<string, unknown>, props);
260
+ }
261
+ };
262
+
263
+ // The shader types convertToShader makes, by feature bits.
264
+ const BORDER_FEATURE = 1;
265
+ const SHADOW_FEATURE = 2;
266
+ const ROUNDED_SHADER_TYPES = [
267
+ 'rounded',
268
+ 'roundedWithBorder',
269
+ 'roundedWithShadow',
270
+ 'roundedWithBorderWithShadow',
271
+ ];
272
+
273
+ const BORDER_WIDTH_KEYS = [
274
+ 'border-w',
275
+ 'border-top',
276
+ 'border-right',
277
+ 'border-bottom',
278
+ 'border-left',
279
+ ];
280
+
281
+ // Whether a border width is above 0: read from `change` where it has the
282
+ // key, else from `props`. A border of width 0 needs no border shader.
283
+ const hasBorderWidth = (
284
+ props: Record<string, unknown>,
285
+ change?: Record<string, unknown>,
286
+ ) => {
287
+ for (const key of BORDER_WIDTH_KEYS) {
288
+ const w = change !== undefined && key in change ? change[key] : props[key];
289
+ if (isArray(w)) {
290
+ for (let i = 0; i < w.length; i++) if (w[i] > 0) return true;
291
+ } else if ((w as number) > 0) {
292
+ return true;
293
+ }
294
+ }
295
+ return false;
296
+ };
297
+
243
298
  export function convertToShader(
244
- _node: ElementNode,
299
+ node: ElementNode,
245
300
  v: StyleEffects,
246
301
  ): IRendererShader {
247
- let type = 'rounded';
248
- if (v.border) type += 'WithBorder';
249
- if (v.shadow) type += 'WithShadow';
302
+ const props = v as Record<string, unknown>;
303
+ const features =
304
+ (hasBorderWidth(props) ? BORDER_FEATURE : 0) |
305
+ (props.shadow ? SHADOW_FEATURE : 0);
306
+ node._shaderProps = props;
307
+ node._shaderFeatures = features;
250
308
  return renderer.createShader(
251
- type,
252
- v as Record<string, unknown>,
309
+ ROUNDED_SHADER_TYPES[features]!,
310
+ props,
253
311
  ) as IRendererShader;
254
312
  }
255
313
 
@@ -372,6 +430,10 @@ export interface ElementNode extends RendererNode, FocusNode {
372
430
  _containsFlexGrow?: boolean | null;
373
431
  _hasRenderedChildren?: boolean;
374
432
  _effects?: Record<string, any>;
433
+ /** The props of a shader convertToShader made, kept to swap its type. */
434
+ _shaderProps?: Record<string, unknown>;
435
+ /** That shader's ROUNDED_SHADER_TYPES index: border 1, shadow 2. */
436
+ _shaderFeatures?: number;
375
437
  _fontFamily?: string;
376
438
  _id: string | undefined;
377
439
  _parent: ElementNode | undefined;
@@ -385,6 +447,8 @@ export interface ElementNode extends RendererNode, FocusNode {
385
447
  _display?: 'flex' | 'block';
386
448
  _onLayout?: (this: ElementNode, target: ElementNode) => void;
387
449
  _requiresLayout: boolean;
450
+ /** @internal the focus manager's generation stamp for the focus-path diff */
451
+ _focusGen: number;
388
452
  autosize?: boolean;
389
453
  /**
390
454
  * Optional component name for inspector / dev tooling — emitted by the
@@ -857,6 +921,8 @@ export class ElementNode {
857
921
  this._containsFlexGrow = undefined;
858
922
  this._hasRenderedChildren = undefined;
859
923
  this._effects = undefined;
924
+ this._shaderProps = undefined;
925
+ this._shaderFeatures = undefined;
860
926
  this._fontFamily = undefined;
861
927
  this._fontWeight = undefined;
862
928
  this._id = undefined;
@@ -869,6 +935,7 @@ export class ElementNode {
869
935
  this._display = undefined;
870
936
  this._onLayout = undefined;
871
937
  this._requiresLayout = false;
938
+ this._focusGen = 0;
872
939
  }
873
940
 
874
941
  get effects(): StyleEffects | undefined {
@@ -894,16 +961,39 @@ export class ElementNode {
894
961
  }
895
962
  }
896
963
 
964
+ /**
965
+ * Swap a shader convertToShader made when its border width moves to or
966
+ * from 0. For an animated write, `change` holds what animates: a border
967
+ * it adds is swapped in before the animation reads its start values, one
968
+ * it removes stays until the animation stops.
969
+ */
970
+ _syncShaderType(change?: Record<string, unknown>) {
971
+ const props = this._shaderProps;
972
+ if (props === undefined || !this.lng.shader) return;
973
+ const features = this._shaderFeatures!;
974
+ let next = features & SHADOW_FEATURE;
975
+ if (hasBorderWidth(props, change)) next |= BORDER_FEATURE;
976
+ else if (change !== undefined) next |= features & BORDER_FEATURE;
977
+ if (next === features) return;
978
+ this._shaderFeatures = next;
979
+ this.lng.shader = renderer.createShader(
980
+ ROUNDED_SHADER_TYPES[next]!,
981
+ props,
982
+ ) as IRendererShader;
983
+ }
984
+
897
985
  set effects(v: StyleEffects) {
898
986
  if (!SHADERS_ENABLED) return;
899
987
  let target = this.lng.shader || {};
900
988
  if (this.lng.shader?.props) {
901
989
  target = this.lng.shader.props;
902
990
  }
903
- if (v.rounded) target.radius = v.rounded.radius;
904
- if (v.borderRadius) target.radius = v.borderRadius;
905
- for (const k of EFFECT_SHADER_KEYS) {
906
- if (v[k]) parseAndAssignShaderProps(k, v[k], target);
991
+ assignEffects(v, target);
992
+
993
+ const props = this._shaderProps;
994
+ if (props !== undefined) {
995
+ if (props !== target) assignEffects(v, props);
996
+ this._syncShaderType();
907
997
  }
908
998
 
909
999
  this._writeShaderTarget(target);
@@ -953,12 +1043,7 @@ export class ElementNode {
953
1043
  }
954
1044
 
955
1045
  this._fontWeight = v;
956
- const weight =
957
- (Config.fontWeightAlias &&
958
- (Config.fontWeightAlias[v as string] as number | string)) ??
959
- v;
960
- (this.lng as ElementNode).fontFamily =
961
- `${this.fontFamily || Config.fontSettings?.fontFamily}${weight}`;
1046
+ this._writeFontFamily();
962
1047
  }
963
1048
 
964
1049
  get fontWeight() {
@@ -967,13 +1052,38 @@ export class ElementNode {
967
1052
 
968
1053
  set fontFamily(v) {
969
1054
  this._fontFamily = v;
970
- (this.lng as ElementNode).fontFamily = v;
1055
+ this._writeFontFamily();
971
1056
  }
972
1057
 
973
1058
  get fontFamily() {
974
1059
  return this._fontFamily;
975
1060
  }
976
1061
 
1062
+ /**
1063
+ * The renderer's family name from `fontFamily` and `fontWeight`, resolved
1064
+ * in one place so either JSX order gives the same name (B17).
1065
+ */
1066
+ _writeFontFamily() {
1067
+ const weight = this._fontWeight as number | string | undefined;
1068
+ if (weight === undefined) {
1069
+ // No family of its own: before render, undefined lets render's font
1070
+ // template fill it in; after render, write what the template gave
1071
+ // (Config.fontSettings' family and weight, read at the first text
1072
+ // render), not undefined, which the renderer takes as its default.
1073
+ const family = this._fontFamily;
1074
+ (this.lng as ElementNode).fontFamily =
1075
+ family === undefined && this.rendered ? _fontFamilyWithWeight : family;
1076
+ return;
1077
+ }
1078
+ const alias = Config.fontWeightAlias;
1079
+ const aliased =
1080
+ alias !== undefined && alias !== null
1081
+ ? (alias[weight] as number | string | undefined)
1082
+ : undefined;
1083
+ (this.lng as ElementNode).fontFamily =
1084
+ `${this._fontFamily || Config.fontSettings?.fontFamily}${aliased ?? weight}`;
1085
+ }
1086
+
977
1087
  insertChild(
978
1088
  node: ElementNode | ElementText | TextNode,
979
1089
  beforeNode?: ElementNode | ElementText | TextNode | null,
@@ -1040,6 +1150,7 @@ export class ElementNode {
1040
1150
  set shader(
1041
1151
  shaderProps: IRendererShader | [kind: string, props: IRendererShaderProps],
1042
1152
  ) {
1153
+ this._shaderProps = undefined;
1043
1154
  this.lng.shader = isArray(shaderProps)
1044
1155
  ? renderer.createShader(...shaderProps)
1045
1156
  : shaderProps;
@@ -1897,16 +2008,26 @@ export function shaderAccessor<T extends Record<string, any> | number>(
1897
2008
  }
1898
2009
  }
1899
2010
 
1900
- if (key === 'rounded' || typeof value === 'number') {
1901
- target.radius = value;
1902
- } else {
1903
- parseAndAssignShaderProps(key, value, target);
2011
+ assignShaderProp(key, value, target);
2012
+
2013
+ const props = this._shaderProps;
2014
+ if (props !== undefined) {
2015
+ const animated = target !== this.lng.shader?.props;
2016
+ if (animated) this._syncShaderType(target);
2017
+ if (props !== target) assignShaderProp(key, value, props);
2018
+ if (!animated) this._syncShaderType();
1904
2019
  }
1905
2020
 
1906
2021
  this._writeShaderTarget(target);
1907
2022
 
1908
2023
  if (animationSettings) {
1909
- this.animate({ shaderProps: target }, animationSettings).start();
2024
+ const animation = this.animate(
2025
+ { shaderProps: target },
2026
+ animationSettings,
2027
+ ).start();
2028
+ if (props !== undefined) {
2029
+ void animation.waitUntilStopped().then(() => this._syncShaderType());
2030
+ }
1910
2031
  }
1911
2032
  },
1912
2033
  get(this: ElementNode) {
@@ -37,6 +37,11 @@ const flattenKeyMap = (
37
37
  newTargetMap[v] = key;
38
38
  });
39
39
  } else if (value === null) {
40
+ // Unmap every key mapped to this name, defaults included (B4). The
41
+ // entry keyed by the name itself goes too, as it always did.
42
+ for (const mapped in newTargetMap) {
43
+ if (newTargetMap[mapped] === key) delete newTargetMap[mapped];
44
+ }
40
45
  delete newTargetMap[key];
41
46
  } else {
42
47
  newTargetMap[value as KeyNameOrKeyCode] = key;
@@ -298,6 +303,9 @@ const updateFocusPath = (
298
303
  let lastGlobalKeyPressTime = 0;
299
304
  let lastInputKey: string | number | undefined;
300
305
 
306
+ // Per-element throttleInput applies to key presses only, like the global
307
+ // Config.throttleInput: a release is never dropped and never starts a window
308
+ // (B3).
301
309
  const isElementThrottled = (
302
310
  elm: ElementNode,
303
311
  sameKey: boolean,
@@ -372,14 +380,14 @@ const propagateKeyPress = (
372
380
 
373
381
  for (let i = fp.length - 1; i >= 0; i--) {
374
382
  const elm = fp[i]!;
375
- if (isElementThrottled(elm, sameKey, currentTime)) return true;
383
+ if (!isUp && isElementThrottled(elm, sameKey, currentTime)) return true;
376
384
 
377
385
  const captureHandler = elm[captureEvent] || elm[captureKey];
378
386
  if (
379
387
  isFunction(captureHandler) &&
380
388
  captureHandler.call(elm, e, elm, finalFocusElm, mappedEvent) === true
381
389
  ) {
382
- elm._lastAnyKeyPressTime = currentTime;
390
+ if (!isUp) elm._lastAnyKeyPressTime = currentTime;
383
391
  return true;
384
392
  }
385
393
  }
@@ -393,7 +401,7 @@ const propagateKeyPress = (
393
401
 
394
402
  for (let i = 0; i < fp.length; i++) {
395
403
  const elm = fp[i]!;
396
- if (isElementThrottled(elm, sameKey, currentTime)) return true;
404
+ if (!isUp && isElementThrottled(elm, sameKey, currentTime)) return true;
397
405
 
398
406
  let handled = false;
399
407
  if (eventHandlerKey) {
@@ -414,7 +422,7 @@ const propagateKeyPress = (
414
422
  }
415
423
 
416
424
  if (handled) {
417
- elm._lastAnyKeyPressTime = currentTime;
425
+ if (!isUp) elm._lastAnyKeyPressTime = currentTime;
418
426
  return true;
419
427
  }
420
428
  }
@@ -11,6 +11,71 @@ export let renderer: lng.RendererMain | DOMRendererMain;
11
11
 
12
12
  export const getRenderer = () => renderer;
13
13
 
14
+ // @solidtv/renderer 2.0 has one engine (WebGL) and one text engine (SDF), so
15
+ // these settings are gone; apps written for 1.x still pass them.
16
+ const REMOVED_SETTINGS = ['renderEngine', 'fontEngines'];
17
+
18
+ const warned: { [message: string]: true | undefined } = {};
19
+
20
+ /** `console.warn`, once per page, in every build (not only in dev). */
21
+ function warnOnce(message: string) {
22
+ if (warned[message] !== true) {
23
+ warned[message] = true;
24
+ console.warn(message);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * `options` without the settings 2.0 removed, each warned about once. The
30
+ * app's own object is not touched: the same object is returned when it has
31
+ * none of them, a copy when it does.
32
+ */
33
+ function withoutRemovedSettings<T extends object>(options: T): T {
34
+ const source = options as { [name: string]: unknown };
35
+ let found = false;
36
+ for (let i = 0; i < REMOVED_SETTINGS.length; i++) {
37
+ const name = REMOVED_SETTINGS[i]!;
38
+ if (source[name] !== undefined) {
39
+ found = true;
40
+ warnOnce(
41
+ '[solid] Config.rendererOptions.' +
42
+ name +
43
+ ' was removed in @solidtv/renderer 2.0 and is ignored',
44
+ );
45
+ }
46
+ }
47
+ if (found === false) {
48
+ return options;
49
+ }
50
+
51
+ const copy: { [name: string]: unknown } = {};
52
+ const keys = Object.keys(source);
53
+ for (let i = 0; i < keys.length; i++) {
54
+ const key = keys[i]!;
55
+ if (REMOVED_SETTINGS.indexOf(key) === -1) {
56
+ copy[key] = source[key];
57
+ }
58
+ }
59
+ return copy as T;
60
+ }
61
+
62
+ /**
63
+ * 1.10's `renderer.stage.shManager.registerShaderType(...)`: in 2.0 the stage
64
+ * is the renderer and `registerShaderType` is on it. Defined once, here, as an
65
+ * alias of the renderer; it warns the first time an app reads it.
66
+ */
67
+ function aliasShManager(rendererMain: lng.RendererMain) {
68
+ Object.defineProperty(rendererMain, 'shManager', {
69
+ configurable: true,
70
+ get() {
71
+ warnOnce(
72
+ '[solid] renderer.stage.shManager was removed in @solidtv/renderer 2.0: use renderer.registerShaderType',
73
+ );
74
+ return rendererMain;
75
+ },
76
+ });
77
+ }
78
+
14
79
  export function startLightningRenderer(
15
80
  options: lng.RendererMainSettings | DomRendererMainSettings,
16
81
  rootId: string | HTMLElement = 'app',
@@ -18,10 +83,19 @@ export function startLightningRenderer(
18
83
  // Inlined (not isDomRendererActive()) so bundlers can fold DOM_RENDERING to
19
84
  // false and drop the DOMRendererMain branch + import in WebGL builds.
20
85
  const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
21
-
22
- renderer = enableDomRenderer
23
- ? new DOMRendererMain(options, rootId)
24
- : new lng.RendererMain(options, rootId);
86
+ const settings = withoutRemovedSettings(options);
87
+
88
+ if (enableDomRenderer) {
89
+ // Its stage has its own (inert) shManager.
90
+ renderer = new DOMRendererMain(settings, rootId);
91
+ } else {
92
+ const rendererMain = new lng.RendererMain(
93
+ settings as lng.RendererMainSettings,
94
+ rootId,
95
+ );
96
+ aliasShManager(rendererMain);
97
+ renderer = rendererMain;
98
+ }
25
99
 
26
100
  // A stage now exists, so any fonts requested before this point can finish.
27
101
  flushPendingFonts();
@@ -8,11 +8,14 @@ export const NodeType = {
8
8
  export type NodeTypes = (typeof NodeType)[keyof typeof NodeType];
9
9
 
10
10
  export class TextNode {
11
- readonly _type = 'text' as const;
12
- parent: ElementText | undefined = undefined;
13
- text: string;
11
+ // Assigned in the constructor, not class fields (design 3.6.5).
12
+ declare readonly _type: 'text';
13
+ declare parent: ElementText | undefined;
14
+ declare text: string;
14
15
 
15
16
  constructor(text: string) {
17
+ this._type = 'text';
18
+ this.parent = undefined;
16
19
  this.text = text;
17
20
  }
18
21
  }
@@ -150,11 +150,18 @@ function createLazy<T>(
150
150
  // proximity check must use child units.
151
151
  const rendered = container.children.length;
152
152
 
153
+ // B16: the mount lands only after this press (the key handler's writes
154
+ // are batched), so it has to start while this press's move still has a
155
+ // child to land on: a buffer below 2 acts as 2. With buffer 1 the press
156
+ // that reached the rendered edge found no child and bubbled, so every
157
+ // other press was lost.
158
+ const edge = Math.max(buffer(), 2);
159
+
153
160
  // Already mounted everything (offset is in data units — a diverged child
154
161
  // count must neither stop mounting early nor keep it running forever),
155
162
  // or still far enough from the rendered edge that the buffer covers the
156
163
  // next selection — no work to do.
157
- if (offset() >= maxOffset || selected < rendered - buffer()) return;
164
+ if (offset() >= maxOffset || selected < rendered - edge) return;
158
165
 
159
166
  const bump = () => setOffset((prev) => Math.min(prev + 1, maxOffset));
160
167