@moku-labs/game 0.15.55 → 0.15.57

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.
@@ -5839,10 +5839,27 @@ function wrongBlocked(step, payload) {
5839
5839
  return /* @__PURE__ */ new Error(`[game] The guide of node "${step.path}" blocks with "${blocked.intent}", which is no outcome of the node.\n Add it to outcomes or drop blocked.`);
5840
5840
  }
5841
5841
  /**
5842
+ * Hands a result to the `guide` handler with a signal of its own. A handler that fails is logged,
5843
+ * `flow:guide-handler-failed`; one that fails after the node's abort was told to stop.
5844
+ *
5845
+ * @param ctx - Domain context of the flow plugin.
5846
+ * @param modules - Injected sibling APIs.
5847
+ * @param step - The node run in progress.
5848
+ * @param payload - The result as the descriptor's payload.
5849
+ */
5850
+ function runGuide(ctx, modules, step, payload) {
5851
+ modules.fx.run({
5852
+ kind: "guide",
5853
+ payload
5854
+ }, step.signal).catch((error) => {
5855
+ if (step.signal.aborted) return;
5856
+ ctx.log.error("flow:guide-handler-failed", { path: step.path }, asError$4(error));
5857
+ });
5858
+ }
5859
+ /**
5842
5860
  * Shows a new result of the guide: the guide shown so far ends with its narrow, the gate is
5843
5861
  * narrowed to `allow` and `blocked`, and the `guide` handler gets the payload with a signal of its
5844
- * own. A result equal to the last one changes nothing; `undefined` only lifts. A handler that fails
5845
- * is logged, `flow:guide-handler-failed`; one that fails after the node's abort was told to stop.
5862
+ * own. A result equal to the last one changes nothing; `undefined` only lifts.
5846
5863
  *
5847
5864
  * @param ctx - Domain context of the flow plugin.
5848
5865
  * @param modules - Injected sibling APIs.
@@ -5860,13 +5877,7 @@ function show$1(ctx, modules, step, guide, payload) {
5860
5877
  return;
5861
5878
  }
5862
5879
  modules.gate.narrow(guideAnswer(payload, "allow"), guideAnswer(payload, "blocked"));
5863
- modules.fx.run({
5864
- kind: "guide",
5865
- payload
5866
- }, step.signal).catch((error) => {
5867
- if (step.signal.aborted) return;
5868
- ctx.log.error("flow:guide-handler-failed", { path: step.path }, asError$4(error));
5869
- });
5880
+ runGuide(ctx, modules, step, payload);
5870
5881
  }
5871
5882
  /**
5872
5883
  * Derives the guide from the committed state and shows a new result.
@@ -5897,7 +5908,8 @@ function derive(ctx, modules, step, guide) {
5897
5908
  * Enters the guide of a node: derives it from the committed state and keeps it in the runner state,
5898
5909
  * so a commit while the node waits at its gate derives it again. Called after the node's `onEnter`
5899
5910
  * stages and before its outcome is awaited. A node without `guide`, and one already aborted, change
5900
- * nothing. A `guide` that throws again after a commit fails the node through `step.fail`.
5911
+ * nothing. A `guide` that throws again after a commit fails the node through `step.fail`. `reshow`
5912
+ * hands the last result to the handler again, once the mode is live after a fast walk.
5901
5913
  *
5902
5914
  * @param ctx - Domain context of the flow plugin.
5903
5915
  * @param modules - Injected sibling APIs.
@@ -5908,13 +5920,20 @@ function enterGuide(ctx, modules, step) {
5908
5920
  if (step.node.guide === void 0 || step.signal.aborted) return void 0;
5909
5921
  const guide = {
5910
5922
  last: void 0,
5911
- refresh: noop
5923
+ refresh: noop,
5924
+ reshow: noop
5912
5925
  };
5913
5926
  guide.refresh = () => {
5914
5927
  if (step.signal.aborted || ctx.state.runner.guide !== guide) return;
5915
5928
  const failed = derive(ctx, modules, step, guide);
5916
5929
  if (failed !== void 0) step.fail(failed);
5917
5930
  };
5931
+ guide.reshow = () => {
5932
+ const last = guide.last;
5933
+ if (step.signal.aborted || ctx.state.runner.guide !== guide || last === void 0) return;
5934
+ modules.fx.endGuides();
5935
+ runGuide(ctx, modules, step, last);
5936
+ };
5918
5937
  ctx.state.runner.guide = guide;
5919
5938
  return derive(ctx, modules, step, guide);
5920
5939
  }
@@ -6811,7 +6830,7 @@ async function playRoute(ctx, modules, route, running) {
6811
6830
  * after the switch, so it never starts live and never shows its popup. The mode of the caller
6812
6831
  * is put back afterwards, also when the bookmark is refused or a step rejects, and a
6813
6832
  * substitution the route never reached is disarmed: it must not skip a sub-flow in the live play
6814
- * that follows.
6833
+ * that follows. Back in live mode, the guide of the node the walk ends at is shown.
6815
6834
  *
6816
6835
  * @param ctx - Domain context of the flow plugin.
6817
6836
  * @param modules - Injected sibling APIs: features, fx, gate, inbox.
@@ -6835,6 +6854,7 @@ async function walkRoute(ctx, modules, route, start) {
6835
6854
  } finally {
6836
6855
  loopSeam(ctx.state.runner).substitutions.clear();
6837
6856
  modules.fx.setMode(previous);
6857
+ if (previous === "live") ctx.state.runner.guide?.reshow();
6838
6858
  }
6839
6859
  return readState(ctx);
6840
6860
  }
@@ -7020,7 +7040,9 @@ function createRunnerApi(ctx, modules) {
7020
7040
  history: () => [...state.journal],
7021
7041
  setMode: (mode) => {
7022
7042
  if (state.running !== void 0 && !resting(ctx)) throw new Error("[game] flow.setMode() was called while a transit node runs.\n Call it before run() or while the graph rests.");
7043
+ const previous = ctx.state.fx.mode;
7023
7044
  modules.fx.setMode(mode);
7045
+ if (previous === "fast" && mode === "live") state.guide?.reshow();
7024
7046
  }
7025
7047
  };
7026
7048
  }
@@ -7165,7 +7187,7 @@ function refreshGuide(ctx, payload) {
7165
7187
  * @param ctx - Kernel context of the flow plugin.
7166
7188
  * @returns The two hooks of the plugin.
7167
7189
  */
