@orangecharts/wrun-chart-host 0.19.0 → 0.20.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.
Files changed (55) hide show
  1. package/README.md +2 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/settings-templates/frvp-fields.js +9 -3
  5. package/dist/settings-templates/index.d.ts +36 -3
  6. package/dist/settings-templates/index.js +111 -27
  7. package/dist/settings-templates/indicator-fields.d.ts +11 -0
  8. package/dist/settings-templates/indicator-fields.js +5 -4
  9. package/dist/settings-templates/market-bound.d.ts +93 -19
  10. package/dist/settings-templates/market-bound.js +235 -30
  11. package/dist/settings-templates/tool-rules.d.ts +197 -18
  12. package/dist/settings-templates/tool-rules.js +98 -4
  13. package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
  14. package/dist/settings-templates/tool-tables.generated.js +194 -11
  15. package/dist/utility/chart/calendar-interval.util.d.ts +7 -0
  16. package/dist/utility/chart/calendar-interval.util.js +9 -0
  17. package/dist/utility/chart/index-mode.util.d.ts +11 -0
  18. package/dist/utility/chart/index-mode.util.js +24 -0
  19. package/dist/utility/chart/indicator-run-interval.util.d.ts +7 -3
  20. package/dist/utility/chart/indicator-run-interval.util.js +16 -5
  21. package/dist/utility/chart/market-session-schedule.util.d.ts +2 -0
  22. package/dist/utility/chart/market-session-schedule.util.js +2 -0
  23. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +16 -1
  24. package/dist/utility/chart/run-interval-warmup.leaf.js +28 -2
  25. package/dist/utility/options/option-contract-market.leaf.d.ts +2 -0
  26. package/dist/utility/options/option-contract-market.leaf.js +21 -0
  27. package/dist/utility/options/option-trade-units.util.d.ts +35 -5
  28. package/dist/utility/options/option-trade-units.util.js +31 -5
  29. package/dist/utility/wrun/wrun-chart-market-facts.util.js +3 -3
  30. package/dist/utility/wrun/wrun-color-settings.util.d.ts +2 -13
  31. package/dist/utility/wrun/wrun-color-settings.util.js +3 -29
  32. package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +1 -1
  33. package/dist/utility/wrun/wrun-lane-warmup.util.js +8 -3
  34. package/dist/utility/wrun/wrun-live-intake.util.js +13 -6
  35. package/dist/utility/wrun/wrun-live-tick.util.js +35 -18
  36. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +34 -1
  37. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +57 -0
  38. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +76 -13
  39. package/dist/utility/wrun/wrun-market-size-defaults.util.js +286 -45
  40. package/dist/utility/wrun/wrun-market-size-rank.leaf.d.ts +75 -0
  41. package/dist/utility/wrun/wrun-market-size-rank.leaf.js +154 -0
  42. package/dist/utility/wrun/wrun-overlay-run.util.js +124 -21
  43. package/dist/utility/wrun/wrun-param-values.util.d.ts +2 -1
  44. package/dist/utility/wrun/wrun-param-values.util.js +3 -9
  45. package/dist/utility/wrun/wrun-row-scalars.leaf.d.ts +30 -0
  46. package/dist/utility/wrun/wrun-row-scalars.leaf.js +73 -0
  47. package/dist/utility/wrun/wrun-run-health.util.d.ts +24 -2
  48. package/dist/utility/wrun/wrun-run-health.util.js +39 -7
  49. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +18 -0
  50. package/dist/utility/wrun/wrun-run-interval-session.util.js +25 -0
  51. package/dist/utility/wrun/wrun-run-interval.util.d.ts +52 -5
  52. package/dist/utility/wrun/wrun-run-interval.util.js +88 -7
  53. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +4 -7
  54. package/dist/utility/wrun/wrun-script-inputs.util.js +6 -33
  55. package/package.json +1 -1
@@ -20,10 +20,19 @@
20
20
  * meets a market: keep (OWN), swap for that market's remembered or default values (FOREIGN), or trust and stamp
21
21
  * (UNKEYED). A heatmap row keeps its own path (settleHeatmapScale on web): reconcileMarketBound leaves it alone.
22
22
  *
