embedded-react 0.16.0 → 0.17.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.
@@ -31,6 +31,8 @@ const INDENT = ' ';
31
31
  export const APP_UPDATE_CALL = ' app_update();';
32
32
  /** The indent list operations print at, whatever block they sit in. */
33
33
  const LIST_INDENT = INDENT;
34
+ /** The file-scope flags that record which state was written since app_update() last ran. */
35
+ export const CHANGED_FLAGS = 's_changed';
34
36
  /*----------------------------------------------------------------------------------------------------------------------
35
37
  - Implementation
36
38
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -42,6 +44,16 @@ const LIST_INDENT = INDENT;
42
44
  * @returns A pattern that finds it in the C source.
43
45
  */
44
46
  const readsMember = (member) => new RegExp(`(^|[^\\w.])${member.replace(/\./g, '\\.')}(?![\\w])`);
47
+ /**
48
+ * The line that flags a state as written, so app_update() sets the nodes that read it again; none when no node
49
+ * reads it.
50
+ *
51
+ * @param state The state.
52
+ * @param indent The line's indentation.
53
+ *
54
+ * @returns The C lines.
55
+ */
56
+ export const printChangedFlag = (state, indent) => state.isWatched ? [`${indent}${CHANGED_FLAGS}.${state.cField} = 1;`] : [];
45
57
  /**
46
58
  * A timer as the C call that starts it and evaluates to its id. A timestamp or float delay goes through
47
59
  * ToInt32 and a floor at 0, as Flow A's setTimeout does.
@@ -151,27 +163,44 @@ function printStmt(stmt, indent) {
151
163
  case 'clearTimer':
152
164
  return [`${indent}er_timer_clear(${printExpr(stmt.id)});`];
153
165
  case 'setState':
154
- return [`${indent}${stmt.state.cMember} = ${printExpr(stmt.value)};`];
166
+ return [
167
+ `${indent}${stmt.state.cMember} = ${printExpr(stmt.value)};`,
168
+ ...printChangedFlag(stmt.state, indent),
169
+ ];
155
170
  case 'setStateText':
156
- return [printSetStateText(stmt, indent)];
171
+ return [
172
+ printSetStateText(stmt, indent),
173
+ ...printChangedFlag(stmt.state, indent),
174
+ ];
157
175
  case 'clearList':
158
- return [`${LIST_INDENT}${stmt.list.countMember} = 0;`];
176
+ return [
177
+ `${LIST_INDENT}${stmt.list.countMember} = 0;`,
178
+ ...printChangedFlag(stmt.list, LIST_INDENT),
179
+ ];
159
180
  case 'appendItem':
160
- return printAppendItem(stmt);
181
+ return [
182
+ ...printAppendItem(stmt),
183
+ ...printChangedFlag(stmt.list, LIST_INDENT),
184
+ ];
161
185
  case 'dropLastItem': {
162
186
  const count = stmt.list.countMember;
163
- return [`${LIST_INDENT}if (${count} > 0) ${count}--;`];
187
+ return [
188
+ `${LIST_INDENT}if (${count} > 0) ${count}--;`,
189
+ ...printChangedFlag(stmt.list, LIST_INDENT),
190
+ ];
164
191
  }
165
192
  case 'keepFirstItems': {
166
193
  const count = stmt.list.countMember;
167
194
  return [
168
195
  `${LIST_INDENT}${count} = (${count} < ${stmt.count}) ? ${count} : ${stmt.count};`,
196
+ ...printChangedFlag(stmt.list, LIST_INDENT),
169
197
  ];
170
198
  }
171
199
  case 'sliceItems': {
172
200
  const count = stmt.list.countMember;
173
201
  return [
174
202
  `${LIST_INDENT}${count} = app_slice_len(${count}, ${printExpr(stmt.end)});`,
203
+ ...printChangedFlag(stmt.list, LIST_INDENT),
175
204
  ];
176
205
  }
177
206
  case 'writeRef':
@@ -21,6 +21,8 @@ import { parse } from '@babel/parser';
21
21
  import { readFileSync, existsSync } from 'node:fs';
22
22
  import { resolve } from 'node:path';
23
23
  import { aotError } from './diagnostics.mjs';
24
+ import { mergeBranchElements } from './branch-merge.mjs';
25
+ import { bootCheckpoint, foldBoot, isBoot, nameBootValues, screenBinding, } from './boot.mjs';
24
26
  import { evalStaticOrThrow, evalStatic, withUndefined } from './static-eval.mjs';
25
27
  import { cConstant, cTypeOfValue } from './c-syntax.mjs';
26
28
  /*----------------------------------------------------------------------------------------------------------------------
@@ -125,7 +127,20 @@ export function declaredNames(body) {
125
127
  return names;
126
128
  }
127
129
  /**
128
- * The module's compile-time scope: `screen`, the seed, and every module-level `const` that folds.
130
+ * A const's folded value, with the boot values in it named after the const.
131
+ *
132
+ * @param name The const's name.
133
+ * @param value Its folded value.
134
+ *
135
+ * @returns The value.
136
+ */
137
+ export function bindConst(name, value) {
138
+ nameBootValues(value, name);
139
+ return value;
140
+ }
141
+ /**
142
+ * The module's compile-time scope: `screen`, the seed, and every module-level `const` that folds. A const
143
+ * derived from `screen` is a boot value (see BootValue).
129
144
  *
130
145
  * @param program The parsed module.
131
146
  * @param screen The panel size in this build folds its layout at.
@@ -135,7 +150,7 @@ export function declaredNames(body) {
135
150
  */