7168
- function createHandlers$7(ctx) {
7190
+ function createHandlers$8(ctx) {
7169
7191
  return {
7170
7192
  /**
7171
7193
  * Reacts to a change of the pause stack.
@@ -7395,7 +7417,7 @@ const flowPlugin = /*#__PURE__*/ createPlugin$1("flow", {
7395
7417
  }),
7396
7418
  createState: createFlowState,
7397
7419
  api: createFlowApi,
7398
- hooks: createHandlers$7,
7420
+ hooks: createHandlers$8,
7399
7421
  onInit: connectFlow,
7400
7422
  onStop: ({ config, state }) => stopRunner({
7401
7423
  config,
@@ -8863,7 +8885,7 @@ var QueryWalk = class {
8863
8885
  if (entity === void 0 || value === void 0) continue;
8864
8886
  if (!carriesAll(state.stores, names, entity)) continue;
8865
8887
  markWritten(state, written, entity);
8866
- this.value = rowOf$1(state.stores, names, entity, value);
8888
+ this.value = rowOf$2(state.stores, names, entity, value);
8867
8889
  return this;
8868
8890
  }
8869
8891
  return this.end();
@@ -8990,7 +9012,7 @@ function carriesAll(stores, names, entity) {
8990
9012
  * @param value - Its stored value of the first term.
8991
9013
  * @returns The row: the entity, then one stored value per name.
8992
9014
  */
8993
- function rowOf$1(stores, names, entity, value) {
9015
+ function rowOf$2(stores, names, entity, value) {
8994
9016
  switch (names.length) {
8995
9017
  case 1: return [entity, value];
8996
9018
  case 2: return [
@@ -9581,7 +9603,7 @@ function startTiming(state, clock) {
9581
9603
  * @param name - The system's name.
9582
9604
  * @returns Its row; 0 for a name the table never saw, which cannot happen for a registered system.
9583
9605
  */
9584
- function rowOf(state, name) {
9606
+ function rowOf$1(state, name) {
9585
9607
  return state.timingSlots.get(name) ?? 0;
9586
9608
  }
9587
9609
  /**
@@ -9794,7 +9816,7 @@ function runTimed(ctx, timing, entries, context, phase, time) {
9794
9816
  const entry = entries[index];
9795
9817
  if (entry === void 0 || entry.frame >= time.frame) continue;
9796
9818
  if (!wakes(state, entry, context)) continue;
9797
- const row = rowOf(state, entry.definition.name);
9819
+ const row = rowOf$1(state, entry.definition.name);
9798
9820
  const started = timing.clock();
9799
9821
  guardedRun(ctx, entry, context, phase);
9800
9822
  timing.ms[row] = (timing.ms[row] ?? 0) + timing.clock() - started;
@@ -10129,7 +10151,8 @@ function connectWorld(ctx) {
10129
10151
  /**
10130
10152
  * Empties the world in `onStop`: the frame callbacks and the hint listener are removed, then
10131
10153
  * every track, view, queued view, entity and resource is dropped, a running scene build and the
10132
- * `onBuild` checks with them, every warm record, and the scenes and the frame history are reset.
10154
+ * `onBuild` checks with them, every warm record, every held name and owed `show`, every value fed, and the scenes
10155
+ * and the frame history are reset.
10133
10156
  * No `onRemoved` fires, because `renderer` stopped earlier and destroyed its own objects.
10134
10157
  *
10135
10158
  * @param state - The plugin state, the only thing a teardown context carries.
@@ -10162,6 +10185,10 @@ function clearWorld(state) {
10162
10185
  state.projection.warmHeld.clear();
10163
10186
  delete state.projection.warmActive;
10164
10187
  state.projection.warmStale = false;
10188
+ state.projection.held.clear();
10189
+ state.projection.showing.length = 0;
10190
+ state.projection.fed.clear();
10191
+ state.projection.heldFed.clear();
10165
10192
  state.ecs.generations.length = 0;
10166
10193
  state.ecs.free.length = 0;
10167
10194
  state.ecs.owners.clear();
@@ -11740,14 +11767,16 @@ function isSeen(seen, snapshot) {
11740
11767
  return seen !== void 0 && seen.player === snapshot.player && seen.session === snapshot.session;
11741
11768
  }
11742
11769
  /**
11743
- * Gives a mounted projection that declares `warm` its record, cold, at the end of the warm list. A projection that
11744
- * has one keeps it: a projection a scene before mounted and the coming one keeps (F23) keeps its held view.
11770
+ * Gives a mounted projection that declares `warm`, or is held, its record, cold, at the end of the warm list. A
11771
+ * projection that has one keeps it: a projection a scene before mounted and the coming one keeps (F23) keeps its held
11772
+ * view.
11745
11773
  *
11746
11774
  * @param state - The projection branch of the plugin state.
11747
11775
  * @param spec - The projection spec.
11748
11776
  */
11749
11777
  function ensureWarm(state, spec) {
11750
- if (spec.warm === void 0 || state.warm.has(spec.name)) return;
11778
+ if (state.warm.has(spec.name)) return;
11779
+ if (spec.warm === void 0 && !state.held.has(spec.name)) return;
11751
11780
  const record = {
11752
11781
  name: spec.name,
11753
11782
  entities: /* @__PURE__ */ new Set(),
@@ -11859,7 +11888,8 @@ function forgetWarm(pctx, name) {
11859
11888
  state.warmList.splice(state.warmList.indexOf(record), 1);
11860
11889
  }
11861
11890
  /**
11862
- * Drops every held view and forgets every record: the clear of the projections.
11891
+ * Drops every held view and forgets every record, every held name, every owed `show` and every value fed: the clear of
11892
+ * the projections.
11863
11893
  *
11864
11894
  * @param pctx - Domain context of the projection module.
11865
11895
  */
@@ -11869,6 +11899,10 @@ function clearWarm(pctx) {
11869
11899
  state.warm.clear();
11870
11900
  state.warmList.length = 0;
11871
11901
  state.warmHeld.clear();
11902
+ state.held.clear();
11903
+ state.showing.length = 0;
11904
+ state.fed.clear();
11905
+ state.heldFed.clear();
11872
11906
  delete state.warmActive;
11873
11907
  state.warmStale = false;
11874
11908
  }
@@ -11955,7 +11989,7 @@ function frameBudget(state) {
11955
11989
  * @param record - The record that holds the view.
11956
11990
  * @param cause - `"mount"` for a direct reconcile, `"change"` for a live one.
11957
11991
  */
11958
- function showHeld(pctx, mounted, record, cause) {
11992
+ function showHeld$1(pctx, mounted, record, cause) {
11959
11993
  const state = pctx.ctx.state.projection;
11960
11994
  const view = record.view;
11961
11995
  for (const entity of record.entities) state.warmHeld.delete(entity);
@@ -12041,17 +12075,31 @@ function pollActive(state, active) {
12041
12075
  delete state.warmActive;
12042
12076
  }
12043
12077
  /**
12044
- * Reads the warm item of a projection and its key. A `warm` or a `key` that throws is logged as a projection that
12045
- * failed, and nothing is warm.
12078
+ * The first item `from` gives: the first of a list, or the one object of a screen.
12079
+ *
12080
+ * @param spec - The projection spec.
12081
+ * @param snapshot - The state now.
12082
+ * @param sw - The switch `from` reads.
12083
+ * @returns The item, or `undefined` for an empty list.
12084
+ */
12085
+ function firstItem(spec, snapshot, sw) {
12086
+ const source = spec.from(snapshot.player, snapshot.session, sw);
12087
+ return Array.isArray(source) ? source[0] : source;
12088
+ }
12089
+ /**
12090
+ * Reads the item a record holds and its key: `from`'s first item while the projection is held, read with the value the
12091
+ * first feed after `hold` stored (else the one fed before), so a later feed never makes it differ; else the item
12092
+ * `warm` gives. A `warm`, a `from` or a `key` that throws is logged as a projection that failed, and nothing is held.
12046
12093
  *
12047
12094
  * @param pctx - Domain context of the projection module.
12048
- * @param spec - The projection spec, which declares `warm`.
12095
+ * @param spec - The projection spec, which declares `warm` or is held.
12049
12096
  * @param snapshot - The state now.
12050
12097
  * @returns The item and its key, or `undefined` for no item and for a throw.
12051
12098
  */
12052
12099
  function readWarm(pctx, spec, snapshot) {
12100
+ const state = pctx.ctx.state.projection;
12053
12101
  try {
12054
- const item = spec.warm?.(snapshot.player, snapshot.session);
12102
+ const item = state.held.has(spec.name) ? firstItem(spec, snapshot, state.heldFed.get(spec.name) ?? state.fed.get(spec.name)) : spec.warm?.(snapshot.player, snapshot.session);
12055
12103
  if (item === void 0 || item === null) return void 0;
12056
12104
  return {
12057
12105
  item,
@@ -12153,8 +12201,8 @@ function refreshWarm(pctx, spec, record, warm) {
12153
12201
  }
12154
12202
  /**
12155
12203
  * One record's turn in the warm step: a record shown, in work, or read against this state is passed over. Otherwise
12156
- * `warm` is read: with no item, or with a key `from` shows, what is held is dropped; a cold record spawns its held
12157
- * view, a ready one is brought up to date.
12204
+ * its item is read (`warm`, or `from`'s first while held): with no item, or with a key `from` shows, what is held is
12205
+ * dropped; a cold record spawns its held view, a ready one is brought up to date.
12158
12206
  *
12159
12207
  * @param pctx - Domain context of the projection module.
12160
12208
  * @param record - The record.
@@ -12369,7 +12417,7 @@ function enterEntry(pctx, spec, mounted, entry) {
12369
12417
  function adoptEntry(pctx, spec, mounted, record, entry) {
12370
12418
  const view = record.view;
12371
12419
  const next = sameItem(record.item, entry.item) ? void 0 : collectView(pctx, spec, entry.item);
12372
- showHeld(pctx, mounted, record, entry.direct ? "mount" : "change");
12420
+ showHeld$1(pctx, mounted, record, entry.direct ? "mount" : "change");
12373
12421
  if (next === void 0) view.item = entry.item;
12374
12422
  else writeDifference(pctx, view, next, entry.item);
12375
12423
  playEnter$1(pctx, spec, view, entry);
@@ -12587,7 +12635,9 @@ function exitGone(pctx, spec, mounted, next, entry, counts) {
12587
12635
  }
12588
12636
  }
12589
12637
  /**
12590
- * Reads the keyed items of one projection. A throw from `from` or `key` is reported and the
12638
+ * Reads the keyed items of one projection, `from` reading the value last fed to it (`undefined`
12639
+ * for one never fed). A held projection (`hold`) shows none: `from` is not read, and the warm step
12640
+ * keeps its first item built and hidden. A throw from `from` or `key` is reported and the
12591
12641
  * projection is skipped for this reconcile.
12592
12642
  *
12593
12643
  * @param pctx - Domain context of the projection module.
@@ -12597,8 +12647,10 @@ function exitGone(pctx, spec, mounted, next, entry, counts) {
12597
12647
  */
12598
12648
  function keyedItems(pctx, spec, snapshot) {
12599
12649
  const next = /* @__PURE__ */ new Map();
12650
+ const state = pctx.ctx.state.projection;
12651
+ if (state.held.has(spec.name)) return next;
12600
12652
  try {
12601
- const source = spec.from(snapshot.player, snapshot.session);
12653
+ const source = spec.from(snapshot.player, snapshot.session, state.fed.get(spec.name));
12602
12654
  if (!Array.isArray(source)) {
12603
12655
  if (source !== void 0 && source !== null) next.set(spec.key?.(source) ?? spec.name, source);
12604
12656
  return next;
@@ -12927,8 +12979,9 @@ function drawsAlike(before, after, spec) {
12927
12979
  }
12928
12980
  /**
12929
12981
  * Unmounts projections: every motion of their views is finished, and the live views and the
12930
- * despawn queue are despawned in the same call, and so is the view a warm window holds hidden.
12931
- * An unknown or unmounted name is skipped.
12982
+ * despawn queue are despawned in the same call, and so is the view a warm window or a hold keeps
12983
+ * hidden. A held name is held no more. The value fed to a name stays: a `hold` or a `mount` that places it again
12984
+ * reads it, and the public `unmount` forgets it. An unknown or unmounted name is skipped.
12932
12985
  *
12933
12986
  * @param pctx - Domain context of the projection module.
12934
12987
  * @param names - Names of the projections to unmount.
@@ -12940,6 +12993,8 @@ function unmountNames(pctx, names) {
12940
12993
  if (mounted === void 0) continue;
12941
12994
  clearMounted(pctx, mounted);
12942
12995
  forgetWarm(pctx, name);
12996
+ state.held.delete(name);
12997
+ state.heldFed.delete(name);
12943
12998
  state.mounted.delete(name);
12944
12999
  }
12945
13000
  }
@@ -12998,7 +13053,8 @@ function mountNames(pctx, names, owner) {
12998
13053
  * Gives every projection of a list its place under the current layer list: a missing one gets an
12999
13054
  * empty record at the `Order` of its place, a kept one mounted under another list takes its new
13000
13055
  * place (`placeMounted`), its held warm view too. A screen root draws at its place in the list
13001
- * (spec 16 U1.6). A projection that declares `warm` gets its warm record, cold, unless it has one.
13056
+ * (spec 16 U1.6). A projection that declares `warm` or is held gets its warm record, cold, unless
13057
+ * it has one.
13002
13058
  *
13003
13059
  * @param pctx - Domain context of the projection module.
13004
13060
  * @param names - The projection list of the scene.
@@ -13173,6 +13229,106 @@ function discardBuild(pctx) {
13173
13229
  handBack(pctx, building);
13174
13230
  }
13175
13231
  //#endregion
13232
+ //#region src/plugins/world/projection/hold.ts
13233
+ /**
13234
+ * Mounts projections held: the checks of a mount first, so a throw holds nothing; then every name joins the held set
13235
+ * before its record is made and before the reconcile, which shows none of its items. A record a projection had
13236
+ * already (its `warm`) reads its item again, from `from` now, with the value the first `feed` after this hold stores,
13237
+ * else the one fed before. Every name of the list is reconciled at once, direct: a kept one that showed views drops
13238
+ * them.
13239
+ *
13240
+ * @param pctx - Domain context of the projection module.
13241
+ * @param names - Names of the projections to hold.
13242
+ * @param owner - Who owns the entities of the new ones.
13243
+ * @throws {Error} For an unknown name, or a `layer` or `lift` the scene does not declare.
13244
+ */
13245
+ function holdNames(pctx, names, owner) {
13246
+ const state = pctx.ctx.state.projection;
13247
+ const { again } = sortMount(pctx, names, state.layers);
13248
+ unmountNames(pctx, again);
13249
+ for (const name of names) {
13250
+ state.held.add(name);
13251
+ state.heldFed.delete(name);
13252
+ delete state.warm.get(name)?.seen;
13253
+ }
13254
+ state.warmStale = true;
13255
+ placeNames(pctx, names, owner);
13256
+ reconcileFresh(pctx, names);
13257
+ }
13258
+ /**
13259
+ * Releases a held projection: it is held no more, its `from` and its record are read again, the next reconcile
13260
+ * reconciles it by name, and its `from` reads the latest value fed. A name that is not held changes nothing.
13261
+ *
13262
+ * @param pctx - Domain context of the projection module.
13263
+ * @param name - The projection.
13264
+ */
13265
+ function showName(pctx, name) {
13266
+ const state = pctx.ctx.state.projection;
13267
+ if (!state.held.delete(name)) return;
13268
+ state.heldFed.delete(name);
13269
+ delete state.mounted.get(name)?.seen;
13270
+ delete state.warm.get(name)?.seen;
13271
+ state.warmStale = true;
13272
+ state.showing.push(name);
13273
+ }
13274
+ /**
13275
+ * Tells whether two switches are equal field by field. Pure.
13276
+ *
13277
+ * @param before - The switch stored.
13278
+ * @param after - The switch fed.
13279
+ * @returns True when `from`, `to` and `progress` are the same.
13280
+ * @example
13281
+ * ```ts
13282
+ * sameSwitch({ from: "ward", to: "board", progress: 0.5 }, { from: "ward", to: "board", progress: 0.5 }); // true
13283
+ * ```
13284
+ */
13285
+ function sameSwitch(before, after) {
13286
+ return before.from === after.from && before.to === after.to && before.progress === after.progress;
13287
+ }
13288
+ /**
13289
+ * Hands a projection the switch its `from` reads. An equal value changes nothing and allocates nothing. Another one is
13290
+ * stored; then a held name keeps the value its warm step reads (the first feed after `hold` sets it, so a later commit
13291
+ * re-reads the held item with it and a feed never rebuilds the held view), a mounted shown name is read again by name
13292
+ * in the next reconcile (its `seen` dropped, its name on `showing` once), and a name not mounted is only stored.
13293
+ *
13294
+ * @param pctx - Domain context of the projection module.
13295
+ * @param name - The projection.
13296
+ * @param sw - The switch.
13297
+ */
13298
+ function feedName(pctx, name, sw) {
13299
+ const state = pctx.ctx.state.projection;
13300
+ const stored = state.fed.get(name);
13301
+ const held = state.held.has(name);
13302
+ if (held && !state.heldFed.has(name)) state.heldFed.set(name, sw);
13303
+ if (stored !== void 0 && sameSwitch(stored, sw)) return;
13304
+ state.fed.set(name, sw);
13305
+ if (held) return;
13306
+ const mounted = state.mounted.get(name);
13307
+ if (mounted === void 0) return;
13308
+ delete mounted.seen;
13309
+ if (!state.showing.includes(name)) state.showing.push(name);
13310
+ }
13311
+ /**
13312
+ * Reconciles the projections `show` released and the shown ones `feed` changed since the last reconcile, by name: a
13313
+ * running scene build would pass over a mounted projection its list does not name. A live world plays the enter of the
13314
+ * view it shows; a world that is not live shows it direct. Nothing runs while none was released.
13315
+ *
13316
+ * @param pctx - Domain context of the projection module.
13317
+ */
13318
+ function reconcileShown(pctx) {
13319
+ const state = pctx.ctx.state.projection;
13320
+ const names = state.showing;
13321
+ if (names.length === 0) return;
13322
+ state.showing = [];
13323
+ reconcile(pctx, {
13324
+ names,
13325
+ direct: pctx.deps.ecs.mode() !== "live",
13326
+ force: false,
13327
+ converge: false,
13328
+ settle: false
13329
+ });
13330
+ }
13331
+ //#endregion
13176
13332
  //#region src/plugins/world/projection/api.ts
13177
13333
  /**
13178
13334
  * Tells whether a cause sets the picture instead of playing it.
@@ -13278,6 +13434,7 @@ function createProjectionApi(ctx, deps) {
13278
13434
  * and whether an unchanged view that stands off its rest pose is settled (a rollback does).
13279
13435
  * A restore, a load and a forced rerun drop the views warm windows hold hidden first: they
13280
13436
  * replace the state or run `view` anew. After a reconcile the warm step looks at its records.
13437
+ * Then the projections `show` released are reconciled by name.
13281
13438
  */
13282
13439
  const reconcileIfDirty = () => {
13283
13440
  const dirty = state.dirty;
@@ -13295,6 +13452,7 @@ function createProjectionApi(ctx, deps) {
13295
13452
  });
13296
13453
  if (state.warmList.length > 0) state.warmStale = true;
13297
13454
  }
13455
+ reconcileShown(pctx);
13298
13456
  state.hints.length = 0;
13299
13457
  };
13300
13458
  /**
@@ -13326,7 +13484,7 @@ function createProjectionApi(ctx, deps) {
13326
13484
  state.specs.set(spec.name, spec);
13327
13485
  reseedViews(state, spec.name, from, seed);
13328
13486
  if (!mounted) return;
13329
- if (spec.warm === void 0) forgetWarm(pctx, spec.name);
13487
+ if (spec.warm === void 0 && !state.held.has(spec.name)) forgetWarm(pctx, spec.name);
13330
13488
  else ensureWarm(state, spec);
13331
13489
  forceRerun();
13332
13490
  },
@@ -13339,6 +13497,16 @@ function createProjectionApi(ctx, deps) {
13339
13497
  },
13340
13498
  unmount: (names) => {
13341
13499
  unmountNames(pctx, names);
13500
+ for (const name of names) state.fed.delete(name);
13501
+ },
13502
+ hold: (names, owner) => {
13503
+ holdNames(pctx, names, owner);
13504
+ },
13505
+ show: (name) => {
13506
+ showName(pctx, name);
13507
+ },
13508
+ feed: (name, sw) => {
13509
+ feedName(pctx, name, sw);
13342
13510
  },
13343
13511
  restOf: (entity, component) => {
13344
13512
  const stored = (state.byEntity.get(entity)?.rest ?? state.rests.get(entity))?.get(component.componentName);
@@ -13637,6 +13805,9 @@ function exposeProjection(projection) {
13637
13805
  layers: projection.layers,
13638
13806
  mount: projection.mount,
13639
13807
  unmount: projection.unmount,
13808
+ hold: projection.hold,
13809
+ show: projection.show,
13810
+ feed: projection.feed,
13640
13811
  settle: projection.settle,
13641
13812
  mute: projection.mute,
13642
13813
  lift: projection.lift,
@@ -13698,7 +13869,7 @@ function createWorldApi(ctx) {
13698
13869
  * @param ctx - Kernel context of the world plugin.
13699
13870
  * @returns The one hook of the plugin.
13700
13871
  */
13701
- function createHandlers$6(ctx) {
13872
+ function createHandlers$7(ctx) {
13702
13873
  let modules;
13703
13874
  return {
13704
13875
  /**
@@ -13814,7 +13985,8 @@ function emptySet$8() {
13814
13985
  * Creates the initial projection state: nothing registered, nothing mounted, no layer list, no
13815
13986
  * running track and no driver, so every motion is instant until `anim` installs one. No build
13816
13987
  * runs: `building` is absent. No warm window is held, and none is being built: `warmActive` is
13817
- * absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate.
13988
+ * absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate. No
13989
+ * projection is held, no `show` is owed, and nothing was fed.
13818
13990
  *
13819
13991
  * @returns The projection branch of the plugin state.
13820
13992
  */
@@ -13848,7 +14020,11 @@ function createProjectionState() {
13848
14020
  warmList: [],
13849
14021
  warmHeld: emptySet$8(),
13850
14022
  warmStale: false,
13851
- warmBudgetMs: FALLBACK_WARM_MS
14023
+ warmBudgetMs: FALLBACK_WARM_MS,
14024
+ held: emptySet$8(),
14025
+ showing: [],
14026
+ fed: emptyMap$9(),
14027
+ heldFed: emptyMap$9()
13852
14028
  };
13853
14029
  }
13854
14030
  //#endregion
@@ -13897,7 +14073,7 @@ const worldPlugin = /*#__PURE__*/ createPlugin$1("world", {
13897
14073
  events: (register) => register.map({ "world:reconciled": "A reconcile finished (dev only)" }),
13898
14074
  createState: createWorldState,
13899
14075
  api: createWorldApi,
13900
- hooks: createHandlers$6,
14076
+ hooks: createHandlers$7,
13901
14077
  onStart: connectWorld,
13902
14078
  onStop: ({ state }) => clearWorld(state)
13903
14079
  });
@@ -27288,7 +27464,8 @@ function syncLayers(sctx) {
27288
27464
  /**
27289
27465
  * Detaches the containers of the layers that are no longer declared and names the views that stay in them. The views
27290
27466
  * that went with the scene are gone already (the pass drops the removed ones first), and a view that plays its exit
27291
- * (`Exiting`, a root that leaves with a motion) goes with it: neither is named.
27467
+ * (`Exiting`, a root that leaves with a motion) goes with it: neither is named. A layer the loader of a scene being
27468
+ * left holds above the veil stays there: it fades out with the veil after the swap, and its views go with the loader.
27292
27469
  *
27293
27470
  * @param sctx - Domain context of the sync module.
27294
27471
  * @param next - The new table of layers.
@@ -27296,9 +27473,11 @@ function syncLayers(sctx) {
27296
27473
  function dropLeftLayers(sctx, next) {
27297
27474
  const state = sctx.ctx.state.sync;
27298
27475
  const ecs = sctx.ctx.deps.world.ecs;
27476
+ const held = state.leave.objects?.held;
27299
27477
  const stranded = [];
27300
27478
  for (const [name, entry] of state.layers) {
27301
27479
  if (next.has(name)) continue;
27480
+ if (held !== void 0 && entry.container?.parent === held) continue;
27302
27481
  if (entry.container !== void 0) detach$1(entry.container);
27303
27482
  for (const [entity, view] of state.views) if (view.layer === name && !isLeaving(ecs, entity)) stranded.push(entity);
27304
27483
  }
@@ -28048,27 +28227,95 @@ function loaderOf$1(sctx, look) {
28048
28227
  return { loader: "ring" };
28049
28228
  }
28050
28229
  /**
28051
- * Puts a layer the look drew above the veil back under the root, at the place of its layer: the layer list of the
28052
- * scene orders the root's children. A layer the list of a swap took back already, or let go, is left alone.
28230
+ * Puts a layer the look drew above the veil back under the root at alpha 1, at the place of its layer in the layer
28231
+ * list as it stands now: the list orders the root's children. A layer that list does not declare is let go. One that
28232
+ * no longer hangs above the veil (a layer list took it back, its application was lost) is left where it is.
28053
28233
  *
28054
28234
  * @param sctx - Domain context of the sync module.
28055
- * @param run - The look whose layer goes back.
28235
+ * @param container - The layer's container.
28236
+ * @param name - The layer.
28056
28237
  */
28057
- function unlift(sctx, run) {
28058
- const lifted = run.lifted;
28059
- if (lifted === void 0) return;
28060
- delete run.lifted;
28238
+ function putBack(sctx, container, name) {
28061
28239
  const state = sctx.ctx.state.sync;
28062
- if (lifted.parent !== state.leave.objects?.held) return;
28063
- const name = run.layer;
28240
+ container.alpha = 1;
28241
+ if (container.parent !== state.leave.objects?.held) return;
28064
28242
  const at = state.layerList?.findIndex((spec) => spec.name === name) ?? -1;
28065
28243
  const root = state.root;
28066
28244
  state.passesVersion += 1;
28067
28245
  if (root === void 0 || at === -1) {
28068
- detach$1(lifted);
28246
+ detach$1(container);
28069
28247
  return;
28070
28248
  }
28071
- root.addChildAt(lifted, Math.min(at, root.children.length));
28249
+ root.addChildAt(container, Math.min(at, root.children.length));
28250
+ }
28251
+ /**
28252
+ * The frames a loader layer waits at most after the veil's fade-out of `outMs`: `scenes` unmounts the loader once the
28253
+ * frame deltas it counts reach `outMs`, and `time` caps a delta at its `maxDeltaMs` (50 by default), so after a run of
28254
+ * long frames it counts at least 50 ms a frame; two frames more cover the frame it starts counting in and its last.
28255
+ *
28256
+ * @param outMs - The veil's fade-out.
28257
+ * @returns The frames.
28258
+ * @example
28259
+ * ```ts
28260
+ * parkFrames(300); // 8
28261
+ * ```
28262
+ */
28263
+ function parkFrames(outMs) {
28264
+ return Math.ceil(outMs / 50) + 2;
28265
+ }
28266
+ /**
28267
+ * Leaves a loader layer waiting where it hangs, at alpha 0, until the loader's views left it, or for `framesLeft`
28268
+ * frames at most: one layer at a time, so an older one goes back now.
28269
+ *
28270
+ * @param sctx - Domain context of the sync module.
28271
+ * @param container - The layer's container.
28272
+ * @param name - The layer.
28273
+ * @param framesLeft - The frames it waits at most.
28274
+ */
28275
+ function park(sctx, container, name, framesLeft) {
28276
+ const state = sctx.ctx.state.sync;
28277
+ const before = state.leave.parked;
28278
+ if (before !== void 0 && before.container !== container) putBack(sctx, before.container, before.layer);
28279
+ container.alpha = 0;
28280
+ state.leave.parked = {
28281
+ container,
28282
+ layer: name,
28283
+ framesLeft
28284
+ };
28285
+ state.passesVersion += 1;
28286
+ }
28287
+ /**
28288
+ * Lets the layer a look drew above the veil go. Before the swap, and once no view hangs in it, it goes back under the
28289
+ * root (`putBack`). After the swap, while the loader's views still hang in it, it waits above the veil at alpha 0:
28290
+ * `scenes` unmounts the loader projection in the first frame `outMs` has passed in, which can come a frame after the
28291
+ * veil is gone, and under the root the layer would draw the loader whole in that frame. The step puts it back once
28292
+ * its views left, or after a bounded wait (`stepParked`).
28293
+ *
28294
+ * @param sctx - Domain context of the sync module.
28295
+ * @param run - The look whose layer goes.
28296
+ */
28297
+ function unlift(sctx, run) {
28298
+ const lifted = run.lifted;
28299
+ if (lifted === void 0) return;
28300
+ delete run.lifted;
28301
+ if (run.landed && lifted.children.length > 0) park(sctx, lifted, run.layer, parkFrames(run.look.cover?.outMs ?? 0));
28302
+ else putBack(sctx, lifted, run.layer);
28303
+ }
28304
+ /**
28305
+ * Puts a layer that waits for the loader's views back once they left it, or once it waited its frames: views another
28306
+ * owner draws there stay, and are drawn whole again. A frame is asked for while it waits, so the wait ends.
28307
+ *
28308
+ * @param sctx - Domain context of the sync module.
28309
+ * @param parked - The waiting layer.
28310
+ */
28311
+ function stepParked(sctx, parked) {
28312
+ if (parked.container.children.length > 0 && parked.framesLeft > 0) {
28313
+ parked.framesLeft -= 1;
28314
+ sctx.deps.demand.request();
28315
+ return;
28316
+ }
28317
+ delete sctx.ctx.state.sync.leave.parked;
28318
+ putBack(sctx, parked.container, parked.layer);
28072
28319
  }
28073
28320
  /**
28074
28321
  * Takes the look down at once: its layer goes back, its objects leave the stage and are kept for the next look, and the
@@ -28157,8 +28404,10 @@ function paintVeil(objects, run) {
28157
28404
  objects.veil.alpha = cover.alpha * run.level;
28158
28405
  }
28159
28406
  /**
28160
- * Keeps the layer of a shown `"layer"` loader in the holder above the veil until the swap. A layer the scene does not
28161
- * declare draws nothing.
28407
+ * Keeps the layer of a shown `"layer"` loader in the holder above the veil, until the end of the fade-out after the
28408
+ * swap: the container lifted stays the look's, also when the next scene's layer list takes it back under the root or
28409
+ * does not declare it. After the swap its alpha is the veil's level. A layer the last loader left waiting is this
28410
+ * look's again, drawn whole. A layer the scene does not declare draws nothing.
28162
28411
  *
28163
28412
  * @param sctx - Domain context of the sync module.
28164
28413
  * @param objects - The engine's objects.
@@ -28166,11 +28415,19 @@ function paintVeil(objects, run) {
28166
28415
  */
28167
28416
  function lift(sctx, objects, run) {
28168
28417
  const state = sctx.ctx.state.sync;
28169
- const container = run.layer === void 0 ? void 0 : layerContainer(state, run.layer);
28170
- if (container === void 0 || container.parent === objects.held) return;
28171
- objects.held.addChild(container);
28418
+ const container = run.lifted ?? (run.layer === void 0 ? void 0 : layerContainer(state, run.layer));
28419
+ if (container === void 0) return;
28172
28420
  run.lifted = container;
28173
- state.passesVersion += 1;
28421
+ if (state.leave.parked?.container === container) {
28422
+ delete state.leave.parked;
28423
+ container.alpha = 1;
28424
+ state.passesVersion += 1;
28425
+ }
28426
+ if (container.parent !== objects.held) {
28427
+ objects.held.addChild(container);
28428
+ state.passesVersion += 1;
28429
+ }
28430
+ if (run.landed) container.alpha = run.landedLevel > 0 ? run.level / run.landedLevel : 0;
28174
28431
  }
28175
28432
  /**
28176
28433
  * Turns the ring or the spinner at the centre of the frame: one turn a second from the switch start.
@@ -28188,9 +28445,23 @@ function turn(objects, run, now, size) {
28188
28445
  turned.rotation = angle;
28189
28446
  }
28190
28447
  /**
28448
+ * Whether the loader of a running look shows in this frame: from `afterMs` after the switch start until the swap. After
28449
+ * the swap a layer loader that showed shows on, fading out with the veil; a ring, a texture, or a loader not due yet,
28450
+ * shows no more.
28451
+ *
28452
+ * @param run - The running look.
28453
+ * @param now - The clock now, ms.
28454
+ * @returns True while it shows.
28455
+ */
28456
+ function loaderShown(run, now) {
28457
+ if (run.landed) return run.shown && run.loader === "layer";
28458
+ return run.loader !== "none" && now - run.startedAt >= (run.look.loader?.afterMs ?? 0);
28459
+ }
28460
+ /**
28191
28461
  * Shows the loader once the switch took `afterMs`, until the swap: a layer loader asks its `due` then and lifts the
28192
- * layer it answers above the veil; a ring or a texture turns. A loader that comes or goes moves the walks of `shown`,
28193
- * so the loops of a lifted layer's views run while it shows.
28462
+ * layer it answers above the veil, where it stays and fades out with the veil after the swap; a ring or a texture
28463
+ * turns until the swap. A loader that comes or goes moves the walks of `shown`, so the loops of a lifted layer's views
28464
+ * run while it shows.
28194
28465
  *
28195
28466
  * @param sctx - Domain context of the sync module.
28196
28467
  * @param objects - The engine's objects.
@@ -28199,8 +28470,7 @@ function turn(objects, run, now, size) {
28199
28470
  * @returns True when the loader came, went or turns in this frame: the frame is drawn.
28200
28471
  */
28201
28472
  function paintLoader(sctx, objects, run, now) {
28202
- const afterMs = run.look.loader?.afterMs ?? 0;
28203
- const shown = !run.landed && run.loader !== "none" && now - run.startedAt >= afterMs;
28473
+ const shown = loaderShown(run, now);
28204
28474
  const due = shown && run.loader === "layer";
28205
28475
  if (due && !run.asked) ask(sctx, run);
28206
28476
  if (due) lift(sctx, objects, run);
@@ -28219,7 +28489,8 @@ function paintLoader(sctx, objects, run, now) {
28219
28489
  }
28220
28490
  /**
28221
28491
  * Shows a look from now, in place of one that runs: the veil fades in from where it stands (0, or the level of a veil
28222
- * still fading out after the last swap), the loader waits for its `afterMs`. Inert, nothing is kept.
28492
+ * still fading out after the last swap), the loader waits for its `afterMs`. A layer the last loader faded out with
28493
+ * waits unseen for its views to leave. Inert, nothing is kept.
28223
28494
  *
28224
28495
  * @param sctx - Domain context of the sync module.
28225
28496
  * @param look - The veil and the loader, resolved.
@@ -28238,6 +28509,7 @@ function showLeave(sctx, look) {
28238
28509
  steppedAt: now,
28239
28510
  level,
28240
28511
  landed: false,
28512
+ landedLevel: 1,
28241
28513
  asked: false,
28242
28514
  shown: false,
28243
28515
  ...loader
@@ -28245,26 +28517,29 @@ function showLeave(sctx, look) {
28245
28517
  sctx.deps.demand.request();
28246
28518
  }
28247
28519
  /**
28248
- * The swap came: the loader goes at once and the veil fades out over its `outMs` from where it stands; a look without
28249
- * a veil, or with `outMs: 0`, is taken down at once. Nothing runs, or the swap was told already: nothing happens.
28520
+ * The swap came: the veil fades out over its `outMs` from where it stands, and a layer loader that shows stays above
28521
+ * it and fades with it, its layer waiting unseen at the end until the loader's views left it; a ring or a texture goes
28522
+ * at once. A look without a veil, or with `outMs: 0`, is taken down at once, a layer loader's layer waiting the same.
28523
+ * Nothing runs, or the swap was told already: nothing happens.
28250
28524
  *
28251
28525
  * @param sctx - Domain context of the sync module.
28252
28526
  */
28253
28527
  function landLeave(sctx) {
28254
28528
  const run = sctx.ctx.state.sync.leave.run;
28255
28529
  if (run === void 0 || run.landed) return;
28530
+ run.landed = true;
28531
+ run.landedLevel = run.level;
28256
28532
  const cover = run.look.cover;
28257
28533
  if (cover === void 0 || cover.outMs <= 0) {
28258
28534
  takeDown(sctx);
28259
28535
  return;
28260
28536
  }
28261
- unlift(sctx, run);
28262
- run.landed = true;
28263
28537
  run.steppedAt = sctx.ctx.deps.clock.now();
28264
28538
  sctx.deps.demand.request();
28265
28539
  }
28266
28540
  /**
28267
- * The switch ended without a swap: the veil and the loader go at once. Nothing runs: nothing happens.
28541
+ * The switch ended without a swap: the veil and the loader go at once, a lifted layer back under the root. Nothing
28542
+ * runs: nothing happens.
28268
28543
  *
28269
28544
  * @param sctx - Domain context of the sync module.
28270
28545
  */
@@ -28275,13 +28550,16 @@ function dropLeave(sctx) {
28275
28550
  /**
28276
28551
  * The look of this frame, before the decision: the veil's level from the clock, the loader once due, both placed over
28277
28552
  * the canvas as it stands, and a frame asked for while either moves. A look whose veil faded out after the swap is
28278
- * taken down. One field read and no allocation while no look runs; a lost device leaves the look waiting for the
28279
- * restore, which makes its objects again.
28553
+ * taken down, a layer loader fading with it left waiting; a waiting layer whose views left goes back. Two field reads
28554
+ * and no allocation while no look runs, none during a fade or a wait either; a lost device leaves the look waiting for
28555
+ * the restore, which makes its objects again.
28280
28556
  *
28281
28557
  * @param sctx - Domain context of the sync module.
28282
28558
  */
28283
28559
  function stepLeave(sctx) {
28284
- const run = sctx.ctx.state.sync.leave.run;
28560
+ const leave = sctx.ctx.state.sync.leave;
28561
+ const run = leave.run;
28562
+ if (leave.parked !== void 0) stepParked(sctx, leave.parked);
28285
28563
  if (run === void 0) return;
28286
28564
  const objects = objectsOf(sctx);
28287
28565
  const stage = sctx.deps.host.stage();
@@ -28299,18 +28577,19 @@ function stepLeave(sctx) {
28299
28577
  if (moved || loading) sctx.deps.demand.request();
28300
28578
  }
28301
28579
  /**
28302
- * Forgets the objects of a lost application: they go with its stage, and so does a layer lifted above the veil. The
28303
- * running look stays: the step makes its objects again on the restored device.
28580
+ * Forgets the objects of a lost application: they go with its stage, and so does a layer lifted above the veil or
28581
+ * waiting there. The running look stays: the step makes its objects again on the restored device.
28304
28582
  *
28305
28583
  * @param state - The sync branch of the plugin state.
28306
28584
  */
28307
28585
  function forgetLeave$1(state) {
28308
28586
  delete state.leave.objects;
28587
+ delete state.leave.parked;
28309
28588
  if (state.leave.run !== void 0) delete state.leave.run.lifted;
28310
28589
  }
28311
28590
  /**
28312
- * Drops the look and frees the engine's objects when the plugin stops. A lifted layer is the layer table's and the
28313
- * spinner's texture is the game's: neither is freed with them.
28591
+ * Drops the look and frees the engine's objects when the plugin stops. A lifted or waiting layer is the layer table's
28592
+ * and the spinner's texture is the game's: neither is freed with them.
28314
28593
  *
28315
28594
  * @param state - The sync branch of the plugin state.
28316
28595
  */
@@ -28318,6 +28597,7 @@ function stopLeave(state) {
28318
28597
  const objects = state.leave.objects;
28319
28598
  delete state.leave.run;
28320
28599
  delete state.leave.objects;
28600
+ delete state.leave.parked;
28321
28601
  if (objects === void 0) return;
28322
28602
  objects.held.removeChildren();
28323
28603
  objects.top.destroy({ children: true });
@@ -32727,7 +33007,7 @@ function checkTree(sctx, entities) {
32727
33007
  /** Label of the container the viewport transform is written on. */
32728
33008
  const ROOT_LABEL = "renderer.root";
32729
33009
  /** The change steps of a pass that write an entity's view: what `runStep` does for each changed component. */
32730
- const STEP = {
33010
+ const STEP$1 = {
32731
33011
  transform: 0,
32732
33012
  sprite: 1,
32733
33013
  nineSlice: 2,
@@ -32920,27 +33200,27 @@ function createSyncApi(ctx, deps) {
32920
33200
  */
32921
33201
  const runStep = (step, entity, view) => {
32922
33202
  switch (step) {
32923
- case STEP.transform:
33203
+ case STEP$1.transform:
32924
33204
  applyTransform(sctx, entity, view);
32925
33205
  resort(sctx, entity, view);
32926
33206
  break;
32927
- case STEP.sprite:
33207
+ case STEP$1.sprite:
32928
33208
  if (applySprite(sctx, entity, view)) applyTransform(sctx, entity, view);
32929
33209
  break;
32930
- case STEP.nineSlice:
33210
+ case STEP$1.nineSlice:
32931
33211
  applyNineSlice(sctx, entity, view);
32932
33212
  break;
32933
- case STEP.shape:
33213
+ case STEP$1.shape:
32934
33214
  applyShape(sctx, entity, view);
32935
33215
  break;
32936
- case STEP.order:
33216
+ case STEP$1.order:
32937
33217
  resort(sctx, entity, view);
32938
33218
  break;
32939
- case STEP.layer:
33219
+ case STEP$1.layer:
32940
33220
  attach$1(sctx, entity, view);
32941
33221
  resort(sctx, entity, view);
32942
33222
  break;
32943
- case STEP.parent:
33223
+ case STEP$1.parent:
32944
33224
  rehang(entity, view);
32945
33225
  break;
32946
33226
  default: if (view.display === adapterEntry) updateAdapterView(sctx, entity, view);
@@ -32972,14 +33252,14 @@ function createSyncApi(ctx, deps) {
32972
33252
  const view = state.views.get(entity);
32973
33253
  if (view !== void 0) guardedStep(step, entity, view);
32974
33254
  };
32975
- const onTransform = (entity) => stepOn(STEP.transform, entity);
32976
- const onSprite = (entity) => stepOn(STEP.sprite, entity);
32977
- const onNineSlice = (entity) => stepOn(STEP.nineSlice, entity);
32978
- const onShape = (entity) => stepOn(STEP.shape, entity);
32979
- const onOrder = (entity) => stepOn(STEP.order, entity);
32980
- const onLayer = (entity) => stepOn(STEP.layer, entity);
32981
- const onParent = (entity) => stepOn(STEP.parent, entity);
32982
- const onAdapter = (entity) => stepOn(STEP.adapter, entity);
33255
+ const onTransform = (entity) => stepOn(STEP$1.transform, entity);
33256
+ const onSprite = (entity) => stepOn(STEP$1.sprite, entity);
33257
+ const onNineSlice = (entity) => stepOn(STEP$1.nineSlice, entity);
33258
+ const onShape = (entity) => stepOn(STEP$1.shape, entity);
33259
+ const onOrder = (entity) => stepOn(STEP$1.order, entity);
33260
+ const onLayer = (entity) => stepOn(STEP$1.layer, entity);
33261
+ const onParent = (entity) => stepOn(STEP$1.parent, entity);
33262
+ const onAdapter = (entity) => stepOn(STEP$1.adapter, entity);
32983
33263
  /**
32984
33264
  * A new `Display` object of the game replaces the old view outright, unless this pass built it, or it waits aside
32985
33265
  * for its view (spec 31): the chunk that makes it reads the new object.
@@ -33990,7 +34270,7 @@ function createRendererApi(ctx) {
33990
34270
  * @param ctx - Kernel context of the renderer plugin.
33991
34271
  * @returns The hooks of the plugin.
33992
34272
  */
33993
- function createHandlers$5(ctx) {
34273
+ function createHandlers$6(ctx) {
33994
34274
  let monitor;
33995
34275
  /**
33996
34276
  * The monitor module, built once.
@@ -34451,7 +34731,7 @@ const rendererPlugin = /*#__PURE__*/ createPlugin$1("renderer", {
34451
34731
  events: (register) => register.map({ "renderer:device-lost": "The GPU device or context was lost; the game is paused" }),
34452
34732
  createState: createRendererState,
34453
34733
  api: createRendererApi,
34454
- hooks: createHandlers$5,
34734
+ hooks: createHandlers$6,
34455
34735
  onStart: startRenderer,
34456
34736
  onStop: ({ config, state }) => stopRenderer({
34457
34737
  config,
@@ -34568,7 +34848,7 @@ function countPlaying(ecs, entity, delta) {
34568
34848
  * frameMsOf(10); // 100
34569
34849
  * ```
34570
34850
  */
34571
- function frameMsOf(fps) {
34851
+ function frameMsOf$1(fps) {
34572
34852
  return fps > 0 ? 1e3 / fps : 0;
34573
34853
  }
34574
34854
  /**
@@ -34583,7 +34863,7 @@ function frameMsOf(fps) {
34583
34863
  * ```
34584
34864
  */
34585
34865
  function framesDurationMs(keys, fps) {
34586
- return keys.length * frameMsOf(fps);
34866
+ return keys.length * frameMsOf$1(fps);
34587
34867
  }
34588
34868
  /**
34589
34869
  * Which key of the list belongs to a point of the step. A looping list wraps; a list that plays
@@ -34601,7 +34881,7 @@ function framesDurationMs(keys, fps) {
34601
34881
  * ```
34602
34882
  */
34603
34883
  function frameIndexAt(keys, fps, loop, elapsed) {
34604
- const frameMs = frameMsOf(fps);
34884
+ const frameMs = frameMsOf$1(fps);
34605
34885
  const raw = frameMs > 0 ? Math.floor(elapsed / frameMs) : keys.length - 1;
34606
34886
  if (loop) return (raw % keys.length + keys.length) % keys.length;
34607
34887
  return Math.min(Math.max(raw, 0), keys.length - 1);
@@ -40383,7 +40663,7 @@ function createSwap$1(ctx, reload = reloadPage$1) {
40383
40663
  * means the page reload; a test passes a spy.
40384
40664
  * @returns The two hooks of the plugin.
40385
40665
  */
40386
- function createHandlers$4(ctx, reload) {
40666
+ function createHandlers$5(ctx, reload) {
40387
40667
  let assets;
40388
40668
  let swap;
40389
40669
  return {
@@ -40515,7 +40795,7 @@ const assetsPlugin = /*#__PURE__*/ createPlugin$1("assets", {
40515
40795
  }),
40516
40796
  createState: createAssetsState,
40517
40797
  api: createAssetsApi,
40518
- hooks: createHandlers$4,
40798
+ hooks: createHandlers$5,
40519
40799
  onInit: connectAssets,
40520
40800
  onStart: startAssets,
40521
40801
  onStop: ({ state }) => releaseAll(state)
@@ -40538,6 +40818,236 @@ function createScenesApi(ctx) {
40538
40818
  };
40539
40819
  }
40540
40820
  //#endregion
40821
+ //#region src/plugins/scenes/progress.ts
40822
+ /**
40823
+ * @file scenes plugin — the switch a leave loader projection reads (F107 part 1). `world.projection.feed` hands its
40824
+ * `from` a `SceneSwitch`, `{ from, to, progress }`, as a third argument: while a scene stands, its held loader reads
40825
+ * `{ from: current, to: current, progress: 0 }`; a switch feeds it the scene left, the scene entered and the share of
40826
+ * the switch's bundles loaded, in steps of 0.01 up to 1: a bundle loaded at the start counts whole, one being loaded
40827
+ * counts its files from `assets:bundle-progress`, and every bundle the scene stage finds loaded counts whole (a bundle
40828
+ * with no file sends no progress). Only a loader scenes holds, or one with no view yet (A2, mounted at its due), is
40829
+ * fed: a projection another owner shows never is. The progress is counted in integer thousandths, so the last value
40830
+ * fed is exactly 1.
40831
+ */
40832
+ /** A bundle loaded, and a switch whose bundles are all in, in thousandths. */
40833
+ const WHOLE = 1e3;
40834
+ /** The growth of the progress, in thousandths, a switch waits for before it feeds the loader again: 0.01. */
40835
+ const STEP = 10;
40836
+ /**
40837
+ * Reads the committed state a scene's `bundles` gets: the frozen trees of the store, in a frozen
40838
+ * wrapper. During the scene stage no node writes, so it is the state the node is entered with.
40839
+ *
40840
+ * @param ctx - Domain context of the plugin.
40841
+ * @returns The committed `player` and `session`.
40842
+ */
40843
+ function committedState(ctx) {
40844
+ const { player, session } = ctx.deps.model.store.snapshot();
40845
+ return Object.freeze({
40846
+ player,
40847
+ session
40848
+ });
40849
+ }
40850
+ /**
40851
+ * The share of a bundle one progress event tells, in thousandths, floored: the whole once every file settled.
40852
+ *
40853
+ * @param loaded - The settled files.
40854
+ * @param total - The files of the bundle.
40855
+ * @returns 0 to 1000.
40856
+ * @example
40857
+ * ```ts
40858
+ * shareOf(1, 3); // 333
40859
+ * ```
40860
+ */
40861
+ function shareOf(loaded, total) {
40862
+ return loaded >= total ? WHOLE : Math.floor(WHOLE * loaded / total);
40863
+ }
40864
+ /**
40865
+ * The progress of a switch, in thousandths: the mean of its bundles' shares, floored; the whole with no bundle.
40866
+ *
40867
+ * @param bundles - The table of the switch.
40868
+ * @returns 0 to 1000.
40869
+ * @example
40870
+ * ```ts
40871
+ * meanOf([{ bundle: "board", share: 250 }, { bundle: "ep01", share: 0 }]); // 125
40872
+ * ```
40873
+ */
40874
+ function meanOf(bundles) {
40875
+ if (bundles.length === 0) return WHOLE;
40876
+ let sum = 0;
40877
+ for (const row of bundles) sum += row.share;
40878
+ return Math.floor(sum / bundles.length);
40879
+ }
40880
+ /**
40881
+ * Tells whether the progress moved far enough to feed the loader again: by 0.01 since the last feed, or onto the whole
40882
+ * for the first time.
40883
+ *
40884
+ * @param fed - The progress last fed, in thousandths.
40885
+ * @param now - The progress now, in thousandths.
40886
+ * @returns True when the loader is fed.
40887
+ * @example
40888
+ * ```ts
40889
+ * isStep(995, 1000); // true: the switch is done
40890
+ * ```
40891
+ */
40892
+ function isStep(fed, now) {
40893
+ return now - fed >= STEP || now === WHOLE && fed < WHOLE;
40894
+ }
40895
+ /**
40896
+ * The row of a bundle in the table of a switch.
40897
+ *
40898
+ * @param bundles - The table.
40899
+ * @param bundle - The bundle.
40900
+ * @returns Its row, or `undefined` for a bundle the switch does not name.
40901
+ * @example
40902
+ * ```ts
40903
+ * rowOf([{ bundle: "board", share: 0 }], "ep01"); // undefined
40904
+ * ```
40905
+ */
40906
+ function rowOf(bundles, bundle) {
40907
+ for (const row of bundles) if (row.bundle === bundle) return row;
40908
+ }
40909
+ /**
40910
+ * The table of a switch: one row per bundle the scene being switched to names for the committed state, a bundle
40911
+ * loaded already counted whole. A `bundles` that throws gives an empty table, a switch done: the `scene` stage throws
40912
+ * it again, as it does without a loader.
40913
+ *
40914
+ * @param ctx - Domain context of the plugin.
40915
+ * @param scene - The scene being switched to.
40916
+ * @returns The rows, in the order the scene names its bundles.
40917
+ */
40918
+ function sharesOf(ctx, scene) {
40919
+ let named;
40920
+ try {
40921
+ named = namedBundles(scene, committedState(ctx));
40922
+ } catch {
40923
+ return [];
40924
+ }
40925
+ const assets = ctx.deps.assets;
40926
+ return named.map((bundle) => ({
40927
+ bundle,
40928
+ share: assets.isLoaded(bundle) ? WHOLE : 0
40929
+ }));
40930
+ }
40931
+ /**
40932
+ * Starts feeding the loader projection of a switch, before it is due: the table of its bundles, one `feed` bound to
40933
+ * the name, and the first value, `{ from, to, progress }`. A held loader only stores it, and the show writes it into
40934
+ * the view built ahead once; a loader with no view (A2) reads it when it is mounted at its due. A projection another
40935
+ * owner shows is not fed: a held one answers no entity either, so a view means someone else's.
40936
+ *
40937
+ * @param ctx - Domain context of the plugin.
40938
+ * @param leaving - The look of the switch: it keeps what it feeds.
40939
+ * @param name - The loader projection.
40940
+ * @param between - The scene being left and the scene being switched to.
40941
+ * @param between.from - The scene being left.
40942
+ * @param between.to - The scene being switched to.
40943
+ */
40944
+ function startFeeding(ctx, leaving, name, between) {
40945
+ const projection = ctx.deps.world.projection;
40946
+ if (projection.entitiesOf(name).length > 0) return;
40947
+ const bundles = sharesOf(ctx, between.to);
40948
+ const feeding = {
40949
+ name,
40950
+ from: between.from.id,
40951
+ to: between.to.id,
40952
+ bundles,
40953
+ fed: meanOf(bundles),
40954
+ feed: (sw) => projection.feed(name, sw)
40955
+ };
40956
+ leaving.feeding = feeding;
40957
+ feeding.feed({
40958
+ from: feeding.from,
40959
+ to: feeding.to,
40960
+ progress: feeding.fed / WHOLE
40961
+ });
40962
+ }
40963
+ /**
40964
+ * Feeds the loader a new switch when the progress moved by a step since the last feed; below the step it only reads
40965
+ * numbers.
40966
+ *
40967
+ * @param feeding - What the switch feeds.
40968
+ */
40969
+ function feedStep(feeding) {
40970
+ const now = meanOf(feeding.bundles);
40971
+ if (!isStep(feeding.fed, now)) return;
40972
+ feeding.fed = now;
40973
+ feeding.feed({
40974
+ from: feeding.from,
40975
+ to: feeding.to,
40976
+ progress: now / WHOLE
40977
+ });
40978
+ }
40979
+ /**
40980
+ * Counts one settled file of a bundle of the running switch, from the `assets:bundle-progress` hook: the bundle's share
40981
+ * is set, and the loader is fed when the progress moved by a step. With no switch (none runs, or it swapped or
40982
+ * dropped: `endLeave` takes it out of the state), no loader fed, or a bundle the switch does not name, nothing happens.
40983
+ * Below the step it reads and writes numbers only: no allocation.
40984
+ *
40985
+ * @param state - The plugin state.
40986
+ * @param bundle - The bundle the event names.
40987
+ * @param loaded - Its settled files.
40988
+ * @param total - Its files.
40989
+ */
40990
+ function countProgress(state, bundle, loaded, total) {
40991
+ const feeding = state.leaving?.feeding;
40992
+ if (feeding === void 0) return;
40993
+ const row = rowOf(feeding.bundles, bundle);
40994
+ if (row === void 0) return;
40995
+ row.share = shareOf(loaded, total);
40996
+ feedStep(feeding);
40997
+ }
40998
+ /**
40999
+ * Counts every bundle of the running switch whole once the scene stage has its loads in: a bundle with no file, which
41000
+ * sends no progress, counts then, and the loader reads 1 before the warm and the build. With no loader fed, nothing
41001
+ * happens.
41002
+ *
41003
+ * @param state - The plugin state.
41004
+ */
41005
+ function countLoaded(state) {
41006
+ const feeding = state.leaving?.feeding;
41007
+ if (feeding === void 0) return;
41008
+ for (const row of feeding.bundles) row.share = WHOLE;
41009
+ feedStep(feeding);
41010
+ }
41011
+ /**
41012
+ * Feeds a loader scenes holds the switch of the scene that stands, right after the hold: `world` keeps the first
41013
+ * value fed after a hold for the view it builds ahead, so the loader is built for `{ from: current, to: current,
41014
+ * progress: 0 }` and not for the last switch.
41015
+ *
41016
+ * @param ctx - Domain context of the plugin.
41017
+ * @param name - The loader held.
41018
+ */
41019
+ function feedStanding(ctx, name) {
41020
+ const scene = ctx.state.current;
41021
+ if (scene === void 0) return;
41022
+ ctx.deps.world.projection.feed(name, {
41023
+ from: scene,
41024
+ to: scene,
41025
+ progress: 0
41026
+ });
41027
+ }
41028
+ //#endregion
41029
+ //#region src/plugins/scenes/handlers.ts
41030
+ /**
41031
+ * @file scenes plugin — the hook of `assets` (F107 part 1): every settled file of a bundle of the running switch moves
41032
+ * the progress its leave loader projection reads (`progress.ts`). It reads the plugin state only, so it allocates
41033
+ * nothing for an event that does not move the progress by a step. A bundle that is loaded is counted by the switch
41034
+ * itself, at its start and once the scene stage has its loads, not on `assets:bundle-loaded`: the kernel awaits each
41035
+ * handler of an event in plugin order, so a scenes handler there would move the font install of `text`, a later
41036
+ * plugin, one microtask later.
41037
+ */
41038
+ /**
41039
+ * Creates the hook handler. It reads the state only, which exists when the kernel registers hooks: the `feed` of a
41040
+ * switch is bound to `world` when the switch starts.
41041
+ *
41042
+ * @param ctx - Kernel context of the scenes plugin.
41043
+ * @returns The one hook of the plugin.
41044
+ */
41045
+ function createHandlers$4(ctx) {
41046
+ return { "assets:bundle-progress": ({ bundle, loaded, total }) => {
41047
+ countProgress(ctx.state, bundle, loaded, total);
41048
+ } };
41049
+ }
41050
+ //#endregion
40541
41051
  //#region src/plugins/scenes/swap.ts
40542
41052
  /**
40543
41053
  * The projections of the scene that leaves which the scene that comes does not list. A projection
@@ -40627,8 +41137,8 @@ function swapIn(ctx, scene, named, build) {
40627
41137
  const SECOND_MS$1 = 1e3;
40628
41138
  /** The share of a frame interval `"auto"` gives the building work: two thirds. */
40629
41139
  const BUILD_SHARE = 2 / 3;
40630
- /** The budget of a frame when `time` answers no usable frame rate: two thirds of a 60 Hz frame, ≈ 11.1 ms. */
40631
- const FALLBACK_BUDGET_MS = SECOND_MS$1 / 60 * BUILD_SHARE;
41140
+ /** The frame interval when `time` answers no usable frame rate: a 60 Hz frame, ≈ 16.7 ms. */
41141
+ const FALLBACK_FRAME_MS = SECOND_MS$1 / 60;
40632
41142
  /**
40633
41143
  * Tells whether a value is a number a frame can count with: finite and above 0. Pure.
40634
41144
  *
@@ -40657,6 +41167,17 @@ function agentNow(ctx) {
40657
41167
  return clock === void 0 ? 0 : clock();
40658
41168
  }
40659
41169
  /**
41170
+ * The frame interval the loop runs at now, `1000 / time.rate().fps`. A rate that is not a finite number above 0 gives
41171
+ * a 60 Hz frame.
41172
+ *
41173
+ * @param ctx - Domain context of the plugin.
41174
+ * @returns Milliseconds of one frame.
41175
+ */
41176
+ function frameMsOf(ctx) {
41177
+ const { fps } = ctx.deps.time.rate();
41178
+ return isPositiveFinite(fps) ? SECOND_MS$1 / fps : FALLBACK_FRAME_MS;
41179
+ }
41180
+ /**
40660
41181
  * The building budget of a frame for a build that starts now: the number a game configured, or
40661
41182
  * for `"auto"` two thirds of the frame interval the loop runs at, `(1000 / time.rate().fps) * 2 / 3`,
40662
41183
  * read once here. A rate that is not a finite number above 0 gives two thirds of a 60 Hz frame.
@@ -40667,8 +41188,7 @@ function agentNow(ctx) {
40667
41188
  function budgetOf(ctx) {
40668
41189
  const { buildMs } = ctx.config;
40669
41190
  if (buildMs !== "auto") return buildMs;
40670
- const { fps } = ctx.deps.time.rate();
40671
- return isPositiveFinite(fps) ? SECOND_MS$1 / fps * BUILD_SHARE : FALLBACK_BUDGET_MS;
41191
+ return frameMsOf(ctx) * BUILD_SHARE;
40672
41192
  }
40673
41193
  /**
40674
41194
  * Ends the build with the swap: its listeners go and the record is dropped, then the swap of a
@@ -40830,109 +41350,38 @@ function dropBuild(build) {
40830
41350
  build.resolve();
40831
41351
  }
40832
41352
  //#endregion
40833
- //#region src/plugins/scenes/leave.ts
40834
- /**
40835
- * What a game gets when it writes nothing: black at 45 %, 50 ms in and 150 ms out, the engine's ring once the switch took
40836
- * 400 ms. The level under `config.leave`, and where a part written over `false` starts. `index.ts` writes the same
40837
- * value inline as the plugin's default config; a test pins the two equal.
40838
- */
40839
- const FALLBACK_LEAVE = Object.freeze({
40840
- cover: Object.freeze({
40841
- color: 0,
40842
- alpha: .45,
40843
- inMs: 50,
40844
- outMs: 150
40845
- }),
40846
- loader: Object.freeze({ afterMs: 400 })
40847
- });
40848
- /**
40849
- * Merges one level's veil over the one below, field by field. `false` turns it off; a veil written over `false`
40850
- * starts from the engine's.
40851
- *
40852
- * @param below - The veil of the levels below, or `false`.
40853
- * @param over - What this level writes: nothing, `false` or fields.
40854
- * @returns The veil, or `false`.
40855
- * @example
40856
- * ```ts
40857
- * coverOver(false, { alpha: 0.6 }); // { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }
40858
- * ```
40859
- */
40860
- function coverOver(below, over) {
40861
- if (over === void 0) return below;
40862
- if (over === false) return false;
40863
- const base = below === false ? FALLBACK_LEAVE.cover : below;
40864
- return {
40865
- color: over.color ?? base.color,
40866
- alpha: over.alpha ?? base.alpha,
40867
- inMs: over.inMs ?? base.inMs,
40868
- outMs: over.outMs ?? base.outMs
40869
- };
40870
- }
41353
+ //#region src/plugins/scenes/loader.ts
40871
41354
  /**
40872
- * The look of a loader: its projection, else its texture, else nothing (the engine's ring).
40873
- *
40874
- * @param loader - A level that names a look, or the level below.
40875
- * @returns At most one of the two fields.
40876
- * @example
40877
- * ```ts
40878
- * lookOf({ texture: "ui.loader.ring", projection: "loading" }); // { projection: "loading" }
40879
- * ```
41355
+ * Does nothing: the remover of a fade before its frame callback is registered.
40880
41356
  */
40881
- function lookOf(loader) {
40882
- if (loader.projection !== void 0) return { projection: loader.projection };
40883
- if (loader.texture !== void 0) return { texture: loader.texture };
40884
- return {};
40885
- }
41357
+ function noFrame() {}
40886
41358
  /**
40887
- * Merges one level's loader over the one below. `afterMs` is a field of its own; `texture` and `projection` are one
40888
- * choice: a level that names either replaces both of the level below. `false` turns it off; a loader written over
40889
- * `false` starts from the engine's.
41359
+ * Tells whether an entry of a feature's `projections` list names its layer. The key carries whatever the game put
41360
+ * there, so an entry that does not is skipped.
40890
41361
  *
40891
- * @param below - The loader of the levels below, or `false`.
40892
- * @param over - What this level writes: nothing, `false` or fields.
40893
- * @returns The loader, or `false`.
41362
+ * @param entry - One entry of the list.
41363
+ * @returns True for an object with a string `name` and a string `layer`.
40894
41364
  * @example
40895
41365
  * ```ts
40896
- * loaderOver({ afterMs: 400, projection: "loading" }, { texture: "ui.loader.ring" }); // { afterMs: 400, texture: "ui.loader.ring" }
41366
+ * isLayered({ name: "loading", layer: "loading", view: () => [] }); // true
40897
41367
  * ```
40898
41368
  */
40899
- function loaderOver(below, over) {
40900
- if (over === void 0) return below;
40901
- if (over === false) return false;
40902
- const base = below === false ? FALLBACK_LEAVE.loader : below;
40903
- const named = over.texture !== void 0 || over.projection !== void 0;
40904
- return {
40905
- afterMs: over.afterMs ?? base.afterMs,
40906
- ...lookOf(named ? over : base)
40907
- };
41369
+ function isLayered(entry) {
41370
+ return typeof entry === "object" && entry !== null && "name" in entry && typeof entry.name === "string" && "layer" in entry && typeof entry.layer === "string";
40908
41371
  }
40909
41372
  /**
40910
- * Resolves what a switch shows over the scene being left: the scene's `leave` over the config's over the engine's,
40911
- * field by field. `false` at a level turns both parts off there.
41373
+ * The layer a projection's spec names, read from the `projections` of the features, the list `world` registers.
40912
41374
  *
40913
- * @param config - `config.leave`.
40914
- * @param scene - The `leave` of the scene being left.
40915
- * @returns Both parts, each resolved or `false`; `undefined` when both are off.
40916
- * @example
40917
- * ```ts
40918
- * leaveOf({ loader: false }, { cover: { alpha: 0.6 } }); // { cover: { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }, loader: false }
40919
- * ```
41375
+ * @param ctx - Domain context of the plugin.
41376
+ * @param name - The projection.
41377
+ * @returns Its `layer`, or `undefined` when no feature brings it.
40920
41378
  */
40921
- function leaveOf(config, scene) {
40922
- let cover = FALLBACK_LEAVE.cover;
40923
- let loader = FALLBACK_LEAVE.loader;
40924
- for (const level of [config, scene]) if (level === false) {
40925
- cover = false;
40926
- loader = false;
40927
- } else if (level !== void 0) {
40928
- cover = coverOver(cover, level.cover);
40929
- loader = loaderOver(loader, level.loader);
41379
+ function specLayerOf(ctx, name) {
41380
+ for (const feature of ctx.deps.flow.features.all()) {
41381
+ const list = feature.description.projections;
41382
+ if (!Array.isArray(list)) continue;
41383
+ for (const entry of list) if (isLayered(entry) && entry.name === name) return entry.layer;
40930
41384
  }
40931
- if (cover === false && loader === false) return void 0;
40932
- return {
40933
- cover,
40934
- loader
40935
- };
40936
41385
  }
40937
41386
  /**
40938
41387
  * The layer a mounted projection's views draw in, read from its first view.
@@ -40947,12 +41396,31 @@ function layerOf(ctx, name) {
40947
41396
  return entity === void 0 ? void 0 : ecs.get(entity, Layer)?.name;
40948
41397
  }
40949
41398
  /**
40950
- * Unmounts the loader projection a switch mounted, once: one it did not mount is left alone.
41399
+ * Refuses a loader whose layer a projection of the scene being left draws in too: lifted above the veil, that layer
41400
+ * would take the scene's own views with it. Warned; the renderer draws the ring.
41401
+ *
41402
+ * @param ctx - Domain context of the plugin.
41403
+ * @param name - The loader projection.
41404
+ * @param layer - The layer of the loader.
41405
+ * @param from - The scene being left.
41406
+ * @returns True when one of the scene's projections has a view in that layer.
41407
+ */
41408
+ function refusesShared(ctx, name, layer, from) {
41409
+ if (!from.projections.some((other) => layerOf(ctx, other) === layer)) return false;
41410
+ ctx.log.warn("scenes:loader-layer-shared", {
41411
+ projection: name,
41412
+ layer,
41413
+ scene: from.id
41414
+ });
41415
+ return true;
41416
+ }
41417
+ /**
41418
+ * Unmounts the loader projection a switch mounted or showed, at once: one it did not is left alone.
40951
41419
  *
40952
41420
  * @param ctx - Domain context of the plugin.
40953
41421
  * @param leaving - The look of the switch.
40954
41422
  */
40955
- function unmountLoader(ctx, leaving) {
41423
+ function dropLoader(ctx, leaving) {
40956
41424
  const name = leaving.projection;
40957
41425
  if (name === void 0) return;
40958
41426
  delete leaving.projection;
@@ -40986,44 +41454,364 @@ function mountOnce(ctx, name, from, leaving) {
40986
41454
  return true;
40987
41455
  }
40988
41456
  /**
40989
- * Tells whether a projection of the scene being left draws in a layer: lifted above the veil, that layer would take
40990
- * the scene's own views with it.
41457
+ * Mounts a loader projection the scene being left does not hold, in the frame it is due (A2), and answers the layer its
41458
+ * views draw in. A mount that throws, a layer a projection of the scene draws in too and a projection with no view give
41459
+ * the engine's ring.
40991
41460
  *
40992
41461
  * @param ctx - Domain context of the plugin.
41462
+ * @param name - The loader projection.
40993
41463
  * @param from - The scene being left.
40994
- * @param layer - The layer of the loader.
40995
- * @returns True when one of its projections has a view in that layer.
41464
+ * @param leaving - The look of the switch: it keeps the name to unmount at the end.
41465
+ * @returns The layer, or `undefined` for the ring.
40996
41466
  */
40997
- function sharesLayer(ctx, from, layer) {
40998
- return from.projections.some((other) => layerOf(ctx, other) === layer);
41467
+ function mountLoader(ctx, name, from, leaving) {
41468
+ if (!mountOnce(ctx, name, from, leaving)) return void 0;
41469
+ const layer = layerOf(ctx, name);
41470
+ if (layer === void 0 || !refusesShared(ctx, name, layer, from)) return layer;
41471
+ dropLoader(ctx, leaving);
40999
41472
  }
41000
41473
  /**
41001
- * Mounts a loader projection once its loader is due, called by the renderer in that frame, and answers the layer its
41002
- * views draw in, which the renderer draws above the veil. A mount that throws, a layer a projection of the scene being
41003
- * left draws in too, and a projection with no view give the engine's ring. A switch that ended meanwhile mounts
41004
- * nothing.
41474
+ * Shows the loader the scene being left holds: built already, it is on the screen in the next frame, the same views,
41475
+ * no spawn. Its layer is its spec's: the view `show` brings is reconciled in the next frame, so it has no `Layer` yet.
41476
+ * One whose layer a projection of the scene draws in too is unmounted instead, and the renderer draws the ring.
41477
+ *
41478
+ * @param ctx - Domain context of the plugin.
41479
+ * @param held - The loader the scene holds.
41480
+ * @param from - The scene being left.
41481
+ * @param leaving - The look of the switch: it keeps the name to unmount or fade out at the end.
41482
+ * @returns The layer, or `undefined` for the ring.
41483
+ */
41484
+ function showHeld(ctx, held, from, leaving) {
41485
+ const projection = ctx.deps.world.projection;
41486
+ delete ctx.state.held;
41487
+ if (refusesShared(ctx, held.name, held.layer, from)) {
41488
+ projection.unmount([held.name]);
41489
+ return;
41490
+ }
41491
+ projection.show(held.name);
41492
+ leaving.projection = held.name;
41493
+ return held.layer;
41494
+ }
41495
+ /**
41496
+ * The `due` of a loader projection, called by the renderer in the first frame the loader is due: a loader the scene
41497
+ * being left holds is shown, any other is mounted then (A2). It answers the layer the renderer draws above the veil.
41498
+ * A switch that ended meanwhile shows nothing.
41005
41499
  *
41006
41500
  * @param ctx - Domain context of the plugin.
41007
41501
  * @param name - The loader projection.
41008
41502
  * @param from - The scene being left.
41009
- * @param leaving - The look of the switch: it keeps the name to unmount at the end.
41503
+ * @param leaving - The look of the switch.
41010
41504
  * @returns The layer, or `undefined` for the ring.
41011
41505
  */
41012
- function mountLoader(ctx, name, from, leaving) {
41013
- if (leaving.done || !mountOnce(ctx, name, from, leaving)) return void 0;
41014
- const layer = layerOf(ctx, name);
41015
- if (layer === void 0 || !sharesLayer(ctx, from, layer)) return layer;
41016
- ctx.log.warn("scenes:loader-layer-shared", {
41017
- projection: name,
41018
- layer,
41019
- scene: from.id
41020
- });
41021
- unmountLoader(ctx, leaving);
41506
+ function dueLoader(ctx, name, from, leaving) {
41507
+ if (leaving.done) return void 0;
41508
+ const held = ctx.state.held;
41509
+ if (held !== void 0 && held.name === name) return showHeld(ctx, held, from, leaving);
41510
+ return mountLoader(ctx, name, from, leaving);
41511
+ }
41512
+ /**
41513
+ * Holds a loader for the next switch and feeds it the switch of the scene that stands right after, in the same call:
41514
+ * the first value fed after a hold is the one `world` builds the held view for. A hold `world` refuses (a `lift` the
41515
+ * scene does not declare) is warned and holds nothing: the loader is then mounted when it is due, and that mount is
41516
+ * refused the same way.
41517
+ *
41518
+ * @param ctx - Domain context of the plugin.
41519
+ * @param loader - The loader to hold.
41520
+ */
41521
+ function holdNow(ctx, loader) {
41522
+ try {
41523
+ ctx.deps.world.projection.hold([loader.name], ctx.state.owner);
41524
+ } catch (error) {
41525
+ ctx.log.warn("scenes:loader-unmounted", {
41526
+ projection: loader.name,
41527
+ scene: ctx.state.current,
41528
+ error
41529
+ });
41530
+ return;
41531
+ }
41532
+ feedStanding(ctx, loader.name);
41533
+ ctx.state.held = loader;
41534
+ }
41535
+ /**
41536
+ * The loader a scene that stands may hold, by the rules of A2: a projection the scene does not list, whose spec's
41537
+ * layer the scene declares.
41538
+ *
41539
+ * @param ctx - Domain context of the plugin.
41540
+ * @param scene - The scene that stands.
41541
+ * @param name - The projection its leave loader names.
41542
+ * @returns The loader, or `undefined` when the scene cannot hold it.
41543
+ */
41544
+ function loaderToHold(ctx, scene, name) {
41545
+ if (scene.projections.includes(name)) return void 0;
41546
+ const layer = specLayerOf(ctx, name);
41547
+ if (layer === void 0 || !scene.layers.some((spec) => spec.name === layer)) return void 0;
41548
+ return {
41549
+ name,
41550
+ layer
41551
+ };
41552
+ }
41553
+ /**
41554
+ * Holds the leave loader of a scene that stands for its next switch: `world` builds the view of its `from`'s first
41555
+ * item in idle frames and keeps it hidden, so the frame the loader is due only shows it. A loader the scene before held
41556
+ * and this one does not hold is unmounted: the next switch does not use it. The one this switch showed, still fading
41557
+ * out with the veil, is held again once the fade is over. A projection another owner shows is never held.
41558
+ *
41559
+ * @param ctx - Domain context of the plugin.
41560
+ * @param scene - The scene that stands.
41561
+ * @param name - The projection its leave loader names; `undefined` when it holds none (no projection loader, a fast
41562
+ * walk, a world that does not run live, a headless app).
41563
+ */
41564
+ function holdLoader(ctx, scene, name) {
41565
+ const state = ctx.state;
41566
+ const want = name === void 0 ? void 0 : loaderToHold(ctx, scene, name);
41567
+ const held = state.held;
41568
+ if (held !== void 0 && held.name !== want?.name) {
41569
+ delete state.held;
41570
+ ctx.deps.world.projection.unmount([held.name]);
41571
+ }
41572
+ if (want === void 0) return;
41573
+ const fading = state.fading;
41574
+ if (fading !== void 0 && fading.name === want.name) {
41575
+ fading.rehold = want;
41576
+ return;
41577
+ }
41578
+ if (ctx.deps.world.projection.entitiesOf(want.name).length > 0) return;
41579
+ holdNow(ctx, want);
41580
+ }
41581
+ /**
41582
+ * Unmounts the loader held for the running switch when the scene it switches to lists it, before that scene is built
41583
+ * or mounted: the scene mounts it as its own, and a projection still held would show nothing there.
41584
+ *
41585
+ * @param ctx - Domain context of the plugin.
41586
+ * @param scene - The scene being switched to.
41587
+ */
41588
+ function releaseListed(ctx, scene) {
41589
+ const held = ctx.state.held;
41590
+ if (held === void 0 || !scene.projections.includes(held.name)) return;
41591
+ delete ctx.state.held;
41592
+ ctx.deps.world.projection.unmount([held.name]);
41593
+ }
41594
+ /**
41595
+ * Ends a fade: the frame callback goes, and the loader is unmounted, or held again for the scene that stands.
41596
+ *
41597
+ * @param ctx - Domain context of the plugin.
41598
+ * @param fading - The fade.
41599
+ */
41600
+ function endFade(ctx, fading) {
41601
+ fading.off();
41602
+ delete ctx.state.fading;
41603
+ if (fading.rehold === void 0) ctx.deps.world.projection.unmount([fading.name]);
41604
+ else holdNow(ctx, fading.rehold);
41605
+ }
41606
+ /**
41607
+ * The `signals` callback of a fade: counts the frame's milliseconds before the time scale (a game time frozen at
41608
+ * scale 0 counts one frame of the loop's rate) and ends the fade in the frame the veil's `outMs` ran out, before that
41609
+ * frame is drawn: about the frame the renderer takes the veil down, which keeps the layer unseen until then. A fade a
41610
+ * new switch ended earlier in the frame does nothing: `time` runs the callbacks it took at the frame start. Per frame
41611
+ * while a loader fades: a subtraction, no allocation.
41612
+ *
41613
+ * @param ctx - Domain context of the plugin.
41614
+ * @param fading - The fade.
41615
+ * @param time - The frame's `Time`.
41616
+ */
41617
+ function stepFade(ctx, fading, time) {
41618
+ if (ctx.state.fading !== fading) return;
41619
+ fading.leftMs -= time.scale > 0 ? time.delta / time.scale : frameMsOf(ctx);
41620
+ if (fading.leftMs > 0) return;
41621
+ endFade(ctx, fading);
41622
+ }
41623
+ /**
41624
+ * The swap came (F107 part 3): the loader the switch mounted or showed fades out with the veil above the scene that
41625
+ * stands, and is unmounted in the frame the veil's `outMs` ran out, or held again when the scene that stands leaves with
41626
+ * it too (`holdLoader`). A look without a veil, or with `outMs: 0`, leaves the screen at once, and so does its loader.
41627
+ *
41628
+ * @param ctx - Domain context of the plugin.
41629
+ * @param leaving - The look of the switch.
41630
+ */
41631
+ function landLoader(ctx, leaving) {
41632
+ const name = leaving.projection;
41633
+ if (name === void 0) return;
41634
+ delete leaving.projection;
41635
+ if (leaving.outMs <= 0) {
41636
+ ctx.deps.world.projection.unmount([name]);
41637
+ return;
41638
+ }
41639
+ const fading = {
41640
+ name,
41641
+ leftMs: leaving.outMs,
41642
+ off: noFrame
41643
+ };
41644
+ fading.off = ctx.deps.time.onFrame("signals", (time) => stepFade(ctx, fading, time));
41645
+ ctx.state.fading = fading;
41646
+ }
41647
+ /**
41648
+ * Ends a loader still fading out when the next switch starts: it is unmounted, or held again, before that switch shows
41649
+ * its look or touches the world.
41650
+ *
41651
+ * @param ctx - Domain context of the plugin.
41652
+ */
41653
+ function settleFade(ctx) {
41654
+ const fading = ctx.state.fading;
41655
+ if (fading !== void 0) endFade(ctx, fading);
41656
+ }
41657
+ /**
41658
+ * Forgets the held loader and a fade when the plugin stops: the frame callback of the fade goes. Nothing is unmounted:
41659
+ * a teardown context may not call another plugin, and `world.onStop` clears the projections.
41660
+ *
41661
+ * @param state - The plugin state.
41662
+ */
41663
+ function forgetLoader(state) {
41664
+ state.fading?.off();
41665
+ delete state.fading;
41666
+ delete state.held;
41667
+ }
41668
+ //#endregion
41669
+ //#region src/plugins/scenes/leave.ts
41670
+ /**
41671
+ * What a game gets when it writes nothing: black at 45 %, 50 ms in and 150 ms out, the engine's ring once the switch took
41672
+ * 400 ms. The level under `config.leave`, and where a part written over `false` starts. `index.ts` writes the same
41673
+ * value inline as the plugin's default config; a test pins the two equal.
41674
+ */
41675
+ const FALLBACK_LEAVE = Object.freeze({
41676
+ cover: Object.freeze({
41677
+ color: 0,
41678
+ alpha: .45,
41679
+ inMs: 50,
41680
+ outMs: 150
41681
+ }),
41682
+ loader: Object.freeze({ afterMs: 400 })
41683
+ });
41684
+ /**
41685
+ * Merges one level's veil over the one below, field by field. `false` turns it off; a veil written over `false`
41686
+ * starts from the engine's.
41687
+ *
41688
+ * @param below - The veil of the levels below, or `false`.
41689
+ * @param over - What this level writes: nothing, `false` or fields.
41690
+ * @returns The veil, or `false`.
41691
+ * @example
41692
+ * ```ts
41693
+ * coverOver(false, { alpha: 0.6 }); // { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }
41694
+ * ```
41695
+ */
41696
+ function coverOver(below, over) {
41697
+ if (over === void 0) return below;
41698
+ if (over === false) return false;
41699
+ const base = below === false ? FALLBACK_LEAVE.cover : below;
41700
+ return {
41701
+ color: over.color ?? base.color,
41702
+ alpha: over.alpha ?? base.alpha,
41703
+ inMs: over.inMs ?? base.inMs,
41704
+ outMs: over.outMs ?? base.outMs
41705
+ };
41706
+ }
41707
+ /**
41708
+ * The veil of a switch: the one the scene being left resolved, with the `color` and `alpha` of the scene being entered
41709
+ * over it, field by field, in a new object (the resolved veil may be the engine's frozen one). A veil turned off stays
41710
+ * off: the scene being entered never turns one on, and the times stay the left scene's.
41711
+ *
41712
+ * @param cover - The veil the scene being left resolved, or `false`.
41713
+ * @param enter - The `enter.cover` of the scene being entered.
41714
+ * @returns The veil, or `false`.
41715
+ * @example
41716
+ * ```ts
41717
+ * enteredCover(FALLBACK_LEAVE.cover, { color: 0x0b1020 }); // { color: 0x0b1020, alpha: 0.45, inMs: 50, outMs: 150 }
41718
+ * ```
41719
+ */
41720
+ function enteredCover(cover, enter) {
41721
+ if (cover === false || enter === void 0) return cover;
41722
+ return {
41723
+ color: enter.color ?? cover.color,
41724
+ alpha: enter.alpha ?? cover.alpha,
41725
+ inMs: cover.inMs,
41726
+ outMs: cover.outMs
41727
+ };
41728
+ }
41729
+ /**
41730
+ * The look of a loader: its projection, else its texture, else nothing (the engine's ring).
41731
+ *
41732
+ * @param loader - A level that names a look, or the level below.
41733
+ * @returns At most one of the two fields.
41734
+ * @example
41735
+ * ```ts
41736
+ * lookOf({ texture: "ui.loader.ring", projection: "loading" }); // { projection: "loading" }
41737
+ * ```
41738
+ */
41739
+ function lookOf(loader) {
41740
+ if (loader.projection !== void 0) return { projection: loader.projection };
41741
+ if (loader.texture !== void 0) return { texture: loader.texture };
41742
+ return {};
41743
+ }
41744
+ /**
41745
+ * Merges one level's loader over the one below. `afterMs` is a field of its own; `texture` and `projection` are one
41746
+ * choice: a level that names either replaces both of the level below. `false` turns it off; a loader written over
41747
+ * `false` starts from the engine's.
41748
+ *
41749
+ * @param below - The loader of the levels below, or `false`.
41750
+ * @param over - What this level writes: nothing, `false` or fields.
41751
+ * @returns The loader, or `false`.
41752
+ * @example
41753
+ * ```ts
41754
+ * loaderOver({ afterMs: 400, projection: "loading" }, { texture: "ui.loader.ring" }); // { afterMs: 400, texture: "ui.loader.ring" }
41755
+ * ```
41756
+ */
41757
+ function loaderOver(below, over) {
41758
+ if (over === void 0) return below;
41759
+ if (over === false) return false;
41760
+ const base = below === false ? FALLBACK_LEAVE.loader : below;
41761
+ const named = over.texture !== void 0 || over.projection !== void 0;
41762
+ return {
41763
+ afterMs: over.afterMs ?? base.afterMs,
41764
+ ...lookOf(named ? over : base)
41765
+ };
41766
+ }
41767
+ /**
41768
+ * Resolves what a switch shows over the scene being left: the scene's `leave` over the config's over the engine's,
41769
+ * field by field. `false` at a level turns both parts off there.
41770
+ *
41771
+ * @param config - `config.leave`.
41772
+ * @param scene - The `leave` of the scene being left.
41773
+ * @returns Both parts, each resolved or `false`; `undefined` when both are off.
41774
+ * @example
41775
+ * ```ts
41776
+ * leaveOf({ loader: false }, { cover: { alpha: 0.6 } }); // { cover: { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }, loader: false }
41777
+ * ```
41778
+ */
41779
+ function leaveOf(config, scene) {
41780
+ let cover = FALLBACK_LEAVE.cover;
41781
+ let loader = FALLBACK_LEAVE.loader;
41782
+ for (const level of [config, scene]) if (level === false) {
41783
+ cover = false;
41784
+ loader = false;
41785
+ } else if (level !== void 0) {
41786
+ cover = coverOver(cover, level.cover);
41787
+ loader = loaderOver(loader, level.loader);
41788
+ }
41789
+ if (cover === false && loader === false) return void 0;
41790
+ return {
41791
+ cover,
41792
+ loader
41793
+ };
41794
+ }
41795
+ /**
41796
+ * The loader projection a scene leaves with: the one its `leave` over `config.leave` names, when the loader is on.
41797
+ *
41798
+ * @param config - `config.leave`.
41799
+ * @param scene - The `leave` of the scene.
41800
+ * @returns The projection's name, or `undefined` for a ring, a texture, a loader turned off or no look at all.
41801
+ * @example
41802
+ * ```ts
41803
+ * loaderProjectionOf({ loader: { projection: "loading" } }, { cover: false }); // "loading"
41804
+ * ```
41805
+ */
41806
+ function loaderProjectionOf(config, scene) {
41807
+ const leave = leaveOf(config, scene);
41808
+ return leave === void 0 || leave.loader === false ? void 0 : leave.loader.projection;
41022
41809
  }
41023
41810
  /**
41024
41811
  * The renderer's loader of a resolved one: a texture as it is, nothing for the ring, and for a projection the `due`
41025
- * the renderer calls once the loader is due, which mounts it then: a switch done sooner never runs its `from` and
41026
- * `view`. A projection a scene of the switch lists is no loader: warned, the ring.
41812
+ * the renderer calls once the loader is due, which shows it then when the scene being left holds it built (F103), and
41813
+ * mounts it then otherwise: a switch done sooner shows nothing of it. Such a projection is fed the switch from now on
41814
+ * (F107 part 1). A projection a scene of the switch lists is no loader: warned, the ring.
41027
41815
  *
41028
41816
  * @param ctx - Domain context of the plugin.
41029
41817
  * @param loader - The resolved loader.
@@ -41049,9 +41837,10 @@ function loaderLook(ctx, loader, between, leaving) {
41049
41837
  });
41050
41838
  return { afterMs };
41051
41839
  }
41840
+ startFeeding(ctx, leaving, projection, between);
41052
41841
  return {
41053
41842
  afterMs,
41054
- due: () => mountLoader(ctx, projection, from, leaving)
41843
+ due: () => dueLoader(ctx, projection, from, leaving)
41055
41844
  };
41056
41845
  }
41057
41846
  /**
@@ -41071,8 +41860,9 @@ function leftScene(ctx, run) {
41071
41860
  }
41072
41861
  /**
41073
41862
  * Shows the veil and the loader of a switch that starts now, before its bundles are awaited: the scene being left
41074
- * decides. A loader projection is mounted only once its loader is due. An abort of the node drops both at once, from
41075
- * its listener. The look keeps the node's signal, so the `scene` stage of the same node takes it over.
41863
+ * decides, and the scene being entered sets the veil's colour and alpha (`enter.cover`). A loader projection is fed
41864
+ * the switch from now on, and shown or mounted only once its loader is due. An abort of the node drops both at once,
41865
+ * from its listener. The look keeps the node's signal, so the `scene` stage of the same node takes it over.
41076
41866
  *
41077
41867
  * @param ctx - Domain context of the plugin.
41078
41868
  * @param scene - The scene being switched to.
@@ -41084,15 +41874,17 @@ function startLeave(ctx, scene, run) {
41084
41874
  if (from === void 0) return void 0;
41085
41875
  const leave = leaveOf(ctx.config.leave, from.leave);
41086
41876
  if (leave === void 0) return void 0;
41877
+ const cover = enteredCover(leave.cover, scene.enter?.cover);
41087
41878
  const listening = new AbortController();
41088
41879
  const leaving = {
41089
41880
  signal: run.signal,
41090
41881
  to: scene.id,
41091
41882
  done: false,
41883
+ outMs: cover === false ? 0 : cover.outMs,
41092
41884
  off: () => listening.abort()
41093
41885
  };
41094
41886
  const look = {};
41095
- if (leave.cover !== false) look.cover = leave.cover;
41887
+ if (cover !== false) look.cover = cover;
41096
41888
  if (leave.loader !== false) look.loader = loaderLook(ctx, leave.loader, {
41097
41889
  from,
41098
41890
  to: scene
@@ -41144,9 +41936,11 @@ function dropLeftOver(ctx, run) {
41144
41936
  if (leaving !== void 0 && leaving.signal !== run.signal) endLeave(ctx, leaving, "drop");
41145
41937
  }
41146
41938
  /**
41147
- * Ends the look of a switch once: `"land"` at the swap (the loader goes, the veil fades out over the next scene),
41148
- * `"drop"` on an abort or a throw (both go at once). A loader projection mounted for the wait is unmounted. A look
41149
- * ended already, or a switch that showed nothing, is left alone.
41939
+ * Ends the look of a switch once: `"land"` at the swap (the veil fades out over the next scene, and a loader
41940
+ * projection mounted or shown for the wait fades out with it and is unmounted after the veil's `outMs`), `"drop"` on an
41941
+ * abort or a throw (both go at once, the loader projection unmounted). Either ends the feeding of its loader: the look
41942
+ * leaves the state, where the hooks of `assets` find it, and a fading loader keeps the last value fed. A look ended
41943
+ * already, or a switch that showed nothing, is left alone.
41150
41944
  *
41151
41945
  * @param ctx - Domain context of the plugin.
41152
41946
  * @param leaving - The look of the switch.
@@ -41158,9 +41952,13 @@ function endLeave(ctx, leaving, how) {
41158
41952
  leaving.off();
41159
41953
  if (ctx.state.leaving === leaving) delete ctx.state.leaving;
41160
41954
  const leave = ctx.deps.renderer.sync.leave;
41161
- if (how === "land") leave.land();
41162
- else leave.drop();
41163
- unmountLoader(ctx, leaving);
41955
+ if (how === "land") {
41956
+ leave.land();
41957
+ landLoader(ctx, leaving);
41958
+ } else {
41959
+ leave.drop();
41960
+ dropLoader(ctx, leaving);
41961
+ }
41164
41962
  }
41165
41963
  /**
41166
41964
  * Forgets the look of a running switch when the plugin stops: its abort listener goes and a later end does nothing.
@@ -41245,16 +42043,20 @@ function isName(value) {
41245
42043
  function isRecord$2(value) {
41246
42044
  return typeof value === "object" && value !== null && !Array.isArray(value);
41247
42045
  }
42046
+ /** The colour of a veil. */
42047
+ const COLOR_RULE = {
42048
+ ok: isColor$1,
42049
+ hint: "a colour from 0x000000 to 0xffffff"
42050
+ };
42051
+ /** The alpha of a veil. */
42052
+ const ALPHA_RULE = {
42053
+ ok: isAlpha,
42054
+ hint: "the alpha the veil fades in to, a number from 0 to 1"
42055
+ };
41248
42056
  /** The fields of a veil. */
41249
42057
  const COVER_RULES = Object.freeze({
41250
- color: {
41251
- ok: isColor$1,
41252
- hint: "a colour from 0x000000 to 0xffffff"
41253
- },
41254
- alpha: {
41255
- ok: isAlpha,
41256
- hint: "the alpha the veil fades in to, a number from 0 to 1"
41257
- },
42058
+ color: COLOR_RULE,
42059
+ alpha: ALPHA_RULE,
41258
42060
  inMs: {
41259
42061
  ok: isDuration,
41260
42062
  hint: "the milliseconds of the fade-in, 0 or more"
@@ -41264,6 +42066,11 @@ const COVER_RULES = Object.freeze({
41264
42066
  hint: "the milliseconds of the fade-out, 0 or more"
41265
42067
  }
41266
42068
  });
42069
+ /** The fields of the veil a scene being entered sets: its look, never its times. */
42070
+ const ENTER_COVER_RULES = Object.freeze({
42071
+ color: COLOR_RULE,
42072
+ alpha: ALPHA_RULE
42073
+ });
41267
42074
  /** The fields of a loader. */
41268
42075
  const LOADER_RULES = Object.freeze({
41269
42076
  afterMs: {
@@ -41331,6 +42138,24 @@ function checkLeave(where, leave) {
41331
42138
  checkPart(`${where}.cover`, leave.cover, COVER_RULES);
41332
42139
  checkPart(`${where}.loader`, leave.loader, LOADER_RULES);
41333
42140
  }
42141
+ /**
42142
+ * Checks a scene's `enter`: nothing, or an object whose `cover` is nothing or an object of a colour and an alpha from 0
42143
+ * to 1, by the rules of `leave.cover`.
42144
+ *
42145
+ * @param where - Where it was written, for the message: `Scene "night": enter`.
42146
+ * @param enter - What was written.
42147
+ * @throws {Error} For an `enter` that is no object, and for the first field of the wrong shape.
42148
+ * @example
42149
+ * ```ts
42150
+ * checkEnter('Scene "night": enter', { cover: { alpha: 2 } });
42151
+ * // throws '[game] Scene "night": enter.cover.alpha is 2.\n Give the alpha the veil fades in to, a number from 0 to 1.'
42152
+ * ```
42153
+ */
42154
+ function checkEnter(where, enter) {
42155
+ if (enter === void 0) return;
42156
+ if (!isRecord$2(enter)) throw wrong(where, enter, "{ cover }");
42157
+ checkPart(`${where}.cover`, enter.cover, ENTER_COVER_RULES);
42158
+ }
41334
42159
  //#endregion
41335
42160
  //#region src/plugins/scenes/switch.ts
41336
42161
  /**
@@ -41398,20 +42223,6 @@ async function untilAborted(ctx, bundles, signal) {
41398
42223
  if (load.failed && !signal.aborted) throw load.error;
41399
42224
  }
41400
42225
  /**
41401
- * Reads the committed state a scene's `bundles` gets: the frozen trees of the store, in a frozen
41402
- * wrapper. During the scene stage no node writes, so it is the state the node is entered with.
41403
- *
41404
- * @param ctx - Domain context of the plugin.
41405
- * @returns The committed `player` and `session`.
41406
- */
41407
- function committedState(ctx) {
41408
- const { player, session } = ctx.deps.model.store.snapshot();
41409
- return Object.freeze({
41410
- player,
41411
- session
41412
- });
41413
- }
41414
- /**
41415
42226
  * Tells whether two lists name the same bundles in the same order.
41416
42227
  *
41417
42228
  * @param left - One list.
@@ -41504,7 +42315,8 @@ function buildsAside(ctx, run) {
41504
42315
  /**
41505
42316
  * Builds the scene: aside on a live switch with a drawing renderer, resolving at the commit or
41506
42317
  * the abort; in one block otherwise, and when the world refuses to build it aside because a
41507
- * projection both scenes list is declared on other layer rules (named in a dev build).
42318
+ * projection both scenes list is declared on other layer rules (named in a dev build). A loader
42319
+ * held for this switch that the scene lists is unmounted first: the scene mounts it as its own.
41508
42320
  *
41509
42321
  * @param ctx - Domain context of the plugin.
41510
42322
  * @param scene - The scene whose bundles are there.
@@ -41514,6 +42326,7 @@ function buildsAside(ctx, run) {
41514
42326
  * @throws {Error} Whatever the mount or the build threw: a `view` or an unknown projection.
41515
42327
  */
41516
42328
  async function standUp(ctx, scene, named, run) {
42329
+ releaseListed(ctx, scene);
41517
42330
  if (buildsAside(ctx, run)) {
41518
42331
  const building = buildAside(ctx, scene, named, run.signal);
41519
42332
  if (building !== void 0) {
@@ -41531,7 +42344,8 @@ async function standUp(ctx, scene, named, run) {
41531
42344
  /**
41532
42345
  * Awaits every bundle the scene names and only then builds the scene. In live mode it waits between
41533
42346
  * the two for the textures of those bundles to reach the GPU; a fast walk does not, so tests and
41534
- * restores keep their pace. An aborted node, or a plugin stopped during the wait, returns without
42347
+ * restores keep their pace. Once the loads are in, a loader projection fed the switch counts every
42348
+ * loaded bundle whole. An aborted node, or a plugin stopped during the wait, returns without
41535
42349
  * touching anything. A live switch with a drawing renderer resolves at the commit of the scene
41536
42350
  * built aside, frames later.
41537
42351
  *
@@ -41544,18 +42358,46 @@ async function standUp(ctx, scene, named, run) {
41544
42358
  */
41545
42359
  async function loadAndStand(ctx, scene, named, run) {
41546
42360
  await untilAborted(ctx, named, run.signal);
41547
- if (run.mode === "live" && !run.signal.aborted) await untilWarmed(ctx, named, run.signal);
42361
+ const warmsFirst = run.mode === "live" && !run.signal.aborted;
42362
+ if (warmsFirst) countLoaded(ctx.state);
42363
+ if (warmsFirst) await untilWarmed(ctx, named, run.signal);
41548
42364
  const stopped = ctx.state.teardown === void 0;
41549
42365
  if (run.signal.aborted || stopped) return;
41550
42366
  await standUp(ctx, scene, named, run);
41551
42367
  }
41552
42368
  /**
41553
- * Switches to another scene: it takes over the veil and the loader the `begin` stage of the node
41554
- * showed over the scene being left for this scene (a cold first visit reacts in the next frame),
41555
- * or shows them now when that stage did not, or showed them for another scene, after reading what
41556
- * the scene names from the committed state. Then
41557
- * it awaits the bundles and builds the scene (`loadAndStand`). The look lands when the scene
41558
- * stands, and is dropped when the switch ends without it or throws.
42369
+ * Holds the loader of the scene that stands for its next switch (`loader.ts`): the projection its
42370
+ * leave loader names, on a live run while the world runs live and the renderer draws, the switches
42371
+ * that show a look. A fast walk, a world that does not run live and a headless app hold none.
42372
+ *
42373
+ * @param ctx - Domain context of the plugin.
42374
+ * @param scene - The scene that stands.
42375
+ * @param run - The runner's mode and signal.
42376
+ */
42377
+ function standLoader(ctx, scene, run) {
42378
+ holdLoader(ctx, scene, buildsAside(ctx, run) ? loaderProjectionOf(ctx.config.leave, scene.leave) : void 0);
42379
+ }
42380
+ /**
42381
+ * Holds the loader of the scene that still stands after a switch that ended without its swap: the drop unmounted the
42382
+ * loader the switch showed, and its next switch would mount it in the frame it is due. A loader the switch did not show
42383
+ * is held still; no scene stands: nothing.
42384
+ *
42385
+ * @param ctx - Domain context of the plugin.
42386
+ * @param run - The runner's mode and signal.
42387
+ */
42388
+ function standAgain(ctx, run) {
42389
+ if (ctx.state.held !== void 0) return;
42390
+ const current = ctx.state.current === void 0 ? void 0 : ctx.state.scenes.get(ctx.state.current);
42391
+ if (current !== void 0) standLoader(ctx, current, run);
42392
+ }
42393
+ /**
42394
+ * Switches to another scene: a loader still fading out after the last swap goes first. It takes
42395
+ * over the veil and the loader the `begin` stage of the node showed over the scene being left for
42396
+ * this scene (a cold first visit reacts in the next frame), or shows them now when that stage did
42397
+ * not, or showed them for another scene, after reading what the scene names from the committed
42398
+ * state. Then it awaits the bundles and builds the scene (`loadAndStand`). The look lands when the
42399
+ * scene stands, and the scene holds its own loader then; the look is dropped when the switch ends
42400
+ * without it or throws.
41559
42401
  *
41560
42402
  * @param ctx - Domain context of the plugin.
41561
42403
  * @param target - Id of the scene to mount.
@@ -41566,6 +42408,7 @@ async function loadAndStand(ctx, scene, named, run) {
41566
42408
  async function switchTo(ctx, target, run) {
41567
42409
  const scene = ctx.state.scenes.get(target);
41568
42410
  if (scene === void 0) throw new Error(`[game] Scene "${target}" is not registered.\n List it in the scenes of a feature.`);
42411
+ settleFade(ctx);
41569
42412
  let leaving = leaveFor(ctx, run, scene.id);
41570
42413
  try {
41571
42414
  const named = namedBundles(scene, committedState(ctx));
@@ -41573,9 +42416,13 @@ async function switchTo(ctx, target, run) {
41573
42416
  await loadAndStand(ctx, scene, named, run);
41574
42417
  } catch (error) {
41575
42418
  endLeave(ctx, leaving, "drop");
42419
+ standAgain(ctx, run);
41576
42420
  throw error;
41577
42421
  }
41578
- endLeave(ctx, leaving, ctx.state.current === scene.id ? "land" : "drop");
42422
+ const stands = ctx.state.current === scene.id;
42423
+ endLeave(ctx, leaving, stands ? "land" : "drop");
42424
+ if (stands) standLoader(ctx, scene, run);
42425
+ else standAgain(ctx, run);
41579
42426
  }
41580
42427
  /**
41581
42428
  * Reads again what the mounted scene names, at a node that keeps it: a bundle it names now and
@@ -41645,8 +42492,9 @@ function nextScene(ctx, node, run) {
41645
42492
  * downloads the bundles of the coming one, so a cold first visit reacts in the next frame. The
41646
42493
  * `scene` stage of the same node takes the look over, lands it at the swap or drops it. A node
41647
42494
  * that keeps the scene, the first scene of a run, a fast walk and an aborted node start nothing
41648
- * (`startLeave` decides the rest). A stage after `begin` that throws aborts the node, and the abort
41649
- * drops the look; one a node before left running all the same is dropped first.
42495
+ * (`startLeave` decides the rest). A loader still fading out after the last swap goes before the
42496
+ * look shows. A stage after `begin` that throws aborts the node, and the abort drops the look; one a
42497
+ * node before left running all the same is dropped first.
41650
42498
  *
41651
42499
  * @param ctx - Domain context of the plugin.
41652
42500
  * @param node - The node being entered.
@@ -41657,7 +42505,9 @@ function beginScene(ctx, node, run) {
41657
42505
  const target = nextScene(ctx, node, run);
41658
42506
  if (target === void 0 || target === ctx.state.current) return;
41659
42507
  const scene = ctx.state.scenes.get(target);
41660
- if (scene !== void 0) startLeave(ctx, scene, run);
42508
+ if (scene === void 0) return;
42509
+ settleFade(ctx);
42510
+ startLeave(ctx, scene, run);
41661
42511
  }
41662
42512
  //#endregion
41663
42513
  //#region src/plugins/scenes/lifecycle.ts
@@ -41767,9 +42617,10 @@ function startScenes(ctx) {
41767
42617
  /**
41768
42618
  * Removes the two `onEnter` callbacks in `onStop` and forgets every scene and the bundles the mounted
41769
42619
  * one named. A running build loses its frame callback and its switch returns; the look of a running
41770
- * switch loses its abort listener (the renderer drops it at its own stop). Nothing is unmounted
41771
- * or discarded: a teardown context may not call another plugin, and `world.onStop` clears every
41772
- * entity and the build table anyway.
42620
+ * switch loses its abort listener (the renderer drops it at its own stop), a loader fading out its
42621
+ * frame callback, and the held loader is forgotten. Nothing is unmounted or discarded: a teardown
42622
+ * context may not call another plugin, and `world.onStop` clears every entity and the build table
42623
+ * anyway.
41773
42624
  *
41774
42625
  * @param teardown - What the teardown context carries.
41775
42626
  * @param teardown.state - The plugin state.
@@ -41786,6 +42637,7 @@ function stopScenes(teardown) {
41786
42637
  dropBuild(state.build);
41787
42638
  delete state.build;
41788
42639
  forgetLeave(state);
42640
+ forgetLoader(state);
41789
42641
  state.scenes.clear();
41790
42642
  state.current = void 0;
41791
42643
  state.pending = void 0;
@@ -41883,6 +42735,7 @@ const scenesPlugin = /*#__PURE__*/ createPlugin$1("scenes", {
41883
42735
  events: (register) => register.map({ "scenes:changed": "The mounted scene changed" }),
41884
42736
  createState: createScenesState,
41885
42737
  api: createScenesApi,
42738
+ hooks: createHandlers$4,
41886
42739
  onInit: ({ config }) => checkConfig(config),
41887
42740
  onStart: startScenes,
41888
42741
  onStop: ({ state }) => stopScenes({ state })
@@ -50356,19 +51209,28 @@ function notifyTap(ctx, entity) {
50356
51209
  * and forgot to name it — so it is reported with the projection it came from and still offered,
50357
51210
  * which keeps the return value honest.
50358
51211
  *
51212
+ * A press the narrow of a guide drops — another intent, or the allowed intent with another
51213
+ * payload (a drop on the wrong cell) — answers the guide's `blocked` instead, once, when the gate
51214
+ * is open and the guide names one. A closed gate holds the press as it is and converts nothing.
51215
+ * The gate's state is read only for a refused answer, never for an accepted one.
51216
+ *
50359
51217
  * @param ctx - Domain context of the input plugin.
50360
51218
  * @param entity - The view the answer came from, for the warning.
50361
51219
  * @param answer - The answer one of the builders produced.
50362
- * @returns What `flow.gate.answer` returned.
51220
+ * @returns What `flow.gate.answer` returned: for the answer, or for `blocked` in its place.
50363
51221
  */
50364
51222
  function submit(ctx, entity, answer) {
50365
51223
  if (answer.intent === "") ctx.log.warn("input: empty intent", { view: ctx.deps.world.projection.keyOf(entity) });
50366
- return ctx.deps.flow.gate.answer(answer);
51224
+ const gate = ctx.deps.flow.gate;
51225
+ if (gate.answer(answer)) return true;
51226
+ const { open, blocked } = gate.state();
51227
+ return open && blocked !== void 0 && gate.answer(blocked);
50367
51228
  }
50368
51229
  /**
50369
51230
  * Answers a press the lock of a guide kept from every view: the gate's `blocked`, the answer the
50370
51231
  * running guide names for a press outside its window, with its payload. A guide that names none
50371
- * drops the press: the gate is not called.
51232
+ * drops the press: the gate is not called. A press inside the window that the narrow drops answers
51233
+ * `blocked` through `submit`.
50372
51234
  *
50373
51235
  * @param ctx - Domain context of the input plugin.
50374
51236
  * @returns What `flow.gate.answer` returned; `false` when the guide names no `blocked`.
@@ -52536,7 +53398,8 @@ function setAwake(ctx, provider, on) {
52536
53398
  /**
52537
53399
  * @file platform plugin — API factory, the Back chain and the exit. One press runs three steps and
52538
53400
  * the first that takes it wins: the Escape button of the top popup, the intent `back` of the
52539
- * resting node, the provider leaving the app. `exit()` is that last step alone.
53401
+ * resting node, the provider leaving the app. A guide that narrows the open gate takes it first.
53402
+ * `exit()` is that last step alone.
52540
53403
  */
52541
53404
  /** The intent a resting node lists to take the Back press itself. */
52542
53405
  const BACK_INTENT = "back";
@@ -52553,19 +53416,28 @@ function leave(ctx) {
52553
53416
  }
52554
53417
  /**
52555
53418
  * Runs the Back chain once. `back()` and the provider's `onBack` both go through here, so a test
52556
- * and a real press end the same way. Escape is what ui answers with the `escape` button of its
52557
- * top root; it also ends the editing of a text field. While the graph moves between nodes the gate
52558
- * is closed: it holds the answer for the next gate (one frame, or `flow.holdMs`), so the press
52559
- * counts as taken and never leaves the app in the middle of a step.
53419
+ * and a real press end the same way. A guide that narrows the open gate owns the screen and takes
53420
+ * Back before step 1: the press is offered as the intent `back`, which only a guide that allows
53421
+ * `back` takes, and counts as taken either way. It never presses Escape, so an `escape` button on
53422
+ * a guided screen never turns Back into the guide's `blocked`, and it never leaves the app.
53423
+ * Otherwise Escape is what ui answers with the `escape` button of its top root; it also ends the
53424
+ * editing of a text field. While the graph moves between nodes the gate is closed: it holds the
53425
+ * answer for the next gate (one frame, or `flow.holdMs`), so the press counts as taken and never
53426
+ * leaves the app in the middle of a step.
52560
53427
  *
52561
53428
  * @param ctx - Kernel context of the platform plugin.
52562
53429
  * @returns What took the press, `"none"` without a provider.
52563
53430
  */
52564
53431
  function runBack(ctx) {
52565
53432
  if (ctx.config.provider === void 0) return "none";
52566
- if (ctx.require(inputPlugin).pressKey("Escape")) return "popup";
52567
53433
  const gate = ctx.require(flowPlugin).gate;
52568
- if (gate.answer({ intent: BACK_INTENT }) || !gate.state().open) return "intent";
53434
+ const before = gate.state();
53435
+ if (before.open && before.narrowed) {
53436
+ gate.answer({ intent: BACK_INTENT });
53437
+ return "intent";
53438
+ }
53439
+ if (ctx.require(inputPlugin).pressKey("Escape")) return "popup";
53440
+ if (gate.answer({ intent: BACK_INTENT }) || !before.open) return "intent";
52569
53441
  leave(ctx);
52570
53442
  return "exit";
52571
53443
  }
@@ -68817,14 +69689,15 @@ function namesOf(id, layers, projections) {
68817
69689
  * `lift` is not among them does not compile — and throws here for a caller without types.
68818
69690
  * `bundles` names bundles that depend on the committed state: the scene is mounted once those
68819
69691
  * are in too. `leave` is what a live switch shows over the scene when it is left, merged over the
68820
- * config's: `false` shows nothing.
69692
+ * config's: `false` shows nothing. `enter` sets the colour and the alpha of the veil of every live switch to the scene.
68821
69693
  *
68822
69694
  * @param id - Id of the scene. A node names it with `defineNode({ scene: id })`.
68823
69695
  * @param scene - The bundle, the optional bundles of state, the layers, the projections, the
68824
- * optional music key and the optional `leave`.
69696
+ * optional music key, the optional `leave` and the optional `enter`.
68825
69697
  * @returns The scene as frozen data, ready for the `scenes` key of a feature.
68826
69698
  * @throws {Error} For an integer-like layer name, for a `layer` or `lift` that is not declared, for two HUD layers,
68827
- * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` of the wrong shape.
69699
+ * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` or an `enter` of the wrong
69700
+ * shape.
68828
69701
  * @example
68829
69702
  * ```ts
68830
69703
  * // features/board/view/scene.ts of a game.
@@ -68857,12 +69730,21 @@ function namesOf(id, layers, projections) {
68857
69730
  * projections: [],
68858
69731
  * leave: { cover: { color: 0x0b1020, alpha: 0.6 }, loader: { texture: "ui.loader.ring" } }
68859
69732
  * }).leave; // { cover: { color: 0x0b1020, alpha: 0.6 }, loader: { texture: "ui.loader.ring" } }
69733
+ *
69734
+ * // Every switch to the night dims the scene being left in navy at 70 %, whatever that scene leaves with.
69735
+ * defineScene("night", {
69736
+ * bundle: "night",
69737
+ * layers: { sky: {} },
69738
+ * projections: [],
69739
+ * enter: { cover: { color: 0x0b1020, alpha: 0.7 } }
69740
+ * }).enter; // { cover: { color: 0x0b1020, alpha: 0.7 } }
68860
69741
  * ```
68861
69742
  */
68862
69743
  function defineScene(id, scene) {
68863
69744
  const layers = layersOf(id, scene.layers);
68864
69745
  const projections = scene.projections;
68865
69746
  checkLeave(`Scene "${id}": leave`, scene.leave);
69747
+ checkEnter(`Scene "${id}": enter`, scene.enter);
68866
69748
  return Object.freeze({
68867
69749
  id,
68868
69750
  bundle: scene.bundle,
@@ -68870,7 +69752,8 @@ function defineScene(id, scene) {
68870
69752
  layers: Object.freeze(layers),
68871
69753
  projections: Object.freeze(namesOf(id, layers, projections)),
68872
69754
  ...scene.bundles === void 0 ? {} : { bundles: scene.bundles },
68873
- ...scene.leave === void 0 ? {} : { leave: scene.leave }
69755
+ ...scene.leave === void 0 ? {} : { leave: scene.leave },
69756
+ ...scene.enter === void 0 ? {} : { enter: scene.enter }
68874
69757
  });
68875
69758
  }
68876
69759
  /**