23
- * This file imports only the registry, holds no state and never mutates an input. Every input is read defensively: a
24
- * stored document can hold anything.
23
+ * A script row (wave 3) is bound by its package: the params of `WRUN_MARKET_SCALED_PARAMS` sized in coins or contracts
24
+ * (`wrunMarketBoundParamsOf`, by rule kind alone) are its units, each a `row` (a declared `scriptInputs` row: its value
25
+ * flat under its name, with that row's `defaultValue` and `carriedValue`, parked and given back together) or a `flat`
26
+ * value an older pin left with no row. A row unit reads as typed by the run head's own test
27
+ * (`wrunMarketScaledRowChanged`), so the run head's moves of an untouched default never break a stamp.
28
+ *
29
+ * This file imports the registry and three light leaves (the market size leaf, the row scalars under it, the overlay
30
+ * identity), never the script inputs module or the host env; it holds no state and never mutates an input. Every
31
+ * input is read defensively: a stored document can hold anything.
25
32
  */
26
33
  import { HEATMAP_SCALE_TYPES, INDICATOR_COMMON_FIELDS, INDICATOR_TYPE_FIELDS, SCRIPT_INDICATOR_TYPE, } from './indicator-fields.js';
34
+ import { isWrunMarketScaledRow, wrunMarketBoundParamsOf, wrunMarketScaledParamsOf, wrunMarketScaledRowChanged, } from '../utility/wrun/wrun-market-size-defaults.leaf.js';
35
+ import { wrunRegistryRefOf } from '../utility/wrun/wrun-overlay-identity.util.js';
27
36
  /** A capital M after the count is a month ('1M', '3M'); a lower-case m is a minute. */
28
37
  const MONTH_INTERVAL = /^\d+M$/;
29
38
  /** An interval id as a key spells it before upper-casing: a month ('1M') as '1MO', so it never meets the minute. */
@@ -132,32 +141,42 @@ function clonePlain(value) {
132
141
  return value;
133
142
  }
134
143
  const isStashEntry = (entry) => isPlainRecord(entry) && typeof entry.key === 'string' && entry.key !== '' && isPlainRecord(entry.values);
144
+ /** A copy of one entry: its key, its values and, when it holds a record of them, its row companions. */
145
+ function copyEntry(key, values, rows) {
146
+ const entry = {
147
+ key,
148
+ values: clonePlain(isPlainRecord(values) ? values : {}),
149
+ };
150
+ if (isPlainRecord(rows) && Object.keys(rows).length)
151
+ entry.rows = clonePlain(rows);
152
+ return entry;
153
+ }
135
154
  /** The well-formed entries of a stored list, copied; anything else in the list (or a list that is none) is dropped. */
136
155
  function readStash(list) {
137
156
  if (!Array.isArray(list))
138
157
  return [];
139
- return list
140
- .filter(isStashEntry)
141
- .map((entry) => ({ key: entry.key, values: clonePlain(entry.values) }));
158
+ return list.filter(isStashEntry).map((entry) => copyEntry(entry.key, entry.values, entry.rows));
142
159
  }
143
160
  /**
144
161
  * A new stash list: any entry for `key` removed, the new entry appended last, and the oldest entries dropped past
145
162
  * BOUND_STASH_CAP. Malformed entries of the given list are dropped. Never mutates its inputs.
146
163
  */
147
- export function stashBound(list, key, values) {
164
+ export function stashBound(list, key, values, rows) {
148
165
  const kept = readStash(list).filter((entry) => entry.key !== key);
149
- kept.push({ key, values: clonePlain(isPlainRecord(values) ? values : {}) });
166
+ kept.push(copyEntry(key, values, rows));
150
167
  return kept.length > BOUND_STASH_CAP ? kept.slice(kept.length - BOUND_STASH_CAP) : kept;
151
168
  }
152
169
  /**
153
- * The stashed values for `key` (null when none) and a new list without that entry. Tolerates a malformed list (gives
154
- * null and []) and drops malformed entries. Never mutates its input.
170
+ * The stashed values for `key` (null when none), their row companions (only when the entry holds some) and a new list
171
+ * without that entry. Tolerates a malformed list (gives null and []) and drops malformed entries. Never mutates its
172
+ * input.
155
173
  */
156
174
  export function takeBound(list, key) {
157
175
  const entries = readStash(list);
158
176
  const found = entries.find((entry) => entry.key === key);
159
177
  return {
160
178
  values: found ? found.values : null,
179
+ ...(found?.rows ? { rows: found.rows } : {}),
161
180
  list: entries.filter((entry) => entry.key !== key),
162
181
  };
163
182
  }
@@ -190,14 +209,54 @@ function declaredFieldsOf(type) {
190
209
  return fields;
191
210
  }
192
211
  const UNITS = new Map();
212
+ /** The `scriptInputs` row a script bag declares under `name`. */
213
+ function scriptRowOf(settings, name) {
214
+ const rows = Array.isArray(settings.scriptInputs) ? settings.scriptInputs : [];
215
+ return rows.find((row) => isPlainRecord(row) && row.name === name);
216
+ }
217
+ const isPositiveNumber = (value) => typeof value === 'number' && Number.isFinite(value) && value > 0;
218
+ /** The package a script row runs (its registry identity, the run's own lookup), or undefined. */
219
+ const scriptPackageOf = (settings) => wrunRegistryRefOf(settings)?.package;
220
+ /** A script unit of `name`, frozen. */
221
+ const scriptUnit = (name, input) => Object.freeze({ key: name, keys: Object.freeze([name]), keep: 'typed', input });
222
+ /**
223
+ * A script row's units: one per bound param of its package (`wrunMarketBoundParamsOf`) the row holds, a `row` unit
224
+ * where its `scriptInputs` declare the param in a kind that holds a market default (`isWrunMarketScaledRow`), a `flat`
225
+ * unit where no row declares it and a finite positive value sits flat on the record. `extra` names params counted as
226
+ * flat units even with no value (a stash that holds one for them).
227
+ */
228
+ function scriptUnitsOf(settings, extra) {
229
+ if (!isPlainRecord(settings))
230
+ return [];
231
+ const packageName = scriptPackageOf(settings);
232
+ const rules = wrunMarketScaledParamsOf(packageName);
233
+ if (!rules)
234
+ return [];
235
+ const units = [];
236
+ for (const name of wrunMarketBoundParamsOf(packageName)) {
237
+ const row = scriptRowOf(settings, name);
238
+ if (row) {
239
+ if (isWrunMarketScaledRow(row, rules[name]))
240
+ units.push(scriptUnit(name, 'row'));
241
+ }
242
+ else if (isPositiveNumber(ownValue(settings, name)) || extra?.has(name)) {
243
+ units.push(scriptUnit(name, 'flat'));
244
+ }
245
+ }
246
+ return units;
247
+ }
193
248
  /**
194
249
  * The reconciled units of a type, in the registry's declared order: every settings-bag field with `quantity: 'bound'`
195
250
  * and a `keep`, with its `with` companions (a companion is never a unit of its own). None for a heatmap type (its own
196
- * path), a technical script (its inputs are the script's) or a type without such a field. Frozen and cached.
251
+ * path) or a type without such a field. A technical script's units are its package's coin and contract sizes the row
252
+ * holds (scriptUnitsOf), read off `settings`; without `settings` a script has none. A native type's are frozen and
253
+ * cached, and never read `settings`.
197
254
  */
198
- export function boundFieldsOf(type) {
199
- if (typeof type !== 'string' || isHeatmapScaleType(type) || isScriptType(type))
255
+ export function boundFieldsOf(type, settings) {
256
+ if (typeof type !== 'string' || isHeatmapScaleType(type))
200
257
  return [];
258
+ if (isScriptType(type))
259
+ return settings === undefined ? [] : Object.freeze(scriptUnitsOf(settings));
201
260
  let units = UNITS.get(type);
202
261
  if (!units) {
203
262
  const fields = declaredFieldsOf(type);
@@ -212,6 +271,8 @@ export function boundFieldsOf(type) {
212
271
  const unit = { key: path, keys: Object.freeze([path, ...(field.with ?? [])]), keep: field.keep };
213
272
  if (field.boundWhen)
214
273
  unit.boundWhen = field.boundWhen;
274
+ if (field.ownDefault)
275
+ unit.ownDefault = field.ownDefault;
215
276
  list.push(Object.freeze(unit));
216
277
  }
217
278
  units = Object.freeze(list);
@@ -233,28 +294,72 @@ export function isBoundNow(condition, settings) {
233
294
  }
234
295
  /** The units of a type that are bound right now on this bag (each unit's `boundWhen` read off the bag). */
235
296
  export function boundUnitsNow(type, settings) {
236
- return boundFieldsOf(type).filter((unit) => isBoundNow(unit.boundWhen, settings));
297
+ return boundFieldsOf(type, settings).filter((unit) => isBoundNow(unit.boundWhen, settings));
237
298
  }
238
299
  const ownValue = (settings, key) => Object.hasOwn(settings, key) ? settings[key] : undefined;
300
+ /** A value as a signature reads it (undefined as null), for an equality of plain JSON values. */
301
+ const asJson = (value) => JSON.stringify(value === undefined ? null : value);
302
+ /** Whether each key of a unit holds the value `source` names for it (no value where `source` names none). */
303
+ function holdsValuesOf(unit, settings, source) {
304
+ return unit.keys.every((key) => {
305
+ const expected = source && Object.hasOwn(source, key) ? source[key] : undefined;
306
+ return asJson(ownValue(settings, key)) === asJson(expected);
307
+ });
308
+ }
309
+ /** The defaults table that names a unit's field, or null. */
310
+ const namingUnit = (unit, table) => isPlainRecord(table) && Object.hasOwn(table, unit.key) ? table : null;
311
+ /** isTypedUnit with the reconcile's own `defaults` as the last fallback of a native unit. */
312
+ function typedUnit(unit, settings, ownDefaults, defaults) {
313
+ if (unit.keep !== 'typed')
314
+ return false;
315
+ if (unit.input === 'row') {
316
+ const row = scriptRowOf(settings, unit.key);
317
+ return !!row && wrunMarketScaledRowChanged(settings, row);
318
+ }
319
+ if (unit.input === 'flat')
320
+ return isPositiveNumber(ownValue(settings, unit.key));
321
+ if (unit.ownDefault && ownValue(settings, unit.ownDefault) !== undefined) {
322
+ return asJson(ownValue(settings, unit.key)) !== asJson(ownValue(settings, unit.ownDefault));
323
+ }
324
+ return !holdsValuesOf(unit, settings, namingUnit(unit, ownDefaults) ?? namingUnit(unit, defaults));
325
+ }
326
+ /**
327
+ * Whether a unit holds a value the user typed on the market the row was on (the one test a reconcile parks by and a
328
+ * script signature signs by). A script `row` unit: the run head's own test (`wrunMarketScaledRowChanged`: off its
329
+ * row's default, or at its carried mark). A `flat` unit: a finite positive value. A native unit: off its own default,
330
+ * read from the row's companion (`ownDefault`) first, else `ownDefaults` (the leaving market's defaults, by field
331
+ * key), else no value at all. A measured unit is never typed.
332
+ */
333
+ export function isTypedUnit(unit, settings, ownDefaults) {
334
+ return typedUnit(unit, isPlainRecord(settings) ? settings : {}, ownDefaults ?? null, null);
335
+ }
239
336
  /**
240
337
  * The signature of a threshold row: boundSignature over the values of the type's typed units that are bound right now,
241
- * each unit's keys in order, the units in the registry's declared order, a missing value as null. A non-record bag reads
242
- * as empty.
338
+ * each unit's keys in order, the units in the registry's declared order, a missing value as null. A script unit signs
339
+ * its value while it reads typed (isTypedUnit) and null while it does not, so the run head moving an untouched value
340
+ * and its default together leaves the stamp valid. A non-record bag reads as empty.
243
341
  */
244
342
  export function marketBoundSignature(type, settings) {
245
343
  const bag = isPlainRecord(settings) ? settings : {};
246
344
  const values = boundUnitsNow(type, bag)
247
345
  .filter((unit) => unit.keep === 'typed')
248
- .flatMap((unit) => unit.keys.map((key) => ownValue(bag, key)));
346
+ .flatMap((unit) => {
347
+ if (unit.input === undefined)
348
+ return unit.keys.map((key) => ownValue(bag, key));
349
+ return [typedUnit(unit, bag, null, null) ? ownValue(bag, unit.key) : null];
350
+ });
249
351
  return boundSignature(values);
250
352
  }
251
353
  /**
252
354
  * The row after a user's edit of its bound values (they were just typed on the live market): `boundKey` stamped with
253
355
  * `liveKey` and the row's signature. The same object when the stamp is already that one, and for a type with no
254
- * reconciled unit or a bag that is no record.
356
+ * reconciled unit on this bag or a bag that is no record.
255
357
  */
256
358
  export function stampMarketBound(type, settings, liveKey) {
257
- if (!isPlainRecord(settings) || !boundFieldsOf(type).length || typeof liveKey !== 'string' || liveKey === '') {
359
+ if (!isPlainRecord(settings) ||
360
+ !boundFieldsOf(type, settings).length ||
361
+ typeof liveKey !== 'string' ||
362
+ liveKey === '') {
258
363
  return settings;
259
364
  }
260
365
  const stamp = stampBoundKey(liveKey, marketBoundSignature(type, settings));
@@ -262,23 +367,65 @@ export function stampMarketBound(type, settings, liveKey) {
262
367
  return settings;
263
368
  return { ...settings, boundKey: stamp };
264
369
  }
370
+ /**
371
+ * Whether a row holds anything a reconcile judges. A native row: a value of a reconciled field, a stamp or a stash (a
372
+ * row that holds none, a workspace row its control fills at its init, has nothing typed on any market). A script row:
373
+ * a stamp, a stash or a typed unit (an untouched row follows the run head's market defaults and needs no stamp).
374
+ */
375
+ export function holdsBoundState(type, settings) {
376
+ if (!isPlainRecord(settings))
377
+ return false;
378
+ if (settings.boundKey !== undefined || settings.boundByMarket !== undefined)
379
+ return true;
380
+ const units = boundFieldsOf(type, settings);
381
+ if (typeof type === 'string' && isScriptType(type))
382
+ return units.some((unit) => typedUnit(unit, settings, null, null));
383
+ return units.some((unit) => unit.keys.some((key) => settings[key] !== undefined));
384
+ }
385
+ /** A script row's `scriptInputs` with each named row's companions replaced (a `carriedValue` of undefined removed). */
386
+ function withRows(settings, changes) {
387
+ const rows = Array.isArray(settings.scriptInputs) ? settings.scriptInputs : [];
388
+ return rows.map((row) => {
389
+ if (!isPlainRecord(row) || typeof row.name !== 'string' || !changes.has(row.name))
390
+ return row;
391
+ const change = changes.get(row.name);
392
+ const { carriedValue: _carried, ...rest } = row;
393
+ const next = { ...rest };
394
+ if (change.defaultValue !== undefined)
395
+ next.defaultValue = clonePlain(change.defaultValue);
396
+ if (typeof change.carriedValue === 'number')
397
+ next.carriedValue = change.carriedValue;
398
+ return next;
399
+ });
400
+ }
265
401
  /**
266
402
  * The one decision a reader makes when a threshold row meets the live market `liveKey` (contract section 6). Pure:
267
403
  * reads its inputs defensively and never mutates them.
268
404
  * - OWN (the stamp parses, its signature matches, its key is `liveKey`): unchanged, the same object.
269
- * - FOREIGN (the stamp parses and signs, another key): the typed units bound right now are kept under the stamp's key
270
- * in `boundByMarket` (measured ones are dropped); each unit takes the live market's remembered values out of the
271
- * stash, else `options.defaults`, else is removed; the row is stamped with `liveKey`. A group is one unit.
405
+ * - FOREIGN (the stamp parses and signs, another key): the typed units bound right now (isTypedUnit) are kept under the
406
+ * stamp's key in `boundByMarket`; a measured unit and an untouched one are not (with none kept, an older entry for
407
+ * the stamp's key goes). Each unit then takes the live market's remembered values out of the stash; else a native
408
+ * unit takes `options.defaults` or is removed, a script `row` unit that was typed takes its row's current default as
409
+ * its value and loses its carried mark (the run head then moves value and default to this market's), and a `flat`
410
+ * unit is written as null. A script row unit's row companions (`defaultValue`, `carriedValue`) are kept and given
411
+ * back with its value, `scriptInputs` written whole. The row is stamped with `liveKey`. A group is one unit.
272
412
  * - UNKEYED (no stamp, a malformed one, or a signature that does not match): the values are trusted on this market and
273
413
  * stamped with `liveKey`; with `options.unkeyedAs` the row is first read as stamped with that key (OWN or FOREIGN).
274
- * A field not bound right now (its unit is notional) is never kept, reset or signed. A heatmap type, a script, a type
275
- * without a reconciled unit and a row with no unit bound right now come back untouched (`none`).
414
+ * A field not bound right now (its unit is notional) is never kept, reset or signed. A heatmap type, a type without a
415
+ * reconciled unit and a row with no unit bound right now (and, for a script, no flat value remembered for `liveKey`)
416
+ * come back untouched (`none`).
276
417
  */
277
418
  export function reconcileMarketBound(type, settings, liveKey, options) {
278
419
  const result = (next, verdict, rowKey, restored = false, stashed = false) => ({ settings: next, verdict, rowKey, liveKey, restored, stashed });
279
420
  if (!isPlainRecord(settings) || typeof liveKey !== 'string' || liveKey === '')
280
421
  return result(settings, 'none', null);
281
- const units = boundUnitsNow(type, settings);
422
+ const taken = takeBound(settings.boundByMarket, liveKey);
423
+ const remembered = taken.values;
424
+ // A script's flat value the live market remembers is a unit here even once nulled: its return gives it back.
425
+ const script = typeof type === 'string' && isScriptType(type);
426
+ const units = script
427
+ ? scriptUnitsOf(settings, new Set(Object.keys(remembered ?? {})))
428
+ : boundUnitsNow(type, settings);
282
429
  if (!units.length)
283
430
  return result(settings, 'none', null);
284
431
  const signature = marketBoundSignature(type, settings);
@@ -293,25 +440,62 @@ export function reconcileMarketBound(type, settings, liveKey, options) {
293
440
  }
294
441
  // FOREIGN: the values belong to `rowKey`.
295
442
  const next = { ...settings };
443
+ const defaults = isPlainRecord(options?.defaults) ? options.defaults : null;
444
+ const ownDefaults = isPlainRecord(options?.ownDefaults) ? options.ownDefaults : null;
445
+ // Only a typed unit is kept: a default needs no memory, and a stash entry of defaults would push a typed value out
446
+ // of the capped list.
296
447
  const typed = {};
448
+ const typedRows = {};
449
+ const wasTyped = new Set();
297
450
  for (const unit of units) {
298
- if (unit.keep !== 'typed')
451
+ if (!typedUnit(unit, settings, ownDefaults, defaults))
299
452
  continue;
453
+ wasTyped.add(unit.key);
300
454
  for (const key of unit.keys) {
301
455
  const value = ownValue(settings, key);
302
456
  if (value !== undefined)
303
457
  typed[key] = value;
304
458
  }
459
+ const row = unit.input === 'row' ? scriptRowOf(settings, unit.key) : undefined;
460
+ if (row) {
461
+ const companions = {};
462
+ if (row.defaultValue !== undefined)
463
+ companions.defaultValue = row.defaultValue;
464
+ if (typeof row.carriedValue === 'number')
465
+ companions.carriedValue = row.carriedValue;
466
+ typedRows[unit.key] = companions;
467
+ }
305
468
  }
306
- const taken = takeBound(settings.boundByMarket, liveKey);
307
469
  const stashed = Object.keys(typed).length > 0;
308
- const list = stashed ? stashBound(taken.list, rowKey, typed) : taken.list;
309
- const remembered = taken.values;
310
- const defaults = isPlainRecord(options?.defaults) ? options.defaults : null;
470
+ // With nothing typed, an older entry for `rowKey` goes too: on a return the defaults are what it held.
471
+ const list = stashed
472
+ ? stashBound(taken.list, rowKey, typed, typedRows)
473
+ : taken.list.filter((entry) => entry.key !== rowKey);
474
+ const rowChanges = new Map();
311
475
  let restored = false;
312
476
  for (const unit of units) {
477
+ const fromStash = unit.keep === 'typed' && !!remembered && unit.keys.some((key) => Object.hasOwn(remembered, key));
478
+ if (unit.input !== undefined) {
479
+ if (fromStash && remembered) {
480
+ restored = true;
481
+ next[unit.key] = clonePlain(remembered[unit.key]);
482
+ if (unit.input === 'row')
483
+ rowChanges.set(unit.key, { ...(taken.rows?.[unit.key] ?? {}) });
484
+ }
485
+ else if (wasTyped.has(unit.key)) {
486
+ if (unit.input === 'flat') {
487
+ next[unit.key] = null;
488
+ }
489
+ else {
490
+ const row = scriptRowOf(settings, unit.key);
491
+ next[unit.key] = clonePlain(row?.defaultValue);
492
+ rowChanges.set(unit.key, { defaultValue: row?.defaultValue });
493
+ }
494
+ }
495
+ continue;
496
+ }
313
497
  let source = null;
314
- if (unit.keep === 'typed' && remembered && unit.keys.some((key) => Object.hasOwn(remembered, key))) {
498
+ if (fromStash) {
315
499
  source = remembered;
316
500
  restored = true;
317
501
  }
@@ -325,6 +509,8 @@ export function reconcileMarketBound(type, settings, liveKey, options) {
325
509
  delete next[key];
326
510
  }
327
511
  }
512
+ if (rowChanges.size)
513
+ next.scriptInputs = withRows(settings, rowChanges);
328
514
  if (list.length)
329
515
  next.boundByMarket = list;
330
516
  else
@@ -332,6 +518,25 @@ export function reconcileMarketBound(type, settings, liveKey, options) {
332
518
  next.boundKey = stampBoundKey(liveKey, marketBoundSignature(type, next));
333
519
  return result(next, 'key-mismatch', rowKey, restored, stashed);
334
520
  }
521
+ /**
522
+ * Whether a saved bag's typed values (a template, a saved default, a layout's row) are written onto the live market,
523
+ * and the key to write back into the save when it is trusted once:
524
+ * - the saved key equals the live key: written, nothing to adopt;
525
+ * - a saved key that differs (or no live key to meet it): not written;
526
+ * - no saved key, the person's own save, and its `exchange|symbol` market is the live one: written once, and the live
527
+ * key is adopted (the host writes it into the save, so the next use is judged by key);
528
+ * - no saved key otherwise (another person's content, another market, or no live key): not written.
529
+ */
530
+ export function savedBoundVerdict(a) {
531
+ const named = (value) => (typeof value === 'string' && value !== '' ? value : null);
532
+ const savedKey = named(a?.savedKey);
533
+ const liveKey = named(a?.liveKey);
534
+ if (savedKey)
535
+ return { write: savedKey === liveKey, adopt: null };
536
+ const savedMarket = named(a?.savedMarket);
537
+ const own = a?.origin === 'own' && !!liveKey && !!savedMarket && savedMarket === named(a?.liveMarket);
538
+ return own ? { write: true, adopt: liveKey } : { write: false, adopt: null };
539
+ }
335
540
  /** Whether a value is a number, or a list or record that holds one at any depth (a container of numbers). */
336
541
  function holdsNumber(value, depth = 0) {
337
542
  if (typeof value === 'number')
@@ -1,20 +1,3 @@
1
- /**
2
- * The drawing template rules (TEMPLATES-PLAN decision 1 and A9): what a drawing type's template and Save as default
3
- * keep beyond its registry style. scripts/generate-tool-tables.mjs reads this file at package build (it transpiles it
4
- * on its own, so it imports nothing) and writes tool-tables.generated.ts from it and chart-schema TOOLS:
5
- *
6
- * - TOOL_DEFAULT_STYLE[type]: the registry defaultStyle, then the held extras below with their declared defaults;
7
- * - TOOL_TEMPLATE_KEYS[type]: those keys, then the text of a type whose text is a label (the text rule, textRoleOf),
8
- * then `visibleIntervalsMs` unless the type is interval-bound, never an instance key (the type's own too,
9
- * `instanceKeysByType`) or a cached compute key (`settingsKeysToStrip`).
10
- *
11
- * The text rule is the hosts' too: a host's text box reads it through toolTextRole (settings-templates/index.ts), so
12
- * the box and the template tables give every type one answer.
13
- *
14
- * A rule changes here, then the generator runs (the package build does), and both commit together:
15
- * tests/packages/wrun-chart-host/settings-templates/tool-tables.generated.spec.ts regenerates the tables and fails
16
- * when they differ from the committed file.
17
- */
18
1
  export declare const TOOL_TEMPLATE_RULES: {
19
2
  /**
20
3
  * Per-drawing state a template never carries and never writes: lock, hide, layer and name are the drawing's own
@@ -58,7 +41,7 @@ export declare const TOOL_TEMPLATE_RULES: {
58
41
  readonly key: "text";
59
42
  readonly heldBy: "fontSize";
60
43
  readonly content: readonly ["Text", "AnchoredText", "Note", "AnchoredNote", "Callout", "Comment"];
61
- readonly ignored: readonly ["PriceLabel"];
44
+ readonly ignored: readonly ["PriceLabel", "FibonacciRetracement", "FibonacciTrend", "FibChannel", "FibCircles", "FibSpeedResistanceArcs", "FibSpeedResistanceFan", "FibTimeZone", "FibTrendTime", "FibWedge", "GannBox", "GannFan", "GannSquare", "GannSquareFixed"];
62
45
  };
63
46
  /**
64
47
  * Drawings whose legs or captured bars read wrong on another interval (a GhostFeed's legs, a Bar Pattern's bars, a
@@ -89,12 +72,196 @@ export declare const TOOL_TEMPLATE_RULES: {
89
72
  readonly CrossLine: {
90
73
  readonly highlight: true;
91
74
  };
75
+ readonly LongPosition: {
76
+ readonly backgroundOpacity: 19;
77
+ };
78
+ readonly ShortPosition: {
79
+ readonly backgroundOpacity: 19;
80
+ };
81
+ readonly RegressionTrend: {
82
+ readonly backgroundOpacity: 20;
83
+ };
84
+ readonly PriceRange: {
85
+ readonly backgroundOpacity: 15;
86
+ };
87
+ readonly DatePriceRange: {
88
+ readonly backgroundOpacity: 15;
89
+ };
90
+ readonly DateRange: {
91
+ readonly backgroundOpacity: 15;
92
+ };
93
+ readonly Signpost: {
94
+ readonly backgroundOpacity: 15;
95
+ };
96
+ readonly Callout: {
97
+ readonly backgroundOpacity: 50;
98
+ };
92
99
  readonly FibonacciRetracement: {
100
+ readonly fontSize: 11;
101
+ readonly fontWeight: 400;
102
+ readonly levelsInk: "text";
103
+ readonly levelsColor: "#787B86";
93
104
  readonly levelsOnLogScale: false;
94
105
  };
95
106
  readonly FibonacciTrend: {
107
+ readonly fontSize: 11;
108
+ readonly fontWeight: 400;
109
+ readonly levelsInk: "text";
110
+ readonly levelsColor: "#787B86";
96
111
  readonly levelsOnLogScale: false;
97
112
  };
113
+ readonly FibChannel: {
114
+ readonly fontSize: 11;
115
+ readonly fontWeight: 400;
116
+ readonly levelsInk: "text";
117
+ readonly levelsColor: "#787B86";
118
+ };
119
+ readonly FibCircles: {
120
+ readonly fontSize: 11;
121
+ readonly fontWeight: 400;
122
+ readonly levelsInk: "text";
123
+ readonly levelsColor: "#787B86";
124
+ };
125
+ readonly FibSpeedResistanceArcs: {
126
+ readonly fontSize: 11;
127
+ readonly fontWeight: 400;
128
+ readonly levelsInk: "text";
129
+ readonly levelsColor: "#787B86";
130
+ };
131
+ readonly FibSpeedResistanceFan: {
132
+ readonly fontSize: 11;
133
+ readonly fontWeight: 400;
134
+ readonly levelsInk: "text";
135
+ readonly levelsColor: "#787B86";
136
+ };
137
+ readonly FibSpiral: {
138
+ readonly levelsInk: "text";
139
+ readonly levelsColor: "#787B86";
140
+ };
141
+ readonly FibTimeZone: {
142
+ readonly fontSize: 11;
143
+ readonly fontWeight: 400;
144
+ readonly levelsInk: "text";
145
+ readonly levelsColor: "#787B86";
146
+ };
147
+ readonly FibTrendTime: {
148
+ readonly fontSize: 11;
149
+ readonly fontWeight: 400;
150
+ readonly levelsInk: "text";
151
+ readonly levelsColor: "#787B86";
152
+ };
153
+ readonly FibWedge: {
154
+ readonly fontSize: 11;
155
+ readonly fontWeight: 400;
156
+ readonly levelsInk: "text";
157
+ readonly levelsColor: "#787B86";
158
+ };
159
+ readonly GannBox: {
160
+ readonly fontSize: 11;
161
+ readonly fontWeight: 400;
162
+ readonly levelsInk: "text";
163
+ readonly levelsColor: "#787B86";
164
+ };
165
+ readonly GannFan: {
166
+ readonly fontSize: 11;
167
+ readonly fontWeight: 400;
168
+ readonly levelsInk: "text";
169
+ readonly levelsColor: "#787B86";
170
+ };
171
+ readonly GannSquare: {
172
+ readonly fontSize: 11;
173
+ readonly fontWeight: 400;
174
+ readonly levelsInk: "text";
175
+ readonly levelsColor: "#787B86";
176
+ };
177
+ readonly GannSquareFixed: {
178
+ readonly fontSize: 11;
179
+ readonly fontWeight: 400;
180
+ readonly levelsInk: "text";
181
+ readonly levelsColor: "#787B86";
182
+ };
183
+ readonly Pitchfork: {
184
+ readonly levelsInk: "text";
185
+ readonly levelsColor: "#787B86";
186
+ };
187
+ readonly SchiffPitchfork: {
188
+ readonly levelsInk: "text";
189
+ readonly levelsColor: "#787B86";
190
+ };
191
+ readonly ModSchiffPitchfork: {
192
+ readonly levelsInk: "text";
193
+ readonly levelsColor: "#787B86";
194
+ };
195
+ readonly InsidePitchfork: {
196
+ readonly levelsInk: "text";
197
+ readonly levelsColor: "#787B86";
198
+ };
199
+ readonly Pitchfan: {
200
+ readonly levelsInk: "text";
201
+ readonly levelsColor: "#787B86";
202
+ };
203
+ };
204
+ /**
205
+ * The values a NEW drawing starts at where they differ from the registry defaultStyle (TOOL_START_STYLE, generated):
206
+ * the fib, Gann and pitchfork family's quieter look (a 4% wash, a dotted diagonal), seeded by titan's tool classes
207
+ * from the same release as LEVELS_LOOK. The registry keeps its defaults (a drawing saved without a key restores at
208
+ * them), so a changed default of a key the registry lists rides here, never in the held extras (the generator refuses
209
+ * a held extra the registry lists). The generator refuses a key the type's style does not hold and a value equal to
210
+ * it. Web's arm and Reset read TOOL_START_STYLE, and so does the phone.
211
+ */
212
+ readonly startOverrides: {
213
+ readonly FibonacciRetracement: {
214
+ readonly backgroundOpacity: 4;
215
+ readonly trendLineLineStyle: "dotted";
216
+ };
217
+ readonly FibonacciTrend: {
218
+ readonly backgroundOpacity: 4;
219
+ readonly trendLineLineStyle: "dotted";
220
+ };
221
+ readonly FibChannel: {
222
+ readonly backgroundOpacity: 4;
223
+ };
224
+ readonly FibCircles: {
225
+ readonly backgroundOpacity: 4;
226
+ };
227
+ readonly FibSpeedResistanceArcs: {
228
+ readonly backgroundOpacity: 4;
229
+ };
230
+ readonly FibSpeedResistanceFan: {
231
+ readonly backgroundOpacity: 4;
232
+ };
233
+ readonly FibTimeZone: {
234
+ readonly backgroundOpacity: 4;
235
+ readonly trendLineLineStyle: "dotted";
236
+ };
237
+ readonly FibTrendTime: {
238
+ readonly backgroundOpacity: 4;
239
+ readonly trendLineLineStyle: "dotted";
240
+ };
241
+ readonly FibWedge: {
242
+ readonly backgroundOpacity: 4;
243
+ };
244
+ readonly GannBox: {
245
+ readonly backgroundOpacity: 4;
246
+ };
247
+ readonly GannFan: {
248
+ readonly backgroundOpacity: 4;
249
+ };
250
+ readonly Pitchfork: {
251
+ readonly backgroundOpacity: 4;
252
+ };
253
+ readonly SchiffPitchfork: {
254
+ readonly backgroundOpacity: 4;
255
+ };
256
+ readonly ModSchiffPitchfork: {
257
+ readonly backgroundOpacity: 4;
258
+ };
259
+ readonly InsidePitchfork: {
260
+ readonly backgroundOpacity: 4;
261
+ };
262
+ readonly Pitchfan: {
263
+ readonly backgroundOpacity: 4;
264
+ };
98
265
  };
99
266
  /**
100
267
  * Style keys Save as default never keeps, and so neither does web's style memory (src/store/tool-style-memory.ts
@@ -111,6 +278,18 @@ export declare const TOOL_TEMPLATE_RULES: {
111
278
  */
112
279
  readonly defaultExcludedTypes: readonly ["Image"];
113
280
  };
281
+ /**
282
+ * A number field's range on one drawing type, where the type's own look reaches past the range chart-schema's
283
+ * TOOL_FIELD_SPECS gives the key on every type: the bound named here replaces that bound on this type only, in every
284
+ * host (web and phone read it through toolFieldRange, settings-templates/index.ts). A Highlighter starts at width 14
285
+ * (chart-schema TOOLS) while every type's Width stops at 12, so its first step up made the stroke thinner; a marker
286
+ * stroke takes a thick width, so it goes to 40. The schema's own per-type field table (beside TOOL_FIELD_GATES) is
287
+ * this rule's home once it has one; then this table goes.
288
+ */
289
+ export declare const TOOL_FIELD_RANGES: Readonly<Record<string, Readonly<Record<string, {
290
+ min?: number;
291
+ max?: number;
292
+ }>>>>;
114
293
  /** What a drawing type's free text is, by the text rule: its label, its content, or a text its engine never draws. */
115
294
  export type ToolTextRole = 'label' | 'content' | 'ignored';
116
295
  /**