@moku-labs/game 0.15.94 → 0.15.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/app/page.d.mts +1 -1
  2. package/dist/app/page.mjs +1 -1
  3. package/dist/app/system.d.mts +3 -3
  4. package/dist/app.d.mts +3 -3
  5. package/dist/app.mjs +1 -1
  6. package/dist/assets.d.mts +1 -1
  7. package/dist/{commands-B05keaNh.d.mts → commands-DQXSQB_C.d.mts} +5 -5
  8. package/dist/control.d.mts +4 -4
  9. package/dist/{define-C5oKi9M2.d.mts → define-hPbGjPAY.d.mts} +2 -2
  10. package/dist/{headless-rXLWKvZq.d.mts → headless-Co3SEFi5.d.mts} +1 -1
  11. package/dist/{index-DuiCPP3n.d.mts → index-U_AN5j0L.d.mts} +5 -4
  12. package/dist/index.d.mts +4 -4
  13. package/dist/index.mjs +2 -2
  14. package/dist/inspect.d.mts +6 -6
  15. package/dist/inspect.mjs +1 -1
  16. package/dist/jsx-dev-runtime.d.mts +1 -1
  17. package/dist/jsx-runtime.d.mts +1 -1
  18. package/dist/{runtime-DGpGGQAh.d.mts → runtime-B69fIYx_.d.mts} +1 -1
  19. package/dist/{sources-DIl02J8z.mjs → sources-Cqqz-0-b.mjs} +1 -1
  20. package/dist/{src-CkBzjWRd.mjs → src-C32BYdgi.mjs} +792 -196
  21. package/dist/testing.d.mts +4 -4
  22. package/dist/testing.mjs +1 -1
  23. package/dist/{types-CSkVNKPZ.d.mts → types-BE6tcAFX.d.mts} +2 -2
  24. package/dist/{types-CA98KS-U.d.mts → types-Brsj29M-.d.mts} +4 -4
  25. package/dist/{types-BrEqXapX.d.mts → types-Cffn9Rbm.d.mts} +18 -9
  26. package/dist/{types-DhCTe-kr.d.mts → types-L3E-YS4N.d.mts} +46 -3
  27. package/dist/{types-D33h-CNj.d.mts → types-qCcSw8YI.d.mts} +61 -16
  28. package/dist/{visual-BfN2jgqg.d.mts → visual-72OVwKM4.d.mts} +6 -6
  29. package/dist/{visual-Cl7Q7pO9.mjs → visual-DhqD6W3v.mjs} +15 -5
  30. package/dist/visual.d.mts +1 -1
  31. package/dist/visual.mjs +1 -1
  32. package/llms.txt +4 -4
  33. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { r as systemSource, t as memory } from "./memory-CWlqhS7l.mjs";
3
3
  import { a as finishDrafts, i as enableDraftPatches, n as deepFreeze$1, o as openDrafts, r as dropDrafts } from "./drafts-BawpSaVp.mjs";
4
4
  import { _ as compact, c as collectFlows, d as findNode, f as framePath, g as slotNames, h as restlessCapOf, i as servePaused, l as describeGraph, m as isRestCheckpoint, n as captureFrame, o as epochOf, p as graphHash, r as serveCaptures, s as pageNow$1, t as cancelCaptures, v as pushEntry } from "./capture-BtS6_oWr.mjs";
5
- import { $ as Shape, A as Countdown, B as isLeaving, C as uiFor, D as isTextFormat, E as formatBound, G as rootPoseInto, H as parentOf$1, J as HudPart, K as rootPoseOf, L as readStyle, N as builtInStyles, O as unitOf, Q as Parent, R as textFor, U as poseUnder, V as localPoseOf, W as rootPointOf, X as Overlay, Y as NineSlice, Z as OverlayLevel, _ as LocalWrite, a as fieldsLeftAlone, at as Exiting, b as UI_OWNER, c as namesFormat, ct as Order, d as visualOf$1, et as Sprite, f as visualRectOf, ft as resource, g as Escapable, h as DebugTrigger, ht as tag, i as drawnRect, j as Text, k as wholeValue, l as restValueOf, lt as Tree, m as Covered, mt as systemsFor, n as CONTENT$1, nt as arcDefaults, o as fitScaleOf, ot as Layer, p as Box, pt as system, q as Display, r as bindOf, rt as componentsFor, s as livePatch, st as Now, tt as Transform, u as samePose, ut as component, v as Scroll, x as UiCounters, y as ScrollState, z as applyPose } from "./visual-Cl7Q7pO9.mjs";
5
+ import { $ as Shape, A as Countdown, B as isLeaving, C as uiFor, D as isTextFormat, E as formatBound, G as rootPoseInto, H as parentOf$1, J as HudPart, K as rootPoseOf, L as readStyle, N as builtInStyles, O as unitOf, Q as Parent, R as textFor, U as poseUnder, V as localPoseOf, W as rootPointOf, X as Overlay, Y as NineSlice, Z as OverlayLevel, _ as LocalWrite, a as fieldsLeftAlone, at as Exiting, b as UI_OWNER, c as namesFormat, ct as Order, d as visualOf$1, et as Sprite, f as visualRectOf, ft as resource, g as Escapable, h as DebugTrigger, ht as tag, i as drawnRect, j as Text, k as wholeValue, l as restValueOf, lt as Tree, m as Covered, mt as systemsFor, n as CONTENT$1, nt as arcDefaults, o as fitScaleOf, ot as Layer, p as Box, pt as system, q as Display, r as bindOf, rt as componentsFor, s as livePatch, st as Now, tt as Transform, u as samePose, ut as component, v as Scroll, x as UiCounters, y as ScrollState, z as applyPose } from "./visual-DhqD6W3v.mjs";
6
6
  import { a as isDev } from "./dev-BNndV-hU.mjs";
7
7
  import { n as isComponentDefinition } from "./component-DGg5DqKK.mjs";
8
8
  import { n as flatten } from "./flatten-nUX9PpGo.mjs";
@@ -17949,6 +17949,16 @@ function setOrigins(slots, x, y) {
17949
17949
  }
17950
17950
  }
17951
17951
  /**
17952
+ * Tells whether a record's filters read where its picture is drawn on the canvas: a placed filter, or a body that reads
17953
+ * the screen. Such a record is never drawn scaled, owes its output to a move and steps as a placed one does.
17954
+ *
17955
+ * @param record - The record.
17956
+ * @returns True for a `"placed"` or a `"screen"` record.
17957
+ */
17958
+ function readsPlace(record) {
17959
+ return record.category !== "local";
17960
+ }
17961
+ /**
17952
17962
  * Stage 3, the filter output: the stand-in, carrying the record's filters, is rendered at `M3 = translate(Ps, Ps)`
17953
17963
  * into the output texture. A placed filter's origin gets the picture's canvas origin first, `O + Δ`; a local one
17954
17964
  * writes nothing.
@@ -17969,7 +17979,7 @@ function renderStage3(kctx, pixi, matrices, record, now) {
17969
17979
  const output = outputOf(kctx, pixi, record, now.r, now.P);
17970
17980
  const standIn = standInOf(pixi, record);
17971
17981
  const Ps = key[KEY.Ps] ?? 0;
17972
- if (record.category === "placed") setOrigins(record.slots, (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0), (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0));
17982
+ if (readsPlace(record)) setOrigins(record.slots, (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0), (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0));
17973
17983
  matrices.m3.set(1, 0, 0, 1, Ps, Ps);
17974
17984
  if (!kctx.host.renderTo(standIn, output, matrices.m3, true)) return false;
17975
17985
  key[KEY.r] = now.r;
@@ -19163,6 +19173,7 @@ const WHY = {
19163
19173
  off: 1,
19164
19174
  backdrop: 2,
19165
19175
  filterBlend: 3,
19176
+ cacheFalse: 4,
19166
19177
  hidden: 5,
19167
19178
  fadedOut: 6,
19168
19179
  topBlend: 7,
@@ -19405,16 +19416,16 @@ function drawnAnyway(kctx, node) {
19405
19416
  return node.renderable || kctx.sync.hiddenOnlyAmong(kctx.hidden, node, DRAWN_ANYWAY);
19406
19417
  }
19407
19418
  /**
19408
- * Tells whether an ancestor filters a placed record's view: a filter of its own or its kept picture. Live, the canvas
19409
- * position of a placed filter is then relative to that filter's texture.
19419
+ * Tells whether an ancestor filters a record's view whose filters read their place: a filter of its own or its kept
19420
+ * picture. Live, the canvas position of a placed filter is then relative to that filter's texture.
19410
19421
  *
19411
19422
  * @param kctx - The kept context.
19412
19423
  * @param record - The record.
19413
19424
  * @param node - The ancestor.
19414
- * @returns True when the record is placed and the ancestor filters it.
19425
+ * @returns True when the record reads its place and the ancestor filters it.
19415
19426
  */
19416
19427
  function filtersPlaced(kctx, record, node) {
19417
- return record.category === "placed" && (holdsFilters(node) || kctx.state.byTop.get(node)?.mode === "kept");
19428
+ return readsPlace(record) && (holdsFilters(node) || kctx.state.byTop.get(node)?.mode === "kept");
19418
19429
  }
19419
19430
  /**
19420
19431
  * Tells whether an ancestor draws what is under it as a picture would: visible, untinted, blending normally, drawn (an
@@ -19459,8 +19470,8 @@ function ancestorsWhy(kctx, record, stage, stack) {
19459
19470
  }
19460
19471
  /**
19461
19472
  * Whether a record may be kept this frame (P4.1): the switch on, an enabled filter, filters that draw like a picture, a
19462
- * top and a visual that blend normally (the visual sits inside the wrapper of a kept bare view, D4), a top that is
19463
- * drawn, ancestors that draw it as a picture would.
19473
+ * body that reads the screen only on its quad, a top and a visual that blend normally (the visual sits inside the
19474
+ * wrapper of a kept bare view, D4), a top that is drawn, ancestors that draw it as a picture would.
19464
19475
  *
19465
19476
  * @param kctx - The kept context.
19466
19477
  * @param record - The record.
@@ -19473,6 +19484,7 @@ function eligible(kctx, record, view, stack) {
19473
19484
  if (!keepingOn(kctx) || stage === void 0 || stack.enabled === 0) return WHY.off;
19474
19485
  const filters = filtersWhy(record.slots);
19475
19486
  if (filters !== 0) return filters;
19487
+ if (record.category === "screen" && !shadeFits(kctx, record, stack)) return WHY.cacheFalse;
19476
19488
  const picture = pictureWhy(record.top, view);
19477
19489
  if (picture !== 0) return picture;
19478
19490
  if (!topDrawn(kctx.sync, view)) return WHY.hidden;
@@ -19981,9 +19993,20 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
19981
19993
  return ok;
19982
19994
  }
19983
19995
  /**
19996
+ * Tells whether the record being stepped may be kept on its mesh alone: a placed view under a filter (`NOW.under`), where
19997
+ * a stage 3 picture would hold the wrong place, or a body that reads the screen, whose stage 3 would read the picture's
19998
+ * target. Its first take goes on the mesh, and it does not count its way there.
19999
+ *
20000
+ * @param record - The record.
20001
+ * @returns True when it may draw no other way.
20002
+ */
20003
+ function quadOnly(record) {
20004
+ return NOW.under || record.category === "screen";
20005
+ }
20006
+ /**
19984
20007
  * Settles what a take draws through, before its output: a stack that stopped fitting leaves before anything is drawn
19985
- * for it, and the frame draws a sprite of stage 3. Under a filter there is no sprite to draw, so a picture that rendered
19986
- * goes on the mesh; the sprite a mesh takes the place of may not exist yet.
20008
+ * for it, and the frame draws a sprite of stage 3. Under a filter, and for a body that reads the screen, there is no
20009
+ * sprite to draw, so a picture that rendered goes on the mesh; the sprite a mesh takes the place of may not exist yet.
19987
20010
  *
19988
20011
  * @param kctx - The kept context.
19989
20012
  * @param pixi - The module that draws.
@@ -19993,7 +20016,7 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
19993
20016
  function meshForTake(kctx, pixi, record, ok) {
19994
20017
  if (record.shaded && !shadeFits(kctx, record, NOW)) leaveShade(record);
19995
20018
  const quad = enabledSlot(record.slots)?.quad;
19996
- if (!ok || !NOW.under || record.shaded || quad === void 0) return;
20019
+ if (!ok || !quadOnly(record) || record.shaded || quad === void 0) return;
19997
20020
  quadDrawing(pixi, record, record.s3 ?? pixi.Texture.EMPTY);
19998
20021
  enterShade(kctx, pixi, record, quad, NOW);
19999
20022
  }
@@ -20089,7 +20112,7 @@ function scaledQuad(key, Ps, inverse, local) {
20089
20112
  */
