@solidtv/solid 1.6.5 → 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 (60) hide show
  1. package/dist/src/core/dom-renderer/domRenderer.d.ts +7 -7
  2. package/dist/src/core/dom-renderer/domRenderer.js +1 -9
  3. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  4. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +4 -4
  5. package/dist/src/core/elementNode.d.ts +23 -5
  6. package/dist/src/core/elementNode.js +194 -45
  7. package/dist/src/core/elementNode.js.map +1 -1
  8. package/dist/src/core/flex.js +2 -1
  9. package/dist/src/core/flex.js.map +1 -1
  10. package/dist/src/core/focusManager.js +144 -99
  11. package/dist/src/core/focusManager.js.map +1 -1
  12. package/dist/src/core/index.d.ts +3 -0
  13. package/dist/src/core/index.js +2 -0
  14. package/dist/src/core/index.js.map +1 -1
  15. package/dist/src/core/intrinsicTypes.d.ts +5 -2
  16. package/dist/src/core/lightningInit.d.ts +2 -2
  17. package/dist/src/core/lightningInit.js +71 -32
  18. package/dist/src/core/lightningInit.js.map +1 -1
  19. package/dist/src/core/nodeTypes.d.ts +1 -1
  20. package/dist/src/core/nodeTypes.js +2 -3
  21. package/dist/src/core/nodeTypes.js.map +1 -1
  22. package/dist/src/core/shaders.d.ts +1 -1
  23. package/dist/src/core/states.js +20 -4
  24. package/dist/src/core/states.js.map +1 -1
  25. package/dist/src/primitives/FPSCounter.jsx +3 -3
  26. package/dist/src/primitives/FPSCounter.jsx.map +1 -1
  27. package/dist/src/primitives/Image.jsx +2 -10
  28. package/dist/src/primitives/Image.jsx.map +1 -1
  29. package/dist/src/primitives/Lazy.jsx +7 -1
  30. package/dist/src/primitives/Lazy.jsx.map +1 -1
  31. package/dist/src/primitives/Virtual.d.ts +4 -0
  32. package/dist/src/primitives/Virtual.jsx +192 -106
  33. package/dist/src/primitives/Virtual.jsx.map +1 -1
  34. package/dist/src/primitives/VirtualGrid.jsx +87 -18
  35. package/dist/src/primitives/VirtualGrid.jsx.map +1 -1
  36. package/dist/src/primitives/utils/handleNavigation.js +12 -5
  37. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  38. package/dist/src/primitives/utils/withScrolling.js +63 -57
  39. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  40. package/dist/src/render.d.ts +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +12 -5
  43. package/src/core/dom-renderer/domRenderer.ts +4 -12
  44. package/src/core/dom-renderer/domRendererTypes.ts +4 -4
  45. package/src/core/elementNode.ts +219 -50
  46. package/src/core/flex.ts +2 -1
  47. package/src/core/focusManager.ts +173 -135
  48. package/src/core/index.ts +4 -0
  49. package/src/core/intrinsicTypes.ts +10 -2
  50. package/src/core/lightningInit.ts +85 -35
  51. package/src/core/nodeTypes.ts +6 -3
  52. package/src/core/shaders.ts +1 -1
  53. package/src/core/states.ts +19 -4
  54. package/src/primitives/FPSCounter.tsx +4 -4
  55. package/src/primitives/Image.tsx +2 -9
  56. package/src/primitives/Lazy.tsx +8 -1
  57. package/src/primitives/Virtual.tsx +211 -117
  58. package/src/primitives/VirtualGrid.tsx +98 -21
  59. package/src/primitives/utils/handleNavigation.ts +12 -5
  60. package/src/primitives/utils/withScrolling.ts +63 -62
@@ -26,8 +26,6 @@ const keyMapEntries: KeyMapEntries = {
26
26
  Escape: 'Escape',
27
27
  };
28
28
 
29
- const keyOf = (e: KeyboardEvent): KeyNameOrKeyCode => e.key || e.keyCode;
30
-
31
29
  const flattenKeyMap = (
32
30
  keyMap: Partial<KeyMap>,
33
31
  targetMap: KeyMapEntries,
@@ -39,6 +37,11 @@ const flattenKeyMap = (
39
37
  newTargetMap[v] = key;
40
38
  });
