@solidtv/solid 1.7.3 → 1.8.0-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 (73) hide show
  1. package/MIGRATION-1.8.md +270 -0
  2. package/dist/src/core/dom-renderer/dashedBorderStyle.d.ts +20 -0
  3. package/dist/src/core/dom-renderer/dashedBorderStyle.js +104 -0
  4. package/dist/src/core/dom-renderer/dashedBorderStyle.js.map +1 -0
  5. package/dist/src/core/dom-renderer/domRenderer.d.ts +14 -0
  6. package/dist/src/core/dom-renderer/domRenderer.js +194 -12
  7. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  8. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +12 -2
  9. package/dist/src/core/elementNode.d.ts +176 -9
  10. package/dist/src/core/elementNode.js +1906 -411
  11. package/dist/src/core/elementNode.js.map +1 -1
  12. package/dist/src/core/flexLayout.d.ts +6 -0
  13. package/dist/src/core/flexLayout.js +535 -218
  14. package/dist/src/core/flexLayout.js.map +1 -1
  15. package/dist/src/core/focusManager.js +70 -23
  16. package/dist/src/core/focusManager.js.map +1 -1
  17. package/dist/src/core/fontLoaded.d.ts +10 -0
  18. package/dist/src/core/fontLoaded.js +26 -0
  19. package/dist/src/core/fontLoaded.js.map +1 -0
  20. package/dist/src/core/intrinsicTypes.d.ts +2 -1
  21. package/dist/src/core/lightningInit.js +8 -1
  22. package/dist/src/core/lightningInit.js.map +1 -1
  23. package/dist/src/core/shaders.d.ts +5 -2
  24. package/dist/src/core/shaders.js +6 -0
  25. package/dist/src/core/shaders.js.map +1 -1
  26. package/dist/src/core/states.d.ts +2 -0
  27. package/dist/src/core/states.js +26 -7
  28. package/dist/src/core/states.js.map +1 -1
  29. package/dist/src/core/stylePlan.d.ts +39 -0
  30. package/dist/src/core/stylePlan.js +159 -0
  31. package/dist/src/core/stylePlan.js.map +1 -0
  32. package/dist/src/core/utils.js +2 -2
  33. package/dist/src/primitives/Grid.d.ts +7 -1
  34. package/dist/src/primitives/Grid.jsx +48 -4
  35. package/dist/src/primitives/Grid.jsx.map +1 -1
  36. package/dist/src/primitives/Virtual.jsx +16 -6
  37. package/dist/src/primitives/Virtual.jsx.map +1 -1
  38. package/dist/src/primitives/useMouse.d.ts +10 -5
  39. package/dist/src/primitives/useMouse.js +42 -10
  40. package/dist/src/primitives/useMouse.js.map +1 -1
  41. package/dist/src/primitives/utils/handleNavigation.js +29 -6
  42. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  43. package/dist/src/primitives/utils/withScrolling.js +2 -1
  44. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  45. package/dist/src/solidOpts.js +22 -8
  46. package/dist/src/solidOpts.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/docs/AI_CODING_GUIDELINES.md +7 -6
  49. package/docs/AI_UPGRADE_1.8.md +290 -0
  50. package/package.json +5 -3
  51. package/src/core/dom-renderer/dashedBorderStyle.ts +128 -0
  52. package/src/core/dom-renderer/domRenderer.ts +201 -10
  53. package/src/core/dom-renderer/domRendererTypes.ts +12 -0
  54. package/src/core/elementNode.ts +2124 -459
  55. package/src/core/flexLayout.ts +583 -231
  56. package/src/core/focusManager.ts +86 -27
  57. package/src/core/fontLoaded.ts +29 -0
  58. package/src/core/intrinsicTypes.ts +2 -0
  59. package/src/core/lightningInit.ts +8 -1
  60. package/src/core/shaders.ts +12 -0
  61. package/src/core/states.ts +29 -9
  62. package/src/core/stylePlan.ts +195 -0
  63. package/src/core/utils.ts +2 -2
  64. package/src/primitives/Grid.tsx +66 -14
  65. package/src/primitives/Virtual.tsx +20 -6
  66. package/src/primitives/useMouse.ts +73 -6
  67. package/src/primitives/utils/handleNavigation.ts +40 -6
  68. package/src/primitives/utils/withScrolling.ts +3 -2
  69. package/src/solidOpts.ts +23 -8
  70. package/dist/src/core/flex.d.ts +0 -2
  71. package/dist/src/core/flex.js +0 -285
  72. package/dist/src/core/flex.js.map +0 -1
  73. package/src/core/flex.ts +0 -332
