@solidtv/solid 1.3.9 → 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 +16 -7
- 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/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 +18 -7
- package/src/core/lightningInit.ts +99 -2
- package/src/mergeProps.ts +48 -0
- 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": {},
|
|
@@ -2279,7 +2279,7 @@ export class DOMRendererMain implements IRendererMain {
|
|
|
2279
2279
|
}
|
|
2280
2280
|
|
|
2281
2281
|
export function loadFontToDom(font: FontLoadOptions): void {
|
|
2282
|
-
// fontFamily: string;
|
|
2282
|
+
// fontFamily: string | string[];
|
|
2283
2283
|
// metrics?: FontMetrics;
|
|
2284
2284
|
// fontUrl?: string;
|
|
2285
2285
|
// atlasUrl?: string;
|
|
@@ -2294,16 +2294,27 @@ export function loadFontToDom(font: FontLoadOptions): void {
|
|
|
2294
2294
|
return;
|
|
2295
2295
|
}
|
|
2296
2296
|
|
|
2297
|
-
const fontFace = new FontFace(font.fontFamily, `url(${font.fontUrl})`);
|
|
2298
2297
|
const fontSet = document.fonts as FontFaceSet & {
|
|
2299
2298
|
add?: (font: FontFace) => FontFaceSet;
|
|
2300
2299
|
};
|
|
2301
|
-
fontSet.add?.(fontFace);
|
|
2302
2300
|
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
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
|
+
}
|
|
2307
2318
|
}
|
|
2308
2319
|
|
|
2309
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;
|
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;
|