136
151
  export function moduleScope(program, screen, seed = {}) {
137
152
  // Seed the scope (image imports as asset names) before folding module consts, so a const can reference them.
138
- const scope = { screen, ...seed };
153
+ const scope = { screen: screenBinding(screen), ...seed };
139
154
  // Fold module variables in order so later ones see earlier ones; skip functions, destructuring and non-folds.
140
155
  for (const stmt of program.body) {
141
156
  const declaration = stmt.type === 'ExportNamedDeclaration' ? stmt.declaration : stmt;
@@ -149,7 +164,7 @@ export function moduleScope(program, screen, seed = {}) {
149
164
  continue;
150
165
  }
151
166
  try {
152
- scope[decl.id.name] = evalStatic(decl.init, withUndefined(scope));
167
+ scope[decl.id.name] = bindConst(decl.id.name, evalStatic(decl.init, withUndefined(scope), 'boot'));
153
168
  }
154
169
  catch {
155
170
  /* not a static const — skip */
@@ -348,8 +363,9 @@ export function collectState(fnBody, scope, caps, prefix = '', wide = NO_WIDE) {
348
363
  return { byName, bySetter };
349
364
  }
350
365
  /**
351
- * The JSX a component body returns. A top-level `if` whose test folds are decided at compile time, so a
352
- * responsive layout returns the branch for this build's screen.
366
+ * The JSX a component body returns. A top-level `if` whose test folds is decided at compile time, so a
367
+ * responsive layout returns the branch for this build's screen. When the test depends on the panel and both
368
+ * outcomes return elements of one shape, they merge into one element whose values boot picks.
353
369
  *
354
370
  * @param fnBody The component's body.
355
371
  * @param scope Compile-time constants the `if` tests fold against.
@@ -357,23 +373,31 @@ export function collectState(fnBody, scope, caps, prefix = '', wide = NO_WIDE) {
357
373
  * @returns The returned element.
358
374
  */
359
375
  export function findReturnJSX(fnBody, scope = {}) {
376
+ const statementsOf = (branch) => branch.type === 'BlockStatement' ? branch.body : [branch];
360
377
  // Fold top-level `if (staticCond) return …` at compile time — responsive layouts switch on `screen`.
361
378
  const scan = (statements) => {
362
- for (const stmt of statements) {
379
+ for (const [index, stmt] of statements.entries()) {
363
380
  // A top-level `if` must fold; only the branch it takes is scanned.
364
381
  if (stmt.type === 'IfStatement') {
365
382
  let testValue;
366
383
  try {
367
- testValue = evalStatic(stmt.test, scope);
384
+ testValue = evalStatic(stmt.test, scope, 'boot');
368
385
  }
369
386
  catch {
370
387
  throw new Error('AOT: a top-level `if` in the component must have a compile-time-constant test (e.g. ' +
371
388
  'on the `screen` global) — runtime layout branching is not supported');
372
389
  }
390
+ // A test that depends on the panel needs no variant when both outcomes have one shape.
391
+ if (isBoot(testValue)) {
392
+ const merged = mergeOutcomes(stmt, statements.slice(index + 1));
393
+ if (merged)
394
+ return merged;
395
+ testValue = foldBoot(testValue);
396
+ }
373
397
  // Follow only the statically selected branch and keep scanning it until a JSX return is found.
374
398
  const branch = testValue ? stmt.consequent : stmt.alternate;
375
399
  if (branch) {
376
- const branchJSX = scan(branch.type === 'BlockStatement' ? branch.body : [branch]);
400
+ const branchJSX = scan(statementsOf(branch));
377
401
  if (branchJSX)
378
402
  return branchJSX;
379
403
  }
@@ -388,6 +412,24 @@ export function findReturnJSX(fnBody, scope = {}) {
388
412
  }
389
413
  return null;
390
414
  };
415
+ // What each outcome of an `if` returns (a branch that does not return falls through), merged when it can be.
416
+ const mergeOutcomes = (stmt, rest) => {
417
+ const restore = bootCheckpoint();
418
+ try {
419
+ const whenTrue = scan(statementsOf(stmt.consequent)) ?? scan(rest);
420
+ const whenFalse = (stmt.alternate && scan(statementsOf(stmt.alternate))) ?? scan(rest);
421
+ const merged = whenTrue && whenFalse
422
+ ? mergeBranchElements(stmt.test, whenTrue, whenFalse)
423
+ : null;
424
+ if (merged)
425
+ return merged;
426
+ }
427
+ catch {
428
+ /* an outcome that does not compile here is left to the fold, which reports it if it is taken */
429
+ }
430
+ restore();
431
+ return null;
432
+ };
391
433
  // Scan the body; a component that never returns is an error.
392
434
  const returnJSX = scan(fnBody.body);
393
435
  if (!returnJSX) {
@@ -17,9 +17,11 @@
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
19
  import { aotError } from './diagnostics.mjs';
20
+ import { foldBoot, isBoot } from './boot.mjs';
21
+ import { mergeBranchElements } from './branch-merge.mjs';
20
22
  import { evalStatic, withUndefined } from './static-eval.mjs';
21
23
  import { emitSourcedWide, lowerExpr } from './expressions.mjs';
22
- import { isFn, declaredNames, collectState, componentReturnJSX, collectHelpers, collectCallbacks, collectMemos, collectEffects, usesState, } from './collect.mjs';
24
+ import { isFn, declaredNames, collectState, componentReturnJSX, collectHelpers, collectCallbacks, collectMemos, collectEffects, usesState, bindConst, } from './collect.mjs';
23
25
  import { collectAnims, collectRefs } from './animations.mjs';
24
26
  import { attrExpr } from './style-text.mjs';
25
27
  import { inlineFragments } from './elements/props.mjs';
@@ -93,9 +95,10 @@ function extractProps(openingElement, scope, env) {
93
95
  }
94
96
  // Any other prop folds to a constant when it can, else becomes a runtime C expression.
95
97
  try {
96
- props[attr.name.name] = {
98
+ const propName = attr.name.name;
99
+ props[propName] = {
97
100
  static: true,
98
- value: evalStatic(node, scope),
101
+ value: bindConst(propName, evalStatic(node, scope, 'boot')),
99
102
  };
100
103
  }
101
104
  catch {
@@ -277,7 +280,7 @@ export function emitComponent(element, scope, out, env, state, opts) {
277
280
  if (childLocals.has(decl.id.name))
278
281
  continue; // a dynamic prop of that name is already bound
279
282
  try {
280
- childScope[decl.id.name] = evalStatic(decl.init, withUndefined(childScope));
283
+ childScope[decl.id.name] = bindConst(decl.id.name, evalStatic(decl.init, withUndefined(childScope), 'boot'));
281
284
  }
282
285
  catch {
283
286
  // A dynamic const hides any same-named module const; a memo re-binds it below, else it stays unresolved.
@@ -324,7 +327,7 @@ export function emitComponent(element, scope, out, env, state, opts) {
324
327
  // Resolve memos in order (fold, else a local C expr), then compile its effects, all in the child's env/state.
325
328
  for (const [name, expr] of childMemos) {
326
329
  try {
327
- childScope[name] = evalStatic(expr, childScope);
330
+ childScope[name] = bindConst(name, evalStatic(expr, childScope, 'boot'));
328
331
  }
329
332
  catch {
330
333
  const cExpr = emitSourcedWide(expr, childEnv);
@@ -492,6 +495,7 @@ function emitDynamicMap(call, listState, scope, out, env, state) {
492
495
  rowLocals.set(itemName, {
493
496
  code: `${listState.arrayName}[${rowIndex}]`,
494
497
  struct: listState.struct,
498
+ list: listState,
495
499
  });
496
500
  }
497
501
  rows.push(emitElementInto(rowJSX, rowScope, out, rowEnv(env, [itemName, indexName], rowScope, rowLocals), state, { show: { kind: 'rowInUse', row: rowIndex, list: listState } }));
@@ -558,11 +562,20 @@ function lowerBranch(expr, scope, out, env, state, within) {
558
562
  // A test that folds picks its branch at build time; `&&` with a false test renders nothing.
559
563
  let folded;
560
564
  try {
561
- folded = { value: evalStatic(testNode, scope) };
565
+ folded = { value: evalStatic(testNode, scope, 'boot') };
562
566
  }
563
567
  catch {
564
568
  folded = null;
565
569
  }
570
+ // A test that depends on the panel needs no variant when both branches are elements of one shape.
571
+ if (folded && isBoot(folded.value)) {
572
+ const merged = whenTrue.type === 'JSXElement' && whenFalse?.type === 'JSXElement'
573
+ ? mergeBranchElements(testNode, whenTrue, whenFalse)
574
+ : null;
575
+ if (merged)
576
+ return lowerBranch(merged, scope, out, env, state, within);
577
+ folded = { value: foldBoot(folded.value) };
578
+ }
566
579
  if (folded) {
567
580
  // A false `&&` yields its left value, which must be one React renders as nothing (`0` is text).
568
581
  if (isAnd && !folded.value && !rendersNothing(folded.value)) {
@@ -109,7 +109,7 @@ export function emitDial(element, scope, out, env, state) {
109
109
  const numeric = (field, node, isFloat, attr) => {
110
110
  let number;
111
111
  try {
112
- number = evalStatic(node, scope);
112
+ number = evalStatic(node, scope, 'strict');
113
113
  }
114
114
  catch {
115
115
  const value = lowerExpr(node, env);
@@ -135,7 +135,7 @@ export function emitDial(element, scope, out, env, state) {
135
135
  const colour = (field, node, attr) => {
136
136
  let color;
137
137
  try {
138
- color = evalStatic(node, scope);
138
+ color = evalStatic(node, scope, 'strict');
139
139
  }
140
140
  catch {
141
141
  dynAssigns.push({ field, value: lowerColorValue(node, env) });
@@ -182,7 +182,7 @@ export function emitDial(element, scope, out, env, state) {
182
182
  const { field, table } = DIAL_ENUM_PROPS[name];
183
183
  let token = null;
184
184
  try {
185
- token = evalStatic(node, scope);
185
+ token = evalStatic(node, scope, 'strict');
186
186
  }
187
187
  catch {
188
188
  /* state-driven — handled below */
@@ -203,7 +203,10 @@ export function emitDial(element, scope, out, env, state) {
203
203
  else if (name === 'adjustable' || name === 'range') {
204
204
  const field = name === 'range' ? 'arc_range' : 'arc_adjustable';
205
205
  try {
206
- staticAssigns.push({ field, expr: evalStatic(node, scope) ? '1' : '0' });
206
+ staticAssigns.push({
207
+ field,
208
+ expr: evalStatic(node, scope, 'strict') ? '1' : '0',
209
+ });
207
210
  }
208
211
  catch {
209
212
  dynAssigns.push({
@@ -19,6 +19,7 @@
19
19
  import { attemptLowering, checkNumber } from './check.mjs';
20
20
  import { traverse } from '@babel/core';
21
21
  import { aotError, locateError, withLoc } from './diagnostics.mjs';
22
+ import { bootSlotOf, containsBoot, foldBoot, isBoot, wholeBootValue, } from './boot.mjs';
22
23
  import { evalStatic, foldScope } from './static-eval.mjs';
23
24
  import { lowerGestureField } from './pan-responder.mjs';
24
25
  import { toCExpr } from './c/expressions.mjs';
@@ -45,6 +46,14 @@ const CHECKED_HELPER = {
45
46
  '-': 'sub',
46
47
  '*': 'mul',
47
48
  };
49
+ /** Expressions an app may write over values worked out at boot, which then read as one boot slot. */
50
+ const WHOLE_BOOT_TYPES = new Set([
51
+ 'BinaryExpression',
52
+ 'UnaryExpression',
53
+ 'LogicalExpression',
54
+ 'ConditionalExpression',
55
+ 'CallExpression',
56
+ ]);
48
57
  /** The range of a C int. */
49
58
  const INT_MIN = -(2 ** 31);
50
59
  export const INT_MAX = 2 ** 31 - 1;
@@ -143,7 +152,7 @@ export function findShadowedClockCalls(ast) {
143
152
  */
144
153
  export function staticInt(node, env) {
145
154
  try {
146
- const value = evalStatic(node, foldScope(env, env.consts ?? {}));
155
+ const value = evalStatic(node, foldScope(env, env.consts ?? {}), 'strict');
147
156
  return Number.isInteger(value) ? value : null;
148
157
  }
149
158
  catch {
@@ -182,6 +191,87 @@ function numberSource(value, loc) {
182
191
  }
183
192
  return { kind: 'number', value, loc };
184
193
  }
194
+ /**
195
+ * A read of a value worked out at boot. One boot cannot work out is taken at the build's panel instead, which
196
+ * the panel at boot must then give too.
197
+ *
198
+ * @param value The value.
199
+ * @param loc Where it is read.
200
+ *
201
+ * @returns Its source.
202
+ */
203
+ function bootSource(value, loc) {
204
+ const slot = bootSlotOf(value);
205
+ if (slot) {
206
+ return { kind: 'fixed', expr: { kind: 'boot', slot, type: slot.type }, loc };
207
+ }
208
+ const buildValue = foldBoot(value);
209
+ if (typeof buildValue === 'number')
210
+ return numberSource(buildValue, loc);
211
+ if (typeof buildValue === 'string') {
212
+ return { kind: 'string', value: buildValue, loc };
213
+ }
214
+ if (typeof buildValue === 'boolean') {
215
+ return { kind: 'boolean', value: buildValue, loc };
216
+ }
217
+ throw new Error('AOT: a value derived from the panel size cannot be used in a dynamic expression');
218
+ }
219
+ /**
220
+ * Whether an expression names a binding that is, or holds, a value worked out at boot.
221
+ *
222
+ * @param node The expression.
223
+ * @param scope The constants it reads.
224
+ *
225
+ * @returns True when it does.
226
+ */
227
+ function readsBootName(node, scope) {
228
+ if (typeof node !== 'object' || node === null)
229
+ return false;
230
+ if (Array.isArray(node))
231
+ return node.some(item => readsBootName(item, scope));
232
+ const typed = node;
233
+ if (typed.type === 'Identifier') {
234
+ return typed.name in scope && containsBoot(scope[typed.name]);
235
+ }
236
+ // A member's name and an object key are not reads.
237
+ if (typed.type === 'MemberExpression') {
238
+ return (readsBootName(typed.object, scope) ||
239
+ (typed.computed && readsBootName(typed.property, scope)));
240
+ }
241
+ if (typed.type === 'ObjectProperty' && !typed.computed) {
242
+ return readsBootName(typed.value, scope);
243
+ }
244
+ return Object.entries(typed).some(([key, value]) => key !== 'loc' && readsBootName(value, scope));
245
+ }
246
+ /**
247
+ * An expression that depends only on the panel, read as a whole from its boot slot, so it is worked out once and
248
+ * in double precision. Null for one that also reads state, or that boot cannot work out.
249
+ *
250
+ * @param node The expression.
251
+ * @param env The expression environment.
252
+ * @param loc Where it is.
253
+ *
254
+ * @returns Its source, or null.
255
+ */
256
+ function wholeBootSource(node, env, loc) {
257
+ const scope = foldScope(env, env.consts ?? {});
258
+ if (!readsBootName(node, scope))
259
+ return null;
260
+ let value;
261
+ try {
262
+ value = evalStatic(node, scope, 'boot');
263
+ }
264
+ catch {
265
+ return null;
266
+ }
267
+ if (!isBoot(value) || !value.lowerable)
268
+ return null;
269
+ const whole = wholeBootValue(node, scope, value);
270
+ const slot = whole && bootSlotOf(whole);
271
+ return slot
272
+ ? { kind: 'fixed', expr: { kind: 'boot', slot, type: slot.type }, loc }
273
+ : null;
274
+ }
185
275
  /**
186
276
  * A compile-time string.
187
277
  *
@@ -1024,6 +1114,12 @@ const binarySource = (node, left, right, env) => ({
1024
1114
  */
1025
1115
  function sourceOf(node, env) {
1026
1116
  const loc = node.loc?.start;
1117
+ // An expression that depends only on the panel is read from a slot worked out at boot, in doubles as JS.
1118
+ const whole = WHOLE_BOOT_TYPES.has(node.type)
1119
+ ? wholeBootSource(node, env, loc)
1120
+ : null;
1121
+ if (whole)
1122
+ return whole;
1027
1123
  const operand = (operandNode) => lowerSource(operandNode, env).source;
1028
1124
  switch (node.type) {
1029
1125
  case 'NumericLiteral':
@@ -1046,6 +1142,8 @@ function sourceOf(node, env) {
1046
1142
  }
1047
1143
  if (node.name in env.consts) {
1048
1144
  const constValue = env.consts[node.name];
1145
+ if (isBoot(constValue))
1146
+ return bootSource(constValue, loc);
1049
1147
  if (typeof constValue === 'number')
1050
1148
  return numberSource(constValue, loc);
1051
1149
  if (typeof constValue === 'string') {
@@ -1110,7 +1208,9 @@ function sourceOf(node, env) {
1110
1208
  case 'MemberExpression': {
1111
1209
  // Static fold: member access that resolves to a compile-time constant (e.g., a .map item's `.key`).
1112
1210
  try {
1113
- const constValue = evalStatic(node, foldScope(env, env.consts ?? {}));
1211
+ const constValue = evalStatic(node, foldScope(env, env.consts ?? {}), 'boot');
1212
+ if (isBoot(constValue))
1213
+ return bootSource(constValue, loc);
1114
1214
  // A number with no float form falls through too, so its check runs now, not in the check pass.
1115
1215
  if (typeof constValue === 'number') {
1116
1216
  return attemptLowering(() => numberSource(constValue, loc));
@@ -1387,9 +1487,9 @@ function lowerTextParts(node, env, scope, isOperand = false) {
1387
1487
  parts: [{ kind: 'literal', text: isOperand ? 'undefined' : '' }],
1388
1488
  };
1389
1489
  }
1390
- // A compile-time constant becomes literal text.
1490
+ // A compile-time constant becomes literal text; a value worked out at boot is a runtime value.
1391
1491
  try {
1392
- const constValue = evalStatic(node, scope);
1492
+ const constValue = evalStatic(node, scope, 'strict');
1393
1493
  return {
1394
1494
  isString: typeof constValue === 'string',
1395
1495
  parts: [
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -13,20 +13,44 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { isBootOnlyNode, isBootOnlyVector } from './reads.mjs';
16
20
  /*----------------------------------------------------------------------------------------------------------------------
17
21
  - Implementation
18
22
  ---------------------------------------------------------------------------------------------------------------------*/
19
23
  /**
20
- * Whether state drives any of a node's props, text or image, so it keeps a handle and app_update() sets its
21
- * props again.
24
+ * Whether any of a node's props, text, or image is a runtime value rather than a constant.
22
25
  *
23
26
  * @param node The node.
24
27
  *
25
- * @returns True when state drives it.
28
+ * @returns True when one is.
26
29
  */
27
- export const isStateDriven = (node) => (node.text?.parts.some(part => part.kind !== 'literal') ?? false) ||
30
+ export const hasRuntimeProps = (node) => (node.text?.parts.some(part => part.kind !== 'literal') ?? false) ||
28
31
  node.stateProps.length > 0 ||
29
32
  node.image?.kind === 'value';
33
+ /**
34
+ * Whether state drives any of a node's props, text or image, so it keeps a handle and app_update() sets its
35
+ * props again. Props that read-only values worked out at boot are set once, by er_app_build().
36
+ *
37
+ * @param node The node.
38
+ *
39
+ * @returns True when state drives it.
40
+ */
41
+ export const isStateDriven = (node) => hasRuntimeProps(node) && !isBootOnlyNode(node);
42
+ /**
43
+ * The drawing state drives on a node if it has one: a drawing that reads only values worked out at boot is
44
+ * built once, by er_app_build().
45
+ *
46
+ * @param node The node.
47
+ *
48
+ * @returns The drawing, or null.
49
+ */
50
+ export function updatedVectorOf(node) {
51
+ const vector = stateDrivenVectorOf(node);
52
+ return vector && !isBootOnlyVector(vector) ? vector : null;
53
+ }
30
54
  /**
31
55
  * The drawing state drives on a node, if it has one.
32
56
  *