@moku-labs/game 0.15.156 → 0.15.158

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.
@@ -8144,7 +8144,7 @@ function emptyComponents() {
8144
8144
  *
8145
8145
  * @returns An empty table of component name to its counts.
8146
8146
  */
8147
- function emptyMarks() {
8147
+ function emptyMarks$1() {
8148
8148
  return /* @__PURE__ */ new Map();
8149
8149
  }
8150
8150
  /**
@@ -8553,7 +8553,7 @@ function recordFrame(ctx, frame) {
8553
8553
  slots: emptySlots(),
8554
8554
  newest: void 0,
8555
8555
  started: void 0,
8556
- marks: emptyMarks(),
8556
+ marks: emptyMarks$1(),
8557
8557
  markList: [],
8558
8558
  markFrames: 0,
8559
8559
  warned: emptyNames()
@@ -10395,7 +10395,7 @@ function withDeps$9(ctx) {
10395
10395
  * @param key - Which list to read.
10396
10396
  * @returns The entries, or an empty list.
10397
10397
  */
10398
- function listOf$1(description, key) {
10398
+ function listOf$2(description, key) {
10399
10399
  const value = description[key];
10400
10400
  return Array.isArray(value) ? value : [];
10401
10401
  }
@@ -10457,7 +10457,7 @@ function isProjectionEntry(entry) {
10457
10457
  * @param register - What to do with an accepted entry.
10458
10458
  */
10459
10459
  function registerEach(ctx, feature, key, accepts, register) {
10460
- for (const entry of listOf$1(feature.description, key)) if (accepts(entry)) register(entry);
10460
+ for (const entry of listOf$2(feature.description, key)) if (accepts(entry)) register(entry);
10461
10461
  else ctx.log.warn("world:bad-feature-entry", {
10462
10462
  feature: feature.name,
10463
10463
  key
@@ -19434,7 +19434,7 @@ function releaseRange(kctx, id) {
19434
19434
  * @param id - The overlay's entity.
19435
19435
  * @returns The sprite, or `undefined` for an unknown id.
19436
19436
  */
19437
- function spriteOf$1(kctx, id) {
19437
+ function spriteOf$2(kctx, id) {
19438
19438
  return kctx.state.ranges.get(id)?.sprite;
19439
19439
  }
19440
19440
  /** The quads a range render hides for its duration: one list for the module, emptied after each render. */
@@ -19758,9 +19758,7 @@ function drawnBounds(pixi, top) {
19758
19758
  * record's held stage 2 results under the names its quad gives (F126 stage 4).
19759
19759
  */
19760
19760
  /** The numbers `renderShade` wants in the group this frame, in the order of `writeGlobals`. One array: it allocates nothing. */
19761
- const WANTED = /* @__PURE__ */ new Float32Array(24);
19762
- /** `uOutputTexture.z` of a pass that ends on the canvas: Pixi's sign for a root target, which turns `y` over. */
19763
- const ROOT_TARGET = -1;
19761
+ const WANTED$1 = /* @__PURE__ */ new Float32Array(24);
19764
19762
  /**
19765
19763
  * The first enabled slot of a stack: the one slot of a stack that fits the mode.
19766
19764
  *
@@ -19947,10 +19945,10 @@ function bindHeld(shade, record) {
19947
19945
  * @param at - Where the vector starts in `WANTED`.
19948
19946
  * @returns True when a number differed.
19949
19947
  */
19950
- function writeVector$1(target, at) {
19948
+ function writeVector$2(target, at) {
19951
19949
  let differs = false;
19952
19950
  for (let index = 0; index < 4; index += 1) {
19953
- const value = WANTED[at + index] ?? 0;
19951
+ const value = WANTED$1[at + index] ?? 0;
19954
19952
  if (target[index] !== value) {
19955
19953
  target[index] = value;
19956
19954
  differs = true;
@@ -19971,44 +19969,44 @@ function writeVector$1(target, at) {
19971
19969
  * @param now.tx - The top's x translation now.
19972
19970
  * @param now.ty - The top's y translation now.
19973
19971
  */
19974
- function writeGlobals(kctx, record, shade, source, now) {
19972
+ function writeGlobals$1(kctx, record, shade, source, now) {
19975
19973
  const { key } = record;
19976
19974
  const { width, height, pixelWidth, pixelHeight } = source;
19977
19975
  const screen = kctx.host.screen();
19978
19976
  const screenWidth = screen?.width ?? 0;
19979
19977
  const screenHeight = screen?.height ?? 0;
19980
19978
  const Ps = key[KEY.Ps] ?? 0;
19981
- WANTED[0] = width;
19982
- WANTED[1] = height;
19983
- WANTED[2] = 1 / width;
19984
- WANTED[3] = 1 / height;
19985
- WANTED[4] = pixelWidth;
19986
- WANTED[5] = pixelHeight;
19987
- WANTED[6] = 1 / pixelWidth;
19988
- WANTED[7] = 1 / pixelHeight;
19989
- WANTED[8] = .5 / pixelWidth;
19990
- WANTED[9] = .5 / pixelHeight;
19991
- WANTED[10] = 1 - .5 / pixelWidth;
19992
- WANTED[11] = 1 - .5 / pixelHeight;
19993
- WANTED[12] = (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0);
19994
- WANTED[13] = (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0);
19995
- WANTED[14] = width;
19996
- WANTED[15] = height;
19997
- WANTED[16] = 0;
19998
- WANTED[17] = 0;
19999
- WANTED[18] = screenWidth * now.r;
20000
- WANTED[19] = screenHeight * now.r;
20001
- WANTED[20] = screenWidth;
20002
- WANTED[21] = screenHeight;
20003
- WANTED[22] = ROOT_TARGET;
20004
- WANTED[23] = 0;
19979
+ WANTED$1[0] = width;
19980
+ WANTED$1[1] = height;
19981
+ WANTED$1[2] = 1 / width;
19982
+ WANTED$1[3] = 1 / height;
19983
+ WANTED$1[4] = pixelWidth;
19984
+ WANTED$1[5] = pixelHeight;
19985
+ WANTED$1[6] = 1 / pixelWidth;
19986
+ WANTED$1[7] = 1 / pixelHeight;
19987
+ WANTED$1[8] = .5 / pixelWidth;
19988
+ WANTED$1[9] = .5 / pixelHeight;
19989
+ WANTED$1[10] = 1 - .5 / pixelWidth;
19990
+ WANTED$1[11] = 1 - .5 / pixelHeight;
19991
+ WANTED$1[12] = (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0);
19992
+ WANTED$1[13] = (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0);
19993
+ WANTED$1[14] = width;
19994
+ WANTED$1[15] = height;
19995
+ WANTED$1[16] = 0;
19996
+ WANTED$1[17] = 0;
19997
+ WANTED$1[18] = screenWidth * now.r;
19998
+ WANTED$1[19] = screenHeight * now.r;
19999
+ WANTED$1[20] = screenWidth;
20000
+ WANTED$1[21] = screenHeight;
20001
+ WANTED$1[22] = -1;
20002
+ WANTED$1[23] = 0;
20005
20003
  const { vectors } = shade;
20006
- let differs = writeVector$1(vectors.uInputSize, 0);
20007
- differs = writeVector$1(vectors.uInputPixel, 4) || differs;
20008
- differs = writeVector$1(vectors.uInputClamp, 8) || differs;
20009
- differs = writeVector$1(vectors.uOutputFrame, 12) || differs;
20010
- differs = writeVector$1(vectors.uGlobalFrame, 16) || differs;
20011
- differs = writeVector$1(vectors.uOutputTexture, 20) || differs;
20004
+ let differs = writeVector$2(vectors.uInputSize, 0);
20005
+ differs = writeVector$2(vectors.uInputPixel, 4) || differs;
20006
+ differs = writeVector$2(vectors.uInputClamp, 8) || differs;
20007
+ differs = writeVector$2(vectors.uOutputFrame, 12) || differs;
20008
+ differs = writeVector$2(vectors.uGlobalFrame, 16) || differs;
20009
+ differs = writeVector$2(vectors.uOutputTexture, 20) || differs;
20012
20010
  if (differs) shade.gfu.update();
20013
20011
  }
20014
20012
  /**
@@ -20071,7 +20069,7 @@ function renderShade(kctx, pixi, matrices, record, now) {
20071
20069
  bindHeld(shade, record);
20072
20070
  const resized = source.pixelWidth !== shade.copiedWidth || source.pixelHeight !== shade.copiedHeight;
20073
20071
  if ((shade.copied !== record.s1Version || resized) && !copyPadded(kctx, pixi, matrices, record, output)) return false;
20074
- writeGlobals(kctx, record, shade, source, now);
20072
+ writeGlobals$1(kctx, record, shade, source, now);
20075
20073
  setOrigins(record.slots, 0, 0);
20076
20074
  key[KEY.r] = now.r;
20077
20075
  key[KEY.P] = now.P;
@@ -22886,7 +22884,7 @@ function createKeptApi(ctx, deps) {
22886
22884
  move: (id, slot) => moveRange(kctx, id, slot),
22887
22885
  release: (id) => releaseRange(kctx, id),
22888
22886
  kept: (id) => state.ranges.get(id)?.picture !== void 0,
22889
- sprite: (id) => spriteOf$1(kctx, id),
22887
+ sprite: (id) => spriteOf$2(kctx, id),
22890
22888
  stats: () => ({
22891
22889
  pictures: state.drawnPictures,
22892
22890
  mb: roundTo(state.bytes / BYTES_PER_MB$2, 2),
@@ -32160,6 +32158,734 @@ function destroyTexture(state, texture) {
32160
32158
  destroyWhole(texture);
32161
32159
  }
32162
32160
  //#endregion
32161
+ //#region src/plugins/world/projection/easing.ts
32162
+ /** How far the two back curves overshoot. */
32163
+ const BACK = 1.70158;
32164
+ /** The nine curves a step, a projection hook and a `defineMotion` transition may name. */
32165
+ const EASE_NAMES = [
32166
+ "linear",
32167
+ "in",
32168
+ "out",
32169
+ "inOut",
32170
+ "inCubic",
32171
+ "outCubic",
32172
+ "inOutCubic",
32173
+ "inBack",
32174
+ "outBack"
32175
+ ];
32176
+ /**
32177
+ * Eases the normalised time in one cell of a `Float64Array`, in place: `applyEase` for the frame
32178
+ * step. It takes no number and returns none, so a frame boxes no number whether V8 inlines it or
32179
+ * not. A curve nobody knows is linear, and a function ease is called with the same time.
32180
+ *
32181
+ * @param ease - The curve to apply.
32182
+ * @param cells - The cells; `cells[at]` holds the normalised time and receives the eased fraction.
32183
+ * @param at - The index of the cell.
32184
+ * @example
32185
+ * ```ts
32186
+ * const cells = Float64Array.of(0.5);
32187
+ * easeCell("out", cells, 0); // cells[0] === 0.75
32188
+ * ```
32189
+ */
32190
+ function easeCell(ease, cells, at) {
32191
+ const t = cells[at] ?? 0;
32192
+ if (typeof ease === "function") {
32193
+ cells[at] = ease(t);
32194
+ return;
32195
+ }
32196
+ switch (ease) {
32197
+ case "in":
32198
+ cells[at] = t * t;
32199
+ break;
32200
+ case "out":
32201
+ cells[at] = 1 - (1 - t) * (1 - t);
32202
+ break;
32203
+ case "inOut":
32204
+ cells[at] = t < .5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
32205
+ break;
32206
+ case "inCubic":
32207
+ cells[at] = t ** 3;
32208
+ break;
32209
+ case "outCubic":
32210
+ cells[at] = 1 - (1 - t) ** 3;
32211
+ break;
32212
+ case "inOutCubic":
32213
+ cells[at] = t < .5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2;
32214
+ break;
32215
+ case "inBack":
32216
+ cells[at] = 2.70158 * t ** 3 - BACK * t * t;
32217
+ break;
32218
+ case "outBack": cells[at] = 1 + 2.70158 * (t - 1) ** 3 + BACK * (t - 1) ** 2;
32219
+ }
32220
+ }
32221
+ /** The cell `applyEase` eases in. */
32222
+ const EASED$1 = /* @__PURE__ */ new Float64Array(1);
32223
+ /**
32224
+ * Eases a normalised time. A curve nobody knows is linear, and a function ease is called with
32225
+ * the same normalised time.
32226
+ *
32227
+ * @param ease - The curve to apply.
32228
+ * @param t - Normalised time between 0 and 1.
32229
+ * @returns The eased fraction. `inBack` dips below 0 and `outBack` rises above 1 in the middle.
32230
+ * @example
32231
+ * ```ts
32232
+ * applyEase("out", 0.5); // 0.75
32233
+ * applyEase("inCubic", 0.5); // 0.125
32234
+ * ```
32235
+ */
32236
+ function applyEase(ease, t) {
32237
+ EASED$1[0] = t;
32238
+ easeCell(ease, EASED$1, 0);
32239
+ return EASED$1[0] ?? 0;
32240
+ }
32241
+ //#endregion
32242
+ //#region src/plugins/renderer/sync/transition.ts
32243
+ /**
32244
+ * @file renderer/sync — the transition of a scene switch (spec 36). `scenes` asks for a picture of the screen being
32245
+ * left (`capture`): the next drawn frame copies the canvas texture into a texture of its pixel size, one copy and one
32246
+ * submit on the GPU, no render pass, the veil and the loader in it as drawn. At the swap `play` hangs the picture in the
32247
+ * look's top container, above every layer, and each render phase draws it for this frame of the transition: a sprite
32248
+ * that fades or slides off, or the unit quad on the body of a set member `effects` handed (`RevealLine`, `RevealRound`,
32249
+ * `Dissolve`), its uniforms written by name. At the end the picture leaves the stage and its texture is destroyed: 0
32250
+ * bytes at rest. The sprite, the mesh and its numbers are made once per application and kept, like the veil. This file
32251
+ * imports nothing of `leave.ts`; the take-down of the look at `play` is there.
32252
+ */
32253
+ /** The hint of the warning of a missing body: which set member each kind draws on. Export names, not set ids. */
32254
+ const BODY_HINT = "List the set member of the kind in a feature's filters: wipe RevealLine, iris RevealRound, dissolve Dissolve.";
32255
+ /** Label of the picture's texture and of what draws it. */
32256
+ const PICTURE_LABEL = "renderer.leave.picture";
32257
+ /** Where each number of a run sits in `TransitionRun.numbers`: the time, then what each kind writes by name. */
32258
+ const MS = 0;
32259
+ const ANGLE = 1;
32260
+ const SOFT = 2;
32261
+ const X = 3;
32262
+ const Y = 4;
32263
+ /** An iris's radius that shows every pixel: the distance to the farthest corner, past the soft edge. */
32264
+ const OPEN = 5;
32265
+ const SCALE = 6;
32266
+ const EDGE = 7;
32267
+ /** How many numbers a run holds. */
32268
+ const NUMBERS = 8;
32269
+ /** A number V8 cannot keep as a small integer: the first store of a field in double form, never shown. */
32270
+ const DOUBLE_SEED$1 = .5;
32271
+ /**
32272
+ * Where the display object goes this frame (its left and top edge, CSS px), as point data Pixi's `copyFrom` reads. The
32273
+ * fields start as doubles, so V8 keeps them in double form and each write lands in place. Pixi's own setter
32274
+ * (`position.x = x`) takes the number as an argument, and a double handed to a call that is not inlined is boxed: 16 B
32275
+ * a frame, whether it is inlined or not depends on the optimizer's budget (`transition.perf.ts`).
32276
+ */
32277
+ const AT = {
32278
+ x: DOUBLE_SEED$1,
32279
+ y: DOUBLE_SEED$1
32280
+ };
32281
+ /** What the display object is scaled by this frame, on x and on y; point data like `AT`. */
32282
+ const SCALED = {
32283
+ x: DOUBLE_SEED$1,
32284
+ y: DOUBLE_SEED$1
32285
+ };
32286
+ /** The eased progress of the frame, in place: `easeCell` takes no number and returns none, so a frame boxes none. */
32287
+ const EASED = /* @__PURE__ */ new Float64Array(1);
32288
+ /** The global filter numbers this frame wants, in the order of the group's vectors. One array: it allocates nothing. */
32289
+ const WANTED = /* @__PURE__ */ new Float32Array(24);
32290
+ /**
32291
+ * Tells whether a kind draws on a set body.
32292
+ *
32293
+ * @param kind - The transition kind.
32294
+ * @returns True for `wipe`, `iris` and `dissolve`.
32295
+ * @example
32296
+ * ```ts
32297
+ * isBodyKind("iris"); // true
32298
+ * ```
32299
+ */
32300
+ function isBodyKind(kind) {
32301
+ return kind === "wipe" || kind === "iris" || kind === "dissolve";
32302
+ }
32303
+ /**
32304
+ * Lets the picture of a run go: no longer counted as kept, destroyed whole, its bind groups let go first.
32305
+ *
32306
+ * @param sctx - Domain context of the sync module.
32307
+ * @param playing - The run.
32308
+ */
32309
+ function freePicture(sctx, playing) {
32310
+ const picture = playing.picture;
32311
+ if (picture === void 0) return;
32312
+ playing.picture = void 0;
32313
+ sctx.deps.host.keep(picture.source, false);
32314
+ destroyWhole(picture);
32315
+ }
32316
+ /**
32317
+ * Takes the picture's display objects out of the look's top, the top off the stage when no look runs, and shows the
32318
+ * look's own parts again for the next look.
32319
+ *
32320
+ * @param sctx - Domain context of the sync module.
32321
+ * @param objects - The engine's objects.
32322
+ */
32323
+ function unhang(sctx, objects) {
32324
+ const { sprite, mesh } = objects.picture;
32325
+ const pixi = sctx.deps.host.pixi();
32326
+ if (sprite !== void 0) {
32327
+ detach$1(sprite);
32328
+ if (pixi !== void 0) sprite.texture = pixi.Texture.EMPTY;
32329
+ }
32330
+ if (mesh !== void 0) detach$1(mesh);
32331
+ objects.frame.visible = true;
32332
+ if (sctx.ctx.state.sync.leave.run === void 0) detach$1(objects.top);
32333
+ }
32334
+ /**
32335
+ * Ends the transition asked for or playing at once: its picture leaves the stage and is destroyed, and a frame is asked
32336
+ * for, so the screen without it is drawn. Nothing asked: nothing happens.
32337
+ *
32338
+ * @param sctx - Domain context of the sync module.
32339
+ */
32340
+ function endTransition(sctx) {
32341
+ const leave = sctx.ctx.state.sync.leave;
32342
+ const playing = leave.playing;
32343
+ if (playing === void 0) return;
32344
+ delete leave.playing;
32345
+ if (leave.objects !== void 0) unhang(sctx, leave.objects);
32346
+ freePicture(sctx, playing);
32347
+ sctx.deps.demand.request();
32348
+ }
32349
+ /**
32350
+ * The transition a look shown now may play: none with reduced motion on for one that is cut then.
32351
+ *
32352
+ * @param leave - The leave branch of the sync state.
32353
+ * @param transition - The look's transition.
32354
+ * @returns The transition, or `undefined`.
32355
+ */
32356
+ function playableOf(leave, transition) {
32357
+ return leave.reduced && transition?.reduced === "cut" ? void 0 : transition;
32358
+ }
32359
+ /**
32360
+ * Answers the swap gate: the picture of the running look's transition, asked for at the first call, which asks for a
32361
+ * frame. `"wait"` until a drawn frame took it, `"ready"` then; `"none"` without a transition to play, after the swap,
32362
+ * and without a WebGPU device.
32363
+ *
32364
+ * @param sctx - Domain context of the sync module.
32365
+ * @returns What the swap does now.
32366
+ */
32367
+ function captureLeave(sctx) {
32368
+ const leave = sctx.ctx.state.sync.leave;
32369
+ const playing = leave.playing;
32370
+ if (playing?.capture === "taken") return "ready";
32371
+ if (playing?.capture === "asked") {
32372
+ sctx.deps.demand.request();
32373
+ return "wait";
32374
+ }
32375
+ const run = leave.run;
32376
+ const transition = run === void 0 || run.landed ? void 0 : run.transition;
32377
+ if (transition === void 0 || sctx.deps.host.device() === void 0) return "none";
32378
+ endTransition(sctx);
32379
+ leave.playing = {
32380
+ transition,
32381
+ picture: void 0,
32382
+ playStartedAt: 0,
32383
+ capture: "asked",
32384
+ drawn: transition.kind,
32385
+ quad: void 0,
32386
+ edgeColor: -1,
32387
+ numbers: new Float64Array(NUMBERS)
32388
+ };
32389
+ sctx.deps.demand.request();
32390
+ return "wait";
32391
+ }
32392
+ /**
32393
+ * Copies the canvas texture of the frame just drawn into a new picture of its pixel size and format: one encoder, one
32394
+ * copy, one submit, no render pass.
32395
+ *
32396
+ * @param sctx - Domain context of the sync module.
32397
+ * @param playing - The run, its picture asked for.
32398
+ * @returns True when the picture holds the frame.
32399
+ */
32400
+ function copyCanvas(sctx, playing) {
32401
+ const host = sctx.deps.host;
32402
+ const device = host.device();
32403
+ const pixi = host.pixi();
32404
+ const canvas = host.canvasTexture();
32405
+ if (device === void 0 || pixi === void 0 || canvas === void 0) return false;
32406
+ const picture = pixi.RenderTexture.create({
32407
+ width: canvas.width,
32408
+ height: canvas.height,
32409
+ resolution: 1,
32410
+ scaleMode: "linear",
32411
+ addressMode: "clamp-to-edge",
32412
+ autoGarbageCollect: false,
32413
+ format: canvas.format === "rgba8unorm" ? "rgba8unorm" : "bgra8unorm",
32414
+ label: PICTURE_LABEL
32415
+ });
32416
+ playing.picture = picture;
32417
+ host.keep(picture.source, true);
32418
+ host.initSource(picture.source);
32419
+ const target = host.gpuTexture(picture.source);
32420
+ if (target === void 0) return false;
32421
+ const encoder = device.createCommandEncoder();
32422
+ encoder.copyTextureToTexture({ texture: canvas }, { texture: target }, [canvas.width, canvas.height]);
32423
+ device.queue.submit([encoder.finish()]);
32424
+ playing.capture = "taken";
32425
+ return true;
32426
+ }
32427
+ /**
32428
+ * The picture of a transition after the stage render: a picture asked for is taken from a drawn frame. A frame with no
32429
+ * canvas texture to copy gives the transition up: the swap commits without it.
32430
+ *
32431
+ * @param sctx - Domain context of the sync module.
32432
+ * @param drawn - Whether Pixi drew the frame.
32433
+ */
32434
+ function afterLeave(sctx, drawn) {
32435
+ const leave = sctx.ctx.state.sync.leave;
32436
+ const playing = leave.playing;
32437
+ if (playing === void 0 || playing.capture !== "asked" || !drawn) return;
32438
+ if (copyCanvas(sctx, playing)) return;
32439
+ endTransition(sctx);
32440
+ if (leave.run !== void 0) leave.run.transition = void 0;
32441
+ }
32442
+ /**
32443
+ * Warns once per kind, in a dev or agent build, that a transition plays as a fade for want of its set body.
32444
+ *
32445
+ * @param sctx - Domain context of the sync module.
32446
+ * @param kind - The kind.
32447
+ */
32448
+ function warnMissingBody(sctx, kind) {
32449
+ if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__ || typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) {
32450
+ const warned = sctx.ctx.state.sync.leave.warnedKinds;
32451
+ if (warned.has(kind)) return;
32452
+ warned.add(kind);
32453
+ sctx.ctx.log.warn("renderer:transition-body-missing", {
32454
+ kind,
32455
+ hint: BODY_HINT
32456
+ });
32457
+ }
32458
+ }
32459
+ /**
32460
+ * Copies the numbers a frame of the transition reads into the run's own array, once at `play`.
32461
+ *
32462
+ * @param playing - The run.
32463
+ */
32464
+ function copyNumbers(playing) {
32465
+ const { transition, numbers } = playing;
32466
+ numbers[MS] = transition.ms;
32467
+ switch (transition.kind) {
32468
+ case "wipe":
32469
+ numbers[ANGLE] = transition.angle + Math.PI;
32470
+ numbers[SOFT] = transition.soft;
32471
+ break;
32472
+ case "iris": {
32473
+ const reachX = Math.max(transition.x, 1 - transition.x);
32474
+ const reachY = Math.max(transition.y, 1 - transition.y);
32475
+ numbers[X] = transition.x;
32476
+ numbers[Y] = transition.y;
32477
+ numbers[SOFT] = transition.soft;
32478
+ numbers[OPEN] = Math.sqrt(reachX * reachX + reachY * reachY) + transition.soft;
32479
+ break;
32480
+ }
32481
+ case "dissolve":
32482
+ numbers[SCALE] = transition.scale;
32483
+ numbers[EDGE] = transition.edge;
32484
+ }
32485
+ }
32486
+ /**
32487
+ * Starts a transition whose picture is taken, from now on the clock: what it is drawn with is picked, a kind whose body
32488
+ * was not handed is drawn as a fade.
32489
+ *
32490
+ * @param sctx - Domain context of the sync module.
32491
+ * @param playing - The run, its picture taken.
32492
+ */
32493
+ function startTransition(sctx, playing) {
32494
+ const kind = playing.transition.kind;
32495
+ const quad = isBodyKind(kind) ? sctx.ctx.state.sync.leave.bodies.get(kind) : void 0;
32496
+ playing.capture = "playing";
32497
+ playing.playStartedAt = sctx.ctx.deps.clock.now();
32498
+ playing.quad = quad;
32499
+ playing.drawn = !isBodyKind(kind) || quad !== void 0 ? kind : "fade";
32500
+ copyNumbers(playing);
32501
+ if (isBodyKind(kind) && quad === void 0) warnMissingBody(sctx, kind);
32502
+ sctx.deps.demand.request();
32503
+ }
32504
+ /**
32505
+ * Hands the renderer the body a kind draws on; a body handed again for the kind replaces it.
32506
+ *
32507
+ * @param sctx - Domain context of the sync module.
32508
+ * @param kind - The kind.
32509
+ * @param quad - The body.
32510
+ * @param member - The member's export name.
32511
+ * @returns What takes this body back, once: a later body for the kind stays; it ends a run drawn on the body and
32512
+ * destroys the shaders made on it.
32513
+ */
32514
+ function handBody(sctx, kind, quad, member) {
32515
+ const bodies = sctx.ctx.state.sync.leave.bodies;
32516
+ bodies.set(kind, quad);
32517
+ if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__ || typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) sctx.ctx.log.debug("renderer:transition-body", {
32518
+ kind,
32519
+ member
32520
+ });
32521
+ return () => {
32522
+ const leave = sctx.ctx.state.sync.leave;
32523
+ if (bodies.get(kind) === quad) bodies.delete(kind);
32524
+ if (leave.playing?.quad === quad) endTransition(sctx);
32525
+ const shaders = leave.objects?.picture.shaders;
32526
+ if (shaders === void 0) return;
32527
+ for (const [shadersKind, held] of shaders) {
32528
+ if (held.quad !== quad) continue;
32529
+ held.shader.destroy();
32530
+ shaders.delete(shadersKind);
32531
+ }
32532
+ };
32533
+ }
32534
+ /**
32535
+ * Hangs a display object of the picture in the look's top, the top last on the stage and drawn, the look's own veil and
32536
+ * frame hidden: they are in the picture.
32537
+ *
32538
+ * @param objects - The engine's objects.
32539
+ * @param stage - The stage of the application.
32540
+ * @param shown - The sprite or the mesh.
32541
+ */
32542
+ function hangPicture(objects, stage, shown) {
32543
+ if (stage.children.at(-1) !== objects.top) stage.addChild(objects.top);
32544
+ objects.top.visible = true;
32545
+ objects.veil.visible = false;
32546
+ objects.frame.visible = false;
32547
+ if (shown.parent !== objects.top) objects.top.addChild(shown);
32548
+ }
32549
+ /**
32550
+ * The sprite of a fade or a slide, made once and kept: it grows from its top left corner.
32551
+ *
32552
+ * @param pixi - The module that draws.
32553
+ * @param picture - The picture's objects.
32554
+ * @returns The sprite.
32555
+ */
32556
+ function spriteOf$1(pixi, picture) {
32557
+ if (picture.sprite === void 0) {
32558
+ picture.sprite = new pixi.Sprite(pixi.Texture.EMPTY);
32559
+ picture.sprite.label = PICTURE_LABEL;
32560
+ picture.sprite.anchor.set(0, 0);
32561
+ }
32562
+ return picture.sprite;
32563
+ }
32564
+ /**
32565
+ * Draws the picture on the sprite over the canvas at the frame's eased progress (`EASED[0]`): a fade lowers its alpha
32566
+ * from 1 to 0, a slide moves it whole off the canvas towards `to`.
32567
+ *
32568
+ * @param sprite - The sprite.
32569
+ * @param picture - The picture.
32570
+ * @param playing - The run.
32571
+ * @param screen - The canvas in CSS pixels.
32572
+ */
32573
+ function paintSprite(sprite, picture, playing, screen) {
32574
+ const eased = EASED[0] ?? 0;
32575
+ const { transition } = playing;
32576
+ if (sprite.texture !== picture) sprite.texture = picture;
32577
+ AT.x = screen.x;
32578
+ AT.y = screen.y;
32579
+ SCALED.x = screen.width / picture.width;
32580
+ SCALED.y = screen.height / picture.height;
32581
+ if (transition.kind !== "slide") {
32582
+ sprite.alpha = 1 - eased;
32583
+ placeAt(sprite);
32584
+ return;
32585
+ }
32586
+ sprite.alpha = 1;
32587
+ switch (transition.to) {
32588
+ case "left":
32589
+ AT.x = screen.x - eased * screen.width;
32590
+ break;
32591
+ case "right":
32592
+ AT.x = screen.x + eased * screen.width;
32593
+ break;
32594
+ case "up":
32595
+ AT.y = screen.y - eased * screen.height;
32596
+ break;
32597
+ case "down": AT.y = screen.y + eased * screen.height;
32598
+ }
32599
+ placeAt(sprite);
32600
+ }
32601
+ /**
32602
+ * Places a display object at `AT` and scales it by `SCALED`: Pixi's `copyFrom` compares both numbers with the point's
32603
+ * own and writes them where they differ, reading them inside Pixi, so no number is handed to a call.
32604
+ *
32605
+ * @param shown - The sprite or the mesh.
32606
+ */
32607
+ function placeAt(shown) {
32608
+ shown.position.copyFrom(AT);
32609
+ shown.scale.copyFrom(SCALED);
32610
+ }
32611
+ /**
32612
+ * The shader of a kind on its body, bound to the picture: made once per body, built again for another body, and the
32613
+ * picture's texture bound in place of the last run's under the texture names and the body's input names.
32614
+ *
32615
+ * @param pixi - The module that draws.
32616
+ * @param picture - The picture's objects, their globals made.
32617
+ * @param playing - The run, its body held.
32618
+ * @param source - The picture's texture.
32619
+ * @returns The shader, or `undefined` for a run with no body.
32620
+ */
32621
+ function shaderOf(pixi, picture, playing, source) {
32622
+ const { quad } = playing;
32623
+ const kind = playing.drawn;
32624
+ if (quad === void 0 || picture.globals === void 0 || !isBodyKind(kind)) return void 0;
32625
+ const held = picture.shaders.get(kind);
32626
+ if (held !== void 0 && held.quad === quad) {
32627
+ bindPicture(held.shader, quad, source);
32628
+ return held.shader;
32629
+ }
32630
+ held?.shader.destroy();
32631
+ const shader = quadShader(pixi, quad, picture.globals.group, source);
32632
+ picture.shaders.set(kind, {
32633
+ quad,
32634
+ shader
32635
+ });
32636
+ return shader;
32637
+ }
32638
+ /**
32639
+ * Binds a picture under the texture and sampler of a shader and of each input its body names, where another is bound.
32640
+ *
32641
+ * @param shader - The shader.
32642
+ * @param quad - Its body.
32643
+ * @param source - The picture's texture.
32644
+ */
32645
+ function bindPicture(shader, quad, source) {
32646
+ const { resources } = shader;
32647
+ if (resources.uTexture === source) return;
32648
+ resources.uTexture = source;
32649
+ resources.uSampler = source.style;
32650
+ for (const [index, name] of (quad.inputNames ?? []).entries()) resources[name] = index % 2 === 0 ? source : source.style;
32651
+ }
32652
+ /**
32653
+ * Copies a vector of `WANTED` into the group where it differs, both sides 32-bit numbers.
32654
+ *
32655
+ * @param target - The group's vector.
32656
+ * @param at - Where the vector starts in `WANTED`.
32657
+ * @returns True when a number differed.
32658
+ */
32659
+ function writeVector$1(target, at) {
32660
+ let differs = false;
32661
+ for (let index = 0; index < 4; index += 1) {
32662
+ const value = WANTED[at + index] ?? 0;
32663
+ if (target[index] !== value) {
32664
+ target[index] = value;
32665
+ differs = true;
32666
+ }
32667
+ }
32668
+ return differs;
32669
+ }
32670
+ /**
32671
+ * Writes the numbers a filter pass over the whole canvas hands a body: the input is the picture, `W` x `H` CSS and its
32672
+ * `pw` x `ph` pixels, the frame and the target the canvas. Uploaded once, only when one differs.
32673
+ *
32674
+ * @param picture - The picture's objects, their globals made.
32675
+ * @param source - The picture's texture.
32676
+ * @param screen - The canvas in CSS pixels.
32677
+ * @param resolution - The renderer resolution.
32678
+ */
32679
+ function writeGlobals(picture, source, screen, resolution) {
32680
+ const globals = picture.globals;
32681
+ if (globals === void 0) return;
32682
+ const { width, height } = screen;
32683
+ const { pixelWidth, pixelHeight } = source;
32684
+ WANTED[0] = width;
32685
+ WANTED[1] = height;
32686
+ WANTED[2] = 1 / width;
32687
+ WANTED[3] = 1 / height;
32688
+ WANTED[4] = pixelWidth;
32689
+ WANTED[5] = pixelHeight;
32690
+ WANTED[6] = 1 / pixelWidth;
32691
+ WANTED[7] = 1 / pixelHeight;
32692
+ WANTED[8] = .5 / pixelWidth;
32693
+ WANTED[9] = .5 / pixelHeight;
32694
+ WANTED[10] = 1 - .5 / pixelWidth;
32695
+ WANTED[11] = 1 - .5 / pixelHeight;
32696
+ WANTED[12] = 0;
32697
+ WANTED[13] = 0;
32698
+ WANTED[14] = width;
32699
+ WANTED[15] = height;
32700
+ WANTED[16] = 0;
32701
+ WANTED[17] = 0;
32702
+ WANTED[18] = width * resolution;
32703
+ WANTED[19] = height * resolution;
32704
+ WANTED[20] = width;
32705
+ WANTED[21] = height;
32706
+ WANTED[22] = -1;
32707
+ WANTED[23] = 0;
32708
+ const { vectors } = globals;
32709
+ let differs = writeVector$1(vectors.uInputSize, 0);
32710
+ differs = writeVector$1(vectors.uInputPixel, 4) || differs;
32711
+ differs = writeVector$1(vectors.uInputClamp, 8) || differs;
32712
+ differs = writeVector$1(vectors.uOutputFrame, 12) || differs;
32713
+ differs = writeVector$1(vectors.uGlobalFrame, 16) || differs;
32714
+ differs = writeVector$1(vectors.uOutputTexture, 20) || differs;
32715
+ if (differs) globals.group.update();
32716
+ }
32717
+ /**
32718
+ * Writes a wipe's uniforms for the frame's eased progress (`EASED[0]`): its line sweeps the picture away, `progress`
32719
+ * from 1 to 0; `angle` and `soft` where they differ. One function per kind: each write site sees one body's group.
32720
+ *
32721
+ * @param numbers - The run's numbers.
32722
+ * @param uniforms - The values of the body's uniform group.
32723
+ */
32724
+ function writeWipe(numbers, uniforms) {
32725
+ const angle = numbers[ANGLE] ?? 0;
32726
+ const soft = numbers[SOFT] ?? 0;
32727
+ uniforms.progress = 1 - (EASED[0] ?? 0);
32728
+ if (uniforms.angle !== angle) uniforms.angle = angle;
32729
+ if (uniforms.soft !== soft) uniforms.soft = soft;
32730
+ }
32731
+ /**
32732
+ * Writes an iris's uniforms for the frame's eased progress (`EASED[0]`): it closes around (`x`, `y`), `radius` from
32733
+ * `OPEN`, where every pixel shows, to 0; the rest where they differ.
32734
+ *
32735
+ * @param numbers - The run's numbers.
32736
+ * @param uniforms - The values of the body's uniform group.
32737
+ */
32738
+ function writeIris(numbers, uniforms) {
32739
+ const x = numbers[X] ?? 0;
32740
+ const y = numbers[Y] ?? 0;
32741
+ const soft = numbers[SOFT] ?? 0;
32742
+ uniforms.radius = (numbers[OPEN] ?? 0) * (1 - (EASED[0] ?? 0));
32743
+ if (uniforms.x !== x) uniforms.x = x;
32744
+ if (uniforms.y !== y) uniforms.y = y;
32745
+ if (uniforms.soft !== soft) uniforms.soft = soft;
32746
+ }
32747
+ /**
32748
+ * Writes a dissolve's uniforms for the frame's eased progress (`EASED[0]`): the noise eats the picture, `progress` from
32749
+ * 0 to 1; `scale` and `edge` where they differ, and `edgeColor` into the three channels of the colour uniform's own
32750
+ * array, 0..1 each, once a run.
32751
+ *
32752
+ * @param playing - The run.
32753
+ * @param transition - The dissolve.
32754
+ * @param uniforms - The values of the body's uniform group.
32755
+ */
32756
+ function writeDissolve(playing, transition, uniforms) {
32757
+ const scale = playing.numbers[SCALE] ?? 0;
32758
+ const edge = playing.numbers[EDGE] ?? 0;
32759
+ uniforms.progress = EASED[0] ?? 0;
32760
+ if (uniforms.scale !== scale) uniforms.scale = scale;
32761
+ if (uniforms.edge !== edge) uniforms.edge = edge;
32762
+ const color = uniforms.edgeColor;
32763
+ const hex = transition.edgeColor;
32764
+ if (playing.edgeColor === hex || !(color instanceof Float32Array)) return;
32765
+ color[0] = (hex >> 16 & 255) / 255;
32766
+ color[1] = (hex >> 8 & 255) / 255;
32767
+ color[2] = (hex & 255) / 255;
32768
+ playing.edgeColor = hex;
32769
+ }
32770
+ /**
32771
+ * Writes the body's own uniforms by name for this frame: the picture goes from whole to nothing.
32772
+ *
32773
+ * @param playing - The run.
32774
+ * @param uniforms - The values of the body's uniform group.
32775
+ */
32776
+ function writeBody(playing, uniforms) {
32777
+ const { transition } = playing;
32778
+ switch (transition.kind) {
32779
+ case "wipe":
32780
+ writeWipe(playing.numbers, uniforms);
32781
+ break;
32782
+ case "iris":
32783
+ writeIris(playing.numbers, uniforms);
32784
+ break;
32785
+ case "dissolve": writeDissolve(playing, transition, uniforms);
32786
+ }
32787
+ }
32788
+ /**
32789
+ * Draws the picture on the unit quad with its body over the canvas: the mesh, its geometry and the global numbers made
32790
+ * once and kept, the kind's shader on the mesh, bound to the picture.
32791
+ *
32792
+ * @param sctx - Domain context of the sync module.
32793
+ * @param pixi - The module that draws.
32794
+ * @param objects - The engine's objects.
32795
+ * @param playing - The run, its body held.
32796
+ * @param screen - The canvas in CSS pixels.
32797
+ * @returns The mesh, or `undefined` for a run with no body.
32798
+ */
32799
+ function paintMesh(sctx, pixi, objects, playing, screen) {
32800
+ const { picture } = objects;
32801
+ const texture = playing.picture;
32802
+ const fu = playing.quad?.fu;
32803
+ if (texture === void 0) return void 0;
32804
+ picture.globals ??= filterGlobals(pixi);
32805
+ const shader = shaderOf(pixi, picture, playing, texture.source);
32806
+ if (shader === void 0) return void 0;
32807
+ if (picture.mesh === void 0) {
32808
+ picture.geometry ??= unitQuad(pixi);
32809
+ picture.mesh = new pixi.Mesh({
32810
+ geometry: picture.geometry,
32811
+ shader
32812
+ });
32813
+ picture.mesh.label = PICTURE_LABEL;
32814
+ }
32815
+ const { mesh } = picture;
32816
+ if (mesh.shader !== shader) mesh.shader = shader;
32817
+ AT.x = screen.x;
32818
+ AT.y = screen.y;
32819
+ SCALED.x = screen.width;
32820
+ SCALED.y = screen.height;
32821
+ placeAt(mesh);
32822
+ writeGlobals(picture, texture.source, screen, sctx.deps.host.resolution());
32823
+ if (fu !== void 0) writeBody(playing, fu.uniforms);
32824
+ return mesh;
32825
+ }
32826
+ /**
32827
+ * The frame of a playing transition: its time on the clock from `play`, eased, the picture drawn for it above every
32828
+ * layer, a frame asked for; at the end the picture leaves and is destroyed.
32829
+ *
32830
+ * @param sctx - Domain context of the sync module.
32831
+ * @param objects - The engine's objects.
32832
+ * @param stage - The stage of the application.
32833
+ * @param screen - The canvas in CSS pixels.
32834
+ * @param playing - The run, playing.
32835
+ */
32836
+ function stepTransition(sctx, objects, stage, screen, playing) {
32837
+ const pixi = sctx.deps.host.pixi();
32838
+ const texture = playing.picture;
32839
+ const { ease } = playing.transition;
32840
+ const ms = playing.numbers[MS] ?? 0;
32841
+ if (pixi === void 0 || texture === void 0) return;
32842
+ const t = ms > 0 ? (sctx.ctx.deps.clock.now() - playing.playStartedAt) / ms : 1;
32843
+ EASED[0] = Math.min(1, Math.max(0, t));
32844
+ easeCell(ease, EASED, 0);
32845
+ const shown = playing.drawn === "fade" || playing.drawn === "slide" ? spriteOf$1(pixi, objects.picture) : paintMesh(sctx, pixi, objects, playing, screen);
32846
+ if (shown === void 0) return;
32847
+ if (shown === objects.picture.sprite) paintSprite(shown, texture, playing, screen);
32848
+ hangPicture(objects, stage, shown);
32849
+ if (t >= 1) {
32850
+ endTransition(sctx);
32851
+ return;
32852
+ }
32853
+ sctx.deps.demand.request();
32854
+ }
32855
+ /**
32856
+ * Destroys the picture's objects of a stopped application: the sprite, the mesh and its geometry, the shaders, and the
32857
+ * global numbers' buffer by hand (Pixi leaves it to a collector).
32858
+ *
32859
+ * @param picture - The picture's objects.
32860
+ */
32861
+ function destroyPictureObjects(picture) {
32862
+ if (picture.sprite !== void 0) {
32863
+ detach$1(picture.sprite);
32864
+ picture.sprite.destroy();
32865
+ }
32866
+ if (picture.mesh !== void 0) {
32867
+ detach$1(picture.mesh);
32868
+ picture.mesh.destroy();
32869
+ }
32870
+ picture.geometry?.destroy(true);
32871
+ picture.globals?.group.buffer?.destroy();
32872
+ for (const { shader } of picture.shaders.values()) shader.destroy();
32873
+ picture.shaders.clear();
32874
+ }
32875
+ /**
32876
+ * Drops the transition and frees what it holds when the plugin stops, while the application exists: the picture and
32877
+ * the objects that draw it.
32878
+ *
32879
+ * @param state - The sync branch of the plugin state.
32880
+ */
32881
+ function stopTransition(state) {
32882
+ const { leave } = state;
32883
+ const picture = leave.playing?.picture;
32884
+ delete leave.playing;
32885
+ if (picture !== void 0) destroyWhole(picture);
32886
+ if (leave.objects !== void 0) destroyPictureObjects(leave.objects.picture);
32887
+ }
32888
+ //#endregion
32163
32889
  //#region src/plugins/renderer/sync/leave.ts
32164
32890
  /** Label of the container the look hangs in, last on the stage. */
32165
32891
  const TOP_LABEL = "renderer.leave";
@@ -32167,6 +32893,10 @@ const TOP_LABEL = "renderer.leave";
32167
32893
  const TURN_MS = 1e3;
32168
32894
  /** A whole turn, in radians. */
32169
32895
  const TURN$1 = 2 * Math.PI;
32896
+ /** The most clock milliseconds `time` counts for one frame (its default `maxDeltaMs`). */
32897
+ const MAX_DELTA_MS = 50;
32898
+ /** The frames a parked layer waits beyond the veil's fade-out: the frame `scenes` starts counting in, and its last. */
32899
+ const SPARE_FRAMES = 2;
32170
32900
  /** The engine's ring: three quarters of a white circle 96 u across, 10 u wide, round ends, turned about its centre. */
32171
32901
  const RING = Object.freeze({
32172
32902
  kind: "arc",
@@ -32221,7 +32951,8 @@ function objectsOf(sctx) {
32221
32951
  frame,
32222
32952
  held,
32223
32953
  ring,
32224
- spinner
32954
+ spinner,
32955
+ picture: { shaders: /* @__PURE__ */ new Map() }
32225
32956
  };
32226
32957
  return leave.objects;
32227
32958
  }
@@ -32280,7 +33011,7 @@ function putBack(sctx, container, name) {
32280
33011
  * ```
32281
33012
  */
32282
33013
  function parkFrames(outMs) {
32283
- return Math.ceil(outMs / 50) + 2;
33014
+ return Math.ceil(outMs / MAX_DELTA_MS) + SPARE_FRAMES;
32284
33015
  }
32285
33016
  /**
32286
33017
  * Leaves a loader layer waiting where it hangs, at alpha 0, until the loader's views left it, or for `framesLeft`
@@ -32312,12 +33043,13 @@ function park(sctx, container, name, framesLeft) {
32312
33043
  *
32313
33044
  * @param sctx - Domain context of the sync module.
32314
33045
  * @param run - The look whose layer goes.
33046
+ * @param outMs - The fade-out the layer waits after: the veil's, or 0 when a transition's picture took its place.
32315
33047
  */
32316
- function unlift(sctx, run) {
33048
+ function unlift(sctx, run, outMs) {
32317
33049
  const lifted = run.lifted;
32318
33050
  if (lifted === void 0) return;
32319
33051
  delete run.lifted;
32320
- if (run.landed && lifted.children.length > 0) park(sctx, lifted, run.layer, parkFrames(run.look.cover?.outMs ?? 0));
33052
+ if (run.landed && lifted.children.length > 0) park(sctx, lifted, run.layer, parkFrames(outMs));
32321
33053
  else putBack(sctx, lifted, run.layer);
32322
33054
  }
32323
33055
  /**
@@ -32341,11 +33073,12 @@ function stepParked(sctx, parked) {
32341
33073
  * spinner lets the game's texture go. A frame is asked for, so the screen without it is drawn.
32342
33074
  *
32343
33075
  * @param sctx - Domain context of the sync module.
33076
+ * @param outMs - The fade-out a layer loader's layer waits after; the veil's when left out.
32344
33077
  */
32345
- function takeDown(sctx) {
33078
+ function takeDown(sctx, outMs) {
32346
33079
  const leave = sctx.ctx.state.sync.leave;
32347
33080
  const run = leave.run;
32348
- if (run !== void 0) unlift(sctx, run);
33081
+ if (run !== void 0) unlift(sctx, run, outMs ?? run.look.cover?.outMs ?? 0);
32349
33082
  delete leave.run;
32350
33083
  const objects = leave.objects;
32351
33084
  if (objects !== void 0) {
@@ -32510,16 +33243,19 @@ function paintLoader(sctx, objects, run, now) {
32510
33243
  /**
32511
33244
  * Shows a look from now, in place of one that runs: the veil fades in from where it stands (0, or the level of a veil
32512
33245
  * still fading out after the last swap), the loader waits for its `afterMs`. A layer the last loader faded out with
32513
- * waits unseen for its views to leave. Inert, nothing is kept.
33246
+ * waits unseen for its views to leave. A transition still playing ends at once, its picture freed, so the new look's
33247
+ * own picture is the screen as it stands; with reduced motion on, a transition cut then is dropped. Inert, nothing is
33248
+ * kept.
32514
33249
  *
32515
33250
  * @param sctx - Domain context of the sync module.
32516
- * @param look - The veil and the loader, resolved.
33251
+ * @param look - The veil, the loader and the transition, resolved.
32517
33252
  */
32518
33253
  function showLeave(sctx, look) {
32519
33254
  const state = sctx.ctx.state.sync;
32520
33255
  if (state.root === void 0) return;
33256
+ endTransition(sctx);
32521
33257
  const before = state.leave.run;
32522
- if (before !== void 0) unlift(sctx, before);
33258
+ if (before !== void 0) unlift(sctx, before, before.look.cover?.outMs ?? 0);
32523
33259
  const now = sctx.ctx.deps.clock.now();
32524
33260
  const level = before?.look.cover === void 0 ? 0 : before.level;
32525
33261
  const loader = loaderOf$1(sctx, look);
@@ -32532,6 +33268,7 @@ function showLeave(sctx, look) {
32532
33268
  landedLevel: 1,
32533
33269
  asked: false,
32534
33270
  shown: false,
33271
+ transition: playableOf(state.leave, look.transition),
32535
33272
  ...loader
32536
33273
  };
32537
33274
  sctx.deps.demand.request();
@@ -32540,12 +33277,15 @@ function showLeave(sctx, look) {
32540
33277
  * The swap came: the veil fades out over its `outMs` from where it stands, and a layer loader that shows stays above
32541
33278
  * it and fades with it, its layer waiting unseen at the end until the loader's views left it; a ring or a texture goes
32542
33279
  * at once. A look without a veil, or with `outMs: 0`, is taken down at once, a layer loader's layer waiting the same.
32543
- * Nothing runs, or the swap was told already: nothing happens.
33280
+ * A picture asked for and not played is freed; a transition playing goes on. Nothing runs, or the swap was told
33281
+ * already: nothing happens.
32544
33282
  *
32545
33283
  * @param sctx - Domain context of the sync module.
32546
33284
  */
32547
33285
  function landLeave(sctx) {
32548
- const run = sctx.ctx.state.sync.leave.run;
33286
+ const leave = sctx.ctx.state.sync.leave;
33287
+ if (leave.playing !== void 0 && leave.playing.capture !== "playing") endTransition(sctx);
33288
+ const run = leave.run;
32549
33289
  if (run === void 0 || run.landed) return;
32550
33290
  run.landed = true;
32551
33291
  run.landedLevel = run.level;
@@ -32558,33 +33298,56 @@ function landLeave(sctx) {
32558
33298
  sctx.deps.demand.request();
32559
33299
  }
32560
33300
  /**
32561
- * The switch ended without a swap: the veil and the loader go at once, a lifted layer back under the root. Nothing
32562
- * runs: nothing happens.
33301
+ * The switch ended without a swap: the veil and the loader go at once, a lifted layer back under the root, and a
33302
+ * transition's picture, asked for or playing, is freed. Nothing runs: nothing happens.
32563
33303
  *
32564
33304
  * @param sctx - Domain context of the sync module.
32565
33305
  */
32566
33306
  function dropLeave(sctx) {
33307
+ endTransition(sctx);
32567
33308
  if (sctx.ctx.state.sync.leave.run === void 0) return;
32568
33309
  takeDown(sctx);
32569
33310
  }
32570
33311
  /**
33312
+ * The swap came with the picture taken: the transition plays from now. The veil, a ring or a texture loader leave at
33313
+ * once (they are in the picture), a layer loader's layer waits unseen for its views to leave as after `outMs: 0`, and
33314
+ * the look's run ends, so a `land` after it changes nothing. No picture taken: nothing happens.
33315
+ *
33316
+ * @param sctx - Domain context of the sync module.
33317
+ */
33318
+ function playLeave(sctx) {
33319
+ const leave = sctx.ctx.state.sync.leave;
33320
+ const playing = leave.playing;
33321
+ if (playing?.capture !== "taken") return;
33322
+ const run = leave.run;
33323
+ if (run !== void 0) {
33324
+ run.landed = true;
33325
+ run.landedLevel = run.level;
33326
+ takeDown(sctx, 0);
33327
+ }
33328
+ startTransition(sctx, playing);
33329
+ }
33330
+ /**
32571
33331
  * The look of this frame, before the decision: the veil's level from the clock, the loader once due, both placed over
32572
33332
  * the canvas as it stands, and a frame asked for while either moves. A look whose veil faded out after the swap is
32573
- * taken down, a layer loader fading with it left waiting; a waiting layer whose views left goes back. Two field reads
32574
- * and no allocation while no look runs, none during a fade or a wait either; a lost device leaves the look waiting for
32575
- * the restore, which makes its objects again.
33333
+ * taken down, a layer loader fading with it left waiting; a waiting layer whose views left goes back; a transition
33334
+ * that plays draws its frame (`stepTransition`). Three field reads and no allocation while no look runs, none during a
33335
+ * fade or a wait either; a lost device leaves the look waiting for the restore, which makes its objects again.
32576
33336
  *
32577
33337
  * @param sctx - Domain context of the sync module.
32578
33338
  */
32579
33339
  function stepLeave(sctx) {
32580
33340
  const leave = sctx.ctx.state.sync.leave;
32581
33341
  const run = leave.run;
33342
+ const playing = leave.playing;
32582
33343
  if (leave.parked !== void 0) stepParked(sctx, leave.parked);
32583
- if (run === void 0) return;
33344
+ if (run === void 0 && playing === void 0) return;
32584
33345
  const objects = objectsOf(sctx);
32585
33346
  const stage = sctx.deps.host.stage();
32586
33347
  const screen = sctx.deps.host.screen();
32587
33348
  if (objects === void 0 || stage === void 0 || screen === void 0) return;
33349
+ if (playing?.capture === "playing") stepTransition(sctx, objects, stage, screen, playing);
33350
+ if (run === void 0) return;
32588
33351
  const now = sctx.ctx.deps.clock.now();
32589
33352
  const moved = advance(run, now);
32590
33353
  if (run.landed && run.level <= 0) {
@@ -32598,23 +33361,26 @@ function stepLeave(sctx) {
32598
33361
  }
32599
33362
  /**
32600
33363
  * Forgets the objects of a lost application: they go with its stage, and so does a layer lifted above the veil or
32601
- * waiting there. The running look stays: the step makes its objects again on the restored device.
33364
+ * waiting there, and a transition's picture, whose transition ends. The running look stays: the step makes its
33365
+ * objects again on the restored device.
32602
33366
  *
32603
33367
  * @param state - The sync branch of the plugin state.
32604
33368
  */
32605
33369
  function forgetLeave$1(state) {
33370
+ delete state.leave.playing;
32606
33371
  delete state.leave.objects;
32607
33372
  delete state.leave.parked;
32608
33373
  if (state.leave.run !== void 0) delete state.leave.run.lifted;
32609
33374
  }
32610
33375
  /**
32611
- * Drops the look and frees the engine's objects when the plugin stops. A lifted or waiting layer is the layer table's
32612
- * and the spinner's texture is the game's: neither is freed with them.
33376
+ * Drops the look and frees the engine's objects when the plugin stops, a transition's picture and what draws it first.
33377
+ * A lifted or waiting layer is the layer table's and the spinner's texture is the game's: neither is freed with them.
32613
33378
  *
32614
33379
  * @param state - The sync branch of the plugin state.
32615
33380
  */
32616
33381
  function stopLeave(state) {
32617
33382
  const objects = state.leave.objects;
33383
+ stopTransition(state);
32618
33384
  delete state.leave.run;
32619
33385
  delete state.leave.objects;
32620
33386
  delete state.leave.parked;
@@ -35402,7 +36168,8 @@ function withDeps$8(ctx) {
35402
36168
  * drawn and clears them; a drawn frame draws the probes of the warm-up onto the canvas first (F4: the
35403
36169
  * stage pass clears them, in the same task, so they never show), then uploads the queued texture sources (F60), then
35404
36170
  * the kept pictures (`kept.flush`, so the canvas stays one pass, E7), then the stage, then a shot of the frame just drawn
35405
- * while the canvas texture holds it (`shots.after`, never of the heat map), then, when Pixi drew it, the decoded images
36171
+ * while the canvas texture holds it (`shots.after`, never of the heat map), then the copy of a transition's picture
36172
+ * (`sync.leaveAfter`, spec 36), then, when Pixi drew it, the decoded images
35406
36173
  * now on the GPU are freed (`sync.releaseStep`, F189), then the pixel leg of the kept oracle;
35407
36174
  * `demand` settles the frame (the dev check, the pixel oracle), and `monitor` closes it and hands a drawn one to a
35408
36175
  * waiting capture; last, `host` trims Pixi's texture pool when a rest or a scene change is due. The display objects
@@ -35443,6 +36210,7 @@ function renderFrame(ctx, modules) {
35443
36210
  modules.kept.flush();
35444
36211
  const rendered = overdraw ? modules.sync.drawOverdraw(modules.host.render) : modules.host.render();
35445
36212
  modules.shots.after(rendered && !overdraw);
36213
+ modules.sync.leaveAfter(rendered && !overdraw);
35446
36214
  if (rendered) {
35447
36215
  ctx.deps.time.frameDrawn();
35448
36216
  trailFrame(ctx.state.trail, uploaded);
@@ -38723,7 +39491,13 @@ function createSyncApi(ctx, deps) {
38723
39491
  leave: {
38724
39492
  show: (look) => showLeave(sctx, look),
38725
39493
  land: () => landLeave(sctx),
38726
- drop: () => dropLeave(sctx)
39494
+ drop: () => dropLeave(sctx),
39495
+ capture: () => captureLeave(sctx),
39496
+ play: () => playLeave(sctx),
39497
+ body: (kind, quad, member) => handBody(sctx, kind, quad, member),
39498
+ setReducedMotion: (on) => {
39499
+ state.leave.reduced = on;
39500
+ }
38727
39501
  },
38728
39502
  renderPasses: () => renderPassesOf(state, ctx.state.kept),
38729
39503
  canvasPasses: () => canvasPassesOf(state),
@@ -38732,6 +39506,7 @@ function createSyncApi(ctx, deps) {
38732
39506
  layerOf: (entity) => layerOf$1(sctx, entity),
38733
39507
  stepOverlays: () => stepOverlays(sctx),
38734
39508
  stepLeave: () => stepLeave(sctx),
39509
+ leaveAfter: (drawn) => afterLeave(sctx, drawn),
38735
39510
  stepFilters: () => applySwitched(state, deps.kept),
38736
39511
  drainOverlayEvents: (monitor) => drainOverlayEvents(sctx, monitor),
38737
39512
  warmStep: () => warmStep(sctx),
@@ -39672,7 +40447,11 @@ function createSyncState(debug) {
39672
40447
  version: 0,
39673
40448
  reported: false
39674
40449
  },
39675
- leave: {},
40450
+ leave: {
40451
+ bodies: emptyMap$6(),
40452
+ reduced: false,
40453
+ warnedKinds: emptySet$4()
40454
+ },
39676
40455
  cleanups: []
39677
40456
  };
39678
40457
  }
@@ -41653,75 +42432,6 @@ function sumOffsets(actx, key) {
41653
42432
  return cellValue(SUM);
41654
42433
  }
41655
42434
  //#endregion
41656
- //#region src/plugins/anim/tween/easing.ts
41657
- /** How far the two back curves overshoot. */
41658
- const BACK = 1.70158;
41659
- /**
41660
- * Eases the normalised time in one cell of a `Float64Array`, in place: `applyEase` for the frame
41661
- * step. It takes no number and returns none, so a frame boxes no number whether V8 inlines it or
41662
- * not. A curve nobody knows is linear, and a function ease is called with the same time.
41663
- *
41664
- * @param ease - The curve to apply.
41665
- * @param cells - The cells; `cells[at]` holds the normalised time and receives the eased fraction.
41666
- * @param at - The index of the cell.
41667
- * @example
41668
- * ```ts
41669
- * const cells = Float64Array.of(0.5);
41670
- * easeCell("out", cells, 0); // cells[0] === 0.75
41671
- * ```
41672
- */
41673
- function easeCell(ease, cells, at) {
41674
- const t = cells[at] ?? 0;
41675
- if (typeof ease === "function") {
41676
- cells[at] = ease(t);
41677
- return;
41678
- }
41679
- switch (ease) {
41680
- case "in":
41681
- cells[at] = t * t;
41682
- break;
41683
- case "out":
41684
- cells[at] = 1 - (1 - t) * (1 - t);
41685
- break;
41686
- case "inOut":
41687
- cells[at] = t < .5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
41688
- break;
41689
- case "inCubic":
41690
- cells[at] = t ** 3;
41691
- break;
41692
- case "outCubic":
41693
- cells[at] = 1 - (1 - t) ** 3;
41694
- break;
41695
- case "inOutCubic":
41696
- cells[at] = t < .5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2;
41697
- break;
41698
- case "inBack":
41699
- cells[at] = 2.70158 * t ** 3 - BACK * t * t;
41700
- break;
41701
- case "outBack": cells[at] = 1 + 2.70158 * (t - 1) ** 3 + BACK * (t - 1) ** 2;
41702
- }
41703
- }
41704
- /** The cell `applyEase` eases in. */
41705
- const EASED = /* @__PURE__ */ new Float64Array(1);
41706
- /**
41707
- * Eases a normalised time. A curve nobody knows is linear, and a function ease is called with
41708
- * the same normalised time.
41709
- *
41710
- * @param ease - The curve to apply.
41711
- * @param t - Normalised time between 0 and 1.
41712
- * @returns The eased fraction. `inBack` dips below 0 and `outBack` rises above 1 in the middle.
41713
- * @example
41714
- * ```ts
41715
- * applyEase("out", 0.5); // 0.75
41716
- * applyEase("inCubic", 0.5); // 0.125
41717
- * ```
41718
- */
41719
- function applyEase(ease, t) {
41720
- EASED[0] = t;
41721
- easeCell(ease, EASED, 0);
41722
- return EASED[0] ?? 0;
41723
- }
41724
- //#endregion
41725
42435
  //#region src/plugins/anim/tween/advance.ts
41726
42436
  /**
41727
42437
  * @file anim/tween — the one track table: starting a track, the retarget policy per field, the
@@ -42908,7 +43618,9 @@ function startAnim(ctx) {
42908
43618
  actx.state.removeDriver = actx.deps.world.projection.setDriver(createDriver(actx));
42909
43619
  actx.state.offPlay = actx.deps.flow.fx.handle("play", createPlayHandler(actx, rt), { runInFast: false });
42910
43620
  openFrameLoops(actx);
42911
- actx.state.loopsHeld = ctx.require(rendererPlugin).sync.loopsHeld;
43621
+ const renderer = ctx.require(rendererPlugin);
43622
+ actx.state.loopsHeld = renderer.sync.loopsHeld;
43623
+ renderer.sync.leave.setReducedMotion(actx.state.reducedMotion);
42912
43624
  }
42913
43625
  /**
42914
43626
  * Closes what the plugin opened. Everything is finished first, so every pending `done` resolves,
@@ -42972,6 +43684,7 @@ function createAnimApi(ctx) {
42972
43684
  reducedMotion: () => actx.state.reducedMotion,
42973
43685
  setReducedMotion: (on) => {
42974
43686
  actx.state.reducedMotion = on;
43687
+ ctx.require(rendererPlugin).sync.leave.setReducedMotion(on);
42975
43688
  },
42976
43689
  replace: (definition) => {
42977
43690
  if (!actx.state.registry.has(definition.id)) throw new Error(`[game] Animation "${definition.id}" is not registered.\n Register it before replacing it.`);
@@ -45623,7 +46336,7 @@ function pickIo(ctx) {
45623
46336
  * @param value - What the feature put under that key.
45624
46337
  * @returns The entries, or an empty list.
45625
46338
  */
45626
- function listOf(value) {
46339
+ function listOf$1(value) {
45627
46340
  return Array.isArray(value) ? value : [];
45628
46341
  }
45629
46342
  /**
@@ -45651,8 +46364,8 @@ function stringField(entry, key) {
45651
46364
  */
45652
46365
  function readFeatures(ctx) {
45653
46366
  for (const feature of ctx.deps.flow.features.all()) {
45654
- for (const scene of listOf(feature.description.scenes)) if (isSceneDefinition(scene)) ctx.state.scenes.set(scene.id, scene);
45655
- for (const flow of listOf(feature.description.flows)) {
46367
+ for (const scene of listOf$1(feature.description.scenes)) if (isSceneDefinition(scene)) ctx.state.scenes.set(scene.id, scene);
46368
+ for (const flow of listOf$1(feature.description.flows)) {
45656
46369
  const id = stringField(flow, "id");
45657
46370
  if (id !== void 0) ctx.state.featureOfFlow.set(id, feature.name);
45658
46371
  }
@@ -46983,6 +47696,11 @@ const FALLBACK_FRAME_MS = SECOND_MS / 60;
46983
47696
  */
46984
47697
  const HOLD_FRAMES = 2;
46985
47698
  /**
47699
+ * The frames the swap waits for the picture of a transition: the first asks for it, the next one holds it. A renderer
47700
+ * that still answers `"wait"` after this many frames gets no more: the switch commits without the transition.
47701
+ */
47702
+ const CAPTURE_FRAMES = 3;
47703
+ /**
46986
47704
  * Tells whether a value is a number a frame can count with: finite and above 0. Pure.
46987
47705
  *
46988
47706
  * @param value - The value.
@@ -47048,6 +47766,7 @@ function endBuild(ctx, build, how) {
47048
47766
  build.off();
47049
47767
  delete ctx.state.build;
47050
47768
  if (how === "mount") ctx.deps.world.projection.discard();
47769
+ const leaving = ctx.state.leaving;
47051
47770
  try {
47052
47771
  swapIn(ctx, build.scene, build.named, how === "commit" ? build : void 0);
47053
47772
  } catch (error) {
@@ -47056,6 +47775,7 @@ function endBuild(ctx, build, how) {
47056
47775
  build.reject(error);
47057
47776
  return;
47058
47777
  }
47778
+ if (leaving?.transition?.ready === true) playTransition(ctx, leaving);
47059
47779
  build.resolve();
47060
47780
  }
47061
47781
  /**
@@ -47078,8 +47798,43 @@ function holdOver(ctx, frame, elapsed) {
47078
47798
  return false;
47079
47799
  }
47080
47800
  /**
47081
- * Tells whether a running build may commit now: every part of it is done and the floor on the swap
47082
- * passed. Two calls, no allocation.
47801
+ * Asks the renderer whether the swap may commit with the transition of the look (spec 36). `"ready"`: the picture holds
47802
+ * the last drawn frame, the commit plays it. `"none"`: no picture can be taken, the swap commits as without a transition.
47803
+ * `"wait"`: the swap holds and the loop is kept awake for the frame that copies the picture, until `CAPTURE_FRAMES` frames
47804
+ * passed, then it commits without one (the renderer frees the picture asked for when the look lands). A look with no
47805
+ * transition asks nothing. One call and a counter step, no allocation.
47806
+ *
47807
+ * @param ctx - Domain context of the plugin.
47808
+ * @returns True when the swap may commit.
47809
+ */
47810
+ function pictureTaken(ctx) {
47811
+ const gate = ctx.state.leaving?.transition;
47812
+ if (gate === void 0) return true;
47813
+ const answer = ctx.deps.renderer.sync.leave.capture();
47814
+ if (answer === "wait" && gate.captureFrames < CAPTURE_FRAMES) {
47815
+ gate.captureFrames += 1;
47816
+ ctx.deps.time.wake();
47817
+ return false;
47818
+ }
47819
+ gate.ready = answer === "ready";
47820
+ return true;
47821
+ }
47822
+ /**
47823
+ * Plays the transition of the look right after the swap, in the same phase, so the swap frame draws the picture of the
47824
+ * scene that left over the scene that came. The veil and a ring or texture loader leave with the picture's start: the
47825
+ * loader projection the switch mounted is unmounted at once as well, as with a veil of `outMs: 0`, since it is in the
47826
+ * picture.
47827
+ *
47828
+ * @param ctx - Domain context of the plugin.
47829
+ * @param leaving - The look of the switch.
47830
+ */
47831
+ function playTransition(ctx, leaving) {
47832
+ ctx.deps.renderer.sync.leave.play();
47833
+ leaving.outMs = 0;
47834
+ }
47835
+ /**
47836
+ * Tells whether a running build may commit now: every part of it is done, the floor on the swap
47837
+ * passed and the picture of a transition is taken. Three calls, no allocation.
47083
47838
  *
47084
47839
  * @param ctx - Domain context of the plugin.
47085
47840
  * @param frame - The frame counter now.
@@ -47087,7 +47842,7 @@ function holdOver(ctx, frame, elapsed) {
47087
47842
  * @returns True when the build may commit.
47088
47843
  */
47089
47844
  function readyToCommit(ctx, frame, elapsed) {
47090
- return ctx.deps.world.projection.built() && holdOver(ctx, frame, elapsed);
47845
+ return ctx.deps.world.projection.built() && holdOver(ctx, frame, elapsed) && pictureTaken(ctx);
47091
47846
  }
47092
47847
  /**
47093
47848
  * The `signals` callback of a running build: counts the frame and commits the build the frame
@@ -47228,8 +47983,16 @@ function dropBuild(build) {
47228
47983
  }
47229
47984
  //#endregion
47230
47985
  //#region src/plugins/scenes/leave-check.ts
47986
+ /**
47987
+ * @file scenes plugin — the check of a `leave` a game wrote, in the config (`onInit`) or in a scene (`defineScene`),
47988
+ * and of a scene's `enter`. Pure. A game written in plain JS passes anything, so both are a boundary: a field of the
47989
+ * wrong shape throws where it was written, not in the middle of a switch. A transition (spec 36) is checked by its kind:
47990
+ * every field of the kind in its range, and no field of another kind.
47991
+ */
47231
47992
  /** The largest colour, `0xffffff`. */
47232
47993
  const MAX_COLOR = 16777215;
47994
+ /** The longest a transition may take, in milliseconds. */
47995
+ const MAX_TRANSITION_MS = 5e3;
47233
47996
  /**
47234
47997
  * Tells whether a value is a finite number of at least 0: a duration.
47235
47998
  *
@@ -47295,6 +48058,89 @@ function isName(value) {
47295
48058
  function isRecord$2(value) {
47296
48059
  return typeof value === "object" && value !== null && !Array.isArray(value);
47297
48060
  }
48061
+ /**
48062
+ * Tells whether a value is a number above 0 and at most the longest a transition may take: its `ms`.
48063
+ *
48064
+ * @param value - The value.
48065
+ * @returns True for a finite number in `(0, 5000]`.
48066
+ * @example
48067
+ * ```ts
48068
+ * isTransitionMs(5001); // false
48069
+ * ```
48070
+ */
48071
+ function isTransitionMs(value) {
48072
+ return typeof value === "number" && value > 0 && value <= MAX_TRANSITION_MS;
48073
+ }
48074
+ /**
48075
+ * Tells whether a value is a finite number above 0.
48076
+ *
48077
+ * @param value - The value.
48078
+ * @returns True for a finite number above 0.
48079
+ * @example
48080
+ * ```ts
48081
+ * isPositive(0); // false
48082
+ * ```
48083
+ */
48084
+ function isPositive(value) {
48085
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
48086
+ }
48087
+ /**
48088
+ * Tells whether a value is a finite number.
48089
+ *
48090
+ * @param value - The value.
48091
+ * @returns True for a finite number.
48092
+ * @example
48093
+ * ```ts
48094
+ * isFiniteNumber(Number.POSITIVE_INFINITY); // false
48095
+ * ```
48096
+ */
48097
+ function isFiniteNumber$2(value) {
48098
+ return typeof value === "number" && Number.isFinite(value);
48099
+ }
48100
+ /**
48101
+ * Tells whether a value is a curve a transition can run on: a name `applyEase` knows, or a function of the time.
48102
+ *
48103
+ * @param value - The value.
48104
+ * @returns True for a known name or a function.
48105
+ * @example
48106
+ * ```ts
48107
+ * isEase("outBack"); // true
48108
+ * ```
48109
+ */
48110
+ function isEase(value) {
48111
+ return typeof value === "function" || EASE_NAMES.includes(value);
48112
+ }
48113
+ /**
48114
+ * Lists names the way a sentence does: `a, b and c`.
48115
+ *
48116
+ * @param names - The names, two at least or one alone.
48117
+ * @param word - The word before the last name.
48118
+ * @returns The list.
48119
+ * @example
48120
+ * ```ts
48121
+ * listOf(["kind", "ms", "to"], "and"); // "kind, ms and to"
48122
+ * ```
48123
+ */
48124
+ function listOf(names, word) {
48125
+ return names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} ${word} ${names.at(-1)}`;
48126
+ }
48127
+ /**
48128
+ * Builds the rule of a field that is one of a list of strings.
48129
+ *
48130
+ * @param names - The values it may hold.
48131
+ * @returns The rule, its hint naming them all.
48132
+ * @example
48133
+ * ```ts
48134
+ * oneOf(["cut", "keep"]).hint; // 'one of "cut" or "keep"'
48135
+ * ```
48136
+ */
48137
+ function oneOf(names) {
48138
+ const allowed = names;
48139
+ return {
48140
+ ok: (value) => allowed.includes(value),
48141
+ hint: `one of ${listOf(names.map((name) => `"${name}"`), "or")}`
48142
+ };
48143
+ }
47298
48144
  /** The colour of a veil. */
47299
48145
  const COLOR_RULE = {
47300
48146
  ok: isColor$1,
@@ -47342,6 +48188,72 @@ const LOADER_RULES = Object.freeze({
47342
48188
  hint: "the name of a registered projection such as \"loading\""
47343
48189
  }
47344
48190
  });
48191
+ /** The kinds of transition, and the fields each takes beside the common ones. */
48192
+ const TRANSITION_KINDS = Object.freeze({
48193
+ fade: [],
48194
+ slide: ["to"],
48195
+ wipe: ["angle", "soft"],
48196
+ iris: [
48197
+ "x",
48198
+ "y",
48199
+ "soft"
48200
+ ],
48201
+ dissolve: [
48202
+ "scale",
48203
+ "edge",
48204
+ "edgeColor"
48205
+ ]
48206
+ });
48207
+ /** The fields every kind of transition takes. */
48208
+ const TRANSITION_COMMON = [
48209
+ "kind",
48210
+ "ms",
48211
+ "ease",
48212
+ "reduced"
48213
+ ];
48214
+ /** A share of the screen, a number from 0 to 1. */
48215
+ const SHARE_RULE = {
48216
+ ok: isAlpha,
48217
+ hint: "a share of the screen, a number from 0 to 1"
48218
+ };
48219
+ /** The fields of a transition, by name; a kind reads the ones it takes. */
48220
+ const TRANSITION_RULES = Object.freeze({
48221
+ kind: oneOf(Object.keys(TRANSITION_KINDS)),
48222
+ ms: {
48223
+ ok: isTransitionMs,
48224
+ hint: `the milliseconds the transition takes, more than 0 and at most ${MAX_TRANSITION_MS}`
48225
+ },
48226
+ ease: {
48227
+ ok: isEase,
48228
+ hint: `a curve name (${listOf(EASE_NAMES.map((name) => `"${name}"`), "or")}) or a function of the time`
48229
+ },
48230
+ reduced: oneOf(["cut", "keep"]),
48231
+ to: oneOf([
48232
+ "left",
48233
+ "right",
48234
+ "up",
48235
+ "down"
48236
+ ]),
48237
+ angle: {
48238
+ ok: isFiniteNumber$2,
48239
+ hint: "the angle in radians, a finite number"
48240
+ },
48241
+ soft: {
48242
+ ok: isAlpha,
48243
+ hint: "the softness of the edge, a number from 0 to 1"
48244
+ },
48245
+ x: SHARE_RULE,
48246
+ y: SHARE_RULE,
48247
+ scale: {
48248
+ ok: isPositive,
48249
+ hint: "the cells of the noise across the screen, a number above 0"
48250
+ },
48251
+ edge: {
48252
+ ok: isAlpha,
48253
+ hint: "the width of the rim, a number from 0 to 1"
48254
+ },
48255
+ edgeColor: COLOR_RULE
48256
+ });
47345
48257
  /**
47346
48258
  * Builds the error of a field of the wrong shape.
47347
48259
  *
@@ -47375,9 +48287,41 @@ function checkPart(where, part, rules) {
47375
48287
  }
47376
48288
  }
47377
48289
  /**
48290
+ * Tells whether a value names one of the transition kinds: `isKnownKind("iris") // true`.
48291
+ *
48292
+ * @param kind - What the game wrote as `kind`.
48293
+ * @returns True for a kind of `TRANSITION_KINDS`.
48294
+ */
48295
+ function isKnownKind(kind) {
48296
+ return typeof kind === "string" && Object.hasOwn(TRANSITION_KINDS, kind);
48297
+ }
48298
+ /**
48299
+ * Checks a transition a game wrote: an object whose `kind` is one of the five, whose common fields and whose kind's
48300
+ * own fields have the right shape, and that holds no field of another kind.
48301
+ *
48302
+ * @param where - Where it was written, `scenes.leave.transition`.
48303
+ * @param transition - What was written.
48304
+ * @param offable - Whether `false` is a value: it is for a `leave`, which turns the transition off, and no other place.
48305
+ * @throws {Error} For the first field of the wrong shape, and for a field the kind does not take.
48306
+ */
48307
+ function checkTransition(where, transition, offable) {
48308
+ if (transition === void 0 || offable && transition === false) return;
48309
+ if (!isRecord$2(transition)) throw wrong(where, transition, offable ? "an object { kind } or false" : "an object { kind }");
48310
+ const kind = transition.kind;
48311
+ const own = isKnownKind(kind) ? TRANSITION_KINDS[kind] : void 0;
48312
+ if (own === void 0) throw wrong(`${where}.kind`, kind, TRANSITION_RULES.kind?.hint ?? "");
48313
+ const takes = [...TRANSITION_COMMON, ...own];
48314
+ for (const field of Object.keys(transition)) if (!takes.includes(field)) throw new Error(`[game] ${where}.${field} is ${String(transition[field])}.\n A "${String(kind)}" transition takes ${listOf(takes, "and")}; leave "${field}" out.`);
48315
+ for (const field of takes) {
48316
+ const value = transition[field];
48317
+ const rule = TRANSITION_RULES[field];
48318
+ if (value !== void 0 && rule !== void 0 && !rule.ok(value)) throw wrong(`${where}.${field}`, value, rule.hint);
48319
+ }
48320
+ }
48321
+ /**
47378
48322
  * Checks a `leave` a game wrote: nothing, `false`, or an object whose `cover` and `loader` are each nothing, `false`
47379
48323
  * or an object of the right fields: a colour, an alpha from 0 to 1, durations of 0 or more, and names that are not
47380
- * empty.
48324
+ * empty. Its `transition` is nothing, `false`, or an object of one of the five kinds.
47381
48325
  *
47382
48326
  * @param where - Where it was written, for the message: `scenes.leave`, or `Scene "board": leave`.
47383
48327
  * @param leave - What was written.
@@ -47386,6 +48330,8 @@ function checkPart(where, part, rules) {
47386
48330
  * ```ts
47387
48331
  * checkLeave("scenes.leave", { cover: { alpha: 2 } });
47388
48332
  * // throws '[game] scenes.leave.cover.alpha is 2.\n Give the alpha the veil fades in to, a number from 0 to 1.'
48333
+ * checkLeave("scenes.leave", { transition: { kind: "fade", ms: 0 } });
48334
+ * // throws '[game] scenes.leave.transition.ms is 0.\n Give the milliseconds the transition takes, more than 0 and at most 5000.'
47389
48335
  * ```
47390
48336
  */
47391
48337
  function checkLeave(where, leave) {
@@ -47393,10 +48339,12 @@ function checkLeave(where, leave) {
47393
48339
  if (!isRecord$2(leave)) throw wrong(where, leave, "{ cover, loader } or false");
47394
48340
  checkPart(`${where}.cover`, leave.cover, COVER_RULES);
47395
48341
  checkPart(`${where}.loader`, leave.loader, LOADER_RULES);
48342
+ checkTransition(`${where}.transition`, leave.transition, true);
47396
48343
  }
47397
48344
  /**
47398
48345
  * Checks a scene's `enter`: nothing, or an object whose `cover` is nothing or an object of a colour and an alpha from 0
47399
- * to 1, by the rules of `leave.cover`.
48346
+ * to 1, by the rules of `leave.cover`, and whose `transition` is nothing or an object of one of the five kinds (`false`
48347
+ * is refused: `enter` never turns a transition off).
47400
48348
  *
47401
48349
  * @param where - Where it was written, for the message: `Scene "night": enter`.
47402
48350
  * @param enter - What was written.
@@ -47411,6 +48359,7 @@ function checkEnter(where, enter) {
47411
48359
  if (enter === void 0) return;
47412
48360
  if (!isRecord$2(enter)) throw wrong(where, enter, "{ cover }");
47413
48361
  checkPart(`${where}.cover`, enter.cover, ENTER_COVER_RULES);
48362
+ checkTransition(`${where}.transition`, enter.transition, false);
47414
48363
  }
47415
48364
  //#endregion
47416
48365
  //#region src/plugins/scenes/loader.ts
@@ -47729,6 +48678,111 @@ function forgetLoader(state) {
47729
48678
  delete state.held;
47730
48679
  }
47731
48680
  //#endregion
48681
+ //#region src/plugins/scenes/transition.ts
48682
+ /** The milliseconds a transition takes when the game writes none. */
48683
+ const DEFAULT_MS = 400;
48684
+ /** The curve of a transition when the game writes none. */
48685
+ const DEFAULT_EASE$1 = "inOut";
48686
+ /** The softness of the edge of a wipe, a share of the screen. */
48687
+ const WIPE_SOFT = .04;
48688
+ /** The point an iris closes into, a share of the screen on each axis. */
48689
+ const IRIS_CENTRE = .5;
48690
+ /** The softness of the edge of an iris, a share of the screen. */
48691
+ const IRIS_SOFT = .05;
48692
+ /** The cells of the noise of a dissolve across the screen. */
48693
+ const DISSOLVE_SCALE = 8;
48694
+ /** The width of the rim of a dissolve. */
48695
+ const DISSOLVE_EDGE = .08;
48696
+ /** The colour of the rim of a dissolve, white. */
48697
+ const DISSOLVE_EDGE_COLOR = 16777215;
48698
+ /**
48699
+ * Fills every default into a transition a game wrote, in a new frozen object the game's is never written into.
48700
+ *
48701
+ * @param transition - What the game wrote.
48702
+ * @returns The transition with every field of its kind set.
48703
+ * @example
48704
+ * ```ts
48705
+ * resolveTransition({ kind: "iris", ms: 500 });
48706
+ * // { kind: "iris", ms: 500, ease: "inOut", reduced: "cut", x: 0.5, y: 0.5, soft: 0.05 }
48707
+ * ```
48708
+ */
48709
+ function resolveTransition(transition) {
48710
+ const common = {
48711
+ ms: transition.ms ?? DEFAULT_MS,
48712
+ ease: transition.ease ?? DEFAULT_EASE$1,
48713
+ reduced: transition.reduced ?? "cut"
48714
+ };
48715
+ switch (transition.kind) {
48716
+ case "fade": return Object.freeze({
48717
+ kind: "fade",
48718
+ ...common
48719
+ });
48720
+ case "slide": return Object.freeze({
48721
+ kind: "slide",
48722
+ ...common,
48723
+ to: transition.to ?? "left"
48724
+ });
48725
+ case "wipe": return Object.freeze({
48726
+ kind: "wipe",
48727
+ ...common,
48728
+ angle: transition.angle ?? 0,
48729
+ soft: transition.soft ?? WIPE_SOFT
48730
+ });
48731
+ case "iris": return Object.freeze({
48732
+ kind: "iris",
48733
+ ...common,
48734
+ x: transition.x ?? IRIS_CENTRE,
48735
+ y: transition.y ?? IRIS_CENTRE,
48736
+ soft: transition.soft ?? IRIS_SOFT
48737
+ });
48738
+ case "dissolve": return Object.freeze({
48739
+ kind: "dissolve",
48740
+ ...common,
48741
+ scale: transition.scale ?? DISSOLVE_SCALE,
48742
+ edge: transition.edge ?? DISSOLVE_EDGE,
48743
+ edgeColor: transition.edgeColor ?? DISSOLVE_EDGE_COLOR
48744
+ });
48745
+ }
48746
+ }
48747
+ /**
48748
+ * The transition one level of `leave` writes over the level below it: nothing keeps the level below, `leave: false` and
48749
+ * `transition: false` turn it off, an object replaces it whole.
48750
+ *
48751
+ * @param below - The transition of the levels below: one, `false` for off, `undefined` for none written.
48752
+ * @param leave - What the level writes.
48753
+ * @returns The transition of the levels up to this one.
48754
+ * @example
48755
+ * ```ts
48756
+ * transitionOver({ kind: "fade" }, { transition: false }); // false
48757
+ * ```
48758
+ */
48759
+ function transitionOver(below, leave) {
48760
+ if (leave === void 0) return below;
48761
+ if (leave === false) return false;
48762
+ return leave.transition === void 0 ? below : leave.transition;
48763
+ }
48764
+ /**
48765
+ * Resolves the transition of a switch: the `enter.transition` of the scene being entered, else the `leave.transition` of
48766
+ * the scene being left, else the one of `config.leave`, else none. `false` the scene being left (or the config, until the
48767
+ * scene writes one) resolves to, from `leave: false` or `transition: false`, gives none, and `enter` never turns a
48768
+ * transition on over it. A level replaces the one below whole: no field is merged.
48769
+ *
48770
+ * @param config - `config.leave`.
48771
+ * @param scene - The `leave` of the scene being left, for this switch.
48772
+ * @param enter - The `enter` of the scene being entered.
48773
+ * @returns The transition with every default filled in, a new frozen object; `undefined` for none.
48774
+ * @example
48775
+ * ```ts
48776
+ * transitionOf({ transition: { kind: "fade" } }, undefined, { transition: { kind: "iris", ms: 500 } })?.kind; // "iris"
48777
+ * ```
48778
+ */
48779
+ function transitionOf(config, scene, enter) {
48780
+ const left = transitionOver(transitionOver(void 0, config), scene);
48781
+ if (left === false) return void 0;
48782
+ const chosen = enter?.transition ?? left;
48783
+ return chosen === void 0 ? void 0 : resolveTransition(chosen);
48784
+ }
48785
+ //#endregion
47732
48786
  //#region src/plugins/scenes/leave.ts
47733
48787
  /**
47734
48788
  * What a game gets when it writes nothing: black at 45 %, 50 ms in and 150 ms out, the engine's ring once the switch took
@@ -47833,17 +48887,20 @@ function loaderOver(below, over) {
47833
48887
  }
47834
48888
  /**
47835
48889
  * Resolves what a switch shows over the scene being left: the scene's `leave` over the config's over the engine's,
47836
- * field by field. `false` at a level turns both parts off there.
48890
+ * field by field. `false` at a level turns both parts off there. The transition (spec 36) is resolved on its own:
48891
+ * the scene being entered over the scene being left over the config (`transition.ts`), and it makes a look by itself
48892
+ * when the veil and the loader are both off.
47837
48893
  *
47838
48894
  * @param config - `config.leave`.
47839
48895
  * @param scene - The `leave` of the scene being left.
47840
- * @returns Both parts, each resolved or `false`; `undefined` when both are off.
48896
+ * @param enter - The `enter` of the scene being entered.
48897
+ * @returns Both parts, each resolved or `false`, and the transition when one is resolved; `undefined` when all are off.
47841
48898
  * @example
47842
48899
  * ```ts
47843
48900
  * leaveOf({ loader: false }, { cover: { alpha: 0.6 } }); // { cover: { color: 0, alpha: 0.6, inMs: 50, outMs: 150 }, loader: false }
47844
48901
  * ```
47845
48902
  */
47846
- function leaveOf(config, scene) {
48903
+ function leaveOf(config, scene, enter) {
47847
48904
  let cover = FALLBACK_LEAVE.cover;
47848
48905
  let loader = FALLBACK_LEAVE.loader;
47849
48906
  for (const level of [config, scene]) if (level === false) {
@@ -47853,6 +48910,12 @@ function leaveOf(config, scene) {
47853
48910
  cover = coverOver(cover, level.cover);
47854
48911
  loader = loaderOver(loader, level.loader);
47855
48912
  }
48913
+ const transition = transitionOf(config, scene, enter);
48914
+ if (transition !== void 0) return {
48915
+ cover,
48916
+ loader,
48917
+ transition
48918
+ };
47856
48919
  if (cover === false && loader === false) return void 0;
47857
48920
  return {
47858
48921
  cover,
@@ -47988,7 +49051,7 @@ function stampHold(ctx, leaving, loader) {
47988
49051
  function startLeave(ctx, scene, run) {
47989
49052
  const from = leftScene(ctx, run);
47990
49053
  if (from === void 0) return void 0;
47991
- const leave = leaveOf(ctx.config.leave, sceneLeaveOf(ctx, from, scene.id));
49054
+ const leave = leaveOf(ctx.config.leave, sceneLeaveOf(ctx, from, scene.id), scene.enter);
47992
49055
  if (leave === void 0) {
47993
49056
  ctx.state.declined = {
47994
49057
  signal: run.signal,
@@ -48014,6 +49077,13 @@ function startLeave(ctx, scene, run) {
48014
49077
  }, leaving);
48015
49078
  stampHold(ctx, leaving, leave.loader);
48016
49079
  }
49080
+ if (leave.transition !== void 0) {
49081
+ look.transition = leave.transition;
49082
+ leaving.transition = {
49083
+ captureFrames: 0,
49084
+ ready: false
49085
+ };
49086
+ }
48017
49087
  ctx.deps.renderer.sync.leave.show(look);
48018
49088
  run.signal.addEventListener("abort", () => endLeave(ctx, leaving, "drop"), {
48019
49089
  once: true,
@@ -55269,6 +56339,131 @@ function retireAllFilters(ectx) {
55269
56339
  warm.started = false;
55270
56340
  warm.core = [];
55271
56341
  }
56342
+ //#endregion
56343
+ //#region src/plugins/effects/set/transition-mark.ts
56344
+ /**
56345
+ * Creates the table of the marks. A function: the module-scope rule sees no collection literal.
56346
+ *
56347
+ * @returns An empty weak map.
56348
+ */
56349
+ function emptyMarks() {
56350
+ return /* @__PURE__ */ new WeakMap();
56351
+ }
56352
+ /** The mark of each marked definition. Weak: a definition nobody holds takes its mark with it. */
56353
+ const MARKS = /*#__PURE__*/ emptyMarks();
56354
+ /**
56355
+ * Marks a filter component as the body of a transition kind and gives the component back, unchanged. The mark is kept
56356
+ * for the component's definition, in a table the start of `effects` reads for every listed filter.
56357
+ *
56358
+ * @param component - The component `defineFilter` made.
56359
+ * @param kind - The transition kind it draws.
56360
+ * @param member - Its export name, for the renderer's warning.
56361
+ * @returns The same component.
56362
+ */
56363
+ function markTransition(component, kind, member) {
56364
+ MARKS.set(component.filter, {
56365
+ kind,
56366
+ member
56367
+ });
56368
+ return component;
56369
+ }
56370
+ /**
56371
+ * The mark of a definition, if its member is one of the transition bodies.
56372
+ *
56373
+ * @param definition - A filter definition.
56374
+ * @returns Its kind and member name; `undefined` for any other filter.
56375
+ */
56376
+ function transitionMarkOf(definition) {
56377
+ return MARKS.get(definition);
56378
+ }
56379
+ //#endregion
56380
+ //#region src/plugins/effects/filters/transition.ts
56381
+ /** A number V8 cannot keep as a small integer: the first store of a field in double form. */
56382
+ const DOUBLE_SEED = .5;
56383
+ /**
56384
+ * Moves the number fields of a uniform group to V8's double form, so a write of a changing number lands in the field in
56385
+ * place. The renderer writes the uniforms of a body by name in every frame of a transition (`uniforms.progress = e`),
56386
+ * and Pixi's upload reads them by name. A number field in tagged form (what `tagNumbers` gives the values of an
56387
+ * instance, for its keyed reads) holds a pointer to a box, and each write of a new double makes a new box: 16 B a
56388
+ * frame and uniform. The values are copied to a new object whose fields are added in the reverse order, a shape no
56389
+ * instance of the filter has, so what `tagNumbers` did to the shape of the instances stays out of it: the shape, not
56390
+ * the object, holds the form. The vectors and every other field are the same ones as before. Once, at hand-over.
56391
+ *
56392
+ * @param group - The uniform group of the body's warm filter. Its `uniforms` object is replaced.
56393
+ */
56394
+ function holdNumbersAsDoubles(group) {
56395
+ const held = group.uniforms;
56396
+ const names = Object.keys(held).toReversed();
56397
+ const fresh = {};
56398
+ for (const name of names) fresh[name] = typeof held[name] === "number" ? DOUBLE_SEED : held[name];
56399
+ for (const name of names) if (typeof held[name] === "number") fresh[name] = held[name];
56400
+ group.uniforms = fresh;
56401
+ }
56402
+ /**
56403
+ * Builds the body of a transition from a definition whose quad program compiled: a warm filter of it, its uniform group
56404
+ * in double form, and the quad over that group. The renderer writes the group's numbers by name in every frame.
56405
+ *
56406
+ * @param pixi - The module the renderer loaded.
56407
+ * @param definition - The definition of a member that carries a transition mark.
56408
+ * @param program - Its quad program.
56409
+ * @returns The quad and its teardown.
56410
+ */
56411
+ function createTransitionBody(pixi, definition, program) {
56412
+ const warm = createWarmFilter(pixi, definition, program);
56413
+ const fu = warm.quad?.fu;
56414
+ if (fu !== void 0) holdNumbersAsDoubles(fu);
56415
+ return {
56416
+ quad: {
56417
+ program,
56418
+ fu
56419
+ },
56420
+ destroy: warm.destroy
56421
+ };
56422
+ }
56423
+ /**
56424
+ * Builds a warm filter of each marked body whose quad program compiled and hands it to the renderer, and keeps the
56425
+ * take-back and the filter's teardown in `state.removers`. A body whose quad check failed, or that no quad was checked
56426
+ * for (WebGL, no device), hands nothing: the renderer plays its kind as a fade. So does a renderer that has no Pixi any
56427
+ * more (its context was lost since). The checks of a run that stopped never settle, so a stopped run hands nothing.
56428
+ *
56429
+ * @param ectx - Domain context of the effects plugin.
56430
+ * @param bodies - The listed definitions that carry a transition mark.
56431
+ */
56432
+ function handBodies(ectx, bodies) {
56433
+ const pixi = ectx.deps.renderer.host.pixi();
56434
+ if (pixi === void 0) return;
56435
+ for (const { definition, mark } of bodies) {
56436
+ const program = quadProgramOf(ectx, pixi, definition);
56437
+ if (program === void 0) continue;
56438
+ const body = createTransitionBody(pixi, definition, program);
56439
+ const takeBack = ectx.deps.renderer.sync.leave.body(mark.kind, body.quad, mark.member);
56440
+ ectx.state.removers.push(() => {
56441
+ takeBack();
56442
+ body.destroy();
56443
+ });
56444
+ }
56445
+ }
56446
+ /**
56447
+ * Arranges the hand-over of the transition bodies at the start of the plugin: when a registered kind carries a
56448
+ * transition mark, the bodies are handed once every shader check of this run answered. Nothing is arranged for a game
56449
+ * that lists no marked member.
56450
+ *
56451
+ * @param ectx - Domain context of the effects plugin.
56452
+ */
56453
+ function openTransitionBodies(ectx) {
56454
+ const { state } = ectx;
56455
+ const bodies = [];
56456
+ for (const kind of state.kindList) {
56457
+ if (kind.source !== "wgsl") continue;
56458
+ const mark = transitionMarkOf(kind.definition);
56459
+ if (mark !== void 0) bodies.push({
56460
+ definition: kind.definition,
56461
+ mark
56462
+ });
56463
+ }
56464
+ if (bodies.length === 0) return;
56465
+ state.checks.settled.then(() => handBodies(ectx, bodies));
56466
+ }
55272
56467
  /**
55273
56468
  * A particle effect on an entity. A `burst` effect emits when the component appears or its
55274
56469
  * `effect` changes; a `rate` effect emits while `active` is true and the entity lives. An effect in
@@ -56554,7 +57749,8 @@ function warnUnlisted(ectx, id, entity) {
56554
57749
  * Starts the plugin in `onStart`. The teardown closure goes first into `state.removers`, because
56555
57750
  * a teardown context carries no `ctx`: it captures the world and the renderer here. Then the
56556
57751
  * phone, the kinds, the `load` gate that holds every node entry until the shader checks answered,
56557
- * the emitters and the world side. Nothing is compiled here: the host is not ready yet.
57752
+ * the emitters, the world side and, for a listed member that is a transition body, the hand-over to the
57753
+ * renderer once its checks answered. Nothing is compiled here: the host is not ready yet.
56558
57754
  *
56559
57755
  * @param ctx - Kernel context of the effects plugin.
56560
57756
  */
@@ -56572,6 +57768,7 @@ function startEffects(ctx) {
56572
57768
  state.removers.push(ectx.deps.flow.onEnter("load", (node, run) => gateChecks(ectx, node, run)));
56573
57769
  registerEmitters(ectx);
56574
57770
  openWorld(ectx, state.kindList);
57771
+ openTransitionBodies(ectx);
56575
57772
  }
56576
57773
  /**
56577
57774
  * Frees what `onStart` opened, from state alone: the teardown closure destroys every container,
@@ -67354,7 +68551,8 @@ function formatIfLoaded(ctx, message, locale) {
67354
68551
  }
67355
68552
  /**
67356
68553
  * Measures a text in every loaded locale, in the key its markup names for this frame, and reports
67357
- * the widest one that does not fit. A lazy locale the player has not picked yet cannot be
68554
+ * the widest one that does not fit. A wrapping style is measured at the element's width, so its
68555
+ * lines are compared by height. A lazy locale the player has not picked yet cannot be
67358
68556
  * measured, so it is skipped.
67359
68557
  *
67360
68558
  * @param ctx - Domain context of the ui plugin.
@@ -67370,7 +68568,7 @@ function textOverflow(ctx, element) {
67370
68568
  const parts = formatIfLoaded(ctx, content, locale);
67371
68569
  if (parts === void 0) continue;
67372
68570
  const joined = parts.map((part) => part.kind === "text" ? part.text : "").join("");
67373
- const size = ctx.deps.text.measure(joined, style);
68571
+ const size = ctx.deps.text.measure(joined, style, element.rect.w);
67374
68572
  if (size.width <= element.rect.w && size.height <= element.rect.h) continue;
67375
68573
  return {
67376
68574
  rule: "text-overflow",
@@ -78248,14 +79446,15 @@ function namesOf(id, layers, projections) {
78248
79446
  * `bundles` names bundles that depend on the committed state: the scene is mounted once those
78249
79447
  * are in too. `leave` is what a live switch shows over the scene when it is left, merged over the
78250
79448
  * config's: `false` shows nothing; a function of the switch is called once per switch with `{ from, to }` and kept as it
78251
- * is. `enter` sets the colour and the alpha of the veil of every live switch to the scene.
79449
+ * is. `enter` sets the colour and the alpha of the veil of every live switch to the scene. A `transition` in `leave` or
79450
+ * `enter` plays a picture of the last frame of the scene being left over the new scene.
78252
79451
  *
78253
79452
  * @param id - Id of the scene. A node names it with `defineNode({ scene: id })`.
78254
79453
  * @param scene - The bundle, the optional bundles of state, the layers, the projections, the
78255
79454
  * optional music key, the optional `leave` and the optional `enter`.
78256
79455
  * @returns The scene as frozen data, ready for the `scenes` key of a feature.
78257
79456
  * @throws {Error} For an integer-like layer name, for a `layer` or `lift` that is not declared, for two HUD layers,
78258
- * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` value or an `enter` of the
79457
+ * an `above` other than `"overlays"`, a `ui` declared after the HUD layer, and a `leave` value (its `transition` included) or an `enter` of the
78259
79458
  * wrong shape (the result of a `leave` function is checked at the switch and logged).
78260
79459
  * @example
78261
79460
  * ```ts
@@ -78307,6 +79506,20 @@ function namesOf(id, layers, projections) {
78307
79506
  * });
78308
79507
  * typeof memory.leave; // "function", called with { from: "memory", to: "ward" } at the switch,
78309
79508
  * // and with { from: "memory", to: "memory" } when the memory stands live
79509
+ *
79510
+ * // The board leaves with a wipe from right to left; every way into the night is an iris of 500 ms.
79511
+ * defineScene("board", {
79512
+ * bundle: "board",
79513
+ * layers: { cells: {} },
79514
+ * projections: [],
79515
+ * leave: { transition: { kind: "wipe", angle: Math.PI } }
79516
+ * }).leave; // { transition: { kind: "wipe", angle: Math.PI } }, the defaults are filled in at the switch
79517
+ * defineScene("night", {
79518
+ * bundle: "night",
79519
+ * layers: { sky: {} },
79520
+ * projections: [],
79521
+ * enter: { transition: { kind: "iris", ms: 500 } }
79522
+ * }).enter; // { transition: { kind: "iris", ms: 500 } }
78310
79523
  * ```
78311
79524
  */
78312
79525
  function defineScene(id, scene) {
@@ -79021,6 +80234,8 @@ const Bloom = /*#__PURE__*/ defineFilter("effects.bloom", {
79021
80234
  * `filters`, as a game's own filter. One render pass, one sample of the input; on WebGPU a tween draws on the view's
79022
80235
  * own quad, no pass, from its third frame.
79023
80236
  *
80237
+ * Listed, it is also the body of the `dissolve` scene transition (`transition: { kind: "dissolve" }`).
80238
+ *
79024
80239
  * @example
79025
80240
  * ```ts
79026
80241
  * // A cleared piece burns away with a white rim.
@@ -79028,7 +80243,7 @@ const Bloom = /*#__PURE__*/ defineFilter("effects.bloom", {
79028
80243
  * view.tween(Dissolve, { progress: 1 }, { ms: 600 });
79029
80244
  * ```
79030
80245
  */
79031
- const Dissolve = /*#__PURE__*/ defineFilter("effects.dissolve", {
80246
+ const Dissolve = /*#__PURE__*/ markTransition(/*#__PURE__*/ defineFilter("effects.dissolve", {
79032
80247
  wgsl: /* @__PURE__ */ withSetWgsl(`@fragment
79033
80248
  fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79034
80249
  let n = inputPlace(uv);
@@ -79070,7 +80285,7 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79070
80285
  edge: .08,
79071
80286
  edgeColor: { color: 16777215 }
79072
80287
  }
79073
- });
80288
+ }), "dissolve", "Dissolve");
79074
80289
  /**
79075
80290
  * A view washed with `color` by `amount`: 0 draws the view as it is, 1 draws its shape in `color`, its alpha kept.
79076
80291
  * For a hit, a pick, a merge: tween `amount` up and down. List it in a feature's `filters`, as a game's own filter.
@@ -79353,6 +80568,8 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79353
80568
  * in or out of a card, a panel, a picture. List it in a feature's `filters`, as a game's own filter. One render pass,
79354
80569
  * one sample; on WebGPU a tween draws on the view's own quad, no pass, from its third frame.
79355
80570
  *
80571
+ * Listed, it is also the body of the `wipe` scene transition (`transition: { kind: "wipe" }`).
80572
+ *
79356
80573
  * @example
79357
80574
  * ```ts
79358
80575
  * // A level card wipes in from the top: it starts hidden, and a motion tweens progress to 1.
@@ -79360,7 +80577,7 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79360
80577
  * view.tween(RevealLine, { progress: 1 }, { ms: 400 });
79361
80578
  * ```
79362
80579
  */
79363
- const RevealLine = /*#__PURE__*/ defineFilter("effects.revealLine", {
80580
+ const RevealLine = /*#__PURE__*/ markTransition(/*#__PURE__*/ defineFilter("effects.revealLine", {
79364
80581
  wgsl: /* @__PURE__ */ withSetWgsl(`@fragment
79365
80582
  fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79366
80583
  let n = inputPlace(uv);
@@ -79391,7 +80608,7 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79391
80608
  angle: 0,
79392
80609
  soft: .05
79393
80610
  }
79394
- });
80611
+ }), "wipe", "RevealLine");
79395
80612
  /**
79396
80613
  * A view shown inside a disc around the point `x`, `y`: `radius: 0` hides all of it, and from about 0.75 a disc at the
79397
80614
  * centre shows every corner (1.5 shows all of it from any point). The edge fades over `soft` and waves by `wobble`
@@ -79400,6 +80617,8 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79400
80617
  * feature's `filters`, as a game's own filter. One render pass, one sample; on WebGPU a tween draws on the view's own
79401
80618
  * quad, no pass, from its third frame.
79402
80619
  *
80620
+ * Listed, it is also the body of the `iris` scene transition (`transition: { kind: "iris" }`).
80621
+ *
79403
80622
  * @example
79404
80623
  * ```ts
79405
80624
  * // A lens opens over the map: the window starts closed and grows to show the whole view.
@@ -79407,7 +80626,7 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79407
80626
  * view.tween(RevealRound, { radius: 1.2 }, { ms: 640 });
79408
80627
  * ```
79409
80628
  */
79410
- const RevealRound = /*#__PURE__*/ defineFilter("effects.revealRound", {
80629
+ const RevealRound = /*#__PURE__*/ markTransition(/*#__PURE__*/ defineFilter("effects.revealRound", {
79411
80630
  wgsl: /* @__PURE__ */ withSetWgsl(`@fragment
79412
80631
  fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79413
80632
  let n = inputPlace(uv);
@@ -79436,7 +80655,7 @@ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
79436
80655
  soft: .05,
79437
80656
  wobble: 0
79438
80657
  }
79439
- });
80658
+ }), "iris", "RevealRound");
79440
80659
  /**
79441
80660
  * A drop shadow of `color` at `alpha` (0..1) under the shape of a view and its subtree, moved by `x`, `y` CSS px and
79442
80661
  * blurred `soft` CSS px wide; the view is drawn over it. The view is padded by 8 px, the shadow's reach: `soft` is at
@@ -79727,7 +80946,7 @@ void main() {
79727
80946
  * | assets | baseUrl | undefined |
79728
80947
  * | assets | io | undefined, the browser fetch and the renderer textures |
79729
80948
  * | scenes | buildMs | "auto", two thirds of a frame ((1000 / time.rate().fps) * 2 / 3, 11.1 ms at 60 Hz), read at each build start; a number fixes it |
79730
- * | scenes | leave | { cover: { color: 0x000000, alpha: 0.45, inMs: 50, outMs: 150 }, loader: { afterMs: 400 } }, what a live switch shows over the scene being left: a veil from its start and a loader (the engine's ring, a `texture` or a `projection`) once it took `afterMs`, with `loader.holdMs` (default 0) a floor on the swap; a scene's `leave` is merged over it field by field, a field left out keeps this default, `false` turns a part or the whole off |
80949
+ * | scenes | leave | { cover: { color: 0x000000, alpha: 0.45, inMs: 50, outMs: 150 }, loader: { afterMs: 400 } }, what a live switch shows over the scene being left: a veil from its start and a loader (the engine's ring, a `texture` or a `projection`) once it took `afterMs`, with `loader.holdMs` (default 0) a floor on the swap; a scene's `leave` is merged over it field by field, a field left out keeps this default, `false` turns a part or the whole off; `leave.transition` (none by default) plays a picture of the last frame of the scene being left over the next scene, see `Scenes.SceneTransition` |
79731
80950
  * | anim | maxTracks | 2000 |
79732
80951
  * | anim | reducedMotion | false |
79733
80952
  * | i18n | locale | "en" |