@solidtv/solid 1.7.4 → 1.8.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/MIGRATION-1.8.md +270 -0
- package/dist/src/core/dom-renderer/dashedBorderStyle.d.ts +20 -0
- package/dist/src/core/dom-renderer/dashedBorderStyle.js +104 -0
- package/dist/src/core/dom-renderer/dashedBorderStyle.js.map +1 -0
- package/dist/src/core/dom-renderer/domRenderer.d.ts +14 -0
- package/dist/src/core/dom-renderer/domRenderer.js +194 -12
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +12 -2
- package/dist/src/core/elementNode.d.ts +176 -9
- package/dist/src/core/elementNode.js +1906 -411
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/flexLayout.d.ts +6 -0
- package/dist/src/core/flexLayout.js +535 -218
- package/dist/src/core/flexLayout.js.map +1 -1
- package/dist/src/core/focusManager.js +70 -23
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/fontLoaded.d.ts +10 -0
- package/dist/src/core/fontLoaded.js +26 -0
- package/dist/src/core/fontLoaded.js.map +1 -0
- package/dist/src/core/intrinsicTypes.d.ts +2 -1
- package/dist/src/core/lightningInit.js +8 -1
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/core/shaders.d.ts +5 -2
- package/dist/src/core/shaders.js +6 -0
- package/dist/src/core/shaders.js.map +1 -1
- package/dist/src/core/states.d.ts +2 -0
- package/dist/src/core/states.js +26 -7
- package/dist/src/core/states.js.map +1 -1
- package/dist/src/core/stylePlan.d.ts +39 -0
- package/dist/src/core/stylePlan.js +159 -0
- package/dist/src/core/stylePlan.js.map +1 -0
- package/dist/src/core/utils.js +2 -2
- package/dist/src/primitives/Grid.jsx +22 -3
- package/dist/src/primitives/Grid.jsx.map +1 -1
- package/dist/src/primitives/Virtual.jsx +16 -6
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/utils/handleNavigation.js +29 -6
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.js +2 -1
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/src/solidOpts.js +22 -8
- package/dist/src/solidOpts.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/AI_CODING_GUIDELINES.md +7 -6
- package/docs/AI_UPGRADE_1.8.md +290 -0
- package/package.json +5 -3
- package/src/core/dom-renderer/dashedBorderStyle.ts +128 -0
- package/src/core/dom-renderer/domRenderer.ts +201 -10
- package/src/core/dom-renderer/domRendererTypes.ts +12 -0
- package/src/core/elementNode.ts +2124 -459
- package/src/core/flexLayout.ts +583 -231
- package/src/core/focusManager.ts +86 -27
- package/src/core/fontLoaded.ts +29 -0
- package/src/core/intrinsicTypes.ts +2 -0
- package/src/core/lightningInit.ts +8 -1
- package/src/core/shaders.ts +12 -0
- package/src/core/states.ts +29 -9
- package/src/core/stylePlan.ts +195 -0
- package/src/core/utils.ts +2 -2
- package/src/primitives/Grid.tsx +35 -9
- package/src/primitives/Virtual.tsx +20 -6
- package/src/primitives/utils/handleNavigation.ts +40 -6
- package/src/primitives/utils/withScrolling.ts +3 -2
- package/src/solidOpts.ts +23 -8
- package/dist/src/core/flex.d.ts +0 -2
- package/dist/src/core/flex.js +0 -285
- package/dist/src/core/flex.js.map +0 -1
- package/src/core/flex.ts +0 -332
|
@@ -1,37 +1,76 @@
|
|
|
1
1
|
import { renderer } from './lightningInit.js';
|
|
2
2
|
import States from './states.js';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
? calculateFlexNew
|
|
7
|
-
: calculateFlexOld;
|
|
8
|
-
import { log, isArray, keyExists, isINode, isElementNode, isElementText, logRenderTree, isFunction, } from './utils.js';
|
|
3
|
+
import calculateFlex, { getArrayValue } from './flexLayout.js';
|
|
4
|
+
import { log, isArray, isObject, isString, isINode, isElementNode, isElementText, logRenderTree, isFunction, } from './utils.js';
|
|
5
|
+
import { compileBlock, shaderParse } from './stylePlan.js';
|
|
9
6
|
import { isDev, SHADERS_ENABLED } from './env.js';
|
|
10
7
|
import { Config, isDomRendererActive } from './config.js';
|
|
11
8
|
import { assertTruthy } from '@solidtv/renderer/utils';
|
|
12
9
|
import { NodeType } from './nodeTypes.js';
|
|
13
10
|
import { setActiveElementCore, } from './focusManager.js';
|
|
14
11
|
import { initClickInspector } from './clickInspector.js';
|
|
12
|
+
import { onFontLoaded } from './fontLoaded.js';
|
|
15
13
|
// Unified post-mutation scheduler.
|
|
16
14
|
//
|
|
17
|
-
// Three phases run in one microtask (or
|
|
15
|
+
// Three phases run in one microtask (or, for a `loaded` handler, in the
|
|
16
|
+
// renderer frame between its walks: schedulePostMutationInFrame):
|
|
18
17
|
// 1. delete-flush — destroy nodes that were removed and not re-inserted
|
|
19
|
-
// 2. layout —
|
|
18
|
+
// 2. layout — measure the texts written since the last run (and
|
|
19
|
+
// those that waited for a font), then recompute flex
|
|
20
|
+
// layout for any dirty subtree
|
|
20
21
|
// 3. focus — resolve forwardFocus on deferred elements, then apply
|
|
21
22
|
//
|
|
22
23
|
// Order matters: layout reads the rendered tree (so destroyed nodes must be
|
|
23
24
|
// gone), and focus reads the laid-out tree.
|
|
24
25
|
let postMutationQueued = false;
|
|
26
|
+
let postMutationInFrame = false;
|
|
25
27
|
let nextActiveElement = null;
|
|
26
28
|
let deferredFocusElement = null;
|
|
27
|
-
|
|
29
|
+
// Entries past elementDeleteCount are undefined; the array keeps its
|
|
30
|
+
// capacity between runs.
|
|
28
31
|
const elementDeleteQueue = [];
|
|
32
|
+
let elementDeleteCount = 0;
|
|
33
|
+
// The layout queue: containers bucketed by depth (the root's children are at
|
|
34
|
+
// depth 1), laid out deepest first, so a container runs after every queued
|
|
35
|
+
// container inside it. A node is in at most one bucket entry that counts
|
|
36
|
+
// (`_layoutQueued`); updateLayout() clears it, so a node laid out directly is
|
|
37
|
+
// skipped when its entry comes up. Buckets keep their capacity: no allocation
|
|
38
|
+
// per run once the tree's depth has been seen.
|
|
39
|
+
const layoutBuckets = [];
|
|
40
|
+
const layoutBucketSize = [];
|
|
41
|
+
let layoutMaxDepth = -1; // deepest bucket that may hold a node
|
|
42
|
+
let layoutSweepDepth = -1; // bucket the layout phase is on, -1 outside it
|
|
43
|
+
// A node was queued since the layout phase last ran to its end (one that
|
|
44
|
+
// threw leaves it set, so the entries it left run next time).
|
|
45
|
+
let layoutPending = false;
|
|
46
|
+
// Text measurement (design 3.4): a `<text>` whose parent lays out is sized by
|
|
47
|
+
// the renderer's synchronous `measure()` before the parent's flex, not by the
|
|
48
|
+
// walk and its `loaded` event. A write to a prop its layout reads queues it
|
|
49
|
+
// here (`TextMeasure.due`); the layout phase measures the queue and queues
|
|
50
|
+
// the parent of a text whose size, as flex reads it, changed. Entries past
|
|
51
|
+
// textMeasureCount are undefined; the array keeps its capacity.
|
|
52
|
+
const textMeasureQueue = [];
|
|
53
|
+
let textMeasureCount = 0;
|
|
54
|
+
// Texts whose font's description was missing when measured (`waiting`):
|
|
55
|
+
// each hears `loaded` once (the walk lays it out when the font arrives), and
|
|
56
|
+
// loadFonts() tells when a font has loaded, for those no walk visits. Both
|
|
57
|
+
// set fontWaitingDue; the layout phase then measures them.
|
|
58
|
+
const fontWaiting = [];
|
|
59
|
+
let fontWaitingDue = false;
|
|
60
|
+
// Length at which the list is next swept of texts that no longer wait
|
|
61
|
+
// (destroyed: nothing else takes them off while their font never loads).
|
|
62
|
+
// Never while measureFontWaiting walks it (`measuringFontWaiting`).
|
|
63
|
+
let fontWaitingSweepAt = 64;
|
|
64
|
+
let measuringFontWaiting = false;
|
|
65
|
+
// Re-measures in one layout phase before the rest waits for its next change:
|
|
66
|
+
// a text whose size flex writes (flexGrow, flexShrink, minWidth) settles in
|
|
67
|
+
// one or two, so more means a layout that does not converge.
|
|
68
|
+
const MAX_TEXT_SWEEPS = 16;
|
|
29
69
|
export function enqueueDelete(node, n) {
|
|
30
70
|
if (node._queueDelete === undefined) {
|
|
31
71
|
node._queueDelete = n;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
72
|
+
elementDeleteQueue[elementDeleteCount++] = node;
|
|
73
|
+
schedulePostMutation();
|
|
35
74
|
}
|
|
36
75
|
else {
|
|
37
76
|
node._queueDelete += n;
|
|
@@ -41,31 +80,98 @@ function schedulePostMutation() {
|
|
|
41
80
|
if (postMutationQueued)
|
|
42
81
|
return;
|
|
43
82
|
postMutationQueued = true;
|
|
44
|
-
if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) {
|
|
45
|
-
renderer.stage.reprocessUpdates(runPostMutation);
|
|
46
|
-
}
|
|
47
83
|
queueMicrotask(runPostMutation);
|
|
48
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Also runs the post-mutation pass inside the renderer's current or next
|
|
87
|
+
* frame, after its walk and before the draw, so what it writes is drawn in
|
|
88
|
+
* that frame. For handlers the renderer calls between its walks (`loaded`).
|
|
89
|
+
*/
|
|
90
|
+
function schedulePostMutationInFrame() {
|
|
91
|
+
schedulePostMutation();
|
|
92
|
+
if (postMutationInFrame)
|
|
93
|
+
return;
|
|
94
|
+
const stage = renderer.stage;
|
|
95
|
+
if ('reprocessUpdates' in stage && stage.reprocessUpdates) {
|
|
96
|
+
postMutationInFrame = true;
|
|
97
|
+
stage.reprocessUpdates(runPostMutation);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
49
100
|
function runPostMutation() {
|
|
50
101
|
postMutationQueued = false;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
102
|
+
postMutationInFrame = false;
|
|
103
|
+
// Phase 1: delete-flush (the count is read every time: a destroy can
|
|
104
|
+
// queue more). An entry is cleared before its destroy, so one whose
|
|
105
|
+
// onDestroy threw is not retried and the next run carries on after it.
|
|
106
|
+
if (elementDeleteCount > 0) {
|
|
107
|
+
for (let i = 0; i < elementDeleteCount; i++) {
|
|
108
|
+
const el = elementDeleteQueue[i];
|
|
109
|
+
elementDeleteQueue[i] = undefined;
|
|
110
|
+
if (el === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
const queued = el._queueDelete ?? 0;
|
|
113
|
+
el._queueDelete = undefined;
|
|
114
|
+
if (queued < 0) {
|
|
55
115
|
el.destroy();
|
|
56
116
|
}
|
|
57
|
-
el._queueDelete = undefined;
|
|
58
117
|
}
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
// Phase 2: layout
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
118
|
+
elementDeleteCount = 0;
|
|
119
|
+
}
|
|
120
|
+
// Phase 2: layout. Inline, not a function of its own: terser's default
|
|
121
|
+
// `reduce_funcs` turns a module function with one call site into a
|
|
122
|
+
// closure per call (as with every helper on this path).
|
|
123
|
+
if (fontWaitingDue === true) {
|
|
124
|
+
TextMeasure.measureFontWaiting();
|
|
125
|
+
}
|
|
126
|
+
if (layoutPending === true || textMeasureCount > 0) {
|
|
127
|
+
measureQueuedTexts();
|
|
128
|
+
// Start from the deepest bucket there is, so entries a run that threw
|
|
129
|
+
// left behind are not stranded.
|
|
130
|
+
layoutMaxDepth = layoutBuckets.length - 1;
|
|
131
|
+
let textSweeps = 0;
|
|
132
|
+
while (layoutMaxDepth >= 0) {
|
|
133
|
+
let depth = layoutMaxDepth;
|
|
134
|
+
layoutMaxDepth = -1;
|
|
135
|
+
for (; depth >= 0; depth--) {
|
|
136
|
+
layoutSweepDepth = depth;
|
|
137
|
+
const bucket = layoutBuckets[depth];
|
|
138
|
+
// Read the size every time: a run can queue more at this depth.
|
|
139
|
+
for (let i = 0; i < layoutBucketSize[depth]; i++) {
|
|
140
|
+
const node = bucket[i];
|
|
141
|
+
bucket[i] = undefined;
|
|
142
|
+
if (node !== undefined && node._layoutQueued === true) {
|
|
143
|
+
node.updateLayout();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
layoutBucketSize[depth] = 0;
|
|
147
|
+
}
|
|
148
|
+
layoutSweepDepth = -1;
|
|
149
|
+
// Texts the sweep wrote (flex sizing a text, an onLayout): measured
|
|
150
|
+
// now, so the container of one that resized runs again in another
|
|
151
|
+
// sweep.
|
|
152
|
+
if (textMeasureCount > 0 && textSweeps < MAX_TEXT_SWEEPS) {
|
|
153
|
+
textSweeps++;
|
|
154
|
+
measureQueuedTexts();
|
|
155
|
+
}
|
|
68
156
|
}
|
|
157
|
+
if (textMeasureCount > 0) {
|
|
158
|
+
// Not converging: drop the rest (each is measured again at its next
|
|
159
|
+
// change), or the run its writes scheduled would start over.
|
|
160
|
+
for (let i = 0; i < textMeasureCount; i++) {
|
|
161
|
+
const t = textMeasureQueue[i];
|
|
162
|
+
textMeasureQueue[i] = undefined;
|
|
163
|
+
if (t !== undefined) {
|
|
164
|
+
t._text.due = false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
textMeasureCount = 0;
|
|
168
|
+
if (isDev) {
|
|
169
|
+
console.warn('[solid] Text sizes did not settle in ' +
|
|
170
|
+
MAX_TEXT_SWEEPS +
|
|
171
|
+
' layout passes (a layout that changes the size of a text it lays out); the rest waits for its next change.');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
layoutPending = false;
|
|
69
175
|
}
|
|
70
176
|
// Phase 3: focus. setFocus() may have evaluated forwardFocus pre-render
|
|
71
177
|
// (when no children existed yet); deferredFocusElement re-runs setFocus
|
|
@@ -81,26 +187,170 @@ function runPostMutation() {
|
|
|
81
187
|
setActiveElementCore(element);
|
|
82
188
|
}
|
|
83
189
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
190
|
+
function enqueueLayout(node) {
|
|
191
|
+
if (node._layoutQueued === true)
|
|
192
|
+
return;
|
|
193
|
+
node._layoutQueued = true;
|
|
194
|
+
layoutPending = true;
|
|
195
|
+
// The depth in its tree: a removed node's tree ends at it.
|
|
196
|
+
let depth = 0;
|
|
197
|
+
for (let n = node, p = n.parent; n._detached !== true && p !== undefined && p !== null; n = p, p = n.parent) {
|
|
198
|
+
depth++;
|
|
199
|
+
}
|
|
200
|
+
while (layoutBuckets.length <= depth) {
|
|
201
|
+
layoutBuckets.push([]);
|
|
202
|
+
layoutBucketSize.push(0);
|
|
203
|
+
}
|
|
204
|
+
const size = layoutBucketSize[depth];
|
|
205
|
+
layoutBuckets[depth][size] = node;
|
|
206
|
+
layoutBucketSize[depth] = size + 1;
|
|
207
|
+
// During a sweep, a node at the bucket being run or shallower is reached
|
|
208
|
+
// by that sweep; a deeper one needs another.
|
|
209
|
+
if (depth > layoutMaxDepth && depth > layoutSweepDepth) {
|
|
210
|
+
layoutMaxDepth = depth;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Queue `node`'s layout (flex and `onLayout`) for the post-mutation pass.
|
|
215
|
+
* Within one pass, containers run deepest first, each at most once unless a
|
|
216
|
+
* child's size changed after its run.
|
|
217
|
+
*/
|
|
218
|
+
function queueLayout(node) {
|
|
219
|
+
enqueueLayout(node);
|
|
86
220
|
schedulePostMutation();
|
|
87
221
|
}
|
|
88
222
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
223
|
+
* Measures the texts written since the last call (`_textLayoutDirty`) and
|
|
224
|
+
* queues the parent of each whose size, as flex reads it, changed. A text
|
|
225
|
+
* the parent's updateLayout() measured already is skipped.
|
|
226
|
+
*/
|
|
227
|
+
function measureQueuedTexts() {
|
|
228
|
+
for (let i = 0; i < textMeasureCount; i++) {
|
|
229
|
+
const t = textMeasureQueue[i];
|
|
230
|
+
textMeasureQueue[i] = undefined;
|
|
231
|
+
// Cleared by a run that threw part way (the count was not reset).
|
|
232
|
+
if (t === undefined) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const m = t._text;
|
|
236
|
+
if (m.due !== true) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const parent = t._parent;
|
|
240
|
+
if (parent === undefined || parent._requiresLayout !== true) {
|
|
241
|
+
// Moved out, or the parent stopped laying out: nothing to size.
|
|
242
|
+
m.due = false;
|
|
243
|
+
m.w = NaN;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (t._measureText() === true) {
|
|
247
|
+
enqueueLayout(parent);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
textMeasureCount = 0;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* A text that waited for its font heard `loaded`: the walk laid it out, as
|
|
254
|
+
* the font's description arrived. Shared by every waiting text (no closure
|
|
255
|
+
* per text); the layout phase, in this frame, measures them all.
|
|
256
|
+
*/
|
|
257
|
+
function fontWaitHeard() {
|
|
258
|
+
fontWaitingDue = true;
|
|
259
|
+
schedulePostMutationInFrame();
|
|
260
|
+
}
|
|
261
|
+
/** Drops the texts that no longer wait for a font (destroyed ones). */
|
|
262
|
+
function sweepFontWaiting() {
|
|
263
|
+
let kept = 0;
|
|
264
|
+
for (let i = 0; i < fontWaiting.length; i++) {
|
|
265
|
+
const t = fontWaiting[i];
|
|
266
|
+
if (t._text.waiting === true && t.destroyed !== true) {
|
|
267
|
+
fontWaiting[kept++] = t;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
fontWaiting.length = kept;
|
|
271
|
+
fontWaitingSweepAt = kept * 2 > 64 ? kept * 2 : 64;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* What Solid knows of a `<text>` it measures (`ElementNode._text`), made the
|
|
275
|
+
* first time: only texts in a container that lays out have one. Its sizes
|
|
276
|
+
* start as doubles, so storing a measured size allocates nothing.
|
|
92
277
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
278
|
+
class TextMeasure {
|
|
279
|
+
constructor() {
|
|
280
|
+
this.due = false;
|
|
281
|
+
this.waiting = false;
|
|
282
|
+
this.w = NaN;
|
|
283
|
+
this.h = NaN;
|
|
284
|
+
this.listening = false;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Measures the texts that waited for a font (`_waitForFont`): one whose
|
|
288
|
+
* font is there now stops waiting and, if its size changed, queues its
|
|
289
|
+
* parent; one whose font is still missing waits again. A method, not a
|
|
290
|
+
* module function: the post-mutation pass is its one caller, and terser's
|
|
291
|
+
* default `reduce_funcs` turns such a function into a closure per call.
|
|
292
|
+
* (Its own: the try would keep that pass from being optimized.)
|
|
293
|
+
*/
|
|
294
|
+
static measureFontWaiting() {
|
|
295
|
+
fontWaitingDue = false;
|
|
296
|
+
const n = fontWaiting.length;
|
|
297
|
+
// A text whose font is still missing is appended again (_waitForFont),
|
|
298
|
+
// which must not sweep the list under this loop.
|
|
299
|
+
measuringFontWaiting = true;
|
|
300
|
+
try {
|
|
301
|
+
for (let i = 0; i < n; i++) {
|
|
302
|
+
const t = fontWaiting[i];
|
|
303
|
+
const m = t._text;
|
|
304
|
+
if (m.waiting !== true) {
|
|
305
|
+
continue; // measured meanwhile
|
|
306
|
+
}
|
|
307
|
+
// Off first, so a measure() now queues no `loaded` for it.
|
|
308
|
+
t.lng.off('loaded', fontWaitHeard);
|
|
309
|
+
m.waiting = false;
|
|
310
|
+
if (t.destroyed === true) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const parent = t._parent;
|
|
314
|
+
if (parent === undefined ||
|
|
315
|
+
t._detached === true ||
|
|
316
|
+
parent._requiresLayout !== true) {
|
|
317
|
+
m.w = NaN;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
// Waits again (appended past n) while the font is still missing.
|
|
321
|
+
if (t._measureText() === true) {
|
|
322
|
+
enqueueLayout(parent);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
99
325
|
}
|
|
100
|
-
|
|
326
|
+
finally {
|
|
327
|
+
measuringFontWaiting = false;
|
|
328
|
+
}
|
|
329
|
+
// Keep the entries appended meanwhile, without allocating.
|
|
330
|
+
const length = fontWaiting.length;
|
|
331
|
+
for (let i = n; i < length; i++) {
|
|
332
|
+
fontWaiting[i - n] = fontWaiting[i];
|
|
333
|
+
}
|
|
334
|
+
fontWaiting.length = length - n;
|
|
101
335
|
}
|
|
102
|
-
return index;
|
|
103
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* The settings of an animation that has none (no `animationSettings` on the
|
|
339
|
+
* node or in Config): one object, so renderer v2's animateProp, which reuses
|
|
340
|
+
* its controller for the same settings object, retargets a running one
|
|
341
|
+
* rather than stopping it and making another per write. Nothing writes it.
|
|
342
|
+
*/
|
|
343
|
+
const NO_ANIMATION_SETTINGS = Object.freeze({});
|
|
344
|
+
/** onAnimation.stopped for one write, after its duration and delay. */
|
|
345
|
+
function fireAnimationStopped(node, stopped, name, value) {
|
|
346
|
+
stopped.call(node, name, value);
|
|
347
|
+
}
|
|
348
|
+
onFontLoaded(() => {
|
|
349
|
+
if (fontWaiting.length > 0) {
|
|
350
|
+
fontWaitingDue = true;
|
|
351
|
+
schedulePostMutation();
|
|
352
|
+
}
|
|
353
|
+
});
|
|
104
354
|
// Text-default template, built once on first use. Config.fontSettings is
|
|
105
355
|
// expected to be set at app startup and not change afterwards.
|
|
106
356
|
let _fontTemplate;
|
|
@@ -128,45 +378,19 @@ const EFFECT_SHADER_KEYS = [
|
|
|
128
378
|
'borderLeft',
|
|
129
379
|
'shadow',
|
|
130
380
|
];
|
|
131
|
-
const
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const parseAndAssignShaderProps = (prefix, obj, props = {}) => {
|
|
144
|
-
if (!obj)
|
|
145
|
-
return;
|
|
146
|
-
const side = borderSideMap[prefix];
|
|
147
|
-
const actualPrefix = side ? 'border' : prefix;
|
|
148
|
-
let names = shaderPropNames[prefix];
|
|
149
|
-
if (names === undefined) {
|
|
150
|
-
names = Object.create(null);
|
|
151
|
-
shaderPropNames[prefix] = names;
|
|
152
|
-
}
|
|
153
|
-
props[actualPrefix] = obj;
|
|
154
|
-
// The object's own enumerable keys in order, as Object.entries gave them,
|
|
155
|
-
// without its arrays and closure.
|
|
156
|
-
for (const key in obj) {
|
|
157
|
-
if (!hasOwnProperty.call(obj, key))
|
|
158
|
-
continue;
|
|
159
|
-
let name = names[key];
|
|
160
|
-
if (name === undefined) {
|
|
161
|
-
let transformedKey = key === 'width' ? 'w' : key;
|
|
162
|
-
// If border side and key is width/w, transform to side (bottom/left/right/top)
|
|
163
|
-
if (side && transformedKey === 'w') {
|
|
164
|
-
transformedKey = side;
|
|
165
|
-
}
|
|
166
|
-
name = actualPrefix + '-' + transformedKey;
|
|
167
|
-
names[key] = name;
|
|
381
|
+
const parseAndAssignShaderProps = (prefix, obj, props) => {
|
|
382
|
+
// Parsed once per object (stylePlan.ts): `border` and `border-w`, ... A
|
|
383
|
+
// sub-prop the props already hold with that value is not written again
|
|
384
|
+
// (a facade write repacks); the result is the merge 1.6's writes gave.
|
|
385
|
+
const parse = shaderParse(prefix, obj);
|
|
386
|
+
const keys = parse.keys;
|
|
387
|
+
const values = parse.values;
|
|
388
|
+
for (let i = 0; i < keys.length; i++) {
|
|
389
|
+
const name = keys[i];
|
|
390
|
+
const value = values[i];
|
|
391
|
+
if (props[name] !== value) {
|
|
392
|
+
props[name] = value;
|
|
168
393
|
}
|
|
169
|
-
props[name] = obj[key];
|
|
170
394
|
}
|
|
171
395
|
};
|
|
172
396
|
const assignEffects = (v, props) => {
|
|
@@ -175,16 +399,10 @@ const assignEffects = (v, props) => {
|
|
|
175
399
|
if (v.borderRadius)
|
|
176
400
|
props.radius = v.borderRadius;
|
|
177
401
|
for (const k of EFFECT_SHADER_KEYS) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
const assignShaderProp = (key, value, props) => {
|
|
183
|
-
if (key === 'rounded' || typeof value === 'number') {
|
|
184
|
-
props.radius = value;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
parseAndAssignShaderProps(key, value, props);
|
|
402
|
+
const obj = v[k];
|
|
403
|
+
if (isObject(obj)) {
|
|
404
|
+
parseAndAssignShaderProps(k, obj, props);
|
|
405
|
+
}
|
|
188
406
|
}
|
|
189
407
|
};
|
|
190
408
|
// The shader types convertToShader makes, by feature bits.
|
|
@@ -219,6 +437,96 @@ const hasBorderWidth = (props, change) => {
|
|
|
219
437
|
}
|
|
220
438
|
return false;
|
|
221
439
|
};
|
|
440
|
+
const copyOf = (value) => isArray(value) ? value.slice() : value;
|
|
441
|
+
/** The gradient shaders the raw accessors made, by accessor key. */
|
|
442
|
+
const gradientShaders = new WeakMap();
|
|
443
|
+
/** Marks a key a state change tracks but has not written yet. */
|
|
444
|
+
const UNWRITTEN = {};
|
|
445
|
+
/**
|
|
446
|
+
* The border family: the style keys whose objects write the `border-*`
|
|
447
|
+
* shader props (a `border` write sets all four widths, a side its own).
|
|
448
|
+
*/
|
|
449
|
+
const BORDER_FAMILY = {
|
|
450
|
+
border: true,
|
|
451
|
+
borderTop: true,
|
|
452
|
+
borderRight: true,
|
|
453
|
+
borderBottom: true,
|
|
454
|
+
borderLeft: true,
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Append the keys of the `$state` block `block` that `keys` does not hold
|
|
458
|
+
* yet (they are written for the first time). Returns the new count.
|
|
459
|
+
*/
|
|
460
|
+
function trackKeys(block, keys, count, applied) {
|
|
461
|
+
if (!isObject(block)) {
|
|
462
|
+
return count;
|
|
463
|
+
}
|
|
464
|
+
const blockKeys = compileBlock(block).keys;
|
|
465
|
+
for (let j = 0; j < blockKeys.length; j++) {
|
|
466
|
+
const key = blockKeys[j];
|
|
467
|
+
let k = 0;
|
|
468
|
+
while (k < count && keys[k] !== key) {
|
|
469
|
+
k++;
|
|
470
|
+
}
|
|
471
|
+
if (k === count) {
|
|
472
|
+
if (count < keys.length) {
|
|
473
|
+
keys[count] = key;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
keys.push(key);
|
|
477
|
+
}
|
|
478
|
+
count++;
|
|
479
|
+
applied[key] = UNWRITTEN;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return count;
|
|
483
|
+
}
|
|
484
|
+
/** The base value undo restores: theme[key], else style[key] (pinned). */
|
|
485
|
+
function styleFallback(node, key) {
|
|
486
|
+
const theme = node._theme;
|
|
487
|
+
let value = theme !== undefined ? theme[key] : undefined;
|
|
488
|
+
if (value === undefined) {
|
|
489
|
+
const style = node._style;
|
|
490
|
+
if (style !== undefined) {
|
|
491
|
+
value = style[key];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (isDev && value === undefined) {
|
|
495
|
+
console.warn('fallback style key not found: ', key);
|
|
496
|
+
}
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* The value `key` takes with `states` on: from the block of the state of
|
|
501
|
+
* highest precedence that has it (the later in `order`, then the later
|
|
502
|
+
* added; `order` undefined: the later added), else the base value.
|
|
503
|
+
*/
|
|
504
|
+
function resolveStateValue(node, key, states, order) {
|
|
505
|
+
let best = -2;
|
|
506
|
+
let plan;
|
|
507
|
+
let at = 0;
|
|
508
|
+
for (let i = 0; i < states.length; i++) {
|
|
509
|
+
const state = states[i];
|
|
510
|
+
const block = node[state];
|
|
511
|
+
if (isObject(block)) {
|
|
512
|
+
const candidate = compileBlock(block);
|
|
513
|
+
const pos = candidate.index[key];
|
|
514
|
+
if (pos !== undefined) {
|
|
515
|
+
const rank = order === undefined ? -1 : order.indexOf(state);
|
|
516
|
+
if (rank >= best) {
|
|
517
|
+
best = rank;
|
|
518
|
+
plan = candidate;
|
|
519
|
+
at = pos;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (plan === undefined) {
|
|
525
|
+
return styleFallback(node, key);
|
|
526
|
+
}
|
|
527
|
+
// A getter is read now, each time the state is applied (pinned).
|
|
528
|
+
return plan.getters[at] === true ? plan.block[key] : plan.values[at];
|
|
529
|
+
}
|
|
222
530
|
export function convertToShader(node, v) {
|
|
223
531
|
const props = v;
|
|
224
532
|
const features = (hasBorderWidth(props) ? BORDER_FEATURE : 0) |
|
|
@@ -227,88 +535,6 @@ export function convertToShader(node, v) {
|
|
|
227
535
|
node._shaderFeatures = features;
|
|
228
536
|
return renderer.createShader(ROUNDED_SHADER_TYPES[features], props);
|
|
229
537
|
}
|
|
230
|
-
function getPropertyAlias(name) {
|
|
231
|
-
if (name === 'w')
|
|
232
|
-
return 'width';
|
|
233
|
-
if (name === 'h')
|
|
234
|
-
return 'height';
|
|
235
|
-
return name;
|
|
236
|
-
}
|
|
237
|
-
const LightningRendererNumberProps = [
|
|
238
|
-
'alpha',
|
|
239
|
-
'color',
|
|
240
|
-
'colorTop',
|
|
241
|
-
'colorRight',
|
|
242
|
-
'colorLeft',
|
|
243
|
-
'colorBottom',
|
|
244
|
-
'colorTl',
|
|
245
|
-
'colorTr',
|
|
246
|
-
'colorBl',
|
|
247
|
-
'colorBr',
|
|
248
|
-
'h',
|
|
249
|
-
'fontSize',
|
|
250
|
-
'lineHeight',
|
|
251
|
-
'mount',
|
|
252
|
-
'mountX',
|
|
253
|
-
'mountY',
|
|
254
|
-
'pivot',
|
|
255
|
-
'pivotX',
|
|
256
|
-
'pivotY',
|
|
257
|
-
'rotation',
|
|
258
|
-
'scale',
|
|
259
|
-
'scaleX',
|
|
260
|
-
'scaleY',
|
|
261
|
-
'w',
|
|
262
|
-
'worldX',
|
|
263
|
-
'worldY',
|
|
264
|
-
'x',
|
|
265
|
-
'y',
|
|
266
|
-
'zIndex',
|
|
267
|
-
'zIndexLocked',
|
|
268
|
-
];
|
|
269
|
-
const LightningRendererNonAnimatingProps = [
|
|
270
|
-
'absX',
|
|
271
|
-
'absY',
|
|
272
|
-
'atlasGroup',
|
|
273
|
-
'autosize',
|
|
274
|
-
'clipping',
|
|
275
|
-
'contain',
|
|
276
|
-
'componentName',
|
|
277
|
-
'componentLocation',
|
|
278
|
-
'data',
|
|
279
|
-
'destroyed',
|
|
280
|
-
'forceLoad',
|
|
281
|
-
'fontStretch',
|
|
282
|
-
'fontStyle',
|
|
283
|
-
'group',
|
|
284
|
-
'ignoreParentAlpha',
|
|
285
|
-
'imageType',
|
|
286
|
-
'letterSpacing',
|
|
287
|
-
'maxHeight',
|
|
288
|
-
'maxLines',
|
|
289
|
-
'maxWidth',
|
|
290
|
-
'offsetY',
|
|
291
|
-
'overflowSuffix',
|
|
292
|
-
'placeholderColor',
|
|
293
|
-
'preventCleanup',
|
|
294
|
-
'scrollable',
|
|
295
|
-
'scrollY',
|
|
296
|
-
'srcHeight',
|
|
297
|
-
'srcWidth',
|
|
298
|
-
'srcX',
|
|
299
|
-
'srcY',
|
|
300
|
-
'strictBounds',
|
|
301
|
-
'text',
|
|
302
|
-
'textAlign',
|
|
303
|
-
'textBaseline',
|
|
304
|
-
'textOverflow',
|
|
305
|
-
'texture',
|
|
306
|
-
'textureOptions',
|
|
307
|
-
'textRendererOverride',
|
|
308
|
-
'verticalAlign',
|
|
309
|
-
'wordBreak',
|
|
310
|
-
'wordWrap',
|
|
311
|
-
];
|
|
312
538
|
initClickInspector();
|
|
313
539
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
314
540
|
export class ElementNode {
|
|
@@ -343,6 +569,16 @@ export class ElementNode {
|
|
|
343
569
|
this._calcWidth = undefined;
|
|
344
570
|
this._calcHeight = undefined;
|
|
345
571
|
this._containsFlexGrow = undefined;
|
|
572
|
+
this._flexBase = undefined;
|
|
573
|
+
this._flexGrown = undefined;
|
|
574
|
+
this._flexX = undefined;
|
|
575
|
+
this._flexY = undefined;
|
|
576
|
+
this._flexW = undefined;
|
|
577
|
+
this._flexH = undefined;
|
|
578
|
+
// Written by flexLayout when it resizes a container: here, so that
|
|
579
|
+
// write adds no field.
|
|
580
|
+
this.preFlexwidth = undefined;
|
|
581
|
+
this.preFlexheight = undefined;
|
|
346
582
|
this._hasRenderedChildren = undefined;
|
|
347
583
|
this._effects = undefined;
|
|
348
584
|
this._shaderProps = undefined;
|
|
@@ -356,10 +592,16 @@ export class ElementNode {
|
|
|
356
592
|
this._theme = undefined;
|
|
357
593
|
this._lastAnyKeyPressTime = undefined;
|
|
358
594
|
this._undoStyles = undefined;
|
|
595
|
+
this._undoCount = 0;
|
|
596
|
+
this._applied = undefined;
|
|
359
597
|
this._display = undefined;
|
|
360
598
|
this._onLayout = undefined;
|
|
361
599
|
this._requiresLayout = false;
|
|
362
600
|
this._focusGen = 0;
|
|
601
|
+
this._layoutQueued = false;
|
|
602
|
+
this._textProps = undefined;
|
|
603
|
+
this._detached = false;
|
|
604
|
+
this._text = undefined;
|
|
363
605
|
}
|
|
364
606
|
get effects() {
|
|
365
607
|
return this.lng.shader;
|
|
@@ -388,7 +630,8 @@ export class ElementNode {
|
|
|
388
630
|
* Swap a shader convertToShader made when its border width moves to or
|
|
389
631
|
* from 0. For an animated write, `change` holds what animates: a border
|
|
390
632
|
* it adds is swapped in before the animation reads its start values, one
|
|
391
|
-
* it removes stays until the animation stops.
|
|
633
|
+
* it removes stays until the animation stops. A type the app did not
|
|
634
|
+
* register (createShader returns null) keeps the current shader.
|
|
392
635
|
*/
|
|
393
636
|
_syncShaderType(change) {
|
|
394
637
|
const props = this._shaderProps;
|
|
@@ -402,21 +645,25 @@ export class ElementNode {
|
|
|
402
645
|
next |= features & BORDER_FEATURE;
|
|
403
646
|
if (next === features)
|
|
404
647
|
return;
|
|
648
|
+
const shader = renderer.createShader(ROUNDED_SHADER_TYPES[next], props);
|
|
649
|
+
if (!shader)
|
|
650
|
+
return;
|
|
405
651
|
this._shaderFeatures = next;
|
|
406
|
-
this.lng.shader =
|
|
652
|
+
this.lng.shader = shader;
|
|
407
653
|
}
|
|
408
654
|
set effects(v) {
|
|
409
655
|
if (!SHADERS_ENABLED)
|
|
410
656
|
return;
|
|
411
657
|
let target = this.lng.shader || {};
|
|
412
|
-
|
|
413
|
-
|
|
658
|
+
const props = this.lng.shader?.props;
|
|
659
|
+
if (props) {
|
|
660
|
+
target = props;
|
|
414
661
|
}
|
|
415
662
|
assignEffects(v, target);
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
if (
|
|
419
|
-
assignEffects(v,
|
|
663
|
+
const kept = this._shaderProps;
|
|
664
|
+
if (kept !== undefined) {
|
|
665
|
+
if (kept !== target)
|
|
666
|
+
assignEffects(v, kept);
|
|
420
667
|
this._syncShaderType();
|
|
421
668
|
}
|
|
422
669
|
this._writeShaderTarget(target);
|
|
@@ -470,9 +717,14 @@ export class ElementNode {
|
|
|
470
717
|
}
|
|
471
718
|
/**
|
|
472
719
|
* The renderer's family name from `fontFamily` and `fontWeight`, resolved
|
|
473
|
-
* in one place so either JSX order gives the same name (B17).
|
|
720
|
+
* in one place so either JSX order gives the same name (B17). Only a
|
|
721
|
+
* `<text>` has a font: another element keeps both on the ElementNode and
|
|
722
|
+
* writes nothing to its renderer node (B20).
|
|
474
723
|
*/
|
|
475
724
|
_writeFontFamily() {
|
|
725
|
+
if (this._type !== NodeType.TextNode) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
476
728
|
const weight = this._fontWeight;
|
|
477
729
|
if (weight === undefined) {
|
|
478
730
|
// No family of its own: before render, undefined lets render's font
|
|
@@ -482,51 +734,123 @@ export class ElementNode {
|
|
|
482
734
|
const family = this._fontFamily;
|
|
483
735
|
this.lng.fontFamily =
|
|
484
736
|
family === undefined && this.rendered ? _fontFamilyWithWeight : family;
|
|
485
|
-
return;
|
|
486
737
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
738
|
+
else {
|
|
739
|
+
const alias = Config.fontWeightAlias;
|
|
740
|
+
const aliased = alias !== undefined && alias !== null
|
|
741
|
+
? alias[weight]
|
|
742
|
+
: undefined;
|
|
743
|
+
this.lng.fontFamily =
|
|
744
|
+
`${this._fontFamily || Config.fontSettings?.fontFamily}${aliased ?? weight}`;
|
|
745
|
+
}
|
|
746
|
+
this._textLayoutDirty();
|
|
493
747
|
}
|
|
494
748
|
insertChild(node, beforeNode) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
749
|
+
const children = this.children;
|
|
750
|
+
const prevParent = node.parent;
|
|
751
|
+
// Removed earlier (its parent link stays, as in 1.6): it is in no child
|
|
752
|
+
// list, so there is nothing to take it out of.
|
|
753
|
+
const detached = isElementNode(node) && node._detached;
|
|
754
|
+
// The renderer node of a rendered element is placed among its siblings
|
|
755
|
+
// in `children` order (B19: renderer v2 draws siblings in that order).
|
|
756
|
+
// The renderer keeps siblings sorted by zIndex: when the anchor's zIndex
|
|
757
|
+
// is not the child's, it takes the nearest sorted place instead, so
|
|
758
|
+
// among equal-zIndex siblings its order can then differ from `children`.
|
|
759
|
+
const drawn = this.rendered && isElementNode(node) && node.rendered;
|
|
760
|
+
// A move within this node: the renderer sibling it was drawn before, so
|
|
761
|
+
// a move that leaves it there costs the renderer nothing.
|
|
762
|
+
let drawnBefore = null;
|
|
763
|
+
// Before itself: it stays where it is (DOM semantics). Solid's swap of
|
|
764
|
+
// adjacent items asks for this (insertNode(parent, y, nextSibling(x))).
|
|
765
|
+
if (beforeNode === node) {
|
|
766
|
+
beforeNode =
|
|
767
|
+
prevParent === this && !detached
|
|
768
|
+
? children[lastIndexOf(children, node) + 1]
|
|
769
|
+
: undefined;
|
|
770
|
+
}
|
|
771
|
+
// A node in a parent (this one too) is taken out first, then inserted
|
|
772
|
+
// before `beforeNode`, or appended.
|
|
773
|
+
if (prevParent !== undefined && !detached) {
|
|
774
|
+
if (drawn && prevParent === this) {
|
|
775
|
+
drawnBefore = nextDrawn(children, lastIndexOf(children, node) + 1);
|
|
776
|
+
}
|
|
777
|
+
prevParent.removeChild(node);
|
|
778
|
+
}
|
|
779
|
+
// In a child list again (removeChild above marked it detached).
|
|
780
|
+
if (isElementNode(node)) {
|
|
781
|
+
node._detached = false;
|
|
782
|
+
}
|
|
783
|
+
// We're inserting a node thats been rendered into a node that hasn't been
|
|
784
|
+
if (!this.rendered && isElementNode(node) && node.rendered) {
|
|
785
|
+
this._hasRenderedChildren = true;
|
|
786
|
+
}
|
|
787
|
+
// DOM insertBefore semantics: an anchor that is not a child appends.
|
|
788
|
+
let index = beforeNode !== undefined && beforeNode !== null
|
|
789
|
+
? lastIndexOf(children, beforeNode)
|
|
790
|
+
: -1;
|
|
791
|
+
if (index === -1) {
|
|
792
|
+
index = children.length;
|
|
793
|
+
children.push(node);
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
// Shifted up by hand: splice allocates, and a module helper with this
|
|
797
|
+
// one call site would be a closure per call under terser's defaults.
|
|
798
|
+
let i = children.length;
|
|
799
|
+
children.push(node);
|
|
800
|
+
for (; i > index; i--) {
|
|
801
|
+
children[i] = children[i - 1];
|
|
519
802
|
}
|
|
803
|
+
children[index] = node;
|
|
804
|
+
}
|
|
805
|
+
if (!drawn) {
|
|
806
|
+
node.parent = this;
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
// insertBefore reparents the renderer node too, so the parent setter's
|
|
810
|
+
// renderer write is skipped.
|
|
811
|
+
node._parent = this;
|
|
812
|
+
const next = nextDrawn(children, index + 1);
|
|
813
|
+
if (prevParent !== this || detached || next !== drawnBefore) {
|
|
814
|
+
this.lng.insertBefore(node.lng, next === null ? null : next.lng);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* After `render()` made `node`'s renderer node (it appends), move it before
|
|
819
|
+
* the renderer node of its next rendered sibling (B19). solidOpts calls it
|
|
820
|
+
* for a node inserted before an anchor.
|
|
821
|
+
*/
|
|
822
|
+
_drawInOrder(node) {
|
|
823
|
+
const children = this.children;
|
|
824
|
+
const next = nextDrawn(children, lastIndexOf(children, node) + 1);
|
|
825
|
+
if (next !== null) {
|
|
826
|
+
this.lng.insertBefore(node.lng, next.lng);
|
|
520
827
|
}
|
|
521
|
-
this.children.push(node);
|
|
522
828
|
}
|
|
523
829
|
removeChild(node) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
830
|
+
const children = this.children;
|
|
831
|
+
const index = lastIndexOf(children, node);
|
|
832
|
+
if (index > -1) {
|
|
833
|
+
// Shifted down by hand: splice allocates the array of removed items,
|
|
834
|
+
// and a module helper with this one call site would be a closure per
|
|
835
|
+
// call under terser's defaults.
|
|
836
|
+
if (index === 0) {
|
|
837
|
+
children.shift();
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
const last = children.length - 1;
|
|
841
|
+
for (let i = index; i < last; i++) {
|
|
842
|
+
children[i] = children[i + 1];
|
|
843
|
+
}
|
|
844
|
+
children.pop();
|
|
845
|
+
}
|
|
846
|
+
if (isElementNode(node)) {
|
|
847
|
+
node._detached = true;
|
|
848
|
+
if (node.onRemove) {
|
|
849
|
+
node.onRemove.call(node, node);
|
|
850
|
+
}
|
|
527
851
|
}
|
|
528
852
|
if (this.requiresLayout()) {
|
|
529
|
-
|
|
853
|
+
queueLayout(this);
|
|
530
854
|
}
|
|
531
855
|
}
|
|
532
856
|
}
|
|
@@ -547,30 +871,54 @@ export class ElementNode {
|
|
|
547
871
|
? renderer.createShader(...shaderProps)
|
|
548
872
|
: shaderProps;
|
|
549
873
|
}
|
|
874
|
+
/**
|
|
875
|
+
* The transition path of an animatable prop's setter, which calls it only
|
|
876
|
+
* when the node has a `transition`. Returns true when the write became an
|
|
877
|
+
* animation; false when the setter stores the value itself (the common
|
|
878
|
+
* case is a direct store in the setter, under its own name).
|
|
879
|
+
*/
|
|
550
880
|
_sendToLightningAnimatable(name, value) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
881
|
+
const transition = this.transition;
|
|
882
|
+
if (!this.rendered || !transition || !Config.animationsEnabled) {
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
let animationSettings;
|
|
886
|
+
if (transition !== true) {
|
|
887
|
+
const own = transition[name];
|
|
888
|
+
// The transition may name w/h as width/height. Written inline: a
|
|
889
|
+
// single-use helper here is what terser inlines as an IIFE (a closure
|
|
890
|
+
// per call) under its default compress options.
|
|
891
|
+
const setting = own ||
|
|
892
|
+
(name === 'w'
|
|
893
|
+
? transition.width
|
|
894
|
+
: name === 'h'
|
|
895
|
+
? transition.height
|
|
896
|
+
: undefined);
|
|
897
|
+
if (!setting) {
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
animationSettings =
|
|
901
|
+
own === true ? undefined : setting;
|
|
902
|
+
}
|
|
903
|
+
// If the renderer doesn't support animateProp,
|
|
904
|
+
// keep backwards compatible with LightningRenderer
|
|
905
|
+
if (!('animateProp' in this.lng)) {
|
|
906
|
+
const animationController = this.animate({ [name]: value }, animationSettings);
|
|
569
907
|
this._fireAnimationEvents(name, value, animationSettings);
|
|
570
|
-
|
|
908
|
+
animationController.start();
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
this.lng.animateProp(name, value, animationSettings || this.animationSettings || NO_ANIMATION_SETTINGS);
|
|
912
|
+
// A text's layout prop: its container follows the animated sizes.
|
|
913
|
+
if (this._type === NodeType.TextNode &&
|
|
914
|
+
(name === 'fontSize' ||
|
|
915
|
+
name === 'lineHeight' ||
|
|
916
|
+
name === 'w' ||
|
|
917
|
+
name === 'h')) {
|
|
918
|
+
this._textLayoutAnimated();
|
|
571
919
|
}
|
|
572
|
-
this.
|
|
573
|
-
|
|
920
|
+
this._fireAnimationEvents(name, value, animationSettings);
|
|
921
|
+
return true;
|
|
574
922
|
}
|
|
575
923
|
_fireAnimationEvents(name, value, animationSettings) {
|
|
576
924
|
if (!this.onAnimation)
|
|
@@ -582,7 +930,8 @@ export class ElementNode {
|
|
|
582
930
|
}
|
|
583
931
|
if (stopped) {
|
|
584
932
|
const total = (settings?.duration ?? 0) + (settings?.delay ?? 0);
|
|
585
|
-
|
|
933
|
+
// Its arguments through the timer, not a closure per write.
|
|
934
|
+
setTimeout(fireAnimationStopped, total, this, stopped, name, value);
|
|
586
935
|
}
|
|
587
936
|
}
|
|
588
937
|
animate(props, animationSettings) {
|
|
@@ -591,7 +940,23 @@ export class ElementNode {
|
|
|
591
940
|
console.log('NOT RENDERED! CANNOT ANIMATE');
|
|
592
941
|
return { start: () => { } };
|
|
593
942
|
}
|
|
594
|
-
|
|
943
|
+
const controller = this.lng.animate(props, animationSettings || this.animationSettings || NO_ANIMATION_SETTINGS);
|
|
944
|
+
// A prop the text's layout reads (inline: a module function with this
|
|
945
|
+
// one call site would be a closure per call under terser's defaults).
|
|
946
|
+
if (this._type === NodeType.TextNode &&
|
|
947
|
+
('fontSize' in props ||
|
|
948
|
+
'lineHeight' in props ||
|
|
949
|
+
'letterSpacing' in props ||
|
|
950
|
+
'maxWidth' in props ||
|
|
951
|
+
'maxHeight' in props ||
|
|
952
|
+
'maxLines' in props ||
|
|
953
|
+
'w' in props ||
|
|
954
|
+
'h' in props)) {
|
|
955
|
+
// Started now or later, again or not at all: the text hears its
|
|
956
|
+
// layouts from now on (`_listenTextLoaded`).
|
|
957
|
+
this._textLayoutAnimated();
|
|
958
|
+
}
|
|
959
|
+
return controller;
|
|
595
960
|
}
|
|
596
961
|
chain(props, animationSettings) {
|
|
597
962
|
if (this._animationRunning) {
|
|
@@ -665,11 +1030,216 @@ export class ElementNode {
|
|
|
665
1030
|
}
|
|
666
1031
|
}
|
|
667
1032
|
_layoutOnLoad() {
|
|
1033
|
+
// An autosize node takes its size from its texture: the size the
|
|
1034
|
+
// parent's last layout saw, so a load that leaves it unchanged needs no
|
|
1035
|
+
// layout; a new one queues the parent and runs the pass in the frame.
|
|
1036
|
+
// (A text in a layout parent is measured instead: _measureText.)
|
|
1037
|
+
let width = this.width;
|
|
1038
|
+
let height = this.height;
|
|
668
1039
|
this.lng.on('loaded', () => {
|
|
669
|
-
|
|
670
|
-
this.
|
|
1040
|
+
const w = this.width;
|
|
1041
|
+
const h = this.height;
|
|
1042
|
+
if (w === width && h === height)
|
|
1043
|
+
return;
|
|
1044
|
+
width = w;
|
|
1045
|
+
height = h;
|
|
1046
|
+
const parent = this.parent;
|
|
1047
|
+
if (parent !== undefined && parent !== null && !this._detached) {
|
|
1048
|
+
enqueueLayout(parent);
|
|
1049
|
+
schedulePostMutationInFrame();
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* @internal A prop the text layout reads was written on this element:
|
|
1055
|
+
* `text`, `fontFamily`/`fontWeight`, `fontSize`, `lineHeight`,
|
|
1056
|
+
* `letterSpacing`, `maxWidth`/`width`, `maxHeight`/`height`, `maxLines`,
|
|
1057
|
+
* `wordBreak`, `overflowSuffix`. A rendered `<text>` whose parent lays out
|
|
1058
|
+
* is measured again in the post-mutation pass, and its parent laid out if
|
|
1059
|
+
* its size changed. Anything else returns at once.
|
|
1060
|
+
*/
|
|
1061
|
+
_textLayoutDirty() {
|
|
1062
|
+
if (this._type !== NodeType.TextNode || this.rendered !== true) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
let m = this._text;
|
|
1066
|
+
if (m !== undefined && m.due === true) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const parent = this._parent;
|
|
1070
|
+
if (parent === undefined || parent._requiresLayout !== true) {
|
|
1071
|
+
// No layout reads it: a parent that lays it out later measures it
|
|
1072
|
+
// first (updateLayout), as one it never measured.
|
|
1073
|
+
if (m !== undefined) {
|
|
1074
|
+
m.w = NaN;
|
|
1075
|
+
}
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (m === undefined) {
|
|
1079
|
+
m = new TextMeasure();
|
|
1080
|
+
this._text = m;
|
|
1081
|
+
}
|
|
1082
|
+
m.due = true;
|
|
1083
|
+
textMeasureQueue[textMeasureCount++] = this;
|
|
1084
|
+
schedulePostMutation();
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @internal Size this rendered `<text>` for its parent's layout now, with
|
|
1088
|
+
* the renderer's synchronous `measure()` (renderer v2 lays it out into its
|
|
1089
|
+
* layout cache, and the walk reuses that layout). Returns whether its
|
|
1090
|
+
* width or height, as flex reads them (`maxWidth || w`, `maxHeight || h`),
|
|
1091
|
+
* changed since the last call. A text with both max sizes is that large to
|
|
1092
|
+
* flex whatever its layout: the walk lays it out. While its font is
|
|
1093
|
+
* missing it waits (`_waitForFont`).
|
|
1094
|
+
*/
|
|
1095
|
+
_measureText() {
|
|
1096
|
+
let m = this._text;
|
|
1097
|
+
if (m === undefined) {
|
|
1098
|
+
m = new TextMeasure();
|
|
1099
|
+
this._text = m;
|
|
1100
|
+
}
|
|
1101
|
+
m.due = false;
|
|
1102
|
+
const lng = this.lng;
|
|
1103
|
+
const maxWidth = lng.maxWidth;
|
|
1104
|
+
const maxHeight = lng.maxHeight;
|
|
1105
|
+
if (!(maxWidth > 0 && maxHeight > 0)) {
|
|
1106
|
+
if (lng.measure() === true) {
|
|
1107
|
+
if (m.waiting === true) {
|
|
1108
|
+
// The font arrived: stop listening (the list entry goes at the
|
|
1109
|
+
// next measureFontWaiting).
|
|
1110
|
+
m.waiting = false;
|
|
1111
|
+
lng.off('loaded', fontWaitHeard);
|
|
1112
|
+
fontWaitingDue = true;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
else if (lng.destroyed === true) {
|
|
1116
|
+
return false; // in a subtree destroyed since it was written
|
|
1117
|
+
}
|
|
1118
|
+
else if (m.waiting === false) {
|
|
1119
|
+
this._waitForFont(m);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
const w = maxWidth || lng.w;
|
|
1123
|
+
const h = maxHeight || lng.h;
|
|
1124
|
+
if (w === m.w && h === m.h) {
|
|
1125
|
+
return false;
|
|
1126
|
+
}
|
|
1127
|
+
m.w = w;
|
|
1128
|
+
m.h = h;
|
|
1129
|
+
return true;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* @internal Development only, on `loaded`: a layout Solid did not ask for
|
|
1133
|
+
* (the walk's) changed the size of a text Solid measures, so its parent's
|
|
1134
|
+
* flex has the old one. A prop the layout reads was written on the
|
|
1135
|
+
* renderer node (`el.lng`) rather than on the element, or animated there.
|
|
1136
|
+
*/
|
|
1137
|
+
_warnUnmeasuredLayout() {
|
|
1138
|
+
const m = this._text;
|
|
1139
|
+
if (m === undefined ||
|
|
1140
|
+
m.due === true ||
|
|
1141
|
+
m.waiting === true ||
|
|
1142
|
+
m.listening === true ||
|
|
1143
|
+
m.w !== m.w ||
|
|
1144
|
+
this._parent === undefined ||
|
|
1145
|
+
this._parent._requiresLayout !== true) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const lng = this.lng;
|
|
1149
|
+
if ((lng.maxWidth || lng.w) !== m.w || (lng.maxHeight || lng.h) !== m.h) {
|
|
1150
|
+
console.warn('[solid] A text in a flex container was laid out at a size Solid did not measure: a prop its layout reads was written, or animated, on its renderer node (el.lng) instead of on the element. Its container keeps the old size.', this);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* @internal `measure()` found no font description: hear `loaded` once,
|
|
1155
|
+
* when the walk lays the text out (the renderer wakes the nodes it
|
|
1156
|
+
* visited), and wait for loadFonts() to say a font loaded (for one no walk
|
|
1157
|
+
* visits). Either way measureFontWaiting measures it again.
|
|
1158
|
+
*/
|
|
1159
|
+
_waitForFont(m) {
|
|
1160
|
+
m.waiting = true;
|
|
1161
|
+
this.lng.on('loaded', fontWaitHeard);
|
|
1162
|
+
if (measuringFontWaiting === false &&
|
|
1163
|
+
fontWaiting.length >= fontWaitingSweepAt) {
|
|
1164
|
+
sweepFontWaiting();
|
|
1165
|
+
}
|
|
1166
|
+
fontWaiting.push(this);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* @internal Solid animated a prop this text's layout reads
|
|
1170
|
+
* (`_sendToLightningAnimatable`, `animate()`): from now on, for the text's
|
|
1171
|
+
* lifetime, each layout the walk makes of an animated value lays its
|
|
1172
|
+
* container out again in that frame, as 1.6's `loaded` listener did.
|
|
1173
|
+
* Lifetime, not the animation's: Solid does not see a controller started
|
|
1174
|
+
* later, or again (`animate()` returns it to the app).
|
|
1175
|
+
*/
|
|
1176
|
+
_textLayoutAnimated() {
|
|
1177
|
+
if (this.rendered !== true) {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
const parent = this._parent;
|
|
1181
|
+
if (parent === undefined || parent._requiresLayout !== true) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
this._listenTextLoaded();
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* @internal Hear every layout of this text: one whose size, as flex reads
|
|
1188
|
+
* it, Solid did not measure lays the container out in that frame. One
|
|
1189
|
+
* closure per text, made once and kept for its lifetime, on its renderer
|
|
1190
|
+
* node only (nothing else holds it, so it goes with the node). A layout
|
|
1191
|
+
* Solid measured changes nothing, and asks for no second walk.
|
|
1192
|
+
*/
|
|
1193
|
+
_listenTextLoaded() {
|
|
1194
|
+
let m = this._text;
|
|
1195
|
+
if (m === undefined) {
|
|
1196
|
+
m = new TextMeasure();
|
|
1197
|
+
this._text = m;
|
|
1198
|
+
}
|
|
1199
|
+
if (m.listening === true) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
m.listening = true;
|
|
1203
|
+
this._hearTextLayouts();
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* @internal The listener `_listenTextLoaded` adds, once per text. A method
|
|
1207
|
+
* of its own: an arrow's `this` is allocated in a context on every call of
|
|
1208
|
+
* the method that holds it, and that one runs on every animated write.
|
|
1209
|
+
*/
|
|
1210
|
+
_hearTextLayouts() {
|
|
1211
|
+
this.lng.on('loaded', () => {
|
|
1212
|
+
if (this._textSizeChanged() === true) {
|
|
1213
|
+
enqueueLayout(this._parent);
|
|
1214
|
+
schedulePostMutationInFrame();
|
|
1215
|
+
}
|
|
671
1216
|
});
|
|
672
1217
|
}
|
|
1218
|
+
/**
|
|
1219
|
+
* @internal After a layout Solid did not make (the walk's, of an animated
|
|
1220
|
+
* value; the DOM renderer's late re-measure): whether this text's size, as
|
|
1221
|
+
* flex reads it, changed since Solid last saw it. If so, it is recorded
|
|
1222
|
+
* and the caller lays the parent out. False while a measure is due.
|
|
1223
|
+
*/
|
|
1224
|
+
_textSizeChanged() {
|
|
1225
|
+
const m = this._text;
|
|
1226
|
+
if (m === undefined || m.due === true || m.waiting === true) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
const parent = this._parent;
|
|
1230
|
+
if (parent === undefined || parent._requiresLayout !== true) {
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
const lng = this.lng;
|
|
1234
|
+
const w = lng.maxWidth || lng.w;
|
|
1235
|
+
const h = lng.maxHeight || lng.h;
|
|
1236
|
+
if (w === m.w && h === m.h) {
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
m.w = w;
|
|
1240
|
+
m.h = h;
|
|
1241
|
+
return true;
|
|
1242
|
+
}
|
|
673
1243
|
getText() {
|
|
674
1244
|
const len = this.children.length;
|
|
675
1245
|
if (len === 1)
|
|
@@ -688,7 +1258,9 @@ export class ElementNode {
|
|
|
688
1258
|
// If onDestroy returns a promise, wait for it to resolve before destroying
|
|
689
1259
|
// Useful with animations waitUntilStopped method which returns promise
|
|
690
1260
|
if (destroyPromise instanceof Promise) {
|
|
691
|
-
|
|
1261
|
+
// Bound here, not an arrow: an arrow's `this` is allocated in a
|
|
1262
|
+
// context on every destroy(), a promise or not.
|
|
1263
|
+
void destroyPromise.then(this._destroy.bind(this));
|
|
692
1264
|
}
|
|
693
1265
|
else {
|
|
694
1266
|
this._destroy();
|
|
@@ -743,7 +1315,10 @@ export class ElementNode {
|
|
|
743
1315
|
return this.children.length > 0;
|
|
744
1316
|
}
|
|
745
1317
|
set src(src) {
|
|
746
|
-
if (typeof src === 'string'
|
|
1318
|
+
if (typeof src === 'string' ||
|
|
1319
|
+
(typeof Blob !== 'undefined' && src instanceof Blob)) {
|
|
1320
|
+
// The renderer types `Node.src` as a string, but loads a Blob src as
|
|
1321
|
+
// ImageTexture does; the DOM renderer shows it through an object URL.
|
|
747
1322
|
this.lng.src = src;
|
|
748
1323
|
if (!this.color && this.rendered) {
|
|
749
1324
|
this.color = 0xffffffff;
|
|
@@ -753,10 +1328,8 @@ export class ElementNode {
|
|
|
753
1328
|
this.color = 0x00000000;
|
|
754
1329
|
}
|
|
755
1330
|
}
|
|
1331
|
+
/** An image URL, or a Blob holding the image (e.g. a fetch() response's). */
|
|
756
1332
|
get src() {
|
|
757
|
-
// Renderer 1.8 widened `src` to `string | Blob | ImageData`. The solid
|
|
758
|
-
// `src` prop only ever assigns strings (see the setter above), so the
|
|
759
|
-
// non-string arms are unreachable through this path.
|
|
760
1333
|
return this.lng.src;
|
|
761
1334
|
}
|
|
762
1335
|
getChildById(id) {
|
|
@@ -778,9 +1351,52 @@ export class ElementNode {
|
|
|
778
1351
|
}
|
|
779
1352
|
}
|
|
780
1353
|
set states(states) {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1354
|
+
const current = this._states;
|
|
1355
|
+
if (current === undefined) {
|
|
1356
|
+
const created = new States(this._stateChanged.bind(this), states);
|
|
1357
|
+
this._states = created;
|
|
1358
|
+
if (this.rendered && created.length > 0) {
|
|
1359
|
+
this._stateChanged();
|
|
1360
|
+
}
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
// An unchanged list is a no-op (design 3.3.3): nothing to re-apply.
|
|
1364
|
+
// "Unchanged" by the rules of States.merge: an array or a string
|
|
1365
|
+
// replaces the list, an object adds its truthy keys (`has`) and removes
|
|
1366
|
+
// its falsy ones. (Inline on purpose here and in the gradient accessor:
|
|
1367
|
+
// terser's default `reduce_funcs` turns a single-use helper into a
|
|
1368
|
+
// closure per call.)
|
|
1369
|
+
const len = current.length;
|
|
1370
|
+
let changed = false;
|
|
1371
|
+
if (isArray(states)) {
|
|
1372
|
+
changed = states.length !== len;
|
|
1373
|
+
for (let i = 0; !changed && i < len; i++) {
|
|
1374
|
+
changed = states[i] !== current[i];
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
else if (isString(states)) {
|
|
1378
|
+
changed = len !== 1 || current[0] !== states;
|
|
1379
|
+
}
|
|
1380
|
+
else {
|
|
1381
|
+
for (const key in states) {
|
|
1382
|
+
const state = key;
|
|
1383
|
+
if (states[state]) {
|
|
1384
|
+
changed = !current.has(state);
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
for (let i = 0; !changed && i < len; i++) {
|
|
1388
|
+
changed = current[i] === state;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
if (changed) {
|
|
1392
|
+
break;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
if (!changed) {
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
current.merge(states);
|
|
784
1400
|
if (this.rendered) {
|
|
785
1401
|
this._stateChanged();
|
|
786
1402
|
}
|
|
@@ -862,39 +1478,82 @@ export class ElementNode {
|
|
|
862
1478
|
return null;
|
|
863
1479
|
}
|
|
864
1480
|
updateLayout() {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
1481
|
+
this._layoutQueued = false;
|
|
1482
|
+
const children = this.children;
|
|
1483
|
+
const numChildren = children.length;
|
|
1484
|
+
if (numChildren === 0)
|
|
1485
|
+
return;
|
|
1486
|
+
if (isDev)
|
|
1487
|
+
log('Layout: ', this);
|
|
1488
|
+
const isFlex = this._display === 'flex';
|
|
1489
|
+
if (isFlex && this.flexGrow && this.width === 0) {
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
// Texts written since Solid last measured them (a direct updateLayout()
|
|
1493
|
+
// before the post-mutation pass), or never measured (this container lays
|
|
1494
|
+
// out only now): sized before the pass reads them.
|
|
1495
|
+
for (let i = 0; i < numChildren; i++) {
|
|
1496
|
+
const c = children[i];
|
|
1497
|
+
if (c._type === NodeType.TextNode && c.rendered === true) {
|
|
1498
|
+
const m = c._text;
|
|
1499
|
+
if (m === undefined || m.due === true || m.w !== m.w) {
|
|
1500
|
+
c._measureText();
|
|
1501
|
+
}
|
|
870
1502
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
1503
|
+
}
|
|
1504
|
+
let flexChanged = isFlex && calculateFlex(this);
|
|
1505
|
+
if (isFlex && this._containsFlexGrow === true) {
|
|
1506
|
+
// This pass changed its children's sizes: lay out the flex ones again,
|
|
1507
|
+
// directly, so they do not queue this container back through their
|
|
1508
|
+
// own size. If one of them resized, lay this container out once more.
|
|
1509
|
+
let childResized = false;
|
|
1510
|
+
for (let i = 0; i < numChildren; i++) {
|
|
1511
|
+
const c = children[i];
|
|
1512
|
+
if (isElementNode(c) && c._display === 'flex') {
|
|
1513
|
+
if (calculateFlex(c))
|
|
1514
|
+
childResized = true;
|
|
1515
|
+
const childOnLayout = c._onLayout;
|
|
1516
|
+
if (childOnLayout !== undefined && isFunction(childOnLayout)) {
|
|
1517
|
+
childOnLayout.call(c, c);
|
|
885
1518
|
}
|
|
886
|
-
}
|
|
1519
|
+
}
|
|
887
1520
|
}
|
|
1521
|
+
if (childResized && calculateFlex(this)) {
|
|
1522
|
+
flexChanged = true;
|
|
1523
|
+
}
|
|
1524
|
+
this._containsFlexGrow = null;
|
|
1525
|
+
}
|
|
1526
|
+
// One onLayout, after the final layout (the children's included).
|
|
1527
|
+
const onLayout = this._onLayout;
|
|
1528
|
+
const onLayoutChanged = onLayout !== undefined &&
|
|
1529
|
+
isFunction(onLayout) &&
|
|
1530
|
+
onLayout.call(this, this);
|
|
1531
|
+
// A container whose size changed queues its parent (one with nothing to
|
|
1532
|
+
// lay out would do nothing).
|
|
1533
|
+
// A removed container keeps its parent link but not its place.
|
|
1534
|
+
const parent = this._detached ? undefined : this.parent;
|
|
1535
|
+
if ((flexChanged || onLayoutChanged) && parent && parent._requiresLayout) {
|
|
1536
|
+
queueLayout(parent);
|
|
888
1537
|
}
|
|
889
1538
|
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Apply the `$state` blocks of the active states (design 3.3). The keys
|
|
1541
|
+
* any state wrote since the states were last empty are tracked in
|
|
1542
|
+
* `_undoStyles`, in first-write order; each takes its value from the
|
|
1543
|
+
* active block of highest precedence, else the base value (`theme`, then
|
|
1544
|
+
* `style`, then undefined: pinned). After render a key is written only
|
|
1545
|
+
* when that value differs from the one written last (`_applied`); before
|
|
1546
|
+
* render every key is written, into the props bag, as before 1.7.
|
|
1547
|
+
*/
|
|
890
1548
|
_stateChanged() {
|
|
891
1549
|
if (isDev)
|
|
892
1550
|
log('State Changed: ', this, this.states);
|
|
1551
|
+
const states = this.states;
|
|
893
1552
|
if (isDev) {
|
|
894
1553
|
const div = this.lng?.div;
|
|
895
1554
|
if (div) {
|
|
896
|
-
if (
|
|
897
|
-
div.dataset.states =
|
|
1555
|
+
if (states.length > 0) {
|
|
1556
|
+
div.dataset.states = states.join(' ');
|
|
898
1557
|
}
|
|
899
1558
|
else {
|
|
900
1559
|
delete div.dataset.states;
|
|
@@ -902,98 +1561,179 @@ export class ElementNode {
|
|
|
902
1561
|
}
|
|
903
1562
|
}
|
|
904
1563
|
if (this.forwardStates) {
|
|
905
|
-
//
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1564
|
+
// Children first. They take this list: their setter copies it
|
|
1565
|
+
// (forwardStates overwrites their own states, pinned) and does nothing
|
|
1566
|
+
// when it is unchanged.
|
|
1567
|
+
const children = this.children;
|
|
1568
|
+
for (let i = 0; i < children.length; i++) {
|
|
1569
|
+
children[i].states = states;
|
|
1570
|
+
}
|
|
910
1571
|
}
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
if (this._undoStyles && this._undoStyles.length) {
|
|
920
|
-
stylesToUndo = {};
|
|
921
|
-
this._undoStyles.forEach((styleKey) => {
|
|
922
|
-
let fallbackValue = this.theme[styleKey];
|
|
923
|
-
if (fallbackValue === undefined) {
|
|
924
|
-
fallbackValue = this.style[styleKey];
|
|
925
|
-
}
|
|
926
|
-
if (isDev) {
|
|
927
|
-
if (fallbackValue === undefined) {
|
|
928
|
-
console.warn('fallback style key not found: ', styleKey);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
stylesToUndo[styleKey] = fallbackValue;
|
|
932
|
-
});
|
|
1572
|
+
const n = states.length;
|
|
1573
|
+
const count = this._undoCount;
|
|
1574
|
+
if (count === 0) {
|
|
1575
|
+
// Nothing to undo: done unless an active state has a block. This runs
|
|
1576
|
+
// on every path element of every focus change.
|
|
1577
|
+
let i = 0;
|
|
1578
|
+
while (i < n && !isObject(this[states[i]])) {
|
|
1579
|
+
i++;
|
|
933
1580
|
}
|
|
934
|
-
|
|
935
|
-
if (numStates === 0) {
|
|
936
|
-
Object.assign(this, stylesToUndo);
|
|
937
|
-
this._undoStyles = [];
|
|
1581
|
+
if (i === n) {
|
|
938
1582
|
return;
|
|
939
1583
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1584
|
+
}
|
|
1585
|
+
if (this._undoStyles === undefined) {
|
|
1586
|
+
this._undoStyles = [];
|
|
1587
|
+
}
|
|
1588
|
+
if (this._applied === undefined) {
|
|
1589
|
+
this._applied = Object.create(null);
|
|
1590
|
+
}
|
|
1591
|
+
this._writeStates(n);
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* The state-style loops of `_stateChanged`, for `n` active states: a
|
|
1595
|
+
* method of its own, so that `_stateChanged`, which runs for every path
|
|
1596
|
+
* element of every focus change, stays the short early-return above. Each
|
|
1597
|
+
* key is written through its setter, as before 1.7: a border or shadow
|
|
1598
|
+
* object merges into the shader props, the later write of a sub-prop
|
|
1599
|
+
* winning.
|
|
1600
|
+
*/
|
|
1601
|
+
_writeStates(n) {
|
|
1602
|
+
const states = this._states;
|
|
1603
|
+
const keys = this._undoStyles;
|
|
1604
|
+
const applied = this._applied;
|
|
1605
|
+
const diff = this.rendered;
|
|
1606
|
+
let count = this._undoCount;
|
|
1607
|
+
// The border family's keys write one set of shader props. When a change
|
|
1608
|
+
// writes some of the tracked family keys and skips the others as
|
|
1609
|
+
// unchanged, a written one may have overwritten what a skipped one holds
|
|
1610
|
+
// (a `border` sets all four widths): then the family is written again,
|
|
1611
|
+
// every tracked key in tracked order, the order 1.6 wrote the merged
|
|
1612
|
+
// object in, so the later key wins as it did. (The shadow is one key.)
|
|
1613
|
+
let borderKeys = 0;
|
|
1614
|
+
let borderWrites = 0;
|
|
1615
|
+
if (n === 0) {
|
|
1616
|
+
// Undo every tracked key, in its order (`transition` too: pinned), to
|
|
1617
|
+
// its base value. A setter that throws leaves the keys after it for
|
|
1618
|
+
// the next change, as before 1.7.
|
|
1619
|
+
for (let i = 0; i < count; i++) {
|
|
1620
|
+
const key = keys[i];
|
|
1621
|
+
const value = styleFallback(this, key);
|
|
1622
|
+
const border = BORDER_FAMILY[key] === true;
|
|
1623
|
+
if (border) {
|
|
1624
|
+
borderKeys++;
|
|
962
1625
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
this._undoStyles = Object.keys(newStyles);
|
|
970
|
-
// Apply transition first
|
|
971
|
-
if (newStyles.transition !== undefined) {
|
|
972
|
-
this.transition = newStyles.transition;
|
|
1626
|
+
if (!diff || value !== applied[key]) {
|
|
1627
|
+
applied[key] = value;
|
|
1628
|
+
this[key] = value;
|
|
1629
|
+
if (border) {
|
|
1630
|
+
borderWrites++;
|
|
1631
|
+
}
|
|
973
1632
|
}
|
|
974
|
-
// Apply the styles
|
|
975
|
-
Object.assign(this, newStyles);
|
|
976
1633
|
}
|
|
977
|
-
|
|
978
|
-
this.
|
|
1634
|
+
if (borderWrites !== 0 && borderWrites !== borderKeys) {
|
|
1635
|
+
this._rewriteBorderKeys(count);
|
|
979
1636
|
}
|
|
980
|
-
|
|
981
|
-
}
|
|
982
|
-
render(topNode) {
|
|
983
|
-
// Elements are inserted from the inside out, then rendered from the outside in.
|
|
984
|
-
// Render starts when an element is inserted with a parent that is already renderered.
|
|
985
|
-
const node = this;
|
|
986
|
-
const parent = this.parent;
|
|
987
|
-
if (!parent) {
|
|
988
|
-
console.warn('Parent not set - no node created for: ', this);
|
|
1637
|
+
this._undoCount = 0;
|
|
989
1638
|
return;
|
|
990
1639
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1640
|
+
// Track the active blocks' keys, block by block in precedence order
|
|
1641
|
+
// (lowest first), after the tracked ones: the key order of the merged
|
|
1642
|
+
// object before 1.7, which decides the write order.
|
|
1643
|
+
const stateOrder = this.stateOrder || Config.stateOrder;
|
|
1644
|
+
const order = n > 1 && stateOrder !== undefined && stateOrder.length > 0
|
|
1645
|
+
? stateOrder
|
|
1646
|
+
: undefined;
|
|
1647
|
+
if (order === undefined) {
|
|
1648
|
+
for (let i = 0; i < n; i++) {
|
|
1649
|
+
count = trackKeys(this[states[i]], keys, count, applied);
|
|
1650
|
+
}
|
|
994
1651
|
}
|
|
995
|
-
|
|
996
|
-
|
|
1652
|
+
else {
|
|
1653
|
+
// States not in `order` first, in the order added, then by `order`.
|
|
1654
|
+
let lastRank = -2;
|
|
1655
|
+
let lastPos = -1;
|
|
1656
|
+
for (let done = 0; done < n; done++) {
|
|
1657
|
+
let pick = 0;
|
|
1658
|
+
let pickRank = 0;
|
|
1659
|
+
let found = false;
|
|
1660
|
+
for (let i = 0; i < n; i++) {
|
|
1661
|
+
const rank = order.indexOf(states[i]);
|
|
1662
|
+
if ((rank > lastRank || (rank === lastRank && i > lastPos)) &&
|
|
1663
|
+
(!found || rank < pickRank)) {
|
|
1664
|
+
pick = i;
|
|
1665
|
+
pickRank = rank;
|
|
1666
|
+
found = true;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
count = trackKeys(this[states[pick]], keys, count, applied);
|
|
1670
|
+
lastRank = pickRank;
|
|
1671
|
+
lastPos = pick;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
this._undoCount = count;
|
|
1675
|
+
// `transition` first, so the other keys animate with it (pinned); one
|
|
1676
|
+
// that resolves to undefined is written in its place.
|
|
1677
|
+
for (let i = 0; i < count; i++) {
|
|
1678
|
+
if (keys[i] === 'transition') {
|
|
1679
|
+
const value = resolveStateValue(this, 'transition', states, order);
|
|
1680
|
+
if (value !== undefined && (!diff || value !== applied.transition)) {
|
|
1681
|
+
applied.transition = value;
|
|
1682
|
+
this.transition = value;
|
|
1683
|
+
}
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
for (let i = 0; i < count; i++) {
|
|
1688
|
+
const key = keys[i];
|
|
1689
|
+
const value = resolveStateValue(this, key, states, order);
|
|
1690
|
+
const border = BORDER_FAMILY[key] === true;
|
|
1691
|
+
if (border) {
|
|
1692
|
+
borderKeys++;
|
|
1693
|
+
}
|
|
1694
|
+
if (!diff || value !== applied[key]) {
|
|
1695
|
+
applied[key] = value;
|
|
1696
|
+
this[key] = value;
|
|
1697
|
+
if (border) {
|
|
1698
|
+
borderWrites++;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
if (borderWrites !== 0 && borderWrites !== borderKeys) {
|
|
1703
|
+
// The tracked count as it is now: a setter above may have changed the
|
|
1704
|
+
// states and tracked more keys.
|
|
1705
|
+
this._rewriteBorderKeys(this._undoCount);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Write every tracked border-family key again, in tracked order, with the
|
|
1710
|
+
* value the state change resolved for it (`_applied`): see `_writeStates`.
|
|
1711
|
+
*/
|
|
1712
|
+
_rewriteBorderKeys(count) {
|
|
1713
|
+
const keys = this._undoStyles;
|
|
1714
|
+
const applied = this._applied;
|
|
1715
|
+
for (let i = 0; i < count; i++) {
|
|
1716
|
+
const key = keys[i];
|
|
1717
|
+
if (BORDER_FAMILY[key] === true) {
|
|
1718
|
+
this[key] = applied[key];
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
render(topNode) {
|
|
1723
|
+
// Elements are inserted from the inside out, then rendered from the outside in.
|
|
1724
|
+
// Render starts when an element is inserted with a parent that is already renderered.
|
|
1725
|
+
const node = this;
|
|
1726
|
+
const parent = this.parent;
|
|
1727
|
+
if (!parent) {
|
|
1728
|
+
console.warn('Parent not set - no node created for: ', this);
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
if (!parent.rendered) {
|
|
1732
|
+
console.warn('Parent not rendered yet: ', this);
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (parent.requiresLayout()) {
|
|
1736
|
+
queueLayout(parent);
|
|
997
1737
|
}
|
|
998
1738
|
if (this.rendered) {
|
|
999
1739
|
// This happens if Array of items is reordered to reuse elements.
|
|
@@ -1066,17 +1806,27 @@ export class ElementNode {
|
|
|
1066
1806
|
if (!textProps.h && !textProps.maxHeight) {
|
|
1067
1807
|
textProps.maxLines = textProps.maxLines ?? 99;
|
|
1068
1808
|
}
|
|
1809
|
+
// B11: margins live on the ElementNode, not in the renderer props;
|
|
1810
|
+
// resolved as flex resolves them (a side, else the margin array).
|
|
1069
1811
|
if (!textProps.maxWidth) {
|
|
1070
1812
|
textProps.maxWidth =
|
|
1071
|
-
parentWidth -
|
|
1813
|
+
parentWidth -
|
|
1814
|
+
textProps.x -
|
|
1815
|
+
(node.marginRight || getArrayValue(node.margin, 1));
|
|
1072
1816
|
}
|
|
1073
1817
|
if (textProps.contain === 'both' && !textProps.maxHeight) {
|
|
1074
1818
|
textProps.maxHeight =
|
|
1075
|
-
parentHeight -
|
|
1819
|
+
parentHeight -
|
|
1820
|
+
textProps.y -
|
|
1821
|
+
(node.marginBottom || getArrayValue(node.margin, 2));
|
|
1076
1822
|
}
|
|
1077
|
-
else if (textProps.maxLines === 1) {
|
|
1823
|
+
else if (textProps.maxLines === 1 && !textProps.maxHeight) {
|
|
1824
|
+
// B12: a lineHeight at or below 3 multiplies the font size.
|
|
1825
|
+
const lineHeight = textProps.lineHeight;
|
|
1078
1826
|
textProps.maxHeight =
|
|
1079
|
-
|
|
1827
|
+
lineHeight && lineHeight <= 3 && textProps.fontSize
|
|
1828
|
+
? lineHeight * textProps.fontSize
|
|
1829
|
+
: lineHeight || textProps.fontSize;
|
|
1080
1830
|
}
|
|
1081
1831
|
// textProps.w = textProps.h = 0;
|
|
1082
1832
|
}
|
|
@@ -1090,11 +1840,9 @@ export class ElementNode {
|
|
|
1090
1840
|
if (isDev)
|
|
1091
1841
|
log('Rendering: ', this, props);
|
|
1092
1842
|
node.lng = renderer.createTextNode(props);
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1843
|
+
// A text in a layout parent is queued to be measured below, once its
|
|
1844
|
+
// listeners are on (an `onEvent.loaded` hears the layout measure()
|
|
1845
|
+
// makes).
|
|
1098
1846
|
}
|
|
1099
1847
|
else {
|
|
1100
1848
|
// If its not an image or texture apply some defaults
|
|
@@ -1148,14 +1896,6 @@ export class ElementNode {
|
|
|
1148
1896
|
if (isDev)
|
|
1149
1897
|
log('Rendering: ', this, props);
|
|
1150
1898
|
node.lng = renderer.createNode(props);
|
|
1151
|
-
if (node._hasRenderedChildren) {
|
|
1152
|
-
node._hasRenderedChildren = false;
|
|
1153
|
-
for (const child of node.children) {
|
|
1154
|
-
if (isElementNode(child) && isINode(child.lng)) {
|
|
1155
|
-
child.lng.parent = node.lng;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
1899
|
}
|
|
1160
1900
|
node.rendered = true;
|
|
1161
1901
|
if (isDev) {
|
|
@@ -1167,18 +1907,38 @@ export class ElementNode {
|
|
|
1167
1907
|
}
|
|
1168
1908
|
this.onCreate?.(this);
|
|
1169
1909
|
this.onRender?.(this);
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
//
|
|
1910
|
+
const onEvent = node.onEvent;
|
|
1911
|
+
if (onEvent) {
|
|
1912
|
+
// for-in with an own-property test, as Object.entries (Chrome 54)
|
|
1913
|
+
// reads it: the floor is Chrome 47.
|
|
1173
1914
|
for (const name in onEvent) {
|
|
1174
|
-
if (
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
node
|
|
1915
|
+
if (Object.prototype.hasOwnProperty.call(onEvent, name) &&
|
|
1916
|
+
typeof node.lng.on === 'function') {
|
|
1917
|
+
const handler = onEvent[name];
|
|
1918
|
+
// The listener captures these block-scoped names, not render()'s
|
|
1919
|
+
// `node`: a captured local is allocated in a context on every
|
|
1920
|
+
// call, onEvent or not.
|
|
1921
|
+
const target = node;
|
|
1922
|
+
node.lng.on(name, (_inode, data) => handler.call(target, target, data));
|
|
1179
1923
|
}
|
|
1180
1924
|
}
|
|
1181
1925
|
}
|
|
1926
|
+
if (node._type === NodeType.TextNode && parent._requiresLayout === true) {
|
|
1927
|
+
// Its parent's flex reads its size: it is measured in the post-mutation
|
|
1928
|
+
// pass, before the parent's layout (queued above) and before the frame,
|
|
1929
|
+
// instead of waiting for the walk's `loaded`. Not here: a write later
|
|
1930
|
+
// in this tick would lay it out twice (and `loaded` twice).
|
|
1931
|
+
if (isDomRendererActive()) {
|
|
1932
|
+
// The DOM renderer measures again when a web font loads after the
|
|
1933
|
+
// text was measured (its size then was the fallback font's): lay the
|
|
1934
|
+
// container out at that size, as before 1.7.
|
|
1935
|
+
node._listenTextLoaded();
|
|
1936
|
+
}
|
|
1937
|
+
else if (isDev) {
|
|
1938
|
+
node.lng.on('loaded', () => node._warnUnmeasuredLayout());
|
|
1939
|
+
}
|
|
1940
|
+
node._textLayoutDirty();
|
|
1941
|
+
}
|
|
1182
1942
|
// L3 Inspector adds div to the lng object
|
|
1183
1943
|
const div = node.lng?.div;
|
|
1184
1944
|
if (isDev && div) {
|
|
@@ -1189,6 +1949,10 @@ export class ElementNode {
|
|
|
1189
1949
|
}
|
|
1190
1950
|
if (node._type === NodeType.Element) {
|
|
1191
1951
|
// only element nodes will have children that need rendering
|
|
1952
|
+
// Children rendered before this node (moved in) are reparented here,
|
|
1953
|
+
// in children order with the new ones (B19: v2 draws in that order).
|
|
1954
|
+
const reparent = node._hasRenderedChildren === true;
|
|
1955
|
+
node._hasRenderedChildren = false;
|
|
1192
1956
|
const numChildren = node.children.length;
|
|
1193
1957
|
for (let i = 0; i < numChildren; i++) {
|
|
1194
1958
|
const c = node.children[i];
|
|
@@ -1196,6 +1960,9 @@ export class ElementNode {
|
|
|
1196
1960
|
assertTruthy(c, 'Child is undefined');
|
|
1197
1961
|
// Text elements sneak in from Solid creating tracked nodes
|
|
1198
1962
|
if (isElementNode(c)) {
|
|
1963
|
+
if (reparent && isINode(c.lng)) {
|
|
1964
|
+
c.lng.parent = node.lng;
|
|
1965
|
+
}
|
|
1199
1966
|
c.render();
|
|
1200
1967
|
}
|
|
1201
1968
|
}
|
|
@@ -1209,30 +1976,709 @@ export class ElementNode {
|
|
|
1209
1976
|
node.setFocus();
|
|
1210
1977
|
}
|
|
1211
1978
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1979
|
+
/**
|
|
1980
|
+
* The index of `item` in `list`, scanning from the end: Solid appends and
|
|
1981
|
+
* removes at the tail most often. The first item is checked first, for
|
|
1982
|
+
* Solid's cleanChildren, which removes the first child until none is left.
|
|
1983
|
+
*/
|
|
1984
|
+
function lastIndexOf(list, item) {
|
|
1985
|
+
if (list[0] === item) {
|
|
1986
|
+
return 0;
|
|
1987
|
+
}
|
|
1988
|
+
let i = list.length - 1;
|
|
1989
|
+
while (i > 0 && list[i] !== item) {
|
|
1990
|
+
i--;
|
|
1991
|
+
}
|
|
1992
|
+
return i === 0 ? -1 : i;
|
|
1993
|
+
}
|
|
1994
|
+
/** The first rendered element in `children` from `from` on: the renderer sibling to draw before. */
|
|
1995
|
+
function nextDrawn(children, from) {
|
|
1996
|
+
for (let i = from; i < children.length; i++) {
|
|
1997
|
+
const c = children[i];
|
|
1998
|
+
if (c instanceof ElementNode && c.rendered) {
|
|
1999
|
+
return c;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
return null;
|
|
2003
|
+
}
|
|
2004
|
+
const NO_TEXT_PROPS = Object.freeze({});
|
|
2005
|
+
/**
|
|
2006
|
+
* Where a text-only prop is written: a `<text>`'s renderer node (its props
|
|
2007
|
+
* bag before render); on any other element, the ElementNode's `_textProps`.
|
|
2008
|
+
* A renderer v2 handle takes no field it does not know (it would become a
|
|
2009
|
+
* field of its own) and a view draws no text (B20).
|
|
2010
|
+
*/
|
|
2011
|
+
function textPropsFor(node) {
|
|
2012
|
+
if (node._type === NodeType.TextNode) {
|
|
2013
|
+
return node.lng;
|
|
2014
|
+
}
|
|
2015
|
+
let own = node._textProps;
|
|
2016
|
+
if (own === undefined) {
|
|
2017
|
+
own = {};
|
|
2018
|
+
node._textProps = own;
|
|
2019
|
+
}
|
|
2020
|
+
return own;
|
|
2021
|
+
}
|
|
2022
|
+
/** Where a text-only prop is read (textPropsFor), without allocating. */
|
|
2023
|
+
function textPropsOf(node) {
|
|
2024
|
+
if (node._type === NodeType.TextNode) {
|
|
2025
|
+
return node.lng;
|
|
2026
|
+
}
|
|
2027
|
+
const own = node._textProps;
|
|
2028
|
+
return own === undefined ? NO_TEXT_PROPS : own;
|
|
2029
|
+
}
|
|
2030
|
+
/** The setter of a read-only forwarded prop: the write is ignored. */
|
|
2031
|
+
function ignoreWrite(_v) { }
|
|
2032
|
+
Object.defineProperties(ElementNode.prototype, {
|
|
2033
|
+
// Animatable
|
|
2034
|
+
alpha: {
|
|
1214
2035
|
get() {
|
|
1215
|
-
return this.lng
|
|
2036
|
+
return this.lng.alpha;
|
|
1216
2037
|
},
|
|
1217
2038
|
set(v) {
|
|
1218
|
-
this.
|
|
2039
|
+
if (this.transition === undefined ||
|
|
2040
|
+
!this._sendToLightningAnimatable('alpha', v)) {
|
|
2041
|
+
this.lng.alpha = v;
|
|
2042
|
+
}
|
|
1219
2043
|
},
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
for (const key of LightningRendererNonAnimatingProps) {
|
|
1223
|
-
Object.defineProperty(ElementNode.prototype, key, {
|
|
2044
|
+
},
|
|
2045
|
+
color: {
|
|
1224
2046
|
get() {
|
|
1225
|
-
return this.lng
|
|
2047
|
+
return this.lng.color;
|
|
1226
2048
|
},
|
|
1227
2049
|
set(v) {
|
|
1228
|
-
this.
|
|
2050
|
+
if (this.transition === undefined ||
|
|
2051
|
+
!this._sendToLightningAnimatable('color', v)) {
|
|
2052
|
+
this.lng.color = v;
|
|
2053
|
+
}
|
|
1229
2054
|
},
|
|
1230
|
-
}
|
|
1231
|
-
|
|
2055
|
+
},
|
|
2056
|
+
colorTop: {
|
|
2057
|
+
get() {
|
|
2058
|
+
return this.lng.colorTop;
|
|
2059
|
+
},
|
|
2060
|
+
set(v) {
|
|
2061
|
+
if (this.transition === undefined ||
|
|
2062
|
+
!this._sendToLightningAnimatable('colorTop', v)) {
|
|
2063
|
+
this.lng.colorTop = v;
|
|
2064
|
+
}
|
|
2065
|
+
},
|
|
2066
|
+
},
|
|
2067
|
+
colorRight: {
|
|
2068
|
+
get() {
|
|
2069
|
+
return this.lng.colorRight;
|
|
2070
|
+
},
|
|
2071
|
+
set(v) {
|
|
2072
|
+
if (this.transition === undefined ||
|
|
2073
|
+
!this._sendToLightningAnimatable('colorRight', v)) {
|
|
2074
|
+
this.lng.colorRight = v;
|
|
2075
|
+
}
|
|
2076
|
+
},
|
|
2077
|
+
},
|
|
2078
|
+
colorLeft: {
|
|
2079
|
+
get() {
|
|
2080
|
+
return this.lng.colorLeft;
|
|
2081
|
+
},
|
|
2082
|
+
set(v) {
|
|
2083
|
+
if (this.transition === undefined ||
|
|
2084
|
+
!this._sendToLightningAnimatable('colorLeft', v)) {
|
|
2085
|
+
this.lng.colorLeft = v;
|
|
2086
|
+
}
|
|
2087
|
+
},
|
|
2088
|
+
},
|
|
2089
|
+
colorBottom: {
|
|
2090
|
+
get() {
|
|
2091
|
+
return this.lng.colorBottom;
|
|
2092
|
+
},
|
|
2093
|
+
set(v) {
|
|
2094
|
+
if (this.transition === undefined ||
|
|
2095
|
+
!this._sendToLightningAnimatable('colorBottom', v)) {
|
|
2096
|
+
this.lng.colorBottom = v;
|
|
2097
|
+
}
|
|
2098
|
+
},
|
|
2099
|
+
},
|
|
2100
|
+
colorTl: {
|
|
2101
|
+
get() {
|
|
2102
|
+
return this.lng.colorTl;
|
|
2103
|
+
},
|
|
2104
|
+
set(v) {
|
|
2105
|
+
if (this.transition === undefined ||
|
|
2106
|
+
!this._sendToLightningAnimatable('colorTl', v)) {
|
|
2107
|
+
this.lng.colorTl = v;
|
|
2108
|
+
}
|
|
2109
|
+
},
|
|
2110
|
+
},
|
|
2111
|
+
colorTr: {
|
|
2112
|
+
get() {
|
|
2113
|
+
return this.lng.colorTr;
|
|
2114
|
+
},
|
|
2115
|
+
set(v) {
|
|
2116
|
+
if (this.transition === undefined ||
|
|
2117
|
+
!this._sendToLightningAnimatable('colorTr', v)) {
|
|
2118
|
+
this.lng.colorTr = v;
|
|
2119
|
+
}
|
|
2120
|
+
},
|
|
2121
|
+
},
|
|
2122
|
+
colorBl: {
|
|
2123
|
+
get() {
|
|
2124
|
+
return this.lng.colorBl;
|
|
2125
|
+
},
|
|
2126
|
+
set(v) {
|
|
2127
|
+
if (this.transition === undefined ||
|
|
2128
|
+
!this._sendToLightningAnimatable('colorBl', v)) {
|
|
2129
|
+
this.lng.colorBl = v;
|
|
2130
|
+
}
|
|
2131
|
+
},
|
|
2132
|
+
},
|
|
2133
|
+
colorBr: {
|
|
2134
|
+
get() {
|
|
2135
|
+
return this.lng.colorBr;
|
|
2136
|
+
},
|
|
2137
|
+
set(v) {
|
|
2138
|
+
if (this.transition === undefined ||
|
|
2139
|
+
!this._sendToLightningAnimatable('colorBr', v)) {
|
|
2140
|
+
this.lng.colorBr = v;
|
|
2141
|
+
}
|
|
2142
|
+
},
|
|
2143
|
+
},
|
|
2144
|
+
h: {
|
|
2145
|
+
get() {
|
|
2146
|
+
return this.lng.h;
|
|
2147
|
+
},
|
|
2148
|
+
set(v) {
|
|
2149
|
+
if (this.transition === undefined ||
|
|
2150
|
+
!this._sendToLightningAnimatable('h', v)) {
|
|
2151
|
+
this.lng.h = v;
|
|
2152
|
+
}
|
|
2153
|
+
// On a text, the max height (renderer v2), which its layout reads.
|
|
2154
|
+
if (this._type === NodeType.TextNode) {
|
|
2155
|
+
this._textLayoutDirty();
|
|
2156
|
+
}
|
|
2157
|
+
},
|
|
2158
|
+
},
|
|
2159
|
+
mount: {
|
|
2160
|
+
get() {
|
|
2161
|
+
return this.lng.mount;
|
|
2162
|
+
},
|
|
2163
|
+
set(v) {
|
|
2164
|
+
if (this.transition === undefined ||
|
|
2165
|
+
!this._sendToLightningAnimatable('mount', v)) {
|
|
2166
|
+
this.lng.mount = v;
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
},
|
|
2170
|
+
mountX: {
|
|
2171
|
+
get() {
|
|
2172
|
+
return this.lng.mountX;
|
|
2173
|
+
},
|
|
2174
|
+
set(v) {
|
|
2175
|
+
if (this.transition === undefined ||
|
|
2176
|
+
!this._sendToLightningAnimatable('mountX', v)) {
|
|
2177
|
+
this.lng.mountX = v;
|
|
2178
|
+
}
|
|
2179
|
+
},
|
|
2180
|
+
},
|
|
2181
|
+
mountY: {
|
|
2182
|
+
get() {
|
|
2183
|
+
return this.lng.mountY;
|
|
2184
|
+
},
|
|
2185
|
+
set(v) {
|
|
2186
|
+
if (this.transition === undefined ||
|
|
2187
|
+
!this._sendToLightningAnimatable('mountY', v)) {
|
|
2188
|
+
this.lng.mountY = v;
|
|
2189
|
+
}
|
|
2190
|
+
},
|
|
2191
|
+
},
|
|
2192
|
+
pivot: {
|
|
2193
|
+
get() {
|
|
2194
|
+
return this.lng.pivot;
|
|
2195
|
+
},
|
|
2196
|
+
set(v) {
|
|
2197
|
+
if (this.transition === undefined ||
|
|
2198
|
+
!this._sendToLightningAnimatable('pivot', v)) {
|
|
2199
|
+
this.lng.pivot = v;
|
|
2200
|
+
}
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2203
|
+
pivotX: {
|
|
2204
|
+
get() {
|
|
2205
|
+
return this.lng.pivotX;
|
|
2206
|
+
},
|
|
2207
|
+
set(v) {
|
|
2208
|
+
if (this.transition === undefined ||
|
|
2209
|
+
!this._sendToLightningAnimatable('pivotX', v)) {
|
|
2210
|
+
this.lng.pivotX = v;
|
|
2211
|
+
}
|
|
2212
|
+
},
|
|
2213
|
+
},
|
|
2214
|
+
pivotY: {
|
|
2215
|
+
get() {
|
|
2216
|
+
return this.lng.pivotY;
|
|
2217
|
+
},
|
|
2218
|
+
set(v) {
|
|
2219
|
+
if (this.transition === undefined ||
|
|
2220
|
+
!this._sendToLightningAnimatable('pivotY', v)) {
|
|
2221
|
+
this.lng.pivotY = v;
|
|
2222
|
+
}
|
|
2223
|
+
},
|
|
2224
|
+
},
|
|
2225
|
+
rotation: {
|
|
2226
|
+
get() {
|
|
2227
|
+
return this.lng.rotation;
|
|
2228
|
+
},
|
|
2229
|
+
set(v) {
|
|
2230
|
+
if (this.transition === undefined ||
|
|
2231
|
+
!this._sendToLightningAnimatable('rotation', v)) {
|
|
2232
|
+
this.lng.rotation = v;
|
|
2233
|
+
}
|
|
2234
|
+
},
|
|
2235
|
+
},
|
|
2236
|
+
scale: {
|
|
2237
|
+
get() {
|
|
2238
|
+
return this.lng.scale;
|
|
2239
|
+
},
|
|
2240
|
+
set(v) {
|
|
2241
|
+
if (this.transition === undefined ||
|
|
2242
|
+
!this._sendToLightningAnimatable('scale', v)) {
|
|
2243
|
+
this.lng.scale = v;
|
|
2244
|
+
}
|
|
2245
|
+
},
|
|
2246
|
+
},
|
|
2247
|
+
scaleX: {
|
|
2248
|
+
get() {
|
|
2249
|
+
return this.lng.scaleX;
|
|
2250
|
+
},
|
|
2251
|
+
set(v) {
|
|
2252
|
+
if (this.transition === undefined ||
|
|
2253
|
+
!this._sendToLightningAnimatable('scaleX', v)) {
|
|
2254
|
+
this.lng.scaleX = v;
|
|
2255
|
+
}
|
|
2256
|
+
},
|
|
2257
|
+
},
|
|
2258
|
+
scaleY: {
|
|
2259
|
+
get() {
|
|
2260
|
+
return this.lng.scaleY;
|
|
2261
|
+
},
|
|
2262
|
+
set(v) {
|
|
2263
|
+
if (this.transition === undefined ||
|
|
2264
|
+
!this._sendToLightningAnimatable('scaleY', v)) {
|
|
2265
|
+
this.lng.scaleY = v;
|
|
2266
|
+
}
|
|
2267
|
+
},
|
|
2268
|
+
},
|
|
2269
|
+
w: {
|
|
2270
|
+
get() {
|
|
2271
|
+
return this.lng.w;
|
|
2272
|
+
},
|
|
2273
|
+
set(v) {
|
|
2274
|
+
if (this.transition === undefined ||
|
|
2275
|
+
!this._sendToLightningAnimatable('w', v)) {
|
|
2276
|
+
this.lng.w = v;
|
|
2277
|
+
}
|
|
2278
|
+
// On a text, the max width (renderer v2), which its layout reads.
|
|
2279
|
+
if (this._type === NodeType.TextNode) {
|
|
2280
|
+
this._textLayoutDirty();
|
|
2281
|
+
}
|
|
2282
|
+
},
|
|
2283
|
+
},
|
|
2284
|
+
x: {
|
|
2285
|
+
get() {
|
|
2286
|
+
return this.lng.x;
|
|
2287
|
+
},
|
|
2288
|
+
set(v) {
|
|
2289
|
+
if (this.transition === undefined ||
|
|
2290
|
+
!this._sendToLightningAnimatable('x', v)) {
|
|
2291
|
+
this.lng.x = v;
|
|
2292
|
+
}
|
|
2293
|
+
},
|
|
2294
|
+
},
|
|
2295
|
+
y: {
|
|
2296
|
+
get() {
|
|
2297
|
+
return this.lng.y;
|
|
2298
|
+
},
|
|
2299
|
+
set(v) {
|
|
2300
|
+
if (this.transition === undefined ||
|
|
2301
|
+
!this._sendToLightningAnimatable('y', v)) {
|
|
2302
|
+
this.lng.y = v;
|
|
2303
|
+
}
|
|
2304
|
+
},
|
|
2305
|
+
},
|
|
2306
|
+
zIndex: {
|
|
2307
|
+
get() {
|
|
2308
|
+
return this.lng.zIndex;
|
|
2309
|
+
},
|
|
2310
|
+
set(v) {
|
|
2311
|
+
if (this.transition === undefined ||
|
|
2312
|
+
!this._sendToLightningAnimatable('zIndex', v)) {
|
|
2313
|
+
this.lng.zIndex = v;
|
|
2314
|
+
}
|
|
2315
|
+
},
|
|
2316
|
+
},
|
|
2317
|
+
// Animatable, text only
|
|
2318
|
+
fontSize: {
|
|
2319
|
+
get() {
|
|
2320
|
+
return textPropsOf(this).fontSize;
|
|
2321
|
+
},
|
|
2322
|
+
set(v) {
|
|
2323
|
+
if (this._type !== NodeType.TextNode ||
|
|
2324
|
+
this.transition === undefined ||
|
|
2325
|
+
!this._sendToLightningAnimatable('fontSize', v)) {
|
|
2326
|
+
textPropsFor(this).fontSize = v;
|
|
2327
|
+
}
|
|
2328
|
+
this._textLayoutDirty();
|
|
2329
|
+
},
|
|
2330
|
+
},
|
|
2331
|
+
lineHeight: {
|
|
2332
|
+
get() {
|
|
2333
|
+
return textPropsOf(this).lineHeight;
|
|
2334
|
+
},
|
|
2335
|
+
set(v) {
|
|
2336
|
+
if (this._type !== NodeType.TextNode ||
|
|
2337
|
+
this.transition === undefined ||
|
|
2338
|
+
!this._sendToLightningAnimatable('lineHeight', v)) {
|
|
2339
|
+
textPropsFor(this).lineHeight = v;
|
|
2340
|
+
}
|
|
2341
|
+
this._textLayoutDirty();
|
|
2342
|
+
},
|
|
2343
|
+
},
|
|
2344
|
+
// Not animated
|
|
2345
|
+
atlasGroup: {
|
|
2346
|
+
get() {
|
|
2347
|
+
return this.lng.atlasGroup;
|
|
2348
|
+
},
|
|
2349
|
+
set(v) {
|
|
2350
|
+
this.lng.atlasGroup = v;
|
|
2351
|
+
},
|
|
2352
|
+
},
|
|
2353
|
+
autosize: {
|
|
2354
|
+
get() {
|
|
2355
|
+
return this.lng.autosize;
|
|
2356
|
+
},
|
|
2357
|
+
set(v) {
|
|
2358
|
+
this.lng.autosize = v;
|
|
2359
|
+
},
|
|
2360
|
+
},
|
|
2361
|
+
clipping: {
|
|
2362
|
+
get() {
|
|
2363
|
+
return this.lng.clipping;
|
|
2364
|
+
},
|
|
2365
|
+
set(v) {
|
|
2366
|
+
this.lng.clipping = v;
|
|
2367
|
+
},
|
|
2368
|
+
},
|
|
2369
|
+
componentName: {
|
|
2370
|
+
get() {
|
|
2371
|
+
return this.lng.componentName;
|
|
2372
|
+
},
|
|
2373
|
+
set(v) {
|
|
2374
|
+
this.lng.componentName = v;
|
|
2375
|
+
},
|
|
2376
|
+
},
|
|
2377
|
+
componentLocation: {
|
|
2378
|
+
get() {
|
|
2379
|
+
return this.lng.componentLocation;
|
|
2380
|
+
},
|
|
2381
|
+
set(v) {
|
|
2382
|
+
this.lng.componentLocation = v;
|
|
2383
|
+
},
|
|
2384
|
+
},
|
|
2385
|
+
data: {
|
|
2386
|
+
get() {
|
|
2387
|
+
return this.lng.data;
|
|
2388
|
+
},
|
|
2389
|
+
set(v) {
|
|
2390
|
+
this.lng.data = v;
|
|
2391
|
+
},
|
|
2392
|
+
},
|
|
2393
|
+
ignoreParentAlpha: {
|
|
2394
|
+
get() {
|
|
2395
|
+
return this.lng.ignoreParentAlpha;
|
|
2396
|
+
},
|
|
2397
|
+
set(v) {
|
|
2398
|
+
this.lng.ignoreParentAlpha = v;
|
|
2399
|
+
},
|
|
2400
|
+
},
|
|
2401
|
+
imageType: {
|
|
2402
|
+
get() {
|
|
2403
|
+
return this.lng.imageType;
|
|
2404
|
+
},
|
|
2405
|
+
set(v) {
|
|
2406
|
+
this.lng.imageType = v;
|
|
2407
|
+
},
|
|
2408
|
+
},
|
|
2409
|
+
placeholderColor: {
|
|
2410
|
+
get() {
|
|
2411
|
+
return this.lng.placeholderColor;
|
|
2412
|
+
},
|
|
2413
|
+
set(v) {
|
|
2414
|
+
this.lng.placeholderColor = v;
|
|
2415
|
+
},
|
|
2416
|
+
},
|
|
2417
|
+
srcHeight: {
|
|
2418
|
+
get() {
|
|
2419
|
+
return this.lng.srcHeight;
|
|
2420
|
+
},
|
|
2421
|
+
set(v) {
|
|
2422
|
+
this.lng.srcHeight = v;
|
|
2423
|
+
},
|
|
2424
|
+
},
|
|
2425
|
+
srcWidth: {
|
|
2426
|
+
get() {
|
|
2427
|
+
return this.lng.srcWidth;
|
|
2428
|
+
},
|
|
2429
|
+
set(v) {
|
|
2430
|
+
this.lng.srcWidth = v;
|
|
2431
|
+
},
|
|
2432
|
+
},
|
|
2433
|
+
srcX: {
|
|
2434
|
+
get() {
|
|
2435
|
+
return this.lng.srcX;
|
|
2436
|
+
},
|
|
2437
|
+
set(v) {
|
|
2438
|
+
this.lng.srcX = v;
|
|
2439
|
+
},
|
|
2440
|
+
},
|
|
2441
|
+
srcY: {
|
|
2442
|
+
get() {
|
|
2443
|
+
return this.lng.srcY;
|
|
2444
|
+
},
|
|
2445
|
+
set(v) {
|
|
2446
|
+
this.lng.srcY = v;
|
|
2447
|
+
},
|
|
2448
|
+
},
|
|
2449
|
+
texture: {
|
|
2450
|
+
get() {
|
|
2451
|
+
return this.lng.texture;
|
|
2452
|
+
},
|
|
2453
|
+
set(v) {
|
|
2454
|
+
this.lng.texture = v;
|
|
2455
|
+
},
|
|
2456
|
+
},
|
|
2457
|
+
textureOptions: {
|
|
2458
|
+
get() {
|
|
2459
|
+
return this.lng.textureOptions;
|
|
2460
|
+
},
|
|
2461
|
+
set(v) {
|
|
2462
|
+
this.lng.textureOptions = v;
|
|
2463
|
+
},
|
|
2464
|
+
},
|
|
2465
|
+
// Not animated, text only
|
|
2466
|
+
contain: {
|
|
2467
|
+
get() {
|
|
2468
|
+
return textPropsOf(this).contain;
|
|
2469
|
+
},
|
|
2470
|
+
set(v) {
|
|
2471
|
+
textPropsFor(this).contain = v;
|
|
2472
|
+
// The DOM renderer sizes a text by it (renderer v2 only moves the
|
|
2473
|
+
// block: the measure finds nothing to lay out).
|
|
2474
|
+
this._textLayoutDirty();
|
|
2475
|
+
},
|
|
2476
|
+
},
|
|
2477
|
+
forceLoad: {
|
|
2478
|
+
get() {
|
|
2479
|
+
return textPropsOf(this).forceLoad;
|
|
2480
|
+
},
|
|
2481
|
+
set(v) {
|
|
2482
|
+
textPropsFor(this).forceLoad = v;
|
|
2483
|
+
},
|
|
2484
|
+
},
|
|
2485
|
+
fontStyle: {
|
|
2486
|
+
get() {
|
|
2487
|
+
return textPropsOf(this).fontStyle;
|
|
2488
|
+
},
|
|
2489
|
+
set(v) {
|
|
2490
|
+
textPropsFor(this).fontStyle = v;
|
|
2491
|
+
this._textLayoutDirty();
|
|
2492
|
+
},
|
|
2493
|
+
},
|
|
2494
|
+
letterSpacing: {
|
|
2495
|
+
get() {
|
|
2496
|
+
return textPropsOf(this).letterSpacing;
|
|
2497
|
+
},
|
|
2498
|
+
set(v) {
|
|
2499
|
+
textPropsFor(this).letterSpacing = v;
|
|
2500
|
+
this._textLayoutDirty();
|
|
2501
|
+
},
|
|
2502
|
+
},
|
|
2503
|
+
maxHeight: {
|
|
2504
|
+
get() {
|
|
2505
|
+
return textPropsOf(this).maxHeight;
|
|
2506
|
+
},
|
|
2507
|
+
set(v) {
|
|
2508
|
+
textPropsFor(this).maxHeight = v;
|
|
2509
|
+
this._textLayoutDirty();
|
|
2510
|
+
},
|
|
2511
|
+
},
|
|
2512
|
+
maxLines: {
|
|
2513
|
+
get() {
|
|
2514
|
+
return textPropsOf(this).maxLines;
|
|
2515
|
+
},
|
|
2516
|
+
set(v) {
|
|
2517
|
+
textPropsFor(this).maxLines = v;
|
|
2518
|
+
this._textLayoutDirty();
|
|
2519
|
+
},
|
|
2520
|
+
},
|
|
2521
|
+
maxWidth: {
|
|
2522
|
+
get() {
|
|
2523
|
+
return textPropsOf(this).maxWidth;
|
|
2524
|
+
},
|
|
2525
|
+
set(v) {
|
|
2526
|
+
textPropsFor(this).maxWidth = v;
|
|
2527
|
+
this._textLayoutDirty();
|
|
2528
|
+
},
|
|
2529
|
+
},
|
|
2530
|
+
offsetY: {
|
|
2531
|
+
get() {
|
|
2532
|
+
return textPropsOf(this).offsetY;
|
|
2533
|
+
},
|
|
2534
|
+
set(v) {
|
|
2535
|
+
textPropsFor(this).offsetY = v;
|
|
2536
|
+
},
|
|
2537
|
+
},
|
|
2538
|
+
overflowSuffix: {
|
|
2539
|
+
get() {
|
|
2540
|
+
return textPropsOf(this).overflowSuffix;
|
|
2541
|
+
},
|
|
2542
|
+
set(v) {
|
|
2543
|
+
textPropsFor(this).overflowSuffix = v;
|
|
2544
|
+
this._textLayoutDirty();
|
|
2545
|
+
},
|
|
2546
|
+
},
|
|
2547
|
+
text: {
|
|
2548
|
+
get() {
|
|
2549
|
+
return textPropsOf(this).text;
|
|
2550
|
+
},
|
|
2551
|
+
set(v) {
|
|
2552
|
+
textPropsFor(this).text = v;
|
|
2553
|
+
this._textLayoutDirty();
|
|
2554
|
+
},
|
|
2555
|
+
},
|
|
2556
|
+
textAlign: {
|
|
2557
|
+
get() {
|
|
2558
|
+
return textPropsOf(this).textAlign;
|
|
2559
|
+
},
|
|
2560
|
+
set(v) {
|
|
2561
|
+
textPropsFor(this).textAlign = v;
|
|
2562
|
+
},
|
|
2563
|
+
},
|
|
2564
|
+
verticalAlign: {
|
|
2565
|
+
get() {
|
|
2566
|
+
return textPropsOf(this).verticalAlign;
|
|
2567
|
+
},
|
|
2568
|
+
set(v) {
|
|
2569
|
+
textPropsFor(this).verticalAlign = v;
|
|
2570
|
+
},
|
|
2571
|
+
},
|
|
2572
|
+
wordBreak: {
|
|
2573
|
+
get() {
|
|
2574
|
+
return textPropsOf(this).wordBreak;
|
|
2575
|
+
},
|
|
2576
|
+
set(v) {
|
|
2577
|
+
textPropsFor(this).wordBreak = v;
|
|
2578
|
+
this._textLayoutDirty();
|
|
2579
|
+
},
|
|
2580
|
+
},
|
|
2581
|
+
// Read-only on the renderer node: a write would throw there (B20)
|
|
2582
|
+
absX: {
|
|
2583
|
+
get() {
|
|
2584
|
+
return this.lng.absX;
|
|
2585
|
+
},
|
|
2586
|
+
set: ignoreWrite,
|
|
2587
|
+
},
|
|
2588
|
+
absY: {
|
|
2589
|
+
get() {
|
|
2590
|
+
return this.lng.absY;
|
|
2591
|
+
},
|
|
2592
|
+
set: ignoreWrite,
|
|
2593
|
+
},
|
|
2594
|
+
destroyed: {
|
|
2595
|
+
get() {
|
|
2596
|
+
return this.lng.destroyed;
|
|
2597
|
+
},
|
|
2598
|
+
set: ignoreWrite,
|
|
2599
|
+
},
|
|
2600
|
+
});
|
|
2601
|
+
// The DOM renderer draws fontStretch; a rendered WebGL text node has no such
|
|
2602
|
+
// prop, and a @solidtv/renderer 2.0 node would take it as a field of its own.
|
|
2603
|
+
// Before render the value waits in the props bag, which the renderer's
|
|
2604
|
+
// createTextNode ignores.
|
|
2605
|
+
Object.defineProperty(ElementNode.prototype, 'fontStretch', {
|
|
2606
|
+
get() {
|
|
2607
|
+
return this.lng.fontStretch;
|
|
2608
|
+
},
|
|
2609
|
+
set(v) {
|
|
2610
|
+
if (this.rendered && !isDomRendererActive())
|
|
2611
|
+
return;
|
|
2612
|
+
this.lng.fontStretch = v;
|
|
2613
|
+
},
|
|
2614
|
+
});
|
|
1232
2615
|
export function createRawShaderAccessor(key) {
|
|
1233
2616
|
return {
|
|
1234
2617
|
set(value) {
|
|
2618
|
+
const shader = this.lng.shader;
|
|
2619
|
+
if (value == null) {
|
|
2620
|
+
// Clear the shader this accessor made; createShader would make one
|
|
2621
|
+
// with the type's defaults. A shader made otherwise is not ours.
|
|
2622
|
+
if (shader != null && gradientShaders.get(shader) === key) {
|
|
2623
|
+
this._shaderProps = undefined;
|
|
2624
|
+
this.lng.shader = null;
|
|
2625
|
+
}
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
if (shader != null &&
|
|
2629
|
+
isObject(value) &&
|
|
2630
|
+
gradientShaders.get(shader) === key) {
|
|
2631
|
+
// The gradient shader this accessor made: update it, not a new one,
|
|
2632
|
+
// to the props createShader would have built from `value`: a
|
|
2633
|
+
// declared prop `value` does not name takes its default. The type's
|
|
2634
|
+
// declaration is read here, each set: a gradient is set rarely.
|
|
2635
|
+
const type = shader.shaderType;
|
|
2636
|
+
const defs = isObject(type) ? type.props : undefined;
|
|
2637
|
+
if (!isObject(defs)) {
|
|
2638
|
+
// The DOM renderer keeps the given object as the props.
|
|
2639
|
+
shader.props = value;
|
|
2640
|
+
}
|
|
2641
|
+
else {
|
|
2642
|
+
const props = shader.props;
|
|
2643
|
+
// Props first, then aliases, each in declaration order, as
|
|
2644
|
+
// createShader applies them; an alias only writes when given.
|
|
2645
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
2646
|
+
for (const name in defs) {
|
|
2647
|
+
const def = defs[name];
|
|
2648
|
+
// An AdvancedProp has a default (the registry's test).
|
|
2649
|
+
const advanced = isObject(def) && def.default !== undefined;
|
|
2650
|
+
const alias = advanced && def.set !== undefined;
|
|
2651
|
+
if (alias !== (pass === 1)) {
|
|
2652
|
+
continue;
|
|
2653
|
+
}
|
|
2654
|
+
const resolves = advanced && def.resolve !== undefined;
|
|
2655
|
+
const given = value[name];
|
|
2656
|
+
if (given !== undefined) {
|
|
2657
|
+
// createShader copies an array, unless the prop resolves it.
|
|
2658
|
+
props[name] = resolves ? given : copyOf(given);
|
|
2659
|
+
}
|
|
2660
|
+
else if (!alias) {
|
|
2661
|
+
// What a shader created without it holds: a prop that
|
|
2662
|
+
// resolves its value resolves its default from undefined, a
|
|
2663
|
+
// plain one takes a copy of its default.
|
|
2664
|
+
props[name] = resolves
|
|
2665
|
+
? undefined
|
|
2666
|
+
: copyOf(advanced ? def.default : def);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
if (this.rendered && isDomRendererActive()) {
|
|
2672
|
+
// The DOM renderer restyles when its shader is assigned.
|
|
2673
|
+
this.lng.shader = shader;
|
|
2674
|
+
}
|
|
2675
|
+
return;
|
|
2676
|
+
}
|
|
1235
2677
|
this.shader = [key, value];
|
|
2678
|
+
const created = this.lng.shader;
|
|
2679
|
+
if (created != null) {
|
|
2680
|
+
gradientShaders.set(created, key);
|
|
2681
|
+
}
|
|
1236
2682
|
},
|
|
1237
2683
|
get() {
|
|
1238
2684
|
return this.shader;
|
|
@@ -1242,37 +2688,85 @@ export function createRawShaderAccessor(key) {
|
|
|
1242
2688
|
export function shaderAccessor(key) {
|
|
1243
2689
|
return {
|
|
1244
2690
|
set(value) {
|
|
1245
|
-
let
|
|
1246
|
-
|
|
1247
|
-
|
|
2691
|
+
let effects = this._effects;
|
|
2692
|
+
if (effects === undefined) {
|
|
2693
|
+
effects = this._effects = {};
|
|
2694
|
+
}
|
|
2695
|
+
const prev = effects[key];
|
|
2696
|
+
effects[key] = value;
|
|
2697
|
+
// The radius (a number written to a border key too), else a border or
|
|
2698
|
+
// shadow object: as before 1.7, its sub-props merge into the shader
|
|
2699
|
+
// props, the later write winning, so a state undo that writes the
|
|
2700
|
+
// style's object back leaves the sub-props it does not name (B18, not
|
|
2701
|
+
// fixed in 1.7); undefined writes nothing.
|
|
2702
|
+
const radius = key === 'rounded' || typeof value === 'number';
|
|
2703
|
+
const shader = this.lng.shader;
|
|
2704
|
+
const props = shader != null ? shader.props : undefined;
|
|
2705
|
+
let target;
|
|
1248
2706
|
let animationSettings;
|
|
1249
|
-
if (
|
|
1250
|
-
target =
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
2707
|
+
if (props != null) {
|
|
2708
|
+
target = props;
|
|
2709
|
+
// With a transition for the key, the sub-props go into a target of
|
|
2710
|
+
// their own, which animates (one of `true` is built and dropped, as
|
|
2711
|
+
// before 1.7).
|
|
2712
|
+
const transition = this.transition;
|
|
2713
|
+
if (transition) {
|
|
2714
|
+
const setting = transition === true
|
|
2715
|
+
? true
|
|
2716
|
+
: transition[key === 'rounded' ? 'borderRadius' : key];
|
|
2717
|
+
if (setting) {
|
|
2718
|
+
target = {};
|
|
2719
|
+
animationSettings =
|
|
2720
|
+
setting === true ? undefined : setting;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
else {
|
|
2725
|
+
// No shader yet: before render, the props bag createShader reads at
|
|
2726
|
+
// render; after render, the props of a new shader. (A rendered DOM
|
|
2727
|
+
// node without one holds the renderer's shared default: never write
|
|
2728
|
+
// into it.)
|
|
2729
|
+
target =
|
|
2730
|
+
shader != null && !this.rendered
|
|
2731
|
+
? shader
|
|
2732
|
+
: {};
|
|
2733
|
+
}
|
|
2734
|
+
if (radius) {
|
|
2735
|
+
// Into the shader's props only when it changed. An animated undo to
|
|
2736
|
+
// no radius animates to 0, which is what 1.6.4 showed: renderer 1.9
|
|
2737
|
+
// made a track for undefined and resolved it to [0, 0, 0, 0];
|
|
2738
|
+
// renderer 2.0 makes no track for undefined.
|
|
2739
|
+
if (target === props && value === prev) {
|
|
2740
|
+
return;
|
|
1259
2741
|
}
|
|
2742
|
+
target.radius =
|
|
2743
|
+
value === undefined && animationSettings !== undefined ? 0 : value;
|
|
1260
2744
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
2745
|
+
else if (isObject(value)) {
|
|
2746
|
+
parseAndAssignShaderProps(key, value, target);
|
|
2747
|
+
}
|
|
2748
|
+
// A shader convertToShader made keeps its props and swaps its type when
|
|
2749
|
+
// a border width moves to or from 0. An animated write swaps a border
|
|
2750
|
+
// it adds in before the animation reads its start values; one it
|
|
2751
|
+
// removes stays until the animation stops.
|
|
2752
|
+
const kept = this._shaderProps;
|
|
2753
|
+
if (kept !== undefined) {
|
|
2754
|
+
const animated = target !== props;
|
|
1265
2755
|
if (animated)
|
|
1266
2756
|
this._syncShaderType(target);
|
|
1267
|
-
if (
|
|
1268
|
-
|
|
2757
|
+
if (kept !== target) {
|
|
2758
|
+
if (radius)
|
|
2759
|
+
kept.radius = target.radius;
|
|
2760
|
+
else if (isObject(value))
|
|
2761
|
+
parseAndAssignShaderProps(key, value, kept);
|
|
2762
|
+
}
|
|
1269
2763
|
if (!animated)
|
|
1270
2764
|
this._syncShaderType();
|
|
1271
2765
|
}
|
|
1272
2766
|
this._writeShaderTarget(target);
|
|
1273
|
-
if (animationSettings) {
|
|
2767
|
+
if (animationSettings !== undefined) {
|
|
1274
2768
|
const animation = this.animate({ shaderProps: target }, animationSettings).start();
|
|
1275
|
-
if (
|
|
2769
|
+
if (kept !== undefined) {
|
|
1276
2770
|
void animation.waitUntilStopped().then(() => this._syncShaderType());
|
|
1277
2771
|
}
|
|
1278
2772
|
}
|
|
@@ -1299,5 +2793,6 @@ Object.defineProperties(ElementNode.prototype, {
|
|
|
1299
2793
|
borderRadius: shaderAccessor('rounded'),
|
|
1300
2794
|
linearGradient: createRawShaderAccessor('linearGradient'),
|
|
1301
2795
|
radialGradient: createRawShaderAccessor('radialGradient'),
|
|
2796
|
+
dashedBorder: createRawShaderAccessor('dashedBorder'),
|
|
1302
2797
|
});
|
|
1303
2798
|
//# sourceMappingURL=elementNode.js.map
|