@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
@@ -6,6 +6,7 @@ Experimental DOM renderer
6
6
  import * as lng from '@solidtv/renderer';
7
7
  import { EventEmitter } from '@solidtv/renderer/utils';
8
8
  import { Config } from '../config.js';
9
+ import { dashedBorderStyle } from './dashedBorderStyle.js';
9
10
  import { applyEasing, applySubTextureScaling, buildGradientStops, colorToRgba, compactString, computeLegacyObjectFit, computeRenderStateForNode, getNodeLineHeight, interpolateProp, isRenderStateInBounds, nodeHasTextureSource, } from './domRendererUtils.js';
10
11
  // Feature detection for legacy brousers
11
12
  const _styleRef = typeof document !== 'undefined' ? document.documentElement?.style || {} : {};
@@ -252,6 +253,44 @@ function applyLegacyObjectFit(node, img, srcPos) {
252
253
  : 0.5;
253
254
  computeLegacyObjectFit(node, img, resizeMode, clipX, clipY, srcPos, supportsObjectFit, supportsObjectPosition);
254
255
  }
256
+ /**
257
+ * The URL an <img> loads for an image source: a string as is; a Blob through
258
+ * an object URL the node makes once and reuses while that Blob stays its
259
+ * source; anything else (ImageData) null, as the DOM can't load it.
260
+ */
261
+ function imageUrlOf(node, source) {
262
+ if (typeof Blob === 'undefined' || !(source instanceof Blob)) {
263
+ node.blobSrc = null;
264
+ node.blobUrl = null;
265
+ return typeof source === 'string' ? source : null;
266
+ }
267
+ // A destroyed node can still be written to (an animation or effect that
268
+ // outlives it): a URL made now would never be revoked.
269
+ if (node.destroyed)
270
+ return null;
271
+ if (node.blobSrc !== source) {
272
+ const url = URL.createObjectURL(source);
273
+ node.blobSrc = source;
274
+ node.blobUrl = url;
275
+ (node.blobUrls ??= new Set()).add(url);
276
+ }
277
+ return node.blobUrl;
278
+ }
279
+ /**
280
+ * Revokes the object URLs `node` made that are no longer in use: all of them
281
+ * once it is destroyed, else all but its current one and the one its <img>
282
+ * still shows (out of bounds, the <img> moves to a new src only on re-entry).
283
+ */
284
+ function releaseBlobUrls(node, all) {
285
+ const urls = node.blobUrls;
286
+ const shown = node.imgEl?.dataset.rawSrc;
287
+ for (const url of urls) {
288
+ if (!all && (url === node.blobUrl || url === shown))
289
+ continue;
290
+ URL.revokeObjectURL(url);
291
+ urls.delete(url);
292
+ }
293
+ }
255
294
  function updateNodeStyles(node) {
256
295
  const { props } = node;
257
296
  let style = `position: absolute; z-index: ${props.zIndex};`;
@@ -394,23 +433,20 @@ function updateNodeStyles(node) {
394
433
  : vGradient || hGradient;
395
434
  let srcImg = null;
396
435
  let srcPos = null;
397
- let rawImgSrc = null;
436
+ let imgSource = props.src;
398
437
  if (props.texture != null &&
399
438
  props.texture.type === lng.TextureType.subTexture) {
400
439
  const texture = props.texture;
401
440
  srcPos = texture.props;
402
- rawImgSrc = texture.props.texture.props.src;
403
- }
404
- else if (typeof props.src === 'string') {
405
- // Renderer 1.8 widened `src` to `string | Blob | ImageData`; the DOM
406
- // renderer only paints string URLs.
407
- rawImgSrc = props.src;
441
+ imgSource = texture.props.texture.props.src;
408
442
  }
443
+ const rawImgSrc = imageUrlOf(node, imgSource);
409
444
  if (rawImgSrc) {
410
445
  srcImg = `url(${rawImgSrc})`;
411
446
  }
412
447
  let bgStyle = '';
413
448
  let borderStyle = '';
449
+ let needsDashedBorderLayer = false;
414
450
  let radiusStyle = '';
415
451
  let maskStyle = '';
416
452
  let needsBackgroundLayer = false;
@@ -567,6 +603,16 @@ function updateNodeStyles(node) {
567
603
  }
568
604
  }
569
605
  }
