@solidtv/solid 1.3.9-0 → 1.4.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/README.md +4 -1
- package/dist/src/core/dom-renderer/domRenderer.js +21 -8
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/lightningInit.d.ts +12 -0
- package/dist/src/core/lightningInit.js +76 -2
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/mergeProps.d.ts +27 -0
- package/dist/src/mergeProps.js +41 -0
- package/dist/src/mergeProps.js.map +1 -0
- package/dist/src/primitives/Virtual.jsx +1 -1
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/useMouse.js +11 -1
- package/dist/src/primitives/useMouse.js.map +1 -1
- package/dist/src/render.d.ts +2 -2
- package/dist/src/render.js +5 -1
- package/dist/src/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/core/dom-renderer/domRenderer.ts +23 -8
- package/src/core/lightningInit.ts +99 -2
- package/src/mergeProps.ts +48 -0
- package/src/primitives/Virtual.tsx +1 -1
- package/src/primitives/useMouse.ts +13 -1
- package/src/render.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidtv/solid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "SolidTV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
},
|
|
110
110
|
"peerDependencies": {
|
|
111
111
|
"@solidjs/router": "^0.16.1",
|
|
112
|
-
"@solidtv/renderer": "^1.
|
|
112
|
+
"@solidtv/renderer": "^1.6.3",
|
|
113
113
|
"solid-js": "*"
|
|
114
114
|
},
|
|
115
115
|
"peerDependenciesMeta": {},
|
|
@@ -1232,7 +1232,11 @@ function updateNodeData(node: DOMNode | DOMText) {
|
|
|
1232
1232
|
if (keyValue === undefined) {
|
|
1233
1233
|
node.div.removeAttribute('data-' + key);
|
|
1234
1234
|
} else {
|
|
1235
|
-
|
|
1235
|
+
// dataset[key] requires key to already be camelCase (DOMStringMap rejects hyphenated
|
|
1236
|
+
// property names outright, e.g. "section-id" -- SyntaxError: not a valid property
|
|
1237
|
+
// name). Our data props are passed as data-attribute-style keys (kebab-case), so use
|
|
1238
|
+
// setAttribute directly instead, consistent with the removeAttribute branch above.
|
|
1239
|
+
node.div.setAttribute('data-' + key, String(keyValue));
|
|
1236
1240
|
}
|
|
1237
1241
|
}
|
|
1238
1242
|
}
|
|
@@ -2275,7 +2279,7 @@ export class DOMRendererMain implements IRendererMain {
|
|
|
2275
2279
|
}
|
|
2276
2280
|
|
|
2277
2281
|
export function loadFontToDom(font: FontLoadOptions): void {
|
|
2278
|
-
// fontFamily: string;
|
|
2282
|
+
// fontFamily: string | string[];
|
|
2279
2283
|
// metrics?: FontMetrics;
|
|
2280
2284
|
// fontUrl?: string;
|
|
2281
2285
|
// atlasUrl?: string;
|
|
@@ -2290,16 +2294,27 @@ export function loadFontToDom(font: FontLoadOptions): void {
|
|
|
2290
2294
|
return;
|
|
2291
2295
|
}
|
|
2292
2296
|
|
|
2293
|
-
const fontFace = new FontFace(font.fontFamily, `url(${font.fontUrl})`);
|
|
2294
2297
|
const fontSet = document.fonts as FontFaceSet & {
|
|
2295
2298
|
add?: (font: FontFace) => FontFaceSet;
|
|
2296
2299
|
};
|
|
2297
|
-
fontSet.add?.(fontFace);
|
|
2298
2300
|
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2301
|
+
// One load may register the same file under several family names. Each name
|
|
2302
|
+
// needs its own FontFace — the browser dedupes the download by URL — so that
|
|
2303
|
+
// text referring to any of them resolves. Passing the array straight to
|
|
2304
|
+
// FontFace would stringify it into a single bogus family.
|
|
2305
|
+
const names = Array.isArray(font.fontFamily)
|
|
2306
|
+
? font.fontFamily
|
|
2307
|
+
: [font.fontFamily];
|
|
2308
|
+
|
|
2309
|
+
for (let i = 0; i < names.length; i++) {
|
|
2310
|
+
const fontFace = new FontFace(names[i]!, `url(${font.fontUrl})`);
|
|
2311
|
+
fontSet.add?.(fontFace);
|
|
2312
|
+
|
|
2313
|
+
fontFace
|
|
2314
|
+
.load()
|
|
2315
|
+
.then(scheduleContainTextNodesMeasurement)
|
|
2316
|
+
.catch(() => {});
|
|
2317
|
+
}
|
|
2303
2318
|
}
|
|
2304
2319
|
|
|
2305
2320
|
export function isDomRenderer(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as lng from '@solidtv/renderer';
|
|
2
|
+
import { prefetchFont } from '@solidtv/renderer';
|
|
2
3
|
import { Config, DOM_RENDERING } from './config.js';
|
|
3
4
|
import { DOMRendererMain, loadFontToDom } from './dom-renderer/domRenderer.js';
|
|
4
5
|
import { DomRendererMainSettings } from './dom-renderer/domRendererTypes.js';
|
|
@@ -21,17 +22,36 @@ export function startLightningRenderer(
|
|
|
21
22
|
renderer = enableDomRenderer
|
|
22
23
|
? new DOMRendererMain(options, rootId)
|
|
23
24
|
: new lng.RendererMain(options, rootId);
|
|
25
|
+
|
|
26
|
+
// A stage now exists, so any fonts requested before this point can finish.
|
|
27
|
+
flushPendingFonts();
|
|
28
|
+
|
|
24
29
|
return renderer;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
/**
|
|
33
|
+
* A `loadFonts()` call made before the renderer existed. The download is
|
|
34
|
+
* already in flight; only the stage-dependent half is still owed.
|
|
35
|
+
*/
|
|
36
|
+
interface PendingFontLoad {
|
|
37
|
+
fonts: FontLoadOptions[];
|
|
38
|
+
resolve: () => void;
|
|
39
|
+
reject: (reason?: unknown) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pendingFontLoads: PendingFontLoad[] = [];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hand fonts to the stage. Requires a renderer.
|
|
46
|
+
*/
|
|
47
|
+
function attachFonts(fonts: FontLoadOptions[]) {
|
|
28
48
|
// Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
|
|
29
49
|
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
|
|
30
50
|
const hasCanvas =
|
|
31
51
|
!enableDomRenderer &&
|
|
32
52
|
'textRenderers' in renderer.stage &&
|
|
33
53
|
!!(renderer.stage as lng.Stage).textRenderers.canvas;
|
|
34
|
-
|
|
54
|
+
return Promise.all(
|
|
35
55
|
fonts.map((font) => {
|
|
36
56
|
// WebGL — SDF
|
|
37
57
|
if (
|
|
@@ -52,3 +72,80 @@ export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
|
52
72
|
}),
|
|
53
73
|
);
|
|
54
74
|
}
|
|
75
|
+
|
|
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
|
+
function flushPendingFonts() {
|
|
92
|
+
if (pendingFontLoads.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const queued = pendingFontLoads.splice(0, pendingFontLoads.length);
|
|
97
|
+
for (let i = 0; i < queued.length; i++) {
|
|
98
|
+
const pending = queued[i]!;
|
|
99
|
+
attachFonts(pending.fonts).then(() => pending.resolve(), pending.reject);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Load fonts into the renderer.
|
|
105
|
+
*
|
|
106
|
+
* Can be called either side of `createRenderer()`. Calling it *first* is
|
|
107
|
+
* preferred: the downloads start immediately and overlap the renderer's boot
|
|
108
|
+
* (GL context, shaders, buffers) instead of queueing behind it. The fonts are
|
|
109
|
+
* then attached to the stage as soon as it exists.
|
|
110
|
+
*
|
|
111
|
+
* The returned promise resolves when the fonts are attached to the stage — so
|
|
112
|
+
* when called before `createRenderer()`, it cannot settle until
|
|
113
|
+
* `createRenderer()` has run. Do not `await` it before creating the renderer.
|
|
114
|
+
*/
|
|
115
|
+
export async function loadFonts(fonts: FontLoadOptions[]) {
|
|
116
|
+
if (renderer !== undefined) {
|
|
117
|
+
await attachFonts(fonts);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Inlined so the loadFontToDom branch + import tree-shake in WebGL builds.
|
|
122
|
+
const enableDomRenderer = DOM_RENDERING && Config.domRendererEnabled;
|
|
123
|
+
const preferSdf = mayUseSdf();
|
|
124
|
+
const deferred: FontLoadOptions[] = [];
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < fonts.length; i++) {
|
|
127
|
+
const font = fonts[i]!;
|
|
128
|
+
|
|
129
|
+
// The DOM path registers fonts with the document, never with a stage —
|
|
130
|
+
// there is nothing to wait for, so finish it here.
|
|
131
|
+
if (enableDomRenderer) {
|
|
132
|
+
if ('fontUrl' in font) {
|
|
133
|
+
loadFontToDom(font);
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Starts the download now; the stage-dependent half is owed until
|
|
139
|
+
// `createRenderer()` runs and `flushPendingFonts()` attaches it.
|
|
140
|
+
prefetchFont(preferSdf ? font : { ...font, type: 'canvas' });
|
|
141
|
+
deferred.push(font);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (deferred.length === 0) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
await new Promise<void>((resolve, reject) => {
|
|
149
|
+
pendingFontLoads.push({ fonts: deferred, resolve, reject });
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { mergeProps as solidMergeProps } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether the host engine implements ES2015 `Proxy`. Chrome < 49 — notably the
|
|
5
|
+
* Chrome 38 engine on LG webOS 3.x and older Tizen — does not, which changes how
|
|
6
|
+
* solid-js merges props (see {@link mergeProps}).
|
|
7
|
+
*/
|
|
8
|
+
export const SUPPORTS_PROXY = typeof Proxy === 'function';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Mirror of solid-js's internal `resolveSource`: a reactive spread source is
|
|
12
|
+
* handed to `mergeProps` as a thunk; calling it yields the object to merge.
|
|
13
|
+
*/
|
|
14
|
+
function resolveSource(source: unknown): unknown {
|
|
15
|
+
const value =
|
|
16
|
+
typeof source === 'function' ? (source as () => unknown)() : source;
|
|
17
|
+
return value == null ? {} : value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Proxy-free-safe `mergeProps`, re-exported by the renderer so the JSX compiler
|
|
22
|
+
* (`moduleName: '@lightningtv/solid'`) routes every compiled spread through it.
|
|
23
|
+
*
|
|
24
|
+
* With `Proxy` this is solid-js's `mergeProps` unchanged. Without `Proxy`
|
|
25
|
+
* (Chrome 38 / webOS 3), solid-js falls back to a path that enumerates each
|
|
26
|
+
* source via `Object.getOwnPropertyNames`. A reactive spread — e.g.
|
|
27
|
+
* `<Comp {...someFn()} />`, which the compiler passes as a *function* — reaches
|
|
28
|
+
* that fallback as the function itself, so enumeration yields `['length','name']`
|
|
29
|
+
* (or throws on `caller`/`callee`/`arguments` for strict-mode functions) instead
|
|
30
|
+
* of the object's props, and every spread-provided prop is silently dropped.
|
|
31
|
+
*
|
|
32
|
+
* Resolving function sources to their objects first lets the fallback enumerate
|
|
33
|
+
* real props. Getters are preserved, so values stay reactive; only a source
|
|
34
|
+
* whose object *identity* changes over time won't re-track — an accepted limit
|
|
35
|
+
* of running without `Proxy`.
|
|
36
|
+
*
|
|
37
|
+
* @see https://github.com/solidjs/solid/issues/2282
|
|
38
|
+
*/
|
|
39
|
+
export const mergeProps = ((...sources: unknown[]) => {
|
|
40
|
+
if (SUPPORTS_PROXY) {
|
|
41
|
+
return solidMergeProps(...(sources as Parameters<typeof solidMergeProps>));
|
|
42
|
+
}
|
|
43
|
+
return solidMergeProps(
|
|
44
|
+
...(sources.map((source) =>
|
|
45
|
+
typeof source === 'function' ? resolveSource(source) : source,
|
|
46
|
+
) as Parameters<typeof solidMergeProps>),
|
|
47
|
+
);
|
|
48
|
+
}) as typeof solidMergeProps;
|
|
@@ -51,7 +51,7 @@ function createKeyboardEvent(
|
|
|
51
51
|
keyCode: number,
|
|
52
52
|
eventName: string = 'keydown',
|
|
53
53
|
): KeyboardEvent {
|
|
54
|
-
|
|
54
|
+
const event = new KeyboardEvent(eventName, {
|
|
55
55
|
key,
|
|
56
56
|
keyCode,
|
|
57
57
|
which: keyCode,
|
|
@@ -61,6 +61,18 @@ function createKeyboardEvent(
|
|
|
61
61
|
metaKey: false,
|
|
62
62
|
bubbles: true,
|
|
63
63
|
});
|
|
64
|
+
|
|
65
|
+
// Chrome < 51 (LG webOS 3.x runs Chrome 38) ignores the key/keyCode/which
|
|
66
|
+
// members of KeyboardEventInit, so the event arrives with key '' / keyCode 0
|
|
67
|
+
// and the focusManager drops it. Force the values onto the instance so Magic
|
|
68
|
+
// Remote clicks and scrolls still map to keys on those devices.
|
|
69
|
+
if (event.key !== key || event.keyCode !== keyCode) {
|
|
70
|
+
Object.defineProperty(event, 'key', { get: () => key });
|
|
71
|
+
Object.defineProperty(event, 'keyCode', { get: () => keyCode });
|
|
72
|
+
Object.defineProperty(event, 'which', { get: () => keyCode });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return event;
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
const [cursorVisible, setCursorVisible] = createSignal(false);
|
package/src/render.ts
CHANGED
|
@@ -61,10 +61,14 @@ export const {
|
|
|
61
61
|
insert,
|
|
62
62
|
spread,
|
|
63
63
|
setProp,
|
|
64
|
-
mergeProps,
|
|
65
64
|
use,
|
|
66
65
|
} = solidRenderer;
|
|
67
66
|
|
|
67
|
+
// Re-export a Proxy-free-safe mergeProps in place of the renderer's own so the
|
|
68
|
+
// JSX compiler routes compiled spreads through it — fixes dropped spread props
|
|
69
|
+
// on engines without Proxy (Chrome 38 / webOS 3). See ./mergeProps.ts.
|
|
70
|
+
export { mergeProps } from './mergeProps.js';
|
|
71
|
+
|
|
68
72
|
type Task = () => void;
|
|
69
73
|
const taskQueue: Task[] = [];
|
|
70
74
|
let tasksEnabled = false;
|