@@ -9,6 +9,7 @@ import * as lng from '@solidtv/renderer';
9
9
  import { EventEmitter } from '@solidtv/renderer/utils';
10
10
  import { Config } from '../config.js';
11
11
  import { FontLoadOptions } from '../intrinsicTypes.js';
12
+ import { dashedBorderStyle } from './dashedBorderStyle.js';
12
13
  import type {
13
14
  DomRendererMainSettings,
14
15
  ExtractProps,
@@ -327,6 +328,44 @@ function applyLegacyObjectFit(
327
328
  );
328
329
  }
329
330
 
331
+ /**
332
+ * The URL an <img> loads for an image source: a string as is; a Blob through
333
+ * an object URL the node makes once and reuses while that Blob stays its
334
+ * source; anything else (ImageData) null, as the DOM can't load it.
335
+ */
336
+ function imageUrlOf(node: DOMNode, source: unknown): string | null {
337
+ if (typeof Blob === 'undefined' || !(source instanceof Blob)) {
338
+ node.blobSrc = null;
339
+ node.blobUrl = null;
340
+ return typeof source === 'string' ? source : null;
341
+ }
342
+ // A destroyed node can still be written to (an animation or effect that
343
+ // outlives it): a URL made now would never be revoked.
344
+ if (node.destroyed) return null;
345
+ if (node.blobSrc !== source) {
346
+ const url = URL.createObjectURL(source);
347
+ node.blobSrc = source;
348
+ node.blobUrl = url;
349
+ (node.blobUrls ??= new Set()).add(url);
350
+ }
351
+ return node.blobUrl;
352
+ }
353
+
354
+ /**
355
+ * Revokes the object URLs `node` made that are no longer in use: all of them
356
+ * once it is destroyed, else all but its current one and the one its <img>
357
+ * still shows (out of bounds, the <img> moves to a new src only on re-entry).
358
+ */
359
+ function releaseBlobUrls(node: DOMNode, all: boolean) {
360
+ const urls = node.blobUrls!;
361
+ const shown = node.imgEl?.dataset.rawSrc;
362
+ for (const url of urls) {
363
+ if (!all && (url === node.blobUrl || url === shown)) continue;
364
+ URL.revokeObjectURL(url);
365
+ urls.delete(url);
366
+ }
367
+ }
368
+
330
369
  function updateNodeStyles(node: DOMNode | DOMText) {
331
370
  const { props } = node;
332
371
 
@@ -483,7 +522,7 @@ function updateNodeStyles(node: DOMNode | DOMText) {
483
522
  let srcImg: string | null = null;
484
523
  let srcPos: null | InstanceType<lng.TextureMap['SubTexture']>['props'] =
485
524
  null;
486
- let rawImgSrc: string | null = null;
525
+ let imgSource: unknown = props.src;
487
526
 
488
527
  if (
489
528
  props.texture != null &&
@@ -493,19 +532,18 @@ function updateNodeStyles(node: DOMNode | DOMText) {
493
532
  lng.TextureMap['SubTexture']
494
533
  >;
495
534
  srcPos = texture.props;
496
- rawImgSrc = (texture.props.texture as any).props.src;
497
- } else if (typeof props.src === 'string') {
498
- // Renderer 1.8 widened `src` to `string | Blob | ImageData`; the DOM
499
- // renderer only paints string URLs.
500
- rawImgSrc = props.src;
535
+ imgSource = (texture.props.texture as any).props.src;
501
536
  }
502
537
 
538
+ const rawImgSrc = imageUrlOf(node, imgSource);
539
+
503
540
  if (rawImgSrc) {
504
541
  srcImg = `url(${rawImgSrc})`;
505
542
  }
506
543
 
507
544
  let bgStyle = '';
508
545
  let borderStyle = '';
546
+ let needsDashedBorderLayer = false;
509
547
  let radiusStyle = '';
510
548
  let maskStyle = '';
511
549
  let needsBackgroundLayer = false;
@@ -677,6 +715,16 @@ function updateNodeStyles(node: DOMNode | DOMText) {
677
715
  }
678
716
  }
679
717
  }
718
+ // Dashed border: gradient strips with the props' dash and gap, in a
719
+ // layer of its own above the node's fill and below its children, so
720
+ // that it neither grows the node nor moves its children.
721
+ if (props.shader.shaderType === 'dashedBorder') {
722
+ const dashedStyle = dashedBorderStyle(props.w, props.h, shaderProps);
723
+ if (dashedStyle !== '') {
724
+ borderStyle += dashedStyle;
725
+ needsDashedBorderLayer = true;
726
+ }
727
+ }
680
728
  // Rounded
681
729
  if (typeof radius === 'number' && radius > 0) {
682
730
  radiusStyle += `border-radius: ${radius}px;`;
@@ -776,8 +824,11 @@ function updateNodeStyles(node: DOMNode | DOMText) {
776
824
  }
777
825
 
778
826
  // If there's still no reason to use divBg, check out tint/gradient/subtexture/radius/bgStyle
827
+ // A dashed border's layer (z-index -1) paints above divBg but below an
828
+ // <img> placed straight in node.div, so the image goes into divBg.
779
829
  if (!needsBackgroundLayer && rawImgSrc) {
780
830
  needsBackgroundLayer =
831
+ needsDashedBorderLayer ||
781
832
  hasTint ||
782
833
  !!gradient ||
783
834
  srcPos !== null ||
@@ -1053,7 +1104,10 @@ function updateNodeStyles(node: DOMNode | DOMText) {
1053
1104
  style += bgStyle;
1054
1105
  }
1055
1106
 
1056
- const needsSeparateBorderLayer = needsBackgroundLayer && maskStyle !== '';
1107
+ if (node.blobUrls !== null) releaseBlobUrls(node, false);
1108
+
1109
+ const needsSeparateBorderLayer =
1110
+ needsDashedBorderLayer || (needsBackgroundLayer && maskStyle !== '');
1057
1111
 
1058
1112
  if (needsSeparateBorderLayer) {
1059
1113
  if (node.divBorder == null) {
@@ -1123,6 +1177,11 @@ function getElSize(node: DOMNode): Size {
1123
1177
  function updateDOMTextSize(node: DOMText, emitLoaded = true): void {
1124
1178
  let size: Size;
1125
1179
  let dimensionsChanged = false;
1180
+ // Text the box (contain, maxLines) clips overflows the element. Read with
1181
+ // the size below, before the writes, so it costs no second layout.
1182
+ const div = node.div;
1183
+ const truncated =
1184
+ div.scrollHeight > div.clientHeight || div.scrollWidth > div.clientWidth;
1126
1185
  switch (node.contain) {
1127
1186
  case 'width':
1128
1187
  size = getElSize(node);
@@ -1145,19 +1204,63 @@ function updateDOMTextSize(node: DOMText, emitLoaded = true): void {
1145
1204
  break;
1146
1205
  }
1147
1206
 
1148
- if (emitLoaded && (!node.loaded || dimensionsChanged)) {
1207
+ // Against the size last emitted, not the size before this measure: a
1208
+ // `measure()` (Solid, before its layout) takes the new size without
1209
+ // emitting, and `loaded` listeners must still hear it.
1210
+ if (
1211
+ emitLoaded &&
1212
+ (!node.loaded ||
1213
+ dimensionsChanged ||
1214
+ node.w !== node.loadedW ||
1215
+ node.h !== node.loadedH ||
1216
+ truncated !== node.truncated)
1217
+ ) {
1149
1218
  const payload: lng.NodeTextLoadedPayload = {
1150
1219
  type: 'text',
1151
1220
  dimensions: {
1152
1221
  w: node.w,
1153
1222
  h: node.h,
1154
1223
  },
1224
+ truncated,
1155
1225
  };
1226
+ node.loadedW = node.w;
1227
+ node.loadedH = node.h;
1228
+ node.truncated = truncated;
1156
1229
  node.emit('loaded', payload);
1157
1230
  node.loaded = true;
1158
1231
  }
1159
1232
  }
1160
1233
 
1234
+ /**
1235
+ * Whether the text's font is loaded, as `document.fonts.check` says (a
1236
+ * family no font face names counts as loaded: a system font). Without a
1237
+ * FontFaceSet, or for a font string it cannot parse, it is taken as loaded.
1238
+ */
1239
+ function isFontLoaded(node: DOMText): boolean {
1240
+ if (typeof document === 'undefined') {
1241
+ return true;
1242
+ }
1243
+ const fonts = document.fonts as FontFaceSet | undefined;
1244
+ if (
1245
+ fonts === undefined ||
1246
+ fonts === null ||
1247
+ typeof fonts.check !== 'function'
1248
+ ) {
1249
+ return true;
1250
+ }
1251
+ let font = node.font;
1252
+ if (font === undefined) {
1253
+ const props = node.props;
1254
+ font = `${props.fontStyle} ${props.fontWeight} ${props.fontSize}px "${props.fontFamily}"`;
1255
+ node.font = font;
1256
+ }
1257
+ try {
1258
+ return fonts.check(font);
1259
+ } catch {
1260
+ return true;
1261
+ }
1262
+ }
1263
+
1161
1264
  function updateDOMTextMeasurements() {
1162
1265
  textNodesToMeasure.forEach((node) => updateDOMTextSize(node));
1163
1266
  textNodesToMeasure.clear();
@@ -1354,6 +1457,11 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1354
1457
  lazyImageSubTextureProps:
1355
1458
  | InstanceType<lng.TextureMap['SubTexture']>['props']
1356
1459
  | null = null;
1460
+ /** The Blob image source shown through `blobUrl`, if the source is one. */
1461
+ blobSrc: Blob | null = null;
1462
+ blobUrl: string | null = null;
1463
+ /** Object URLs this node made and has not revoked yet. */
1464
+ blobUrls: Set<string> | null = null;
1357
1465
  boundsDirty = true;
1358
1466
  children = new Set<DOMNode>();
1359
1467
  /** Cached result of the last updateNodeStyles call — avoids redundant setAttribute writes. */
@@ -1401,6 +1509,7 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1401
1509
  // Like CoreNode, destroying a node marks its whole subtree destroyed.
1402
1510
  private markDestroyed() {
1403
1511
  this.destroyed = true;
1512
+ if (this.blobUrls !== null) releaseBlobUrls(this, true);
1404
1513
  for (const child of this.children) {
1405
1514
  child.markDestroyed();
1406
1515
  }
@@ -1430,6 +1539,59 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1430
1539
  updateNodeParent(this);
1431
1540
  }
1432
1541
 
1542
+ /**
1543
+ * Renderer v2's `Node.insertBefore`: makes `child` a child of this node,
1544
+ * before `before` (`null`, or a node that is not a child, appends); a child
1545
+ * of this node moves, and one placed before itself stays. A destroyed
1546
+ * parent or child does nothing; a destroyed `before` appends. The div order
1547
+ * is the paint order among equal z-index, as v2's sibling order is its
1548
+ * draw order.
1549
+ */
1550
+ insertBefore(child: IRendererNode, before: IRendererNode | null): void {
1551
+ if (
1552
+ !(child instanceof DOMNode) ||
1553
+ child === before ||
1554
+ !elMap.has(this) ||
1555
+ !elMap.has(child)
1556
+ ) {
1557
+ return;
1558
+ }
1559
+ const anchor =
1560
+ before instanceof DOMNode &&
1561
+ before.props.parent === this &&
1562
+ elMap.has(before)
1563
+ ? before
1564
+ : null;
1565
+
1566
+ // A new parent: adds it to this node's children and appends its div.
1567
+ child.parent = this;
1568
+
1569
+ const children = this.children;
1570
+ children.delete(child);
1571
+ if (anchor === null) {
1572
+ children.add(child);
1573
+ this.div.appendChild(child.div);
1574
+ } else {
1575
+ // A Set keeps insertion order: add the child at the end, then move the
1576
+ // anchor and everything after it behind the child (no array: stop at
1577
+ // the last one before the child, as re-added entries come after it).
1578
+ let last: DOMNode | undefined;
1579
+ for (const c of children) last = c;
1580
+ children.add(child);
1581
+ let moving = false;
1582
+ for (const c of children) {
1583
+ if (c === anchor) moving = true;
1584
+ if (moving) {
1585
+ children.delete(c);
1586
+ children.add(c);
1587
+ }
1588
+ if (c === last) break;
1589
+ }
1590
+ this.div.insertBefore(child.div, anchor.div);
1591
+ }
1592
+ this.markChildrenBoundsDirty();
1593
+ }
1594
+
1433
1595
  public markChildrenBoundsDirty() {
1434
1596
  for (const child of this.children) {
1435
1597
  child.boundsDirty = true;
@@ -1499,8 +1661,9 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1499
1661
  this.imgEl.style.display = '';
1500
1662
  this.imgEl.dataset.pendingSrc = pendingSrc;
1501
1663
  // crossOrigin + data: URI fails to load on old WebKit engines (e.g. PS4 WebMAF) —
1502
- // only request CORS for real network sources, never for inlined base64 images.
1503
- if (pendingSrc.startsWith('data:')) {
1664
+ // only request CORS for real network sources, never for inlined base64
1665
+ // images or same-origin object URLs.
1666
+ if (pendingSrc.startsWith('data:') || pendingSrc.startsWith('blob:')) {
1504
1667
  this.imgEl.removeAttribute('crossorigin');
1505
1668
  } else {
1506
1669
  this.imgEl.crossOrigin = 'anonymous';
@@ -1508,6 +1671,8 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1508
1671
  this.imgEl.src = pendingSrc;
1509
1672
  this.imgEl.dataset.rawSrc = pendingSrc;
1510
1673
  this.imgEl.dataset.pendingSrc = '';
1674
+ // The <img> has moved off the object URL it showed out of bounds.
1675
+ if (this.blobUrls !== null) releaseBlobUrls(this, false);
1511
1676
  }
1512
1677
 
1513
1678
  get x() {
@@ -1883,6 +2048,13 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1883
2048
 
1884
2049
  class DOMText extends DOMNode {
1885
2050
  public loaded = false;
2051
+ /** The size `loaded` last told (updateDOMTextSize). */
2052
+ public loadedW = 0;
2053
+ public loadedH = 0;
2054
+ /** Whether the text last told by `loaded` did not all fit (renderer v2's `TextNode.truncated`). */
2055
+ public truncated = false;
2056
+ /** Its CSS font, for document.fonts.check; undefined once a font prop changes. */
2057
+ public font: string | undefined = undefined;
1886
2058
 
1887
2059
  constructor(
1888
2060
  stage: IRendererStage,
@@ -1902,6 +2074,21 @@ class DOMText extends DOMNode {
1902
2074
  super.destroy();
1903
2075
  }
1904
2076
 
2077
+ /**
2078
+ * Renderer v2's `TextNode.measure()`: sizes the text now, synchronously
2079
+ * (`getBoundingClientRect`), when its font is loaded, and returns true.
2080
+ * While it is not (document.fonts.check), returns false and measures
2081
+ * nothing: the async measurement emits `loaded` once it is. False for a
2082
+ * destroyed node too.
2083
+ */
2084
+ measure(): boolean {
2085
+ if (!elMap.has(this) || !isFontLoaded(this)) {
2086
+ return false;
2087
+ }
2088
+ updateDOMTextSize(this, false);
2089
+ return true;
2090
+ }
2091
+
1905
2092
  get text() {
1906
2093
  return this.props.text;
1907
2094
  }
@@ -1917,6 +2104,7 @@ class DOMText extends DOMNode {
1917
2104
  set fontFamily(v) {
1918
2105
  if (this.props.fontFamily === v) return;
1919
2106
  this.props.fontFamily = v;
2107
+ this.font = undefined;
1920
2108
  updateNodeStyles(this);
1921
2109
  scheduleUpdateDOMTextMeasurement(this);
1922
2110
  }
@@ -1926,6 +2114,7 @@ class DOMText extends DOMNode {
1926
2114
  set fontSize(v) {
1927
2115
  if (this.props.fontSize === v) return;
1928
2116
  this.props.fontSize = v;
2117
+ this.font = undefined;
1929
2118
  updateNodeStyles(this);
1930
2119
  scheduleUpdateDOMTextMeasurement(this);
1931
2120
  }
@@ -1935,6 +2124,7 @@ class DOMText extends DOMNode {
1935
2124
  set fontStyle(v) {
1936
2125
  if (this.props.fontStyle === v) return;
1937
2126
  this.props.fontStyle = v;
2127
+ this.font = undefined;
1938
2128
  updateNodeStyles(this);
1939
2129
  scheduleUpdateDOMTextMeasurement(this);
1940
2130
  }
@@ -1944,6 +2134,7 @@ class DOMText extends DOMNode {
1944
2134
  set fontWeight(v) {
1945
2135
  if (this.props.fontWeight === v) return;
1946
2136
  this.props.fontWeight = v;
2137
+ this.font = undefined;
1947
2138
  updateNodeStyles(this);
1948
2139
  scheduleUpdateDOMTextMeasurement(this);
1949
2140
  }
@@ -2,6 +2,7 @@ import * as lng from '@solidtv/renderer';
2
2
  import { EventEmitter } from '@solidtv/renderer/utils';
3
3
  import {
4
4
  ShaderBorderPrefixedProps,
5
+ ShaderDashedBorderProps,
5
6
  ShaderHolePunchProps,
6
7
  ShaderLinearGradientProps,
7
8
  ShaderRadialGradientProps,
@@ -45,6 +46,7 @@ export type IRendererShaderProps = Partial<ShaderBorderPrefixedProps> &
45
46
  Partial<ShaderShadowPrefixedProps> &
46
47
  Partial<ShaderRoundedProps> &
47
48
  Partial<ShaderHolePunchProps> &
49
+ Partial<ShaderDashedBorderProps> &
48
50
  Partial<ShaderRadialGradientProps> &
49
51
  Partial<ShaderLinearGradientProps>;
50
52
 
@@ -80,6 +82,10 @@ export interface IRendererNodeShaded extends EventEmitter {
80
82
  ) => lng.IAnimationController;
81
83
  get absX(): number;
82
84
  get absY(): number;
85
+ /** Renderer v2's `Node.destroyed`: true once destroyed. */
86
+ get destroyed(): boolean;
87
+ /** Renderer v2's `Node.insertBefore` (draw order follows Solid's children). */
88
+ insertBefore(child: IRendererNode, before: IRendererNode | null): void;
83
89
  }
84
90
 
85
91
  /** Based on {@link lng.INodeProps} */
@@ -115,6 +121,12 @@ export interface IRendererTextNode
115
121
  div?: HTMLElement;
116
122
  props: IRendererTextNodeProps;
117
123
  renderState: lng.CoreNodeRenderState;
124
+ /**
125
+ * Renderer v2's `TextNode.measure()`: lays the text out now, outside the
126
+ * walk, so `w` and `h` read its size at once; false, changing nothing,
127
+ * while its font is not loaded (and for a destroyed node).
128
+ */
129
+ measure(): boolean;
118
130
  }
119
131
 
120
132
  /** Based on {@link lng.RendererMain} */