606
+ // Dashed border: gradient strips with the props' dash and gap, in a
607
+ // layer of its own above the node's fill and below its children, so
608
+ // that it neither grows the node nor moves its children.
609
+ if (props.shader.shaderType === 'dashedBorder') {
610
+ const dashedStyle = dashedBorderStyle(props.w, props.h, shaderProps);
611
+ if (dashedStyle !== '') {
612
+ borderStyle += dashedStyle;
613
+ needsDashedBorderLayer = true;
614
+ }
615
+ }
570
616
  // Rounded
571
617
  if (typeof radius === 'number' && radius > 0) {
572
618
  radiusStyle += `border-radius: ${radius}px;`;
@@ -666,9 +712,12 @@ function updateNodeStyles(node) {
666
712
  }
667
713
  }
668
714
  // If there's still no reason to use divBg, check out tint/gradient/subtexture/radius/bgStyle
715
+ // A dashed border's layer (z-index -1) paints above divBg but below an
716
+ // <img> placed straight in node.div, so the image goes into divBg.
669
717
  if (!needsBackgroundLayer && rawImgSrc) {
670
718
  needsBackgroundLayer =
671
- hasTint ||
719
+ needsDashedBorderLayer ||
720
+ hasTint ||
672
721
  !!gradient ||
673
722
  srcPos !== null ||
674
723
  radiusStyle !== '' ||
@@ -895,7 +944,9 @@ function updateNodeStyles(node) {
895
944
  }
896
945
  style += bgStyle;
897
946
  }
