@solidtv/solid 1.6.5 → 1.7.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.
- package/dist/src/core/dom-renderer/domRenderer.d.ts +7 -7
- package/dist/src/core/dom-renderer/domRenderer.js +1 -9
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +4 -4
- package/dist/src/core/elementNode.d.ts +4 -4
- package/dist/src/core/elementNode.js +67 -19
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/flex.js +2 -1
- package/dist/src/core/flex.js.map +1 -1
- package/dist/src/core/focusManager.js +130 -96
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/index.d.ts +3 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/intrinsicTypes.d.ts +5 -2
- package/dist/src/core/lightningInit.d.ts +2 -2
- package/dist/src/core/lightningInit.js +6 -29
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/core/shaders.d.ts +1 -1
- package/dist/src/core/states.js +20 -4
- package/dist/src/core/states.js.map +1 -1
- package/dist/src/primitives/FPSCounter.jsx +3 -3
- package/dist/src/primitives/FPSCounter.jsx.map +1 -1
- package/dist/src/primitives/Image.jsx +2 -10
- package/dist/src/primitives/Image.jsx.map +1 -1
- package/dist/src/render.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/core/dom-renderer/domRenderer.ts +4 -12
- package/src/core/dom-renderer/domRendererTypes.ts +4 -4
- package/src/core/elementNode.ts +79 -31
- package/src/core/flex.ts +2 -1
- package/src/core/focusManager.ts +162 -132
- package/src/core/index.ts +4 -0
- package/src/core/intrinsicTypes.ts +10 -2
- package/src/core/lightningInit.ts +7 -31
- package/src/core/shaders.ts +1 -1
- package/src/core/states.ts +19 -4
- package/src/primitives/FPSCounter.tsx +4 -4
- package/src/primitives/Image.tsx +2 -9
package/src/core/focusManager.ts
CHANGED
|
@@ -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,
|
|
@@ -47,6 +45,20 @@ const flattenKeyMap = (
|
|
|
47
45
|
return newTargetMap;
|
|
48
46
|
};
|
|
49
47
|
|
|
48
|
+
// The handler prop names dispatch looks up for one key, built at the key's
|
|
49
|
+
// first event (per mapped name, or per `e.key` of an unmapped key) so that no
|
|
50
|
+
// event concatenates strings.
|
|
51
|
+
interface HandlerNames {
|
|
52
|
+
/** `on<Name>`; undefined for an unmapped key, which only onKeyPress hears. */
|
|
53
|
+
on: string | undefined;
|
|
54
|
+
onRelease: string | undefined;
|
|
55
|
+
onCapture: string;
|
|
56
|
+
onCaptureRelease: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const mappedHandlerNames = new Map<string, HandlerNames>();
|
|
60
|
+
const unmappedHandlerNames = new Map<string, HandlerNames>();
|
|
61
|
+
|
|
50
62
|
let needFocusDebugStyles = true;
|
|
51
63
|
const addFocusDebug = (
|
|
52
64
|
prevFocusPath: ElementNode[],
|
|
@@ -117,8 +129,11 @@ const elementFocusData = new WeakMap<
|
|
|
117
129
|
{ focusCount: number; lastFocusedAt: number }
|
|
118
130
|
>();
|
|
119
131
|
|
|
120
|
-
/**
|
|
121
|
-
|
|
132
|
+
/**
|
|
133
|
+
* The key that triggered the most recent (non-throttled) propagation pass.
|
|
134
|
+
* One record, updated in place: history entries copy its fields.
|
|
135
|
+
*/
|
|
136
|
+
const _pendingHistoryKey: {
|
|
122
137
|
keyPressed: string | number | undefined;
|
|
123
138
|
mappedKey: string | undefined;
|
|
124
139
|
} = { keyPressed: undefined, mappedKey: undefined };
|
|
@@ -215,7 +230,8 @@ export const setActiveElementCore = (elm: ElementNode) => {
|
|
|
215
230
|
updateFocusPath(elm, prev);
|
|
216
231
|
recordFocusHistory(elm, prev);
|
|
217
232
|
// Reset key attribution so programmatic focus changes show '—' for key fields
|
|
218
|
-
_pendingHistoryKey =
|
|
233
|
+
_pendingHistoryKey.keyPressed = undefined;
|
|
234
|
+
_pendingHistoryKey.mappedKey = undefined;
|
|
219
235
|
// Publish through the swappable hook rather than writing the signal directly,
|
|
220
236
|
// so the active-element signal stays decoupled from this focus manager.
|
|
221
237
|
Config.setActiveElement(elm);
|
|
@@ -292,19 +308,66 @@ const isElementThrottled = (
|
|
|
292
308
|
elm._lastAnyKeyPressTime !== undefined &&
|
|
293
309
|
currentTime - elm._lastAnyKeyPressTime < elm.throttleInput;
|
|
294
310
|
|
|
295
|
-
|
|
296
|
-
// event (or an element on the path is currently rate-limited).
|
|
297
|
-
const runCapturePhase = (
|
|
298
|
-
fp: ElementNode[],
|
|
311
|
+
const propagateKeyPress = (
|
|
299
312
|
e: KeyboardEvent,
|
|
300
|
-
mappedEvent
|
|
301
|
-
isUp: boolean,
|
|
302
|
-
sameKey: boolean,
|
|
303
|
-
currentTime: number,
|
|
313
|
+
mappedEvent?: string,
|
|
314
|
+
isUp: boolean = false,
|
|
304
315
|
): boolean => {
|
|
305
|
-
const
|
|
316
|
+
const currentTime = performance.now();
|
|
317
|
+
const key: KeyNameOrKeyCode = e.key || e.keyCode;
|
|
318
|
+
const sameKey = lastInputKey === key;
|
|
319
|
+
lastInputKey = key;
|
|
320
|
+
|
|
321
|
+
if (!isUp && Config.throttleInput) {
|
|
322
|
+
if (
|
|
323
|
+
sameKey &&
|
|
324
|
+
currentTime - lastGlobalKeyPressTime < Config.throttleInput
|
|
325
|
+
) {
|
|
326
|
+
if (isDev && Config.keyDebug) {
|
|
327
|
+
console.log(
|
|
328
|
+
`Keypress throttled by global Config.throttleInput: ${Config.throttleInput}ms`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
// Dropped on purpose, so consumed: the same answer an element's own
|
|
332
|
+
// throttleInput gives below, and what a host asking through
|
|
333
|
+
// Config.preventDefaultOnHandledKeys needs to hear.
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
lastGlobalKeyPressTime = currentTime;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Keyup events don't trigger focus changes, so don't record their key.
|
|
340
|
+
if (!isUp) {
|
|
341
|
+
_pendingHistoryKey.keyPressed = key;
|
|
342
|
+
_pendingHistoryKey.mappedKey = mappedEvent;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const fp = focusPath();
|
|
346
|
+
if (fp.length === 0) return false;
|
|
347
|
+
|
|
348
|
+
// The handler prop names for this key, built at its first event. This and
|
|
349
|
+
// the two walks below are written out here rather than in helpers: a
|
|
350
|
+
// helper with this one call site becomes a closure per event under
|
|
351
|
+
// terser's default reduce_funcs.
|
|
306
352
|
const keyBase = mappedEvent || e.key;
|
|
307
|
-
const
|
|
353
|
+
const names = mappedEvent ? mappedHandlerNames : unmappedHandlerNames;
|
|
354
|
+
let handlerNames = names.get(keyBase);
|
|
355
|
+
if (handlerNames === undefined) {
|
|
356
|
+
handlerNames = {
|
|
357
|
+
on: mappedEvent ? 'on' + keyBase : undefined,
|
|
358
|
+
onRelease: mappedEvent ? 'on' + keyBase + 'Release' : undefined,
|
|
359
|
+
onCapture: 'onCapture' + keyBase,
|
|
360
|
+
onCaptureRelease: 'onCapture' + keyBase + 'Release',
|
|
361
|
+
};
|
|
362
|
+
names.set(keyBase, handlerNames);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Capture phase: walk the focus path root→leaf. A capture handler that
|
|
366
|
+
// returns true claims the event, as does an element that is rate-limited.
|
|
367
|
+
let finalFocusElm = fp[0]!;
|
|
368
|
+
const captureEvent = isUp
|
|
369
|
+
? handlerNames.onCaptureRelease
|
|
370
|
+
: handlerNames.onCapture;
|
|
308
371
|
const captureKey = isUp ? 'onCaptureKeyRelease' : 'onCaptureKey';
|
|
309
372
|
|
|
310
373
|
for (let i = fp.length - 1; i >= 0; i--) {
|
|
@@ -320,36 +383,17 @@ const runCapturePhase = (
|
|
|
320
383
|
return true;
|
|
321
384
|
}
|
|
322
385
|
}
|
|
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
386
|
|
|
387
|
+
// Bubble phase: walk the focus path leaf→root, reading its leaf again as
|
|
388
|
+
// the capture phase did. lastHandlerSeen is the last element that had
|
|
389
|
+
// *any* matching handler, for the no-handler debug log.
|
|
390
|
+
finalFocusElm = fp[0]!;
|
|
391
|
+
const eventHandlerKey = isUp ? handlerNames.onRelease : handlerNames.on;
|
|
346
392
|
let lastHandlerSeen: ElementNode | undefined;
|
|
347
393
|
|
|
348
394
|
for (let i = 0; i < fp.length; i++) {
|
|
349
395
|
const elm = fp[i]!;
|
|
350
|
-
if (isElementThrottled(elm, sameKey, currentTime))
|
|
351
|
-
return { handled: true, lastHandlerSeen };
|
|
352
|
-
}
|
|
396
|
+
if (isElementThrottled(elm, sameKey, currentTime)) return true;
|
|
353
397
|
|
|
354
398
|
let handled = false;
|
|
355
399
|
if (eventHandlerKey) {
|
|
@@ -359,8 +403,8 @@ const runBubblePhase = (
|
|
|
359
403
|
handled = eventHandler.call(elm, e, elm, finalFocusElm) === true;
|
|
360
404
|
}
|
|
361
405
|
}
|
|
362
|
-
if (!handled &&
|
|
363
|
-
const fallbackHandler = elm
|
|
406
|
+
if (!handled && !isUp) {
|
|
407
|
+
const fallbackHandler = elm.onKeyPress;
|
|
364
408
|
if (isFunction(fallbackHandler)) {
|
|
365
409
|
lastHandlerSeen = elm;
|
|
366
410
|
handled =
|
|
@@ -371,62 +415,10 @@ const runBubblePhase = (
|
|
|
371
415
|
|
|
372
416
|
if (handled) {
|
|
373
417
|
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.
|
|
403
418
|
return true;
|
|
404
419
|
}
|
|
405
|
-
lastGlobalKeyPressTime = currentTime;
|
|
406
420
|
}
|
|
407
421
|
|
|
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
422
|
if (isDev && Config.keyDebug && !isUp) {
|
|
431
423
|
const detail = `key="${e.key}", mappedEvent=${mappedEvent}, isUp=${isUp}`;
|
|
432
424
|
if (lastHandlerSeen) {
|
|
@@ -446,16 +438,24 @@ const propagateKeyPress = (
|
|
|
446
438
|
// carries, and two events are the same key if any identity matches.
|
|
447
439
|
const UNIDENTIFIED = 'Unidentified';
|
|
448
440
|
|
|
441
|
+
// An event's two identities, read as two values so that key dispatch builds
|
|
442
|
+
// no array; undefined when the event does not carry that one.
|
|
443
|
+
// 'Unidentified' names no particular key. Treating it as an identity would
|
|
444
|
+
// conflate every key that reports it.
|
|
445
|
+
const keyNameId = (e: KeyboardEvent): KeyNameOrKeyCode | undefined =>
|
|
446
|
+
e.key && e.key !== UNIDENTIFIED ? e.key : undefined;
|
|
447
|
+
const keyCodeId = (e: KeyboardEvent): KeyNameOrKeyCode | undefined =>
|
|
448
|
+
e.keyCode ? e.keyCode : undefined;
|
|
449
|
+
|
|
449
450
|
const keyIdentities = (
|
|
450
451
|
keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
|
|
451
452
|
): KeyNameOrKeyCode[] => {
|
|
452
453
|
if (typeof keyOrEvent !== 'object') return [keyOrEvent];
|
|
453
454
|
const ids: KeyNameOrKeyCode[] = [];
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (keyOrEvent.keyCode) ids.push(keyOrEvent.keyCode);
|
|
455
|
+
const name = keyNameId(keyOrEvent);
|
|
456
|
+
if (name !== undefined) ids.push(name);
|
|
457
|
+
const code = keyCodeId(keyOrEvent);
|
|
458
|
+
if (code !== undefined) ids.push(code);
|
|
459
459
|
return ids;
|
|
460
460
|
};
|
|
461
461
|
|
|
@@ -480,19 +480,25 @@ type Suppression = {
|
|
|
480
480
|
// key differently still finds it. Entries for one key share a Suppression.
|
|
481
481
|
const suppressedKeys = new Map<KeyNameOrKeyCode, Suppression>();
|
|
482
482
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
// The suppression of an event's key: looked up under its name, then its
|
|
484
|
+
// keyCode (keyNameId, keyCodeId), either of which may be undefined.
|
|
485
|
+
const findSuppression = (
|
|
486
|
+
name: KeyNameOrKeyCode | undefined,
|
|
487
|
+
code: KeyNameOrKeyCode | undefined,
|
|
488
|
+
): Suppression | undefined => {
|
|
489
|
+
let found: Suppression | undefined;
|
|
490
|
+
if (name !== undefined) found = suppressedKeys.get(name);
|
|
491
|
+
if (found === undefined && code !== undefined) {
|
|
492
|
+
found = suppressedKeys.get(code);
|
|
487
493
|
}
|
|
488
|
-
return
|
|
494
|
+
return found;
|
|
489
495
|
};
|
|
490
496
|
|
|
491
|
-
const liftSuppression = (
|
|
492
|
-
const found = findSuppression(ids);
|
|
497
|
+
const liftSuppression = (found: Suppression | undefined): void => {
|
|
493
498
|
if (!found) return;
|
|
494
499
|
// Drop every alias, not just the one that matched.
|
|
495
|
-
|
|
500
|
+
const ids = found.ids;
|
|
501
|
+
for (let i = 0; i < ids.length; i++) suppressedKeys.delete(ids[i]!);
|
|
496
502
|
found.onRelease?.();
|
|
497
503
|
};
|
|
498
504
|
|
|
@@ -529,7 +535,11 @@ export const suppressKeyUntilRelease = (
|
|
|
529
535
|
export const releaseKeySuppression = (
|
|
530
536
|
keyOrEvent: KeyboardEvent | KeyNameOrKeyCode,
|
|
531
537
|
): void => {
|
|
532
|
-
liftSuppression(
|
|
538
|
+
liftSuppression(
|
|
539
|
+
typeof keyOrEvent !== 'object'
|
|
540
|
+
? suppressedKeys.get(keyOrEvent)
|
|
541
|
+
: findSuppression(keyNameId(keyOrEvent), keyCodeId(keyOrEvent)),
|
|
542
|
+
);
|
|
533
543
|
};
|
|
534
544
|
|
|
535
545
|
// Returns whether the app consumed the event: a handler took it, or the focus
|
|
@@ -539,13 +549,14 @@ const handleKeyEvents = (
|
|
|
539
549
|
keyup?: KeyboardEvent,
|
|
540
550
|
): boolean => {
|
|
541
551
|
if (keydown) {
|
|
542
|
-
const
|
|
552
|
+
const name = keyNameId(keydown);
|
|
553
|
+
const code = keyCodeId(keydown);
|
|
543
554
|
if (keydown.repeat) {
|
|
544
|
-
if (findSuppression(
|
|
555
|
+
if (findSuppression(name, code)) return true;
|
|
545
556
|
} else {
|
|
546
557
|
// A fresh press starts a new gesture, so the previous one is over even
|
|
547
558
|
// though its key-up never arrived. Settle it before handling this press.
|
|
548
|
-
liftSuppression(
|
|
559
|
+
liftSuppression(findSuppression(name, code));
|
|
549
560
|
}
|
|
550
561
|
|
|
551
562
|
return propagateKeyPress(
|
|
@@ -557,7 +568,7 @@ const handleKeyEvents = (
|
|
|
557
568
|
// The key is up: whatever was suppressing its repeats is done. Settle it
|
|
558
569
|
// before propagating, so a suppressor that is still in the focus path sees
|
|
559
570
|
// its own release callback rather than a second one via the key-up below.
|
|
560
|
-
liftSuppression(
|
|
571
|
+
liftSuppression(findSuppression(keyNameId(keyup), keyCodeId(keyup)));
|
|
561
572
|
|
|
562
573
|
return propagateKeyPress(
|
|
563
574
|
keyup,
|
|
@@ -601,6 +612,35 @@ export interface KeyEventTarget {
|
|
|
601
612
|
): void;
|
|
602
613
|
}
|
|
603
614
|
|
|
615
|
+
// The key event being dispatched, handed to dispatchKeyDown/dispatchKeyUp so
|
|
616
|
+
// that a key event allocates no closure. Each takes it on entry, so a handler
|
|
617
|
+
// that raises another key event cannot disturb the one in progress.
|
|
618
|
+
let _dispatchEvent: KeyEventLike | undefined;
|
|
619
|
+
|
|
620
|
+
// Handlers are typed as KeyboardEvent throughout; on a host that raises its
|
|
621
|
+
// own objects they see those, which carry the fields read here.
|
|
622
|
+
const dispatchKeyDown = (): void => {
|
|
623
|
+
const event = _dispatchEvent!;
|
|
624
|
+
_dispatchEvent = undefined;
|
|
625
|
+
if (
|
|
626
|
+
handleKeyEvents(event as KeyboardEvent, undefined) &&
|
|
627
|
+
Config.preventDefaultOnHandledKeys
|
|
628
|
+
) {
|
|
629
|
+
event.preventDefault?.();
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
const dispatchKeyUp = (): void => {
|
|
634
|
+
const event = _dispatchEvent!;
|
|
635
|
+
_dispatchEvent = undefined;
|
|
636
|
+
if (
|
|
637
|
+
handleKeyEvents(undefined, event as KeyboardEvent) &&
|
|
638
|
+
Config.preventDefaultOnHandledKeys
|
|
639
|
+
) {
|
|
640
|
+
event.preventDefault?.();
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
604
644
|
export const useFocusManager = (
|
|
605
645
|
userKeyMap?: Partial<KeyMap>,
|
|
606
646
|
target?: KeyEventTarget,
|
|
@@ -630,26 +670,16 @@ export const useFocusManager = (
|
|
|
630
670
|
Config.setActiveElement = (elm) =>
|
|
631
671
|
ownerContext(() => setActiveElementSignal(elm));
|
|
632
672
|
|
|
633
|
-
//
|
|
634
|
-
//
|
|
635
|
-
const keyPressHandler = (event: KeyEventLike) =>
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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
|
-
});
|
|
673
|
+
// One listener per event type, run inside the owner like ownerContext,
|
|
674
|
+
// with no closure per event.
|
|
675
|
+
const keyPressHandler = (event: KeyEventLike) => {
|
|
676
|
+
_dispatchEvent = event;
|
|
677
|
+
runWithOwner(owner, dispatchKeyDown);
|
|
678
|
+
};
|
|
679
|
+
const keyUpHandler = (event: KeyEventLike) => {
|
|
680
|
+
_dispatchEvent = event;
|
|
681
|
+
runWithOwner(owner, dispatchKeyUp);
|
|
682
|
+
};
|
|
653
683
|
|
|
654
684
|
eventTarget.addEventListener('keydown', keyPressHandler);
|
|
655
685
|
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 =
|
|
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.
|
|
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];
|
|
@@ -47,47 +47,24 @@ const pendingFontLoads: PendingFontLoad[] = [];
|
|
|
47
47
|
function attachFonts(fonts: FontLoadOptions[]) {
|
|
48
48
|
// Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
|
|
49
49
|
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
50
|
return Promise.all(
|
|
55
51
|
fonts.map((font) => {
|
|
56
|
-
// WebGL — SDF
|
|
52
|
+
// WebGL — SDF (renderer 2.x renders SDF text only)
|
|
57
53
|
if (
|
|
58
|
-
|
|
54
|
+
!enableDomRenderer &&
|
|
59
55
|
'type' in font &&
|
|
60
56
|
(font.type === 'msdf' || font.type === 'ssdf')
|
|
61
57
|
) {
|
|
62
|
-
return renderer.stage.loadFont('sdf', font);
|
|
58
|
+
return renderer.stage.loadFont('sdf', font as lng.FontLoadOptions);
|
|
63
59
|
}
|
|
64
|
-
//
|
|
65
|
-
if ('fontUrl' in font) {
|
|
66
|
-
|
|
67
|
-
loadFontToDom(font);
|
|
68
|
-
} else if (hasCanvas) {
|
|
69
|
-
return renderer.stage.loadFont('canvas', font);
|
|
70
|
-
}
|
|
60
|
+
// DOM — Web
|
|
61
|
+
if ('fontUrl' in font && enableDomRenderer) {
|
|
62
|
+
loadFontToDom(font);
|
|
71
63
|
}
|
|
72
64
|
}),
|
|
73
65
|
);
|
|
74
66
|
}
|
|
75
67
|
|
|
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
68
|
function flushPendingFonts() {
|
|
92
69
|
if (pendingFontLoads.length === 0) {
|
|
93
70
|
return;
|
|
@@ -120,7 +97,6 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
|
120
97
|
|
|
121
98
|
// Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
|
|
122
99
|
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
|
|
123
|
-
const preferSdf = mayUseSdf();
|
|
124
100
|
const deferred: FontLoadOptions[] = [];
|
|
125
101
|
|
|
126
102
|
for (let i = 0; i < fonts.length; i++) {
|
|
@@ -137,7 +113,7 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
|
137
113
|
|
|
138
114
|
// Starts the download now; the stage-dependent half is owed until
|
|
139
115
|
// `createRenderer()` runs and `flushPendingFonts()` attaches it.
|
|
140
|
-
prefetchFont(
|
|
116
|
+
prefetchFont(font as lng.FontPrefetchOptions);
|
|
141
117
|
deferred.push(font);
|
|
142
118
|
}
|
|
143
119
|
|
package/src/core/shaders.ts
CHANGED
|
@@ -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
|
|
11
|
+
import { type WebGlShaderType as WebGlShader } from '@solidtv/renderer';
|
|
12
12
|
export {
|
|
13
13
|
ShaderHolePunchProps,
|
|
14
14
|
ShaderLinearGradientProps,
|
package/src/core/states.ts
CHANGED
|
@@ -10,7 +10,13 @@ export default class States extends Array<DollarString> {
|
|
|
10
10
|
|
|
11
11
|
constructor(callback: () => void, initialState: NodeStates = {}) {
|
|
12
12
|
if (isArray(initialState)) {
|
|
13
|
-
|
|
13
|
+
// By index: a spread runs the iterator protocol (an iterator and an
|
|
14
|
+
// argument list per call).
|
|
15
|
+
super();
|
|
16
|
+
const n = initialState.length;
|
|
17
|
+
for (let i = 0; i < n; i++) {
|
|
18
|
+
this[i] = initialState[i]!;
|
|
19
|
+
}
|
|
14
20
|
} else if (isString(initialState)) {
|
|
15
21
|
super(initialState); // Assert as DollarString
|
|
16
22
|
} else {
|
|
@@ -66,9 +72,18 @@ export default class States extends Array<DollarString> {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
merge(newStates: NodeStates) {
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (newStates === this) {
|
|
76
|
+
// A self-merge clears the list, as it did when merge emptied the list
|
|
77
|
+
// and then pushed a spread of it.
|
|
78
|
+
this.length = 0;
|
|
79
|
+
} else if (isArray(newStates)) {
|
|
80
|
+
// Copied by index, then cut to length: a spread ran the iterator
|
|
81
|
+
// protocol over the list (with forwardStates, the parent's States).
|
|
82
|
+
const n = newStates.length;
|
|
83
|
+
for (let i = 0; i < n; i++) {
|
|
84
|
+
this[i] = newStates[i]!;
|
|
85
|
+
}
|
|
86
|
+
this.length = n;
|
|
72
87
|
} else if (isString(newStates)) {
|
|
73
88
|
this.length = 0; // Clear the current states
|
|
74
89
|
this.push(newStates); // Assert as DollarString
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type NodeProps, RendererMain } from '@solidtv/solid';
|
|
2
2
|
import { createSignal } from 'solid-js';
|
|
3
3
|
|
|
4
4
|
const fpsStyle = {
|
|
@@ -70,8 +70,8 @@ const calcFps = (fps: number) => {
|
|
|
70
70
|
setAvgFps(Math.round(totalFps / count));
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
function updateMemoryInfo(
|
|
74
|
-
const memInfo =
|
|
73
|
+
function updateMemoryInfo(renderer: RendererMain) {
|
|
74
|
+
const memInfo = renderer.memoryInfo();
|
|
75
75
|
setCriticalThresholdSignal(bytesToMb(memInfo.criticalThreshold));
|
|
76
76
|
setTargetThresholdSignal(bytesToMb(memInfo.targetThreshold));
|
|
77
77
|
setRenderableMemUsedSignal(bytesToMb(memInfo.renderableMemUsed));
|
|
@@ -88,7 +88,7 @@ export function setupFPS(root: any) {
|
|
|
88
88
|
if (fps > 5) {
|
|
89
89
|
calcFps(fps);
|
|
90
90
|
if (frameCount % 10 === 0) {
|
|
91
|
-
updateMemoryInfo(target
|
|
91
|
+
updateMemoryInfo(target);
|
|
92
92
|
frameCount = 0;
|
|
93
93
|
}
|
|
94
94
|
frameCount++;
|
package/src/primitives/Image.tsx
CHANGED
|
@@ -43,15 +43,8 @@ export const Image: Component<ImageProps> = (props) => {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.then((resp) => {
|
|
49
|
-
// if texture fails to load, this is still called after the failed handler
|
|
50
|
-
if (resp.data) setTexture(srcTexture);
|
|
51
|
-
})
|
|
52
|
-
.catch(() => {
|
|
53
|
-
// handle potential errors from getTextureData
|
|
54
|
-
});
|
|
46
|
+
// Renderer 2.x loads a texture only once a node shows it
|
|
47
|
+
setTexture(srcTexture);
|
|
55
48
|
});
|
|
56
49
|
|
|
57
50
|
return (
|