20090
20113
  function scalable(record, stepped) {
20091
20114
  const { key } = record;
20092
- if (record.dirtyS1 || record.cut || record.category === "placed" || !stepped && key[KEY.rs] !== NOW.rs) return false;
20115
+ if (record.dirtyS1 || record.cut || readsPlace(record) || !stepped && key[KEY.rs] !== NOW.rs) return false;
20093
20116
  const taken = Math.abs((key[KEY.a] ?? 1) * (key[KEY.d] ?? 1) - (key[KEY.b] ?? 0) * (key[KEY.c] ?? 0));
20094
20117
  const now = Math.abs(NOW.a * NOW.d - NOW.b * NOW.c);
20095
20118
  const limit = 4;
@@ -20241,14 +20264,14 @@ function wrapBare(kctx, record, view) {
20241
20264
  /**
20242
20265
  * Tells whether a move of a live record's linear part or stack resolution resets its still frames (F113): a zoom or a
20243
20266
  * turn of an ancestor does not, the picture is taken at it and drawn scaled (F67). It does for a new stack resolution,
20244
- * a `"placed"` record (never drawn scaled), a calm one (a picture that churned waits for real rest) and one cut to the
20245
- * canvas at its last take or refusal (never drawn scaled either).
20267
+ * a record that reads its place, `"placed"` or `"screen"` (never drawn scaled), a calm one (a picture that churned
20268
+ * waits for real rest) and one cut to the canvas at its last take or refusal (never drawn scaled either).
20246
20269
  *
20247
20270
  * @param record - The record, live, whose linear part or stack resolution moved since the last frame.
20248
20271
  * @returns True when the move resets its still frames.
20249
20272
  */
20250
20273
  function linearResets(record) {
20251
- return record.key[KEY.seenRs] !== NOW.rs || record.category === "placed" || record.calm || record.cut;
20274
+ return record.key[KEY.seenRs] !== NOW.rs || readsPlace(record) || record.calm || record.cut;
20252
20275
  }
20253
20276
  /**
20254
20277
  * The still frames a live record waits before it is taken: eight after churning, none for a stack drawn direct (its
@@ -20374,7 +20397,8 @@ function retakeOrGoLive(kctx, pixi, matrices, record, view, why) {
20374
20397
  /**
20375
20398
  * A stage-1 change of a kept record (P4.3): retaken, or after three in a row drawn live and calm, so it stands still
20376
20399
  * for eight frames before the next take. Under a filter it is always retaken: live, a body that reads its place reads
20377
- * another one, and a glow would jump; only a refused take or an eviction goes live there.
20400
+ * another one, and a glow would jump; only a refused take or an eviction goes live there. A body that reads the screen
20401
+ * churns as any record does: live, it reads the same canvas.
20378
20402
  *
20379
20403
  * @param kctx - The kept context.
20380
20404
  * @param pixi - The module that draws.
@@ -20405,7 +20429,7 @@ function churn(kctx, pixi, matrices, record, view, why) {
20405
20429
  function retakeWhy(record, stepped) {
20406
20430
  if (!stepped && record.key[KEY.rs] !== NOW.rs) return RETAKE.resolution;
20407
20431
  if (record.dirtyS1) return RETAKE.mark;
20408
- return record.cut || record.category === "placed" ? RETAKE.placedMove : RETAKE.scaleLimit;
20432
+ return record.cut || readsPlace(record) ? RETAKE.placedMove : RETAKE.scaleLimit;
20409
20433
  }
20410
20434
  /**
20411
20435
  * What a refresh of a kept record owes itself to, read before the render writes its keys. Under `hold` the resolution
@@ -20464,14 +20488,14 @@ function canvasChanged(kctx, key) {
20464
20488
  /**
20465
20489
  * Tells whether a step of the renderer resolution passed over a kept picture (F126): drawn at another resolution than
20466
20490
  * the canvas, with a stack that followed the canvas there: a resolution of its own, or `"inherit"`. A picture cut to the
20467
- * canvas or placed, a filter that wrote its own resolution and a mixed stack whose fixed resolution the step crossed
20468
- * are no step: their change is read as a change of the stack.
20491
+ * canvas or one that reads its place, a filter that wrote its own resolution and a mixed stack whose fixed resolution
20492
+ * the step crossed are no step: their change is read as a change of the stack.
20469
20493
  *
20470
20494
  * @param record - The record, kept.
20471
20495
  * @returns True when the picture was stepped over.
20472
20496
  */
20473
20497
  function resolutionStepped(record) {
20474
- if (record.cut || record.category === "placed") return false;
20498
+ if (record.cut || readsPlace(record)) return false;
20475
20499
  const { key } = record;
20476
20500
  const drawn = drawnResolution(key, record.direct);
20477
20501
  if (drawn === NOW.r) return false;
@@ -20617,7 +20641,7 @@ function outputOwed(record, hold) {
20617
20641
  const { key } = record;
20618
20642
  const resolutionOwed = !hold && NOW.r !== key[KEY.r];
20619
20643
  const paddingOwed = hold && record.direct ? NOW.P !== 0 : NOW.P !== key[KEY.P];
20620
- const placedMoved = record.category === "placed" && (NOW.tx !== key[KEY.s3Tx] || NOW.ty !== key[KEY.s3Ty]);
20644
+ const placedMoved = readsPlace(record) && (NOW.tx !== key[KEY.s3Tx] || NOW.ty !== key[KEY.s3Ty]);
20621
20645
  return record.dirtyS3 || resolutionOwed || paddingOwed || placedMoved;
20622
20646
  }
20623
20647
  /**
@@ -20669,7 +20693,7 @@ function refreshOutput(kctx, pixi, matrices, record, view, hold) {
20669
20693
  const fits = shadeFits(kctx, record, NOW);
20670
20694
  const unfit = record.shaded && !fits;
20671
20695
  if (unfit) leaveShade(record);
20672
- const unplaced = unfit || NOW.under && !record.shaded;
20696
+ const unplaced = unfit || quadOnly(record) && !record.shaded;
20673
20697
  const owed = Math.max(stagesOwed(record, hold), unplaced ? OWED.output : OWED.none);
20674
20698
  if (owed === OWED.none) return leaveAtRest(kctx, pixi, matrices, record, view, hold);
20675
20699
  const chain = owed === OWED.chain;
@@ -20727,8 +20751,8 @@ function redrawShade(kctx, pixi, matrices, record) {
20727
20751
  /**
20728
20752
  * Counts an output owed by a record on its sprite, and puts the record on its mesh when it is due: stage 3 alone was owed
20729
20753
  * more than `QUAD_AFTER` times without a gap of `CALM_AFTER` frames, and it fits. The gap rule, not a reset on a quiet
20730
- * frame: a tween that writes every second frame reaches the mode. Under a filter nothing is counted: it may draw no other
20731
- * way. A shaded record counts nothing.
20754
+ * frame: a tween that writes every second frame reaches the mode. Under a filter and for a body that reads the screen
20755
+ * nothing is counted: it may draw no other way. A shaded record counts nothing.
20732
20756
  *
20733
20757
  * @param kctx - The kept context.
20734
20758
  * @param pixi - The module that draws.
@@ -20743,25 +20767,28 @@ function enterShadeWhenDue(kctx, pixi, record, owed, fits) {
20743
20767
  record.outputRuns = frame - record.outputAt > 8 ? 1 : record.outputRuns + 1;
20744
20768
  record.outputAt = frame;
20745
20769
  const quad = enabledSlot(record.slots)?.quad;
20746
- if (!(NOW.under || owed === OWED.output && record.outputRuns > 2) || !fits || quad === void 0) return false;
20770
+ if (!(quadOnly(record) || owed === OWED.output && record.outputRuns > 2) || !fits || quad === void 0) return false;
20747
20771
  return enterShade(kctx, pixi, record, quad, NOW);
20748
20772
  }
20749
20773
  /**
20750
- * Tells whether a shaded record went `QUAD_CALM` drawn frames without a change: it is due to leave.
20774
+ * Tells whether a shaded record went `QUAD_CALM` drawn frames without a change: it is due to leave. A body that reads the
20775
+ * screen never is: it is kept on its mesh alone, so a calm frame does not step it.
20751
20776
  *
20752
20777
  * @param state - The kept state.
20753
20778
  * @param record - The record.
20754
20779
  * @returns True when it is.
20755
20780
  */
20756
20781
  function shadedCalm(state, record) {
20757
- return record.shaded && state.frame - record.shadedAt >= 30;
20782
+ const rested = state.frame - record.shadedAt >= 30;
20783
+ return record.shaded && record.category !== "screen" && rested;
20758
20784
  }
20759
20785
  /**
20760
20786
  * A shaded record that owes nothing and stood `QUAD_CALM` frames goes back to its sprite (F126 stage 2): a resting mesh
20761
20787
  * runs the whole body every frame. Under `limitLeft`, shared with the refining and the settle, it stays shaded in a frame
20762
20788
  * the limit is spent. It counts as a refresh. The pixels do not change, so the pass marks nothing above; a stack whose
20763
20789
  * resolution moved under a held step is taken whole, as `refresh` takes it, and that does change them. Under a filter
20764
- * it stays: its clock starts over, so a calm frame leaves it alone until it comes round again.
20790
+ * it stays: its clock starts over, so a calm frame leaves it alone until it comes round again. A body that reads the
20791
+ * screen is never due (`shadedCalm`).
20765
20792
  *
20766
20793
  * @param kctx - The kept context.
20767
20794
  * @param pixi - The module that draws.
@@ -21132,9 +21159,9 @@ function passOffOrigin(kctx, pixi, node, filters) {
21132
21159
  return passStart(tx + box.x0, resolution, padding, clipped) !== 0 || passStart(ty + box.y0, resolution, padding, clipped) !== 0;
21133
21160
  }
21134
21161
  /**
21135
- * Tells whether a shaded placed record hangs under a filter whose pass starts off the canvas origin. Live, its body
21136
- * reads a place relative to that pass's texture; on the mesh it reads the canvas (spec 23 P8.3). The two differ by that
21137
- * origin by design, not by a stale picture. Only the closest filter counts: Pixi offsets by that one alone. Read with
21162
+ * Tells whether a shaded record that reads its place hangs under a filter whose pass starts off the canvas origin. Live,
21163
+ * its body reads a place relative to that pass's texture; on the mesh it reads the canvas (spec 23 P8.3). The two differ
21164
+ * by that origin by design, not by a stale picture. Only the closest filter counts: Pixi offsets by that one alone. Read with
21138
21165
  * every picture live: a kept ancestor's filters are back on its top, and the views are back in the tree.
21139
21166
  *
21140
21167
  * @param kctx - The kept context.
@@ -21143,7 +21170,7 @@ function passOffOrigin(kctx, pixi, node, filters) {
21143
21170
  */
21144
21171
  function placeDiffers(kctx, record) {
21145
21172
  const pixi = kctx.host.pixi();
21146
- if (!record.shaded || record.category !== "placed" || pixi === void 0) return false;
21173
+ if (!record.shaded || !readsPlace(record) || pixi === void 0) return false;
21147
21174
  for (let node = record.top.parent; node !== null; node = node.parent) {
21148
21175
  const filters = node.filters?.filter((filter) => filter.enabled) ?? [];
21149
21176
  if (filters.length > 0) return passOffOrigin(kctx, pixi, node, filters);
@@ -21404,20 +21431,23 @@ function whyReport(kctx) {
21404
21431
  /** What `why()` answers in every build but an agent build. */
21405
21432
  const NO_WHY = Object.freeze([]);
21406
21433
  /**
21407
- * The category a slot list lets the cache keep it under: the worst of its slots, `undefined` for an empty list, a
21408
- * `"screen"` slot or a slot that names none (a game's own slot is drawn live).
21434
+ * The category a slot list lets the cache keep it under: the worst of its slots, `undefined` for an empty list, a slot
21435
+ * that names none (a game's own slot is drawn live) or a `"screen"` slot without a quad. A body that reads the screen is
21436
+ * kept only while it runs on its quad (F126 stage 2).
21409
21437
  *
21410
21438
  * @param slots - The slots.
21411
- * @returns `"local"`, `"placed"`, or `undefined` when no record is kept.
21439
+ * @returns `"local"`, `"placed"`, `"screen"`, or `undefined` when no record is kept.
21412
21440
  */
21413
21441
  function categoryOf(slots) {
21414
21442
  if (slots.length === 0) return void 0;
21415
- let placed = false;
21443
+ let worst = "local";
21416
21444
  for (const slot of slots) {
21417
- if (slot.cache === void 0 || slot.cache === "screen") return void 0;
21418
- if (slot.cache === "placed") placed = true;
21445
+ const drawnLive = slot.cache === "screen" && slot.quad === void 0;
21446
+ if (slot.cache === void 0 || drawnLive) return void 0;
21447
+ if (slot.cache === "screen") worst = "screen";
21448
+ else if (slot.cache === "placed" && worst === "local") worst = "placed";
21419
21449
  }
21420
- return placed ? "placed" : "local";
21450
+ return worst;
21421
21451
  }
21422
21452
  /**
21423
21453
  * The depth of a node under the stage: its count of parents.
@@ -31134,7 +31164,12 @@ function createRange$1(owner) {
31134
31164
  * @returns The layer name, or `undefined` for a node that is no layer container.
31135
31165
  */
31136
31166
  function layerNameOf$1(state, node) {
31137
- for (const [name, entry] of state.layers) if (entry.container === node) return name;
31167
+ const list = state.layerList;
31168
+ if (list === void 0) return void 0;
31169
+ for (let index = 0; index < list.length; index += 1) {
31170
+ const name = list[index]?.name;
31171
+ if (name !== void 0 && state.layers.get(name)?.container === node) return name;
31172
+ }
31138
31173
  }
31139
31174
  /**
31140
31175
  * Adds or removes a reason on one node of a range: a view's top, a layer container, or an engine object (a lower
@@ -31188,50 +31223,103 @@ function isPicture(sctx, node) {
31188
31223
  */
31189
31224
  function computeRange(sctx, owner, root) {
31190
31225
  const { wantEntries: entries, wantOthers: others, wantSet: set } = sctx.ctx.state.sync.overlay;
31191
- entries.length = 0;
31192
- others.length = 0;
31193
- set.clear();
31194
- lowerLayers(sctx, owner, root);
31195
- rootsBelow(sctx, owner);
31196
- for (const child of root.children) if (!set.has(child) && child !== owner.container) others.push(child);
31197
- for (const child of owner.container.children) if (!set.has(child) && !isPicture(sctx, child)) others.push(child);
31226
+ entries.length = rootsBelow(sctx, owner, lowerLayers(sctx, owner, root));
31227
+ fillSet(set, entries);
31228
+ let count = 0;
31229
+ for (const child of root.children) if (!set.has(child) && child !== owner.container) count = writeAt$1(others, count, child);
31230
+ for (const child of owner.container.children) if (!set.has(child) && !isPicture(sctx, child)) count = writeAt$1(others, count, child);
31231
+ others.length = count;
31232
+ }
31233
+ /**
31234
+ * Writes a node at a place of a reused list, only when another stands there.
31235
+ *
31236
+ * @param list - The list.
31237
+ * @param at - The place, at most its length.
31238
+ * @param node - The node.
31239
+ * @returns The next place.
31240
+ */
31241
+ function writeAt$1(list, at, node) {
31242
+ if (list[at] !== node) list[at] = node;
31243
+ return at + 1;
31198
31244
  }
31199
31245
  /**
31200
- * Adds the layer containers below the owner's layer to the wanted entries, bottom first.
31246
+ * Writes the layer containers below the owner's layer at the start of the wanted entries, bottom first.
31201
31247
  *
31202
31248
  * @param sctx - Domain context of the sync module.
31203
31249
  * @param owner - The owner overlay.
31204
31250
  * @param root - The stage root of `sync`.
31251
+ * @returns How many were written.
31205
31252
  */
31206
31253
  function lowerLayers(sctx, owner, root) {
31207
31254
  const state = sctx.ctx.state.sync;
31208
- const { wantEntries: entries, wantSet: set } = state.overlay;
31209
- for (const spec of (state.layerList ?? []).slice(0, owner.layerIndex)) {
31210
- const container = state.layers.get(spec.name)?.container;
31211
- if (container?.parent === root) {
31212
- entries.push(container);
31213
- set.add(container);
31214
- }
31255
+ const entries = state.overlay.wantEntries;
31256
+ const list = state.layerList;
31257
+ let count = 0;
31258
+ if (list === void 0) return count;
31259
+ for (let index = 0; index < owner.layerIndex && index < list.length; index += 1) {
31260
+ const name = list[index]?.name;
31261
+ const container = name === void 0 ? void 0 : state.layers.get(name)?.container;
31262
+ if (container?.parent === root) count = writeAt$1(entries, count, container);
31215
31263
  }
31264
+ return count;
31216
31265
  }
31217
31266
  /**
31218
- * Adds the children of the owner's layer container drawn before its root (rank: depth, then insertion) to the
31219
- * wanted entries; its own dim and every picture left out.
31267
+ * Tells whether a node is the HUD render layer of an overlay (`hud: "under"`): never part of a range, so the HUD it
31268
+ * draws is never in a picture (U3).
31269
+ *
31270
+ * @param order - The overlays, bottom first.
31271
+ * @param node - A child of a layer container.
31272
+ * @returns True for the render layer of a known overlay.
31273
+ */
31274
+ function isUnderLayer(order, node) {
31275
+ for (const record of order) if (record.under === node) return true;
31276
+ return false;
31277
+ }
31278
+ /**
31279
+ * Writes the children of the owner's layer container drawn before its root (rank: depth, then insertion) into the
31280
+ * wanted entries after the lower layers; its own dim, every HUD render layer and every picture left out.
31220
31281
  *
31221
31282
  * @param sctx - Domain context of the sync module.
31222
31283
  * @param owner - The owner overlay.
31284
+ * @param from - How many entries the lower layers wrote.
31285
+ * @returns How many entries there are now.
31223
31286
  */
31224
- function rootsBelow(sctx, owner) {
31225
- const { wantEntries: entries, wantSet: set } = sctx.ctx.state.sync.overlay;
31287
+ function rootsBelow(sctx, owner, from) {
31288
+ const { wantEntries: entries, order } = sctx.ctx.state.sync.overlay;
31226
31289
  const depth = owner.object.zIndex;
31290
+ const children = owner.container.children;
31227
31291
  const at = owner.container.getChildIndex(owner.object);
31228
- for (const [index, child] of owner.container.children.entries()) {
31229
- if (child === owner.dim || isPicture(sctx, child)) continue;
31230
- if (child.zIndex < depth || child.zIndex === depth && index < at) {
31231
- entries.push(child);
31232
- set.add(child);
31233
- }
31292
+ let count = from;
31293
+ let index = -1;
31294
+ for (const child of children) {
31295
+ index += 1;
31296
+ if (child === owner.dim || isUnderLayer(order, child) || isPicture(sctx, child)) continue;
31297
+ if (child.zIndex < depth || child.zIndex === depth && index < at) count = writeAt$1(entries, count, child);
31234
31298
  }
31299
+ return count;
31300
+ }
31301
+ /**
31302
+ * Tells whether a set holds every node of a list.
31303
+ *
31304
+ * @param set - The set.
31305
+ * @param nodes - The nodes.
31306
+ * @returns True when none is missing.
31307
+ */
31308
+ function holdsAll(set, nodes) {
31309
+ for (const node of nodes) if (!set.has(node)) return false;
31310
+ return true;
31311
+ }
31312
+ /**
31313
+ * Makes a set hold exactly these nodes, writing nothing when it does already: V8 gives a set a new table at every
31314
+ * `clear()`, and the step runs every frame.
31315
+ *
31316
+ * @param set - The set.
31317
+ * @param nodes - The nodes, each once.
31318
+ */
31319
+ function fillSet(set, nodes) {
31320
+ if (set.size === nodes.length && holdsAll(set, nodes)) return;
31321
+ if (set.size > 0) set.clear();
31322
+ for (const node of nodes) set.add(node);
31235
31323
  }
31236
31324
  /**
31237
31325
  * Tells whether two node lists are the same, in order.
@@ -31242,7 +31330,7 @@ function rootsBelow(sctx, owner) {
31242
31330
  */
31243
31331
  function sameList$1(left, right) {
31244
31332
  if (left.length !== right.length) return false;
31245
- for (const [index, node] of left.entries()) if (right[index] !== node) return false;
31333
+ for (let index = 0; index < left.length; index += 1) if (right[index] !== left[index]) return false;
31246
31334
  return true;
31247
31335
  }
31248
31336
  /**
@@ -31409,11 +31497,25 @@ function keepWanted(sctx, range) {
31409
31497
  * @param from - The list wanted now.
31410
31498
  */
31411
31499
  function copyInto(into, from) {
31412
- for (const [index, node] of from.entries()) if (into[index] !== node) into[index] = node;
31500
+ for (let index = 0; index < from.length; index += 1) {
31501
+ const node = from[index];
31502
+ if (node !== void 0 && into[index] !== node) into[index] = node;
31503
+ }
31413
31504
  into.length = from.length;
31414
31505
  }
31415
31506
  /**
31416
- * The range handed to `kept`: the wanted lists and the slot right before the owner's dim, or its root.
31507
+ * The node the picture of an owner's range stands right before: its HUD render layer, so a HUD drawn there lies over
31508
+ * the picture and under the dim; else its dim; else its root.
31509
+ *
31510
+ * @param owner - The owner overlay.
31511
+ * @returns The node.
31512
+ */
31513
+ function pictureBefore(owner) {
31514
+ return owner.under ?? owner.dim ?? owner.object;
31515
+ }
31516
+ /**
31517
+ * The range handed to `kept`: the wanted lists and the slot right before the owner's HUD render layer, its dim, or its
31518
+ * root.
31417
31519
  *
31418
31520
  * @param sctx - Domain context of the sync module.
31419
31521
  * @param owner - The owner overlay.
@@ -31427,7 +31529,7 @@ function keptRangeOf(sctx, owner) {
31427
31529
  others: overlay.wantOthers,
31428
31530
  slot: {
31429
31531
  container: owner.container,
31430
- before: owner.dim ?? owner.object
31532
+ before: pictureBefore(owner)
31431
31533
  }
31432
31534
  };
31433
31535
  }
@@ -31455,7 +31557,7 @@ function handOver$1(sctx, range, owner, root) {
31455
31557
  range.kept = true;
31456
31558
  range.refused = false;
31457
31559
  range.othersStale = false;
31458
- range.before = owner.dim ?? owner.object;
31560
+ range.before = pictureBefore(owner);
31459
31561
  range.blurred = measureBlurred(sctx, sctx.ctx.state.sync.overlay.wantSet, root);
31460
31562
  return true;
31461
31563
  }
@@ -31492,6 +31594,21 @@ function noteFallback(sctx, owner, what) {
31492
31594
  });
31493
31595
  }
31494
31596
  /**
31597
+ * Tells whether the whole reasons of a frame hold one of these. Pure.
31598
+ *
31599
+ * @param wholes - The whole-frame reasons of this decision.
31600
+ * @param reasons - The reasons looked for.
31601
+ * @returns True when one is there.
31602
+ * @example
31603
+ * ```ts
31604
+ * wholeAmong(new Set(["layers", "resize"]), ["resize", "restore", "debug"]); // true
31605
+ * ```
31606
+ */
31607
+ function wholeAmong(wholes, reasons) {
31608
+ for (const reason of reasons) if (wholes.has(reason)) return true;
31609
+ return false;
31610
+ }
31611
+ /**
31495
31612
  * The retake rules of a held picture whose lists stand (O8.3, O8.4): the catch-up of held loops, a mark in the range
31496
31613
  * (live after three frames in a row), the screen changed whole, and the landing and the first exit frame with a loop
31497
31614
  * held. Others that changed are handed over with the next retake.
@@ -31501,15 +31618,13 @@ function noteFallback(sctx, owner, what) {
31501
31618
  * @param owner - The owner overlay.
31502
31619
  * @param root - The stage root.
31503
31620
  * @param context - The frame: its whole reasons and whether the others changed.
31504
- * @param context.wholes - The whole-frame reasons of this decision.
31505
- * @param context.othersChanged - True when the others differ from the last frame.
31506
31621
  * @returns The reason the entries carry now: `"freeze"`, or none when the range went live.
31507
31622
  */
31508
31623
  function stepKept(sctx, range, owner, root, context) {
31509
31624
  if (context.othersChanged) range.othersStale = true;
31510
31625
  const owed = retakeOwed(sctx, range, owner, root);
31511
31626
  if (owed === "live") return void 0;
31512
- if (owed === "none" && RETAKE_WHOLES.some((reason) => context.wholes.has(reason))) retake(sctx, range, owner, root);
31627
+ if (owed === "none" && wholeAmong(context.wholes, RETAKE_WHOLES)) retake(sctx, range, owner, root);
31513
31628
  if (range.touched && (owner.turned === "shown" || owner.turned === "exiting")) range.catchUp = true;
31514
31629
  return range.kept ? "freeze" : void 0;
31515
31630
  }
@@ -31549,11 +31664,7 @@ function retakeOwed(sctx, range, owner, root) {
31549
31664
  * @param range - The range of this owner, counters reset when it is new.
31550
31665
  * @param owner - The owner overlay.
31551
31666
  * @param root - The stage root.
31552
- * @param context - What changed since the last frame.
31553
- * @param context.fresh - The owner is new, or was covering until now.
31554
- * @param context.entriesChanged - The entries differ from the last frame.
31555
- * @param context.othersChanged - The others differ from the last frame.
31556
- * @param context.wholes - The whole-frame reasons of this decision.
31667
+ * @param context - What changed since the last frame: a new owner, new entries or others, the whole reasons.
31557
31668
  * @returns `"freeze"` when a picture holds the range, none when it is drawn live.
31558
31669
  */
31559
31670
  function stepFreeze(sctx, range, owner, root, context) {
@@ -31667,19 +31778,19 @@ function stepRange(sctx, wholes) {
31667
31778
  }
31668
31779
  if (fresh) freshRange(range, owner.entity, sameOwner && held !== void 0 && mode === "freeze");
31669
31780
  range.mode = mode;
31670
- const to = mode === "cover" ? "cover" : stepFreeze(sctx, range, owner, root, {
31671
- fresh,
31672
- entriesChanged,
31673
- othersChanged,
31674
- wholes
31675
- });
31781
+ const { step } = overlay;
31782
+ step.fresh = fresh;
31783
+ step.entriesChanged = entriesChanged;
31784
+ step.othersChanged = othersChanged;
31785
+ step.wholes = wholes;
31786
+ const to = mode === "cover" ? "cover" : stepFreeze(sctx, range, owner, root, step);
31676
31787
  if (mode === "cover") range.kept = false;
31677
31788
  writeReasons(sctx, range, from, to);
31678
31789
  keepWanted(sctx, range);
31679
31790
  range.reason = to;
31680
31791
  overlay.active = range;
31681
31792
  if (held !== void 0 && (held !== owner.entity || !range.kept)) sctx.deps.kept.release(held);
31682
- const before = owner.dim ?? owner.object;
31793
+ const before = pictureBefore(owner);
31683
31794
  if (range.kept && range.before !== before) {
31684
31795
  sctx.deps.kept.move(owner.entity, {
31685
31796
  container: owner.container,
@@ -31729,7 +31840,8 @@ function rangeHolds(state, entity) {
31729
31840
  //#endregion
31730
31841
  //#region src/plugins/renderer/sync/overlay-state.ts
31731
31842
  /**
31732
- * Destroys the dims the records hold, once each, and drops the references.
31843
+ * Destroys the dims and the HUD render layers the records hold, once each, and drops the references; a render layer
31844
+ * lets go of what it holds first, so the HUD layer container is left attached to nothing (U5).
31733
31845
  *
31734
31846
  * @param overlay - The overlay state.
31735
31847
  */
@@ -31738,12 +31850,19 @@ function destroyDims(overlay) {
31738
31850
  if (record.dim !== void 0 && !record.dim.destroyed) record.dim.destroy();
31739
31851
  record.dim = void 0;
31740
31852
  record.sized = false;
31853
+ if (record.under !== void 0) {
31854
+ record.under.detachAll();
31855
+ if (!record.under.destroyed) record.under.destroy();
31856
+ }
31857
+ record.under = void 0;
31741
31858
  }
31859
+ overlay.held = void 0;
31860
+ overlay.heldBy = void 0;
31742
31861
  }
31743
31862
  /**
31744
- * Forgets what the step applied to a tree that goes (a rebuild, a lost device): the dims, the range and the tap set.
31745
- * The records stay, so the next step finds the overlays again in the new tree and takes their ranges anew; the views
31746
- * and the layers it hid are new, so nothing is cleared on them.
31863
+ * Forgets what the step applied to a tree that goes (a rebuild, a lost device): the dims, the HUD render layers and
31864
+ * the HUD they held, the range and the tap set. The records stay, so the next step finds the overlays again in the new
31865
+ * tree and takes their ranges anew; the views and the layers it hid are new, so nothing is cleared on them.
31747
31866
  *
31748
31867
  * @param state - The sync state.
31749
31868
  */
@@ -31759,10 +31878,12 @@ function forgetOverlays(state) {
31759
31878
  overlay.range.kept = false;
31760
31879
  }
31761
31880
  overlay.offTops.clear();
31881
+ overlay.offList.length = 0;
31762
31882
  overlay.order.length = 0;
31763
31883
  }
31764
31884
  /**
31765
- * Forgets every overlay at stop: dims destroyed, records, ranges, taps, events and the watched entities cleared.
31885
+ * Forgets every overlay at stop: dims and HUD render layers destroyed, records, ranges, taps, events and the watched
31886
+ * entities cleared.
31766
31887
  *
31767
31888
  * @param state - The sync state.
31768
31889
  */
@@ -34525,7 +34646,8 @@ function walkChildren(sctx, walk, container, depth, steps) {
34525
34646
  /**
34526
34647
  * Walks every view under the walk's point, topmost first: the layers from the last one of the
34527
34648
  * scene's list, inside a layer by draw order from the top. Nothing while inert or before the scene
34528
- * declared its layers. A layer that hangs under no root, or that is hidden, holds no hit.
34649
+ * declared its layers. A layer that hangs under no root, or that is hidden, holds no hit, and neither does the HUD
34650
+ * layer while an overlay draws it under its dim.
34529
34651
  *
34530
34652
  * @param sctx - Domain context of the sync module.
34531
34653
  * @param walk - The walk.
@@ -34539,7 +34661,7 @@ function walkLayers(sctx, walk) {
34539
34661
  for (let index = list.length - 1; index >= 0; index -= 1) {
34540
34662
  const name = list[index]?.name;
34541
34663
  const container = name === void 0 ? void 0 : state.layers.get(name)?.container;
34542
- if (container === void 0) continue;
34664
+ if (container === void 0 || container === state.overlay.held) continue;
34543
34665
  const alpha = effectiveAlpha(container, root, state.overlay.offTops);
34544
34666
  const steps = stepsToRoot(container, root);
34545
34667
  if (alpha === 0 || steps >= MAX_DEPTH$6) continue;
@@ -35264,8 +35386,44 @@ function lookDim(sctx, record, dim) {
35264
35386
  }
35265
35387
  }
35266
35388
  /**
35389
+ * Makes the render layer an overlay with `hud: "under"` draws the HUD layer in: never a view, nothing attached yet.
35390
+ *
35391
+ * @param pixi - The Pixi module.
35392
+ * @param entity - The marked entity, for the label.
35393
+ * @returns The render layer.
35394
+ */
35395
+ function makeUnder(pixi, entity) {
35396
+ const under = new pixi.RenderLayer();
35397
+ under.label = `overlay-hud:${entity}`;
35398
+ return under;
35399
+ }
35400
+ /**
35401
+ * Places an overlay's HUD render layer immediately before its dim, at the dim's depth, as the dim is placed before the
35402
+ * root: what it draws lies under the dim, and a picture of the range stands right before it. A move marks the whole
35403
+ * frame: the layer has no entity.
35404
+ *
35405
+ * @param sctx - Domain context of the sync module.
35406
+ * @param record - The overlay.
35407
+ * @param under - Its render layer.
35408
+ * @param dim - Its dim, placed already.
35409
+ */
35410
+ function placeUnder(sctx, record, under, dim) {
35411
+ const { container } = record;
35412
+ const at = container.getChildIndex(dim);
35413
+ if (under.parent !== container || container.children[at - 1] !== under) {
35414
+ sctx.deps.demand.whole("overlay");
35415
+ under.removeFromParent();
35416
+ container.addChildAt(under, container.getChildIndex(dim));
35417
+ }
35418
+ if (under.zIndex !== dim.zIndex) {
35419
+ sctx.deps.demand.whole("overlay");
35420
+ under.zIndex = dim.zIndex;
35421
+ }
35422
+ }
35423
+ /**
35267
35424
  * The dims of every overlay with a dim above 0: made once, placed under the root, sized to the canvas (again after a
35268
- * resize, a resolution change or a restore), and their look written.
35425
+ * resize, a resolution change or a restore), and their look written; the HUD render layer of one with `hud: "under"`
35426
+ * made with its dim and placed right under it (U1). A dim of 0 makes neither (U6).
35269
35427
  *
35270
35428
  * @param sctx - Domain context of the sync module.
35271
35429
  * @param wholes - The whole-frame reasons of this decision.
@@ -35283,10 +35441,112 @@ function stepDims(sctx, wholes) {
35283
35441
  placeDim(sctx, record, record.dim);
35284
35442
  if (resized || !record.sized) sizeDim(sctx, record, record.dim);
35285
35443
  lookDim(sctx, record, record.dim);
35444
+ if (needsUnder(record)) record.under = makeUnder(pixi, record.entity);
35445
+ if (record.under !== void 0) placeUnder(sctx, record, record.under, record.dim);
35446
+ }
35447
+ }
35448
+ /**
35449
+ * Tells whether an overlay wants a HUD render layer it does not have yet: `hud: "under"` with a dim above 0 (U1, U6).
35450
+ *
35451
+ * @param record - The overlay.
35452
+ * @returns True when the layer is to be made.
35453
+ */
35454
+ function needsUnder(record) {
35455
+ return record.under === void 0 && record.value.hud === "under" && record.value.dim > 0;
35456
+ }
35457
+ /**
35458
+ * Tells whether an overlay holds the HUD under its dim now, if nothing above it does: its render layer is made, it says
35459
+ * `hud: "under"`, and its dim and its level are above 0.
35460
+ *
35461
+ * @param record - The overlay.
35462
+ * @returns True when it can hold the HUD.
35463
+ */
35464
+ function isUnderHolder(record) {
35465
+ const { value } = record;
35466
+ return record.under !== void 0 && value.hud === "under" && value.dim > 0 && record.level > 0;
35467
+ }
35468
+ /**
35469
+ * The render layer the HUD layer is drawn in now (U2): the topmost overlay with `hud: "under"`, a dim above 0 and a
35470
+ * level above 0, looked for from the top down to the overlay that owns the range. One under that owner holds nothing:
35471
+ * it lies in the owner's picture, which would cover a HUD drawn under it.
35472
+ *
35473
+ * @param order - The overlays, bottom first, their modes decided.
35474
+ * @returns The holder's render layer, or `undefined` while the HUD draws in its own place above the overlays.
35475
+ */
35476
+ function holderOf(order) {
35477
+ for (let index = order.length - 1; index >= 0; index -= 1) {
35478
+ const record = order[index];
35479
+ if (record === void 0) continue;
35480
+ if (isUnderHolder(record)) return record.under;
35481
+ if (record.mode !== "live") return void 0;
35286
35482
  }
35287
35483
  }
35288
35484
  /**
35289
- * Whether one overlay keeps a HUD part shown: 1 for `hud: "all"`, 0 for `"none"`, and whether its list holds the key.
35485
+ * Lets the HUD layer container go from the render layer that holds it, so it draws in its own place again. Only a
35486
+ * container still attached there is detached: Pixi already let go of one that left its parent.
35487
+ *
35488
+ * @param sctx - Domain context of the sync module.
35489
+ */
35490
+ function letGoHud(sctx) {
35491
+ const overlay = sctx.ctx.state.sync.overlay;
35492
+ const { held, heldBy } = overlay;
35493
+ overlay.held = void 0;
35494
+ overlay.heldBy = void 0;
35495
+ if (held === void 0 || heldBy === void 0) return;
35496
+ if (held.parentRenderLayer === heldBy) heldBy.detach(held);
35497
+ sctx.deps.demand.whole("overlay");
35498
+ }
35499
+ /**
35500
+ * Hands the HUD layer container to the overlay that holds it under its dim this frame, or back to its own place (U2):
35501
+ * the old holder lets it go before the new one takes it, and either marks the whole frame. A frame where nothing
35502
+ * changed compares references and writes nothing. The HUD is held only while its container hangs in the stage root,
35503
+ * in the one render group of the layers.
35504
+ *
35505
+ * @param sctx - Domain context of the sync module.
35506
+ */
35507
+ function stepHold(sctx) {
35508
+ const state = sctx.ctx.state.sync;
35509
+ const overlay = state.overlay;
35510
+ const name = state.hudLayer;
35511
+ const container = name === void 0 ? void 0 : state.layers.get(name)?.container;
35512
+ const holder = container !== void 0 && container.parent === state.root ? holderOf(overlay.order) : void 0;
35513
+ const unchanged = holder === overlay.heldBy && container === overlay.held && container?.parentRenderLayer === holder;
35514
+ if (holder === void 0 && overlay.heldBy === void 0) return;
35515
+ if (unchanged) return;
35516
+ letGoHud(sctx);
35517
+ if (holder === void 0 || container === void 0) return;
35518
+ holder.attach(container);
35519
+ overlay.held = container;
35520
+ overlay.heldBy = holder;
35521
+ sctx.deps.demand.whole("overlay");
35522
+ }
35523
+ /**
35524
+ * Destroys an overlay's HUD render layer, the HUD let go first when it holds it, so nothing is left attached (U5).
35525
+ *
35526
+ * @param sctx - Domain context of the sync module.
35527
+ * @param record - The overlay.
35528
+ */
35529
+ function dropUnder(sctx, record) {
35530
+ const { under } = record;
35531
+ if (under === void 0) return;
35532
+ if (sctx.ctx.state.sync.overlay.heldBy === under) letGoHud(sctx);
35533
+ sctx.deps.demand.whole("overlay");
35534
+ under.detachAll();
35535
+ if (!under.destroyed) under.destroy();
35536
+ record.under = void 0;
35537
+ }
35538
+ /**
35539
+ * Destroys the HUD render layer of every overlay, for new layers: the next step of the frame makes them again where
35540
+ * the records hang now (U5).
35541
+ *
35542
+ * @param sctx - Domain context of the sync module.
35543
+ */
35544
+ function dropUnders(sctx) {
35545
+ for (const record of sctx.ctx.state.sync.overlay.records.values()) dropUnder(sctx, record);
35546
+ }
35547
+ /**
35548
+ * Whether one overlay keeps a HUD part shown: 1 for `hud: "all"` and `"under"` (the whole HUD stays, under the dim), 0
35549
+ * for `"none"`, and whether its list holds the key.
35290
35550
  *
35291
35551
  * @param record - The overlay.
35292
35552
  * @param key - The part's key.
@@ -35294,7 +35554,7 @@ function stepDims(sctx, wholes) {
35294
35554
  */
35295
35555
  function keeps(record, key) {
35296
35556
  const { hud } = record.value;
35297
- if (hud === "all") return 1;
35557
+ if (hud === "all" || hud === "under") return 1;
35298
35558
  if (hud === "none") return 0;
35299
35559
  return hud.includes(key) ? 1 : 0;
35300
35560
  }
@@ -35324,18 +35584,37 @@ function targetOf$3(order, key) {
35324
35584
  return target;
35325
35585
  }
35326
35586
  /**
35327
- * Tells whether two sets hold the same nodes.
35587
+ * Tells whether a set holds exactly the nodes of a list: as many, and every one of them.
35328
35588
  *
35329
- * @param left - One set.
35330
- * @param right - The other.
35331
- * @returns True when they are equal.
35589
+ * @param list - The nodes, each once.
35590
+ * @param set - The set.
35591
+ * @returns True when they are the same nodes.
35332
35592
  */
35333
- function sameSet(left, right) {
35334
- if (left.size !== right.size) return false;
35335
- for (const node of left) if (!right.has(node)) return false;
35593
+ function holdsSame(list, set) {
35594
+ if (list.length !== set.size) return false;
35595
+ for (const node of list) if (!set.has(node)) return false;
35336
35596
  return true;
35337
35597
  }
35338
35598
  /**
35599
+ * Makes the tap set hold the faded tops of this frame, the first `count` of `offList`, only when they differ from it:
35600
+ * the set is built aside and swapped in, so a frame where nothing changed clears nothing (V8 gives a set a new table at
35601
+ * every `clear()`, and the step runs every frame).
35602
+ *
35603
+ * @param sctx - Domain context of the sync module.
35604
+ * @param count - How many tops `offList` holds this frame.
35605
+ */
35606
+ function keepOff(sctx, count) {
35607
+ const overlay = sctx.ctx.state.sync.overlay;
35608
+ const { offList } = overlay;
35609
+ offList.length = count;
35610
+ if (holdsSame(offList, overlay.offTops)) return;
35611
+ const next = overlay.nextOff;
35612
+ if (next.size > 0) next.clear();
35613
+ for (const top of offList) next.add(top);
35614
+ overlay.nextOff = overlay.offTops;
35615
+ overlay.offTops = next;
35616
+ }
35617
+ /**
35339
35618
  * Logs one warning of a part once, in dev builds.
35340
35619
  *
35341
35620
  * @param sctx - Domain context of the sync module.
@@ -35369,7 +35648,8 @@ function stepParts(sctx) {
35369
35648
  const settling = heldWaiting(sctx);
35370
35649
  const ecs = sctx.ctx.deps.world.ecs;
35371
35650
  const projection = sctx.ctx.deps.world.projection;
35372
- if (overlay.nextOff.size > 0) overlay.nextOff.clear();
35651
+ const { offList } = overlay;
35652
+ let count = 0;
35373
35653
  for (const entity of overlay.parts) {
35374
35654
  const view = state.views.get(entity);
35375
35655
  if (view === void 0) continue;
@@ -35381,13 +35661,13 @@ function stepParts(sctx) {
35381
35661
  }
35382
35662
  const factor = factorOf(overlay.order, key);
35383
35663
  applyHud(sctx, entity, view, factor);
35384
- if (factor < 1 || targetOf$3(overlay.order, key) < 1) overlay.nextOff.add(view.wrapper ?? view.object);
35385
- }
35386
- if (!sameSet(overlay.offTops, overlay.nextOff)) {
35387
- const next = overlay.nextOff;
35388
- overlay.nextOff = overlay.offTops;
35389
- overlay.offTops = next;
35664
+ if (factor < 1 || targetOf$3(overlay.order, key) < 1) {
35665
+ const top = view.wrapper ?? view.object;
35666
+ if (offList[count] !== top) offList[count] = top;
35667
+ count += 1;
35668
+ }
35390
35669
  }
35670
+ keepOff(sctx, count);
35391
35671
  }
35392
35672
  //#endregion
35393
35673
  //#region src/plugins/renderer/sync/overlay.ts
@@ -35429,8 +35709,8 @@ function isKeyList(value) {
35429
35709
  }
35430
35710
  /**
35431
35711
  * Copies the marker into the record's own value, clamped (O1): `dim` into [0, 1], `fade` to 0 or more, an unknown
35432
- * `cover` as `"none"`, a `hud` that is not `"all"`, `"none"` or a key list as `"all"`, a `hold` that is no boolean as
35433
- * `false`; one dev warning per field.
35712
+ * `cover` as `"none"`, a `hud` that is not `"all"`, `"none"`, `"under"` or a key list as `"all"`, a `hold` that is no
35713
+ * boolean as `false`; one dev warning per field.
35434
35714
  *
35435
35715
  * @param sctx - Domain context of the sync module.
35436
35716
  * @param entity - The marked entity.
@@ -35441,7 +35721,7 @@ function clampInto(sctx, entity, into, raw) {
35441
35721
  const dim = Number.isFinite(raw.dim) ? Math.min(1, Math.max(0, raw.dim)) : 0;
35442
35722
  const fade = Number.isFinite(raw.fade) ? Math.max(0, raw.fade) : 0;
35443
35723
  const cover = raw.cover === "opaque" ? "opaque" : "none";
35444
- const hud = raw.hud === "all" || raw.hud === "none" || isKeyList(raw.hud) ? raw.hud : "all";
35724
+ const hud = raw.hud === "all" || raw.hud === "none" || raw.hud === "under" || isKeyList(raw.hud) ? raw.hud : "all";
35445
35725
  const hold = raw.hold === true;
35446
35726
  if (dim !== raw.dim) warnOnce$4(sctx, "renderer:overlay-value", entity, { field: "dim" });
35447
35727
  if (fade !== raw.fade) warnOnce$4(sctx, "renderer:overlay-value", entity, { field: "fade" });
@@ -35472,29 +35752,37 @@ function rootOf(sctx, entity) {
35472
35752
  }
35473
35753
  return current;
35474
35754
  }
35755
+ /** The layer list of a scene that declared none: no array made per frame. */
35756
+ const NO_LAYERS = [];
35475
35757
  /**
35476
- * Where a root's top hangs: its layer and the layer's index in the scene's list.
35758
+ * The index in the scene's list of the layer a root's top hangs in.
35477
35759
  *
35478
- * @param sctx - Domain context of the sync module.
35760
+ * @param state - The sync state.
35761
+ * @param list - The scene's layers.
35479
35762
  * @param container - The parent of the root's top.
35480
- * @returns The layer name and index, and the index of the HUD layer (-1 without one); `undefined` for an orphan.
35763
+ * @returns The index, or -1 for an orphan.
35481
35764
  */
35482
- function layerSlotOf(sctx, container) {
35483
- const state = sctx.ctx.state.sync;
35484
- const list = state.layerList ?? [];
35485
- let found;
35486
- let hud = -1;
35487
- for (const [index, spec] of list.entries()) {
35488
- if (spec.above === "overlays") hud = index;
35489
- if (container !== null && state.layers.get(spec.name)?.container === container) found = {
35490
- name: spec.name,
35491
- index
35492
- };
35765
+ function layerIndexOf(state, list, container) {
35766
+ if (container === null) return -1;
35767
+ for (let index = 0; index < list.length; index += 1) {
35768
+ const name = list[index]?.name;
35769
+ if (name !== void 0 && state.layers.get(name)?.container === container) return index;
35493
35770
  }
35494
- return found === void 0 ? void 0 : {
35495
- ...found,
35496
- hud
35497
- };
35771
+ return -1;
35772
+ }
35773
+ /**
35774
+ * The index of the HUD layer in a scene's list. Pure.
35775
+ *
35776
+ * @param list - The scene's layers.
35777
+ * @returns The index of the layer above the overlays, -1 without one.
35778
+ * @example
35779
+ * ```ts
35780
+ * hudIndexOf([{ name: "scene", sort: "none" }, { name: "hud", sort: "none", above: "overlays" }]); // 1
35781
+ * ```
35782
+ */
35783
+ function hudIndexOf$1(list) {
35784
+ for (let index = 0; index < list.length; index += 1) if (list[index]?.above === "overlays") return index;
35785
+ return -1;
35498
35786
  }
35499
35787
  /**
35500
35788
  * A new record for an overlay that appeared this frame.
@@ -35519,6 +35807,7 @@ function createRecord(entity, object, container) {
35519
35807
  turned: void 0,
35520
35808
  mode: "live",
35521
35809
  dim: void 0,
35810
+ under: void 0,
35522
35811
  sized: false,
35523
35812
  seen: false,
35524
35813
  news: "open"
@@ -35560,10 +35849,13 @@ function seeOverlay(sctx, entity) {
35560
35849
  const raw = ecs.get(entity, Overlay);
35561
35850
  if (view === void 0 || raw === void 0) return;
35562
35851
  const object = view.wrapper ?? view.object;
35563
- const slot = layerSlotOf(sctx, object.parent);
35564
- if (slot === void 0 || object.parent === null) return;
35565
- if (slot.hud !== -1 && slot.index >= slot.hud) {
35566
- warnOnce$4(sctx, "renderer:overlay-above-hud", entity, { layer: slot.name });
35852
+ const list = state.layerList ?? NO_LAYERS;
35853
+ const index = layerIndexOf(state, list, object.parent);
35854
+ const layer = list[index];
35855
+ if (layer === void 0 || object.parent === null) return;
35856
+ const hud = hudIndexOf$1(list);
35857
+ if (hud !== -1 && index >= hud) {
35858
+ warnOnce$4(sctx, "renderer:overlay-above-hud", entity, { layer: layer.name });
35567
35859
  return;
35568
35860
  }
35569
35861
  const known = state.overlay.records.get(entity);
@@ -35575,8 +35867,8 @@ function seeOverlay(sctx, entity) {
35575
35867
  record.top = top;
35576
35868
  record.object = object;
35577
35869
  record.container = object.parent;
35578
- record.layer = slot.name;
35579
- record.layerIndex = slot.index;
35870
+ record.layer = layer.name;
35871
+ record.layerIndex = index;
35580
35872
  record.level = Math.min(1, Math.max(0, level?.level ?? 0));
35581
35873
  const turned = known === void 0 || phase === record.phase ? void 0 : phase;
35582
35874
  record.turned = turned;
@@ -35603,12 +35895,14 @@ function note(sctx, record, what, mode) {
35603
35895
  });
35604
35896
  }
35605
35897
  /**
35606
- * Drops a record whose entity lost `Overlay` or its view: its dim goes in this frame, `"gone"` is noted.
35898
+ * Drops a record whose entity lost `Overlay` or its view: its dim and its HUD render layer go in this frame, the HUD
35899
+ * let go first when it held it, `"gone"` is noted.
35607
35900
  *
35608
35901
  * @param sctx - Domain context of the sync module.
35609
35902
  * @param record - The overlay that left.
35610
35903
  */
35611
35904
  function dropRecord(sctx, record) {
35905
+ dropUnder(sctx, record);
35612
35906
  if (record.dim !== void 0) {
35613
35907
  sctx.deps.demand.whole("overlay");
35614
35908
  if (!record.dim.destroyed) record.dim.destroy();
@@ -35630,15 +35924,16 @@ function compareRank(left, right) {
35630
35924
  return left.container.getChildIndex(left.object) - right.container.getChildIndex(right.object);
35631
35925
  }
35632
35926
  /**
35633
- * Fills `order` with the records bottom first: an insertion sort on the reused array.
35927
+ * Fills `order` with the records bottom first: an insertion sort on the reused array, written in place and cut to the
35928
+ * count (V8 gives an array set to length 0 a new backing store at the next write).
35634
35929
  *
35635
35930
  * @param overlay - The overlay state.
35636
35931
  */
35637
35932
  function sortOrder(overlay) {
35638
35933
  const { order } = overlay;
35639
- order.length = 0;
35934
+ let count = 0;
35640
35935
  for (const record of overlay.records.values()) {
35641
- let at = order.length;
35936
+ let at = count;
35642
35937
  while (at > 0) {
35643
35938
  const before = order[at - 1];
35644
35939
  if (before === void 0 || compareRank(before, record) <= 0) break;
@@ -35646,7 +35941,9 @@ function sortOrder(overlay) {
35646
35941
  at -= 1;
35647
35942
  }
35648
35943
  order[at] = record;
35944
+ count += 1;
35649
35945
  }
35946
+ order.length = count;
35650
35947
  }
35651
35948
  /**
35652
35949
  * The alpha a set of filters multiplies by: every enabled `AlphaFilter` among them.
@@ -35736,8 +36033,9 @@ function overlaysIdle(overlay) {
35736
36033
  }
35737
36034
  /**
35738
36035
  * The overlay step of the render phase (the body of `SyncInternal.stepOverlays`): the records, their order and modes,
35739
- * the dims, the range with its reasons and its picture, and the HUD parts, in that order. New layers let the range go
35740
- * first; it is built again from the new layers in the same step.
36036
+ * the dims and their HUD render layers, the range with its reasons and its picture, the overlay that holds the HUD
36037
+ * under its dim, and the HUD parts, in that order. New layers let the range and the HUD go first; both are built again
36038
+ * from the new layers in the same step.
35741
36039
  *
35742
36040
  * @param sctx - Domain context of the sync module.
35743
36041
  */
@@ -35747,7 +36045,10 @@ function stepOverlays(sctx) {
35747
36045
  if (state.root === void 0 || overlaysIdle(overlay)) return;
35748
36046
  const wholes = sctx.deps.demand.wholes();
35749
36047
  if (overlay.flipped.size > 0) overlay.flipped.clear();
35750
- if (wholes.has("layers")) clearRange(sctx);
36048
+ if (wholes.has("layers")) {
36049
+ clearRange(sctx);
36050
+ dropUnders(sctx);
36051
+ }
35751
36052
  for (const record of overlay.records.values()) record.seen = false;
35752
36053
  for (const entity of overlay.entities) seeOverlay(sctx, entity);
35753
36054
  for (const record of overlay.records.values()) if (!record.seen) dropRecord(sctx, record);
@@ -35759,6 +36060,7 @@ function stepOverlays(sctx) {
35759
36060
  if (record.news !== void 0) note(sctx, record, record.news, modeReported(overlay, record));
35760
36061
  record.news = void 0;
35761
36062
  }
36063
+ stepHold(sctx);
35762
36064
  stepParts(sctx);
35763
36065
  overlay.left = false;
35764
36066
  }
@@ -37322,6 +37624,8 @@ function createOverlayState() {
37322
37624
  active: void 0,
37323
37625
  range: void 0,
37324
37626
  offTops: emptySet$4(),
37627
+ held: void 0,
37628
+ heldBy: void 0,
37325
37629
  warned: emptySet$4(),
37326
37630
  events: [],
37327
37631
  wantEntries: [],
@@ -37329,6 +37633,13 @@ function createOverlayState() {
37329
37633
  wantSet: emptySet$4(),
37330
37634
  flipped: emptySet$4(),
37331
37635
  nextOff: emptySet$4(),
37636
+ offList: [],
37637
+ step: {
37638
+ fresh: false,
37639
+ entriesChanged: false,
37640
+ othersChanged: false,
37641
+ wholes: emptySet$4()
37642
+ },
37332
37643
  left: false,
37333
37644
  bounds: void 0
37334
37645
  };
@@ -46723,11 +47034,35 @@ function resetSession(state) {
46723
47034
  session.type = "auto";
46724
47035
  } catch {}
46725
47036
  }
47037
+ /**
47038
+ * Tells whether the screen takes touches: iOS and iPadOS answer at least 1, Safari on a Mac 0.
47039
+ *
47040
+ * @returns True when the runtime reports a touch point.
47041
+ */
47042
+ function hasTouch() {
47043
+ if (typeof globalThis.navigator === "undefined") return false;
47044
+ return (globalThis.navigator.maxTouchPoints ?? 0) > 0;
47045
+ }
47046
+ /**
47047
+ * Writes one type on the session the plugin holds. A setter that throws changes nothing: the
47048
+ * renewal goes on with the session as it is.
47049
+ *
47050
+ * @param state - The plugin state, which holds the session.
47051
+ * @param type - What to write, `"auto"` to lift the override.
47052
+ */
47053
+ function writeSession(state, type) {
47054
+ const session = state.session;
47055
+ if (session === void 0) return;
47056
+ try {
47057
+ session.type = type;
47058
+ } catch {}
47059
+ }
46726
47060
  //#endregion
46727
47061
  //#region src/plugins/audio/unlock.ts
46728
47062
  /**
46729
- * @file audio plugin — the unlock: the only file that touches `window`. A browser starts an audio
46730
- * context suspended and lets it run on a user gesture, so two listeners wait for the first one.
47063
+ * @file audio plugin — the unlock: with the renewal of `context.ts`, the only file that touches
47064
+ * `window`. A browser starts an audio context suspended and lets it run on a user gesture, so two
47065
+ * listeners wait for the first one.
46731
47066
  * They sit on `window`, not on the canvas: the gesture may as well be a button of the game's
46732
47067
  * loading page, which `input` never sees. A shell that asks for no gesture, such as a native
46733
47068
  * webview with the requirement switched off, lets the context run at once. So the plugin also
@@ -46737,8 +47072,8 @@ function resetSession(state) {
46737
47072
  const UNLOCK_EVENTS = ["pointerdown", "touchend"];
46738
47073
  /**
46739
47074
  * Reacts to a resume that went through, of a gesture or of the start attempt. The context is
46740
- * unlocked only when it really runs; the sounds fired during the resume and the track a scene
46741
- * declared while it was locked start here. A context that still does not run drops the sounds:
47075
+ * unlocked only when it really runs, and only then do the listeners come off; the sounds fired
47076
+ * during the resume and the track a scene declared while it was locked start here. A context that still does not run drops the sounds:
46742
47077
  * the next gesture is a new moment. A gesture and the start attempt that settle together both
46743
47078
  * come here, and the music still starts once: a track that is on its way or already plays is not
46744
47079
  * started again. A later gesture on an unlocked context tries a remembered track again.
@@ -46754,6 +47089,7 @@ function onResumed(ctx) {
46754
47089
  return;
46755
47090
  }
46756
47091
  state.unlocked = true;
47092
+ removeUnlock(state);
46757
47093
  drainSfx(ctx);
46758
47094
  const remembered = state.music;
46759
47095
  if (remembered === void 0 || isMusicPlaying(state)) return;
@@ -46774,9 +47110,10 @@ function drainSfx(ctx) {
46774
47110
  for (const request of queued) playRequest(ctx, request);
46775
47111
  }
46776
47112
  /**
46777
- * Asks the context to run and marks it `resuming` until the answer comes. A browser that refuses
46778
- * says so once in the log, drops the sounds that waited and gets the listeners back, so the next
46779
- * gesture tries again.
47113
+ * Asks the context to run and marks it `resuming` until the answer comes. The listeners go back on
47114
+ * before the resume: while iOS keeps the audio session away, WebKit holds this promise pending, and
47115
+ * the next gesture must try again (F146). A browser that refuses says so once in the log, drops the
47116
+ * sounds that waited and keeps the listeners.
46780
47117
  *
46781
47118
  * @param ctx - Domain context of the plugin.
46782
47119
  */
@@ -46784,6 +47121,7 @@ function resumeContext(ctx) {
46784
47121
  const context = ctx.state.context;
46785
47122
  if (context === void 0) return;
46786
47123
  ctx.state.resuming = true;
47124
+ installUnlock(ctx);
46787
47125
  context.resume().then(() => {
46788
47126
  onResumed(ctx);
46789
47127
  }, () => {
@@ -46872,10 +47210,158 @@ function removeUnlock(state) {
46872
47210
  state.unlock = void 0;
46873
47211
  }
46874
47212
  //#endregion
47213
+ //#region src/plugins/audio/context.ts
47214
+ /**
47215
+ * @file audio plugin — the one context of the app: making it, and renewing it after a return from
47216
+ * the background on iOS (F149).
47217
+ *
47218
+ * With the `ambient` session, a short trip to the background leaves WebKit silent for good. iOS
47219
+ * deactivates the session, WebKit drops iOS's end of the interruption as spurious and keeps its
47220
+ * cached "active" flag, so it never asks iOS again. Only a closed last context resets the flag:
47221
+ * the renewal lifts the session override, closes the context, writes the session again and makes
47222
+ * a new context, which activates the session for real.
47223
+ *
47224
+ * The timing comes from the iPhone logs. `visibilitychange` fires about 0.3–0.7 s before iOS makes
47225
+ * the app active, and iOS refuses an activation before that, with no retry (build 9). So the
47226
+ * renewal waits a second after the return (build 10, proven on two iPhones), or runs at the first
47227
+ * touch that comes sooner: a touch reaches only an active app. On a healthy session the renewal
47228
+ * costs the sounds in flight and starts the music again.
47229
+ */
47230
+ /** How long the renewal waits after the return, in real milliseconds. */
47231
+ const RENEW_DELAY_MS = 1e3;
47232
+ /** The gestures that renew at once: the app is active when a touch arrives. */
47233
+ const RENEW_EVENTS = ["pointerdown", "touchend"];
47234
+ /**
47235
+ * Makes the one context of the app: the configured factory, the browser's own constructor, or
47236
+ * nothing at all, which is a headless run. A renewal calls it again.
47237
+ *
47238
+ * @param config - The resolved plugin config.
47239
+ * @returns The context, or `undefined` where the runtime has no WebAudio.
47240
+ */
47241
+ function createContext(config) {
47242
+ if (config.context !== void 0) return config.context();
47243
+ const browserContext = globalThis.AudioContext;
47244
+ return typeof browserContext === "function" ? new browserContext() : void 0;
47245
+ }
47246
+ /**
47247
+ * Tells whether a return from the background renews the context: a context exists, WebKit took
47248
+ * the session override, the session is not `"playback"` (iOS keeps that one active in the
47249
+ * background), and the screen takes touches, which leaves Safari on a Mac out.
47250
+ *
47251
+ * @param ctx - Domain context of the plugin.
47252
+ * @returns True on iOS and iPadOS with an `ambient` or `auto` session.
47253
+ */
47254
+ function canRenew(ctx) {
47255
+ const state = ctx.state;
47256
+ return state.context !== void 0 && state.session !== void 0 && ctx.config.session !== "playback" && hasTouch();
47257
+ }
47258
+ /**
47259
+ * Schedules the renewal after a return from the background: a second later, or at the first
47260
+ * touch before that. A second return replaces the renewal that waits.
47261
+ *
47262
+ * @param ctx - Domain context of the plugin.
47263
+ */
47264
+ function scheduleRenewal(ctx) {
47265
+ const state = ctx.state;
47266
+ if (!canRenew(ctx)) return;
47267
+ cancelRenewal(state);
47268
+ /**
47269
+ * Cancels what waits and renews. The timer and the first touch both come here; the first wins.
47270
+ */
47271
+ const renew = () => {
47272
+ cancelRenewal(state);
47273
+ renewContext(ctx);
47274
+ };
47275
+ const timer = setTimeout(renew, RENEW_DELAY_MS);
47276
+ const target = typeof globalThis.window === "undefined" ? void 0 : globalThis.window;
47277
+ if (target !== void 0) for (const type of RENEW_EVENTS) target.addEventListener(type, renew, {
47278
+ once: true,
47279
+ passive: true
47280
+ });
47281
+ state.renewal = () => {
47282
+ clearTimeout(timer);
47283
+ if (target === void 0) return;
47284
+ for (const type of RENEW_EVENTS) target.removeEventListener(type, renew);
47285
+ };
47286
+ }
47287
+ /**
47288
+ * Cancels the renewal that waits: the game went to the background again, or the app stops. A
47289
+ * renewal that already runs goes on.
47290
+ *
47291
+ * @param state - The plugin state.
47292
+ */
47293
+ function cancelRenewal(state) {
47294
+ state.renewal?.();
47295
+ state.renewal = void 0;
47296
+ }
47297
+ /**
47298
+ * Drops every sound of the old context and keeps the music key: the track that plays, or the
47299
+ * switch on its way. A decode still running on the old context may reject when it closes; such a
47300
+ * key is forgotten, so its next play decodes again.
47301
+ *
47302
+ * @param state - The plugin state.
47303
+ */
47304
+ function dropInFlight(state) {
47305
+ const key = state.musicPending?.key ?? state.music?.key;
47306
+ stopMusic(state);
47307
+ stopAllNamed(state);
47308
+ for (const entry of state.retiring) disposeStream(state, entry.stream);
47309
+ state.pendingSfx.clear();
47310
+ if (key !== void 0) state.music = {
47311
+ key,
47312
+ gain: void 0,
47313
+ source: void 0,
47314
+ stream: void 0
47315
+ };
47316
+ for (const [decodedKey, pending] of state.decoded) pending.catch(() => {
47317
+ if (state.decoded.get(decodedKey) === pending) state.decoded.delete(decodedKey);
47318
+ });
47319
+ }
47320
+ /**
47321
+ * Renews the context: the old one goes with every sound in it, the session is written again, and
47322
+ * a new context gets the graph at the same volumes and the unlock. The decoded buffers stay, an
47323
+ * AudioBuffer is bound to no context. The unlock starts the remembered music once the new context
47324
+ * runs. While the old context closes the plugin is headless: a sound is dropped and a music switch
47325
+ * is remembered. A stop, or a newer renewal, during the close makes this one end there.
47326
+ *
47327
+ * @param ctx - Domain context of the plugin.
47328
+ */
47329
+ async function renewContext(ctx) {
47330
+ const state = ctx.state;
47331
+ const old = state.context;
47332
+ if (old === void 0) return;
47333
+ const token = {};
47334
+ state.renewing = token;
47335
+ removeUnlock(state);
47336
+ dropInFlight(state);
47337
+ state.context = void 0;
47338
+ state.unlocked = false;
47339
+ state.resuming = false;
47340
+ writeSession(state, "auto");
47341
+ await old.close().catch(ignoreFailure);
47342
+ if (state.renewing !== token) return;
47343
+ state.renewing = void 0;
47344
+ writeSession(state, ctx.config.session);
47345
+ const fresh = createContext(ctx.config);
47346
+ if (fresh === void 0 || fresh === old) {
47347
+ ctx.log.warn("audio: no new context after the return, the sound stays off");
47348
+ return;
47349
+ }
47350
+ state.context = fresh;
47351
+ state.buses = buildGraph(fresh, state.buses);
47352
+ applyAllGains(state);
47353
+ startUnlock(ctx);
47354
+ }
47355
+ /**
47356
+ * Swallows a close that failed. A context the browser already tore down is gone either way, and
47357
+ * neither a teardown nor a renewal has anybody to report it to.
47358
+ */
47359
+ function ignoreFailure() {}
47360
+ //#endregion
46875
47361
  //#region src/plugins/audio/lifecycle.ts
46876
47362
  /**
46877
- * @file audio plugin — lifecycle: the dependency resolution, the one context of the app with its
46878
- * graph and its unlock, and the teardown that frees exactly what was opened.
47363
+ * @file audio plugin — lifecycle: the dependency resolution, the start that puts the context of
47364
+ * `context.ts` in with its graph and its unlock, and the teardown that frees exactly what was opened.
46879
47365
  */
46880
47366
  /**
46881
47367
  * Resolves the dependency APIs `flow`, `assets`, `model` and `time` with `ctx.require`.
@@ -46906,27 +47392,10 @@ function withDeps$4(ctx) {
46906
47392
  };
46907
47393
  }
46908
47394
  /**
46909
- * Swallows a close that failed. A context the browser already tore down is gone either way, and
46910
- * a teardown has nobody left to report to.
46911
- */
46912
- function ignoreFailure() {}
46913
- /**
46914
- * Makes the one context of the app: the configured factory, the browser's own constructor, or
46915
- * nothing at all, which is a headless run.
46916
- *
46917
- * @param config - The resolved plugin config.
46918
- * @returns The context, or `undefined` where the runtime has no WebAudio.
46919
- */
46920
- function createContext(config) {
46921
- if (config.context !== void 0) return config.context();
46922
- const browserContext = globalThis.AudioContext;
46923
- return typeof browserContext === "function" ? new browserContext() : void 0;
46924
- }
46925
- /**
46926
47395
  * Starts the plugin in `onStart`: the audio session first, before any sound exists, then the
46927
- * three effect handlers, then the context with its graph and its unlock. The unlock asks the context to
46928
- * run at once: a shell that lets audio play is unlocked with no touch, and a browser that wants a
46929
- * gesture gets the two listeners. The handlers are registered even headless, so a node that
47396
+ * three effect handlers, then the context with its graph and its unlock. The unlock asks the
47397
+ * context to run at once: a shell that lets audio play is unlocked with no touch, and a browser
47398
+ * that wants a gesture gets the two listeners. The handlers are registered even headless, so a node that
46930
47399
  * awaits a sound resolves in plain Bun exactly as it does in a browser.
46931
47400
  *
46932
47401
  * @param ctx - Kernel context of the audio plugin.
@@ -46946,16 +47415,18 @@ function startAudio(ctx) {
46946
47415
  }
46947
47416
  /**
46948
47417
  * Frees everything `onStart` opened: the three handler registrations, the two window listeners,
46949
- * the music track, every named sound, every streamed track still fading with its timer, the
46950
- * journal, the audio session and the context itself. The tracks are freed before the close, while their nodes can still
46951
- * disconnect. A browser caps how many contexts a page may hold, so the close is the point of this
46952
- * teardown.
47418
+ * a renewal that waits or runs, the music track, every named sound, every streamed track still
47419
+ * fading with its timer, the journal, the audio session and the context itself. The tracks are
47420
+ * freed before the close, while their nodes can still disconnect. A browser caps how many
47421
+ * contexts a page may hold, so the close is the point of this teardown.
46953
47422
  *
46954
47423
  * @param state - The plugin state, all a teardown context carries.
46955
47424
  * @returns A promise that resolves when the context is closed.
46956
47425
  */
46957
47426
  async function stopAudio(state) {
46958
47427
  for (const remove of state.removers.splice(0)) remove();
47428
+ cancelRenewal(state);
47429
+ state.renewing = void 0;
46959
47430
  removeUnlock(state);
46960
47431
  stopMusic(state);
46961
47432
  stopAllNamed(state);
@@ -47010,20 +47481,46 @@ function read$1(ctx, volumes) {
47010
47481
  }
47011
47482
  }
47012
47483
  /**
47484
+ * Tells whether the OS stopped a context: suspended, or Safari's `"interrupted"`.
47485
+ *
47486
+ * @param context - The audio context of this app.
47487
+ * @returns True when the context waits for a resume.
47488
+ */
47489
+ function isSilenced(context) {
47490
+ return context.state === "suspended" || context.state === "interrupted";
47491
+ }
47492
+ /**
47013
47493
  * Resumes a context the OS silenced while the game was away. Safari leaves it `"interrupted"`
47014
- * after a call; a refused resume puts the unlock listeners back, so the next touch tries again.
47494
+ * after a call, a screenshot or Control Center, and WebKit may hold this resume pending for as
47495
+ * long as iOS keeps the audio session (F146). So the unlock listeners go on before the resume and
47496
+ * come off only once the context runs: until then every touch tries again.
47015
47497
  *
47016
47498
  * @param ctx - Domain context of the plugin.
47017
47499
  */
47018
47500
  function resumeAfterPause(ctx) {
47019
- const context = ctx.state.context;
47020
- if (context === void 0 || !ctx.state.unlocked) return;
47021
- if (context.state !== "suspended" && context.state !== "interrupted") return;
47022
- context.resume().catch(() => {
47501
+ const state = ctx.state;
47502
+ const context = state.context;
47503
+ if (context === void 0 || !state.unlocked || !isSilenced(context)) return;
47504
+ installUnlock(ctx);
47505
+ context.resume().then(() => {
47506
+ if (state.context === context && context.state === "running") removeUnlock(state);
47507
+ }, () => {
47023
47508
  installUnlock(ctx);
47024
47509
  });
47025
47510
  }
47026
47511
  /**
47512
+ * Follows the `"background"` reason of the pause: its push cancels a renewal that waits, its pop
47513
+ * schedules one (F149). Any other reason leaves the context alone.
47514
+ *
47515
+ * @param ctx - Domain context of the plugin.
47516
+ * @param payload - What changed on the pause stack.
47517
+ */
47518
+ function followBackground(ctx, payload) {
47519
+ if (payload.reason !== "background") return;
47520
+ if (payload.action === "push") cancelRenewal(ctx.state);
47521
+ else scheduleRenewal(ctx);
47522
+ }
47523
+ /**
47027
47524
  * Forgets the decoded buffer and the one warning of every key named. A key that is no sound is in
47028
47525
  * neither, so it costs nothing. A source that is playing holds its own buffer and plays on.
47029
47526
  *
@@ -47080,7 +47577,8 @@ function createHandlers$3(ctx) {
47080
47577
  /**
47081
47578
  * Holds every bus at zero while the game is paused and puts the volumes back when it is not.
47082
47579
  * The stored volumes and mutes are untouched, so nothing is lost over a pause. A streamed
47083
- * track is paused once the gains are at zero and plays again when the pause ends.
47580
+ * track is paused once the gains are at zero and plays again when the pause ends. On iOS the
47581
+ * return from the background also schedules the renewal of the context.
47084
47582
  *
47085
47583
  * @param payload - What changed on the pause stack.
47086
47584
  */
@@ -47093,6 +47591,7 @@ function createHandlers$3(ctx) {
47093
47591
  resumeAfterPause(audioCtx);
47094
47592
  resumeMusic(audioCtx);
47095
47593
  }
47594
+ followBackground(audioCtx, payload);
47096
47595
  },
47097
47596
  /**
47098
47597
  * Drops the decoded sounds of a bundle that left. A source that is playing keeps its buffer
@@ -47203,6 +47702,8 @@ function createAudioState(ctx) {
47203
47702
  music: void 0,
47204
47703
  musicPending: void 0,
47205
47704
  unlock: void 0,
47705
+ renewal: void 0,
47706
+ renewing: void 0,
47206
47707
  removers: [],
47207
47708
  session: void 0,
47208
47709
  retiring: emptyRetiring(),
@@ -57656,6 +58157,10 @@ const TOKENS = /(\n| +)/;
57656
58157
  const HYPHEN_BREAKS = /(?<=[^\-\u2010][-\u2010])(?=[^\-\u2010\d])/;
57657
58158
  /** The soft hyphen: a break the text allows, drawn as `-` only when the line breaks there. */
57658
58159
  const SOFT_HYPHEN = "­";
58160
+ /** The most lines a balanced style evens out; a longer block keeps its greedy lines, as Chrome. */
58161
+ const BALANCE_MAX_LINES = 6;
58162
+ /** How many halvings the search for the balanced width takes: 2⁻¹⁶ of the range is left. */
58163
+ const BALANCE_STEPS = 16;
57659
58164
  /**
57660
58165
  * Tells whether a value is a plain record, so its fields can be read one by one.
57661
58166
  *
@@ -57893,19 +58398,32 @@ function measureRun(run, style, tables, options) {
57893
58398
  return width;
57894
58399
  }
57895
58400
  /**
58401
+ * Tells whether a glyph piece may join the last run of a line: both glyphs, with the same bold,
58402
+ * italic and colour. An icon never merges.
58403
+ *
58404
+ * @param last - The last run of the line, if any.
58405
+ * @param piece - The glyph piece to append.
58406
+ * @returns True when the piece's text may be added to `last`.
58407
+ */
58408
+ function canMerge(last, piece) {
58409
+ return last?.kind === "text" && last.bold === piece.bold && last.italic === piece.italic && last.color === piece.color;
58410
+ }
58411
+ /**
57896
58412
  * Appends a piece to a line, merging glyphs into the last run when both are glyphs with the same
57897
- * flags. An icon is always a run of its own.
58413
+ * flags. An icon is always a run of its own. A glyph piece is pushed as a copy, so the merge
58414
+ * writes into the line's own run and never into the token the piece came from: a balanced style
58415
+ * runs the wrap pass over the same tokens more than once.
57898
58416
  *
57899
58417
  * @param runs - The runs of the line so far.
57900
58418
  * @param piece - The piece to append.
57901
58419
  */
57902
58420
  function appendRun(runs, piece) {
57903
58421
  const last = runs.at(-1);
57904
- if (piece.kind === "text" && last?.kind === "text" && last.bold === piece.bold && last.italic === piece.italic && last.color === piece.color) {
58422
+ if (piece.kind === "text" && canMerge(last, piece)) {
57905
58423
  last.text += piece.text;
57906
58424
  return;
57907
58425
  }
57908
- runs.push(piece);
58426
+ runs.push(piece.kind === "text" ? { ...piece } : piece);
57909
58427
  }
57910
58428
  /**
57911
58429
  * Lays runs out with no wrapping: one line per `\n` segment.
@@ -58158,22 +58676,23 @@ function placeWord(builder, token, pending, wrap, metrics) {
58158
58676
  else breakWord(builder, token, wrap, metrics);
58159
58677
  }
58160
58678
  /**
58161
- * Lays runs out into lines no wider than the wrap. Words break between them, after a hyphen that
58162
- * joins two parts and at a soft hyphen; a word wider than the wrap breaks between its glyphs.
58679
+ * Lays tokens out into lines no wider than the wrap: the greedy pass. Words break between them,
58680
+ * after a hyphen that joins two parts and at a soft hyphen; a word wider than the wrap breaks
58681
+ * between its glyphs. The tokens are read and never changed, so the pass may run on them again.
58163
58682
  *
58164
- * @param runs - The runs of the block.
58683
+ * @param tokens - The tokens of the block.
58165
58684
  * @param metrics - The style, the tables and the warning.
58166
58685
  * @param wrap - The wrap width in reference pixels.
58167
58686
  * @returns The lines, each with its width.
58168
58687
  */
58169
- function layoutWrapped(runs, metrics, wrap) {
58688
+ function wrapTokens(tokens, metrics, wrap) {
58170
58689
  const builder = {
58171
58690
  lines: [],
58172
58691
  runs: [],
58173
58692
  width: 0
58174
58693
  };
58175
58694
  let pending;
58176
- for (const token of tokenise(runs, metrics.style, metrics.tables, metrics.options)) {
58695
+ for (const token of tokens) {
58177
58696
  if (token.kind === "break") {
58178
58697
  commit(builder);
58179
58698
  pending = void 0;
@@ -58194,6 +58713,59 @@ function layoutWrapped(runs, metrics, wrap) {
58194
58713
  return builder.lines;
58195
58714
  }
58196
58715
  /**
58716
+ * The narrowest line a word may stand on whole: the widest word with the `-` a break after it
58717
+ * draws. Below it a word breaks between its glyphs or its hyphen stands past the line.
58718
+ *
58719
+ * @param tokens - The tokens of the block.
58720
+ * @returns The width in reference pixels; 0 for a block with no word.
58721
+ * @example
58722
+ * ```ts
58723
+ * widestWord([{ kind: "word", runs: [], width: 80, tail: 0 }]); // 80
58724
+ * ```
58725
+ */
58726
+ function widestWord(tokens) {
58727
+ let widest = 0;
58728
+ for (const token of tokens) if (token.kind === "word") widest = Math.max(widest, token.width + token.tail);
58729
+ return widest;
58730
+ }
58731
+ /**
58732
+ * Evens the greedy lines of a balanced style: the narrowest width in `[widest word, wrap]` that
58733
+ * keeps their number, found in 16 halvings, and the lines at that width. A block of one line or of
58734
+ * more than six, or with a word that does not fit the wrap whole, keeps its greedy lines.
58735
+ *
58736
+ * @param tokens - The tokens of the block, as the greedy pass read them.
58737
+ * @param greedy - The greedy lines at the wrap.
58738
+ * @param metrics - The style, the tables and the warning.
58739
+ * @param wrap - The wrap width in reference pixels.
58740
+ * @returns The balanced lines, or the greedy ones.
58741
+ */
58742
+ function balanceLines(tokens, greedy, metrics, wrap) {
58743
+ const count = greedy.length;
58744
+ let low = widestWord(tokens);
58745
+ let high = wrap;
58746
+ if (count < 2 || count > BALANCE_MAX_LINES || low >= high) return greedy;
58747
+ for (let step = 0; step < BALANCE_STEPS; step += 1) {
58748
+ const middle = (low + high) / 2;
58749
+ if (wrapTokens(tokens, metrics, middle).length <= count) high = middle;
58750
+ else low = middle;
58751
+ }
58752
+ return high === wrap ? greedy : wrapTokens(tokens, metrics, high);
58753
+ }
58754
+ /**
58755
+ * Lays runs out into lines no wider than the wrap, evened out when the style balances. The tokens
58756
+ * are made once; the balance runs the wrap pass on them again.
58757
+ *
58758
+ * @param runs - The runs of the block.
58759
+ * @param metrics - The style, the tables and the warning.
58760
+ * @param wrap - The wrap width in reference pixels.
58761
+ * @returns The lines, each with its width.
58762
+ */
58763
+ function layoutWrapped(runs, metrics, wrap) {
58764
+ const tokens = tokenise(runs, metrics.style, metrics.tables, metrics.options);
58765
+ const greedy = wrapTokens(tokens, metrics, wrap);
58766
+ return metrics.style.balance === true ? balanceLines(tokens, greedy, metrics, wrap) : greedy;
58767
+ }
58768
+ /**
58197
58769
  * Wraps the caller's warning so one key is reported once per layout.
58198
58770
  *
58199
58771
  * @param options - What the caller passed.
@@ -69608,6 +70180,15 @@ function askedOffsetOf(container) {
69608
70180
  return typeof offset === "number" && Number.isFinite(offset) ? offset : 0;
69609
70181
  }
69610
70182
  /**
70183
+ * Whether the scroll's last render asks a new `offset` prop to stand there at once.
70184
+ *
70185
+ * @param container - The scroll element.
70186
+ * @returns True when its `jump` prop is true.
70187
+ */
70188
+ function jumpsOf(container) {
70189
+ return container.node.props.jump === true;
70190
+ }
70191
+ /**
69611
70192
  * The `snap` prop of the scroll's last render.
69612
70193
  *
69613
70194
  * @param container - The scroll element.
@@ -69981,9 +70562,27 @@ function place$1(ctx, container, content, motion) {
69981
70562
  ecs.add(content.entity, Transform(pose));
69982
70563
  }
69983
70564
  /**
70565
+ * Takes a new `offset` prop: with `jump` the scroll stands at it at once and stops, without it
70566
+ * glides there; either way it follows the prop from then on. A scroll the finger holds only
70567
+ * remembers it.
70568
+ *
70569
+ * @param motion - The motion of the scroll, its range already the one of this solve.
70570
+ * @param container - The scroll element.
70571
+ * @param asked - The new `offset` prop, from the start.
70572
+ */
70573
+ function followOffset(motion, container, asked) {
70574
+ if (motion.mode === "held") return;
70575
+ if (jumpsOf(container)) {
70576
+ motion.offset = within(asked, motion.max);
70577
+ stop(motion);
70578
+ } else glideTo(motion, asked);
70579
+ motion.atProp = true;
70580
+ }
70581
+ /**
69984
70582
  * Settles a placed scroll on what the solve and the render of this frame gave it: a new range at
69985
- * once, then a glide to a new `offset` prop, which the scroll follows from then on. A scroll the
69986
- * finger holds only remembers the prop.
70583
+ * once, then a glide to a new `offset` prop, which the scroll follows from then on. With `jump` it
70584
+ * stands at the new prop at once instead, in the solve that gave the content its new rects, and a
70585
+ * glide the new range re-aimed stops. A scroll the finger holds only remembers the prop.
69987
70586
  *
69988
70587
  * @param ctx - Domain context of the ui plugin.
69989
70588
  * @param state - The layout state, which keeps the patches.
@@ -69996,10 +70595,7 @@ function settle(ctx, state, container, content, motion) {
69996
70595
  const asked = askedOffsetOf(container);
69997
70596
  if (asked !== motion.seen) {
69998
70597
  motion.seen = asked;
69999
- if (motion.mode !== "held") {
70000
- glideTo(motion, asked);
70001
- motion.atProp = true;
70002
- }
70598
+ followOffset(motion, container, asked);
70003
70599
  }
70004
70600
  show(ctx, state, container, content, motion);
70005
70601
  }