41
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
+ }
42
45
  delete newTargetMap[key];
43
46
  } else {
44
47
  newTargetMap[value as KeyNameOrKeyCode] = key;
@@ -47,6 +50,20 @@ const flattenKeyMap = (
47
50
  return newTargetMap;
48
51
  };
49
52
 
53
+ // The handler prop names dispatch looks up for one key, built at the key's
54
+ // first event (per mapped name, or per `e.key` of an unmapped key) so that no
55
+ // event concatenates strings.
56
+ interface HandlerNames {
57
+ /** `on<Name>`; undefined for an unmapped key, which only onKeyPress hears. */
58
+ on: string | undefined;
59
+ onRelease: string | undefined;
60
+ onCapture: string;
61
+ onCaptureRelease: string;
62
+ }
63
+
64
+ const mappedHandlerNames = new Map<string, HandlerNames>();
65
+ const unmappedHandlerNames = new Map<string, HandlerNames>();
66
+
50
67
  let needFocusDebugStyles = true;
51
68
  const addFocusDebug = (
52
69
  prevFocusPath: ElementNode[],
@@ -117,8 +134,11 @@ const elementFocusData = new WeakMap<
117
134
  { focusCount: number; lastFocusedAt: number }
118
135
  >();
119
136
 
120
- /** The key that triggered the most recent (non-throttled) propagation pass. */
121
- let _pendingHistoryKey: {
137
+ /**
138
+ * The key that triggered the most recent (non-throttled) propagation pass.
139
+ * One record, updated in place: history entries copy its fields.
140
+ */
141
+ const _pendingHistoryKey: {
122
142
  keyPressed: string | number | undefined;
123
143
  mappedKey: string | undefined;
124
144
  } = { keyPressed: undefined, mappedKey: undefined };
@@ -215,7 +235,8 @@ export const setActiveElementCore = (elm: ElementNode) => {
215
235
  updateFocusPath(elm, prev);
216
236
  recordFocusHistory(elm, prev);
217
237
  // Reset key attribution so programmatic focus changes show '—' for key fields
218
- _pendingHistoryKey = { keyPressed: undefined, mappedKey: undefined };
238
+ _pendingHistoryKey.keyPressed = undefined;
239
+ _pendingHistoryKey.mappedKey = undefined;
219
240
  // Publish through the swappable hook rather than writing the signal directly,
220
241
  // so the active-element signal stays decoupled from this focus manager.
221
242
  Config.setActiveElement(elm);
@@ -282,6 +303,9 @@ const updateFocusPath = (
282
303
  let lastGlobalKeyPressTime = 0;
283
304
  let lastInputKey: string | number | undefined;
284
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).
285
309
  const isElementThrottled = (
286
310
  elm: ElementNode,
287
311
  sameKey: boolean,
@@ -292,64 +316,92 @@ const isElementThrottled = (
292
316
  elm._lastAnyKeyPressTime !== undefined &&
293
317
  currentTime - elm._lastAnyKeyPressTime < elm.throttleInput;
294
318
 
295
- // Walk focus path root→leaf. Returns true if a capture handler claimed the
296
- // event (or an element on the path is currently rate-limited).
297
- const runCapturePhase = (
298
- fp: ElementNode[],
319
+ const propagateKeyPress = (
299
320
  e: KeyboardEvent,
300
- mappedEvent: string | undefined,
301
- isUp: boolean,
302
- sameKey: boolean,
303
- currentTime: number,
321
+ mappedEvent?: string,
322
+ isUp: boolean = false,
304
323
  ): boolean => {
305
- const finalFocusElm = fp[0]!;
324
+ const currentTime = performance.now();
325
+ const key: KeyNameOrKeyCode = e.key || e.keyCode;
326
+ const sameKey = lastInputKey === key;
327
+ lastInputKey = key;
328
+
329
+ if (!isUp && Config.throttleInput) {
330
+ if (
331
+ sameKey &&
332
+ currentTime - lastGlobalKeyPressTime < Config.throttleInput
333
+ ) {
334
+ if (isDev && Config.keyDebug) {
335
+ console.log(
336
+ `Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
337
+ );
338
+ }
339
+ // Dropped on purpose, so consumed: the same answer an element's own
340
+ // throttleInput gives below, and what a host asking through
341
+ // Config.preventDefaultOnHandledKeys needs to hear.
342
+ return true;
343
+ }
344
+ lastGlobalKeyPressTime = currentTime;
345
+ }
346
+
347
+ // Keyup events don't trigger focus changes, so don't record their key.
348
+ if (!isUp) {
349
+ _pendingHistoryKey.keyPressed = key;
350
+ _pendingHistoryKey.mappedKey = mappedEvent;
351
+ }
352
+
353
+ const fp = focusPath();
354
+ if (fp.length === 0) return false;
355
+
356
+ // The handler prop names for this key, built at its first event. This and
357
+ // the two walks below are written out here rather than in helpers: a
358
+ // helper with this one call site becomes a closure per event under
359
+ // terser's default reduce_funcs.
306
360
  const keyBase = mappedEvent || e.key;
307
- const captureEvent = `onCapture${keyBase}${isUp ? 'Release' : ''}`;
361
+ const names = mappedEvent ? mappedHandlerNames : unmappedHandlerNames;
362
+ let handlerNames = names.get(keyBase);
363
+ if (handlerNames === undefined) {
364
+ handlerNames = {
365
+ on: mappedEvent ? 'on' + keyBase : undefined,
366
+ onRelease: mappedEvent ? 'on' + keyBase + 'Release' : undefined,
367
+ onCapture: 'onCapture' + keyBase,
368
+ onCaptureRelease: 'onCapture' + keyBase + 'Release',
369
+ };
370
+ names.set(keyBase, handlerNames);
371
+ }
372
+
373
+ // Capture phase: walk the focus path root→leaf. A capture handler that
374
+ // returns true claims the event, as does an element that is rate-limited.
375
+ let finalFocusElm = fp[0]!;
376
+ const captureEvent = isUp
377
+ ? handlerNames.onCaptureRelease
378
+ : handlerNames.onCapture;
308
379
  const captureKey = isUp ? 'onCaptureKeyRelease' : 'onCaptureKey';
309
380
 
310
381
  for (let i = fp.length - 1; i >= 0; i--) {
311
382
  const elm = fp[i]!;
312
- if (isElementThrottled(elm, sameKey, currentTime)) return true;
383
+ if (!isUp && isElementThrottled(elm, sameKey, currentTime)) return true;
313
384
 
314
385
  const captureHandler = elm[captureEvent] || elm[captureKey];
315
386
  if (
316
387
  isFunction(captureHandler) &&
317
388
  captureHandler.call(elm, e, elm, finalFocusElm, mappedEvent) === true
318
389
  ) {
319
- elm._lastAnyKeyPressTime = currentTime;
390
+ if (!isUp) elm._lastAnyKeyPressTime = currentTime;
320
391
  return true;
321
392
  }
322
393
  }
323
- return false;
324
- };
325
-
326
- // Walk focus path leaf→root. Returns whether the event was handled and the
327
- // last element that had *any* matching handler (for the no-handler debug log).
328
- const runBubblePhase = (
329
- fp: ElementNode[],
330
- e: KeyboardEvent,
331
- mappedEvent: string | undefined,
332
- isUp: boolean,
333
- sameKey: boolean,
334
- currentTime: number,
335
- ): { handled: boolean; lastHandlerSeen: ElementNode | undefined } => {
336
- const finalFocusElm = fp[0]!;
337
- const eventHandlerKey = mappedEvent
338
- ? isUp
339
- ? `on${mappedEvent}Release`
340
- : `on${mappedEvent}`
341
- : undefined;
342
- const fallbackHandlerKey: 'onKeyPress' | undefined = isUp
343
- ? undefined
344
- : 'onKeyPress';
345
394
 
395
+ // Bubble phase: walk the focus path leaf→root, reading its leaf again as
396
+ // the capture phase did. lastHandlerSeen is the last element that had
397
+ // *any* matching handler, for the no-handler debug log.
398
+ finalFocusElm = fp[0]!;
399
+ const eventHandlerKey = isUp ? handlerNames.onRelease : handlerNames.on;
346
400
  let lastHandlerSeen: ElementNode | undefined;
347
401
 
348
402
  for (let i = 0; i < fp.length; i++) {
349
403
  const elm = fp[i]!;
350
- if (isElementThrottled(elm, sameKey, currentTime)) {
351
- return { handled: true, lastHandlerSeen };
352
- }
404
+ if (!isUp && isElementThrottled(elm, sameKey, currentTime)) return true;
353
405
 
354
406
  let handled = false;
355
407
  if (eventHandlerKey) {
@@ -359,8 +411,8 @@ const runBubblePhase = (
359
411
  handled = eventHandler.call(elm, e, elm, finalFocusElm) === true;
360
412
  }
361
413
  }
362
- if (!handled && fallbackHandlerKey) {
363
- const fallbackHandler = elm[fallbackHandlerKey];
414
+ if (!handled && !isUp) {
415
+ const fallbackHandler = elm.onKeyPress;
364
416
  if (isFunction(fallbackHandler)) {
365
417
  lastHandlerSeen = elm;
366
418
  handled =
@@ -370,63 +422,11 @@ const runBubblePhase = (
370
422
  }
371
423
 
372
424
  if (handled) {
373
- elm._lastAnyKeyPressTime = currentTime;
374
- return { handled: true, lastHandlerSeen };
375
- }
376
- }
377
- return { handled: false, lastHandlerSeen };
378
- };
379
-
380
- const propagateKeyPress = (
381
- e: KeyboardEvent,
382
- mappedEvent?: string,
383
- isUp: boolean = false,
384
- ): boolean => {
385
- const currentTime = performance.now();
386
- const key = keyOf(e);
387
- const sameKey = lastInputKey === key;
388
- lastInputKey = key;
389
-
390
- if (!isUp && Config.throttleInput) {
391
- if (
392
- sameKey &&
393
- currentTime - lastGlobalKeyPressTime < Config.throttleInput
394
- ) {
395
- if (isDev && Config.keyDebug) {
396
- console.log(
397
- `Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
398
- );
399
- }
400
- // Dropped on purpose, so consumed: the same answer an element's own
401
- // throttleInput gives below, and what a host asking through
402
- // Config.preventDefaultOnHandledKeys needs to hear.
425
+ if (!isUp) elm._lastAnyKeyPressTime = currentTime;
403
426
  return true;
404
427
  }
405
- lastGlobalKeyPressTime = currentTime;
406
428
  }
407
429
 
408
- // Keyup events don't trigger focus changes, so don't record their key.
409
- if (!isUp) {
410
- _pendingHistoryKey = { keyPressed: key, mappedKey: mappedEvent };
411
- }
412
-
413
- const fp = focusPath();
414
- if (fp.length === 0) return false;
415
-
416
- if (runCapturePhase(fp, e, mappedEvent, isUp, sameKey, currentTime)) {
417
- return true;
418
- }
419
-
420
- const { handled, lastHandlerSeen } = runBubblePhase(
421
- fp,
422
- e,
423
- mappedEvent,
424
- isUp,
425
- sameKey,
426
- currentTime,
427
- );
428
- if (handled) return true;
429
-
430
430
  if (isDev && Config.keyDebug && !isUp) {
431
431
  const detail = `key="${e.key}", mappedEvent=${mappedEvent}, isUp=${isUp}`;
432
432
  if (lastHandlerSeen) {
@@ -446,16 +446,24 @@ const propagateKeyPress = (
446
446
  // carries, and two events are the same key if any identity matches.
447
447
  const UNIDENTIFIED = 'Unidentified';
448
448
 
449
+ // An event's two identities, read as two values so that key dispatch builds
450
+ // no array; undefined when the event does not carry that one.
451
+ // 'Unidentified' names no particular key. Treating it as an identity would
452
+ // conflate every key that reports it.
453
+ const keyNameId = (e: KeyboardEvent): KeyNameOrKeyCode | undefined =>
454
+ e.key && e.key !== UNIDENTIFIED ? e.key : undefined;
455
+ const keyCodeId = (e: KeyboardEvent): KeyNameOrKeyCode | undefined =>
456
+ e.keyCode ? e.keyCode : undefined;
457
+
449
458
  const keyIdentities = (
450
459
  keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
451
460
  ): KeyNameOrKeyCode[] => {
452
461
  if (typeof keyOrEvent !== 'object') return [keyOrEvent];
453
462
  const ids: KeyNameOrKeyCode[] = [];
454
- // 'Unidentified' names no particular key. Treating it as an identity would
455
- // conflate every key that reports it.
456
- if (keyOrEvent.key && keyOrEvent.key !== UNIDENTIFIED)
457
- ids.push(keyOrEvent.key);
458
- if (keyOrEvent.keyCode) ids.push(keyOrEvent.keyCode);
463
+ const name = keyNameId(keyOrEvent);
464
+ if (name !== undefined) ids.push(name);
465
+ const code = keyCodeId(keyOrEvent);
466
+ if (code !== undefined) ids.push(code);
459
467
  return ids;
460
468
  };
461
469
 
@@ -480,19 +488,25 @@ type Suppression = {
480
488
  // key differently still finds it. Entries for one key share a Suppression.
481
489
  const suppressedKeys = new Map<KeyNameOrKeyCode, Suppression>();
482
490
 
483
- const findSuppression = (ids: KeyNameOrKeyCode[]): Suppression | undefined => {
484
- for (const id of ids) {
485
- const found = suppressedKeys.get(id);
486
- if (found) return found;
491
+ // The suppression of an event's key: looked up under its name, then its
492
+ // keyCode (keyNameId, keyCodeId), either of which may be undefined.
493
+ const findSuppression = (
494
+ name: KeyNameOrKeyCode | undefined,
495
+ code: KeyNameOrKeyCode | undefined,
496
+ ): Suppression | undefined => {
497
+ let found: Suppression | undefined;
498
+ if (name !== undefined) found = suppressedKeys.get(name);
499
+ if (found === undefined && code !== undefined) {
500
+ found = suppressedKeys.get(code);
487
501
  }
488
- return undefined;
502
+ return found;
489
503
  };
490
504
 
491
- const liftSuppression = (ids: KeyNameOrKeyCode[]): void => {
492
- const found = findSuppression(ids);
505
+ const liftSuppression = (found: Suppression | undefined): void => {
493
506
  if (!found) return;
494
507
  // Drop every alias, not just the one that matched.
495
- for (const id of found.ids) suppressedKeys.delete(id);
508
+ const ids = found.ids;
509
+ for (let i = 0; i < ids.length; i++) suppressedKeys.delete(ids[i]!);
496
510
  found.onRelease?.();
497
511
  };
498
512
 
@@ -529,7 +543,11 @@ export const suppressKeyUntilRelease = (
529
543
  export const releaseKeySuppression = (
530
544
  keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
531
545
  ): void => {
532
- liftSuppression(keyIdentities(keyOrEvent));
546
+ liftSuppression(
547
+ typeof keyOrEvent !== 'object'
548
+ ? suppressedKeys.get(keyOrEvent)
549
+ : findSuppression(keyNameId(keyOrEvent), keyCodeId(keyOrEvent)),
550
+ );
533
551
  };
534
552
 
535
553
  // Returns whether the app consumed the event: a handler took it, or the focus
@@ -539,13 +557,14 @@ const handleKeyEvents = (
539
557
  keyup?: KeyboardEvent,
540
558
  ): boolean => {
541
559
  if (keydown) {
542
- const ids = keyIdentities(keydown);
560
+ const name = keyNameId(keydown);
561
+ const code = keyCodeId(keydown);
543
562
  if (keydown.repeat) {
544
- if (findSuppression(ids)) return true;
563
+ if (findSuppression(name, code)) return true;
545
564
  } else {
546
565
  // A fresh press starts a new gesture, so the previous one is over even
547
566
  // though its key-up never arrived. Settle it before handling this press.
548
- liftSuppression(ids);
567
+ liftSuppression(findSuppression(name, code));
549
568
  }
550
569
 
551
570
  return propagateKeyPress(
@@ -557,7 +576,7 @@ const handleKeyEvents = (
557
576
  // The key is up: whatever was suppressing its repeats is done. Settle it
558
577
  // before propagating, so a suppressor that is still in the focus path sees
559
578
  // its own release callback rather than a second one via the key-up below.
560
- liftSuppression(keyIdentities(keyup));
579
+ liftSuppression(findSuppression(keyNameId(keyup), keyCodeId(keyup)));
561
580
 
562
581
  return propagateKeyPress(
563
582
  keyup,
@@ -601,6 +620,35 @@ export interface KeyEventTarget {
601
620
  ): void;
602
621
  }
603
622
 
623
+ // The key event being dispatched, handed to dispatchKeyDown/dispatchKeyUp so
624
+ // that a key event allocates no closure. Each takes it on entry, so a handler
625
+ // that raises another key event cannot disturb the one in progress.
626
+ let _dispatchEvent: KeyEventLike | undefined;
627
+
628
+ // Handlers are typed as KeyboardEvent throughout; on a host that raises its
629
+ // own objects they see those, which carry the fields read here.
630
+ const dispatchKeyDown = (): void => {
631
+ const event = _dispatchEvent!;
632
+ _dispatchEvent = undefined;
633
+ if (
634
+ handleKeyEvents(event as KeyboardEvent, undefined) &&
635
+ Config.preventDefaultOnHandledKeys
636
+ ) {
637
+ event.preventDefault?.();
638
+ }
639
+ };
640
+
641
+ const dispatchKeyUp = (): void => {
642
+ const event = _dispatchEvent!;
643
+ _dispatchEvent = undefined;
644
+ if (
645
+ handleKeyEvents(undefined, event as KeyboardEvent) &&
646
+ Config.preventDefaultOnHandledKeys
647
+ ) {
648
+ event.preventDefault?.();
649
+ }
650
+ };
651
+
604
652
  export const useFocusManager = (
605
653
  userKeyMap?: Partial<KeyMap>,
606
654
  target?: KeyEventTarget,
@@ -630,26 +678,16 @@ export const useFocusManager = (
630
678
  Config.setActiveElement = (elm) =>
631
679
  ownerContext(() => setActiveElementSignal(elm));
632
680
 
633
- // Handlers are typed as KeyboardEvent throughout; on a host that raises
634
- // its own objects they see those, which carry the fields read here.
635
- const keyPressHandler = (event: KeyEventLike) =>
636
- ownerContext(() => {
637
- if (
638
- handleKeyEvents(event as KeyboardEvent, undefined) &&
639
- Config.preventDefaultOnHandledKeys
640
- ) {
641
- event.preventDefault?.();
642
- }
643
- });
644
- const keyUpHandler = (event: KeyEventLike) =>
645
- ownerContext(() => {
646
- if (
647
- handleKeyEvents(undefined, event as KeyboardEvent) &&
648
- Config.preventDefaultOnHandledKeys
649
- ) {
650
- event.preventDefault?.();
651
- }
652
- });
681
+ // One listener per event type, run inside the owner like ownerContext,
682
+ // with no closure per event.
683
+ const keyPressHandler = (event: KeyEventLike) => {
684
+ _dispatchEvent = event;
685
+ runWithOwner(owner, dispatchKeyDown);
686
+ };
687
+ const keyUpHandler = (event: KeyEventLike) => {
688
+ _dispatchEvent = event;
689
+ runWithOwner(owner, dispatchKeyUp);
690
+ };
653
691
 
654
692
  eventTarget.addEventListener('keydown', keyPressHandler);
655
693
  eventTarget.addEventListener('keyup', keyUpHandler);
package/src/core/index.ts CHANGED
@@ -10,6 +10,10 @@ export * from './config.js';
10
10
  export * from './shaders.js';
11
11
  export type * from '@solidtv/renderer';
12
12
  export { type AnimationSettings } from './intrinsicTypes.js';
13
+ // Solid's own versions of names the renderer also exports
14
+ export { TextNode } from './nodeTypes.js';
15
+ export type { FontLoadOptions, TextProps } from './intrinsicTypes.js';
16
+ export type { IEventEmitter } from './dom-renderer/domRendererTypes.js';
13
17
  // hopefully fix up webpack error
14
18
  import { assertTruthy, deg2Rad } from '@solidtv/renderer/utils';
15
19
  export { assertTruthy, deg2Rad };
@@ -59,11 +59,19 @@ export interface Effects {
59
59
 
60
60
  export type StyleEffects = Effects;
61
61
 
62
- export type FontLoadOptions = Parameters<lngr.Stage['loadFont']>[1] & {
62
+ export type FontLoadOptions = Omit<
63
+ lngr.FontLoadOptions,
64
+ 'atlasUrl' | 'atlasDataUrl'
65
+ > & {
63
66
  type?: 'ssdf' | 'msdf';
67
+ // For web fonts (DOM renderer)
68
+ fontUrl?: string;
69
+ // For SDF fonts
70
+ atlasUrl?: string;
71
+ atlasDataUrl?: string;
64
72
  };
65
73
 
66
- export type CoreShaderManager = lngr.Stage['shManager'];
74
+ export type CoreShaderManager = Pick<lngr.RendererMain, 'registerShaderType'>;
67
75
 
68
76
  export type NewOmit<T, K extends PropertyKey> = {
69
77
  [P in keyof T as Exclude<P, K>]: T[P];
@@ -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();
@@ -47,47 +121,24 @@ const pendingFontLoads: PendingFontLoad[] = [];
47
121
  function attachFonts(fonts: FontLoadOptions[]) {
48
122
  // Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
49
123
  const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
50
- const hasCanvas =
51
- !enableDomRenderer &&
52
- 'textRenderers' in renderer.stage &&
53
- !!(renderer.stage as lng.Stage).textRenderers.canvas;
54
124
  return Promise.all(
55
125
  fonts.map((font) => {
56
- // WebGL — SDF
126
+ // WebGL — SDF (renderer 2.x renders SDF text only)
57
127
  if (
58
- renderer.stage.renderer.mode === 'webgl' &&
128
+ !enableDomRenderer &&
59
129
  'type' in font &&
60
130
  (font.type === 'msdf' || font.type === 'ssdf')
61
131
  ) {
62
- return renderer.stage.loadFont('sdf', font);
132
+ return renderer.stage.loadFont('sdf', font as lng.FontLoadOptions);
63
133
  }
64
- // Canvas — Web
65
- if ('fontUrl' in font) {
66
- if (enableDomRenderer) {
67
- loadFontToDom(font);
68
- } else if (hasCanvas) {
69
- return renderer.stage.loadFont('canvas', font);
70
- }
134
+ // DOM — Web
135
+ if ('fontUrl' in font && enableDomRenderer) {
136
+ loadFontToDom(font);
71
137
  }
72
138
  }),
73
139
  );
74
140
  }
75
141
 
76
- /**
77
- * Whether the app will run an SDF text engine. Read from the renderer options
78
- * rather than the stage, because this has to be answerable before the renderer
79
- * is constructed. Unknown (no `fontEngines` configured yet) is treated as
80
- * "maybe", matching the stage's own SDF-first preference order.
81
- */
82
- function mayUseSdf() {
83
- const engines = (Config.rendererOptions as lng.RendererMainSettings)
84
- ?.fontEngines;
85
- if (engines === undefined || engines.length === 0) {
86
- return true;
87
- }
88
- return engines.some((engine) => engine.type === 'sdf');
89
- }
90
-
91
142
  function flushPendingFonts() {
92
143
  if (pendingFontLoads.length === 0) {
93
144
  return;
@@ -120,7 +171,6 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
120
171
 
121
172
  // Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
122
173
  const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
123
- const preferSdf = mayUseSdf();
124
174
  const deferred: FontLoadOptions[] = [];
125
175
 
126
176
  for (let i = 0; i < fonts.length; i++) {
@@ -137,7 +187,7 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
137
187
 
138
188
  // Starts the download now; the stage-dependent half is owed until
139
189
  // `createRenderer()` runs and `flushPendingFonts()` attaches it.
140
- prefetchFont(preferSdf ? font : { ...font, type: 'canvas' });
190
+ prefetchFont(font as lng.FontPrefetchOptions);
141
191
  deferred.push(font);
142
192
  }
143
193
 
@@ -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
  }
@@ -8,7 +8,7 @@ import type {
8
8
  RoundedProps as ShaderRoundedProps,
9
9
  ShadowProps as ShaderShadowProps,
10
10
  } from '@solidtv/renderer';
11
- import { type WebGlShaderType as WebGlShader } from '@solidtv/renderer/webgl';
11
+ import { type WebGlShaderType as WebGlShader } from '@solidtv/renderer';
12
12
  export {
13
13
  ShaderHolePunchProps,
14
14
  ShaderLinearGradientProps,