898
- const needsSeparateBorderLayer = needsBackgroundLayer && maskStyle !== '';
947
+ if (node.blobUrls !== null)
948
+ releaseBlobUrls(node, false);
949
+ const needsSeparateBorderLayer = needsDashedBorderLayer || (needsBackgroundLayer && maskStyle !== '');
899
950
  if (needsSeparateBorderLayer) {
900
951
  if (node.divBorder == null) {
901
952
  node.divBorder = document.createElement('div');
@@ -956,6 +1007,10 @@ function getElSize(node) {
956
1007
  function updateDOMTextSize(node, emitLoaded = true) {
957
1008
  let size;
958
1009
  let dimensionsChanged = false;
1010
+ // Text the box (contain, maxLines) clips overflows the element. Read with
1011
+ // the size below, before the writes, so it costs no second layout.
1012
+ const div = node.div;
1013
+ const truncated = div.scrollHeight > div.clientHeight || div.scrollWidth > div.clientWidth;
959
1014
  switch (node.contain) {
960
1015
  case 'width':
961
1016
  size = getElSize(node);
@@ -977,18 +1032,58 @@ function updateDOMTextSize(node, emitLoaded = true) {
977
1032
  }
978
1033
  break;
979
1034
  }
980
- if (emitLoaded && (!node.loaded || dimensionsChanged)) {
1035
+ // Against the size last emitted, not the size before this measure: a
1036
+ // `measure()` (Solid, before its layout) takes the new size without
1037
+ // emitting, and `loaded` listeners must still hear it.
1038
+ if (emitLoaded &&
1039
+ (!node.loaded ||
1040
+ dimensionsChanged ||
1041
+ node.w !== node.loadedW ||
1042
+ node.h !== node.loadedH ||
1043
+ truncated !== node.truncated)) {
981
1044
  const payload = {
982
1045
  type: 'text',
983
1046
  dimensions: {
984
1047
  w: node.w,
985
1048
  h: node.h,
986
1049
  },
1050
+ truncated,
987
1051
  };
1052
+ node.loadedW = node.w;
1053
+ node.loadedH = node.h;
1054
+ node.truncated = truncated;
988
1055
  node.emit('loaded', payload);
989
1056
  node.loaded = true;
990
1057
  }
991
1058
  }
1059
+ /**
1060
+ * Whether the text's font is loaded, as `document.fonts.check` says (a
1061
+ * family no font face names counts as loaded: a system font). Without a
1062
+ * FontFaceSet, or for a font string it cannot parse, it is taken as loaded.
1063
+ */
1064
+ function isFontLoaded(node) {
1065
+ if (typeof document === 'undefined') {
1066
+ return true;
1067
+ }
1068
+ const fonts = document.fonts;
1069
+ if (fonts === undefined ||
1070
+ fonts === null ||
1071
+ typeof fonts.check !== 'function') {
1072
+ return true;
1073
+ }
1074
+ let font = node.font;
1075
+ if (font === undefined) {
1076
+ const props = node.props;
1077
+ font = `${props.fontStyle} ${props.fontWeight} ${props.fontSize}px "${props.fontFamily}"`;
1078
+ node.font = font;
1079
+ }
1080
+ try {
1081
+ return fonts.check(font);
1082
+ }
1083
+ catch {
1084
+ return true;
1085
+ }
1086
+ }
992
1087
  function updateDOMTextMeasurements() {
993
1088
  textNodesToMeasure.forEach((node) => updateDOMTextSize(node));
994
1089
  textNodesToMeasure.clear();
@@ -1164,6 +1259,11 @@ export class DOMNode extends EventEmitter {
1164
1259
  imageLoading = false;
1165
1260
  lazyImagePendingSrc = null;
1166
1261
  lazyImageSubTextureProps = null;
1262
+ /** The Blob image source shown through `blobUrl`, if the source is one. */
1263
+ blobSrc = null;
1264
+ blobUrl = null;
1265
+ /** Object URLs this node made and has not revoked yet. */
1266
+ blobUrls = null;
1167
1267
  boundsDirty = true;
1168
1268
  children = new Set();
1169
1269
  /** Cached result of the last updateNodeStyles call — avoids redundant setAttribute writes. */
@@ -1200,6 +1300,8 @@ export class DOMNode extends EventEmitter {
1200
1300
  // Like CoreNode, destroying a node marks its whole subtree destroyed.
1201
1301
  markDestroyed() {
1202
1302
  this.destroyed = true;
1303
+ if (this.blobUrls !== null)
1304
+ releaseBlobUrls(this, true);
1203
1305
  for (const child of this.children) {
1204
1306
  child.markDestroyed();
1205
1307
  }
@@ -1224,6 +1326,57 @@ export class DOMNode extends EventEmitter {
1224
1326
  this.markChildrenBoundsDirty();
1225
1327
  updateNodeParent(this);
1226
1328
  }
1329
+ /**
1330
+ * Renderer v2's `Node.insertBefore`: makes `child` a child of this node,
1331
+ * before `before` (`null`, or a node that is not a child, appends); a child
1332
+ * of this node moves, and one placed before itself stays. A destroyed
1333
+ * parent or child does nothing; a destroyed `before` appends. The div order
1334
+ * is the paint order among equal z-index, as v2's sibling order is its
1335
+ * draw order.
1336
+ */
1337
+ insertBefore(child, before) {
1338
+ if (!(child instanceof DOMNode) ||
1339
+ child === before ||
1340
+ !elMap.has(this) ||
1341
+ !elMap.has(child)) {
1342
+ return;
1343
+ }
1344
+ const anchor = before instanceof DOMNode &&
1345
+ before.props.parent === this &&
1346
+ elMap.has(before)
1347
+ ? before
1348
+ : null;
1349
+ // A new parent: adds it to this node's children and appends its div.
1350
+ child.parent = this;
1351
+ const children = this.children;
1352
+ children.delete(child);
1353
+ if (anchor === null) {
1354
+ children.add(child);
1355
+ this.div.appendChild(child.div);
1356
+ }
1357
+ else {
1358
+ // A Set keeps insertion order: add the child at the end, then move the
1359
+ // anchor and everything after it behind the child (no array: stop at
1360
+ // the last one before the child, as re-added entries come after it).
1361
+ let last;
1362
+ for (const c of children)
1363
+ last = c;
1364
+ children.add(child);
1365
+ let moving = false;
1366
+ for (const c of children) {
1367
+ if (c === anchor)
1368
+ moving = true;
1369
+ if (moving) {
1370
+ children.delete(c);
1371
+ children.add(c);
1372
+ }
1373
+ if (c === last)
1374
+ break;
1375
+ }
1376
+ this.div.insertBefore(child.div, anchor.div);
1377
+ }
1378
+ this.markChildrenBoundsDirty();
1379
+ }
1227
1380
  markChildrenBoundsDirty() {
1228
1381
  for (const child of this.children) {
1229
1382
  child.boundsDirty = true;
@@ -1288,8 +1441,9 @@ export class DOMNode extends EventEmitter {
1288
1441
  this.imgEl.style.display = '';
1289
1442
  this.imgEl.dataset.pendingSrc = pendingSrc;
1290
1443
  // crossOrigin + data: URI fails to load on old WebKit engines (e.g. PS4 WebMAF) —
1291
- // only request CORS for real network sources, never for inlined base64 images.
1292
- if (pendingSrc.startsWith('data:')) {
1444
+ // only request CORS for real network sources, never for inlined base64
1445
+ // images or same-origin object URLs.
1446
+ if (pendingSrc.startsWith('data:') || pendingSrc.startsWith('blob:')) {
1293
1447
  this.imgEl.removeAttribute('crossorigin');
1294
1448
  }
1295
1449
  else {
@@ -1298,6 +1452,9 @@ export class DOMNode extends EventEmitter {
1298
1452
  this.imgEl.src = pendingSrc;
1299
1453
  this.imgEl.dataset.rawSrc = pendingSrc;
1300
1454
  this.imgEl.dataset.pendingSrc = '';
1455
+ // The <img> has moved off the object URL it showed out of bounds.
1456
+ if (this.blobUrls !== null)
1457
+ releaseBlobUrls(this, false);
1301
1458
  }
1302
1459
  get x() {
1303
1460
  return this.props.x;
@@ -1682,6 +1839,13 @@ export class DOMNode extends EventEmitter {
1682
1839
  class DOMText extends DOMNode {
1683
1840
  props;
1684
1841
  loaded = false;
1842
+ /** The size `loaded` last told (updateDOMTextSize). */
1843
+ loadedW = 0;
1844
+ loadedH = 0;
1845
+ /** Whether the text last told by `loaded` did not all fit (renderer v2's `TextNode.truncated`). */
1846
+ truncated = false;
1847
+ /** Its CSS font, for document.fonts.check; undefined once a font prop changes. */
1848
+ font = undefined;
1685
1849
  constructor(stage, props) {
1686
1850
  super(stage, props);
1687
1851
  this.props = props;
@@ -1696,6 +1860,20 @@ class DOMText extends DOMNode {
1696
1860
  containTextNodes.delete(this);
1697
1861
  super.destroy();
1698
1862
  }
1863
+ /**
1864
+ * Renderer v2's `TextNode.measure()`: sizes the text now, synchronously
1865
+ * (`getBoundingClientRect`), when its font is loaded, and returns true.
1866
+ * While it is not (document.fonts.check), returns false and measures
1867
+ * nothing: the async measurement emits `loaded` once it is. False for a
1868
+ * destroyed node too.
1869
+ */
1870
+ measure() {
1871
+ if (!elMap.has(this) || !isFontLoaded(this)) {
1872
+ return false;
1873
+ }
1874
+ updateDOMTextSize(this, false);
1875
+ return true;
1876
+ }
1699
1877
  get text() {
1700
1878
  return this.props.text;
1701
1879
  }
@@ -1713,6 +1891,7 @@ class DOMText extends DOMNode {
1713
1891
  if (this.props.fontFamily === v)
1714
1892
  return;
1715
1893
  this.props.fontFamily = v;
1894
+ this.font = undefined;
1716
1895
  updateNodeStyles(this);
1717
1896
  scheduleUpdateDOMTextMeasurement(this);
1718
1897
  }
@@ -1723,6 +1902,7 @@ class DOMText extends DOMNode {
1723
1902
  if (this.props.fontSize === v)
1724
1903
  return;
1725
1904
  this.props.fontSize = v;
1905
+ this.font = undefined;
1726
1906
  updateNodeStyles(this);
1727
1907
  scheduleUpdateDOMTextMeasurement(this);
1728
1908
  }
@@ -1733,6 +1913,7 @@ class DOMText extends DOMNode {
1733
1913
  if (this.props.fontStyle === v)
1734
1914
  return;
1735
1915
  this.props.fontStyle = v;
1916
+ this.font = undefined;
1736
1917
  updateNodeStyles(this);
1737
1918
  scheduleUpdateDOMTextMeasurement(this);
1738
1919
  }
@@ -1743,6 +1924,7 @@ class DOMText extends DOMNode {
1743
1924
  if (this.props.fontWeight === v)
1744
1925
  return;
1745
1926
  this.props.fontWeight = v;
1927
+ this.font = undefined;
1746
1928
  updateNodeStyles(this);
1747
1929
  scheduleUpdateDOMTextMeasurement(this);
1748
1930
  }