@moku-labs/game 0.15.46 → 0.15.48
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.
- package/dist/app/page.d.mts +1 -1
- package/dist/app/page.mjs +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-DPjJykYd.d.mts → commands-4ZPA_54H.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-CweettNp.d.mts → define-Bi1cUDqV.d.mts} +2 -2
- package/dist/{headless-BlNxy_kO.d.mts → headless-DEvO-OYZ.d.mts} +1 -1
- package/dist/{index-BQh16IG6.d.mts → index-BIDag1mb.d.mts} +3 -3
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/inspect.d.mts +6 -6
- package/dist/inspect.mjs +1 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-BHmaehdl.d.mts → runtime-BBACzetr.d.mts} +2 -2
- package/dist/{sources-MfRpM8sV.mjs → sources-Cjrzga6S.mjs} +1 -1
- package/dist/{src-Bb6Sb530.mjs → src-Ddq1jS-4.mjs} +2373 -286
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-wYdMIjLG.d.mts → types-AIu9QkEJ.d.mts} +2 -2
- package/dist/{types-C4iNGaXh.d.mts → types-BA-vO4zD.d.mts} +32 -4
- package/dist/{types-BMQut7RK.d.mts → types-D0uITVZD.d.mts} +160 -32
- package/dist/{types-BjNmoeuL.d.mts → types-SbQM-OCV.d.mts} +117 -7
- package/dist/{types-CMZvOBAa.d.mts → types-vhOiA6D7.d.mts} +4 -4
- package/dist/{visual-Cl_aeC8t.d.mts → visual-BDfG9Rgh.d.mts} +6 -6
- package/dist/{visual-ClVRMUAi.mjs → visual-LFiLc3GH.mjs} +5 -2
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +1 -1
- package/llms.txt +2 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { r as systemSource, t as memory } from "./memory-CWlqhS7l.mjs";
|
|
3
3
|
import { a as finishDrafts, i as enableDraftPatches, n as deepFreeze$1, o as openDrafts, r as dropDrafts } from "./drafts-BawpSaVp.mjs";
|
|
4
4
|
import { _ as compact, c as collectFlows, d as findNode, f as framePath, g as slotNames, h as restlessCapOf, i as servePaused, l as describeGraph, m as isRestCheckpoint, n as captureFrame, o as epochOf, p as graphHash, r as serveCaptures, s as pageNow$1, t as cancelCaptures, v as pushEntry } from "./capture-BtS6_oWr.mjs";
|
|
5
|
-
import { $ as
|
|
5
|
+
import { $ as Tree, A as isLeaving, B as Overlay, D as readStyle, F as rootPoseInto, G as Transform, H as Parent, I as rootPoseOf, K as arcDefaults, L as Display, M as parentOf$1, N as poseUnder, O as textFor, P as rootPointOf, Q as Order, R as HudPart, S as Text, U as Shape, V as OverlayLevel, W as Sprite, X as Layer, Y as Exiting, Z as Now, a as samePose, at as tag, c as Box, d as Escapable, et as component, f as LocalWrite, g as UiCounters, h as UI_OWNER, i as fitScaleOf, it as systemsFor, j as localPoseOf, k as applyPose, l as Covered, m as ScrollState, n as CONTENT$1, nt as resource, o as visualOf$1, p as Scroll, q as componentsFor, r as drawnRect, rt as system, s as visualRectOf, u as DebugTrigger, v as uiFor, w as builtInStyles, x as Countdown, z as NineSlice } from "./visual-LFiLc3GH.mjs";
|
|
6
6
|
import { a as isDev } from "./dev-BNndV-hU.mjs";
|
|
7
7
|
import { n as isComponentDefinition } from "./component-DGg5DqKK.mjs";
|
|
8
8
|
import { n as flatten } from "./flatten-nUX9PpGo.mjs";
|
|
@@ -838,7 +838,7 @@ const BUSY = 4;
|
|
|
838
838
|
/** The thermal rank from which the rule never steps up: `"moderate"` and every hotter status. */
|
|
839
839
|
const HEAT_LIMIT_RANK = 2;
|
|
840
840
|
/** Milliseconds in a second: turns a rate into the period of one frame. */
|
|
841
|
-
const SECOND_MS$
|
|
841
|
+
const SECOND_MS$3 = 1e3;
|
|
842
842
|
/** Every choice `setRate` takes: `"auto"` and the three fixed rates. */
|
|
843
843
|
const RATE_CHOICES = Object.freeze([
|
|
844
844
|
"auto",
|
|
@@ -1432,8 +1432,8 @@ function judgeFrame$1(ctx, g, intervalMs, at) {
|
|
|
1432
1432
|
const { fps } = ctx.state.rate;
|
|
1433
1433
|
const higher = stepAbove(g.ladder, fps);
|
|
1434
1434
|
const missed = intervalMs > missLineMs(fps, ctx.state.rate.display.hz ?? fps);
|
|
1435
|
-
const heavy = higher !== void 0 && g.lastWorkMs > .5 * SECOND_MS$
|
|
1436
|
-
const busy = missed && g.lastWorkMs > SECOND_MS$
|
|
1435
|
+
const heavy = higher !== void 0 && g.lastWorkMs > .5 * SECOND_MS$3 / higher;
|
|
1436
|
+
const busy = missed && g.lastWorkMs > SECOND_MS$3 / fps;
|
|
1437
1437
|
const slot = g.written % 512;
|
|
1438
1438
|
evict$2(g, at);
|
|
1439
1439
|
g.sampleAt[slot] = at;
|
|
@@ -9763,8 +9763,9 @@ function registerFeatures(ctx, ecs, projection) {
|
|
|
9763
9763
|
* callback records the frame history before it clears the change sets; in an agent build the
|
|
9764
9764
|
* timing table starts with the page clock of `time` and the `input` callback zeroes it each
|
|
9765
9765
|
* frame. The resource `Now` gets `clock.now()` once here and first thing in every `input`
|
|
9766
|
-
* callback, so every system of a frame reads one moment; a running scene build
|
|
9767
|
-
* budget from that moment too.
|
|
9766
|
+
* callback, so every system of a frame reads one moment; a running scene build and a warm window in
|
|
9767
|
+
* work count their frame budget from that moment too. After the reconcile the `input` callback
|
|
9768
|
+
* takes one step of the warm windows. `onStart` has no access to the
|
|
9768
9769
|
* plugin's own API, so it builds its own module objects — they are views on `ctx.state`, which is
|
|
9769
9770
|
* the one place the modules keep their data.
|
|
9770
9771
|
*
|
|
@@ -9788,6 +9789,7 @@ function connectWorld(ctx) {
|
|
|
9788
9789
|
projection.startFrame(now);
|
|
9789
9790
|
worldCtx.state.ecs.timing?.ms.fill(0);
|
|
9790
9791
|
projection.reconcileIfDirty();
|
|
9792
|
+
projection.stepWarm();
|
|
9791
9793
|
ecs.runPhase("input", frame);
|
|
9792
9794
|
}), time.onFrame("animate", (frame) => {
|
|
9793
9795
|
projection.sweep();
|
|
@@ -9801,7 +9803,7 @@ function connectWorld(ctx) {
|
|
|
9801
9803
|
/**
|
|
9802
9804
|
* Empties the world in `onStop`: the frame callbacks and the hint listener are removed, then
|
|
9803
9805
|
* every track, view, queued view, entity and resource is dropped, a running scene build and the
|
|
9804
|
-
* `onBuild` checks with them, and the scenes and the frame history are reset.
|
|
9806
|
+
* `onBuild` checks with them, every warm record, and the scenes and the frame history are reset.
|
|
9805
9807
|
* No `onRemoved` fires, because `renderer` stopped earlier and destroyed its own objects.
|
|
9806
9808
|
*
|
|
9807
9809
|
* @param state - The plugin state, the only thing a teardown context carries.
|
|
@@ -9829,6 +9831,11 @@ function clearWorld(state) {
|
|
|
9829
9831
|
state.projection.owedLoops = 0;
|
|
9830
9832
|
delete state.projection.building;
|
|
9831
9833
|
state.projection.buildChecks.length = 0;
|
|
9834
|
+
state.projection.warm.clear();
|
|
9835
|
+
state.projection.warmList.length = 0;
|
|
9836
|
+
state.projection.warmHeld.clear();
|
|
9837
|
+
delete state.projection.warmActive;
|
|
9838
|
+
state.projection.warmStale = false;
|
|
9832
9839
|
state.ecs.generations.length = 0;
|
|
9833
9840
|
state.ecs.free.length = 0;
|
|
9834
9841
|
state.ecs.owners.clear();
|
|
@@ -10028,7 +10035,8 @@ function startTrack$2(pctx, entity, component, to, options) {
|
|
|
10028
10035
|
entity,
|
|
10029
10036
|
component: component.componentName,
|
|
10030
10037
|
handle,
|
|
10031
|
-
additive: options.additive === true
|
|
10038
|
+
additive: options.additive === true,
|
|
10039
|
+
forever: options.repeat === "forever"
|
|
10032
10040
|
});
|
|
10033
10041
|
return handle;
|
|
10034
10042
|
}
|
|
@@ -10178,6 +10186,8 @@ function diffComponents(rest, next, byIdentity) {
|
|
|
10178
10186
|
}
|
|
10179
10187
|
//#endregion
|
|
10180
10188
|
//#region src/plugins/world/projection/views.ts
|
|
10189
|
+
/** The components of a view built aside or held warm at its spawn: none, so it is flagged before the first `onAdded`. */
|
|
10190
|
+
const NO_COMPONENTS = [];
|
|
10181
10191
|
/**
|
|
10182
10192
|
* Normalises a caught value into an `Error`, so the log always gets one.
|
|
10183
10193
|
*
|
|
@@ -10266,27 +10276,64 @@ function drawsAtPlace(pctx, view, order) {
|
|
|
10266
10276
|
return view.rest.has(Tree.componentName) && typeof rest === "object" && "value" in rest && rest.value === order;
|
|
10267
10277
|
}
|
|
10268
10278
|
/**
|
|
10279
|
+
* Moves one screen root from the `Order` of its old place to the new one, on the entity and in the
|
|
10280
|
+
* rest pose. A view that does not draw at the old place keeps its own.
|
|
10281
|
+
*
|
|
10282
|
+
* @param pctx - Domain context of the projection module.
|
|
10283
|
+
* @param view - The view.
|
|
10284
|
+
* @param previous - The `Order` of the place the projection had.
|
|
10285
|
+
* @param order - The `Order` of its new place.
|
|
10286
|
+
*/
|
|
10287
|
+
function placeView(pctx, view, previous, order) {
|
|
10288
|
+
if (!drawsAtPlace(pctx, view, previous)) return;
|
|
10289
|
+
const value = pctx.deps.components.Order({ value: order });
|
|
10290
|
+
view.rest.set(value.type.componentName, value);
|
|
10291
|
+
writeValue(pctx, view.entity, value);
|
|
10292
|
+
}
|
|
10293
|
+
/**
|
|
10269
10294
|
* Keeps a mounted projection for the scene that comes, as a scene switch does for a projection
|
|
10270
10295
|
* both scenes list: it stays mounted into the new layer list, and its screen roots take the
|
|
10271
10296
|
* `Order` of their place in the new list, on the entity and in the rest pose, so the next node of
|
|
10272
|
-
* a root compares equal and writes none
|
|
10273
|
-
* despawned, no motion is cut, no hook runs. A view on its
|
|
10297
|
+
* a root compares equal and writes none; the view a warm window holds hidden does too. Nothing
|
|
10298
|
+
* else is touched: no view is spawned or despawned, no motion is cut, no hook runs. A view on its
|
|
10299
|
+
* way out keeps the order it leaves with.
|
|
10274
10300
|
*
|
|
10275
10301
|
* @param pctx - Domain context of the projection module.
|
|
10276
10302
|
* @param mounted - The mounted projection the new list names again.
|
|
10277
10303
|
* @param order - The `Order` of its place in the new list.
|
|
10304
|
+
* @param held - The view of its warm window, if any: held hidden, or shown and then placed with the
|
|
10305
|
+
* live views already.
|
|
10278
10306
|
*/
|
|
10279
|
-
function placeMounted(pctx, mounted, order) {
|
|
10307
|
+
function placeMounted(pctx, mounted, order, held) {
|
|
10280
10308
|
const previous = mounted.order;
|
|
10281
10309
|
mounted.layers = pctx.ctx.state.projection.layers;
|
|
10282
10310
|
if (previous === order) return;
|
|
10283
10311
|
mounted.order = order;
|
|
10284
|
-
for (const view of mounted.live.values())
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10312
|
+
for (const view of mounted.live.values()) placeView(pctx, view, previous, order);
|
|
10313
|
+
if (held !== void 0) placeView(pctx, held, previous, order);
|
|
10314
|
+
}
|
|
10315
|
+
/**
|
|
10316
|
+
* Spawns the entity of a view that is built aside or held warm: bare, flagged in `flags`, then
|
|
10317
|
+
* given its `Layer` and its view components in that order. The ecs fires `onAdded` in list order,
|
|
10318
|
+
* so every hook of a plugin already sees the flag (F97), and the `Tree` hook of `ui` the layer.
|
|
10319
|
+
*
|
|
10320
|
+
* @param pctx - Domain context of the projection module.
|
|
10321
|
+
* @param spec - The projection spec.
|
|
10322
|
+
* @param values - The output of `view(item)`, by component name.
|
|
10323
|
+
* @param flags - The set `isBuilding` reads: the scene build's entities, or the warm held ones.
|
|
10324
|
+
* @returns The entity.
|
|
10325
|
+
*/
|
|
10326
|
+
function spawnFlagged(pctx, spec, values, flags) {
|
|
10327
|
+
const ecs = pctx.deps.ecs;
|
|
10328
|
+
const owner = {
|
|
10329
|
+
kind: "projection",
|
|
10330
|
+
name: spec.name
|
|
10331
|
+
};
|
|
10332
|
+
const entity = ecs.spawn(owner, NO_COMPONENTS);
|
|
10333
|
+
flags.add(entity);
|
|
10334
|
+
ecs.add(entity, pctx.deps.components.Layer({ name: spec.layer }));
|
|
10335
|
+
for (const value of values.values()) ecs.add(entity, value);
|
|
10336
|
+
return entity;
|
|
10290
10337
|
}
|
|
10291
10338
|
/**
|
|
10292
10339
|
* Writes the layer of a view.
|
|
@@ -11312,9 +11359,536 @@ function reseedViews(state, name, from, to) {
|
|
|
11312
11359
|
}
|
|
11313
11360
|
}
|
|
11314
11361
|
//#endregion
|
|
11362
|
+
//#region src/plugins/world/projection/warm.ts
|
|
11363
|
+
/** A second in ms: the frame interval is this over the frame rate. */
|
|
11364
|
+
const SECOND_MS$2 = 1e3;
|
|
11365
|
+
/** The share of a frame interval a warm window may take: two thirds, the share of a scene build's `"auto"`. */
|
|
11366
|
+
const WARM_SHARE = 2 / 3;
|
|
11367
|
+
/** The budget of a frame when the loop answers no usable rate: two thirds of a 60 Hz frame, ≈ 11.1 ms. */
|
|
11368
|
+
const FALLBACK_WARM_MS = SECOND_MS$2 / 60 * WARM_SHARE;
|
|
11369
|
+
/**
|
|
11370
|
+
* The building budget of one frame for a warm window: two thirds of the frame interval at `fps`, or of a 60 Hz frame
|
|
11371
|
+
* for a rate that is not a finite number above 0. Pure.
|
|
11372
|
+
*
|
|
11373
|
+
* @param fps - The rate the loop runs at.
|
|
11374
|
+
* @returns Milliseconds per frame.
|
|
11375
|
+
* @example
|
|
11376
|
+
* ```ts
|
|
11377
|
+
* warmBudget(120); // 5.555…
|
|
11378
|
+
* ```
|
|
11379
|
+
*/
|
|
11380
|
+
function warmBudget(fps) {
|
|
11381
|
+
return Number.isFinite(fps) && fps > 0 ? SECOND_MS$2 / fps * WARM_SHARE : FALLBACK_WARM_MS;
|
|
11382
|
+
}
|
|
11383
|
+
/**
|
|
11384
|
+
* Tells whether two items have the same content: the same object, or equal as JSON. Pure.
|
|
11385
|
+
*
|
|
11386
|
+
* @param before - The item the view was built for.
|
|
11387
|
+
* @param after - The item that comes.
|
|
11388
|
+
* @returns True when nothing of the view has to change.
|
|
11389
|
+
* @example
|
|
11390
|
+
* ```ts
|
|
11391
|
+
* sameItem({ page: "main" }, { page: "main" }); // true
|
|
11392
|
+
* ```
|
|
11393
|
+
*/
|
|
11394
|
+
function sameItem(before, after) {
|
|
11395
|
+
return before === after || deepEquals(before, after);
|
|
11396
|
+
}
|
|
11397
|
+
/**
|
|
11398
|
+
* Tells whether a record holds a view.
|
|
11399
|
+
*
|
|
11400
|
+
* @param record - The record.
|
|
11401
|
+
* @returns True when it holds one.
|
|
11402
|
+
*/
|
|
11403
|
+
function holds$2(record) {
|
|
11404
|
+
return record.view !== void 0;
|
|
11405
|
+
}
|
|
11406
|
+
/**
|
|
11407
|
+
* Tells whether a record was read against the state of this snapshot.
|
|
11408
|
+
*
|
|
11409
|
+
* @param seen - The state the record last read.
|
|
11410
|
+
* @param snapshot - The state now.
|
|
11411
|
+
* @returns True when neither root changed since.
|
|
11412
|
+
*/
|
|
11413
|
+
function isSeen(seen, snapshot) {
|
|
11414
|
+
return seen !== void 0 && seen.player === snapshot.player && seen.session === snapshot.session;
|
|
11415
|
+
}
|
|
11416
|
+
/**
|
|
11417
|
+
* Gives a mounted projection that declares `warm` its record, cold, at the end of the warm list. A projection that
|
|
11418
|
+
* has one keeps it: a projection a scene before mounted and the coming one keeps (F23) keeps its held view.
|
|
11419
|
+
*
|
|
11420
|
+
* @param state - The projection branch of the plugin state.
|
|
11421
|
+
* @param spec - The projection spec.
|
|
11422
|
+
*/
|
|
11423
|
+
function ensureWarm(state, spec) {
|
|
11424
|
+
if (spec.warm === void 0 || state.warm.has(spec.name)) return;
|
|
11425
|
+
const record = {
|
|
11426
|
+
name: spec.name,
|
|
11427
|
+
entities: /* @__PURE__ */ new Set(),
|
|
11428
|
+
phase: "cold"
|
|
11429
|
+
};
|
|
11430
|
+
state.warm.set(spec.name, record);
|
|
11431
|
+
state.warmList.push(record);
|
|
11432
|
+
state.warmStale = true;
|
|
11433
|
+
}
|
|
11434
|
+
/**
|
|
11435
|
+
* The record whose held view a new key of a projection shows: one that holds a view of that key, built or still in
|
|
11436
|
+
* work. Only a mounted projection has a record: a name is in one table only, so a projection a scene build mounts
|
|
11437
|
+
* aside has none.
|
|
11438
|
+
*
|
|
11439
|
+
* @param state - The projection branch of the plugin state.
|
|
11440
|
+
* @param name - The projection.
|
|
11441
|
+
* @param key - The key that enters.
|
|
11442
|
+
* @returns The record, or `undefined` when the key spawns as before.
|
|
11443
|
+
*/
|
|
11444
|
+
function heldFor(state, name, key) {
|
|
11445
|
+
if (state.warm.size === 0) return void 0;
|
|
11446
|
+
const record = state.warm.get(name);
|
|
11447
|
+
if (record === void 0 || !holds$2(record) || record.phase === "shown" || record.key !== key) return;
|
|
11448
|
+
return record;
|
|
11449
|
+
}
|
|
11450
|
+
/**
|
|
11451
|
+
* Despawns what a record holds: its view, with the cause `"discard"` and no motion, then every entity `adopt` marked
|
|
11452
|
+
* for it that is still there. The removal hooks still see them held. A shown view belongs to `mounted` and is left
|
|
11453
|
+
* alone. The record keeps its phase; the caller sets it.
|
|
11454
|
+
*
|
|
11455
|
+
* @param pctx - Domain context of the projection module.
|
|
11456
|
+
* @param record - The record.
|
|
11457
|
+
*/
|
|
11458
|
+
function dropHeld(pctx, record) {
|
|
11459
|
+
const state = pctx.ctx.state.projection;
|
|
11460
|
+
const ecs = pctx.deps.ecs;
|
|
11461
|
+
const view = record.view;
|
|
11462
|
+
if (view !== void 0 && record.phase !== "shown") {
|
|
11463
|
+
cancelTracks(pctx, view.entity);
|
|
11464
|
+
state.byEntity.delete(view.entity);
|
|
11465
|
+
state.mutes.delete(view.entity);
|
|
11466
|
+
state.rests.delete(view.entity);
|
|
11467
|
+
view.cause = "discard";
|
|
11468
|
+
state.leaving.set(view.entity, "discard");
|
|
11469
|
+
state.membershipVersion += 1;
|
|
11470
|
+
ecs.despawn(view.entity);
|
|
11471
|
+
}
|
|
11472
|
+
for (const entity of record.entities) if (ecs.ownerOf(entity) !== void 0) ecs.despawn(entity);
|
|
11473
|
+
for (const entity of record.entities) state.warmHeld.delete(entity);
|
|
11474
|
+
record.entities.clear();
|
|
11475
|
+
}
|
|
11476
|
+
/**
|
|
11477
|
+
* Leaves a record cold: nothing held, no longer in work, and the warm step looks at it again.
|
|
11478
|
+
*
|
|
11479
|
+
* @param state - The projection branch of the plugin state.
|
|
11480
|
+
* @param record - The record.
|
|
11481
|
+
*/
|
|
11482
|
+
function coolRecord(state, record) {
|
|
11483
|
+
record.phase = "cold";
|
|
11484
|
+
delete record.key;
|
|
11485
|
+
delete record.item;
|
|
11486
|
+
delete record.view;
|
|
11487
|
+
if (state.warmActive === record) delete state.warmActive;
|
|
11488
|
+
state.warmStale = true;
|
|
11489
|
+
}
|
|
11490
|
+
/**
|
|
11491
|
+
* Drops what a record holds and leaves it cold, to be built again by the warm step.
|
|
11492
|
+
*
|
|
11493
|
+
* @param pctx - Domain context of the projection module.
|
|
11494
|
+
* @param record - The record.
|
|
11495
|
+
*/
|
|
11496
|
+
function discardWarm(pctx, record) {
|
|
11497
|
+
dropHeld(pctx, record);
|
|
11498
|
+
coolRecord(pctx.ctx.state.projection, record);
|
|
11499
|
+
delete record.seen;
|
|
11500
|
+
}
|
|
11501
|
+
/**
|
|
11502
|
+
* Drops the held view of every record and leaves it cold: a restore or a load replaces the state (ui would build held
|
|
11503
|
+
* roots again in one block with its others), and a forced rerun runs `view` anew (a new locale). A view `from` shows
|
|
11504
|
+
* is a live view and stays; its record is warmed again after the close.
|
|
11505
|
+
*
|
|
11506
|
+
* @param pctx - Domain context of the projection module.
|
|
11507
|
+
*/
|
|
11508
|
+
function discardHeld(pctx) {
|
|
11509
|
+
for (const record of pctx.ctx.state.projection.warmList) discardWarm(pctx, record);
|
|
11510
|
+
}
|
|
11511
|
+
/**
|
|
11512
|
+
* Drops the record in work at the start of a scene build: its parts would hold the build's readiness. A ready record
|
|
11513
|
+
* stays held and rests until the build ends; a cold one has nothing.
|
|
11514
|
+
*
|
|
11515
|
+
* @param pctx - Domain context of the projection module.
|
|
11516
|
+
*/
|
|
11517
|
+
function discardActive(pctx) {
|
|
11518
|
+
const active = pctx.ctx.state.projection.warmActive;
|
|
11519
|
+
if (active !== void 0) discardWarm(pctx, active);
|
|
11520
|
+
}
|
|
11521
|
+
/**
|
|
11522
|
+
* Forgets the record of a projection that is unmounted: its held view and the entities marked for it are despawned.
|
|
11523
|
+
*
|
|
11524
|
+
* @param pctx - Domain context of the projection module.
|
|
11525
|
+
* @param name - The projection.
|
|
11526
|
+
*/
|
|
11527
|
+
function forgetWarm(pctx, name) {
|
|
11528
|
+
const state = pctx.ctx.state.projection;
|
|
11529
|
+
const record = state.warm.get(name);
|
|
11530
|
+
if (record === void 0) return;
|
|
11531
|
+
discardWarm(pctx, record);
|
|
11532
|
+
state.warm.delete(name);
|
|
11533
|
+
state.warmList.splice(state.warmList.indexOf(record), 1);
|
|
11534
|
+
}
|
|
11535
|
+
/**
|
|
11536
|
+
* Drops every held view and forgets every record: the clear of the projections.
|
|
11537
|
+
*
|
|
11538
|
+
* @param pctx - Domain context of the projection module.
|
|
11539
|
+
*/
|
|
11540
|
+
function clearWarm(pctx) {
|
|
11541
|
+
const state = pctx.ctx.state.projection;
|
|
11542
|
+
for (const record of state.warmList) dropHeld(pctx, record);
|
|
11543
|
+
state.warm.clear();
|
|
11544
|
+
state.warmList.length = 0;
|
|
11545
|
+
state.warmHeld.clear();
|
|
11546
|
+
delete state.warmActive;
|
|
11547
|
+
state.warmStale = false;
|
|
11548
|
+
}
|
|
11549
|
+
/**
|
|
11550
|
+
* Marks an entity another plugin spawned for the record in work, so `isBuilding` answers for it and a discard
|
|
11551
|
+
* despawns it with the view. Does nothing while no record is in work.
|
|
11552
|
+
*
|
|
11553
|
+
* @param state - The projection branch of the plugin state.
|
|
11554
|
+
* @param entity - The entity.
|
|
11555
|
+
*/
|
|
11556
|
+
function adoptWarm(state, entity) {
|
|
11557
|
+
const active = state.warmActive;
|
|
11558
|
+
if (active === void 0) return;
|
|
11559
|
+
active.entities.add(entity);
|
|
11560
|
+
state.warmHeld.add(entity);
|
|
11561
|
+
}
|
|
11562
|
+
/**
|
|
11563
|
+
* Holds an element whose key a plugin registers under a projection whose warm window is closed: the record holds a
|
|
11564
|
+
* view, not shown, and the projection shows no live view, so the element can only be one of the held root's, made
|
|
11565
|
+
* after the record was ready (a row a windowed list ranges in after the solve). It joins the record as an adopted one:
|
|
11566
|
+
* `isBuilding` answers true, `entityOf` nothing, until the open; a discard despawns it with the view. A projection
|
|
11567
|
+
* that shows other keys live while it warms one is not covered: an element registered for it is taken as live.
|
|
11568
|
+
*
|
|
11569
|
+
* @param state - The projection branch of the plugin state.
|
|
11570
|
+
* @param projection - The projection the key is registered under.
|
|
11571
|
+
* @param entity - The element.
|
|
11572
|
+
*/
|
|
11573
|
+
function holdRegistered(state, projection, entity) {
|
|
11574
|
+
if (state.warm.size === 0) return;
|
|
11575
|
+
const record = state.warm.get(projection);
|
|
11576
|
+
if (record?.view === void 0 || record.phase === "shown") return;
|
|
11577
|
+
if (state.mounted.get(projection)?.live.size !== 0) return;
|
|
11578
|
+
record.entities.add(entity);
|
|
11579
|
+
state.warmHeld.add(entity);
|
|
11580
|
+
}
|
|
11581
|
+
/** What the prune's callback reads: set before the walk, so the callback is module-level and a walk makes no closure. */
|
|
11582
|
+
const pruning = { pctx: void 0 };
|
|
11583
|
+
/**
|
|
11584
|
+
* Forgets one held entity when it is gone: out of the held set and out of the record that marked it.
|
|
11585
|
+
*
|
|
11586
|
+
* @param entity - The held entity.
|
|
11587
|
+
* @param _same - The same entity, as a set hands it twice.
|
|
11588
|
+
* @param held - The held set.
|
|
11589
|
+
*/
|
|
11590
|
+
function dropDeadHeld(entity, _same, held) {
|
|
11591
|
+
const pctx = pruning.pctx;
|
|
11592
|
+
if (pctx === void 0 || pctx.deps.ecs.ownerOf(entity) !== void 0) return;
|
|
11593
|
+
held.delete(entity);
|
|
11594
|
+
const list = pctx.ctx.state.projection.warmList;
|
|
11595
|
+
for (let index = 0; index < list.length; index += 1) list[index]?.entities.delete(entity);
|
|
11596
|
+
}
|
|
11597
|
+
/**
|
|
11598
|
+
* Forgets the held entities that are gone: the elements a plugin despawned while their window was held (the rows a
|
|
11599
|
+
* refresh took away), so the held sets of a window held for a long session do not grow. The sweep calls it after a
|
|
11600
|
+
* frame that despawned an entity; with nothing held it reads one size.
|
|
11601
|
+
*
|
|
11602
|
+
* @param pctx - Domain context of the projection module.
|
|
11603
|
+
*/
|
|
11604
|
+
function forgetDeadHeld(pctx) {
|
|
11605
|
+
const held = pctx.ctx.state.projection.warmHeld;
|
|
11606
|
+
if (held.size === 0) return;
|
|
11607
|
+
const outer = pruning.pctx;
|
|
11608
|
+
pruning.pctx = pctx;
|
|
11609
|
+
held.forEach(dropDeadHeld);
|
|
11610
|
+
pruning.pctx = outer;
|
|
11611
|
+
}
|
|
11612
|
+
/**
|
|
11613
|
+
* The budget `left()` counts down in this frame: the scene build's, else the warm window's while one is in work.
|
|
11614
|
+
*
|
|
11615
|
+
* @param state - The projection branch of the plugin state.
|
|
11616
|
+
* @returns Milliseconds per frame, or `undefined` while nothing is built.
|
|
11617
|
+
*/
|
|
11618
|
+
function frameBudget(state) {
|
|
11619
|
+
if (state.building !== void 0) return state.building.budgetMs;
|
|
11620
|
+
return state.warmActive === void 0 ? void 0 : state.warmBudgetMs;
|
|
11621
|
+
}
|
|
11622
|
+
/**
|
|
11623
|
+
* Shows the held view of a record: it and every entity marked for it stop being held, the view joins the live views
|
|
11624
|
+
* of its projection with the cause of the reconcile, and the record is shown. A record still in work leaves the work:
|
|
11625
|
+
* ui builds the rest of its root in one block.
|
|
11626
|
+
*
|
|
11627
|
+
* @param pctx - Domain context of the projection module.
|
|
11628
|
+
* @param mounted - The mounted projection.
|
|
11629
|
+
* @param record - The record that holds the view.
|
|
11630
|
+
* @param cause - `"mount"` for a direct reconcile, `"change"` for a live one.
|
|
11631
|
+
*/
|
|
11632
|
+
function showHeld(pctx, mounted, record, cause) {
|
|
11633
|
+
const state = pctx.ctx.state.projection;
|
|
11634
|
+
const view = record.view;
|
|
11635
|
+
for (const entity of record.entities) state.warmHeld.delete(entity);
|
|
11636
|
+
record.entities.clear();
|
|
11637
|
+
if (state.warmActive === record) delete state.warmActive;
|
|
11638
|
+
record.phase = "shown";
|
|
11639
|
+
view.cause = cause;
|
|
11640
|
+
mounted.live.set(view.key, view);
|
|
11641
|
+
state.membershipVersion += 1;
|
|
11642
|
+
}
|
|
11643
|
+
/**
|
|
11644
|
+
* The close of a window: when the view leaving is the one a record showed, the record goes cold and is built again
|
|
11645
|
+
* in idle frames. The exit itself runs as for any view.
|
|
11646
|
+
*
|
|
11647
|
+
* @param state - The projection branch of the plugin state.
|
|
11648
|
+
* @param name - The projection.
|
|
11649
|
+
* @param view - The view that leaves the live views.
|
|
11650
|
+
*/
|
|
11651
|
+
function coolShown(state, name, view) {
|
|
11652
|
+
const record = state.warm.get(name);
|
|
11653
|
+
if (record?.view !== view) return;
|
|
11654
|
+
coolRecord(state, record);
|
|
11655
|
+
delete record.seen;
|
|
11656
|
+
}
|
|
11657
|
+
/**
|
|
11658
|
+
* Writes the difference between a view's rest pose and a new output of `view` straight onto its entity: added and
|
|
11659
|
+
* changed components are written, removed ones taken off, no hook runs and no motion plays. The direct write of a
|
|
11660
|
+
* changed item, for a held view and for the one the open shows.
|
|
11661
|
+
*
|
|
11662
|
+
* @param pctx - Domain context of the projection module.
|
|
11663
|
+
* @param view - The view.
|
|
11664
|
+
* @param next - The new output of `view(item)`, by component name.
|
|
11665
|
+
* @param item - The item it was made from.
|
|
11666
|
+
*/
|
|
11667
|
+
function writeDifference(pctx, view, next, item) {
|
|
11668
|
+
const { changed } = diffComponents(view.rest, next, pctx.deps.components.Tree.componentName);
|
|
11669
|
+
for (const [name, value] of next) if (!view.rest.has(name)) writeValue(pctx, view.entity, value);
|
|
11670
|
+
for (const [name, value] of view.rest) if (!next.has(name)) pctx.deps.ecs.remove(view.entity, value.type);
|
|
11671
|
+
view.rest = next;
|
|
11672
|
+
view.item = item;
|
|
11673
|
+
finishHandles(view);
|
|
11674
|
+
writeRestNow(pctx, view, changed);
|
|
11675
|
+
}
|
|
11676
|
+
/**
|
|
11677
|
+
* Tells whether a motion that owns its fields and ends runs: a track that is not additive and does not repeat
|
|
11678
|
+
* forever. A loop adds to its fields and runs for good, and a track that repeats forever never ends, so neither holds
|
|
11679
|
+
* the warm work back.
|
|
11680
|
+
*
|
|
11681
|
+
* @param tracks - The tracks the projection started.
|
|
11682
|
+
* @returns True while one such track is active.
|
|
11683
|
+
*/
|
|
11684
|
+
function ownedMotionRuns(tracks) {
|
|
11685
|
+
const count = tracks.length;
|
|
11686
|
+
for (let index = 0; index < count; index += 1) {
|
|
11687
|
+
const track = tracks[index];
|
|
11688
|
+
if (track !== void 0 && !track.additive && !track.forever && track.handle.active()) return true;
|
|
11689
|
+
}
|
|
11690
|
+
return false;
|
|
11691
|
+
}
|
|
11692
|
+
/**
|
|
11693
|
+
* Tells whether the world may warm now: live, no scene build, and a drawing plugin that registered an `onBuild`
|
|
11694
|
+
* check (a headless world warms nothing).
|
|
11695
|
+
*
|
|
11696
|
+
* @param pctx - Domain context of the projection module.
|
|
11697
|
+
* @returns True when the warm step may run.
|
|
11698
|
+
*/
|
|
11699
|
+
function mayWarm(pctx) {
|
|
11700
|
+
const state = pctx.ctx.state.projection;
|
|
11701
|
+
return state.building === void 0 && state.buildChecks.length > 0 && pctx.deps.ecs.mode() === "live";
|
|
11702
|
+
}
|
|
11703
|
+
/**
|
|
11704
|
+
* Polls the checks of the record in work: when every one answers true its view is built, the record is ready and
|
|
11705
|
+
* `left()` is `Infinity` again.
|
|
11706
|
+
*
|
|
11707
|
+
* @param state - The projection branch of the plugin state.
|
|
11708
|
+
* @param active - The record in work.
|
|
11709
|
+
*/
|
|
11710
|
+
function pollActive(state, active) {
|
|
11711
|
+
const checks = state.buildChecks;
|
|
11712
|
+
const count = checks.length;
|
|
11713
|
+
for (let index = 0; index < count; index += 1) if (checks[index]?.() !== true) return;
|
|
11714
|
+
active.phase = "ready";
|
|
11715
|
+
delete state.warmActive;
|
|
11716
|
+
}
|
|
11717
|
+
/**
|
|
11718
|
+
* Reads the warm item of a projection and its key. A `warm` or a `key` that throws is logged as a projection that
|
|
11719
|
+
* failed, and nothing is warm.
|
|
11720
|
+
*
|
|
11721
|
+
* @param pctx - Domain context of the projection module.
|
|
11722
|
+
* @param spec - The projection spec, which declares `warm`.
|
|
11723
|
+
* @param snapshot - The state now.
|
|
11724
|
+
* @returns The item and its key, or `undefined` for no item and for a throw.
|
|
11725
|
+
*/
|
|
11726
|
+
function readWarm(pctx, spec, snapshot) {
|
|
11727
|
+
try {
|
|
11728
|
+
const item = spec.warm?.(snapshot.player, snapshot.session);
|
|
11729
|
+
if (item === void 0 || item === null) return void 0;
|
|
11730
|
+
return {
|
|
11731
|
+
item,
|
|
11732
|
+
key: spec.key?.(item) ?? spec.name
|
|
11733
|
+
};
|
|
11734
|
+
} catch (error) {
|
|
11735
|
+
pctx.ctx.log.error("world:projection-failed", { projection: spec.name }, asError$2(error));
|
|
11736
|
+
return;
|
|
11737
|
+
}
|
|
11738
|
+
}
|
|
11739
|
+
/**
|
|
11740
|
+
* Runs `view` for a warm item. A throw is logged as a projection that failed.
|
|
11741
|
+
*
|
|
11742
|
+
* @param pctx - Domain context of the projection module.
|
|
11743
|
+
* @param spec - The projection spec.
|
|
11744
|
+
* @param item - The warm item.
|
|
11745
|
+
* @returns The component values, or `undefined` when `view` threw.
|
|
11746
|
+
*/
|
|
11747
|
+
function viewOfItem(pctx, spec, item) {
|
|
11748
|
+
try {
|
|
11749
|
+
return collectView(pctx, spec, item);
|
|
11750
|
+
} catch (error) {
|
|
11751
|
+
pctx.ctx.log.error("world:projection-failed", { projection: spec.name }, asError$2(error));
|
|
11752
|
+
return;
|
|
11753
|
+
}
|
|
11754
|
+
}
|
|
11755
|
+
/**
|
|
11756
|
+
* Starts the work of a record: it becomes the record in work, `left()` counts the warm budget from the frame rate
|
|
11757
|
+
* the loop runs at, and the loop is woken, so the building frames come at the full rate.
|
|
11758
|
+
*
|
|
11759
|
+
* @param pctx - Domain context of the projection module.
|
|
11760
|
+
* @param record - The record.
|
|
11761
|
+
*/
|
|
11762
|
+
function startWork(pctx, record) {
|
|
11763
|
+
const state = pctx.ctx.state.projection;
|
|
11764
|
+
record.phase = "building";
|
|
11765
|
+
state.warmActive = record;
|
|
11766
|
+
state.warmBudgetMs = warmBudget(pctx.ctx.deps.time.rate().fps);
|
|
11767
|
+
pctx.ctx.deps.time.wake();
|
|
11768
|
+
}
|
|
11769
|
+
/**
|
|
11770
|
+
* Spawns the held view of a warm item, as a scene build spawns a view: bare, flagged held, then its `Layer` and its
|
|
11771
|
+
* view components, so an `onAdded` hook already asks `isBuilding` true, and with `"change"` as its cause, so its
|
|
11772
|
+
* enter plays when it is shown. The record is in work from before the spawn: what ui marks in its hooks is the
|
|
11773
|
+
* record's. Nothing is spawned when `view` throws.
|
|
11774
|
+
*
|
|
11775
|
+
* @param pctx - Domain context of the projection module.
|
|
11776
|
+
* @param spec - The projection spec.
|
|
11777
|
+
* @param record - The cold record.
|
|
11778
|
+
* @param warm - The warm item and its key.
|
|
11779
|
+
* @param warm.item - The warm item.
|
|
11780
|
+
* @param warm.key - Its key.
|
|
11781
|
+
*/
|
|
11782
|
+
function spawnWarm(pctx, spec, record, warm) {
|
|
11783
|
+
const values = viewOfItem(pctx, spec, warm.item);
|
|
11784
|
+
if (values === void 0) return;
|
|
11785
|
+
const state = pctx.ctx.state.projection;
|
|
11786
|
+
startWork(pctx, record);
|
|
11787
|
+
const entity = spawnFlagged(pctx, spec, values, state.warmHeld);
|
|
11788
|
+
const view = createViewRecord(entity, spec.name, warm.key, warm.item, values, "change");
|
|
11789
|
+
record.entities.add(entity);
|
|
11790
|
+
seedMutes(state, spec, entity);
|
|
11791
|
+
state.byEntity.set(entity, view);
|
|
11792
|
+
record.view = view;
|
|
11793
|
+
record.key = warm.key;
|
|
11794
|
+
record.item = warm.item;
|
|
11795
|
+
}
|
|
11796
|
+
/**
|
|
11797
|
+
* Brings a ready record up to the warm item a commit gave: the same content changes nothing; the same key writes the
|
|
11798
|
+
* difference into the held view, which ui builds again in parts; another key drops the view and spawns the new one.
|
|
11799
|
+
*
|
|
11800
|
+
* @param pctx - Domain context of the projection module.
|
|
11801
|
+
* @param spec - The projection spec.
|
|
11802
|
+
* @param record - The ready record.
|
|
11803
|
+
* @param warm - The warm item and its key.
|
|
11804
|
+
* @param warm.item - The warm item.
|
|
11805
|
+
* @param warm.key - Its key.
|
|
11806
|
+
* @returns True when the step did work.
|
|
11807
|
+
*/
|
|
11808
|
+
function refreshWarm(pctx, spec, record, warm) {
|
|
11809
|
+
const view = record.view;
|
|
11810
|
+
if (view !== void 0 && warm.key === record.key) {
|
|
11811
|
+
if (sameItem(record.item, warm.item)) return false;
|
|
11812
|
+
const next = viewOfItem(pctx, spec, warm.item);
|
|
11813
|
+
if (next === void 0) {
|
|
11814
|
+
dropHeld(pctx, record);
|
|
11815
|
+
coolRecord(pctx.ctx.state.projection, record);
|
|
11816
|
+
return true;
|
|
11817
|
+
}
|
|
11818
|
+
startWork(pctx, record);
|
|
11819
|
+
writeDifference(pctx, view, next, warm.item);
|
|
11820
|
+
record.item = warm.item;
|
|
11821
|
+
return true;
|
|
11822
|
+
}
|
|
11823
|
+
dropHeld(pctx, record);
|
|
11824
|
+
coolRecord(pctx.ctx.state.projection, record);
|
|
11825
|
+
spawnWarm(pctx, spec, record, warm);
|
|
11826
|
+
return true;
|
|
11827
|
+
}
|
|
11828
|
+
/**
|
|
11829
|
+
* One record's turn in the warm step: a record shown, in work, or read against this state is passed over. Otherwise
|
|
11830
|
+
* `warm` is read: with no item, or with a key `from` shows, what is held is dropped; a cold record spawns its held
|
|
11831
|
+
* view, a ready one is brought up to date.
|
|
11832
|
+
*
|
|
11833
|
+
* @param pctx - Domain context of the projection module.
|
|
11834
|
+
* @param record - The record.
|
|
11835
|
+
* @param snapshot - The state now.
|
|
11836
|
+
* @returns True when the step did work, so the frame takes no more.
|
|
11837
|
+
*/
|
|
11838
|
+
function stepRecord$1(pctx, record, snapshot) {
|
|
11839
|
+
if (record.phase === "shown" || record.phase === "building") return false;
|
|
11840
|
+
if (isSeen(record.seen, snapshot)) return false;
|
|
11841
|
+
const state = pctx.ctx.state.projection;
|
|
11842
|
+
const spec = state.specs.get(record.name);
|
|
11843
|
+
if (spec === void 0) return false;
|
|
11844
|
+
record.seen = snapshot;
|
|
11845
|
+
const warm = readWarm(pctx, spec, snapshot);
|
|
11846
|
+
if (warm === void 0 || state.mounted.get(record.name)?.items.has(warm.key) === true) {
|
|
11847
|
+
if (record.view === void 0) return false;
|
|
11848
|
+
dropHeld(pctx, record);
|
|
11849
|
+
coolRecord(state, record);
|
|
11850
|
+
return true;
|
|
11851
|
+
}
|
|
11852
|
+
if (record.phase === "ready") return refreshWarm(pctx, spec, record, warm);
|
|
11853
|
+
spawnWarm(pctx, spec, record, warm);
|
|
11854
|
+
return record.view !== void 0;
|
|
11855
|
+
}
|
|
11856
|
+
/**
|
|
11857
|
+
* Takes the next record that has work, in mounted order, and does its one step. A walk that finds none leaves the
|
|
11858
|
+
* world at rest until a commit or a close.
|
|
11859
|
+
*
|
|
11860
|
+
* @param pctx - Domain context of the projection module.
|
|
11861
|
+
*/
|
|
11862
|
+
function stepNext(pctx) {
|
|
11863
|
+
const state = pctx.ctx.state.projection;
|
|
11864
|
+
const snapshot = pctx.ctx.deps.model.store.snapshot();
|
|
11865
|
+
for (const record of state.warmList) if (stepRecord$1(pctx, record, snapshot)) return;
|
|
11866
|
+
state.warmStale = false;
|
|
11867
|
+
}
|
|
11868
|
+
/**
|
|
11869
|
+
* One step of the warm windows, run in world's `input` callback after the reconcile. At rest it reads two fields and
|
|
11870
|
+
* returns. It runs only in a live world with no scene build, a drawing plugin, and no motion that owns its fields and
|
|
11871
|
+
* ends: the frames of an animation get no warm step. Where it may not run, the record in work is dropped: a paused or
|
|
11872
|
+
* fast world builds no part of it, and `left()` would stay finite for good; it is built again once the step runs.
|
|
11873
|
+
* While a record is in work its checks are polled; otherwise the next record with work spawns, patches or drops its
|
|
11874
|
+
* held view. One step a frame.
|
|
11875
|
+
*
|
|
11876
|
+
* @param pctx - Domain context of the projection module.
|
|
11877
|
+
*/
|
|
11878
|
+
function stepWarm(pctx) {
|
|
11879
|
+
const state = pctx.ctx.state.projection;
|
|
11880
|
+
const active = state.warmActive;
|
|
11881
|
+
if (active === void 0 && !state.warmStale) return;
|
|
11882
|
+
if (!mayWarm(pctx)) {
|
|
11883
|
+
if (active !== void 0) discardWarm(pctx, active);
|
|
11884
|
+
return;
|
|
11885
|
+
}
|
|
11886
|
+
if (ownedMotionRuns(state.tracks)) return;
|
|
11887
|
+
if (active === void 0) stepNext(pctx);
|
|
11888
|
+
else pollActive(state, active);
|
|
11889
|
+
}
|
|
11890
|
+
//#endregion
|
|
11315
11891
|
//#region src/plugins/world/projection/reconcile.ts
|
|
11316
|
-
/** The components of a view of the build at its spawn: none, so it is flagged before the first `onAdded`. */
|
|
11317
|
-
const NO_COMPONENTS = [];
|
|
11318
11892
|
/**
|
|
11319
11893
|
* Creates the empty set of used hints. It lives in its own non-exported function because lint
|
|
11320
11894
|
* rule L5 refuses a collection built inside an exported declaration.
|
|
@@ -11379,16 +11953,14 @@ function hintFor$1(pctx, projection, key, used) {
|
|
|
11379
11953
|
return hint;
|
|
11380
11954
|
}
|
|
11381
11955
|
/**
|
|
11382
|
-
*
|
|
11383
|
-
*
|
|
11384
|
-
*
|
|
11385
|
-
*
|
|
11386
|
-
* A view of a projection the running build mounts is spawned bare, flagged building, then given
|
|
11387
|
-
* its components in the same order: the `onAdded` hooks of a plugin then tell it apart (F97).
|
|
11956
|
+
* Plays how a view comes when the reconcile plays motions: the `enter` hook and the `loop` hook,
|
|
11957
|
+
* then the settle of what is loose. The loop is not kept with the view's handles: a change cancels
|
|
11958
|
+
* those, and the loop runs until the view dies. A direct reconcile plays neither hook; the view
|
|
11959
|
+
* then owes its loop, which the sweep starts.
|
|
11388
11960
|
*
|
|
11389
11961
|
* @param pctx - Domain context of the projection module.
|
|
11390
11962
|
* @param spec - The projection spec.
|
|
11391
|
-
* @param
|
|
11963
|
+
* @param view - The view that came: spawned now, or shown from a warm window.
|
|
11392
11964
|
* @param entry - The key, its item, the peers, the mode and the used hints.
|
|
11393
11965
|
* @param entry.key - The model key.
|
|
11394
11966
|
* @param entry.item - The model item.
|
|
@@ -11396,33 +11968,12 @@ function hintFor$1(pctx, projection, key, used) {
|
|
|
11396
11968
|
* @param entry.direct - Whether the reconcile writes without motions.
|
|
11397
11969
|
* @param entry.used - The hints that reached an entry.
|
|
11398
11970
|
*/
|
|
11399
|
-
function
|
|
11400
|
-
const values = collectView(pctx, spec, entry.item);
|
|
11401
|
-
const state = pctx.ctx.state.projection;
|
|
11402
|
-
const building = state.building;
|
|
11403
|
-
const ecs = pctx.deps.ecs;
|
|
11404
|
-
const owner = {
|
|
11405
|
-
kind: "projection",
|
|
11406
|
-
name: spec.name
|
|
11407
|
-
};
|
|
11408
|
-
const layer = pctx.deps.components.Layer({ name: spec.layer });
|
|
11409
|
-
let entity;
|
|
11410
|
-
if (building?.mounted.get(spec.name) === mounted) {
|
|
11411
|
-
entity = ecs.spawn(owner, NO_COMPONENTS);
|
|
11412
|
-
building.entities.add(entity);
|
|
11413
|
-
ecs.add(entity, layer);
|
|
11414
|
-
for (const value of values.values()) ecs.add(entity, value);
|
|
11415
|
-
} else entity = ecs.spawn(owner, [layer, ...values.values()]);
|
|
11416
|
-
const view = createViewRecord(entity, spec.name, entry.key, entry.item, values, entry.direct ? "mount" : "change");
|
|
11417
|
-
seedMutes(state, spec, entity);
|
|
11418
|
-
mounted.live.set(entry.key, view);
|
|
11419
|
-
state.byEntity.set(entity, view);
|
|
11420
|
-
state.membershipVersion += 1;
|
|
11971
|
+
function playEnter$1(pctx, spec, view, entry) {
|
|
11421
11972
|
const hook = spec.motion?.enter;
|
|
11422
11973
|
const loop = spec.motion?.loop;
|
|
11423
11974
|
if (entry.direct) {
|
|
11424
11975
|
view.loopOwed = true;
|
|
11425
|
-
state.owedLoops += 1;
|
|
11976
|
+
pctx.ctx.state.projection.owedLoops += 1;
|
|
11426
11977
|
return;
|
|
11427
11978
|
}
|
|
11428
11979
|
if (hook === void 0 && loop === void 0) return;
|
|
@@ -11436,6 +11987,68 @@ function enterEntry(pctx, spec, mounted, entry) {
|
|
|
11436
11987
|
playSettle(pctx, view, spec, entry.peers, looseComponents(pctx, view));
|
|
11437
11988
|
}
|
|
11438
11989
|
/**
|
|
11990
|
+
* A key that is new: spawn the entity with the projection's layer and the view components, then
|
|
11991
|
+
* play how it comes (`playEnter`). A view of a projection the running build mounts is spawned bare,
|
|
11992
|
+
* flagged building, then given its components in the same order: the `onAdded` hooks of a plugin
|
|
11993
|
+
* then tell it apart (F97).
|
|
11994
|
+
*
|
|
11995
|
+
* @param pctx - Domain context of the projection module.
|
|
11996
|
+
* @param spec - The projection spec.
|
|
11997
|
+
* @param mounted - The mounted projection.
|
|
11998
|
+
* @param entry - The key, its item, the peers, the mode and the used hints.
|
|
11999
|
+
* @param entry.key - The model key.
|
|
12000
|
+
* @param entry.item - The model item.
|
|
12001
|
+
* @param entry.peers - The new and the old items.
|
|
12002
|
+
* @param entry.direct - Whether the reconcile writes without motions.
|
|
12003
|
+
* @param entry.used - The hints that reached an entry.
|
|
12004
|
+
*/
|
|
12005
|
+
function enterEntry(pctx, spec, mounted, entry) {
|
|
12006
|
+
const values = collectView(pctx, spec, entry.item);
|
|
12007
|
+
const state = pctx.ctx.state.projection;
|
|
12008
|
+
const building = state.building;
|
|
12009
|
+
let entity;
|
|
12010
|
+
if (building?.mounted.get(spec.name) === mounted) entity = spawnFlagged(pctx, spec, values, building.entities);
|
|
12011
|
+
else {
|
|
12012
|
+
const layer = pctx.deps.components.Layer({ name: spec.layer });
|
|
12013
|
+
entity = pctx.deps.ecs.spawn({
|
|
12014
|
+
kind: "projection",
|
|
12015
|
+
name: spec.name
|
|
12016
|
+
}, [layer, ...values.values()]);
|
|
12017
|
+
}
|
|
12018
|
+
const view = createViewRecord(entity, spec.name, entry.key, entry.item, values, entry.direct ? "mount" : "change");
|
|
12019
|
+
seedMutes(state, spec, entity);
|
|
12020
|
+
mounted.live.set(entry.key, view);
|
|
12021
|
+
state.byEntity.set(entity, view);
|
|
12022
|
+
state.membershipVersion += 1;
|
|
12023
|
+
playEnter$1(pctx, spec, view, entry);
|
|
12024
|
+
}
|
|
12025
|
+
/**
|
|
12026
|
+
* A key that is new while a warm window holds its view: the held view is shown instead of a spawn,
|
|
12027
|
+
* the same entity, built already. An item with the content of the warm one runs no `view` and
|
|
12028
|
+
* writes nothing; another one has the difference written directly, with no `change` hook. Then it
|
|
12029
|
+
* comes as a spawned view does (`playEnter`). A `view` that throws leaves the window held, as an
|
|
12030
|
+
* enter that throws spawns nothing.
|
|
12031
|
+
*
|
|
12032
|
+
* @param pctx - Domain context of the projection module.
|
|
12033
|
+
* @param spec - The projection spec.
|
|
12034
|
+
* @param mounted - The mounted projection.
|
|
12035
|
+
* @param record - The warm record that holds the view of the key.
|
|
12036
|
+
* @param entry - The key, its item, the peers, the mode and the used hints.
|
|
12037
|
+
* @param entry.key - The model key.
|
|
12038
|
+
* @param entry.item - The model item.
|
|
12039
|
+
* @param entry.peers - The new and the old items.
|
|
12040
|
+
* @param entry.direct - Whether the reconcile writes without motions.
|
|
12041
|
+
* @param entry.used - The hints that reached an entry.
|
|
12042
|
+
*/
|
|
12043
|
+
function adoptEntry(pctx, spec, mounted, record, entry) {
|
|
12044
|
+
const view = record.view;
|
|
12045
|
+
const next = sameItem(record.item, entry.item) ? void 0 : collectView(pctx, spec, entry.item);
|
|
12046
|
+
showHeld(pctx, mounted, record, entry.direct ? "mount" : "change");
|
|
12047
|
+
if (next === void 0) view.item = entry.item;
|
|
12048
|
+
else writeDifference(pctx, view, next, entry.item);
|
|
12049
|
+
playEnter$1(pctx, spec, view, entry);
|
|
12050
|
+
}
|
|
12051
|
+
/**
|
|
11439
12052
|
* A key whose item is another object than before: structural changes are written, a changed
|
|
11440
12053
|
* component with a hook is handed to it and one without is written directly, then the retarget
|
|
11441
12054
|
* settles what is loose. A view no motion moves after that gets its pending `lift(false)`.
|
|
@@ -11545,9 +12158,11 @@ function reviveEntry(pctx, spec, mounted, view, entry) {
|
|
|
11545
12158
|
*/
|
|
11546
12159
|
function exitEntry(pctx, spec, mounted, view, entry) {
|
|
11547
12160
|
const hook = spec.motion?.exit;
|
|
12161
|
+
const state = pctx.ctx.state.projection;
|
|
11548
12162
|
mounted.live.delete(view.key);
|
|
11549
|
-
|
|
12163
|
+
state.membershipVersion += 1;
|
|
11550
12164
|
view.cause = entry.direct ? "mount" : "change";
|
|
12165
|
+
coolShown(state, spec.name, view);
|
|
11551
12166
|
if (entry.direct || hook === void 0) {
|
|
11552
12167
|
despawnView(pctx, mounted, view);
|
|
11553
12168
|
return;
|
|
@@ -11590,7 +12205,7 @@ function settleUnchanged(pctx, spec, view, entry) {
|
|
|
11590
12205
|
}
|
|
11591
12206
|
/**
|
|
11592
12207
|
* Routes one key of the new state to the entry it belongs to: a live view changes, a queued view
|
|
11593
|
-
* revives, an unknown key enters.
|
|
12208
|
+
* revives, a key a warm window holds is shown, an unknown key enters.
|
|
11594
12209
|
*
|
|
11595
12210
|
* @param pctx - Domain context of the projection module.
|
|
11596
12211
|
* @param spec - The projection spec.
|
|
@@ -11616,7 +12231,9 @@ function applyEntry(pctx, spec, mounted, entry, counts) {
|
|
|
11616
12231
|
}
|
|
11617
12232
|
const queued = mounted.queue.find((view) => view.key === entry.key);
|
|
11618
12233
|
if (queued === void 0) {
|
|
11619
|
-
|
|
12234
|
+
const held = heldFor(pctx.ctx.state.projection, spec.name, entry.key);
|
|
12235
|
+
if (held === void 0) enterEntry(pctx, spec, mounted, entry);
|
|
12236
|
+
else adoptEntry(pctx, spec, mounted, held, entry);
|
|
11620
12237
|
counts.entered += 1;
|
|
11621
12238
|
return;
|
|
11622
12239
|
}
|
|
@@ -11984,7 +12601,8 @@ function drawsAlike(before, after, spec) {
|
|
|
11984
12601
|
}
|
|
11985
12602
|
/**
|
|
11986
12603
|
* Unmounts projections: every motion of their views is finished, and the live views and the
|
|
11987
|
-
* despawn queue are despawned in the same call
|
|
12604
|
+
* despawn queue are despawned in the same call, and so is the view a warm window holds hidden.
|
|
12605
|
+
* An unknown or unmounted name is skipped.
|
|
11988
12606
|
*
|
|
11989
12607
|
* @param pctx - Domain context of the projection module.
|
|
11990
12608
|
* @param names - Names of the projections to unmount.
|
|
@@ -11995,6 +12613,7 @@ function unmountNames(pctx, names) {
|
|
|
11995
12613
|
const mounted = state.mounted.get(name);
|
|
11996
12614
|
if (mounted === void 0) continue;
|
|
11997
12615
|
clearMounted(pctx, mounted);
|
|
12616
|
+
forgetWarm(pctx, name);
|
|
11998
12617
|
state.mounted.delete(name);
|
|
11999
12618
|
}
|
|
12000
12619
|
}
|
|
@@ -12052,7 +12671,8 @@ function mountNames(pctx, names, owner) {
|
|
|
12052
12671
|
/**
|
|
12053
12672
|
* Gives every projection of a list its place under the current layer list: a missing one gets an
|
|
12054
12673
|
* empty record at the `Order` of its place, a kept one mounted under another list takes its new
|
|
12055
|
-
* place (`placeMounted`). A screen root draws at its place in the list
|
|
12674
|
+
* place (`placeMounted`), its held warm view too. A screen root draws at its place in the list
|
|
12675
|
+
* (spec 16 U1.6). A projection that declares `warm` gets its warm record, cold, unless it has one.
|
|
12056
12676
|
*
|
|
12057
12677
|
* @param pctx - Domain context of the projection module.
|
|
12058
12678
|
* @param names - The projection list of the scene.
|
|
@@ -12064,7 +12684,9 @@ function placeNames(pctx, names, owner) {
|
|
|
12064
12684
|
const order = orderIn(names, name);
|
|
12065
12685
|
const mounted = state.mounted.get(name);
|
|
12066
12686
|
if (mounted === void 0) state.mounted.set(name, emptyMounted(owner, order, state.layers));
|
|
12067
|
-
else if (mounted.layers !== state.layers) placeMounted(pctx, mounted, order);
|
|
12687
|
+
else if (mounted.layers !== state.layers) placeMounted(pctx, mounted, order, state.warm.get(name)?.view);
|
|
12688
|
+
const spec = state.specs.get(name);
|
|
12689
|
+
if (spec !== void 0) ensureWarm(state, spec);
|
|
12068
12690
|
}
|
|
12069
12691
|
}
|
|
12070
12692
|
/**
|
|
@@ -12092,20 +12714,17 @@ function reconcileFresh(pctx, names) {
|
|
|
12092
12714
|
* @param names - The projection list of the coming scene.
|
|
12093
12715
|
* @param layers - The layer list of the coming scene.
|
|
12094
12716
|
* @param owner - Who owns the entities of the projections it mounts.
|
|
12095
|
-
* @param
|
|
12096
|
-
* @
|
|
12097
|
-
* @param timing.now - The game clock at the build start.
|
|
12098
|
-
* @returns The table, its frame starting at the build start.
|
|
12717
|
+
* @param budgetMs - Milliseconds per frame the building work may take.
|
|
12718
|
+
* @returns The table.
|
|
12099
12719
|
*/
|
|
12100
|
-
function emptyBuilding(names, layers, owner,
|
|
12720
|
+
function emptyBuilding(names, layers, owner, budgetMs) {
|
|
12101
12721
|
return {
|
|
12102
12722
|
names: [...names],
|
|
12103
12723
|
layers,
|
|
12104
12724
|
owner,
|
|
12105
12725
|
mounted: /* @__PURE__ */ new Map(),
|
|
12106
12726
|
entities: /* @__PURE__ */ new Set(),
|
|
12107
|
-
|
|
12108
|
-
budgetMs: timing.budgetMs
|
|
12727
|
+
budgetMs
|
|
12109
12728
|
};
|
|
12110
12729
|
}
|
|
12111
12730
|
/**
|
|
@@ -12147,6 +12766,8 @@ function handBack(pctx, building) {
|
|
|
12147
12766
|
* a mount checks it, against the coming layers; a projection the current scene mounts and the
|
|
12148
12767
|
* coming one declares alike stays as it is, and every other one is mounted aside, direct. A view
|
|
12149
12768
|
* that throws leaves nothing behind: what the build spawned is despawned and the throw goes on.
|
|
12769
|
+
* The warm window in work is dropped first, or its parts would hold the build's readiness; a ready
|
|
12770
|
+
* one stays held, and no warm work runs until the build ends. The frame budget counts from now.
|
|
12150
12771
|
*
|
|
12151
12772
|
* @param pctx - Domain context of the projection module.
|
|
12152
12773
|
* @param names - The projection list of the coming scene.
|
|
@@ -12162,10 +12783,9 @@ function buildNames(pctx, names, owner, layers, budgetMs) {
|
|
|
12162
12783
|
if (state.building !== void 0) throw new Error("[game] A scene is already being built.\n Commit or discard the running build before the next one starts.");
|
|
12163
12784
|
const { fresh, again } = sortMount(pctx, names, layers);
|
|
12164
12785
|
if (again.length > 0) return false;
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
});
|
|
12786
|
+
discardActive(pctx);
|
|
12787
|
+
state.frameStart = pctx.ctx.deps.clock.now();
|
|
12788
|
+
const building = emptyBuilding(names, layers, owner, budgetMs);
|
|
12169
12789
|
for (const spec of fresh) building.mounted.set(spec.name, emptyMounted(owner, orderIn(names, spec.name), layers));
|
|
12170
12790
|
state.building = building;
|
|
12171
12791
|
if (fresh.length === 0) return true;
|
|
@@ -12330,6 +12950,8 @@ function createProjectionApi(ctx, deps) {
|
|
|
12330
12950
|
* Reconciles what is dirty. The cause table decides play or direct, whether every live view
|
|
12331
12951
|
* and every element with a recorded rest pose is brought to it (a restore and a load do that),
|
|
12332
12952
|
* and whether an unchanged view that stands off its rest pose is settled (a rollback does).
|
|
12953
|
+
* A restore, a load and a forced rerun drop the views warm windows hold hidden first: they
|
|
12954
|
+
* replace the state or run `view` anew. After a reconcile the warm step looks at its records.
|
|
12333
12955
|
*/
|
|
12334
12956
|
const reconcileIfDirty = () => {
|
|
12335
12957
|
const dirty = state.dirty;
|
|
@@ -12338,12 +12960,14 @@ function createProjectionApi(ctx, deps) {
|
|
|
12338
12960
|
const direct = dirty.force || dirty.causes.some((cause) => isDirectCause(cause)) || deps.ecs.mode() !== "live";
|
|
12339
12961
|
const converge = dirty.causes.some((cause) => isConvergeCause(cause));
|
|
12340
12962
|
const settle = dirty.causes.includes("rollback");
|
|
12963
|
+
if (converge || dirty.force) discardHeld(pctx);
|
|
12341
12964
|
reconcile(pctx, {
|
|
12342
12965
|
direct,
|
|
12343
12966
|
force: dirty.force,
|
|
12344
12967
|
converge,
|
|
12345
12968
|
settle
|
|
12346
12969
|
});
|
|
12970
|
+
if (state.warmList.length > 0) state.warmStale = true;
|
|
12347
12971
|
}
|
|
12348
12972
|
state.hints.length = 0;
|
|
12349
12973
|
};
|
|
@@ -12375,7 +12999,10 @@ function createProjectionApi(ctx, deps) {
|
|
|
12375
12999
|
const seed = learnSeed(state, spec);
|
|
12376
13000
|
state.specs.set(spec.name, spec);
|
|
12377
13001
|
reseedViews(state, spec.name, from, seed);
|
|
12378
|
-
if (mounted)
|
|
13002
|
+
if (!mounted) return;
|
|
13003
|
+
if (spec.warm === void 0) forgetWarm(pctx, spec.name);
|
|
13004
|
+
else ensureWarm(state, spec);
|
|
13005
|
+
forceRerun();
|
|
12379
13006
|
},
|
|
12380
13007
|
setLayers: (list) => {
|
|
12381
13008
|
state.layers = Object.freeze(list.map((layer) => ({ ...layer })));
|
|
@@ -12431,7 +13058,10 @@ function createProjectionApi(ctx, deps) {
|
|
|
12431
13058
|
membershipVersion: () => state.membershipVersion,
|
|
12432
13059
|
causeOf: (entity) => state.byEntity.get(entity)?.cause ?? state.leaving.get(entity),
|
|
12433
13060
|
motionsOf: (entity) => runningComponents(state.tracks, entity),
|
|
12434
|
-
entityOf: (projection, key) =>
|
|
13061
|
+
entityOf: (projection, key) => {
|
|
13062
|
+
const entity = state.mounted.get(projection)?.live.get(key)?.entity ?? state.keys.get(projection)?.get(key);
|
|
13063
|
+
return entity === void 0 || state.building?.entities.has(entity) === true || state.warmHeld.has(entity) ? void 0 : entity;
|
|
13064
|
+
},
|
|
12435
13065
|
entitiesOf: (name) => {
|
|
12436
13066
|
const mounted = state.mounted.get(name) ?? state.building?.mounted.get(name);
|
|
12437
13067
|
return mounted === void 0 ? [] : liveEntities(mounted);
|
|
@@ -12465,6 +13095,7 @@ function createProjectionApi(ctx, deps) {
|
|
|
12465
13095
|
key
|
|
12466
13096
|
});
|
|
12467
13097
|
state.sweptDespawns = -1;
|
|
13098
|
+
holdRegistered(state, projection, entity);
|
|
12468
13099
|
return () => {
|
|
12469
13100
|
if (byKey.get(key) === entity) byKey.delete(key);
|
|
12470
13101
|
if (state.keysByEntity.get(entity)?.key === key) state.keysByEntity.delete(entity);
|
|
@@ -12492,11 +13123,11 @@ function createProjectionApi(ctx, deps) {
|
|
|
12492
13123
|
discardBuild(pctx);
|
|
12493
13124
|
},
|
|
12494
13125
|
left: () => {
|
|
12495
|
-
const
|
|
12496
|
-
if (
|
|
12497
|
-
return
|
|
13126
|
+
const budget = frameBudget(state);
|
|
13127
|
+
if (budget === void 0) return Number.POSITIVE_INFINITY;
|
|
13128
|
+
return budget - (ctx.deps.clock.now() - state.frameStart);
|
|
12498
13129
|
},
|
|
12499
|
-
isBuilding: (entity) => state.building?.entities.has(entity) === true,
|
|
13130
|
+
isBuilding: (entity) => state.building?.entities.has(entity) === true || state.warmHeld.has(entity),
|
|
12500
13131
|
onBuild: (check) => {
|
|
12501
13132
|
state.buildChecks.push(check);
|
|
12502
13133
|
return () => {
|
|
@@ -12505,11 +13136,15 @@ function createProjectionApi(ctx, deps) {
|
|
|
12505
13136
|
};
|
|
12506
13137
|
},
|
|
12507
13138
|
adopt: (entity) => {
|
|
12508
|
-
state.building
|
|
13139
|
+
const building = state.building;
|
|
13140
|
+
if (building === void 0) adoptWarm(state, entity);
|
|
13141
|
+
else building.entities.add(entity);
|
|
12509
13142
|
},
|
|
12510
13143
|
startFrame: (now) => {
|
|
12511
|
-
|
|
12512
|
-
|
|
13144
|
+
state.frameStart = now;
|
|
13145
|
+
},
|
|
13146
|
+
stepWarm: () => {
|
|
13147
|
+
stepWarm(pctx);
|
|
12513
13148
|
},
|
|
12514
13149
|
markDirty: (roots, cause) => {
|
|
12515
13150
|
const dirty = state.dirty ?? emptyDirty();
|
|
@@ -12532,6 +13167,7 @@ function createProjectionApi(ctx, deps) {
|
|
|
12532
13167
|
if (state.sweptDespawns !== despawns) {
|
|
12533
13168
|
state.sweptDespawns = despawns;
|
|
12534
13169
|
forgetDeadElements(pctx);
|
|
13170
|
+
forgetDeadHeld(pctx);
|
|
12535
13171
|
}
|
|
12536
13172
|
if (state.owedLoops > 0) startOwedLoops(pctx);
|
|
12537
13173
|
},
|
|
@@ -12546,10 +13182,13 @@ function createProjectionApi(ctx, deps) {
|
|
|
12546
13182
|
ownerLeft: (owner) => {
|
|
12547
13183
|
if (owner.kind !== "projection") return;
|
|
12548
13184
|
const mounted = state.mounted.get(owner.name);
|
|
13185
|
+
const warm = state.warm.get(owner.name);
|
|
12549
13186
|
if (mounted !== void 0) clearMounted(pctx, mounted);
|
|
13187
|
+
if (warm !== void 0) discardWarm(pctx, warm);
|
|
12550
13188
|
},
|
|
12551
13189
|
clear: () => {
|
|
12552
13190
|
discardBuild(pctx);
|
|
13191
|
+
clearWarm(pctx);
|
|
12553
13192
|
for (const mounted of [...state.mounted.values()]) clearMounted(pctx, mounted);
|
|
12554
13193
|
state.mounted.clear();
|
|
12555
13194
|
state.specs.clear();
|
|
@@ -12837,9 +13476,19 @@ function emptyWeakMap$2() {
|
|
|
12837
13476
|
return /* @__PURE__ */ new WeakMap();
|
|
12838
13477
|
}
|
|
12839
13478
|
/**
|
|
13479
|
+
* Creates an empty set. It lives in its own non-exported function because lint rule L5 refuses a
|
|
13480
|
+
* collection built inside an exported declaration.
|
|
13481
|
+
*
|
|
13482
|
+
* @returns An empty set.
|
|
13483
|
+
*/
|
|
13484
|
+
function emptySet$8() {
|
|
13485
|
+
return /* @__PURE__ */ new Set();
|
|
13486
|
+
}
|
|
13487
|
+
/**
|
|
12840
13488
|
* Creates the initial projection state: nothing registered, nothing mounted, no layer list, no
|
|
12841
13489
|
* running track and no driver, so every motion is instant until `anim` installs one. No build
|
|
12842
|
-
* runs: `building` is absent.
|
|
13490
|
+
* runs: `building` is absent. No warm window is held, and none is being built: `warmActive` is
|
|
13491
|
+
* absent. The warm budget starts at two thirds of a 60 Hz frame until a step reads the rate.
|
|
12843
13492
|
*
|
|
12844
13493
|
* @returns The projection branch of the plugin state.
|
|
12845
13494
|
*/
|
|
@@ -12867,7 +13516,13 @@ function createProjectionState() {
|
|
|
12867
13516
|
moving: false,
|
|
12868
13517
|
owedLoops: 0,
|
|
12869
13518
|
sweptDespawns: 0,
|
|
12870
|
-
buildChecks: []
|
|
13519
|
+
buildChecks: [],
|
|
13520
|
+
frameStart: 0,
|
|
13521
|
+
warm: emptyMap$9(),
|
|
13522
|
+
warmList: [],
|
|
13523
|
+
warmHeld: emptySet$8(),
|
|
13524
|
+
warmStale: false,
|
|
13525
|
+
warmBudgetMs: FALLBACK_WARM_MS
|
|
12871
13526
|
};
|
|
12872
13527
|
}
|
|
12873
13528
|
//#endregion
|
|
@@ -15474,7 +16129,7 @@ function sourceBytes(source) {
|
|
|
15474
16129
|
* isTarget({ uploadMethodId: "unknown", resource: null }); // true
|
|
15475
16130
|
* ```
|
|
15476
16131
|
*/
|
|
15477
|
-
function isTarget$
|
|
16132
|
+
function isTarget$2(source) {
|
|
15478
16133
|
return source.uploadMethodId === "unknown" && (source.resource === null || source.resource === void 0);
|
|
15479
16134
|
}
|
|
15480
16135
|
/**
|
|
@@ -15509,7 +16164,7 @@ function textureUsage(app, kept) {
|
|
|
15509
16164
|
usage.count += 1;
|
|
15510
16165
|
usage.bytes += bytes;
|
|
15511
16166
|
if (kept.has(source)) usage.kept += bytes;
|
|
15512
|
-
else if (isTarget$
|
|
16167
|
+
else if (isTarget$2(source)) usage.targets += bytes;
|
|
15513
16168
|
else usage.art += bytes;
|
|
15514
16169
|
}
|
|
15515
16170
|
return usage;
|
|
@@ -25696,6 +26351,8 @@ function destroyPools(state) {
|
|
|
25696
26351
|
}
|
|
25697
26352
|
//#endregion
|
|
25698
26353
|
//#region src/plugins/renderer/sync/held.ts
|
|
26354
|
+
/** The version of a held list a view left: `membershipVersion()` never answers it, so the next pass scans the list. */
|
|
26355
|
+
const RESCAN = -1;
|
|
25699
26356
|
/**
|
|
25700
26357
|
* Tells whether a view is held: its entity belongs to the running build, and it has no parent or its parent is live.
|
|
25701
26358
|
* A building view under a building parent hangs in the parent's tree, which is held as a whole. One set lookup for a
|
|
@@ -25712,7 +26369,9 @@ function holds(sctx, entity, parent) {
|
|
|
25712
26369
|
}
|
|
25713
26370
|
/**
|
|
25714
26371
|
* Holds a view of the build: out of the tree, no orphan, listed once in `heldViews`. A top keeps the name of the layer
|
|
25715
|
-
* it will hang in, which the coming scene may declare only after the commit.
|
|
26372
|
+
* it will hang in, which the coming scene may declare only after the commit. The first top of an empty list stores
|
|
26373
|
+
* world's membership version: it is building now, so only a later move can release it, and the pass is not woken for
|
|
26374
|
+
* a scan that would find nothing.
|
|
25716
26375
|
*
|
|
25717
26376
|
* @param sctx - Domain context of the sync module.
|
|
25718
26377
|
* @param entity - The entity.
|
|
@@ -25726,13 +26385,25 @@ function holdView(sctx, entity, view, layer) {
|
|
|
25726
26385
|
view.layer = layer;
|
|
25727
26386
|
detach$1(view.wrapper ?? view.object);
|
|
25728
26387
|
if (view.held) return;
|
|
26388
|
+
if (held.count === 0) held.version = sctx.ctx.deps.world.projection.membershipVersion();
|
|
25729
26389
|
view.held = true;
|
|
25730
26390
|
held.entities[held.count] = entity;
|
|
25731
26391
|
held.count += 1;
|
|
25732
26392
|
}
|
|
25733
26393
|
/**
|
|
25734
|
-
*
|
|
25735
|
-
*
|
|
26394
|
+
* Notes that a view leaves (its entity despawned, or its view replaced): a held one has the next pass scan the list
|
|
26395
|
+
* and drop its slot, also when world's membership version did not move (a discard of a build whose entities only
|
|
26396
|
+
* `adopt` marked). One field read for a view that is not held.
|
|
26397
|
+
*
|
|
26398
|
+
* @param state - The sync branch of the plugin state.
|
|
26399
|
+
* @param view - The view that leaves.
|
|
26400
|
+
*/
|
|
26401
|
+
function leaveHeld(state, view) {
|
|
26402
|
+
if (view.held) state.heldViews.version = RESCAN;
|
|
26403
|
+
}
|
|
26404
|
+
/**
|
|
26405
|
+
* Forgets the queues of a scene build and the held windows with the tree, on a device loss, a rebuild or a stop: the
|
|
26406
|
+
* views they name are gone, and a rebuild holds every building view again. Works on the state alone.
|
|
25736
26407
|
*
|
|
25737
26408
|
* @param state - The sync branch of the plugin state.
|
|
25738
26409
|
*/
|
|
@@ -27332,7 +28003,7 @@ const RETAKE_STREAK = 3;
|
|
|
27332
28003
|
/** Frames in a row with no mark in it before a live range is kept as a picture again (spec 23's `CALM_AFTER`). */
|
|
27333
28004
|
const CALM_FRAMES = 8;
|
|
27334
28005
|
/** How deep a walk up the tree goes. */
|
|
27335
|
-
const MAX_DEPTH$
|
|
28006
|
+
const MAX_DEPTH$7 = 32;
|
|
27336
28007
|
/** CSS px a view may fall short of the viewport frame and still cover it: the reference frame rounds by a fraction. */
|
|
27337
28008
|
const COVER_SLACK = 1;
|
|
27338
28009
|
/** The whole-frame reasons after which a kept picture is taken again: the screen changed whole. */
|
|
@@ -27496,7 +28167,7 @@ function sameList$1(left, right) {
|
|
|
27496
28167
|
*/
|
|
27497
28168
|
function inRange(set, node, root) {
|
|
27498
28169
|
let current = node;
|
|
27499
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
28170
|
+
for (let depth = 0; depth < MAX_DEPTH$7 && current !== null && current !== root; depth += 1) {
|
|
27500
28171
|
if (set.has(current)) return true;
|
|
27501
28172
|
current = current.parent;
|
|
27502
28173
|
}
|
|
@@ -29467,6 +30138,7 @@ function dropView(sctx, entity) {
|
|
|
29467
30138
|
if (view === void 0) return;
|
|
29468
30139
|
markView(sctx, entity);
|
|
29469
30140
|
noteLeaving(state, view);
|
|
30141
|
+
leaveHeld(state, view);
|
|
29470
30142
|
sctx.deps.kept.forget(entity);
|
|
29471
30143
|
const host = view.clipped ?? view.wrapper;
|
|
29472
30144
|
if (host !== void 0) detachChildren(sctx, entity, host);
|
|
@@ -29868,7 +30540,7 @@ function countApply(sinks, filter, input) {
|
|
|
29868
30540
|
* @param source - The source.
|
|
29869
30541
|
* @returns True for a render target.
|
|
29870
30542
|
*/
|
|
29871
|
-
function isTarget(source) {
|
|
30543
|
+
function isTarget$1(source) {
|
|
29872
30544
|
return source.uploadMethodId === "unknown";
|
|
29873
30545
|
}
|
|
29874
30546
|
/**
|
|
@@ -30069,7 +30741,7 @@ function createCountingClasses(pixi, sinks, batcherPipe = pixi.BatcherPipe) {
|
|
|
30069
30741
|
* @returns The GPU texture.
|
|
30070
30742
|
*/
|
|
30071
30743
|
initSource(source) {
|
|
30072
|
-
const made = isTarget(source) && !this.targets.has(source);
|
|
30744
|
+
const made = isTarget$1(source) && !this.targets.has(source);
|
|
30073
30745
|
const texture = super.initSource(source);
|
|
30074
30746
|
if (made) {
|
|
30075
30747
|
this.targets.add(source);
|
|
@@ -30202,9 +30874,9 @@ function installPassCounting(pixi, sinks) {
|
|
|
30202
30874
|
//#endregion
|
|
30203
30875
|
//#region src/plugins/renderer/sync/hit-test.ts
|
|
30204
30876
|
/** How deep a parent chain or a container tree is followed. */
|
|
30205
|
-
const MAX_DEPTH$
|
|
30877
|
+
const MAX_DEPTH$6 = 32;
|
|
30206
30878
|
/** Below this effective alpha a view is treated as not there. */
|
|
30207
|
-
const MIN_ALPHA = .01;
|
|
30879
|
+
const MIN_ALPHA$1 = .01;
|
|
30208
30880
|
/**
|
|
30209
30881
|
* Brings a reference point into the local space of an entity: its root pose undone, the pivot
|
|
30210
30882
|
* added back. The point is posed as a child of the entity, so the pose helpers do the walk.
|
|
@@ -30284,7 +30956,7 @@ function clipBoxOf(sctx, entity) {
|
|
|
30284
30956
|
function clippedOut(sctx, entity, x, y) {
|
|
30285
30957
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
30286
30958
|
let current = parentOf$1(ecs, entity);
|
|
30287
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
30959
|
+
for (let depth = 0; depth < MAX_DEPTH$6 && current !== 0; depth += 1) {
|
|
30288
30960
|
const box = clipBoxOf(sctx, current);
|
|
30289
30961
|
if (box !== void 0 && !inBox(box, localPoint(sctx, current, x, y))) return true;
|
|
30290
30962
|
current = parentOf$1(ecs, current);
|
|
@@ -30303,7 +30975,7 @@ function clippedOut(sctx, entity, x, y) {
|
|
|
30303
30975
|
function effectiveAlpha(object, root, off) {
|
|
30304
30976
|
let alpha = 1;
|
|
30305
30977
|
let current = object;
|
|
30306
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
30978
|
+
for (let depth = 0; depth < MAX_DEPTH$6 && current !== void 0; depth += 1) {
|
|
30307
30979
|
if (current === root) return alpha;
|
|
30308
30980
|
if (!current.visible || off?.has(current) === true) return 0;
|
|
30309
30981
|
alpha *= current.alpha;
|
|
@@ -30321,7 +30993,7 @@ function effectiveAlpha(object, root, off) {
|
|
|
30321
30993
|
* @returns True when the object is drawn.
|
|
30322
30994
|
*/
|
|
30323
30995
|
function isShown$1(object, root, off) {
|
|
30324
|
-
return effectiveAlpha(object, root, off) > MIN_ALPHA;
|
|
30996
|
+
return effectiveAlpha(object, root, off) > MIN_ALPHA$1;
|
|
30325
30997
|
}
|
|
30326
30998
|
/**
|
|
30327
30999
|
* Collects the children of a container in draw order from the top: by `zIndex` descending, then
|
|
@@ -30333,7 +31005,7 @@ function isShown$1(object, root, off) {
|
|
|
30333
31005
|
* @returns The same array.
|
|
30334
31006
|
*/
|
|
30335
31007
|
function topFirst(container, out, depth = 0) {
|
|
30336
|
-
if (depth >= MAX_DEPTH$
|
|
31008
|
+
if (depth >= MAX_DEPTH$6) return out;
|
|
30337
31009
|
const ordered = container.children.toSorted((left, right) => left.zIndex - right.zIndex);
|
|
30338
31010
|
for (let index = ordered.length - 1; index >= 0; index -= 1) {
|
|
30339
31011
|
const child = ordered[index];
|
|
@@ -30422,7 +31094,7 @@ function hitAll(sctx, x, y) {
|
|
|
30422
31094
|
* hit test walks, so a box the doors report is the box a click reaches.
|
|
30423
31095
|
*/
|
|
30424
31096
|
/** How deep a parent chain is followed; deeper is treated as a loop. */
|
|
30425
|
-
const MAX_DEPTH$
|
|
31097
|
+
const MAX_DEPTH$5 = 32;
|
|
30426
31098
|
/**
|
|
30427
31099
|
* The four corners of a box, clockwise from the top-left one.
|
|
30428
31100
|
*
|
|
@@ -30516,7 +31188,7 @@ function boundsOf(sctx, entity) {
|
|
|
30516
31188
|
function layerOf$1(sctx, entity) {
|
|
30517
31189
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
30518
31190
|
let top = entity;
|
|
30519
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
31191
|
+
for (let depth = 0; depth < MAX_DEPTH$5; depth += 1) {
|
|
30520
31192
|
const parent = parentOf$1(ecs, top);
|
|
30521
31193
|
if (parent === 0) break;
|
|
30522
31194
|
top = parent;
|
|
@@ -30528,7 +31200,8 @@ function layerOf$1(sctx, entity) {
|
|
|
30528
31200
|
/** Views made between two reads of the clock: a read costs more than a small view. */
|
|
30529
31201
|
const CLOCK_EVERY$1 = 8;
|
|
30530
31202
|
/**
|
|
30531
|
-
* Tells whether a scene is being built: `left()` answers a finite number only while a build runs
|
|
31203
|
+
* Tells whether a scene or a warm window is being built: `left()` answers a finite number only while a build runs
|
|
31204
|
+
* or a window is in work. One field read when nothing is built.
|
|
30532
31205
|
*
|
|
30533
31206
|
* @param sctx - Domain context of the sync module.
|
|
30534
31207
|
* @returns True while a build runs.
|
|
@@ -30574,6 +31247,18 @@ function dropAside(state, entity) {
|
|
|
30574
31247
|
if (state.aside.count > 0) state.aside.waiting.delete(entity);
|
|
30575
31248
|
}
|
|
30576
31249
|
/**
|
|
31250
|
+
* Hands a queued entity whose build ended before its view was made to the live pass: it leaves the waiting set, and
|
|
31251
|
+
* joins `added` while it is alive.
|
|
31252
|
+
*
|
|
31253
|
+
* @param sctx - Domain context of the sync module.
|
|
31254
|
+
* @param entity - The entity, no longer building.
|
|
31255
|
+
*/
|
|
31256
|
+
function toLivePass(sctx, entity) {
|
|
31257
|
+
const state = sctx.ctx.state.sync;
|
|
31258
|
+
state.aside.waiting.delete(entity);
|
|
31259
|
+
if (sctx.ctx.deps.world.ecs.ownerOf(entity) !== void 0) state.added.add(entity);
|
|
31260
|
+
}
|
|
31261
|
+
/**
|
|
30577
31262
|
* Makes the view of one queued entity, its queued parent first (spec 16 U2.3: a child made before its parent finds no
|
|
30578
31263
|
* parent view and is detached for good). The entity leaves the waiting set before its parent is made, so a cycle of
|
|
30579
31264
|
* parents ends. A throw costs that entity.
|
|
@@ -30608,7 +31293,7 @@ function makeParentFirst(sctx, entity, report) {
|
|
|
30608
31293
|
function makeAside(sctx, report) {
|
|
30609
31294
|
const state = sctx.ctx.state.sync;
|
|
30610
31295
|
const { aside } = state;
|
|
30611
|
-
const
|
|
31296
|
+
const projection = sctx.ctx.deps.world.projection;
|
|
30612
31297
|
const version = state.passesVersion;
|
|
30613
31298
|
let made = 0;
|
|
30614
31299
|
let check = 1;
|
|
@@ -30617,8 +31302,7 @@ function makeAside(sctx, report) {
|
|
|
30617
31302
|
aside.head += 1;
|
|
30618
31303
|
if (!aside.waiting.has(entity)) continue;
|
|
30619
31304
|
if (!projection.isBuilding(entity)) {
|
|
30620
|
-
|
|
30621
|
-
if (ecs.ownerOf(entity) !== void 0) state.added.add(entity);
|
|
31305
|
+
toLivePass(sctx, entity);
|
|
30622
31306
|
continue;
|
|
30623
31307
|
}
|
|
30624
31308
|
made += makeParentFirst(sctx, entity, report);
|
|
@@ -30647,7 +31331,8 @@ function underStage(node, stage) {
|
|
|
30647
31331
|
}
|
|
30648
31332
|
/**
|
|
30649
31333
|
* The dev check of a build frame: no view of a building entity hangs under the stage, or it would be drawn and hit
|
|
30650
|
-
* before the commit. Named once per build, as `renderer:building-drawn` with the entities. Dev and agent builds only
|
|
31334
|
+
* before the commit. Named once per build, as `renderer:building-drawn` with the entities. Dev and agent builds only,
|
|
31335
|
+
* in frames with aside work: it walks every view and makes a list, so a frame of resting warm windows never runs it.
|
|
30651
31336
|
*
|
|
30652
31337
|
* @param sctx - Domain context of the sync module.
|
|
30653
31338
|
*/
|
|
@@ -30664,7 +31349,9 @@ function checkDrawn(sctx) {
|
|
|
30664
31349
|
}
|
|
30665
31350
|
/**
|
|
30666
31351
|
* The building step of a frame, after the live pass: the views of the aside queue are made under the budget, and while
|
|
30667
|
-
* views wait to be made or
|
|
31352
|
+
* views wait to be made, or held views wait for a build that runs, the next frame is asked for. Held tops of warm
|
|
31353
|
+
* windows at rest wait for no frame: the pass attaches them when world's membership version moves. A few field reads
|
|
31354
|
+
* and no allocation with no build.
|
|
30668
31355
|
*
|
|
30669
31356
|
* @param sctx - Domain context of the sync module.
|
|
30670
31357
|
* @param report - Logs a throw of one entity's work.
|
|
@@ -30673,28 +31360,56 @@ function stepAside(sctx, report) {
|
|
|
30673
31360
|
const state = sctx.ctx.state.sync;
|
|
30674
31361
|
const { aside } = state;
|
|
30675
31362
|
if (aside.made !== 0) aside.made = 0;
|
|
30676
|
-
if (aside.head >= aside.count && state.heldViews.count === 0) return;
|
|
31363
|
+
if (aside.head >= aside.count && (state.heldViews.count === 0 || !buildRuns(sctx))) return;
|
|
30677
31364
|
if (aside.head < aside.count) aside.made = makeAside(sctx, report);
|
|
30678
31365
|
sctx.deps.demand.request();
|
|
30679
31366
|
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__ || typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) checkDrawn(sctx);
|
|
30680
31367
|
}
|
|
30681
31368
|
/**
|
|
30682
|
-
* Tells whether held views wait for the pass that attaches them:
|
|
30683
|
-
*
|
|
30684
|
-
*
|
|
31369
|
+
* Tells whether held views may wait for the pass that attaches them: world's membership version moved since the list
|
|
31370
|
+
* was last scanned. A build ends only with such a move (a commit, a discard, the open of a warm window, a held view
|
|
31371
|
+
* dropped), so a list whose version stands holds building views only. Read by `still()`: two field reads.
|
|
30685
31372
|
*
|
|
30686
31373
|
* @param sctx - Domain context of the sync module.
|
|
30687
|
-
* @returns True when the pass has held views to
|
|
31374
|
+
* @returns True when the pass has held views to look at again.
|
|
30688
31375
|
*/
|
|
30689
31376
|
function heldWaiting(sctx) {
|
|
30690
31377
|
const held = sctx.ctx.state.sync.heldViews;
|
|
30691
|
-
return held.count > 0 &&
|
|
31378
|
+
return held.count > 0 && sctx.ctx.deps.world.projection.membershipVersion() !== held.version;
|
|
30692
31379
|
}
|
|
30693
31380
|
/**
|
|
30694
|
-
*
|
|
30695
|
-
*
|
|
30696
|
-
*
|
|
30697
|
-
*
|
|
31381
|
+
* Hands the live pass every queued entity whose build ended before its view was made: a scene build committed, or a
|
|
31382
|
+
* window opened, while views of it still waited aside. The pass that attaches the held top makes them next, parents
|
|
31383
|
+
* first, so the top never hangs on the stage without them. The entities still building stay queued and move to the
|
|
31384
|
+
* front, in their order, with no new array; a slot that waits no more (its entity left) is dropped. One set lookup
|
|
31385
|
+
* per slot, and only after world's membership version moved.
|
|
31386
|
+
*
|
|
31387
|
+
* @param sctx - Domain context of the sync module.
|
|
31388
|
+
*/
|
|
31389
|
+
function releaseAside(sctx) {
|
|
31390
|
+
const aside = sctx.ctx.state.sync.aside;
|
|
31391
|
+
const projection = sctx.ctx.deps.world.projection;
|
|
31392
|
+
let kept = 0;
|
|
31393
|
+
for (let index = aside.head; index < aside.count; index += 1) {
|
|
31394
|
+
const entity = aside.entities[index] ?? 0;
|
|
31395
|
+
if (!aside.waiting.has(entity)) continue;
|
|
31396
|
+
if (projection.isBuilding(entity)) {
|
|
31397
|
+
aside.entities[kept] = entity;
|
|
31398
|
+
kept += 1;
|
|
31399
|
+
} else toLivePass(sctx, entity);
|
|
31400
|
+
}
|
|
31401
|
+
aside.head = 0;
|
|
31402
|
+
aside.count = kept;
|
|
31403
|
+
}
|
|
31404
|
+
/**
|
|
31405
|
+
* The swap: once the membership version moved, every held top that is no longer building is attached in one block, in
|
|
31406
|
+
* the order it was made (parents first), and sorted by the rule of the layer list the pass has just applied: the tops
|
|
31407
|
+
* of a committed scene build, a warm window world shows. The tops still building (a window at rest, a scene still
|
|
31408
|
+
* being built) stay held and move to the front of the list, in their order, with no new array; a slot whose view went
|
|
31409
|
+
* (a discard, a view that left) or hangs elsewhere by now is dropped. The views of an ended build still queued aside
|
|
31410
|
+
* go to `added`, for this same pass: the scene or the window is whole in the frame it is attached. The version is
|
|
31411
|
+
* stored, so the next scan waits for its next move. Called by the pass right after `syncLayers`, before it builds
|
|
31412
|
+
* `added`.
|
|
30698
31413
|
*
|
|
30699
31414
|
* @param sctx - Domain context of the sync module.
|
|
30700
31415
|
*/
|
|
@@ -30702,16 +31417,25 @@ function attachHeld(sctx) {
|
|
|
30702
31417
|
if (!heldWaiting(sctx)) return;
|
|
30703
31418
|
const state = sctx.ctx.state.sync;
|
|
30704
31419
|
const held = state.heldViews;
|
|
31420
|
+
const projection = sctx.ctx.deps.world.projection;
|
|
31421
|
+
let kept = 0;
|
|
30705
31422
|
for (let index = 0; index < held.count; index += 1) {
|
|
30706
31423
|
const entity = held.entities[index] ?? 0;
|
|
30707
31424
|
const view = state.views.get(entity);
|
|
30708
31425
|
if (view === void 0 || !view.held) continue;
|
|
31426
|
+
if (projection.isBuilding(entity)) {
|
|
31427
|
+
held.entities[kept] = entity;
|
|
31428
|
+
kept += 1;
|
|
31429
|
+
continue;
|
|
31430
|
+
}
|
|
30709
31431
|
view.held = false;
|
|
30710
31432
|
attach$1(sctx, entity, view);
|
|
30711
31433
|
resort(sctx, entity, view);
|
|
30712
31434
|
}
|
|
30713
|
-
held.count =
|
|
30714
|
-
|
|
31435
|
+
if (kept !== held.count) held.reported = false;
|
|
31436
|
+
releaseAside(sctx);
|
|
31437
|
+
held.count = kept;
|
|
31438
|
+
held.version = projection.membershipVersion();
|
|
30715
31439
|
}
|
|
30716
31440
|
/**
|
|
30717
31441
|
* Tells whether an entity of a set belongs to the running build.
|
|
@@ -31158,7 +31882,7 @@ function stepParts(sctx) {
|
|
|
31158
31882
|
//#endregion
|
|
31159
31883
|
//#region src/plugins/renderer/sync/overlay.ts
|
|
31160
31884
|
/** How deep a `Parent` chain or a walk up the tree goes. */
|
|
31161
|
-
const MAX_DEPTH$
|
|
31885
|
+
const MAX_DEPTH$4 = 32;
|
|
31162
31886
|
/** The owner `ui` gives the entities it spawns: the only overlays honoured (O4.8). */
|
|
31163
31887
|
const UI_OWNER_NAME = "ui";
|
|
31164
31888
|
/**
|
|
@@ -31231,7 +31955,7 @@ function clampInto(sctx, entity, into, raw) {
|
|
|
31231
31955
|
function rootOf(sctx, entity) {
|
|
31232
31956
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
31233
31957
|
let current = entity;
|
|
31234
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
31958
|
+
for (let depth = 0; depth < MAX_DEPTH$4; depth += 1) {
|
|
31235
31959
|
const parent = parentOf$1(ecs, current);
|
|
31236
31960
|
if (parent === 0) return current;
|
|
31237
31961
|
current = parent;
|
|
@@ -31444,7 +32168,7 @@ function drawnAlpha(sctx, record) {
|
|
|
31444
32168
|
const alphaFilter = sctx.deps.host.pixi()?.AlphaFilter;
|
|
31445
32169
|
let alpha = 1;
|
|
31446
32170
|
let node = view.wrapper ?? view.object;
|
|
31447
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
32171
|
+
for (let depth = 0; depth < MAX_DEPTH$4 && node !== null; depth += 1) {
|
|
31448
32172
|
if (node === root) return alpha;
|
|
31449
32173
|
if (!node.visible) return 0;
|
|
31450
32174
|
const owner = state.viewOfTop.get(node);
|
|
@@ -32120,9 +32844,9 @@ function createSyncApi(ctx, deps) {
|
|
|
32120
32844
|
return viewless;
|
|
32121
32845
|
};
|
|
32122
32846
|
/**
|
|
32123
|
-
* The live half of a pass: removed, layers, the held views of a build that ended
|
|
32124
|
-
* invalidated. A despawned entity takes its filter slots with it, also when its view left in an
|
|
32125
|
-
* one keeps them for its next view.
|
|
32847
|
+
* The live half of a pass: removed, layers, the held views of a build that ended and its views still aside, added,
|
|
32848
|
+
* changed, orphans, invalidated. A despawned entity takes its filter slots with it, also when its view left in an
|
|
32849
|
+
* earlier pass; a live one keeps them for its next view.
|
|
32126
32850
|
*/
|
|
32127
32851
|
const livePass = () => {
|
|
32128
32852
|
state.passesVersion += 1;
|
|
@@ -33184,6 +33908,7 @@ function createSyncState(debug) {
|
|
|
33184
33908
|
heldViews: {
|
|
33185
33909
|
entities: [],
|
|
33186
33910
|
count: 0,
|
|
33911
|
+
version: 0,
|
|
33187
33912
|
reported: false
|
|
33188
33913
|
},
|
|
33189
33914
|
leave: {},
|
|
@@ -47163,7 +47888,7 @@ const EFFECTS_OWNER = Object.freeze({
|
|
|
47163
47888
|
name: "effects"
|
|
47164
47889
|
});
|
|
47165
47890
|
/** How deep a parent chain is followed, as `rootPoseOf` does; deeper is treated as a loop. */
|
|
47166
|
-
const MAX_DEPTH$
|
|
47891
|
+
const MAX_DEPTH$3 = 32;
|
|
47167
47892
|
/**
|
|
47168
47893
|
* The one dynamic set of an emitter container (P9): positions, frames, rotations and colours
|
|
47169
47894
|
* upload every frame; `uvs` stays static, because a frame is set at birth and the same `update()`
|
|
@@ -47206,7 +47931,7 @@ function bornFields(size) {
|
|
|
47206
47931
|
*/
|
|
47207
47932
|
function topOf(ecs, host) {
|
|
47208
47933
|
let top = host;
|
|
47209
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
47934
|
+
for (let depth = 0; depth < MAX_DEPTH$3; depth += 1) {
|
|
47210
47935
|
const parent = parentOf$1(ecs, top);
|
|
47211
47936
|
if (parent === 0) break;
|
|
47212
47937
|
top = parent;
|
|
@@ -49437,7 +50162,7 @@ const Pointer = /*#__PURE__*/ resource("Pointer", pointerDefaults);
|
|
|
49437
50162
|
* point: a view drawn over a scroll from another root keeps its press.
|
|
49438
50163
|
*/
|
|
49439
50164
|
/** How deep a `Parent` chain is followed; deeper is treated as a loop. */
|
|
49440
|
-
const MAX_DEPTH = 32;
|
|
50165
|
+
const MAX_DEPTH$2 = 32;
|
|
49441
50166
|
/**
|
|
49442
50167
|
* Resolves what `app.input.*` was pointed at. A `{ projection, key }` goes through
|
|
49443
50168
|
* `world.projection.entityOf`, which answers for live views only, so a view in the despawn queue
|
|
@@ -49533,7 +50258,7 @@ function findPressed(ctx, x, y) {
|
|
|
49533
50258
|
function movingScrollOf(ctx, entity) {
|
|
49534
50259
|
const { ecs } = ctx.deps.world;
|
|
49535
50260
|
let current = entity;
|
|
49536
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50261
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
49537
50262
|
if (ecs.get(current, Scrollable)?.moving === true && !ecs.has(current, Exiting)) return current;
|
|
49538
50263
|
current = parentOf$1(ecs, current);
|
|
49539
50264
|
}
|
|
@@ -49552,7 +50277,7 @@ function movingScrollOf(ctx, entity) {
|
|
|
49552
50277
|
function scrollOnAxisOf(ctx, entity, axis) {
|
|
49553
50278
|
const { ecs } = ctx.deps.world;
|
|
49554
50279
|
let current = entity;
|
|
49555
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50280
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
49556
50281
|
if (ecs.get(current, Scrollable)?.axis === axis && !ecs.has(current, Exiting)) return current;
|
|
49557
50282
|
current = parentOf$1(ecs, current);
|
|
49558
50283
|
}
|
|
@@ -54620,6 +55345,301 @@ const textPlugin = /*#__PURE__*/ createPlugin$1("text", {
|
|
|
54620
55345
|
onStop: ({ state }) => stopText(state)
|
|
54621
55346
|
});
|
|
54622
55347
|
//#endregion
|
|
55348
|
+
//#region src/plugins/ui/drawn.ts
|
|
55349
|
+
/**
|
|
55350
|
+
* @file ui plugin — where a target is drawn, in screen reference units: the one resolver the
|
|
55351
|
+
* `<anchor>` pass and `app.ui.rectOf` share. A target's local box goes through its root pose, the
|
|
55352
|
+
* `Transform` of every entity on its way up composed, so a scroll's offset, a fit, a slot and the
|
|
55353
|
+
* motion of an ancestor move it. Axis-aligned: the rotation is left out. A ui element spawned in
|
|
55354
|
+
* this frame has no `Transform` until the flush of the phase: its rest pose stands in, so it is
|
|
55355
|
+
* found in the frame it is laid out. The frame path allocates nothing: every answer is written into
|
|
55356
|
+
* the caller's objects, and no fractional number crosses a call. `rectOf` answers a new rect.
|
|
55357
|
+
*/
|
|
55358
|
+
/** How deep a chain is followed; deeper is treated as a loop. */
|
|
55359
|
+
const MAX_DEPTH$1 = 32;
|
|
55360
|
+
/** The alpha a target is drawn at below which it counts as not shown, as the hit test reads it. */
|
|
55361
|
+
const MIN_ALPHA = .01;
|
|
55362
|
+
/**
|
|
55363
|
+
* The reader of a running `ui`, over its world and its own state.
|
|
55364
|
+
*
|
|
55365
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55366
|
+
* @returns The reader; it holds the live maps, so it stays current.
|
|
55367
|
+
*/
|
|
55368
|
+
function readerOf(ctx) {
|
|
55369
|
+
return {
|
|
55370
|
+
ecs: ctx.deps.world.ecs,
|
|
55371
|
+
projection: ctx.deps.world.projection,
|
|
55372
|
+
elements: ctx.state.jsx.elements,
|
|
55373
|
+
roots: ctx.state.jsx.roots,
|
|
55374
|
+
exiting: ctx.state.jsx.exiting
|
|
55375
|
+
};
|
|
55376
|
+
}
|
|
55377
|
+
/**
|
|
55378
|
+
* The entity an entity is drawn under: the parent of a ui element, the slot of a root element laid
|
|
55379
|
+
* out in one, the `Parent` of any other view.
|
|
55380
|
+
*
|
|
55381
|
+
* @param reader - What the resolver reads.
|
|
55382
|
+
* @param entity - The entity.
|
|
55383
|
+
* @returns The entity above it, or 0 when it hangs in its layer.
|
|
55384
|
+
*/
|
|
55385
|
+
function upOf(reader, entity) {
|
|
55386
|
+
const element = reader.elements.get(entity);
|
|
55387
|
+
if (element === void 0) return parentOf$1(reader.ecs, entity);
|
|
55388
|
+
return element.parent ?? reader.roots.get(element.root)?.slot ?? 0;
|
|
55389
|
+
}
|
|
55390
|
+
/**
|
|
55391
|
+
* The pose an entity is drawn with: its `Transform`, or the rest pose of a ui element whose
|
|
55392
|
+
* `Transform` waits for the flush.
|
|
55393
|
+
*
|
|
55394
|
+
* @param reader - What the resolver reads.
|
|
55395
|
+
* @param entity - The entity.
|
|
55396
|
+
* @returns The pose, or `undefined` for a view with no `Transform`.
|
|
55397
|
+
*/
|
|
55398
|
+
function poseOf(reader, entity) {
|
|
55399
|
+
return reader.ecs.get(entity, Transform) ?? reader.elements.get(entity)?.rest;
|
|
55400
|
+
}
|
|
55401
|
+
/**
|
|
55402
|
+
* Writes where an entity really is: its pose composed through every entity it is drawn under,
|
|
55403
|
+
* the arithmetic of `rootPoseInto`, over `upOf`. The answer keeps the entity's own pivot. Kept in
|
|
55404
|
+
* step with `rootPoseInto` of `renderer/sync/pose.ts`: the same composition, step by step, over the
|
|
55405
|
+
* parents of `ui` elements and the rest pose of an element whose `Transform` has not landed.
|
|
55406
|
+
*
|
|
55407
|
+
* @param reader - What the resolver reads.
|
|
55408
|
+
* @param entity - The entity.
|
|
55409
|
+
* @param out - The pose to write, its `pivot` included.
|
|
55410
|
+
* @returns False for a view with no `Transform`: `out` is not written.
|
|
55411
|
+
*/
|
|
55412
|
+
function drawnPoseInto(reader, entity, out) {
|
|
55413
|
+
const own = poseOf(reader, entity);
|
|
55414
|
+
if (own === void 0) return false;
|
|
55415
|
+
out.x = own.x;
|
|
55416
|
+
out.y = own.y;
|
|
55417
|
+
out.rotation = own.rotation;
|
|
55418
|
+
out.scale = own.scale;
|
|
55419
|
+
out.pivot.x = own.pivot.x;
|
|
55420
|
+
out.pivot.y = own.pivot.y;
|
|
55421
|
+
let current = entity;
|
|
55422
|
+
for (let depth = 0; depth < MAX_DEPTH$1; depth += 1) {
|
|
55423
|
+
const parent = upOf(reader, current);
|
|
55424
|
+
if (parent === 0) break;
|
|
55425
|
+
const above = poseOf(reader, parent) ?? Transform.defaults;
|
|
55426
|
+
const cos = Math.cos(above.rotation);
|
|
55427
|
+
const sin = Math.sin(above.rotation);
|
|
55428
|
+
const dx = out.x - above.pivot.x;
|
|
55429
|
+
const dy = out.y - above.pivot.y;
|
|
55430
|
+
out.x = above.x + above.scale * (dx * cos - dy * sin);
|
|
55431
|
+
out.y = above.y + above.scale * (dx * sin + dy * cos);
|
|
55432
|
+
out.rotation += above.rotation;
|
|
55433
|
+
out.scale *= above.scale;
|
|
55434
|
+
current = parent;
|
|
55435
|
+
}
|
|
55436
|
+
return true;
|
|
55437
|
+
}
|
|
55438
|
+
/**
|
|
55439
|
+
* Tells whether an entity belongs to a scene built aside or a held warm window: the entity itself,
|
|
55440
|
+
* or the root of a ui element, as the reconcile asks it.
|
|
55441
|
+
*
|
|
55442
|
+
* @param reader - What the resolver reads.
|
|
55443
|
+
* @param entity - The entity.
|
|
55444
|
+
* @returns True while it is not on the screen yet.
|
|
55445
|
+
*/
|
|
55446
|
+
function building(reader, entity) {
|
|
55447
|
+
const element = reader.elements.get(entity);
|
|
55448
|
+
return reader.projection.isBuilding(entity) || element !== void 0 && reader.projection.isBuilding(element.root);
|
|
55449
|
+
}
|
|
55450
|
+
/**
|
|
55451
|
+
* Tells whether the player can see an entity: neither it nor anything it is drawn under is on its
|
|
55452
|
+
* way out, and the alphas of their visuals (`Shape`, `NineSlice`, `Sprite` or `Text`) multiply to
|
|
55453
|
+
* more than 0.01. The alpha of a visual fades the entity's children with it, as the renderer draws
|
|
55454
|
+
* it.
|
|
55455
|
+
*
|
|
55456
|
+
* @param reader - What the resolver reads.
|
|
55457
|
+
* @param entity - The entity.
|
|
55458
|
+
* @returns True when it is shown.
|
|
55459
|
+
*/
|
|
55460
|
+
function visible(reader, entity) {
|
|
55461
|
+
const ecs = reader.ecs;
|
|
55462
|
+
let alpha = 1;
|
|
55463
|
+
let current = entity;
|
|
55464
|
+
for (let depth = 0; depth < MAX_DEPTH$1 && current !== 0; depth += 1) {
|
|
55465
|
+
if (reader.exiting.has(current) || ecs.has(current, Exiting)) return false;
|
|
55466
|
+
alpha *= ecs.get(current, Shape)?.alpha ?? ecs.get(current, NineSlice)?.alpha ?? ecs.get(current, Sprite)?.alpha ?? ecs.get(current, Text)?.alpha ?? 1;
|
|
55467
|
+
current = upOf(reader, current);
|
|
55468
|
+
}
|
|
55469
|
+
return alpha > MIN_ALPHA;
|
|
55470
|
+
}
|
|
55471
|
+
/**
|
|
55472
|
+
* Moves a local box of an entity into root space, in place: moved by the pose, scaled around its
|
|
55473
|
+
* pivot, the rotation left out. The numbers stay in the rect: a fractional number handed to a call
|
|
55474
|
+
* is boxed.
|
|
55475
|
+
*
|
|
55476
|
+
* @param pose - The root pose of the entity.
|
|
55477
|
+
* @param out - The box in the entity's own units, written in root space.
|
|
55478
|
+
*/
|
|
55479
|
+
function toRoot(pose, out) {
|
|
55480
|
+
out.x = pose.x + pose.scale * (out.x - pose.pivot.x);
|
|
55481
|
+
out.y = pose.y + pose.scale * (out.y - pose.pivot.y);
|
|
55482
|
+
out.w *= pose.scale;
|
|
55483
|
+
out.h *= pose.scale;
|
|
55484
|
+
}
|
|
55485
|
+
/**
|
|
55486
|
+
* Writes the box of an entity in its own units, by what it draws: the layout box of a ui element,
|
|
55487
|
+
* the panel of a nine-slice, the rectangle of a shape, the anchor box of a sprite.
|
|
55488
|
+
*
|
|
55489
|
+
* @param reader - What the resolver reads.
|
|
55490
|
+
* @param entity - The entity.
|
|
55491
|
+
* @param out - The rect written, its `x` and `y` at 0 when the call starts.
|
|
55492
|
+
* @returns False for an entity that draws none of them.
|
|
55493
|
+
*/
|
|
55494
|
+
function ownBoxInto(reader, entity, out) {
|
|
55495
|
+
const element = reader.elements.get(entity);
|
|
55496
|
+
if (element !== void 0) {
|
|
55497
|
+
out.w = element.rect.w;
|
|
55498
|
+
out.h = element.rect.h;
|
|
55499
|
+
return true;
|
|
55500
|
+
}
|
|
55501
|
+
const panel = reader.ecs.get(entity, NineSlice);
|
|
55502
|
+
if (panel !== void 0) {
|
|
55503
|
+
out.w = panel.width;
|
|
55504
|
+
out.h = panel.height;
|
|
55505
|
+
return true;
|
|
55506
|
+
}
|
|
55507
|
+
const shape = reader.ecs.get(entity, Shape);
|
|
55508
|
+
if (shape !== void 0) {
|
|
55509
|
+
out.w = shape.w;
|
|
55510
|
+
out.h = shape.h;
|
|
55511
|
+
return true;
|
|
55512
|
+
}
|
|
55513
|
+
const sprite = reader.ecs.get(entity, Sprite);
|
|
55514
|
+
if (sprite === void 0) return false;
|
|
55515
|
+
out.w = sprite.width;
|
|
55516
|
+
out.h = sprite.height;
|
|
55517
|
+
out.x = -sprite.anchor.x * sprite.width;
|
|
55518
|
+
out.y = -sprite.anchor.y * sprite.height;
|
|
55519
|
+
return true;
|
|
55520
|
+
}
|
|
55521
|
+
/**
|
|
55522
|
+
* Writes the box an entity draws in root space: its own box through its root pose.
|
|
55523
|
+
*
|
|
55524
|
+
* @param reader - What the resolver reads.
|
|
55525
|
+
* @param entity - The entity.
|
|
55526
|
+
* @param pose - Its root pose.
|
|
55527
|
+
* @param out - The rect written, in root space.
|
|
55528
|
+
* @returns False for an entity that draws no box.
|
|
55529
|
+
*/
|
|
55530
|
+
function localBoxInto(reader, entity, pose, out) {
|
|
55531
|
+
out.x = 0;
|
|
55532
|
+
out.y = 0;
|
|
55533
|
+
if (!ownBoxInto(reader, entity, out)) return false;
|
|
55534
|
+
toRoot(pose, out);
|
|
55535
|
+
return true;
|
|
55536
|
+
}
|
|
55537
|
+
/**
|
|
55538
|
+
* Writes where an entity is drawn, in screen reference units, when it is shown. Not shown: the
|
|
55539
|
+
* entity belongs to a scene built aside, it or something it is drawn under is leaving, the alphas
|
|
55540
|
+
* on its way up multiply to 0.01 or less, it draws no box, or the box has no area.
|
|
55541
|
+
*
|
|
55542
|
+
* @param reader - What the resolver reads.
|
|
55543
|
+
* @param entity - The entity of the target.
|
|
55544
|
+
* @param out - The rect written.
|
|
55545
|
+
* @param pose - A pose the resolver writes on its way, kept by the caller.
|
|
55546
|
+
* @returns True when the target is shown and `out` holds its rect.
|
|
55547
|
+
*/
|
|
55548
|
+
function drawnInto(reader, entity, out, pose) {
|
|
55549
|
+
if (building(reader, entity) || !visible(reader, entity)) return false;
|
|
55550
|
+
if (!drawnPoseInto(reader, entity, pose) || !localBoxInto(reader, entity, pose, out)) return false;
|
|
55551
|
+
return out.w > 0 && out.h > 0;
|
|
55552
|
+
}
|
|
55553
|
+
/**
|
|
55554
|
+
* Grows a rect to hold another one.
|
|
55555
|
+
*
|
|
55556
|
+
* @param out - The rect grown in place.
|
|
55557
|
+
* @param part - The rect it must hold.
|
|
55558
|
+
*/
|
|
55559
|
+
function unionInto(out, part) {
|
|
55560
|
+
const right = Math.max(out.x + out.w, part.x + part.w);
|
|
55561
|
+
const bottom = Math.max(out.y + out.h, part.y + part.h);
|
|
55562
|
+
out.x = Math.min(out.x, part.x);
|
|
55563
|
+
out.y = Math.min(out.y, part.y);
|
|
55564
|
+
out.w = right - out.x;
|
|
55565
|
+
out.h = bottom - out.y;
|
|
55566
|
+
}
|
|
55567
|
+
/**
|
|
55568
|
+
* Tells a list of targets from one target.
|
|
55569
|
+
*
|
|
55570
|
+
* @param to - What `to` or `rectOf` was given, or nothing.
|
|
55571
|
+
* @returns True for a list.
|
|
55572
|
+
* @example
|
|
55573
|
+
* ```ts
|
|
55574
|
+
* isTargetList([{ projection: "hud", key: "coins" }]); // true
|
|
55575
|
+
* ```
|
|
55576
|
+
*/
|
|
55577
|
+
function isTargetList(to) {
|
|
55578
|
+
return Array.isArray(to);
|
|
55579
|
+
}
|
|
55580
|
+
/**
|
|
55581
|
+
* Writes the rect of one target or the bounding rect of the shown ones of a list.
|
|
55582
|
+
*
|
|
55583
|
+
* @param reader - What the resolver reads.
|
|
55584
|
+
* @param to - One target or a list of them.
|
|
55585
|
+
* @param out - The rect written.
|
|
55586
|
+
* @param scratch - The part and the pose the resolver writes on its way.
|
|
55587
|
+
* @param scratch.part - The rect of one target.
|
|
55588
|
+
* @param scratch.pose - The pose of one target.
|
|
55589
|
+
* @returns True when at least one target is shown.
|
|
55590
|
+
*/
|
|
55591
|
+
function targetsInto(reader, to, out, scratch) {
|
|
55592
|
+
const list = isTargetList(to) ? to : [to];
|
|
55593
|
+
let shown = false;
|
|
55594
|
+
for (const target of list) {
|
|
55595
|
+
const entity = reader.projection.entityOf(target.projection, target.key);
|
|
55596
|
+
if (entity === void 0 || !drawnInto(reader, entity, scratch.part, scratch.pose)) continue;
|
|
55597
|
+
if (shown) unionInto(out, scratch.part);
|
|
55598
|
+
else {
|
|
55599
|
+
out.x = scratch.part.x;
|
|
55600
|
+
out.y = scratch.part.y;
|
|
55601
|
+
out.w = scratch.part.w;
|
|
55602
|
+
out.h = scratch.part.h;
|
|
55603
|
+
shown = true;
|
|
55604
|
+
}
|
|
55605
|
+
}
|
|
55606
|
+
return shown;
|
|
55607
|
+
}
|
|
55608
|
+
/**
|
|
55609
|
+
* Where a target, or the shown targets of a list, are drawn: `app.ui.rectOf`. Not a frame path:
|
|
55610
|
+
* every call answers a new rect.
|
|
55611
|
+
*
|
|
55612
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55613
|
+
* @param to - One target or a list of them.
|
|
55614
|
+
* @returns The rect in screen reference units, or `undefined` when no target is shown.
|
|
55615
|
+
*/
|
|
55616
|
+
function rectOfTargets(ctx, to) {
|
|
55617
|
+
const out = {
|
|
55618
|
+
x: 0,
|
|
55619
|
+
y: 0,
|
|
55620
|
+
w: 0,
|
|
55621
|
+
h: 0
|
|
55622
|
+
};
|
|
55623
|
+
return targetsInto(readerOf(ctx), to, out, {
|
|
55624
|
+
part: {
|
|
55625
|
+
x: 0,
|
|
55626
|
+
y: 0,
|
|
55627
|
+
w: 0,
|
|
55628
|
+
h: 0
|
|
55629
|
+
},
|
|
55630
|
+
pose: {
|
|
55631
|
+
x: 0,
|
|
55632
|
+
y: 0,
|
|
55633
|
+
rotation: 0,
|
|
55634
|
+
scale: 1,
|
|
55635
|
+
pivot: {
|
|
55636
|
+
x: 0,
|
|
55637
|
+
y: 0
|
|
55638
|
+
}
|
|
55639
|
+
}
|
|
55640
|
+
}) ? out : void 0;
|
|
55641
|
+
}
|
|
55642
|
+
//#endregion
|
|
54623
55643
|
//#region src/plugins/ui/jsx/field-layout.ts
|
|
54624
55644
|
/**
|
|
54625
55645
|
* The four edges of a resolved padding.
|
|
@@ -58643,6 +59663,15 @@ const APPLY_CAP = 100;
|
|
|
58643
59663
|
/** What a parked part holds once it is back in the pool: no nodes and no element, so the pool keeps no tree alive. */
|
|
58644
59664
|
const NO_NODES = [];
|
|
58645
59665
|
/**
|
|
59666
|
+
* Creates the set of the roots whose parts wait. Its own function, because lint rule L5 refuses a
|
|
59667
|
+
* collection built inside an exported declaration.
|
|
59668
|
+
*
|
|
59669
|
+
* @returns An empty set.
|
|
59670
|
+
*/
|
|
59671
|
+
function rootSet() {
|
|
59672
|
+
return /* @__PURE__ */ new Set();
|
|
59673
|
+
}
|
|
59674
|
+
/**
|
|
58646
59675
|
* Tells whether a root has parked parts.
|
|
58647
59676
|
*
|
|
58648
59677
|
* @param root - The root.
|
|
@@ -58679,6 +59708,24 @@ function createParts(ctx, reconcile) {
|
|
|
58679
59708
|
let landed = false;
|
|
58680
59709
|
const parkedPool = [];
|
|
58681
59710
|
const cursorPool = [];
|
|
59711
|
+
const busy = rootSet();
|
|
59712
|
+
/**
|
|
59713
|
+
* Notes whether parts of a root wait now, after its queue or its application changed.
|
|
59714
|
+
*
|
|
59715
|
+
* @param root - The root.
|
|
59716
|
+
*/
|
|
59717
|
+
function track(root) {
|
|
59718
|
+
if (waits(root)) busy.add(root);
|
|
59719
|
+
else busy.delete(root);
|
|
59720
|
+
}
|
|
59721
|
+
/**
|
|
59722
|
+
* Tells whether parts of any root wait: children parked, or an application open.
|
|
59723
|
+
*
|
|
59724
|
+
* @returns True while a build in parts has work left.
|
|
59725
|
+
*/
|
|
59726
|
+
function working() {
|
|
59727
|
+
return busy.size > 0;
|
|
59728
|
+
}
|
|
58682
59729
|
/**
|
|
58683
59730
|
* Starts the frame's reconcile: no element entered, the budget not read, no building unit run.
|
|
58684
59731
|
*/
|
|
@@ -58750,6 +59797,7 @@ function createParts(ctx, reconcile) {
|
|
|
58750
59797
|
part.cause = cause;
|
|
58751
59798
|
root.parked ??= [];
|
|
58752
59799
|
root.parked.push(part);
|
|
59800
|
+
track(root);
|
|
58753
59801
|
}
|
|
58754
59802
|
/**
|
|
58755
59803
|
* Puts a parked part back in the pool, its element and nodes dropped.
|
|
@@ -58798,7 +59846,7 @@ function createParts(ctx, reconcile) {
|
|
|
58798
59846
|
* root's queue.
|
|
58799
59847
|
*/
|
|
58800
59848
|
function drainParked() {
|
|
58801
|
-
if (
|
|
59849
|
+
if (busy.size === 0) return;
|
|
58802
59850
|
for (const root of state.roots.values()) {
|
|
58803
59851
|
const parked = root.parked;
|
|
58804
59852
|
while (parked !== void 0 && parked.length > 0) {
|
|
@@ -58808,6 +59856,7 @@ function createParts(ctx, reconcile) {
|
|
|
58808
59856
|
diffPart(root, part);
|
|
58809
59857
|
recycle(part);
|
|
58810
59858
|
}
|
|
59859
|
+
track(root);
|
|
58811
59860
|
}
|
|
58812
59861
|
}
|
|
58813
59862
|
/**
|
|
@@ -58841,6 +59890,16 @@ function createParts(ctx, reconcile) {
|
|
|
58841
59890
|
const part = parked.pop();
|
|
58842
59891
|
if (part !== void 0) recycle(part);
|
|
58843
59892
|
}
|
|
59893
|
+
dropApplication(root);
|
|
59894
|
+
track(root);
|
|
59895
|
+
}
|
|
59896
|
+
/**
|
|
59897
|
+
* Drops the open application of a root, if it has one, with no element applied: its cursor goes
|
|
59898
|
+
* back to the pool, empty.
|
|
59899
|
+
*
|
|
59900
|
+
* @param root - The root.
|
|
59901
|
+
*/
|
|
59902
|
+
function dropApplication(root) {
|
|
58844
59903
|
const cursor = root.applying;
|
|
58845
59904
|
if (cursor === void 0) return;
|
|
58846
59905
|
while (cursor.stack.length > 0) cursor.stack.pop();
|
|
@@ -58848,6 +59907,30 @@ function createParts(ctx, reconcile) {
|
|
|
58848
59907
|
cursorPool.push(cursor);
|
|
58849
59908
|
}
|
|
58850
59909
|
/**
|
|
59910
|
+
* Finishes the build of a root shown before its parts were done (a warm window opened while it
|
|
59911
|
+
* was built, spec 33 B+D): every parked part is diffed now, whatever the budget, and its children
|
|
59912
|
+
* no longer park, since the root is not built aside any more; an open application is dropped.
|
|
59913
|
+
* The root then asks for a solve, which lays it out and applies it whole, so no half-built frame
|
|
59914
|
+
* is drawn.
|
|
59915
|
+
*
|
|
59916
|
+
* @param root - A root that was built aside and is not any more.
|
|
59917
|
+
* @returns True when parts were left, so the solve of this frame applies the root in one block.
|
|
59918
|
+
*/
|
|
59919
|
+
function finish(root) {
|
|
59920
|
+
if (!waits(root)) return false;
|
|
59921
|
+
const parked = root.parked;
|
|
59922
|
+
while (parked !== void 0 && parked.length > 0) {
|
|
59923
|
+
const part = parked.shift();
|
|
59924
|
+
if (part === void 0) break;
|
|
59925
|
+
diffPart(root, part);
|
|
59926
|
+
recycle(part);
|
|
59927
|
+
}
|
|
59928
|
+
dropApplication(root);
|
|
59929
|
+
track(root);
|
|
59930
|
+
root.needsSolve = true;
|
|
59931
|
+
return true;
|
|
59932
|
+
}
|
|
59933
|
+
/**
|
|
58851
59934
|
* Opens the application of a solved root built aside and applies its first part (spec 33 A6).
|
|
58852
59935
|
*
|
|
58853
59936
|
* @param root - The root built aside.
|
|
@@ -58863,6 +59946,7 @@ function createParts(ctx, reconcile) {
|
|
|
58863
59946
|
cursor.stack.push(element);
|
|
58864
59947
|
root.applying = cursor;
|
|
58865
59948
|
applyPart(root, cursor);
|
|
59949
|
+
track(root);
|
|
58866
59950
|
}
|
|
58867
59951
|
/**
|
|
58868
59952
|
* Applies the next elements of an open application, top-down, parent before children in the
|
|
@@ -58909,6 +59993,7 @@ function createParts(ctx, reconcile) {
|
|
|
58909
59993
|
function closeApplication(root, cursor) {
|
|
58910
59994
|
delete root.applying;
|
|
58911
59995
|
cursorPool.push(cursor);
|
|
59996
|
+
track(root);
|
|
58912
59997
|
landed = true;
|
|
58913
59998
|
for (const host of state.hosts) if (lookup(host)?.root === root.entity) state.risen.add(host);
|
|
58914
59999
|
}
|
|
@@ -58918,7 +60003,7 @@ function createParts(ctx, reconcile) {
|
|
|
58918
60003
|
* here is solved again in the same call when it asks for it.
|
|
58919
60004
|
*/
|
|
58920
60005
|
function applyParts() {
|
|
58921
|
-
if (
|
|
60006
|
+
if (busy.size === 0) return;
|
|
58922
60007
|
for (const root of state.roots.values()) {
|
|
58923
60008
|
const cursor = root.applying;
|
|
58924
60009
|
if (cursor === void 0) continue;
|
|
@@ -58934,9 +60019,11 @@ function createParts(ctx, reconcile) {
|
|
|
58934
60019
|
parks,
|
|
58935
60020
|
park,
|
|
58936
60021
|
waits,
|
|
60022
|
+
working,
|
|
58937
60023
|
drainParked,
|
|
58938
60024
|
holdRoot,
|
|
58939
60025
|
forgetParts,
|
|
60026
|
+
finish,
|
|
58940
60027
|
applyInParts,
|
|
58941
60028
|
applyParts
|
|
58942
60029
|
};
|
|
@@ -59310,6 +60397,186 @@ function sameValue(left, right) {
|
|
|
59310
60397
|
return sameFieldsDeep(left, right);
|
|
59311
60398
|
}
|
|
59312
60399
|
//#endregion
|
|
60400
|
+
//#region src/plugins/ui/jsx/state.ts
|
|
60401
|
+
/**
|
|
60402
|
+
* Creates an empty map. Its own non-exported function, because lint rule L5 refuses a collection
|
|
60403
|
+
* built inside an exported declaration.
|
|
60404
|
+
*
|
|
60405
|
+
* @returns A map with nothing in it.
|
|
60406
|
+
*/
|
|
60407
|
+
function emptyMap$1() {
|
|
60408
|
+
return /* @__PURE__ */ new Map();
|
|
60409
|
+
}
|
|
60410
|
+
/**
|
|
60411
|
+
* Creates an empty set, for the same reason as `emptyMap`.
|
|
60412
|
+
*
|
|
60413
|
+
* @returns A set with nothing in it.
|
|
60414
|
+
*/
|
|
60415
|
+
function emptySet() {
|
|
60416
|
+
return /* @__PURE__ */ new Set();
|
|
60417
|
+
}
|
|
60418
|
+
/**
|
|
60419
|
+
* Creates the text input branch: no hidden input, nothing edited, an empty mirror.
|
|
60420
|
+
*
|
|
60421
|
+
* @returns The text state.
|
|
60422
|
+
*/
|
|
60423
|
+
function createTextState() {
|
|
60424
|
+
return {
|
|
60425
|
+
element: void 0,
|
|
60426
|
+
editing: void 0,
|
|
60427
|
+
mirror: {
|
|
60428
|
+
value: "",
|
|
60429
|
+
selectionStart: 0,
|
|
60430
|
+
selectionEnd: 0,
|
|
60431
|
+
direction: "none"
|
|
60432
|
+
},
|
|
60433
|
+
composing: void 0,
|
|
60434
|
+
keyboard: {
|
|
60435
|
+
inset: 0,
|
|
60436
|
+
innerHeight: 0,
|
|
60437
|
+
lift: 0
|
|
60438
|
+
},
|
|
60439
|
+
lifted: void 0,
|
|
60440
|
+
placed: void 0,
|
|
60441
|
+
watching: void 0,
|
|
60442
|
+
cleanups: []
|
|
60443
|
+
};
|
|
60444
|
+
}
|
|
60445
|
+
/**
|
|
60446
|
+
* Creates the jsx branch of the ui state. Everything starts empty: the registry is filled in
|
|
60447
|
+
* `onStart` from the `ui` key of every feature.
|
|
60448
|
+
*
|
|
60449
|
+
* @returns The module state.
|
|
60450
|
+
* @example
|
|
60451
|
+
* ```ts
|
|
60452
|
+
* createJsxState().roots.size; // 0
|
|
60453
|
+
* ```
|
|
60454
|
+
*/
|
|
60455
|
+
function createJsxState() {
|
|
60456
|
+
return {
|
|
60457
|
+
components: emptyMap$1(),
|
|
60458
|
+
roots: emptyMap$1(),
|
|
60459
|
+
elements: emptyMap$1(),
|
|
60460
|
+
byIdentity: emptyMap$1(),
|
|
60461
|
+
byKey: emptyMap$1(),
|
|
60462
|
+
instances: emptyMap$1(),
|
|
60463
|
+
exiting: emptySet(),
|
|
60464
|
+
leading: emptySet(),
|
|
60465
|
+
removing: emptySet(),
|
|
60466
|
+
hosts: emptySet(),
|
|
60467
|
+
hosted: emptyMap$1(),
|
|
60468
|
+
hostsVersion: 0,
|
|
60469
|
+
hostsSeen: -1,
|
|
60470
|
+
membershipSeen: -1,
|
|
60471
|
+
risen: emptySet(),
|
|
60472
|
+
released: emptySet(),
|
|
60473
|
+
building: void 0,
|
|
60474
|
+
reconciles: 0,
|
|
60475
|
+
focus: {
|
|
60476
|
+
entity: void 0,
|
|
60477
|
+
ring: void 0,
|
|
60478
|
+
drawn: void 0,
|
|
60479
|
+
tapping: false,
|
|
60480
|
+
ringless: false
|
|
60481
|
+
},
|
|
60482
|
+
fields: emptyMap$1(),
|
|
60483
|
+
text: createTextState(),
|
|
60484
|
+
hints: [],
|
|
60485
|
+
entering: {
|
|
60486
|
+
list: [],
|
|
60487
|
+
count: 0
|
|
60488
|
+
},
|
|
60489
|
+
scrolls: emptySet(),
|
|
60490
|
+
windowRenders: 0,
|
|
60491
|
+
remount: false,
|
|
60492
|
+
epoch: 0,
|
|
60493
|
+
styled: 0,
|
|
60494
|
+
written: 0,
|
|
60495
|
+
debugTaps: [],
|
|
60496
|
+
debugWarned: false,
|
|
60497
|
+
overlays: emptySet(),
|
|
60498
|
+
asideRoots: 0,
|
|
60499
|
+
anchors: emptyMap$1()
|
|
60500
|
+
};
|
|
60501
|
+
}
|
|
60502
|
+
/**
|
|
60503
|
+
* Creates a rect the anchor pass writes in every frame. Its keys come in an order of their own
|
|
60504
|
+
* (`w`, `h`, `x`, `y`): V8 gives every `{ x, y, w, h }` object one hidden shape, the frozen `Box`
|
|
60505
|
+
* values among them, and in that shape `x` and `y` hold boxed numbers, so each fractional number
|
|
60506
|
+
* written there allocates 16 B. In a shape of its own the four fields take a double in place.
|
|
60507
|
+
*
|
|
60508
|
+
* @param x - The left.
|
|
60509
|
+
* @param y - The top.
|
|
60510
|
+
* @param w - The width.
|
|
60511
|
+
* @param h - The height.
|
|
60512
|
+
* @returns The rect.
|
|
60513
|
+
* @example
|
|
60514
|
+
* ```ts
|
|
60515
|
+
* ownRect(40, 1500, 116, 120).x; // 40
|
|
60516
|
+
* ```
|
|
60517
|
+
*/
|
|
60518
|
+
function ownRect(x, y, w, h) {
|
|
60519
|
+
return {
|
|
60520
|
+
w,
|
|
60521
|
+
h,
|
|
60522
|
+
x,
|
|
60523
|
+
y
|
|
60524
|
+
};
|
|
60525
|
+
}
|
|
60526
|
+
/**
|
|
60527
|
+
* Creates what the anchor pass keeps for a new `<anchor>`: nothing read yet, not placed.
|
|
60528
|
+
*
|
|
60529
|
+
* @returns The record, every rect and the pose zeroed.
|
|
60530
|
+
*/
|
|
60531
|
+
function createAnchor() {
|
|
60532
|
+
return {
|
|
60533
|
+
node: void 0,
|
|
60534
|
+
to: void 0,
|
|
60535
|
+
retarget: false,
|
|
60536
|
+
seen: [],
|
|
60537
|
+
shown: [],
|
|
60538
|
+
count: 0,
|
|
60539
|
+
shownCount: 0,
|
|
60540
|
+
screen: ownRect(0, 0, 0, 0),
|
|
60541
|
+
part: ownRect(0, 0, 0, 0),
|
|
60542
|
+
next: ownRect(0, 0, 0, 0),
|
|
60543
|
+
pose: {
|
|
60544
|
+
x: 0,
|
|
60545
|
+
y: 0,
|
|
60546
|
+
rotation: 0,
|
|
60547
|
+
scale: 1,
|
|
60548
|
+
pivot: {
|
|
60549
|
+
x: 0,
|
|
60550
|
+
y: 0
|
|
60551
|
+
}
|
|
60552
|
+
},
|
|
60553
|
+
placed: false,
|
|
60554
|
+
hidden: false,
|
|
60555
|
+
missing: 0,
|
|
60556
|
+
owed: false,
|
|
60557
|
+
stale: false,
|
|
60558
|
+
boxes: false,
|
|
60559
|
+
held: void 0,
|
|
60560
|
+
aim: {
|
|
60561
|
+
x: 0,
|
|
60562
|
+
y: 0
|
|
60563
|
+
},
|
|
60564
|
+
track: {
|
|
60565
|
+
x: 0,
|
|
60566
|
+
y: 0
|
|
60567
|
+
},
|
|
60568
|
+
wrote: {
|
|
60569
|
+
x: NaN,
|
|
60570
|
+
y: NaN
|
|
60571
|
+
},
|
|
60572
|
+
warned: {
|
|
60573
|
+
missing: false,
|
|
60574
|
+
own: false,
|
|
60575
|
+
style: false
|
|
60576
|
+
}
|
|
60577
|
+
};
|
|
60578
|
+
}
|
|
60579
|
+
//#endregion
|
|
59313
60580
|
//#region src/plugins/ui/jsx/reconcile.ts
|
|
59314
60581
|
/**
|
|
59315
60582
|
* @file ui/jsx — the reconcile: a description tree diffed by identity into the entities `ui`
|
|
@@ -59797,6 +61064,22 @@ function identitySet(identities) {
|
|
|
59797
61064
|
return new Set(identities);
|
|
59798
61065
|
}
|
|
59799
61066
|
/**
|
|
61067
|
+
* Tells whether an element is an `<anchor>` or lies under one: the anchor pass places it after
|
|
61068
|
+
* the solve, by its targets, so the solve leaves it alone.
|
|
61069
|
+
*
|
|
61070
|
+
* @param element - The element.
|
|
61071
|
+
* @param lookup - How a parent entity becomes its element.
|
|
61072
|
+
* @returns True for an anchor and everything under it.
|
|
61073
|
+
*/
|
|
61074
|
+
function isAnchored(element, lookup) {
|
|
61075
|
+
let current = element;
|
|
61076
|
+
while (current !== void 0) {
|
|
61077
|
+
if (current.type === "anchor") return true;
|
|
61078
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
61079
|
+
}
|
|
61080
|
+
return false;
|
|
61081
|
+
}
|
|
61082
|
+
/**
|
|
59800
61083
|
* Tells whether an element whose `Box` just came arrives with an enter: new, and not a row a
|
|
59801
61084
|
* range change scrolled in.
|
|
59802
61085
|
*
|
|
@@ -59847,6 +61130,12 @@ function createReconciler(ctx, modules, fields) {
|
|
|
59847
61130
|
let rendered = 0;
|
|
59848
61131
|
const isAside = (entity) => ctx.deps.world.projection.isBuilding(entity);
|
|
59849
61132
|
let released = false;
|
|
61133
|
+
let anchoring = false;
|
|
61134
|
+
let asideSeen = -1;
|
|
61135
|
+
let enteredSeen = -1;
|
|
61136
|
+
let heldEnters = -1;
|
|
61137
|
+
let asideSolved = false;
|
|
61138
|
+
const isAsideScroll = (container) => state.asideRoots > 0 && state.roots.get(container.root)?.aside !== void 0;
|
|
59850
61139
|
const lookWriter = {
|
|
59851
61140
|
pass: 0,
|
|
59852
61141
|
values: {
|
|
@@ -59858,8 +61147,10 @@ function createReconciler(ctx, modules, fields) {
|
|
|
59858
61147
|
others: (element, type, next) => writeOthers(element, next, type)
|
|
59859
61148
|
};
|
|
59860
61149
|
/**
|
|
59861
|
-
* Registers the key of an element under its root, so `
|
|
59862
|
-
* `ui` gave a node of its own, a spacer's, is never registered.
|
|
61150
|
+
* Registers the key of an element under its root, so `find` and `entityOf` answer for it. A key
|
|
61151
|
+
* `ui` gave a node of its own, a spacer's, is never registered. A root built aside or held warm
|
|
61152
|
+
* is not on the screen: `find` leaves it out, and `world`'s `entityOf` answers nothing for an
|
|
61153
|
+
* entity it builds or holds, so a closed window's button is not reached by key (spec 33 B+D).
|
|
59863
61154
|
*
|
|
59864
61155
|
* @param root - The root the element belongs to.
|
|
59865
61156
|
* @param element - The element that entered.
|
|
@@ -59870,6 +61161,16 @@ function createReconciler(ctx, modules, fields) {
|
|
|
59870
61161
|
if (keys.has(element.key)) ctx.log.warn("ui:duplicate-key", { key: element.key });
|
|
59871
61162
|
else keys.set(element.key, element.entity);
|
|
59872
61163
|
state.byKey.set(root.entity, keys);
|
|
61164
|
+
shareKey(root, element);
|
|
61165
|
+
}
|
|
61166
|
+
/**
|
|
61167
|
+
* Registers the key of an element with `world`, so `entityOf` answers for it.
|
|
61168
|
+
*
|
|
61169
|
+
* @param root - The root the element belongs to.
|
|
61170
|
+
* @param element - An element of the root on the screen.
|
|
61171
|
+
*/
|
|
61172
|
+
function shareKey(root, element) {
|
|
61173
|
+
if (element.key === void 0 || isOwnKey(element.key)) return;
|
|
59873
61174
|
element.dropKey = ctx.deps.world.projection.registerKey(root.name, element.key, element.entity);
|
|
59874
61175
|
}
|
|
59875
61176
|
/**
|
|
@@ -59962,6 +61263,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
59962
61263
|
state.scrolls.add(entity);
|
|
59963
61264
|
element.scroll = scrollMotionOf(node);
|
|
59964
61265
|
}
|
|
61266
|
+
if (element.type === "anchor") state.anchors.set(entity, createAnchor());
|
|
59965
61267
|
modules.layout.attach(element);
|
|
59966
61268
|
element.basis = {
|
|
59967
61269
|
epoch: state.epoch,
|
|
@@ -60530,6 +61832,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60530
61832
|
if (hostsOf(element.node).length > 0) hostsMoved(state);
|
|
60531
61833
|
state.hosts.delete(element.entity);
|
|
60532
61834
|
state.scrolls.delete(element.entity);
|
|
61835
|
+
state.anchors.get(element.entity)?.held?.();
|
|
61836
|
+
state.anchors.delete(element.entity);
|
|
60533
61837
|
state.exiting.delete(element.entity);
|
|
60534
61838
|
state.leading.delete(element.entity);
|
|
60535
61839
|
state.overlays.delete(element.entity);
|
|
@@ -60648,12 +61952,14 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60648
61952
|
}
|
|
60649
61953
|
}
|
|
60650
61954
|
/**
|
|
60651
|
-
* Applies the solved rect of one element: a live one moves, a new one spawns its components.
|
|
61955
|
+
* Applies the solved rect of one element: a live one moves, a new one spawns its components. An
|
|
61956
|
+
* `<anchor>` and everything under it wait for the anchor pass, which places them by their targets.
|
|
60652
61957
|
*
|
|
60653
61958
|
* @param element - The element to apply.
|
|
60654
61959
|
* @param quiet - Whether a live element takes its rect with no motion.
|
|
60655
61960
|
*/
|
|
60656
61961
|
function applyElement(element, quiet) {
|
|
61962
|
+
if (!anchoring && state.anchors.size > 0 && isAnchored(element, lookup)) return;
|
|
60657
61963
|
const parent = parentRect(element);
|
|
60658
61964
|
if (element.live) applyLive(element, parent, quiet);
|
|
60659
61965
|
else applyFirst(element, parent);
|
|
@@ -60807,7 +62113,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60807
62113
|
/**
|
|
60808
62114
|
* Solves one root in a box and applies its rects: a root on the viewport when it is marked, a
|
|
60809
62115
|
* root in a slot also when its slot was resized. A root built aside waits while parts of it wait,
|
|
60810
|
-
* and is applied in parts.
|
|
62116
|
+
* and is applied in parts. A root shown before its parts were done is applied whole and still.
|
|
60811
62117
|
*
|
|
60812
62118
|
* @param root - The root.
|
|
60813
62119
|
* @param box - The viewport, or the slot's content box.
|
|
@@ -60827,8 +62133,12 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60827
62133
|
};
|
|
60828
62134
|
modules.layout.solve(element, box, lookup);
|
|
60829
62135
|
root.needsSolve = false;
|
|
62136
|
+
if (root.aside !== void 0) asideSolved = true;
|
|
60830
62137
|
if (root.aside !== void 0 && isAside(root.entity) && !element.live) parts.applyInParts(root, element, quiet);
|
|
60831
|
-
else
|
|
62138
|
+
else {
|
|
62139
|
+
applyRects(element, quiet || root.still === true);
|
|
62140
|
+
delete root.still;
|
|
62141
|
+
}
|
|
60832
62142
|
return true;
|
|
60833
62143
|
}
|
|
60834
62144
|
/**
|
|
@@ -60893,9 +62203,9 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60893
62203
|
* Keeps an element whose spawn has just been applied: the world calls it from the `Box` hook, at
|
|
60894
62204
|
* the flush of phase `layout`. Its enter hook waits for `playEntered`, so the game's systems see
|
|
60895
62205
|
* the entity first (F48). The hook itself plays at once, so they see the start pose it writes (F49);
|
|
60896
|
-
* `ui.enter` plays it again when one of them changed what it read. An element of a
|
|
60897
|
-
* aside plays nothing here: its enter waits for the swap
|
|
60898
|
-
* point of
|
|
62206
|
+
* `ui.enter` plays it again when one of them changed what it read. An element of a root built
|
|
62207
|
+
* aside or held warm plays nothing here: its enter waits for the swap or the open, and
|
|
62208
|
+
* `poseReleased` plays it at the same point of that frame (spec 31, spec 33 B+D).
|
|
60899
62209
|
*
|
|
60900
62210
|
* @param entity - The entity the `Box` was attached to.
|
|
60901
62211
|
*/
|
|
@@ -60905,7 +62215,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60905
62215
|
else entering.list.push(entity);
|
|
60906
62216
|
entering.count += 1;
|
|
60907
62217
|
const element = state.elements.get(entity);
|
|
60908
|
-
if (arrives(element) && !isAside(
|
|
62218
|
+
if (arrives(element) && !isAside(element.root)) modules.layout.pose(element, overlayOf(element) === void 0 ? void 0 : createSpan());
|
|
60909
62219
|
}
|
|
60910
62220
|
/**
|
|
60911
62221
|
* Plays the enter hooks of the elements a committed build released, at the end of the swap
|
|
@@ -60919,7 +62229,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60919
62229
|
for (let index = 0; index < entering.count; index += 1) {
|
|
60920
62230
|
const entity = entering.list[index];
|
|
60921
62231
|
const element = entity === void 0 ? void 0 : state.elements.get(entity);
|
|
60922
|
-
if (!arrives(element) || element.posed !== void 0 || isAside(element.
|
|
62232
|
+
if (!arrives(element) || element.posed !== void 0 || isAside(element.root)) continue;
|
|
60923
62233
|
modules.layout.pose(element, overlayOf(element) === void 0 ? void 0 : createSpan());
|
|
60924
62234
|
}
|
|
60925
62235
|
}
|
|
@@ -60927,33 +62237,39 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60927
62237
|
* Plays the enter hooks queued since the last call, in the order the elements came. The `ui.enter`
|
|
60928
62238
|
* system calls it in phase `sync`: after the game's systems, which may have written what a hook
|
|
60929
62239
|
* reads (a list's scroll), and before `renderer.sync`, so an element is never drawn at its rest
|
|
60930
|
-
* pose by mistake. An element despawned in between plays nothing. An element of a
|
|
60931
|
-
* aside stays queued, in its order, and plays in the first call after the swap
|
|
60932
|
-
* enter, posed by `poseReleased` in that frame's solve, its
|
|
60933
|
-
* start in the frame the
|
|
62240
|
+
* pose by mistake. An element despawned in between plays nothing. An element of a root built
|
|
62241
|
+
* aside or held warm stays queued, in its order, and plays in the first call after the swap or
|
|
62242
|
+
* the open (spec 31, spec 33 B+D): its enter, posed by `poseReleased` in that frame's solve, its
|
|
62243
|
+
* loop and the level of an overlay start in the frame the root is first drawn. While nothing was
|
|
62244
|
+
* queued since the last call and no root was released, the queue holds only held enters and is
|
|
62245
|
+
* not walked.
|
|
60934
62246
|
*/
|
|
60935
62247
|
function playEntered() {
|
|
60936
62248
|
const entering = state.entering;
|
|
62249
|
+
const version = ctx.deps.world.projection.membershipVersion();
|
|
62250
|
+
if (entering.count === heldEnters && version === enteredSeen) return;
|
|
60937
62251
|
let held = 0;
|
|
62252
|
+
enteredSeen = version;
|
|
60938
62253
|
for (let index = 0; index < entering.count; index += 1) {
|
|
60939
62254
|
const entity = entering.list[index];
|
|
60940
|
-
|
|
60941
|
-
if (
|
|
62255
|
+
const element = entity === void 0 ? void 0 : state.elements.get(entity);
|
|
62256
|
+
if (entity === void 0 || element === void 0) continue;
|
|
62257
|
+
if (isAside(element.root)) {
|
|
60942
62258
|
entering.list[held] = entity;
|
|
60943
62259
|
held += 1;
|
|
60944
|
-
} else playEnter(
|
|
62260
|
+
} else playEnter(element);
|
|
60945
62261
|
}
|
|
60946
62262
|
entering.count = held;
|
|
62263
|
+
heldEnters = held;
|
|
60947
62264
|
}
|
|
60948
62265
|
/**
|
|
60949
62266
|
* Plays the enter hook of an element whose spawn has been applied, once. A row a range change
|
|
60950
62267
|
* scrolled in is not new: it plays no `enter` hook, only its loop starts.
|
|
60951
62268
|
*
|
|
60952
|
-
* @param
|
|
62269
|
+
* @param element - The element the `Box` was attached to.
|
|
60953
62270
|
*/
|
|
60954
|
-
function playEnter(
|
|
60955
|
-
|
|
60956
|
-
if (element === void 0 || element.entered) return;
|
|
62271
|
+
function playEnter(element) {
|
|
62272
|
+
if (element.entered) return;
|
|
60957
62273
|
element.entered = true;
|
|
60958
62274
|
if (element.scrolledIn) modules.layout.loop(element);
|
|
60959
62275
|
else if (overlayOf(element) === void 0) modules.layout.enter(element);
|
|
@@ -61024,20 +62340,23 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61024
62340
|
}
|
|
61025
62341
|
}
|
|
61026
62342
|
/**
|
|
61027
|
-
* The live scroll containers
|
|
61028
|
-
*
|
|
61029
|
-
*
|
|
61030
|
-
* is
|
|
62343
|
+
* The live scroll containers. Read from the set the enter fills and the exit empties, so an idle
|
|
62344
|
+
* frame walks no other element. A scroll of a root built aside waits while parts of the root wait:
|
|
62345
|
+
* it is settled once the root is whole (spec 33 A7). Without `aside`, the scrolls the frame step
|
|
62346
|
+
* moves with the finger and ranges: a scroll of a root built aside or held warm is left out, as
|
|
62347
|
+
* nobody sees it and no finger reaches it, and it moves from the swap or the open on (spec 33 B+D).
|
|
61031
62348
|
*
|
|
61032
|
-
* @
|
|
62349
|
+
* @param aside - Whether the scrolls of roots built aside or held, once whole, are in the list.
|
|
62350
|
+
* @returns Those live elements whose tag is `scroll`: the reconciler's own list, valid until the
|
|
61033
62351
|
* next call.
|
|
61034
62352
|
*/
|
|
61035
|
-
function scrollContainers() {
|
|
62353
|
+
function scrollContainers(aside) {
|
|
61036
62354
|
while (scrollList.length > 0) scrollList.pop();
|
|
61037
62355
|
for (const entity of state.scrolls) {
|
|
61038
62356
|
const element = state.elements.get(entity);
|
|
61039
62357
|
if (element?.live !== true) continue;
|
|
61040
|
-
if (
|
|
62358
|
+
if (parts.working() && parts.waits(state.roots.get(element.root))) continue;
|
|
62359
|
+
if (!aside && isAsideScroll(element)) continue;
|
|
61041
62360
|
scrollList.push(element);
|
|
61042
62361
|
}
|
|
61043
62362
|
return scrollList;
|
|
@@ -61119,20 +62438,27 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61119
62438
|
}
|
|
61120
62439
|
}
|
|
61121
62440
|
/**
|
|
61122
|
-
* Finds the roots the last scene build committed
|
|
61123
|
-
*
|
|
61124
|
-
*
|
|
61125
|
-
*
|
|
62441
|
+
* Finds the roots the last scene build committed, and the held roots of the warm windows that
|
|
62442
|
+
* opened: a root counted aside that `world` builds or holds no more is released, the slots are
|
|
62443
|
+
* given out again, so a kept host takes its coming guest in the swap frame, and this frame's
|
|
62444
|
+
* solve poses the held enters (spec 31, spec 33 B+D). A root a discard dropped is gone from the
|
|
62445
|
+
* registry and is not counted. The roots are walked only when the membership of the world's
|
|
62446
|
+
* projections moved: every release moves it (a commit, an open, a discard), so windows held warm
|
|
62447
|
+
* and at rest, and a build between two of its moves, cost two numbers a frame. The budget is not
|
|
62448
|
+
* read here: a finite `left()` is a number the heap keeps, every frame of a build.
|
|
61126
62449
|
*/
|
|
61127
62450
|
function settleAside() {
|
|
61128
62451
|
if (state.asideRoots === 0) return;
|
|
62452
|
+
const version = ctx.deps.world.projection.membershipVersion();
|
|
62453
|
+
if (version === asideSeen) return;
|
|
62454
|
+
asideSeen = version;
|
|
61129
62455
|
let left = 0;
|
|
61130
62456
|
let committed = false;
|
|
61131
62457
|
for (const root of state.roots.values()) {
|
|
61132
62458
|
if (root.aside === void 0) continue;
|
|
61133
62459
|
if (isAside(root.entity)) left += 1;
|
|
61134
62460
|
else {
|
|
61135
|
-
|
|
62461
|
+
releaseRoot(root);
|
|
61136
62462
|
committed = true;
|
|
61137
62463
|
}
|
|
61138
62464
|
}
|
|
@@ -61142,6 +62468,17 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61142
62468
|
released = true;
|
|
61143
62469
|
}
|
|
61144
62470
|
/**
|
|
62471
|
+
* Releases a root `world` builds or holds no more. A root shown before its parts were done (a
|
|
62472
|
+
* warm window opened while it was built) has the rest made now, in one block, and is laid out
|
|
62473
|
+
* and applied whole in this frame's solve, with no motion, so no half-built frame is drawn.
|
|
62474
|
+
*
|
|
62475
|
+
* @param root - A root counted aside that `world` builds or holds no more.
|
|
62476
|
+
*/
|
|
62477
|
+
function releaseRoot(root) {
|
|
62478
|
+
if (parts.finish(root)) root.still = true;
|
|
62479
|
+
delete root.aside;
|
|
62480
|
+
}
|
|
62481
|
+
/**
|
|
61145
62482
|
* The part of a scene build `ui` does, which `world` asks through `onBuild` (spec 31): done when no
|
|
61146
62483
|
* root of the build is dirty (its tree not diffed yet, or the layout engine not loaded), has
|
|
61147
62484
|
* parked parts, waits for its solve or is applied in parts (spec 33 A8). A root whose first diff
|
|
@@ -61175,9 +62512,11 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61175
62512
|
reorderRoots();
|
|
61176
62513
|
settlePopups(ctx, state, unmountRoot);
|
|
61177
62514
|
fields.pull();
|
|
61178
|
-
const containers = scrollContainers();
|
|
62515
|
+
const containers = scrollContainers(false);
|
|
62516
|
+
const rangesAside = asideSolved || parts.hasLanded();
|
|
62517
|
+
asideSolved = false;
|
|
61179
62518
|
modules.layout.scroll(containers, lookup, time);
|
|
61180
|
-
range.step(containers);
|
|
62519
|
+
range.step(rangesAside ? scrollContainers(true) : containers);
|
|
61181
62520
|
markResizedTexts(ctx, state, modules.layout);
|
|
61182
62521
|
markResizedIcons(ctx, state, modules.layout);
|
|
61183
62522
|
const viewportChanged = modules.styles.useViewport(ctx.deps.renderer.viewport.size());
|
|
@@ -61228,7 +62567,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61228
62567
|
parts.applyParts();
|
|
61229
62568
|
const changed = layOutRoots(viewportBox);
|
|
61230
62569
|
if (changed) ctx.deps.time.wake();
|
|
61231
|
-
if (changed || rendered > 0 || parts.hasLanded()) modules.layout.settleScroll(scrollContainers(), lookup, time);
|
|
62570
|
+
if (changed || rendered > 0 || parts.hasLanded()) modules.layout.settleScroll(scrollContainers(true), lookup, time, isAsideScroll);
|
|
61232
62571
|
rendered = 0;
|
|
61233
62572
|
settleOverlays(ctx, state, modules.layout);
|
|
61234
62573
|
if (state.risen.size > 0) {
|
|
@@ -61332,6 +62671,21 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61332
62671
|
hostsMoved(state);
|
|
61333
62672
|
}
|
|
61334
62673
|
/**
|
|
62674
|
+
* Applies the rect the anchor pass gave one element of an `<anchor>` subtree, as the solve
|
|
62675
|
+
* applies any other element.
|
|
62676
|
+
*
|
|
62677
|
+
* @param element - The anchor or an element under it.
|
|
62678
|
+
* @param quiet - Whether a live element takes its rect with no motion.
|
|
62679
|
+
*/
|
|
62680
|
+
function applyAnchored(element, quiet) {
|
|
62681
|
+
anchoring = true;
|
|
62682
|
+
try {
|
|
62683
|
+
applyElement(element, quiet);
|
|
62684
|
+
} finally {
|
|
62685
|
+
anchoring = false;
|
|
62686
|
+
}
|
|
62687
|
+
}
|
|
62688
|
+
/**
|
|
61335
62689
|
* Re-resolves the style of one element whose pointer or focus flag changed: a press, a release,
|
|
61336
62690
|
* the mouse coming over it or leaving it, the keyboard focus arriving or leaving. A new rect
|
|
61337
62691
|
* waits for the solve; a new look and a new rest pose apply now. Only this element is restyled:
|
|
@@ -61370,7 +62724,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61370
62724
|
playEntered,
|
|
61371
62725
|
sweep,
|
|
61372
62726
|
converged,
|
|
61373
|
-
asideBuilt
|
|
62727
|
+
asideBuilt,
|
|
62728
|
+
applyAnchored
|
|
61374
62729
|
};
|
|
61375
62730
|
}
|
|
61376
62731
|
//#endregion
|
|
@@ -61528,6 +62883,7 @@ function createJsxApi(ctx, modules) {
|
|
|
61528
62883
|
playEntered: frame.playEntered,
|
|
61529
62884
|
converged: frame.converged,
|
|
61530
62885
|
asideBuilt: frame.asideBuilt,
|
|
62886
|
+
applyAnchored: frame.applyAnchored,
|
|
61531
62887
|
key: (input) => focus.key(input),
|
|
61532
62888
|
blur: focus.blur
|
|
61533
62889
|
};
|
|
@@ -61816,16 +63172,20 @@ function writeRest(ctx, element, parent) {
|
|
|
61816
63172
|
if (visual !== void 0) projection.setRest(element.entity, visual.component, visual.value);
|
|
61817
63173
|
}
|
|
61818
63174
|
/**
|
|
61819
|
-
* Tells whether an element waits for the swap of a scene `world` builds aside (spec 31)
|
|
61820
|
-
*
|
|
61821
|
-
*
|
|
63175
|
+
* Tells whether an element waits for the swap of a scene `world` builds aside (spec 31), or for the
|
|
63176
|
+
* open of a window held warm (spec 33 B+D): it has not entered, and it or its root belongs to the
|
|
63177
|
+
* build or to the held view. An element a held root makes while no warm work runs is not marked
|
|
63178
|
+
* by `world`; its root is. Its hooks wait for its enter at the swap; a change before it plays no
|
|
63179
|
+
* motion and is written at once, so the enter starts from where it stands.
|
|
61822
63180
|
*
|
|
61823
63181
|
* @param ctx - Domain context of the ui plugin.
|
|
61824
63182
|
* @param element - The element a hook would play on.
|
|
61825
63183
|
* @returns True while its motions are held.
|
|
61826
63184
|
*/
|
|
61827
63185
|
function isHeld(ctx, element) {
|
|
61828
|
-
|
|
63186
|
+
if (element.entered) return false;
|
|
63187
|
+
const projection = ctx.deps.world.projection;
|
|
63188
|
+
return projection.isBuilding(element.entity) || projection.isBuilding(element.root);
|
|
61829
63189
|
}
|
|
61830
63190
|
/**
|
|
61831
63191
|
* Asks the projection for the handle of a ui-owned entity. A foreign owner is an error in the
|
|
@@ -62302,7 +63662,9 @@ function freeNode(state, element) {
|
|
|
62302
63662
|
}
|
|
62303
63663
|
/**
|
|
62304
63664
|
* Re-places the children of one parent: remove all, insert in order. Once per parent per
|
|
62305
|
-
* reconcile — per exiting child it made a thousand-row churn quadratic (spike P4, point 4).
|
|
63665
|
+
* reconcile — per exiting child it made a thousand-row churn quadratic (spike P4, point 4). An
|
|
63666
|
+
* `<anchor>` is left out: its node is a tree of its own, which the anchor pass lays out at the
|
|
63667
|
+
* size of its targets, so it takes no room in the flow of its parent.
|
|
62306
63668
|
*
|
|
62307
63669
|
* @param state - The layout state.
|
|
62308
63670
|
* @param parent - The element whose child list changed.
|
|
@@ -62315,7 +63677,7 @@ function placeChildren(state, parent, children) {
|
|
|
62315
63677
|
let index = 0;
|
|
62316
63678
|
for (const child of children) {
|
|
62317
63679
|
const childNode = state.byEntity.get(child.entity);
|
|
62318
|
-
if (childNode === void 0) continue;
|
|
63680
|
+
if (childNode === void 0 || child.type === "anchor") continue;
|
|
62319
63681
|
node.insertChild(childNode, index);
|
|
62320
63682
|
index += 1;
|
|
62321
63683
|
}
|
|
@@ -63172,7 +64534,7 @@ function releaseVelocity(state) {
|
|
|
63172
64534
|
* @param motion - Its motion.
|
|
63173
64535
|
* @param owned - Whether the samples are this press's.
|
|
63174
64536
|
*/
|
|
63175
|
-
function letGo(state, container, motion, owned) {
|
|
64537
|
+
function letGo$1(state, container, motion, owned) {
|
|
63176
64538
|
const velocity = owned ? releaseVelocity(state) : 0;
|
|
63177
64539
|
const snap = snapOf(container);
|
|
63178
64540
|
if (snap !== void 0) {
|
|
@@ -63319,7 +64681,7 @@ function stepOne(ctx, state, container, lookup, pointer, time) {
|
|
|
63319
64681
|
const content = contentOf(container, lookup);
|
|
63320
64682
|
if (content === void 0 || !ecs.has(container.entity, Scroll)) return false;
|
|
63321
64683
|
if (pressed) hold(state, container, motion, pointer);
|
|
63322
|
-
else if (motion.mode === "held") letGo(state, container, motion, released);
|
|
64684
|
+
else if (motion.mode === "held") letGo$1(state, container, motion, released);
|
|
63323
64685
|
if (motion.mode === "fling") fling(motion, time);
|
|
63324
64686
|
else if (motion.mode === "glide") glide(motion, time);
|
|
63325
64687
|
show(ctx, state, container, content, motion);
|
|
@@ -63427,19 +64789,36 @@ function settle(ctx, state, container, content, motion) {
|
|
|
63427
64789
|
show(ctx, state, container, content, motion);
|
|
63428
64790
|
}
|
|
63429
64791
|
/**
|
|
64792
|
+
* Ends a glide at its target at once: the scroll stands where its `offset` prop puts it.
|
|
64793
|
+
*
|
|
64794
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64795
|
+
* @param state - The layout state, which keeps the patches.
|
|
64796
|
+
* @param container - The scroll element.
|
|
64797
|
+
* @param content - Its content element.
|
|
64798
|
+
* @param motion - Its motion, gliding.
|
|
64799
|
+
*/
|
|
64800
|
+
function standAtTarget(ctx, state, container, content, motion) {
|
|
64801
|
+
motion.offset = motion.to;
|
|
64802
|
+
stop(motion);
|
|
64803
|
+
show(ctx, state, container, content, motion);
|
|
64804
|
+
}
|
|
64805
|
+
/**
|
|
63430
64806
|
* Settles every scroll on what the solve and the render of this frame gave it. A scroll the solve
|
|
63431
64807
|
* just spawned takes its place at its `offset` prop. A placed one keeps inside a new range at
|
|
63432
64808
|
* once, a running glide's target too, and glides to a new `offset` prop; the same value on a
|
|
63433
|
-
* re-render does nothing, and a scroll the finger holds only remembers it. A scroll
|
|
63434
|
-
*
|
|
64809
|
+
* re-render does nothing, and a scroll the finger holds only remembers it. A scroll nobody sees
|
|
64810
|
+
* yet (`stands`: a root built aside or held warm) stands at its target at once instead of gliding,
|
|
64811
|
+
* so no glide plays hidden or at its open. A scroll left moving wakes the loop the way
|
|
64812
|
+
* `stepScroll` does: not at a time scale of 0, where it stands.
|
|
63435
64813
|
*
|
|
63436
64814
|
* @param ctx - Domain context of the ui plugin.
|
|
63437
64815
|
* @param state - The layout state, which keeps the patches.
|
|
63438
64816
|
* @param containers - The live scroll elements.
|
|
63439
64817
|
* @param lookup - How a child entity becomes its element.
|
|
63440
64818
|
* @param time - The frame's `Time`.
|
|
64819
|
+
* @param stands - Whether a scroll is not on the screen yet; none for every scroll on it.
|
|
63441
64820
|
*/
|
|
63442
|
-
function settleScroll(ctx, state, containers, lookup, time) {
|
|
64821
|
+
function settleScroll(ctx, state, containers, lookup, time, stands) {
|
|
63443
64822
|
let moving = false;
|
|
63444
64823
|
for (const container of containers) {
|
|
63445
64824
|
const motion = container.scroll;
|
|
@@ -63447,6 +64826,7 @@ function settleScroll(ctx, state, containers, lookup, time) {
|
|
|
63447
64826
|
if (motion === void 0 || content === void 0) continue;
|
|
63448
64827
|
if (motion.placed) settle(ctx, state, container, content, motion);
|
|
63449
64828
|
else place$1(ctx, container, content, motion);
|
|
64829
|
+
if (motion.mode === "glide" && stands?.(container) === true) standAtTarget(ctx, state, container, content, motion);
|
|
63450
64830
|
if (motion.mode !== "still") moving = true;
|
|
63451
64831
|
}
|
|
63452
64832
|
if (moving && time.delta > 0) ctx.deps.time.wake();
|
|
@@ -63555,7 +64935,8 @@ function frameOf(state, rect, node) {
|
|
|
63555
64935
|
};
|
|
63556
64936
|
}
|
|
63557
64937
|
/**
|
|
63558
|
-
* Walks the element tree and writes the rect of every element in root coordinates.
|
|
64938
|
+
* Walks the element tree and writes the rect of every element in root coordinates. An `<anchor>`
|
|
64939
|
+
* and everything under it are left to the anchor pass, which places them by their targets.
|
|
63559
64940
|
*
|
|
63560
64941
|
* @param state - The layout state, for the node of each element.
|
|
63561
64942
|
* @param element - The element to place.
|
|
@@ -63565,7 +64946,7 @@ function frameOf(state, rect, node) {
|
|
|
63565
64946
|
*/
|
|
63566
64947
|
function place(state, element, frame, lookup) {
|
|
63567
64948
|
const node = state.byEntity.get(element.entity);
|
|
63568
|
-
if (node === void 0) return false;
|
|
64949
|
+
if (node === void 0 || element.type === "anchor") return false;
|
|
63569
64950
|
const width = node.getComputedWidth();
|
|
63570
64951
|
const height = node.getComputedHeight();
|
|
63571
64952
|
const fitted = element.style.fit === "contain" ? fitInto(frame.content, width, height) : void 0;
|
|
@@ -63784,7 +65165,7 @@ function createLayoutApi(ctx) {
|
|
|
63784
65165
|
},
|
|
63785
65166
|
settled: (element) => canDespawn(element),
|
|
63786
65167
|
scroll: (containers, lookup, time) => stepScroll(ctx, state, containers, lookup, time),
|
|
63787
|
-
settleScroll: (containers, lookup, time) => settleScroll(ctx, state, containers, lookup, time),
|
|
65168
|
+
settleScroll: (containers, lookup, time, stands) => settleScroll(ctx, state, containers, lookup, time, stands),
|
|
63788
65169
|
clampScroll: (container, contentHeight, lookup) => clampScroll(ctx, state, container, contentHeight, lookup),
|
|
63789
65170
|
scrollTo: (container, to, lookup) => scrollTo(ctx, state, container, to, lookup),
|
|
63790
65171
|
windowOf,
|
|
@@ -63798,6 +65179,792 @@ function createLayoutApi(ctx) {
|
|
|
63798
65179
|
};
|
|
63799
65180
|
}
|
|
63800
65181
|
//#endregion
|
|
65182
|
+
//#region src/plugins/ui/anchor.ts
|
|
65183
|
+
/**
|
|
65184
|
+
* @file ui plugin — the anchor pass, the system `ui.anchor` of phase `layout`, right after `ui.solve`.
|
|
65185
|
+
* Every `<anchor>` takes the drawn rect of its targets (`drawn.ts`), padded and mapped into the space
|
|
65186
|
+
* of its parent, in the frame its targets were laid out. Its subtree is a Yoga tree of its own, laid
|
|
65187
|
+
* out only when the anchor's size changed or a node of it is dirty (a child restyled, measured
|
|
65188
|
+
* again, added or taken out); a pure move shifts the rects in place. A change of the targets applies the subtree as the solve applies any element, so the
|
|
65189
|
+
* anchor's `change.Box` motion plays; following a target never starts a motion. A frame of a still
|
|
65190
|
+
* anchor, and of one that follows a moving target, allocates nothing.
|
|
65191
|
+
*/
|
|
65192
|
+
/** How deep a parent chain is followed; deeper is treated as a loop. */
|
|
65193
|
+
const MAX_DEPTH = 32;
|
|
65194
|
+
/** How far a rect may move off a pure shift and still count as one: rounding, not a relayout. */
|
|
65195
|
+
const SHIFT_EPSILON = 1e-6;
|
|
65196
|
+
/** The patch that only marks a component changed: its fields were written in place. */
|
|
65197
|
+
const NO_PATCH = Object.freeze({});
|
|
65198
|
+
/** The fields of the anchor's `Transform` a follow writes, held from a loop while it follows. */
|
|
65199
|
+
const FOLLOWED_FIELDS = Object.freeze(["x", "y"]);
|
|
65200
|
+
/** The style fields an anchor takes from its targets: a style that sets one is ignored there. */
|
|
65201
|
+
const PLACED_FIELDS = [
|
|
65202
|
+
"width",
|
|
65203
|
+
"height",
|
|
65204
|
+
"position",
|
|
65205
|
+
"left",
|
|
65206
|
+
"top",
|
|
65207
|
+
"right",
|
|
65208
|
+
"bottom"
|
|
65209
|
+
];
|
|
65210
|
+
/**
|
|
65211
|
+
* Tells whether a value is a target: an object with a string `projection` and a string `key`.
|
|
65212
|
+
*
|
|
65213
|
+
* @param value - One entry of `to`.
|
|
65214
|
+
* @returns True for a target.
|
|
65215
|
+
* @example
|
|
65216
|
+
* ```ts
|
|
65217
|
+
* isTarget({ projection: "hud", key: "coins" }); // true
|
|
65218
|
+
* ```
|
|
65219
|
+
*/
|
|
65220
|
+
function isTarget(value) {
|
|
65221
|
+
if (typeof value !== "object" || value === null) return false;
|
|
65222
|
+
const target = value;
|
|
65223
|
+
return typeof target.projection === "string" && typeof target.key === "string";
|
|
65224
|
+
}
|
|
65225
|
+
/**
|
|
65226
|
+
* The targets a `to` prop names, when it names one or a list of them.
|
|
65227
|
+
*
|
|
65228
|
+
* @param to - What the render wrote.
|
|
65229
|
+
* @returns The target or the list, or `undefined` for anything else: the anchor is not shown.
|
|
65230
|
+
* @example
|
|
65231
|
+
* ```ts
|
|
65232
|
+
* targetsOf("seat0"); // undefined
|
|
65233
|
+
* ```
|
|
65234
|
+
*/
|
|
65235
|
+
function targetsOf(to) {
|
|
65236
|
+
if (isTarget(to)) return to;
|
|
65237
|
+
return Array.isArray(to) && to.every((entry) => isTarget(entry)) ? to : void 0;
|
|
65238
|
+
}
|
|
65239
|
+
/**
|
|
65240
|
+
* Tells whether two rects are the same in every field.
|
|
65241
|
+
*
|
|
65242
|
+
* @param first - One rect.
|
|
65243
|
+
* @param second - The other.
|
|
65244
|
+
* @returns True when nothing differs.
|
|
65245
|
+
* @example
|
|
65246
|
+
* ```ts
|
|
65247
|
+
* sameRect({ x: 0, y: 0, w: 4, h: 4 }, { x: 0, y: 0, w: 4, h: 4 }); // true
|
|
65248
|
+
* ```
|
|
65249
|
+
*/
|
|
65250
|
+
function sameRect(first, second) {
|
|
65251
|
+
return first.x === second.x && first.y === second.y && first.w === second.w && first.h === second.h;
|
|
65252
|
+
}
|
|
65253
|
+
/**
|
|
65254
|
+
* Tells whether the targets of an anchor are others than the last time it was shown: a new `to`,
|
|
65255
|
+
* or keys that resolve to other entities. The entities of this frame become the shown ones.
|
|
65256
|
+
*
|
|
65257
|
+
* @param anchor - Its record.
|
|
65258
|
+
* @returns True when the set changed.
|
|
65259
|
+
*/
|
|
65260
|
+
function retargeted(anchor) {
|
|
65261
|
+
let changed = anchor.retarget || anchor.count !== anchor.shownCount;
|
|
65262
|
+
for (let index = 0; index < anchor.count; index += 1) {
|
|
65263
|
+
const entity = anchor.seen[index] ?? 0;
|
|
65264
|
+
if (anchor.shown[index] !== entity) changed = true;
|
|
65265
|
+
if (index < anchor.shown.length) anchor.shown[index] = entity;
|
|
65266
|
+
else anchor.shown.push(entity);
|
|
65267
|
+
}
|
|
65268
|
+
anchor.shownCount = anchor.count;
|
|
65269
|
+
anchor.retarget = false;
|
|
65270
|
+
return changed;
|
|
65271
|
+
}
|
|
65272
|
+
/**
|
|
65273
|
+
* Notes where the motion that starts now lands: the anchor's rest pose. A follow while it plays
|
|
65274
|
+
* carries it by how far the rest moved since.
|
|
65275
|
+
*
|
|
65276
|
+
* @param element - The anchor, its rest pose recorded.
|
|
65277
|
+
* @param anchor - Its record.
|
|
65278
|
+
*/
|
|
65279
|
+
function aim(element, anchor) {
|
|
65280
|
+
anchor.aim.x = element.rest.x;
|
|
65281
|
+
anchor.aim.y = element.rest.y;
|
|
65282
|
+
anchor.wrote.x = NaN;
|
|
65283
|
+
anchor.wrote.y = NaN;
|
|
65284
|
+
}
|
|
65285
|
+
/**
|
|
65286
|
+
* Gives the position of an anchor back to its tracks, when a follow held it from a loop.
|
|
65287
|
+
*
|
|
65288
|
+
* @param anchor - Its record.
|
|
65289
|
+
*/
|
|
65290
|
+
function letGo(anchor) {
|
|
65291
|
+
anchor.held?.();
|
|
65292
|
+
anchor.held = void 0;
|
|
65293
|
+
}
|
|
65294
|
+
/**
|
|
65295
|
+
* Creates the set of rects the anchor pass made. Its own function, because lint rule L5 refuses a
|
|
65296
|
+
* collection built inside an exported declaration.
|
|
65297
|
+
*
|
|
65298
|
+
* @returns An empty set.
|
|
65299
|
+
*/
|
|
65300
|
+
function rectSet() {
|
|
65301
|
+
return /* @__PURE__ */ new WeakSet();
|
|
65302
|
+
}
|
|
65303
|
+
/**
|
|
65304
|
+
* Tells whether an element moved by more than the shift of its anchor: it was laid out anew, not
|
|
65305
|
+
* only carried along.
|
|
65306
|
+
*
|
|
65307
|
+
* @param element - An element under an anchor whose rect was written.
|
|
65308
|
+
* @param shift - How far the anchor moved.
|
|
65309
|
+
* @returns True when its size or its place inside the anchor changed.
|
|
65310
|
+
*/
|
|
65311
|
+
function relaidOut(element, shift) {
|
|
65312
|
+
const { rect, previous } = element;
|
|
65313
|
+
return rect.w !== previous.w || rect.h !== previous.h || Math.abs(rect.x - previous.x - shift.x) > SHIFT_EPSILON || Math.abs(rect.y - previous.y - shift.y) > SHIFT_EPSILON;
|
|
65314
|
+
}
|
|
65315
|
+
/**
|
|
65316
|
+
* Tells whether a motion that can end still plays on an element, or one that never ends.
|
|
65317
|
+
*
|
|
65318
|
+
* @param element - The element.
|
|
65319
|
+
* @returns `"finite"` while a motion that ends plays, `"endless"` while the element runs a loop or
|
|
65320
|
+
* only a track that repeats forever plays, `"none"` otherwise.
|
|
65321
|
+
*/
|
|
65322
|
+
function motionOn(element) {
|
|
65323
|
+
if (!still(element)) return "finite";
|
|
65324
|
+
if (element.loop !== void 0) return "endless";
|
|
65325
|
+
for (const handle of element.handles) if (handle.active()) return "endless";
|
|
65326
|
+
return "none";
|
|
65327
|
+
}
|
|
65328
|
+
/**
|
|
65329
|
+
* Builds the anchor pass. Its records live in the jsx state, made when an anchor enters and
|
|
65330
|
+
* dropped when it despawns.
|
|
65331
|
+
*
|
|
65332
|
+
* @param ctx - Domain context of the ui plugin.
|
|
65333
|
+
* @param jsx - The jsx module, which applies a rect the way the solve does.
|
|
65334
|
+
* @returns The step the system `ui.anchor` runs once a frame.
|
|
65335
|
+
*/
|
|
65336
|
+
function createAnchorPass(ctx, jsx) {
|
|
65337
|
+
const state = ctx.state.jsx;
|
|
65338
|
+
const layout = ctx.state.layout;
|
|
65339
|
+
const ecs = ctx.deps.world.ecs;
|
|
65340
|
+
const projection = ctx.deps.world.projection;
|
|
65341
|
+
const reader = readerOf(ctx);
|
|
65342
|
+
const lookup = (entity) => state.elements.get(entity);
|
|
65343
|
+
const found = {
|
|
65344
|
+
shown: false,
|
|
65345
|
+
missing: false,
|
|
65346
|
+
own: void 0
|
|
65347
|
+
};
|
|
65348
|
+
const owned = rectSet();
|
|
65349
|
+
const slot = ownRect(0, 0, 0, 0);
|
|
65350
|
+
const shift = {
|
|
65351
|
+
x: 0,
|
|
65352
|
+
y: 0
|
|
65353
|
+
};
|
|
65354
|
+
/**
|
|
65355
|
+
* Moves an element to a rect: its `previous` takes the rect it had, by value, and its rect the new
|
|
65356
|
+
* numbers, both in place. The first time, the element gets two rects of the pass's own shape, so
|
|
65357
|
+
* every later frame writes doubles with no allocation. A rect that changes marks the element moved.
|
|
65358
|
+
*
|
|
65359
|
+
* @param element - The element.
|
|
65360
|
+
* @param to - The new rect, in root coordinates.
|
|
65361
|
+
*/
|
|
65362
|
+
function writeRect(element, to) {
|
|
65363
|
+
if (!owned.has(element.rect)) {
|
|
65364
|
+
const { rect, previous } = element;
|
|
65365
|
+
element.rect = ownRect(rect.x, rect.y, rect.w, rect.h);
|
|
65366
|
+
element.previous = ownRect(previous.x, previous.y, previous.w, previous.h);
|
|
65367
|
+
owned.add(element.rect);
|
|
65368
|
+
}
|
|
65369
|
+
const { rect, previous } = element;
|
|
65370
|
+
if (sameRect(rect, to)) return;
|
|
65371
|
+
previous.x = rect.x;
|
|
65372
|
+
previous.y = rect.y;
|
|
65373
|
+
previous.w = rect.w;
|
|
65374
|
+
previous.h = rect.h;
|
|
65375
|
+
rect.x = to.x;
|
|
65376
|
+
rect.y = to.y;
|
|
65377
|
+
rect.w = to.w;
|
|
65378
|
+
rect.h = to.h;
|
|
65379
|
+
element.moved = true;
|
|
65380
|
+
}
|
|
65381
|
+
/**
|
|
65382
|
+
* Tells whether an element or one above it is leaving: it no longer follows anything.
|
|
65383
|
+
*
|
|
65384
|
+
* @param element - The anchor.
|
|
65385
|
+
* @returns True while it or an ancestor plays its exit.
|
|
65386
|
+
*/
|
|
65387
|
+
function leaving(element) {
|
|
65388
|
+
let current = element;
|
|
65389
|
+
while (current !== void 0) {
|
|
65390
|
+
if (state.exiting.has(current.entity)) return true;
|
|
65391
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
65392
|
+
}
|
|
65393
|
+
return false;
|
|
65394
|
+
}
|
|
65395
|
+
/**
|
|
65396
|
+
* Reads the props of a new render of an anchor: another `to` retargets it, and a dev build names
|
|
65397
|
+
* a style that sets what the targets decide, once.
|
|
65398
|
+
*
|
|
65399
|
+
* @param element - The anchor.
|
|
65400
|
+
* @param anchor - Its record.
|
|
65401
|
+
*/
|
|
65402
|
+
function readNode(element, anchor) {
|
|
65403
|
+
if (element.node === anchor.node) return;
|
|
65404
|
+
const to = targetsOf(element.node.props.to);
|
|
65405
|
+
if (anchor.node !== void 0 && !sameValue(anchor.to, to)) anchor.retarget = true;
|
|
65406
|
+
anchor.node = element.node;
|
|
65407
|
+
anchor.to = to;
|
|
65408
|
+
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__) warnStyle(element, anchor);
|
|
65409
|
+
}
|
|
65410
|
+
/**
|
|
65411
|
+
* Names, once, an anchor whose style sets what its targets decide. Its own function: a closure
|
|
65412
|
+
* over `element` in `readNode` would make every call of it, every frame, allocate its context.
|
|
65413
|
+
*
|
|
65414
|
+
* @param element - The anchor.
|
|
65415
|
+
* @param anchor - Its record.
|
|
65416
|
+
*/
|
|
65417
|
+
function warnStyle(element, anchor) {
|
|
65418
|
+
if (anchor.warned.style || !PLACED_FIELDS.some((field) => element.style[field] !== void 0)) return;
|
|
65419
|
+
anchor.warned.style = true;
|
|
65420
|
+
ctx.log.warn("ui:anchor-style", { key: element.key ?? element.identity });
|
|
65421
|
+
}
|
|
65422
|
+
/**
|
|
65423
|
+
* Tells whether an entity is the anchor or drawn under it.
|
|
65424
|
+
*
|
|
65425
|
+
* @param entity - A target's entity.
|
|
65426
|
+
* @param anchor - The anchor's entity.
|
|
65427
|
+
* @returns True for the anchor and everything in its subtree.
|
|
65428
|
+
*/
|
|
65429
|
+
function within(entity, anchor) {
|
|
65430
|
+
let current = entity;
|
|
65431
|
+
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
65432
|
+
if (current === anchor) return true;
|
|
65433
|
+
current = upOf(reader, current);
|
|
65434
|
+
}
|
|
65435
|
+
return false;
|
|
65436
|
+
}
|
|
65437
|
+
/**
|
|
65438
|
+
* Resolves one target: notes the entity its key names, and adds its drawn rect to the union when
|
|
65439
|
+
* it is shown. A key that names no entity, and a target under the anchor itself, add nothing.
|
|
65440
|
+
*
|
|
65441
|
+
* @param element - The anchor.
|
|
65442
|
+
* @param anchor - Its record.
|
|
65443
|
+
* @param target - One entry of `to`.
|
|
65444
|
+
*/
|
|
65445
|
+
function visit(element, anchor, target) {
|
|
65446
|
+
const entity = projection.entityOf(target.projection, target.key);
|
|
65447
|
+
const at = anchor.count;
|
|
65448
|
+
if (at < anchor.seen.length) anchor.seen[at] = entity ?? 0;
|
|
65449
|
+
else anchor.seen.push(entity ?? 0);
|
|
65450
|
+
anchor.count += 1;
|
|
65451
|
+
if (entity === void 0) {
|
|
65452
|
+
found.missing = true;
|
|
65453
|
+
return;
|
|
65454
|
+
}
|
|
65455
|
+
if (within(entity, element.entity)) {
|
|
65456
|
+
found.own = target;
|
|
65457
|
+
return;
|
|
65458
|
+
}
|
|
65459
|
+
if (!drawnInto(reader, entity, anchor.part, anchor.pose)) return;
|
|
65460
|
+
if (found.shown) unionInto(anchor.screen, anchor.part);
|
|
65461
|
+
else {
|
|
65462
|
+
anchor.screen.x = anchor.part.x;
|
|
65463
|
+
anchor.screen.y = anchor.part.y;
|
|
65464
|
+
anchor.screen.w = anchor.part.w;
|
|
65465
|
+
anchor.screen.h = anchor.part.h;
|
|
65466
|
+
found.shown = true;
|
|
65467
|
+
}
|
|
65468
|
+
}
|
|
65469
|
+
/**
|
|
65470
|
+
* Resolves the targets of an anchor into the union of the shown ones, in screen reference units,
|
|
65471
|
+
* and logs what a dev build or the author must know: a key that named no entity for two frames in
|
|
65472
|
+
* a row, a target under the anchor itself.
|
|
65473
|
+
*
|
|
65474
|
+
* @param element - The anchor.
|
|
65475
|
+
* @param anchor - Its record.
|
|
65476
|
+
* @returns True when at least one target is shown.
|
|
65477
|
+
*/
|
|
65478
|
+
function resolve(element, anchor) {
|
|
65479
|
+
const to = anchor.to;
|
|
65480
|
+
found.shown = false;
|
|
65481
|
+
found.missing = false;
|
|
65482
|
+
found.own = void 0;
|
|
65483
|
+
anchor.count = 0;
|
|
65484
|
+
if (isTargetList(to)) for (const target of to) visit(element, anchor, target);
|
|
65485
|
+
else if (to !== void 0) visit(element, anchor, to);
|
|
65486
|
+
anchor.missing = found.missing ? anchor.missing + 1 : 0;
|
|
65487
|
+
if (anchor.missing >= 2) warnMissing(element, anchor);
|
|
65488
|
+
if (found.own !== void 0) refuseOwn(element, anchor, found.own);
|
|
65489
|
+
return found.shown;
|
|
65490
|
+
}
|
|
65491
|
+
/**
|
|
65492
|
+
* Names, in a dev build, an anchor a key of which named no entity two frames in a row, once.
|
|
65493
|
+
*
|
|
65494
|
+
* @param element - The anchor.
|
|
65495
|
+
* @param anchor - Its record.
|
|
65496
|
+
*/
|
|
65497
|
+
function warnMissing(element, anchor) {
|
|
65498
|
+
if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__ || anchor.warned.missing) return;
|
|
65499
|
+
anchor.warned.missing = true;
|
|
65500
|
+
ctx.log.warn("ui:anchor-target-missing", {
|
|
65501
|
+
key: element.key ?? element.identity,
|
|
65502
|
+
to: anchor.to
|
|
65503
|
+
});
|
|
65504
|
+
}
|
|
65505
|
+
/**
|
|
65506
|
+
* Logs, once per anchor, a target that lies inside the anchor itself: it is treated as not shown.
|
|
65507
|
+
*
|
|
65508
|
+
* @param element - The anchor.
|
|
65509
|
+
* @param anchor - Its record.
|
|
65510
|
+
* @param target - The target under the anchor.
|
|
65511
|
+
*/
|
|
65512
|
+
function refuseOwn(element, anchor, target) {
|
|
65513
|
+
if (anchor.warned.own) return;
|
|
65514
|
+
anchor.warned.own = true;
|
|
65515
|
+
ctx.log.error("ui:anchor-own-child", {
|
|
65516
|
+
key: element.key ?? element.identity,
|
|
65517
|
+
target: target.key
|
|
65518
|
+
}, /* @__PURE__ */ new Error(`[game] An anchor cannot point at its own child "${target.key}".\n Point it at an element outside the anchor.`));
|
|
65519
|
+
}
|
|
65520
|
+
/**
|
|
65521
|
+
* Maps the union of the targets into the root coordinates of the anchor: through the root pose of
|
|
65522
|
+
* the entity it is drawn under (its parent, or the slot of its root), then by its parent's rect,
|
|
65523
|
+
* then padded outward.
|
|
65524
|
+
*
|
|
65525
|
+
* @param element - The anchor.
|
|
65526
|
+
* @param anchor - Its record: `screen` is read, `next` written.
|
|
65527
|
+
* @returns False when the space it is drawn in is collapsed: nothing of it could be seen.
|
|
65528
|
+
*/
|
|
65529
|
+
function mapInto(element, anchor) {
|
|
65530
|
+
const above = element.parent ?? state.roots.get(element.root)?.slot ?? 0;
|
|
65531
|
+
const pose = anchor.pose;
|
|
65532
|
+
if (above === 0 || !drawnPoseInto(reader, above, pose)) {
|
|
65533
|
+
pose.x = 0;
|
|
65534
|
+
pose.y = 0;
|
|
65535
|
+
pose.scale = 1;
|
|
65536
|
+
pose.pivot.x = 0;
|
|
65537
|
+
pose.pivot.y = 0;
|
|
65538
|
+
}
|
|
65539
|
+
const scale = pose.scale;
|
|
65540
|
+
if (scale <= 0) return false;
|
|
65541
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65542
|
+
const given = element.node.props.pad;
|
|
65543
|
+
const pad = typeof given === "number" && Number.isFinite(given) ? given : 0;
|
|
65544
|
+
const { screen, next } = anchor;
|
|
65545
|
+
next.x = pose.pivot.x + (screen.x - pose.x) / scale + (parent?.rect.x ?? 0) - pad;
|
|
65546
|
+
next.y = pose.pivot.y + (screen.y - pose.y) / scale + (parent?.rect.y ?? 0) - pad;
|
|
65547
|
+
next.w = screen.w / scale + 2 * pad;
|
|
65548
|
+
next.h = screen.h / scale + 2 * pad;
|
|
65549
|
+
return next.w > 0 && next.h > 0;
|
|
65550
|
+
}
|
|
65551
|
+
/**
|
|
65552
|
+
* Writes the alpha of the anchor's visual, which fades its subtree with it: 0 hides the anchor the
|
|
65553
|
+
* way a transparent element is hidden, out of the draw and the hit test. Only a value that
|
|
65554
|
+
* differs is written.
|
|
65555
|
+
*
|
|
65556
|
+
* @param element - The anchor.
|
|
65557
|
+
* @param alpha - The alpha to draw it at.
|
|
65558
|
+
*/
|
|
65559
|
+
function fadeTo(element, alpha) {
|
|
65560
|
+
const shape = ecs.get(element.entity, Shape);
|
|
65561
|
+
if (shape !== void 0) {
|
|
65562
|
+
if (shape.alpha === alpha) return;
|
|
65563
|
+
shape.alpha = alpha;
|
|
65564
|
+
ecs.set(element.entity, Shape, NO_PATCH);
|
|
65565
|
+
return;
|
|
65566
|
+
}
|
|
65567
|
+
const panel = ecs.get(element.entity, NineSlice);
|
|
65568
|
+
if (panel === void 0 || panel.alpha === alpha) return;
|
|
65569
|
+
panel.alpha = alpha;
|
|
65570
|
+
ecs.set(element.entity, NineSlice, NO_PATCH);
|
|
65571
|
+
}
|
|
65572
|
+
/**
|
|
65573
|
+
* Hides an anchor none of whose targets is shown. A placed one stays, drawn at alpha 0; one never
|
|
65574
|
+
* placed waits with no components.
|
|
65575
|
+
*
|
|
65576
|
+
* @param element - The anchor.
|
|
65577
|
+
* @param anchor - Its record.
|
|
65578
|
+
*/
|
|
65579
|
+
function hide(element, anchor) {
|
|
65580
|
+
anchor.hidden = true;
|
|
65581
|
+
if (anchor.placed) fadeTo(element, 0);
|
|
65582
|
+
}
|
|
65583
|
+
/**
|
|
65584
|
+
* Shows an anchor again at the alpha of its style.
|
|
65585
|
+
*
|
|
65586
|
+
* @param element - The anchor.
|
|
65587
|
+
* @param anchor - Its record.
|
|
65588
|
+
*/
|
|
65589
|
+
function show(element, anchor) {
|
|
65590
|
+
if (!anchor.hidden) return;
|
|
65591
|
+
anchor.hidden = false;
|
|
65592
|
+
fadeTo(element, element.style.alpha ?? 1);
|
|
65593
|
+
}
|
|
65594
|
+
/**
|
|
65595
|
+
* Writes an element's `Box` from its rect, field by field on the stored value. Nothing is written
|
|
65596
|
+
* while it holds the same numbers, or before the `Box` landed.
|
|
65597
|
+
*
|
|
65598
|
+
* @param element - The element.
|
|
65599
|
+
*/
|
|
65600
|
+
function writeBox(element) {
|
|
65601
|
+
const box = ecs.get(element.entity, Box);
|
|
65602
|
+
if (box === void 0 || sameRect(box, element.rect)) return;
|
|
65603
|
+
box.x = element.rect.x;
|
|
65604
|
+
box.y = element.rect.y;
|
|
65605
|
+
box.w = element.rect.w;
|
|
65606
|
+
box.h = element.rect.h;
|
|
65607
|
+
ecs.set(element.entity, Box, NO_PATCH);
|
|
65608
|
+
}
|
|
65609
|
+
/**
|
|
65610
|
+
* Lays the subtree of an anchor out in its rect: one Yoga calculation of the anchor's own tree at
|
|
65611
|
+
* its size, then the rects of everything under it written in place.
|
|
65612
|
+
*
|
|
65613
|
+
* @param element - The anchor, its rect set.
|
|
65614
|
+
*/
|
|
65615
|
+
function layOut(element) {
|
|
65616
|
+
const yoga = layout.yoga;
|
|
65617
|
+
const node = layout.byEntity.get(element.entity);
|
|
65618
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65619
|
+
node.setWidth(element.rect.w);
|
|
65620
|
+
node.setHeight(element.rect.h);
|
|
65621
|
+
node.calculateLayout(element.rect.w, element.rect.h, yoga.DIRECTION_LTR);
|
|
65622
|
+
layout.solves += 1;
|
|
65623
|
+
placeUnder(element);
|
|
65624
|
+
}
|
|
65625
|
+
/**
|
|
65626
|
+
* Writes the rects of the children of a laid-out element in root coordinates, and of everything
|
|
65627
|
+
* under them: the computed offsets from its rect, a fitted child centred in its content box at
|
|
65628
|
+
* the scale that fits it. A nested anchor is left to its own place in the pass.
|
|
65629
|
+
*
|
|
65630
|
+
* @param parent - The element whose rect is written.
|
|
65631
|
+
*/
|
|
65632
|
+
function placeUnder(parent) {
|
|
65633
|
+
const yoga = layout.yoga;
|
|
65634
|
+
const node = layout.byEntity.get(parent.entity);
|
|
65635
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65636
|
+
const left = node.getComputedPadding(yoga.EDGE_LEFT);
|
|
65637
|
+
const top = node.getComputedPadding(yoga.EDGE_TOP);
|
|
65638
|
+
const content = {
|
|
65639
|
+
x: parent.rect.x + left,
|
|
65640
|
+
y: parent.rect.y + top,
|
|
65641
|
+
w: parent.rect.w - left - node.getComputedPadding(yoga.EDGE_RIGHT),
|
|
65642
|
+
h: parent.rect.h - top - node.getComputedPadding(yoga.EDGE_BOTTOM)
|
|
65643
|
+
};
|
|
65644
|
+
for (const child of parent.children) {
|
|
65645
|
+
const element = lookup(child);
|
|
65646
|
+
const childNode = element === void 0 ? void 0 : layout.byEntity.get(element.entity);
|
|
65647
|
+
if (element === void 0 || childNode === void 0 || element.type === "anchor") continue;
|
|
65648
|
+
const w = childNode.getComputedWidth();
|
|
65649
|
+
const h = childNode.getComputedHeight();
|
|
65650
|
+
const fitted = element.style.fit === "contain" ? fitInto(content, w, h) : void 0;
|
|
65651
|
+
slot.x = fitted?.rect.x ?? parent.rect.x + childNode.getComputedLeft();
|
|
65652
|
+
slot.y = fitted?.rect.y ?? parent.rect.y + childNode.getComputedTop();
|
|
65653
|
+
slot.w = w;
|
|
65654
|
+
slot.h = h;
|
|
65655
|
+
writeRect(element, slot);
|
|
65656
|
+
if ((fitted?.fit ?? 1) !== element.fit) {
|
|
65657
|
+
element.fit = fitted?.fit ?? 1;
|
|
65658
|
+
element.moved = true;
|
|
65659
|
+
}
|
|
65660
|
+
placeUnder(element);
|
|
65661
|
+
}
|
|
65662
|
+
}
|
|
65663
|
+
/**
|
|
65664
|
+
* Carries everything under an element along by a shift, rects in place. A nested anchor is left
|
|
65665
|
+
* to its own place in the pass.
|
|
65666
|
+
*
|
|
65667
|
+
* @param parent - The element whose children move, by `shift`.
|
|
65668
|
+
* @param mark - Whether they stay marked moved, for an application that follows.
|
|
65669
|
+
*/
|
|
65670
|
+
function shiftUnder(parent, mark) {
|
|
65671
|
+
for (const child of parent.children) {
|
|
65672
|
+
const element = lookup(child);
|
|
65673
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65674
|
+
const { rect } = element;
|
|
65675
|
+
slot.x = rect.x + shift.x;
|
|
65676
|
+
slot.y = rect.y + shift.y;
|
|
65677
|
+
slot.w = rect.w;
|
|
65678
|
+
slot.h = rect.h;
|
|
65679
|
+
writeRect(element, slot);
|
|
65680
|
+
if (!mark) element.moved = false;
|
|
65681
|
+
shiftUnder(element, mark);
|
|
65682
|
+
}
|
|
65683
|
+
}
|
|
65684
|
+
/**
|
|
65685
|
+
* Writes the `Box` of an element and of everything under it from their rects. A nested anchor is
|
|
65686
|
+
* left to its own place in the pass.
|
|
65687
|
+
*
|
|
65688
|
+
* @param element - The anchor or an element under it.
|
|
65689
|
+
*/
|
|
65690
|
+
function writeBoxes(element) {
|
|
65691
|
+
writeBox(element);
|
|
65692
|
+
for (const child of element.children) {
|
|
65693
|
+
const childElement = lookup(child);
|
|
65694
|
+
if (childElement !== void 0 && childElement.type !== "anchor") writeBoxes(childElement);
|
|
65695
|
+
}
|
|
65696
|
+
}
|
|
65697
|
+
/**
|
|
65698
|
+
* Applies an element and everything under it the way the solve applies a root: a new element
|
|
65699
|
+
* spawns its components, a moved live one is committed and plays its `change` hooks. A nested
|
|
65700
|
+
* anchor is left to its own place in the pass.
|
|
65701
|
+
*
|
|
65702
|
+
* @param element - The anchor or an element under it.
|
|
65703
|
+
*/
|
|
65704
|
+
function applyTree(element) {
|
|
65705
|
+
jsx.applyAnchored(element, false);
|
|
65706
|
+
for (const child of element.children) {
|
|
65707
|
+
const childElement = lookup(child);
|
|
65708
|
+
if (childElement !== void 0 && childElement.type !== "anchor") applyTree(childElement);
|
|
65709
|
+
}
|
|
65710
|
+
}
|
|
65711
|
+
/**
|
|
65712
|
+
* Applies what a relayout of an anchor's subtree moved. A child carried along only writes its
|
|
65713
|
+
* `Box`; one laid out anew is applied as the solve applies it, with its `change` hooks, unless
|
|
65714
|
+
* the anchor's size followed its targets: then it takes its rect and its rest pose with no motion.
|
|
65715
|
+
*
|
|
65716
|
+
* @param parent - The element whose children were laid out, its anchor moved by `shift`.
|
|
65717
|
+
* @param followed - Whether the anchor's size changed by following its targets.
|
|
65718
|
+
*/
|
|
65719
|
+
function applyUnder(parent, followed) {
|
|
65720
|
+
for (const child of parent.children) {
|
|
65721
|
+
const element = lookup(child);
|
|
65722
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65723
|
+
if (!element.live) jsx.applyAnchored(element, false);
|
|
65724
|
+
else if (element.moved && !relaidOut(element, shift)) {
|
|
65725
|
+
writeBox(element);
|
|
65726
|
+
element.moved = false;
|
|
65727
|
+
} else if (element.moved && followed) {
|
|
65728
|
+
jsx.applyAnchored(element, true);
|
|
65729
|
+
settlePose(element);
|
|
65730
|
+
} else if (element.moved) jsx.applyAnchored(element, false);
|
|
65731
|
+
applyUnder(element, followed);
|
|
65732
|
+
}
|
|
65733
|
+
}
|
|
65734
|
+
/**
|
|
65735
|
+
* Brings an element under an anchor to the rest pose a follow gave it, with no motion: a `Transform`
|
|
65736
|
+
* a motion is on is taken through a 0 ms rest track, which cuts a finite motion and re-bases a
|
|
65737
|
+
* loop, as a repose does; one nothing moves is written at once.
|
|
65738
|
+
*
|
|
65739
|
+
* @param element - The element, its rest pose recorded.
|
|
65740
|
+
*/
|
|
65741
|
+
function settlePose(element) {
|
|
65742
|
+
if (!element.live || element.type === "content" || !ecs.has(element.entity, Transform)) return;
|
|
65743
|
+
if (motionOn(element) === "none") ecs.set(element.entity, Transform, {
|
|
65744
|
+
...element.rest,
|
|
65745
|
+
pivot: { ...element.rest.pivot }
|
|
65746
|
+
});
|
|
65747
|
+
else handleOf(ctx, element)?.toRest(Transform, { ms: 0 });
|
|
65748
|
+
}
|
|
65749
|
+
/**
|
|
65750
|
+
* Carries a motion that ends by how far the targets moved since it began: the position the motion
|
|
65751
|
+
* wrote this frame, moved by the rest's shift from where the motion lands. The motion writes its
|
|
65752
|
+
* own value again in the next frame, and the carry is added once more, so it lands on the moved
|
|
65753
|
+
* rest instead of jumping there at its end.
|
|
65754
|
+
*
|
|
65755
|
+
* @param element - The anchor.
|
|
65756
|
+
* @param anchor - Its record.
|
|
65757
|
+
* @param pose - Its stored `Transform`.
|
|
65758
|
+
*/
|
|
65759
|
+
function carry(element, anchor, pose) {
|
|
65760
|
+
const { aim: aimed, track, wrote } = anchor;
|
|
65761
|
+
const rest = element.rest;
|
|
65762
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) ecs.set(element.entity, Transform, { pivot: {
|
|
65763
|
+
x: rest.pivot.x,
|
|
65764
|
+
y: rest.pivot.y
|
|
65765
|
+
} });
|
|
65766
|
+
if (pose.x !== wrote.x) track.x = pose.x;
|
|
65767
|
+
if (pose.y !== wrote.y) track.y = pose.y;
|
|
65768
|
+
const x = track.x + rest.x - aimed.x;
|
|
65769
|
+
const y = track.y + rest.y - aimed.y;
|
|
65770
|
+
if (x === pose.x && y === pose.y) return;
|
|
65771
|
+
pose.x = x;
|
|
65772
|
+
pose.y = y;
|
|
65773
|
+
wrote.x = x;
|
|
65774
|
+
wrote.y = y;
|
|
65775
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65776
|
+
}
|
|
65777
|
+
/**
|
|
65778
|
+
* Writes the anchor's `Transform` from its rest pose. While a motion that ends plays (the glide of
|
|
65779
|
+
* a change of targets, a look tween), the motion is carried by the follow and lands on the rest;
|
|
65780
|
+
* the pose is owed to the rest until it ends. Under a loop the follow holds `x` and `y` from every
|
|
65781
|
+
* track while it moves (`world.projection.mute`), and the loop goes on from where the anchor
|
|
65782
|
+
* stands once it is let go. Each field is written on the stored value.
|
|
65783
|
+
*
|
|
65784
|
+
* @param element - The anchor.
|
|
65785
|
+
* @param anchor - Its record.
|
|
65786
|
+
*/
|
|
65787
|
+
function writePose(element, anchor) {
|
|
65788
|
+
const pose = ecs.get(element.entity, Transform);
|
|
65789
|
+
if (!element.live || pose === void 0) return;
|
|
65790
|
+
const motion = motionOn(element);
|
|
65791
|
+
if (motion === "finite") {
|
|
65792
|
+
anchor.owed = true;
|
|
65793
|
+
carry(element, anchor, pose);
|
|
65794
|
+
return;
|
|
65795
|
+
}
|
|
65796
|
+
anchor.owed = false;
|
|
65797
|
+
if (motion === "endless" && anchor.held === void 0) anchor.held = projection.mute(element.entity, Transform, FOLLOWED_FIELDS);
|
|
65798
|
+
const rest = element.rest;
|
|
65799
|
+
if (samePose(pose, rest)) return;
|
|
65800
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) {
|
|
65801
|
+
ecs.set(element.entity, Transform, {
|
|
65802
|
+
...rest,
|
|
65803
|
+
pivot: { ...rest.pivot }
|
|
65804
|
+
});
|
|
65805
|
+
return;
|
|
65806
|
+
}
|
|
65807
|
+
pose.x = rest.x;
|
|
65808
|
+
pose.y = rest.y;
|
|
65809
|
+
pose.rotation = rest.rotation;
|
|
65810
|
+
pose.scale = rest.scale;
|
|
65811
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65812
|
+
}
|
|
65813
|
+
/**
|
|
65814
|
+
* Moves the anchor's rest pose to where its rect and its parent's put it now, its size, and so its
|
|
65815
|
+
* pivot, unchanged: the position of `restTransform`, worked out here, since a fractional number
|
|
65816
|
+
* handed to or returned from a call is boxed. The rest is written in place, and the world's copy
|
|
65817
|
+
* of it is left behind until the anchor stands still. Then the `Transform` follows.
|
|
65818
|
+
*
|
|
65819
|
+
* @param element - The anchor.
|
|
65820
|
+
* @param anchor - Its record.
|
|
65821
|
+
* @returns True when the rest pose moved.
|
|
65822
|
+
*/
|
|
65823
|
+
function follow(element, anchor) {
|
|
65824
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65825
|
+
const { rect, rest, style } = element;
|
|
65826
|
+
const centreX = rect.w / 2;
|
|
65827
|
+
const centreY = rect.h / 2;
|
|
65828
|
+
const x = rect.x - (parent?.rect.x ?? 0) + centreX + (rest.pivot.x + (style.offsetX ?? 0) - centreX);
|
|
65829
|
+
const y = rect.y - (parent?.rect.y ?? 0) + centreY + (rest.pivot.y + (style.offsetY ?? 0) - centreY);
|
|
65830
|
+
if (x === rest.x && y === rest.y) return false;
|
|
65831
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65832
|
+
rest.x = x;
|
|
65833
|
+
rest.y = y;
|
|
65834
|
+
anchor.stale = true;
|
|
65835
|
+
writePose(element, anchor);
|
|
65836
|
+
return true;
|
|
65837
|
+
}
|
|
65838
|
+
/**
|
|
65839
|
+
* Places an anchor for the first time: its rect, its subtree laid out, and everything applied as
|
|
65840
|
+
* a new root is, so its components spawn with their rects and its `enter` hooks play.
|
|
65841
|
+
*
|
|
65842
|
+
* @param element - The anchor.
|
|
65843
|
+
* @param anchor - Its record, `next` holding its rect.
|
|
65844
|
+
*/
|
|
65845
|
+
function place(element, anchor) {
|
|
65846
|
+
const { next } = anchor;
|
|
65847
|
+
element.fit = 1;
|
|
65848
|
+
writeRect(element, next);
|
|
65849
|
+
layOut(element);
|
|
65850
|
+
applyTree(element);
|
|
65851
|
+
aim(element, anchor);
|
|
65852
|
+
anchor.placed = true;
|
|
65853
|
+
}
|
|
65854
|
+
/**
|
|
65855
|
+
* Moves an anchor to its new targets the way a solve moves an element: its `change.Box` motion
|
|
65856
|
+
* plays, and so do the hooks of what moved under it.
|
|
65857
|
+
*
|
|
65858
|
+
* @param element - The anchor.
|
|
65859
|
+
* @param anchor - Its record, `next` holding its new rect.
|
|
65860
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65861
|
+
*/
|
|
65862
|
+
function retarget(element, anchor, relayout) {
|
|
65863
|
+
const next = anchor.next;
|
|
65864
|
+
const rect = element.rect;
|
|
65865
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65866
|
+
shift.x = next.x - rect.x;
|
|
65867
|
+
shift.y = next.y - rect.y;
|
|
65868
|
+
writeRect(element, next);
|
|
65869
|
+
if (resized || relayout) layOut(element);
|
|
65870
|
+
else shiftUnder(element, true);
|
|
65871
|
+
anchor.owed = false;
|
|
65872
|
+
anchor.stale = false;
|
|
65873
|
+
letGo(anchor);
|
|
65874
|
+
applyTree(element);
|
|
65875
|
+
aim(element, anchor);
|
|
65876
|
+
}
|
|
65877
|
+
/**
|
|
65878
|
+
* Keeps an anchor on targets that moved, resized or stood: no motion starts. A pure move writes
|
|
65879
|
+
* every number in place and leaves the `Box` values for the frame the anchor stands (a fractional
|
|
65880
|
+
* number written into a stored `Box` field is boxed); a new size or a dirty node lays the
|
|
65881
|
+
* subtree out again.
|
|
65882
|
+
*
|
|
65883
|
+
* @param element - The anchor.
|
|
65884
|
+
* @param anchor - Its record, `next` holding its rect of this frame.
|
|
65885
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65886
|
+
* @returns True when the anchor's rest pose moved.
|
|
65887
|
+
*/
|
|
65888
|
+
function keep(element, anchor, relayout) {
|
|
65889
|
+
const { next } = anchor;
|
|
65890
|
+
const rect = element.rect;
|
|
65891
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65892
|
+
shift.x = next.x - rect.x;
|
|
65893
|
+
shift.y = next.y - rect.y;
|
|
65894
|
+
writeRect(element, next);
|
|
65895
|
+
if (resized) {
|
|
65896
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65897
|
+
layOut(element);
|
|
65898
|
+
jsx.applyAnchored(element, true);
|
|
65899
|
+
anchor.stale = false;
|
|
65900
|
+
writePose(element, anchor);
|
|
65901
|
+
applyUnder(element, true);
|
|
65902
|
+
return true;
|
|
65903
|
+
}
|
|
65904
|
+
if (relayout) {
|
|
65905
|
+
layOut(element);
|
|
65906
|
+
applyUnder(element, false);
|
|
65907
|
+
writeBox(element);
|
|
65908
|
+
} else if (shift.x !== 0 || shift.y !== 0) {
|
|
65909
|
+
shiftUnder(element, false);
|
|
65910
|
+
anchor.boxes = true;
|
|
65911
|
+
}
|
|
65912
|
+
element.moved = false;
|
|
65913
|
+
return follow(element, anchor);
|
|
65914
|
+
}
|
|
65915
|
+
/**
|
|
65916
|
+
* Places one anchor for this frame: its targets resolved, then placed the first time, moved to
|
|
65917
|
+
* new targets, kept on moving ones, or hidden while none is shown. Its owed pose and the world's
|
|
65918
|
+
* copy of its rest catch up once nothing moves it.
|
|
65919
|
+
*
|
|
65920
|
+
* @param entity - The anchor's entity.
|
|
65921
|
+
* @param anchor - Its record.
|
|
65922
|
+
*/
|
|
65923
|
+
function placeAnchor(entity, anchor) {
|
|
65924
|
+
const element = lookup(entity);
|
|
65925
|
+
if (element === void 0) return;
|
|
65926
|
+
if (leaving(element)) {
|
|
65927
|
+
letGo(anchor);
|
|
65928
|
+
return;
|
|
65929
|
+
}
|
|
65930
|
+
if (projection.isBuilding(element.root)) return;
|
|
65931
|
+
readNode(element, anchor);
|
|
65932
|
+
if (!resolve(element, anchor) || !mapInto(element, anchor)) {
|
|
65933
|
+
hide(element, anchor);
|
|
65934
|
+
return;
|
|
65935
|
+
}
|
|
65936
|
+
const relayout = layout.byEntity.get(entity)?.isDirty() === true;
|
|
65937
|
+
if (!anchor.placed) {
|
|
65938
|
+
place(element, anchor);
|
|
65939
|
+
retargeted(anchor);
|
|
65940
|
+
anchor.hidden = false;
|
|
65941
|
+
return;
|
|
65942
|
+
}
|
|
65943
|
+
let moved = false;
|
|
65944
|
+
if (retargeted(anchor)) retarget(element, anchor, relayout);
|
|
65945
|
+
else moved = keep(element, anchor, relayout);
|
|
65946
|
+
show(element, anchor);
|
|
65947
|
+
if (anchor.owed && !moved) writePose(element, anchor);
|
|
65948
|
+
if (moved) return;
|
|
65949
|
+
if (anchor.stale) {
|
|
65950
|
+
ctx.deps.world.projection.setRest(entity, Transform, element.rest);
|
|
65951
|
+
anchor.stale = false;
|
|
65952
|
+
}
|
|
65953
|
+
if (anchor.boxes) {
|
|
65954
|
+
writeBoxes(element);
|
|
65955
|
+
anchor.boxes = false;
|
|
65956
|
+
}
|
|
65957
|
+
letGo(anchor);
|
|
65958
|
+
}
|
|
65959
|
+
return () => {
|
|
65960
|
+
if (state.anchors.size === 0) return;
|
|
65961
|
+
for (const entity of state.anchors.keys()) {
|
|
65962
|
+
const anchor = state.anchors.get(entity);
|
|
65963
|
+
if (anchor !== void 0) placeAnchor(entity, anchor);
|
|
65964
|
+
}
|
|
65965
|
+
};
|
|
65966
|
+
}
|
|
65967
|
+
//#endregion
|
|
63801
65968
|
//#region src/plugins/ui/hot.ts
|
|
63802
65969
|
/** The global the footer of `@moku-labs/game/hot` calls. */
|
|
63803
65970
|
const HOT_GLOBAL = "__moku_hot";
|
|
@@ -64339,7 +66506,17 @@ function registerComponents(ctx, jsx) {
|
|
|
64339
66506
|
for (const feature of ctx.deps.flow.features.all()) for (const entry of feature.description.ui ?? []) if (isComponent(entry)) jsx.register(entry);
|
|
64340
66507
|
}
|
|
64341
66508
|
/**
|
|
64342
|
-
*
|
|
66509
|
+
* Tells whether a renderer draws the views: one chose a backend at its start. It registers its own
|
|
66510
|
+
* part of a scene build on the same condition, and a scene is built aside only then.
|
|
66511
|
+
*
|
|
66512
|
+
* @param ctx - Domain context of the ui plugin.
|
|
66513
|
+
* @returns True when the renderer draws; false while it is inert or unsupported.
|
|
66514
|
+
*/
|
|
66515
|
+
function drawsViews(ctx) {
|
|
66516
|
+
return ctx.deps.renderer.host.kind() !== "none";
|
|
66517
|
+
}
|
|
66518
|
+
/**
|
|
66519
|
+
* Opens the three systems of phase `layout`, the system `ui.enter` of phase `sync`, the seven world
|
|
64343
66520
|
* hooks of `Tree`, `Box`, `Pressed` and `PointerOver`, the two that tell the hosting step a view
|
|
64344
66521
|
* lost its `Parent` or its `Held` (a view freed so may hang under its host again), the listener
|
|
64345
66522
|
* that asks for every root to be built again after a restore or a load, the two effect handlers,
|
|
@@ -64347,9 +66524,11 @@ function registerComponents(ctx, jsx) {
|
|
|
64347
66524
|
* step, the three tap listeners (the `LocalWrite` patch, the pointer tap that clears the keyboard
|
|
64348
66525
|
* focus, and the tap that starts or ends the editing of a text field), the pointer door that opens
|
|
64349
66526
|
* the keyboard inside the DOM listener, the key listener of the focus and `LocalWrite` as an input
|
|
64350
|
-
* control, so the cursor shows a hand over a local-state button, and
|
|
64351
|
-
* (`onBuild`: the roots built aside are reconciled and solved, spec
|
|
64352
|
-
* tap counter of `DebugTrigger` and its check of a view that takes
|
|
66527
|
+
* control, so the cursor shows a hand over a local-state button, and, with a renderer that draws,
|
|
66528
|
+
* `ui`'s part of a scene build (`onBuild`: the roots built aside are reconciled and solved, spec
|
|
66529
|
+
* 31). On an agent page also the tap counter of `DebugTrigger` and its check of a view that takes
|
|
66530
|
+
* no press. The third system of `layout`, `ui.anchor`, runs after the solve and places every
|
|
66531
|
+
* `<anchor>` on its targets.
|
|
64353
66532
|
*
|
|
64354
66533
|
* The `Box` hook plays an element's enter hook and queues it, so the game's systems see its start
|
|
64355
66534
|
* pose (F49); `ui.enter` starts its loop after them and before the frame is drawn, and plays the
|
|
@@ -64363,6 +66542,7 @@ function registerComponents(ctx, jsx) {
|
|
|
64363
66542
|
function openRegistrations(ctx, jsx, layout) {
|
|
64364
66543
|
const ecs = ctx.deps.world.ecs;
|
|
64365
66544
|
const projection = ctx.deps.world.projection;
|
|
66545
|
+
const anchors = createAnchorPass(ctx, jsx);
|
|
64366
66546
|
ctx.state.layout.cleanups.push(ecs.system(system({
|
|
64367
66547
|
name: "ui.reconcile",
|
|
64368
66548
|
phase: "layout",
|
|
@@ -64373,6 +66553,11 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
64373
66553
|
phase: "layout",
|
|
64374
66554
|
query: [],
|
|
64375
66555
|
run: (_rows, frame) => jsx.solve(frame.time)
|
|
66556
|
+
})), ecs.system(system({
|
|
66557
|
+
name: "ui.anchor",
|
|
66558
|
+
phase: "layout",
|
|
66559
|
+
query: [],
|
|
66560
|
+
run: anchors
|
|
64376
66561
|
})), ecs.system(system({
|
|
64377
66562
|
name: "ui.enter",
|
|
64378
66563
|
phase: "sync",
|
|
@@ -64381,9 +66566,10 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
64381
66566
|
})), ecs.onAdded(Tree, (entity) => {
|
|
64382
66567
|
const place = projection.keyOf(entity);
|
|
64383
66568
|
jsx.mountRoot(entity, place?.projection ?? "ui", ecs.get(entity, Layer)?.name ?? "ui");
|
|
64384
|
-
}), ecs.onRemoved(Tree, (entity) => jsx.unmountRoot(entity)), ecs.onAdded(Box, (entity) => jsx.queueEnter(entity)), projection.onConverged(jsx.converged),
|
|
66569
|
+
}), ecs.onRemoved(Tree, (entity) => jsx.unmountRoot(entity)), ecs.onAdded(Box, (entity) => jsx.queueEnter(entity)), projection.onConverged(jsx.converged), ecs.onAdded(Pressed, (entity) => jsx.markPointer(entity, "pressed", true)), ecs.onRemoved(Pressed, (entity) => jsx.markPointer(entity, "pressed", false)), ecs.onAdded(PointerOver, (entity) => jsx.markPointer(entity, "hover", true)), ecs.onRemoved(PointerOver, (entity) => jsx.markPointer(entity, "hover", false)), ecs.onRemoved(Parent, () => hostsMoved(ctx.state.jsx)), ecs.onRemoved(Held, () => hostsMoved(ctx.state.jsx)), ctx.deps.flow.fx.handle("popup", layout.popupHandler(jsx)), ctx.deps.flow.fx.handle("guide", layout.guideHandler()), ctx.deps.flow.fx.onHint((hint) => {
|
|
64385
66570
|
ctx.state.jsx.hints.push(hint);
|
|
64386
66571
|
}), ctx.deps.input.onTap(jsx.applyTap), ctx.deps.input.onTap(() => jsx.blur()), ctx.deps.input.onTap(jsx.tapped), ctx.deps.input.onPointer(jsx.pointer), ctx.deps.input.onKey(jsx.key), ctx.deps.input.controls.add(LocalWrite), () => jsx.releaseHosted(), () => ecs.despawnOwnedBy(UI_OWNER));
|
|
66572
|
+
if (drawsViews(ctx)) ctx.state.layout.cleanups.push(projection.onBuild(jsx.asideBuilt));
|
|
64387
66573
|
if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) ctx.state.layout.cleanups.push(ctx.deps.input.onTap((entity) => debugTap(ctx, entity)), ecs.onAdded(DebugTrigger, (entity) => checkTrigger(ctx, entity)));
|
|
64388
66574
|
}
|
|
64389
66575
|
/**
|
|
@@ -64439,6 +66625,7 @@ function stopUi(state) {
|
|
|
64439
66625
|
state.jsx.risen.clear();
|
|
64440
66626
|
state.jsx.released.clear();
|
|
64441
66627
|
state.jsx.scrolls.clear();
|
|
66628
|
+
state.jsx.anchors.clear();
|
|
64442
66629
|
state.jsx.remount = false;
|
|
64443
66630
|
state.jsx.asideRoots = 0;
|
|
64444
66631
|
state.jsx.hints.length = 0;
|
|
@@ -64718,121 +66905,21 @@ function createModules(ctx) {
|
|
|
64718
66905
|
};
|
|
64719
66906
|
}
|
|
64720
66907
|
/**
|
|
64721
|
-
* Creates the ui API: the
|
|
66908
|
+
* Creates the ui API: the six members a game calls, flat.
|
|
64722
66909
|
*
|
|
64723
66910
|
* @param ctx - Kernel context of the ui plugin.
|
|
64724
66911
|
* @returns The plugin API.
|
|
64725
66912
|
*/
|
|
64726
66913
|
function createUiApi(ctx) {
|
|
64727
|
-
const
|
|
66914
|
+
const uctx = withDeps(ctx);
|
|
66915
|
+
const { jsx } = createModules(uctx);
|
|
64728
66916
|
return {
|
|
64729
66917
|
tree: jsx.tree,
|
|
64730
66918
|
find: jsx.find,
|
|
64731
66919
|
lint: jsx.lint,
|
|
64732
66920
|
fill: jsx.fill,
|
|
64733
|
-
scroll: jsx.scroll
|
|
64734
|
-
|
|
64735
|
-
}
|
|
64736
|
-
//#endregion
|
|
64737
|
-
//#region src/plugins/ui/jsx/state.ts
|
|
64738
|
-
/**
|
|
64739
|
-
* Creates an empty map. Its own non-exported function, because lint rule L5 refuses a collection
|
|
64740
|
-
* built inside an exported declaration.
|
|
64741
|
-
*
|
|
64742
|
-
* @returns A map with nothing in it.
|
|
64743
|
-
*/
|
|
64744
|
-
function emptyMap$1() {
|
|
64745
|
-
return /* @__PURE__ */ new Map();
|
|
64746
|
-
}
|
|
64747
|
-
/**
|
|
64748
|
-
* Creates an empty set, for the same reason as `emptyMap`.
|
|
64749
|
-
*
|
|
64750
|
-
* @returns A set with nothing in it.
|
|
64751
|
-
*/
|
|
64752
|
-
function emptySet() {
|
|
64753
|
-
return /* @__PURE__ */ new Set();
|
|
64754
|
-
}
|
|
64755
|
-
/**
|
|
64756
|
-
* Creates the text input branch: no hidden input, nothing edited, an empty mirror.
|
|
64757
|
-
*
|
|
64758
|
-
* @returns The text state.
|
|
64759
|
-
*/
|
|
64760
|
-
function createTextState() {
|
|
64761
|
-
return {
|
|
64762
|
-
element: void 0,
|
|
64763
|
-
editing: void 0,
|
|
64764
|
-
mirror: {
|
|
64765
|
-
value: "",
|
|
64766
|
-
selectionStart: 0,
|
|
64767
|
-
selectionEnd: 0,
|
|
64768
|
-
direction: "none"
|
|
64769
|
-
},
|
|
64770
|
-
composing: void 0,
|
|
64771
|
-
keyboard: {
|
|
64772
|
-
inset: 0,
|
|
64773
|
-
innerHeight: 0,
|
|
64774
|
-
lift: 0
|
|
64775
|
-
},
|
|
64776
|
-
lifted: void 0,
|
|
64777
|
-
placed: void 0,
|
|
64778
|
-
watching: void 0,
|
|
64779
|
-
cleanups: []
|
|
64780
|
-
};
|
|
64781
|
-
}
|
|
64782
|
-
/**
|
|
64783
|
-
* Creates the jsx branch of the ui state. Everything starts empty: the registry is filled in
|
|
64784
|
-
* `onStart` from the `ui` key of every feature.
|
|
64785
|
-
*
|
|
64786
|
-
* @returns The module state.
|
|
64787
|
-
* @example
|
|
64788
|
-
* ```ts
|
|
64789
|
-
* createJsxState().roots.size; // 0
|
|
64790
|
-
* ```
|
|
64791
|
-
*/
|
|
64792
|
-
function createJsxState() {
|
|
64793
|
-
return {
|
|
64794
|
-
components: emptyMap$1(),
|
|
64795
|
-
roots: emptyMap$1(),
|
|
64796
|
-
elements: emptyMap$1(),
|
|
64797
|
-
byIdentity: emptyMap$1(),
|
|
64798
|
-
byKey: emptyMap$1(),
|
|
64799
|
-
instances: emptyMap$1(),
|
|
64800
|
-
exiting: emptySet(),
|
|
64801
|
-
leading: emptySet(),
|
|
64802
|
-
removing: emptySet(),
|
|
64803
|
-
hosts: emptySet(),
|
|
64804
|
-
hosted: emptyMap$1(),
|
|
64805
|
-
hostsVersion: 0,
|
|
64806
|
-
hostsSeen: -1,
|
|
64807
|
-
membershipSeen: -1,
|
|
64808
|
-
risen: emptySet(),
|
|
64809
|
-
released: emptySet(),
|
|
64810
|
-
building: void 0,
|
|
64811
|
-
reconciles: 0,
|
|
64812
|
-
focus: {
|
|
64813
|
-
entity: void 0,
|
|
64814
|
-
ring: void 0,
|
|
64815
|
-
drawn: void 0,
|
|
64816
|
-
tapping: false,
|
|
64817
|
-
ringless: false
|
|
64818
|
-
},
|
|
64819
|
-
fields: emptyMap$1(),
|
|
64820
|
-
text: createTextState(),
|
|
64821
|
-
hints: [],
|
|
64822
|
-
entering: {
|
|
64823
|
-
list: [],
|
|
64824
|
-
count: 0
|
|
64825
|
-
},
|
|
64826
|
-
scrolls: emptySet(),
|
|
64827
|
-
windowRenders: 0,
|
|
64828
|
-
remount: false,
|
|
64829
|
-
epoch: 0,
|
|
64830
|
-
styled: 0,
|
|
64831
|
-
written: 0,
|
|
64832
|
-
debugTaps: [],
|
|
64833
|
-
debugWarned: false,
|
|
64834
|
-
overlays: emptySet(),
|
|
64835
|
-
asideRoots: 0
|
|
66921
|
+
scroll: jsx.scroll,
|
|
66922
|
+
rectOf: (target) => rectOfTargets(uctx, target)
|
|
64836
66923
|
};
|
|
64837
66924
|
}
|
|
64838
66925
|
//#endregion
|