@moku-labs/game 0.15.47 → 0.15.49
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-C2-V2uKy.d.mts → commands-iR813FBY.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-NGQXu7Qj.d.mts → define-Bi1cUDqV.d.mts} +2 -2
- package/dist/{headless-DcJCzBkz.d.mts → headless-DEvO-OYZ.d.mts} +1 -1
- package/dist/{index-DTsi9hds.d.mts → index-Uplq0kG1.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--I74mwMY.d.mts → runtime-BnClKG8W.d.mts} +2 -2
- package/dist/{sources-MfRpM8sV.mjs → sources-Cjrzga6S.mjs} +1 -1
- package/dist/{src-CI77RUzT.mjs → src-D5fX75jk.mjs} +1373 -141
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-D4Q5MH_l.d.mts → types-65BDgeC1.d.mts} +32 -4
- package/dist/{types-RX1bYaqD.d.mts → types-AIu9QkEJ.d.mts} +2 -2
- package/dist/{types-dF8Qmn7P.d.mts → types-CP2LCpoj.d.mts} +4 -4
- package/dist/{types-Bc_re3rB.d.mts → types-D0uITVZD.d.mts} +15 -1
- package/dist/{types-CiSVMR89.d.mts → types-kKYSP3h-.d.mts} +108 -3
- package/dist/{visual-wSjsCu_W.d.mts → visual-BeJuimAt.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";
|
|
@@ -16129,7 +16129,7 @@ function sourceBytes(source) {
|
|
|
16129
16129
|
* isTarget({ uploadMethodId: "unknown", resource: null }); // true
|
|
16130
16130
|
* ```
|
|
16131
16131
|
*/
|
|
16132
|
-
function isTarget$
|
|
16132
|
+
function isTarget$2(source) {
|
|
16133
16133
|
return source.uploadMethodId === "unknown" && (source.resource === null || source.resource === void 0);
|
|
16134
16134
|
}
|
|
16135
16135
|
/**
|
|
@@ -16164,7 +16164,7 @@ function textureUsage(app, kept) {
|
|
|
16164
16164
|
usage.count += 1;
|
|
16165
16165
|
usage.bytes += bytes;
|
|
16166
16166
|
if (kept.has(source)) usage.kept += bytes;
|
|
16167
|
-
else if (isTarget$
|
|
16167
|
+
else if (isTarget$2(source)) usage.targets += bytes;
|
|
16168
16168
|
else usage.art += bytes;
|
|
16169
16169
|
}
|
|
16170
16170
|
return usage;
|
|
@@ -28003,7 +28003,7 @@ const RETAKE_STREAK = 3;
|
|
|
28003
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`). */
|
|
28004
28004
|
const CALM_FRAMES = 8;
|
|
28005
28005
|
/** How deep a walk up the tree goes. */
|
|
28006
|
-
const MAX_DEPTH$
|
|
28006
|
+
const MAX_DEPTH$7 = 32;
|
|
28007
28007
|
/** CSS px a view may fall short of the viewport frame and still cover it: the reference frame rounds by a fraction. */
|
|
28008
28008
|
const COVER_SLACK = 1;
|
|
28009
28009
|
/** The whole-frame reasons after which a kept picture is taken again: the screen changed whole. */
|
|
@@ -28167,7 +28167,7 @@ function sameList$1(left, right) {
|
|
|
28167
28167
|
*/
|
|
28168
28168
|
function inRange(set, node, root) {
|
|
28169
28169
|
let current = node;
|
|
28170
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
28170
|
+
for (let depth = 0; depth < MAX_DEPTH$7 && current !== null && current !== root; depth += 1) {
|
|
28171
28171
|
if (set.has(current)) return true;
|
|
28172
28172
|
current = current.parent;
|
|
28173
28173
|
}
|
|
@@ -30540,7 +30540,7 @@ function countApply(sinks, filter, input) {
|
|
|
30540
30540
|
* @param source - The source.
|
|
30541
30541
|
* @returns True for a render target.
|
|
30542
30542
|
*/
|
|
30543
|
-
function isTarget(source) {
|
|
30543
|
+
function isTarget$1(source) {
|
|
30544
30544
|
return source.uploadMethodId === "unknown";
|
|
30545
30545
|
}
|
|
30546
30546
|
/**
|
|
@@ -30741,7 +30741,7 @@ function createCountingClasses(pixi, sinks, batcherPipe = pixi.BatcherPipe) {
|
|
|
30741
30741
|
* @returns The GPU texture.
|
|
30742
30742
|
*/
|
|
30743
30743
|
initSource(source) {
|
|
30744
|
-
const made = isTarget(source) && !this.targets.has(source);
|
|
30744
|
+
const made = isTarget$1(source) && !this.targets.has(source);
|
|
30745
30745
|
const texture = super.initSource(source);
|
|
30746
30746
|
if (made) {
|
|
30747
30747
|
this.targets.add(source);
|
|
@@ -30874,9 +30874,9 @@ function installPassCounting(pixi, sinks) {
|
|
|
30874
30874
|
//#endregion
|
|
30875
30875
|
//#region src/plugins/renderer/sync/hit-test.ts
|
|
30876
30876
|
/** How deep a parent chain or a container tree is followed. */
|
|
30877
|
-
const MAX_DEPTH$
|
|
30877
|
+
const MAX_DEPTH$6 = 32;
|
|
30878
30878
|
/** Below this effective alpha a view is treated as not there. */
|
|
30879
|
-
const MIN_ALPHA = .01;
|
|
30879
|
+
const MIN_ALPHA$1 = .01;
|
|
30880
30880
|
/**
|
|
30881
30881
|
* Brings a reference point into the local space of an entity: its root pose undone, the pivot
|
|
30882
30882
|
* added back. The point is posed as a child of the entity, so the pose helpers do the walk.
|
|
@@ -30956,7 +30956,7 @@ function clipBoxOf(sctx, entity) {
|
|
|
30956
30956
|
function clippedOut(sctx, entity, x, y) {
|
|
30957
30957
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
30958
30958
|
let current = parentOf$1(ecs, entity);
|
|
30959
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
30959
|
+
for (let depth = 0; depth < MAX_DEPTH$6 && current !== 0; depth += 1) {
|
|
30960
30960
|
const box = clipBoxOf(sctx, current);
|
|
30961
30961
|
if (box !== void 0 && !inBox(box, localPoint(sctx, current, x, y))) return true;
|
|
30962
30962
|
current = parentOf$1(ecs, current);
|
|
@@ -30975,7 +30975,7 @@ function clippedOut(sctx, entity, x, y) {
|
|
|
30975
30975
|
function effectiveAlpha(object, root, off) {
|
|
30976
30976
|
let alpha = 1;
|
|
30977
30977
|
let current = object;
|
|
30978
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
30978
|
+
for (let depth = 0; depth < MAX_DEPTH$6 && current !== void 0; depth += 1) {
|
|
30979
30979
|
if (current === root) return alpha;
|
|
30980
30980
|
if (!current.visible || off?.has(current) === true) return 0;
|
|
30981
30981
|
alpha *= current.alpha;
|
|
@@ -30993,7 +30993,7 @@ function effectiveAlpha(object, root, off) {
|
|
|
30993
30993
|
* @returns True when the object is drawn.
|
|
30994
30994
|
*/
|
|
30995
30995
|
function isShown$1(object, root, off) {
|
|
30996
|
-
return effectiveAlpha(object, root, off) > MIN_ALPHA;
|
|
30996
|
+
return effectiveAlpha(object, root, off) > MIN_ALPHA$1;
|
|
30997
30997
|
}
|
|
30998
30998
|
/**
|
|
30999
30999
|
* Collects the children of a container in draw order from the top: by `zIndex` descending, then
|
|
@@ -31005,7 +31005,7 @@ function isShown$1(object, root, off) {
|
|
|
31005
31005
|
* @returns The same array.
|
|
31006
31006
|
*/
|
|
31007
31007
|
function topFirst(container, out, depth = 0) {
|
|
31008
|
-
if (depth >= MAX_DEPTH$
|
|
31008
|
+
if (depth >= MAX_DEPTH$6) return out;
|
|
31009
31009
|
const ordered = container.children.toSorted((left, right) => left.zIndex - right.zIndex);
|
|
31010
31010
|
for (let index = ordered.length - 1; index >= 0; index -= 1) {
|
|
31011
31011
|
const child = ordered[index];
|
|
@@ -31094,7 +31094,7 @@ function hitAll(sctx, x, y) {
|
|
|
31094
31094
|
* hit test walks, so a box the doors report is the box a click reaches.
|
|
31095
31095
|
*/
|
|
31096
31096
|
/** How deep a parent chain is followed; deeper is treated as a loop. */
|
|
31097
|
-
const MAX_DEPTH$
|
|
31097
|
+
const MAX_DEPTH$5 = 32;
|
|
31098
31098
|
/**
|
|
31099
31099
|
* The four corners of a box, clockwise from the top-left one.
|
|
31100
31100
|
*
|
|
@@ -31188,7 +31188,7 @@ function boundsOf(sctx, entity) {
|
|
|
31188
31188
|
function layerOf$1(sctx, entity) {
|
|
31189
31189
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
31190
31190
|
let top = entity;
|
|
31191
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
31191
|
+
for (let depth = 0; depth < MAX_DEPTH$5; depth += 1) {
|
|
31192
31192
|
const parent = parentOf$1(ecs, top);
|
|
31193
31193
|
if (parent === 0) break;
|
|
31194
31194
|
top = parent;
|
|
@@ -31197,8 +31197,11 @@ function layerOf$1(sctx, entity) {
|
|
|
31197
31197
|
}
|
|
31198
31198
|
//#endregion
|
|
31199
31199
|
//#region src/plugins/renderer/sync/build.ts
|
|
31200
|
-
/**
|
|
31201
|
-
|
|
31200
|
+
/**
|
|
31201
|
+
* Views made between two reads of the clock. Eight views of a shop (text, nine-slices, filters) took 4–6 ms on a Galaxy
|
|
31202
|
+
* A26, past a warm window's whole budget; two keep a chunk under a millisecond or so (F61).
|
|
31203
|
+
*/
|
|
31204
|
+
const CLOCK_EVERY$1 = 2;
|
|
31202
31205
|
/**
|
|
31203
31206
|
* Tells whether a scene or a warm window is being built: `left()` answers a finite number only while a build runs
|
|
31204
31207
|
* or a window is in work. One field read when nothing is built.
|
|
@@ -31882,7 +31885,7 @@ function stepParts(sctx) {
|
|
|
31882
31885
|
//#endregion
|
|
31883
31886
|
//#region src/plugins/renderer/sync/overlay.ts
|
|
31884
31887
|
/** How deep a `Parent` chain or a walk up the tree goes. */
|
|
31885
|
-
const MAX_DEPTH$
|
|
31888
|
+
const MAX_DEPTH$4 = 32;
|
|
31886
31889
|
/** The owner `ui` gives the entities it spawns: the only overlays honoured (O4.8). */
|
|
31887
31890
|
const UI_OWNER_NAME = "ui";
|
|
31888
31891
|
/**
|
|
@@ -31955,7 +31958,7 @@ function clampInto(sctx, entity, into, raw) {
|
|
|
31955
31958
|
function rootOf(sctx, entity) {
|
|
31956
31959
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
31957
31960
|
let current = entity;
|
|
31958
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
31961
|
+
for (let depth = 0; depth < MAX_DEPTH$4; depth += 1) {
|
|
31959
31962
|
const parent = parentOf$1(ecs, current);
|
|
31960
31963
|
if (parent === 0) return current;
|
|
31961
31964
|
current = parent;
|
|
@@ -32168,7 +32171,7 @@ function drawnAlpha(sctx, record) {
|
|
|
32168
32171
|
const alphaFilter = sctx.deps.host.pixi()?.AlphaFilter;
|
|
32169
32172
|
let alpha = 1;
|
|
32170
32173
|
let node = view.wrapper ?? view.object;
|
|
32171
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
32174
|
+
for (let depth = 0; depth < MAX_DEPTH$4 && node !== null; depth += 1) {
|
|
32172
32175
|
if (node === root) return alpha;
|
|
32173
32176
|
if (!node.visible) return 0;
|
|
32174
32177
|
const owner = state.viewOfTop.get(node);
|
|
@@ -47888,7 +47891,7 @@ const EFFECTS_OWNER = Object.freeze({
|
|
|
47888
47891
|
name: "effects"
|
|
47889
47892
|
});
|
|
47890
47893
|
/** How deep a parent chain is followed, as `rootPoseOf` does; deeper is treated as a loop. */
|
|
47891
|
-
const MAX_DEPTH$
|
|
47894
|
+
const MAX_DEPTH$3 = 32;
|
|
47892
47895
|
/**
|
|
47893
47896
|
* The one dynamic set of an emitter container (P9): positions, frames, rotations and colours
|
|
47894
47897
|
* upload every frame; `uvs` stays static, because a frame is set at birth and the same `update()`
|
|
@@ -47931,7 +47934,7 @@ function bornFields(size) {
|
|
|
47931
47934
|
*/
|
|
47932
47935
|
function topOf(ecs, host) {
|
|
47933
47936
|
let top = host;
|
|
47934
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
47937
|
+
for (let depth = 0; depth < MAX_DEPTH$3; depth += 1) {
|
|
47935
47938
|
const parent = parentOf$1(ecs, top);
|
|
47936
47939
|
if (parent === 0) break;
|
|
47937
47940
|
top = parent;
|
|
@@ -50162,7 +50165,7 @@ const Pointer = /*#__PURE__*/ resource("Pointer", pointerDefaults);
|
|
|
50162
50165
|
* point: a view drawn over a scroll from another root keeps its press.
|
|
50163
50166
|
*/
|
|
50164
50167
|
/** How deep a `Parent` chain is followed; deeper is treated as a loop. */
|
|
50165
|
-
const MAX_DEPTH = 32;
|
|
50168
|
+
const MAX_DEPTH$2 = 32;
|
|
50166
50169
|
/**
|
|
50167
50170
|
* Resolves what `app.input.*` was pointed at. A `{ projection, key }` goes through
|
|
50168
50171
|
* `world.projection.entityOf`, which answers for live views only, so a view in the despawn queue
|
|
@@ -50258,7 +50261,7 @@ function findPressed(ctx, x, y) {
|
|
|
50258
50261
|
function movingScrollOf(ctx, entity) {
|
|
50259
50262
|
const { ecs } = ctx.deps.world;
|
|
50260
50263
|
let current = entity;
|
|
50261
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50264
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
50262
50265
|
if (ecs.get(current, Scrollable)?.moving === true && !ecs.has(current, Exiting)) return current;
|
|
50263
50266
|
current = parentOf$1(ecs, current);
|
|
50264
50267
|
}
|
|
@@ -50277,7 +50280,7 @@ function movingScrollOf(ctx, entity) {
|
|
|
50277
50280
|
function scrollOnAxisOf(ctx, entity, axis) {
|
|
50278
50281
|
const { ecs } = ctx.deps.world;
|
|
50279
50282
|
let current = entity;
|
|
50280
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50283
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
50281
50284
|
if (ecs.get(current, Scrollable)?.axis === axis && !ecs.has(current, Exiting)) return current;
|
|
50282
50285
|
current = parentOf$1(ecs, current);
|
|
50283
50286
|
}
|
|
@@ -55345,6 +55348,301 @@ const textPlugin = /*#__PURE__*/ createPlugin$1("text", {
|
|
|
55345
55348
|
onStop: ({ state }) => stopText(state)
|
|
55346
55349
|
});
|
|
55347
55350
|
//#endregion
|
|
55351
|
+
//#region src/plugins/ui/drawn.ts
|
|
55352
|
+
/**
|
|
55353
|
+
* @file ui plugin — where a target is drawn, in screen reference units: the one resolver the
|
|
55354
|
+
* `<anchor>` pass and `app.ui.rectOf` share. A target's local box goes through its root pose, the
|
|
55355
|
+
* `Transform` of every entity on its way up composed, so a scroll's offset, a fit, a slot and the
|
|
55356
|
+
* motion of an ancestor move it. Axis-aligned: the rotation is left out. A ui element spawned in
|
|
55357
|
+
* this frame has no `Transform` until the flush of the phase: its rest pose stands in, so it is
|
|
55358
|
+
* found in the frame it is laid out. The frame path allocates nothing: every answer is written into
|
|
55359
|
+
* the caller's objects, and no fractional number crosses a call. `rectOf` answers a new rect.
|
|
55360
|
+
*/
|
|
55361
|
+
/** How deep a chain is followed; deeper is treated as a loop. */
|
|
55362
|
+
const MAX_DEPTH$1 = 32;
|
|
55363
|
+
/** The alpha a target is drawn at below which it counts as not shown, as the hit test reads it. */
|
|
55364
|
+
const MIN_ALPHA = .01;
|
|
55365
|
+
/**
|
|
55366
|
+
* The reader of a running `ui`, over its world and its own state.
|
|
55367
|
+
*
|
|
55368
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55369
|
+
* @returns The reader; it holds the live maps, so it stays current.
|
|
55370
|
+
*/
|
|
55371
|
+
function readerOf(ctx) {
|
|
55372
|
+
return {
|
|
55373
|
+
ecs: ctx.deps.world.ecs,
|
|
55374
|
+
projection: ctx.deps.world.projection,
|
|
55375
|
+
elements: ctx.state.jsx.elements,
|
|
55376
|
+
roots: ctx.state.jsx.roots,
|
|
55377
|
+
exiting: ctx.state.jsx.exiting
|
|
55378
|
+
};
|
|
55379
|
+
}
|
|
55380
|
+
/**
|
|
55381
|
+
* The entity an entity is drawn under: the parent of a ui element, the slot of a root element laid
|
|
55382
|
+
* out in one, the `Parent` of any other view.
|
|
55383
|
+
*
|
|
55384
|
+
* @param reader - What the resolver reads.
|
|
55385
|
+
* @param entity - The entity.
|
|
55386
|
+
* @returns The entity above it, or 0 when it hangs in its layer.
|
|
55387
|
+
*/
|
|
55388
|
+
function upOf(reader, entity) {
|
|
55389
|
+
const element = reader.elements.get(entity);
|
|
55390
|
+
if (element === void 0) return parentOf$1(reader.ecs, entity);
|
|
55391
|
+
return element.parent ?? reader.roots.get(element.root)?.slot ?? 0;
|
|
55392
|
+
}
|
|
55393
|
+
/**
|
|
55394
|
+
* The pose an entity is drawn with: its `Transform`, or the rest pose of a ui element whose
|
|
55395
|
+
* `Transform` waits for the flush.
|
|
55396
|
+
*
|
|
55397
|
+
* @param reader - What the resolver reads.
|
|
55398
|
+
* @param entity - The entity.
|
|
55399
|
+
* @returns The pose, or `undefined` for a view with no `Transform`.
|
|
55400
|
+
*/
|
|
55401
|
+
function poseOf(reader, entity) {
|
|
55402
|
+
return reader.ecs.get(entity, Transform) ?? reader.elements.get(entity)?.rest;
|
|
55403
|
+
}
|
|
55404
|
+
/**
|
|
55405
|
+
* Writes where an entity really is: its pose composed through every entity it is drawn under,
|
|
55406
|
+
* the arithmetic of `rootPoseInto`, over `upOf`. The answer keeps the entity's own pivot. Kept in
|
|
55407
|
+
* step with `rootPoseInto` of `renderer/sync/pose.ts`: the same composition, step by step, over the
|
|
55408
|
+
* parents of `ui` elements and the rest pose of an element whose `Transform` has not landed.
|
|
55409
|
+
*
|
|
55410
|
+
* @param reader - What the resolver reads.
|
|
55411
|
+
* @param entity - The entity.
|
|
55412
|
+
* @param out - The pose to write, its `pivot` included.
|
|
55413
|
+
* @returns False for a view with no `Transform`: `out` is not written.
|
|
55414
|
+
*/
|
|
55415
|
+
function drawnPoseInto(reader, entity, out) {
|
|
55416
|
+
const own = poseOf(reader, entity);
|
|
55417
|
+
if (own === void 0) return false;
|
|
55418
|
+
out.x = own.x;
|
|
55419
|
+
out.y = own.y;
|
|
55420
|
+
out.rotation = own.rotation;
|
|
55421
|
+
out.scale = own.scale;
|
|
55422
|
+
out.pivot.x = own.pivot.x;
|
|
55423
|
+
out.pivot.y = own.pivot.y;
|
|
55424
|
+
let current = entity;
|
|
55425
|
+
for (let depth = 0; depth < MAX_DEPTH$1; depth += 1) {
|
|
55426
|
+
const parent = upOf(reader, current);
|
|
55427
|
+
if (parent === 0) break;
|
|
55428
|
+
const above = poseOf(reader, parent) ?? Transform.defaults;
|
|
55429
|
+
const cos = Math.cos(above.rotation);
|
|
55430
|
+
const sin = Math.sin(above.rotation);
|
|
55431
|
+
const dx = out.x - above.pivot.x;
|
|
55432
|
+
const dy = out.y - above.pivot.y;
|
|
55433
|
+
out.x = above.x + above.scale * (dx * cos - dy * sin);
|
|
55434
|
+
out.y = above.y + above.scale * (dx * sin + dy * cos);
|
|
55435
|
+
out.rotation += above.rotation;
|
|
55436
|
+
out.scale *= above.scale;
|
|
55437
|
+
current = parent;
|
|
55438
|
+
}
|
|
55439
|
+
return true;
|
|
55440
|
+
}
|
|
55441
|
+
/**
|
|
55442
|
+
* Tells whether an entity belongs to a scene built aside or a held warm window: the entity itself,
|
|
55443
|
+
* or the root of a ui element, as the reconcile asks it.
|
|
55444
|
+
*
|
|
55445
|
+
* @param reader - What the resolver reads.
|
|
55446
|
+
* @param entity - The entity.
|
|
55447
|
+
* @returns True while it is not on the screen yet.
|
|
55448
|
+
*/
|
|
55449
|
+
function building(reader, entity) {
|
|
55450
|
+
const element = reader.elements.get(entity);
|
|
55451
|
+
return reader.projection.isBuilding(entity) || element !== void 0 && reader.projection.isBuilding(element.root);
|
|
55452
|
+
}
|
|
55453
|
+
/**
|
|
55454
|
+
* Tells whether the player can see an entity: neither it nor anything it is drawn under is on its
|
|
55455
|
+
* way out, and the alphas of their visuals (`Shape`, `NineSlice`, `Sprite` or `Text`) multiply to
|
|
55456
|
+
* more than 0.01. The alpha of a visual fades the entity's children with it, as the renderer draws
|
|
55457
|
+
* it.
|
|
55458
|
+
*
|
|
55459
|
+
* @param reader - What the resolver reads.
|
|
55460
|
+
* @param entity - The entity.
|
|
55461
|
+
* @returns True when it is shown.
|
|
55462
|
+
*/
|
|
55463
|
+
function visible(reader, entity) {
|
|
55464
|
+
const ecs = reader.ecs;
|
|
55465
|
+
let alpha = 1;
|
|
55466
|
+
let current = entity;
|
|
55467
|
+
for (let depth = 0; depth < MAX_DEPTH$1 && current !== 0; depth += 1) {
|
|
55468
|
+
if (reader.exiting.has(current) || ecs.has(current, Exiting)) return false;
|
|
55469
|
+
alpha *= ecs.get(current, Shape)?.alpha ?? ecs.get(current, NineSlice)?.alpha ?? ecs.get(current, Sprite)?.alpha ?? ecs.get(current, Text)?.alpha ?? 1;
|
|
55470
|
+
current = upOf(reader, current);
|
|
55471
|
+
}
|
|
55472
|
+
return alpha > MIN_ALPHA;
|
|
55473
|
+
}
|
|
55474
|
+
/**
|
|
55475
|
+
* Moves a local box of an entity into root space, in place: moved by the pose, scaled around its
|
|
55476
|
+
* pivot, the rotation left out. The numbers stay in the rect: a fractional number handed to a call
|
|
55477
|
+
* is boxed.
|
|
55478
|
+
*
|
|
55479
|
+
* @param pose - The root pose of the entity.
|
|
55480
|
+
* @param out - The box in the entity's own units, written in root space.
|
|
55481
|
+
*/
|
|
55482
|
+
function toRoot(pose, out) {
|
|
55483
|
+
out.x = pose.x + pose.scale * (out.x - pose.pivot.x);
|
|
55484
|
+
out.y = pose.y + pose.scale * (out.y - pose.pivot.y);
|
|
55485
|
+
out.w *= pose.scale;
|
|
55486
|
+
out.h *= pose.scale;
|
|
55487
|
+
}
|
|
55488
|
+
/**
|
|
55489
|
+
* Writes the box of an entity in its own units, by what it draws: the layout box of a ui element,
|
|
55490
|
+
* the panel of a nine-slice, the rectangle of a shape, the anchor box of a sprite.
|
|
55491
|
+
*
|
|
55492
|
+
* @param reader - What the resolver reads.
|
|
55493
|
+
* @param entity - The entity.
|
|
55494
|
+
* @param out - The rect written, its `x` and `y` at 0 when the call starts.
|
|
55495
|
+
* @returns False for an entity that draws none of them.
|
|
55496
|
+
*/
|
|
55497
|
+
function ownBoxInto(reader, entity, out) {
|
|
55498
|
+
const element = reader.elements.get(entity);
|
|
55499
|
+
if (element !== void 0) {
|
|
55500
|
+
out.w = element.rect.w;
|
|
55501
|
+
out.h = element.rect.h;
|
|
55502
|
+
return true;
|
|
55503
|
+
}
|
|
55504
|
+
const panel = reader.ecs.get(entity, NineSlice);
|
|
55505
|
+
if (panel !== void 0) {
|
|
55506
|
+
out.w = panel.width;
|
|
55507
|
+
out.h = panel.height;
|
|
55508
|
+
return true;
|
|
55509
|
+
}
|
|
55510
|
+
const shape = reader.ecs.get(entity, Shape);
|
|
55511
|
+
if (shape !== void 0) {
|
|
55512
|
+
out.w = shape.w;
|
|
55513
|
+
out.h = shape.h;
|
|
55514
|
+
return true;
|
|
55515
|
+
}
|
|
55516
|
+
const sprite = reader.ecs.get(entity, Sprite);
|
|
55517
|
+
if (sprite === void 0) return false;
|
|
55518
|
+
out.w = sprite.width;
|
|
55519
|
+
out.h = sprite.height;
|
|
55520
|
+
out.x = -sprite.anchor.x * sprite.width;
|
|
55521
|
+
out.y = -sprite.anchor.y * sprite.height;
|
|
55522
|
+
return true;
|
|
55523
|
+
}
|
|
55524
|
+
/**
|
|
55525
|
+
* Writes the box an entity draws in root space: its own box through its root pose.
|
|
55526
|
+
*
|
|
55527
|
+
* @param reader - What the resolver reads.
|
|
55528
|
+
* @param entity - The entity.
|
|
55529
|
+
* @param pose - Its root pose.
|
|
55530
|
+
* @param out - The rect written, in root space.
|
|
55531
|
+
* @returns False for an entity that draws no box.
|
|
55532
|
+
*/
|
|
55533
|
+
function localBoxInto(reader, entity, pose, out) {
|
|
55534
|
+
out.x = 0;
|
|
55535
|
+
out.y = 0;
|
|
55536
|
+
if (!ownBoxInto(reader, entity, out)) return false;
|
|
55537
|
+
toRoot(pose, out);
|
|
55538
|
+
return true;
|
|
55539
|
+
}
|
|
55540
|
+
/**
|
|
55541
|
+
* Writes where an entity is drawn, in screen reference units, when it is shown. Not shown: the
|
|
55542
|
+
* entity belongs to a scene built aside, it or something it is drawn under is leaving, the alphas
|
|
55543
|
+
* on its way up multiply to 0.01 or less, it draws no box, or the box has no area.
|
|
55544
|
+
*
|
|
55545
|
+
* @param reader - What the resolver reads.
|
|
55546
|
+
* @param entity - The entity of the target.
|
|
55547
|
+
* @param out - The rect written.
|
|
55548
|
+
* @param pose - A pose the resolver writes on its way, kept by the caller.
|
|
55549
|
+
* @returns True when the target is shown and `out` holds its rect.
|
|
55550
|
+
*/
|
|
55551
|
+
function drawnInto(reader, entity, out, pose) {
|
|
55552
|
+
if (building(reader, entity) || !visible(reader, entity)) return false;
|
|
55553
|
+
if (!drawnPoseInto(reader, entity, pose) || !localBoxInto(reader, entity, pose, out)) return false;
|
|
55554
|
+
return out.w > 0 && out.h > 0;
|
|
55555
|
+
}
|
|
55556
|
+
/**
|
|
55557
|
+
* Grows a rect to hold another one.
|
|
55558
|
+
*
|
|
55559
|
+
* @param out - The rect grown in place.
|
|
55560
|
+
* @param part - The rect it must hold.
|
|
55561
|
+
*/
|
|
55562
|
+
function unionInto(out, part) {
|
|
55563
|
+
const right = Math.max(out.x + out.w, part.x + part.w);
|
|
55564
|
+
const bottom = Math.max(out.y + out.h, part.y + part.h);
|
|
55565
|
+
out.x = Math.min(out.x, part.x);
|
|
55566
|
+
out.y = Math.min(out.y, part.y);
|
|
55567
|
+
out.w = right - out.x;
|
|
55568
|
+
out.h = bottom - out.y;
|
|
55569
|
+
}
|
|
55570
|
+
/**
|
|
55571
|
+
* Tells a list of targets from one target.
|
|
55572
|
+
*
|
|
55573
|
+
* @param to - What `to` or `rectOf` was given, or nothing.
|
|
55574
|
+
* @returns True for a list.
|
|
55575
|
+
* @example
|
|
55576
|
+
* ```ts
|
|
55577
|
+
* isTargetList([{ projection: "hud", key: "coins" }]); // true
|
|
55578
|
+
* ```
|
|
55579
|
+
*/
|
|
55580
|
+
function isTargetList(to) {
|
|
55581
|
+
return Array.isArray(to);
|
|
55582
|
+
}
|
|
55583
|
+
/**
|
|
55584
|
+
* Writes the rect of one target or the bounding rect of the shown ones of a list.
|
|
55585
|
+
*
|
|
55586
|
+
* @param reader - What the resolver reads.
|
|
55587
|
+
* @param to - One target or a list of them.
|
|
55588
|
+
* @param out - The rect written.
|
|
55589
|
+
* @param scratch - The part and the pose the resolver writes on its way.
|
|
55590
|
+
* @param scratch.part - The rect of one target.
|
|
55591
|
+
* @param scratch.pose - The pose of one target.
|
|
55592
|
+
* @returns True when at least one target is shown.
|
|
55593
|
+
*/
|
|
55594
|
+
function targetsInto(reader, to, out, scratch) {
|
|
55595
|
+
const list = isTargetList(to) ? to : [to];
|
|
55596
|
+
let shown = false;
|
|
55597
|
+
for (const target of list) {
|
|
55598
|
+
const entity = reader.projection.entityOf(target.projection, target.key);
|
|
55599
|
+
if (entity === void 0 || !drawnInto(reader, entity, scratch.part, scratch.pose)) continue;
|
|
55600
|
+
if (shown) unionInto(out, scratch.part);
|
|
55601
|
+
else {
|
|
55602
|
+
out.x = scratch.part.x;
|
|
55603
|
+
out.y = scratch.part.y;
|
|
55604
|
+
out.w = scratch.part.w;
|
|
55605
|
+
out.h = scratch.part.h;
|
|
55606
|
+
shown = true;
|
|
55607
|
+
}
|
|
55608
|
+
}
|
|
55609
|
+
return shown;
|
|
55610
|
+
}
|
|
55611
|
+
/**
|
|
55612
|
+
* Where a target, or the shown targets of a list, are drawn: `app.ui.rectOf`. Not a frame path:
|
|
55613
|
+
* every call answers a new rect.
|
|
55614
|
+
*
|
|
55615
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55616
|
+
* @param to - One target or a list of them.
|
|
55617
|
+
* @returns The rect in screen reference units, or `undefined` when no target is shown.
|
|
55618
|
+
*/
|
|
55619
|
+
function rectOfTargets(ctx, to) {
|
|
55620
|
+
const out = {
|
|
55621
|
+
x: 0,
|
|
55622
|
+
y: 0,
|
|
55623
|
+
w: 0,
|
|
55624
|
+
h: 0
|
|
55625
|
+
};
|
|
55626
|
+
return targetsInto(readerOf(ctx), to, out, {
|
|
55627
|
+
part: {
|
|
55628
|
+
x: 0,
|
|
55629
|
+
y: 0,
|
|
55630
|
+
w: 0,
|
|
55631
|
+
h: 0
|
|
55632
|
+
},
|
|
55633
|
+
pose: {
|
|
55634
|
+
x: 0,
|
|
55635
|
+
y: 0,
|
|
55636
|
+
rotation: 0,
|
|
55637
|
+
scale: 1,
|
|
55638
|
+
pivot: {
|
|
55639
|
+
x: 0,
|
|
55640
|
+
y: 0
|
|
55641
|
+
}
|
|
55642
|
+
}
|
|
55643
|
+
}) ? out : void 0;
|
|
55644
|
+
}
|
|
55645
|
+
//#endregion
|
|
55348
55646
|
//#region src/plugins/ui/jsx/field-layout.ts
|
|
55349
55647
|
/**
|
|
55350
55648
|
* The four edges of a resolved padding.
|
|
@@ -60102,6 +60400,186 @@ function sameValue(left, right) {
|
|
|
60102
60400
|
return sameFieldsDeep(left, right);
|
|
60103
60401
|
}
|
|
60104
60402
|
//#endregion
|
|
60403
|
+
//#region src/plugins/ui/jsx/state.ts
|
|
60404
|
+
/**
|
|
60405
|
+
* Creates an empty map. Its own non-exported function, because lint rule L5 refuses a collection
|
|
60406
|
+
* built inside an exported declaration.
|
|
60407
|
+
*
|
|
60408
|
+
* @returns A map with nothing in it.
|
|
60409
|
+
*/
|
|
60410
|
+
function emptyMap$1() {
|
|
60411
|
+
return /* @__PURE__ */ new Map();
|
|
60412
|
+
}
|
|
60413
|
+
/**
|
|
60414
|
+
* Creates an empty set, for the same reason as `emptyMap`.
|
|
60415
|
+
*
|
|
60416
|
+
* @returns A set with nothing in it.
|
|
60417
|
+
*/
|
|
60418
|
+
function emptySet() {
|
|
60419
|
+
return /* @__PURE__ */ new Set();
|
|
60420
|
+
}
|
|
60421
|
+
/**
|
|
60422
|
+
* Creates the text input branch: no hidden input, nothing edited, an empty mirror.
|
|
60423
|
+
*
|
|
60424
|
+
* @returns The text state.
|
|
60425
|
+
*/
|
|
60426
|
+
function createTextState() {
|
|
60427
|
+
return {
|
|
60428
|
+
element: void 0,
|
|
60429
|
+
editing: void 0,
|
|
60430
|
+
mirror: {
|
|
60431
|
+
value: "",
|
|
60432
|
+
selectionStart: 0,
|
|
60433
|
+
selectionEnd: 0,
|
|
60434
|
+
direction: "none"
|
|
60435
|
+
},
|
|
60436
|
+
composing: void 0,
|
|
60437
|
+
keyboard: {
|
|
60438
|
+
inset: 0,
|
|
60439
|
+
innerHeight: 0,
|
|
60440
|
+
lift: 0
|
|
60441
|
+
},
|
|
60442
|
+
lifted: void 0,
|
|
60443
|
+
placed: void 0,
|
|
60444
|
+
watching: void 0,
|
|
60445
|
+
cleanups: []
|
|
60446
|
+
};
|
|
60447
|
+
}
|
|
60448
|
+
/**
|
|
60449
|
+
* Creates the jsx branch of the ui state. Everything starts empty: the registry is filled in
|
|
60450
|
+
* `onStart` from the `ui` key of every feature.
|
|
60451
|
+
*
|
|
60452
|
+
* @returns The module state.
|
|
60453
|
+
* @example
|
|
60454
|
+
* ```ts
|
|
60455
|
+
* createJsxState().roots.size; // 0
|
|
60456
|
+
* ```
|
|
60457
|
+
*/
|
|
60458
|
+
function createJsxState() {
|
|
60459
|
+
return {
|
|
60460
|
+
components: emptyMap$1(),
|
|
60461
|
+
roots: emptyMap$1(),
|
|
60462
|
+
elements: emptyMap$1(),
|
|
60463
|
+
byIdentity: emptyMap$1(),
|
|
60464
|
+
byKey: emptyMap$1(),
|
|
60465
|
+
instances: emptyMap$1(),
|
|
60466
|
+
exiting: emptySet(),
|
|
60467
|
+
leading: emptySet(),
|
|
60468
|
+
removing: emptySet(),
|
|
60469
|
+
hosts: emptySet(),
|
|
60470
|
+
hosted: emptyMap$1(),
|
|
60471
|
+
hostsVersion: 0,
|
|
60472
|
+
hostsSeen: -1,
|
|
60473
|
+
membershipSeen: -1,
|
|
60474
|
+
risen: emptySet(),
|
|
60475
|
+
released: emptySet(),
|
|
60476
|
+
building: void 0,
|
|
60477
|
+
reconciles: 0,
|
|
60478
|
+
focus: {
|
|
60479
|
+
entity: void 0,
|
|
60480
|
+
ring: void 0,
|
|
60481
|
+
drawn: void 0,
|
|
60482
|
+
tapping: false,
|
|
60483
|
+
ringless: false
|
|
60484
|
+
},
|
|
60485
|
+
fields: emptyMap$1(),
|
|
60486
|
+
text: createTextState(),
|
|
60487
|
+
hints: [],
|
|
60488
|
+
entering: {
|
|
60489
|
+
list: [],
|
|
60490
|
+
count: 0
|
|
60491
|
+
},
|
|
60492
|
+
scrolls: emptySet(),
|
|
60493
|
+
windowRenders: 0,
|
|
60494
|
+
remount: false,
|
|
60495
|
+
epoch: 0,
|
|
60496
|
+
styled: 0,
|
|
60497
|
+
written: 0,
|
|
60498
|
+
debugTaps: [],
|
|
60499
|
+
debugWarned: false,
|
|
60500
|
+
overlays: emptySet(),
|
|
60501
|
+
asideRoots: 0,
|
|
60502
|
+
anchors: emptyMap$1()
|
|
60503
|
+
};
|
|
60504
|
+
}
|
|
60505
|
+
/**
|
|
60506
|
+
* Creates a rect the anchor pass writes in every frame. Its keys come in an order of their own
|
|
60507
|
+
* (`w`, `h`, `x`, `y`): V8 gives every `{ x, y, w, h }` object one hidden shape, the frozen `Box`
|
|
60508
|
+
* values among them, and in that shape `x` and `y` hold boxed numbers, so each fractional number
|
|
60509
|
+
* written there allocates 16 B. In a shape of its own the four fields take a double in place.
|
|
60510
|
+
*
|
|
60511
|
+
* @param x - The left.
|
|
60512
|
+
* @param y - The top.
|
|
60513
|
+
* @param w - The width.
|
|
60514
|
+
* @param h - The height.
|
|
60515
|
+
* @returns The rect.
|
|
60516
|
+
* @example
|
|
60517
|
+
* ```ts
|
|
60518
|
+
* ownRect(40, 1500, 116, 120).x; // 40
|
|
60519
|
+
* ```
|
|
60520
|
+
*/
|
|
60521
|
+
function ownRect(x, y, w, h) {
|
|
60522
|
+
return {
|
|
60523
|
+
w,
|
|
60524
|
+
h,
|
|
60525
|
+
x,
|
|
60526
|
+
y
|
|
60527
|
+
};
|
|
60528
|
+
}
|
|
60529
|
+
/**
|
|
60530
|
+
* Creates what the anchor pass keeps for a new `<anchor>`: nothing read yet, not placed.
|
|
60531
|
+
*
|
|
60532
|
+
* @returns The record, every rect and the pose zeroed.
|
|
60533
|
+
*/
|
|
60534
|
+
function createAnchor() {
|
|
60535
|
+
return {
|
|
60536
|
+
node: void 0,
|
|
60537
|
+
to: void 0,
|
|
60538
|
+
retarget: false,
|
|
60539
|
+
seen: [],
|
|
60540
|
+
shown: [],
|
|
60541
|
+
count: 0,
|
|
60542
|
+
shownCount: 0,
|
|
60543
|
+
screen: ownRect(0, 0, 0, 0),
|
|
60544
|
+
part: ownRect(0, 0, 0, 0),
|
|
60545
|
+
next: ownRect(0, 0, 0, 0),
|
|
60546
|
+
pose: {
|
|
60547
|
+
x: 0,
|
|
60548
|
+
y: 0,
|
|
60549
|
+
rotation: 0,
|
|
60550
|
+
scale: 1,
|
|
60551
|
+
pivot: {
|
|
60552
|
+
x: 0,
|
|
60553
|
+
y: 0
|
|
60554
|
+
}
|
|
60555
|
+
},
|
|
60556
|
+
placed: false,
|
|
60557
|
+
hidden: false,
|
|
60558
|
+
missing: 0,
|
|
60559
|
+
owed: false,
|
|
60560
|
+
stale: false,
|
|
60561
|
+
boxes: false,
|
|
60562
|
+
held: void 0,
|
|
60563
|
+
aim: {
|
|
60564
|
+
x: 0,
|
|
60565
|
+
y: 0
|
|
60566
|
+
},
|
|
60567
|
+
track: {
|
|
60568
|
+
x: 0,
|
|
60569
|
+
y: 0
|
|
60570
|
+
},
|
|
60571
|
+
wrote: {
|
|
60572
|
+
x: NaN,
|
|
60573
|
+
y: NaN
|
|
60574
|
+
},
|
|
60575
|
+
warned: {
|
|
60576
|
+
missing: false,
|
|
60577
|
+
own: false,
|
|
60578
|
+
style: false
|
|
60579
|
+
}
|
|
60580
|
+
};
|
|
60581
|
+
}
|
|
60582
|
+
//#endregion
|
|
60105
60583
|
//#region src/plugins/ui/jsx/reconcile.ts
|
|
60106
60584
|
/**
|
|
60107
60585
|
* @file ui/jsx — the reconcile: a description tree diffed by identity into the entities `ui`
|
|
@@ -60589,6 +61067,22 @@ function identitySet(identities) {
|
|
|
60589
61067
|
return new Set(identities);
|
|
60590
61068
|
}
|
|
60591
61069
|
/**
|
|
61070
|
+
* Tells whether an element is an `<anchor>` or lies under one: the anchor pass places it after
|
|
61071
|
+
* the solve, by its targets, so the solve leaves it alone.
|
|
61072
|
+
*
|
|
61073
|
+
* @param element - The element.
|
|
61074
|
+
* @param lookup - How a parent entity becomes its element.
|
|
61075
|
+
* @returns True for an anchor and everything under it.
|
|
61076
|
+
*/
|
|
61077
|
+
function isAnchored(element, lookup) {
|
|
61078
|
+
let current = element;
|
|
61079
|
+
while (current !== void 0) {
|
|
61080
|
+
if (current.type === "anchor") return true;
|
|
61081
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
61082
|
+
}
|
|
61083
|
+
return false;
|
|
61084
|
+
}
|
|
61085
|
+
/**
|
|
60592
61086
|
* Tells whether an element whose `Box` just came arrives with an enter: new, and not a row a
|
|
60593
61087
|
* range change scrolled in.
|
|
60594
61088
|
*
|
|
@@ -60639,6 +61133,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60639
61133
|
let rendered = 0;
|
|
60640
61134
|
const isAside = (entity) => ctx.deps.world.projection.isBuilding(entity);
|
|
60641
61135
|
let released = false;
|
|
61136
|
+
let anchoring = false;
|
|
60642
61137
|
let asideSeen = -1;
|
|
60643
61138
|
let enteredSeen = -1;
|
|
60644
61139
|
let heldEnters = -1;
|
|
@@ -60771,6 +61266,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60771
61266
|
state.scrolls.add(entity);
|
|
60772
61267
|
element.scroll = scrollMotionOf(node);
|
|
60773
61268
|
}
|
|
61269
|
+
if (element.type === "anchor") state.anchors.set(entity, createAnchor());
|
|
60774
61270
|
modules.layout.attach(element);
|
|
60775
61271
|
element.basis = {
|
|
60776
61272
|
epoch: state.epoch,
|
|
@@ -61339,6 +61835,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61339
61835
|
if (hostsOf(element.node).length > 0) hostsMoved(state);
|
|
61340
61836
|
state.hosts.delete(element.entity);
|
|
61341
61837
|
state.scrolls.delete(element.entity);
|
|
61838
|
+
state.anchors.get(element.entity)?.held?.();
|
|
61839
|
+
state.anchors.delete(element.entity);
|
|
61342
61840
|
state.exiting.delete(element.entity);
|
|
61343
61841
|
state.leading.delete(element.entity);
|
|
61344
61842
|
state.overlays.delete(element.entity);
|
|
@@ -61457,12 +61955,14 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61457
61955
|
}
|
|
61458
61956
|
}
|
|
61459
61957
|
/**
|
|
61460
|
-
* Applies the solved rect of one element: a live one moves, a new one spawns its components.
|
|
61958
|
+
* Applies the solved rect of one element: a live one moves, a new one spawns its components. An
|
|
61959
|
+
* `<anchor>` and everything under it wait for the anchor pass, which places them by their targets.
|
|
61461
61960
|
*
|
|
61462
61961
|
* @param element - The element to apply.
|
|
61463
61962
|
* @param quiet - Whether a live element takes its rect with no motion.
|
|
61464
61963
|
*/
|
|
61465
61964
|
function applyElement(element, quiet) {
|
|
61965
|
+
if (!anchoring && state.anchors.size > 0 && isAnchored(element, lookup)) return;
|
|
61466
61966
|
const parent = parentRect(element);
|
|
61467
61967
|
if (element.live) applyLive(element, parent, quiet);
|
|
61468
61968
|
else applyFirst(element, parent);
|
|
@@ -61614,9 +62114,25 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61614
62114
|
return state.roots.get(host.root)?.pending === true ? void 0 : modules.layout.contentRect(host);
|
|
61615
62115
|
}
|
|
61616
62116
|
/**
|
|
62117
|
+
* Tells whether the solve of a root built aside waits for the next frame: its first solve, when the frame's budget is
|
|
62118
|
+
* spent (F61). A root that waited once is solved in the next frame whatever its budget, so a build always ends. A
|
|
62119
|
+
* root on the screen never waits.
|
|
62120
|
+
*
|
|
62121
|
+
* @param root - A root that needs a solve.
|
|
62122
|
+
* @returns True when it waits.
|
|
62123
|
+
*/
|
|
62124
|
+
function solveWaits(root) {
|
|
62125
|
+
if (root.aside === void 0 || root.solveWaited === true || !isAside(root.entity)) return false;
|
|
62126
|
+
if (ctx.deps.world.projection.left() > 0) return false;
|
|
62127
|
+
root.solveWaited = true;
|
|
62128
|
+
return true;
|
|
62129
|
+
}
|
|
62130
|
+
/**
|
|
61617
62131
|
* Solves one root in a box and applies its rects: a root on the viewport when it is marked, a
|
|
61618
62132
|
* root in a slot also when its slot was resized. A root built aside waits while parts of it wait,
|
|
61619
|
-
* and is applied in parts.
|
|
62133
|
+
* and is applied in parts. Its solve, which cannot be split (3–5 ms for a shop on a Galaxy A26),
|
|
62134
|
+
* waits for the next frame once the frame's budget is spent, and runs there whatever it has left.
|
|
62135
|
+
* A root shown before its parts were done is applied whole and still.
|
|
61620
62136
|
*
|
|
61621
62137
|
* @param root - The root.
|
|
61622
62138
|
* @param box - The viewport, or the slot's content box.
|
|
@@ -61628,6 +62144,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61628
62144
|
if (element === void 0 || parts.waits(root)) return false;
|
|
61629
62145
|
const resized = root.slot !== void 0 && !sameBox(root.slotRect, box);
|
|
61630
62146
|
if (!root.needsSolve && !resized) return false;
|
|
62147
|
+
if (solveWaits(root)) return false;
|
|
61631
62148
|
if (root.slot !== void 0) root.slotRect = {
|
|
61632
62149
|
x: box.x,
|
|
61633
62150
|
y: box.y,
|
|
@@ -61636,6 +62153,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61636
62153
|
};
|
|
61637
62154
|
modules.layout.solve(element, box, lookup);
|
|
61638
62155
|
root.needsSolve = false;
|
|
62156
|
+
delete root.solveWaited;
|
|
61639
62157
|
if (root.aside !== void 0) asideSolved = true;
|
|
61640
62158
|
if (root.aside !== void 0 && isAside(root.entity) && !element.live) parts.applyInParts(root, element, quiet);
|
|
61641
62159
|
else {
|
|
@@ -62174,6 +62692,21 @@ function createReconciler(ctx, modules, fields) {
|
|
|
62174
62692
|
hostsMoved(state);
|
|
62175
62693
|
}
|
|
62176
62694
|
/**
|
|
62695
|
+
* Applies the rect the anchor pass gave one element of an `<anchor>` subtree, as the solve
|
|
62696
|
+
* applies any other element.
|
|
62697
|
+
*
|
|
62698
|
+
* @param element - The anchor or an element under it.
|
|
62699
|
+
* @param quiet - Whether a live element takes its rect with no motion.
|
|
62700
|
+
*/
|
|
62701
|
+
function applyAnchored(element, quiet) {
|
|
62702
|
+
anchoring = true;
|
|
62703
|
+
try {
|
|
62704
|
+
applyElement(element, quiet);
|
|
62705
|
+
} finally {
|
|
62706
|
+
anchoring = false;
|
|
62707
|
+
}
|
|
62708
|
+
}
|
|
62709
|
+
/**
|
|
62177
62710
|
* Re-resolves the style of one element whose pointer or focus flag changed: a press, a release,
|
|
62178
62711
|
* the mouse coming over it or leaving it, the keyboard focus arriving or leaving. A new rect
|
|
62179
62712
|
* waits for the solve; a new look and a new rest pose apply now. Only this element is restyled:
|
|
@@ -62212,7 +62745,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
62212
62745
|
playEntered,
|
|
62213
62746
|
sweep,
|
|
62214
62747
|
converged,
|
|
62215
|
-
asideBuilt
|
|
62748
|
+
asideBuilt,
|
|
62749
|
+
applyAnchored
|
|
62216
62750
|
};
|
|
62217
62751
|
}
|
|
62218
62752
|
//#endregion
|
|
@@ -62370,6 +62904,7 @@ function createJsxApi(ctx, modules) {
|
|
|
62370
62904
|
playEntered: frame.playEntered,
|
|
62371
62905
|
converged: frame.converged,
|
|
62372
62906
|
asideBuilt: frame.asideBuilt,
|
|
62907
|
+
applyAnchored: frame.applyAnchored,
|
|
62373
62908
|
key: (input) => focus.key(input),
|
|
62374
62909
|
blur: focus.blur
|
|
62375
62910
|
};
|
|
@@ -63148,7 +63683,9 @@ function freeNode(state, element) {
|
|
|
63148
63683
|
}
|
|
63149
63684
|
/**
|
|
63150
63685
|
* Re-places the children of one parent: remove all, insert in order. Once per parent per
|
|
63151
|
-
* reconcile — per exiting child it made a thousand-row churn quadratic (spike P4, point 4).
|
|
63686
|
+
* reconcile — per exiting child it made a thousand-row churn quadratic (spike P4, point 4). An
|
|
63687
|
+
* `<anchor>` is left out: its node is a tree of its own, which the anchor pass lays out at the
|
|
63688
|
+
* size of its targets, so it takes no room in the flow of its parent.
|
|
63152
63689
|
*
|
|
63153
63690
|
* @param state - The layout state.
|
|
63154
63691
|
* @param parent - The element whose child list changed.
|
|
@@ -63161,7 +63698,7 @@ function placeChildren(state, parent, children) {
|
|
|
63161
63698
|
let index = 0;
|
|
63162
63699
|
for (const child of children) {
|
|
63163
63700
|
const childNode = state.byEntity.get(child.entity);
|
|
63164
|
-
if (childNode === void 0) continue;
|
|
63701
|
+
if (childNode === void 0 || child.type === "anchor") continue;
|
|
63165
63702
|
node.insertChild(childNode, index);
|
|
63166
63703
|
index += 1;
|
|
63167
63704
|
}
|
|
@@ -64018,7 +64555,7 @@ function releaseVelocity(state) {
|
|
|
64018
64555
|
* @param motion - Its motion.
|
|
64019
64556
|
* @param owned - Whether the samples are this press's.
|
|
64020
64557
|
*/
|
|
64021
|
-
function letGo(state, container, motion, owned) {
|
|
64558
|
+
function letGo$1(state, container, motion, owned) {
|
|
64022
64559
|
const velocity = owned ? releaseVelocity(state) : 0;
|
|
64023
64560
|
const snap = snapOf(container);
|
|
64024
64561
|
if (snap !== void 0) {
|
|
@@ -64165,7 +64702,7 @@ function stepOne(ctx, state, container, lookup, pointer, time) {
|
|
|
64165
64702
|
const content = contentOf(container, lookup);
|
|
64166
64703
|
if (content === void 0 || !ecs.has(container.entity, Scroll)) return false;
|
|
64167
64704
|
if (pressed) hold(state, container, motion, pointer);
|
|
64168
|
-
else if (motion.mode === "held") letGo(state, container, motion, released);
|
|
64705
|
+
else if (motion.mode === "held") letGo$1(state, container, motion, released);
|
|
64169
64706
|
if (motion.mode === "fling") fling(motion, time);
|
|
64170
64707
|
else if (motion.mode === "glide") glide(motion, time);
|
|
64171
64708
|
show(ctx, state, container, content, motion);
|
|
@@ -64419,7 +64956,8 @@ function frameOf(state, rect, node) {
|
|
|
64419
64956
|
};
|
|
64420
64957
|
}
|
|
64421
64958
|
/**
|
|
64422
|
-
* Walks the element tree and writes the rect of every element in root coordinates.
|
|
64959
|
+
* Walks the element tree and writes the rect of every element in root coordinates. An `<anchor>`
|
|
64960
|
+
* and everything under it are left to the anchor pass, which places them by their targets.
|
|
64423
64961
|
*
|
|
64424
64962
|
* @param state - The layout state, for the node of each element.
|
|
64425
64963
|
* @param element - The element to place.
|
|
@@ -64429,7 +64967,7 @@ function frameOf(state, rect, node) {
|
|
|
64429
64967
|
*/
|
|
64430
64968
|
function place(state, element, frame, lookup) {
|
|
64431
64969
|
const node = state.byEntity.get(element.entity);
|
|
64432
|
-
if (node === void 0) return false;
|
|
64970
|
+
if (node === void 0 || element.type === "anchor") return false;
|
|
64433
64971
|
const width = node.getComputedWidth();
|
|
64434
64972
|
const height = node.getComputedHeight();
|
|
64435
64973
|
const fitted = element.style.fit === "contain" ? fitInto(frame.content, width, height) : void 0;
|
|
@@ -64662,6 +65200,792 @@ function createLayoutApi(ctx) {
|
|
|
64662
65200
|
};
|
|
64663
65201
|
}
|
|
64664
65202
|
//#endregion
|
|
65203
|
+
//#region src/plugins/ui/anchor.ts
|
|
65204
|
+
/**
|
|
65205
|
+
* @file ui plugin — the anchor pass, the system `ui.anchor` of phase `layout`, right after `ui.solve`.
|
|
65206
|
+
* Every `<anchor>` takes the drawn rect of its targets (`drawn.ts`), padded and mapped into the space
|
|
65207
|
+
* of its parent, in the frame its targets were laid out. Its subtree is a Yoga tree of its own, laid
|
|
65208
|
+
* out only when the anchor's size changed or a node of it is dirty (a child restyled, measured
|
|
65209
|
+
* 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
|
|
65210
|
+
* anchor's `change.Box` motion plays; following a target never starts a motion. A frame of a still
|
|
65211
|
+
* anchor, and of one that follows a moving target, allocates nothing.
|
|
65212
|
+
*/
|
|
65213
|
+
/** How deep a parent chain is followed; deeper is treated as a loop. */
|
|
65214
|
+
const MAX_DEPTH = 32;
|
|
65215
|
+
/** How far a rect may move off a pure shift and still count as one: rounding, not a relayout. */
|
|
65216
|
+
const SHIFT_EPSILON = 1e-6;
|
|
65217
|
+
/** The patch that only marks a component changed: its fields were written in place. */
|
|
65218
|
+
const NO_PATCH = Object.freeze({});
|
|
65219
|
+
/** The fields of the anchor's `Transform` a follow writes, held from a loop while it follows. */
|
|
65220
|
+
const FOLLOWED_FIELDS = Object.freeze(["x", "y"]);
|
|
65221
|
+
/** The style fields an anchor takes from its targets: a style that sets one is ignored there. */
|
|
65222
|
+
const PLACED_FIELDS = [
|
|
65223
|
+
"width",
|
|
65224
|
+
"height",
|
|
65225
|
+
"position",
|
|
65226
|
+
"left",
|
|
65227
|
+
"top",
|
|
65228
|
+
"right",
|
|
65229
|
+
"bottom"
|
|
65230
|
+
];
|
|
65231
|
+
/**
|
|
65232
|
+
* Tells whether a value is a target: an object with a string `projection` and a string `key`.
|
|
65233
|
+
*
|
|
65234
|
+
* @param value - One entry of `to`.
|
|
65235
|
+
* @returns True for a target.
|
|
65236
|
+
* @example
|
|
65237
|
+
* ```ts
|
|
65238
|
+
* isTarget({ projection: "hud", key: "coins" }); // true
|
|
65239
|
+
* ```
|
|
65240
|
+
*/
|
|
65241
|
+
function isTarget(value) {
|
|
65242
|
+
if (typeof value !== "object" || value === null) return false;
|
|
65243
|
+
const target = value;
|
|
65244
|
+
return typeof target.projection === "string" && typeof target.key === "string";
|
|
65245
|
+
}
|
|
65246
|
+
/**
|
|
65247
|
+
* The targets a `to` prop names, when it names one or a list of them.
|
|
65248
|
+
*
|
|
65249
|
+
* @param to - What the render wrote.
|
|
65250
|
+
* @returns The target or the list, or `undefined` for anything else: the anchor is not shown.
|
|
65251
|
+
* @example
|
|
65252
|
+
* ```ts
|
|
65253
|
+
* targetsOf("seat0"); // undefined
|
|
65254
|
+
* ```
|
|
65255
|
+
*/
|
|
65256
|
+
function targetsOf(to) {
|
|
65257
|
+
if (isTarget(to)) return to;
|
|
65258
|
+
return Array.isArray(to) && to.every((entry) => isTarget(entry)) ? to : void 0;
|
|
65259
|
+
}
|
|
65260
|
+
/**
|
|
65261
|
+
* Tells whether two rects are the same in every field.
|
|
65262
|
+
*
|
|
65263
|
+
* @param first - One rect.
|
|
65264
|
+
* @param second - The other.
|
|
65265
|
+
* @returns True when nothing differs.
|
|
65266
|
+
* @example
|
|
65267
|
+
* ```ts
|
|
65268
|
+
* sameRect({ x: 0, y: 0, w: 4, h: 4 }, { x: 0, y: 0, w: 4, h: 4 }); // true
|
|
65269
|
+
* ```
|
|
65270
|
+
*/
|
|
65271
|
+
function sameRect(first, second) {
|
|
65272
|
+
return first.x === second.x && first.y === second.y && first.w === second.w && first.h === second.h;
|
|
65273
|
+
}
|
|
65274
|
+
/**
|
|
65275
|
+
* Tells whether the targets of an anchor are others than the last time it was shown: a new `to`,
|
|
65276
|
+
* or keys that resolve to other entities. The entities of this frame become the shown ones.
|
|
65277
|
+
*
|
|
65278
|
+
* @param anchor - Its record.
|
|
65279
|
+
* @returns True when the set changed.
|
|
65280
|
+
*/
|
|
65281
|
+
function retargeted(anchor) {
|
|
65282
|
+
let changed = anchor.retarget || anchor.count !== anchor.shownCount;
|
|
65283
|
+
for (let index = 0; index < anchor.count; index += 1) {
|
|
65284
|
+
const entity = anchor.seen[index] ?? 0;
|
|
65285
|
+
if (anchor.shown[index] !== entity) changed = true;
|
|
65286
|
+
if (index < anchor.shown.length) anchor.shown[index] = entity;
|
|
65287
|
+
else anchor.shown.push(entity);
|
|
65288
|
+
}
|
|
65289
|
+
anchor.shownCount = anchor.count;
|
|
65290
|
+
anchor.retarget = false;
|
|
65291
|
+
return changed;
|
|
65292
|
+
}
|
|
65293
|
+
/**
|
|
65294
|
+
* Notes where the motion that starts now lands: the anchor's rest pose. A follow while it plays
|
|
65295
|
+
* carries it by how far the rest moved since.
|
|
65296
|
+
*
|
|
65297
|
+
* @param element - The anchor, its rest pose recorded.
|
|
65298
|
+
* @param anchor - Its record.
|
|
65299
|
+
*/
|
|
65300
|
+
function aim(element, anchor) {
|
|
65301
|
+
anchor.aim.x = element.rest.x;
|
|
65302
|
+
anchor.aim.y = element.rest.y;
|
|
65303
|
+
anchor.wrote.x = NaN;
|
|
65304
|
+
anchor.wrote.y = NaN;
|
|
65305
|
+
}
|
|
65306
|
+
/**
|
|
65307
|
+
* Gives the position of an anchor back to its tracks, when a follow held it from a loop.
|
|
65308
|
+
*
|
|
65309
|
+
* @param anchor - Its record.
|
|
65310
|
+
*/
|
|
65311
|
+
function letGo(anchor) {
|
|
65312
|
+
anchor.held?.();
|
|
65313
|
+
anchor.held = void 0;
|
|
65314
|
+
}
|
|
65315
|
+
/**
|
|
65316
|
+
* Creates the set of rects the anchor pass made. Its own function, because lint rule L5 refuses a
|
|
65317
|
+
* collection built inside an exported declaration.
|
|
65318
|
+
*
|
|
65319
|
+
* @returns An empty set.
|
|
65320
|
+
*/
|
|
65321
|
+
function rectSet() {
|
|
65322
|
+
return /* @__PURE__ */ new WeakSet();
|
|
65323
|
+
}
|
|
65324
|
+
/**
|
|
65325
|
+
* Tells whether an element moved by more than the shift of its anchor: it was laid out anew, not
|
|
65326
|
+
* only carried along.
|
|
65327
|
+
*
|
|
65328
|
+
* @param element - An element under an anchor whose rect was written.
|
|
65329
|
+
* @param shift - How far the anchor moved.
|
|
65330
|
+
* @returns True when its size or its place inside the anchor changed.
|
|
65331
|
+
*/
|
|
65332
|
+
function relaidOut(element, shift) {
|
|
65333
|
+
const { rect, previous } = element;
|
|
65334
|
+
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;
|
|
65335
|
+
}
|
|
65336
|
+
/**
|
|
65337
|
+
* Tells whether a motion that can end still plays on an element, or one that never ends.
|
|
65338
|
+
*
|
|
65339
|
+
* @param element - The element.
|
|
65340
|
+
* @returns `"finite"` while a motion that ends plays, `"endless"` while the element runs a loop or
|
|
65341
|
+
* only a track that repeats forever plays, `"none"` otherwise.
|
|
65342
|
+
*/
|
|
65343
|
+
function motionOn(element) {
|
|
65344
|
+
if (!still(element)) return "finite";
|
|
65345
|
+
if (element.loop !== void 0) return "endless";
|
|
65346
|
+
for (const handle of element.handles) if (handle.active()) return "endless";
|
|
65347
|
+
return "none";
|
|
65348
|
+
}
|
|
65349
|
+
/**
|
|
65350
|
+
* Builds the anchor pass. Its records live in the jsx state, made when an anchor enters and
|
|
65351
|
+
* dropped when it despawns.
|
|
65352
|
+
*
|
|
65353
|
+
* @param ctx - Domain context of the ui plugin.
|
|
65354
|
+
* @param jsx - The jsx module, which applies a rect the way the solve does.
|
|
65355
|
+
* @returns The step the system `ui.anchor` runs once a frame.
|
|
65356
|
+
*/
|
|
65357
|
+
function createAnchorPass(ctx, jsx) {
|
|
65358
|
+
const state = ctx.state.jsx;
|
|
65359
|
+
const layout = ctx.state.layout;
|
|
65360
|
+
const ecs = ctx.deps.world.ecs;
|
|
65361
|
+
const projection = ctx.deps.world.projection;
|
|
65362
|
+
const reader = readerOf(ctx);
|
|
65363
|
+
const lookup = (entity) => state.elements.get(entity);
|
|
65364
|
+
const found = {
|
|
65365
|
+
shown: false,
|
|
65366
|
+
missing: false,
|
|
65367
|
+
own: void 0
|
|
65368
|
+
};
|
|
65369
|
+
const owned = rectSet();
|
|
65370
|
+
const slot = ownRect(0, 0, 0, 0);
|
|
65371
|
+
const shift = {
|
|
65372
|
+
x: 0,
|
|
65373
|
+
y: 0
|
|
65374
|
+
};
|
|
65375
|
+
/**
|
|
65376
|
+
* Moves an element to a rect: its `previous` takes the rect it had, by value, and its rect the new
|
|
65377
|
+
* numbers, both in place. The first time, the element gets two rects of the pass's own shape, so
|
|
65378
|
+
* every later frame writes doubles with no allocation. A rect that changes marks the element moved.
|
|
65379
|
+
*
|
|
65380
|
+
* @param element - The element.
|
|
65381
|
+
* @param to - The new rect, in root coordinates.
|
|
65382
|
+
*/
|
|
65383
|
+
function writeRect(element, to) {
|
|
65384
|
+
if (!owned.has(element.rect)) {
|
|
65385
|
+
const { rect, previous } = element;
|
|
65386
|
+
element.rect = ownRect(rect.x, rect.y, rect.w, rect.h);
|
|
65387
|
+
element.previous = ownRect(previous.x, previous.y, previous.w, previous.h);
|
|
65388
|
+
owned.add(element.rect);
|
|
65389
|
+
}
|
|
65390
|
+
const { rect, previous } = element;
|
|
65391
|
+
if (sameRect(rect, to)) return;
|
|
65392
|
+
previous.x = rect.x;
|
|
65393
|
+
previous.y = rect.y;
|
|
65394
|
+
previous.w = rect.w;
|
|
65395
|
+
previous.h = rect.h;
|
|
65396
|
+
rect.x = to.x;
|
|
65397
|
+
rect.y = to.y;
|
|
65398
|
+
rect.w = to.w;
|
|
65399
|
+
rect.h = to.h;
|
|
65400
|
+
element.moved = true;
|
|
65401
|
+
}
|
|
65402
|
+
/**
|
|
65403
|
+
* Tells whether an element or one above it is leaving: it no longer follows anything.
|
|
65404
|
+
*
|
|
65405
|
+
* @param element - The anchor.
|
|
65406
|
+
* @returns True while it or an ancestor plays its exit.
|
|
65407
|
+
*/
|
|
65408
|
+
function leaving(element) {
|
|
65409
|
+
let current = element;
|
|
65410
|
+
while (current !== void 0) {
|
|
65411
|
+
if (state.exiting.has(current.entity)) return true;
|
|
65412
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
65413
|
+
}
|
|
65414
|
+
return false;
|
|
65415
|
+
}
|
|
65416
|
+
/**
|
|
65417
|
+
* Reads the props of a new render of an anchor: another `to` retargets it, and a dev build names
|
|
65418
|
+
* a style that sets what the targets decide, once.
|
|
65419
|
+
*
|
|
65420
|
+
* @param element - The anchor.
|
|
65421
|
+
* @param anchor - Its record.
|
|
65422
|
+
*/
|
|
65423
|
+
function readNode(element, anchor) {
|
|
65424
|
+
if (element.node === anchor.node) return;
|
|
65425
|
+
const to = targetsOf(element.node.props.to);
|
|
65426
|
+
if (anchor.node !== void 0 && !sameValue(anchor.to, to)) anchor.retarget = true;
|
|
65427
|
+
anchor.node = element.node;
|
|
65428
|
+
anchor.to = to;
|
|
65429
|
+
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__) warnStyle(element, anchor);
|
|
65430
|
+
}
|
|
65431
|
+
/**
|
|
65432
|
+
* Names, once, an anchor whose style sets what its targets decide. Its own function: a closure
|
|
65433
|
+
* over `element` in `readNode` would make every call of it, every frame, allocate its context.
|
|
65434
|
+
*
|
|
65435
|
+
* @param element - The anchor.
|
|
65436
|
+
* @param anchor - Its record.
|
|
65437
|
+
*/
|
|
65438
|
+
function warnStyle(element, anchor) {
|
|
65439
|
+
if (anchor.warned.style || !PLACED_FIELDS.some((field) => element.style[field] !== void 0)) return;
|
|
65440
|
+
anchor.warned.style = true;
|
|
65441
|
+
ctx.log.warn("ui:anchor-style", { key: element.key ?? element.identity });
|
|
65442
|
+
}
|
|
65443
|
+
/**
|
|
65444
|
+
* Tells whether an entity is the anchor or drawn under it.
|
|
65445
|
+
*
|
|
65446
|
+
* @param entity - A target's entity.
|
|
65447
|
+
* @param anchor - The anchor's entity.
|
|
65448
|
+
* @returns True for the anchor and everything in its subtree.
|
|
65449
|
+
*/
|
|
65450
|
+
function within(entity, anchor) {
|
|
65451
|
+
let current = entity;
|
|
65452
|
+
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
65453
|
+
if (current === anchor) return true;
|
|
65454
|
+
current = upOf(reader, current);
|
|
65455
|
+
}
|
|
65456
|
+
return false;
|
|
65457
|
+
}
|
|
65458
|
+
/**
|
|
65459
|
+
* Resolves one target: notes the entity its key names, and adds its drawn rect to the union when
|
|
65460
|
+
* it is shown. A key that names no entity, and a target under the anchor itself, add nothing.
|
|
65461
|
+
*
|
|
65462
|
+
* @param element - The anchor.
|
|
65463
|
+
* @param anchor - Its record.
|
|
65464
|
+
* @param target - One entry of `to`.
|
|
65465
|
+
*/
|
|
65466
|
+
function visit(element, anchor, target) {
|
|
65467
|
+
const entity = projection.entityOf(target.projection, target.key);
|
|
65468
|
+
const at = anchor.count;
|
|
65469
|
+
if (at < anchor.seen.length) anchor.seen[at] = entity ?? 0;
|
|
65470
|
+
else anchor.seen.push(entity ?? 0);
|
|
65471
|
+
anchor.count += 1;
|
|
65472
|
+
if (entity === void 0) {
|
|
65473
|
+
found.missing = true;
|
|
65474
|
+
return;
|
|
65475
|
+
}
|
|
65476
|
+
if (within(entity, element.entity)) {
|
|
65477
|
+
found.own = target;
|
|
65478
|
+
return;
|
|
65479
|
+
}
|
|
65480
|
+
if (!drawnInto(reader, entity, anchor.part, anchor.pose)) return;
|
|
65481
|
+
if (found.shown) unionInto(anchor.screen, anchor.part);
|
|
65482
|
+
else {
|
|
65483
|
+
anchor.screen.x = anchor.part.x;
|
|
65484
|
+
anchor.screen.y = anchor.part.y;
|
|
65485
|
+
anchor.screen.w = anchor.part.w;
|
|
65486
|
+
anchor.screen.h = anchor.part.h;
|
|
65487
|
+
found.shown = true;
|
|
65488
|
+
}
|
|
65489
|
+
}
|
|
65490
|
+
/**
|
|
65491
|
+
* Resolves the targets of an anchor into the union of the shown ones, in screen reference units,
|
|
65492
|
+
* and logs what a dev build or the author must know: a key that named no entity for two frames in
|
|
65493
|
+
* a row, a target under the anchor itself.
|
|
65494
|
+
*
|
|
65495
|
+
* @param element - The anchor.
|
|
65496
|
+
* @param anchor - Its record.
|
|
65497
|
+
* @returns True when at least one target is shown.
|
|
65498
|
+
*/
|
|
65499
|
+
function resolve(element, anchor) {
|
|
65500
|
+
const to = anchor.to;
|
|
65501
|
+
found.shown = false;
|
|
65502
|
+
found.missing = false;
|
|
65503
|
+
found.own = void 0;
|
|
65504
|
+
anchor.count = 0;
|
|
65505
|
+
if (isTargetList(to)) for (const target of to) visit(element, anchor, target);
|
|
65506
|
+
else if (to !== void 0) visit(element, anchor, to);
|
|
65507
|
+
anchor.missing = found.missing ? anchor.missing + 1 : 0;
|
|
65508
|
+
if (anchor.missing >= 2) warnMissing(element, anchor);
|
|
65509
|
+
if (found.own !== void 0) refuseOwn(element, anchor, found.own);
|
|
65510
|
+
return found.shown;
|
|
65511
|
+
}
|
|
65512
|
+
/**
|
|
65513
|
+
* Names, in a dev build, an anchor a key of which named no entity two frames in a row, once.
|
|
65514
|
+
*
|
|
65515
|
+
* @param element - The anchor.
|
|
65516
|
+
* @param anchor - Its record.
|
|
65517
|
+
*/
|
|
65518
|
+
function warnMissing(element, anchor) {
|
|
65519
|
+
if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__ || anchor.warned.missing) return;
|
|
65520
|
+
anchor.warned.missing = true;
|
|
65521
|
+
ctx.log.warn("ui:anchor-target-missing", {
|
|
65522
|
+
key: element.key ?? element.identity,
|
|
65523
|
+
to: anchor.to
|
|
65524
|
+
});
|
|
65525
|
+
}
|
|
65526
|
+
/**
|
|
65527
|
+
* Logs, once per anchor, a target that lies inside the anchor itself: it is treated as not shown.
|
|
65528
|
+
*
|
|
65529
|
+
* @param element - The anchor.
|
|
65530
|
+
* @param anchor - Its record.
|
|
65531
|
+
* @param target - The target under the anchor.
|
|
65532
|
+
*/
|
|
65533
|
+
function refuseOwn(element, anchor, target) {
|
|
65534
|
+
if (anchor.warned.own) return;
|
|
65535
|
+
anchor.warned.own = true;
|
|
65536
|
+
ctx.log.error("ui:anchor-own-child", {
|
|
65537
|
+
key: element.key ?? element.identity,
|
|
65538
|
+
target: target.key
|
|
65539
|
+
}, /* @__PURE__ */ new Error(`[game] An anchor cannot point at its own child "${target.key}".\n Point it at an element outside the anchor.`));
|
|
65540
|
+
}
|
|
65541
|
+
/**
|
|
65542
|
+
* Maps the union of the targets into the root coordinates of the anchor: through the root pose of
|
|
65543
|
+
* the entity it is drawn under (its parent, or the slot of its root), then by its parent's rect,
|
|
65544
|
+
* then padded outward.
|
|
65545
|
+
*
|
|
65546
|
+
* @param element - The anchor.
|
|
65547
|
+
* @param anchor - Its record: `screen` is read, `next` written.
|
|
65548
|
+
* @returns False when the space it is drawn in is collapsed: nothing of it could be seen.
|
|
65549
|
+
*/
|
|
65550
|
+
function mapInto(element, anchor) {
|
|
65551
|
+
const above = element.parent ?? state.roots.get(element.root)?.slot ?? 0;
|
|
65552
|
+
const pose = anchor.pose;
|
|
65553
|
+
if (above === 0 || !drawnPoseInto(reader, above, pose)) {
|
|
65554
|
+
pose.x = 0;
|
|
65555
|
+
pose.y = 0;
|
|
65556
|
+
pose.scale = 1;
|
|
65557
|
+
pose.pivot.x = 0;
|
|
65558
|
+
pose.pivot.y = 0;
|
|
65559
|
+
}
|
|
65560
|
+
const scale = pose.scale;
|
|
65561
|
+
if (scale <= 0) return false;
|
|
65562
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65563
|
+
const given = element.node.props.pad;
|
|
65564
|
+
const pad = typeof given === "number" && Number.isFinite(given) ? given : 0;
|
|
65565
|
+
const { screen, next } = anchor;
|
|
65566
|
+
next.x = pose.pivot.x + (screen.x - pose.x) / scale + (parent?.rect.x ?? 0) - pad;
|
|
65567
|
+
next.y = pose.pivot.y + (screen.y - pose.y) / scale + (parent?.rect.y ?? 0) - pad;
|
|
65568
|
+
next.w = screen.w / scale + 2 * pad;
|
|
65569
|
+
next.h = screen.h / scale + 2 * pad;
|
|
65570
|
+
return next.w > 0 && next.h > 0;
|
|
65571
|
+
}
|
|
65572
|
+
/**
|
|
65573
|
+
* Writes the alpha of the anchor's visual, which fades its subtree with it: 0 hides the anchor the
|
|
65574
|
+
* way a transparent element is hidden, out of the draw and the hit test. Only a value that
|
|
65575
|
+
* differs is written.
|
|
65576
|
+
*
|
|
65577
|
+
* @param element - The anchor.
|
|
65578
|
+
* @param alpha - The alpha to draw it at.
|
|
65579
|
+
*/
|
|
65580
|
+
function fadeTo(element, alpha) {
|
|
65581
|
+
const shape = ecs.get(element.entity, Shape);
|
|
65582
|
+
if (shape !== void 0) {
|
|
65583
|
+
if (shape.alpha === alpha) return;
|
|
65584
|
+
shape.alpha = alpha;
|
|
65585
|
+
ecs.set(element.entity, Shape, NO_PATCH);
|
|
65586
|
+
return;
|
|
65587
|
+
}
|
|
65588
|
+
const panel = ecs.get(element.entity, NineSlice);
|
|
65589
|
+
if (panel === void 0 || panel.alpha === alpha) return;
|
|
65590
|
+
panel.alpha = alpha;
|
|
65591
|
+
ecs.set(element.entity, NineSlice, NO_PATCH);
|
|
65592
|
+
}
|
|
65593
|
+
/**
|
|
65594
|
+
* Hides an anchor none of whose targets is shown. A placed one stays, drawn at alpha 0; one never
|
|
65595
|
+
* placed waits with no components.
|
|
65596
|
+
*
|
|
65597
|
+
* @param element - The anchor.
|
|
65598
|
+
* @param anchor - Its record.
|
|
65599
|
+
*/
|
|
65600
|
+
function hide(element, anchor) {
|
|
65601
|
+
anchor.hidden = true;
|
|
65602
|
+
if (anchor.placed) fadeTo(element, 0);
|
|
65603
|
+
}
|
|
65604
|
+
/**
|
|
65605
|
+
* Shows an anchor again at the alpha of its style.
|
|
65606
|
+
*
|
|
65607
|
+
* @param element - The anchor.
|
|
65608
|
+
* @param anchor - Its record.
|
|
65609
|
+
*/
|
|
65610
|
+
function show(element, anchor) {
|
|
65611
|
+
if (!anchor.hidden) return;
|
|
65612
|
+
anchor.hidden = false;
|
|
65613
|
+
fadeTo(element, element.style.alpha ?? 1);
|
|
65614
|
+
}
|
|
65615
|
+
/**
|
|
65616
|
+
* Writes an element's `Box` from its rect, field by field on the stored value. Nothing is written
|
|
65617
|
+
* while it holds the same numbers, or before the `Box` landed.
|
|
65618
|
+
*
|
|
65619
|
+
* @param element - The element.
|
|
65620
|
+
*/
|
|
65621
|
+
function writeBox(element) {
|
|
65622
|
+
const box = ecs.get(element.entity, Box);
|
|
65623
|
+
if (box === void 0 || sameRect(box, element.rect)) return;
|
|
65624
|
+
box.x = element.rect.x;
|
|
65625
|
+
box.y = element.rect.y;
|
|
65626
|
+
box.w = element.rect.w;
|
|
65627
|
+
box.h = element.rect.h;
|
|
65628
|
+
ecs.set(element.entity, Box, NO_PATCH);
|
|
65629
|
+
}
|
|
65630
|
+
/**
|
|
65631
|
+
* Lays the subtree of an anchor out in its rect: one Yoga calculation of the anchor's own tree at
|
|
65632
|
+
* its size, then the rects of everything under it written in place.
|
|
65633
|
+
*
|
|
65634
|
+
* @param element - The anchor, its rect set.
|
|
65635
|
+
*/
|
|
65636
|
+
function layOut(element) {
|
|
65637
|
+
const yoga = layout.yoga;
|
|
65638
|
+
const node = layout.byEntity.get(element.entity);
|
|
65639
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65640
|
+
node.setWidth(element.rect.w);
|
|
65641
|
+
node.setHeight(element.rect.h);
|
|
65642
|
+
node.calculateLayout(element.rect.w, element.rect.h, yoga.DIRECTION_LTR);
|
|
65643
|
+
layout.solves += 1;
|
|
65644
|
+
placeUnder(element);
|
|
65645
|
+
}
|
|
65646
|
+
/**
|
|
65647
|
+
* Writes the rects of the children of a laid-out element in root coordinates, and of everything
|
|
65648
|
+
* under them: the computed offsets from its rect, a fitted child centred in its content box at
|
|
65649
|
+
* the scale that fits it. A nested anchor is left to its own place in the pass.
|
|
65650
|
+
*
|
|
65651
|
+
* @param parent - The element whose rect is written.
|
|
65652
|
+
*/
|
|
65653
|
+
function placeUnder(parent) {
|
|
65654
|
+
const yoga = layout.yoga;
|
|
65655
|
+
const node = layout.byEntity.get(parent.entity);
|
|
65656
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65657
|
+
const left = node.getComputedPadding(yoga.EDGE_LEFT);
|
|
65658
|
+
const top = node.getComputedPadding(yoga.EDGE_TOP);
|
|
65659
|
+
const content = {
|
|
65660
|
+
x: parent.rect.x + left,
|
|
65661
|
+
y: parent.rect.y + top,
|
|
65662
|
+
w: parent.rect.w - left - node.getComputedPadding(yoga.EDGE_RIGHT),
|
|
65663
|
+
h: parent.rect.h - top - node.getComputedPadding(yoga.EDGE_BOTTOM)
|
|
65664
|
+
};
|
|
65665
|
+
for (const child of parent.children) {
|
|
65666
|
+
const element = lookup(child);
|
|
65667
|
+
const childNode = element === void 0 ? void 0 : layout.byEntity.get(element.entity);
|
|
65668
|
+
if (element === void 0 || childNode === void 0 || element.type === "anchor") continue;
|
|
65669
|
+
const w = childNode.getComputedWidth();
|
|
65670
|
+
const h = childNode.getComputedHeight();
|
|
65671
|
+
const fitted = element.style.fit === "contain" ? fitInto(content, w, h) : void 0;
|
|
65672
|
+
slot.x = fitted?.rect.x ?? parent.rect.x + childNode.getComputedLeft();
|
|
65673
|
+
slot.y = fitted?.rect.y ?? parent.rect.y + childNode.getComputedTop();
|
|
65674
|
+
slot.w = w;
|
|
65675
|
+
slot.h = h;
|
|
65676
|
+
writeRect(element, slot);
|
|
65677
|
+
if ((fitted?.fit ?? 1) !== element.fit) {
|
|
65678
|
+
element.fit = fitted?.fit ?? 1;
|
|
65679
|
+
element.moved = true;
|
|
65680
|
+
}
|
|
65681
|
+
placeUnder(element);
|
|
65682
|
+
}
|
|
65683
|
+
}
|
|
65684
|
+
/**
|
|
65685
|
+
* Carries everything under an element along by a shift, rects in place. A nested anchor is left
|
|
65686
|
+
* to its own place in the pass.
|
|
65687
|
+
*
|
|
65688
|
+
* @param parent - The element whose children move, by `shift`.
|
|
65689
|
+
* @param mark - Whether they stay marked moved, for an application that follows.
|
|
65690
|
+
*/
|
|
65691
|
+
function shiftUnder(parent, mark) {
|
|
65692
|
+
for (const child of parent.children) {
|
|
65693
|
+
const element = lookup(child);
|
|
65694
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65695
|
+
const { rect } = element;
|
|
65696
|
+
slot.x = rect.x + shift.x;
|
|
65697
|
+
slot.y = rect.y + shift.y;
|
|
65698
|
+
slot.w = rect.w;
|
|
65699
|
+
slot.h = rect.h;
|
|
65700
|
+
writeRect(element, slot);
|
|
65701
|
+
if (!mark) element.moved = false;
|
|
65702
|
+
shiftUnder(element, mark);
|
|
65703
|
+
}
|
|
65704
|
+
}
|
|
65705
|
+
/**
|
|
65706
|
+
* Writes the `Box` of an element and of everything under it from their rects. A nested anchor is
|
|
65707
|
+
* left to its own place in the pass.
|
|
65708
|
+
*
|
|
65709
|
+
* @param element - The anchor or an element under it.
|
|
65710
|
+
*/
|
|
65711
|
+
function writeBoxes(element) {
|
|
65712
|
+
writeBox(element);
|
|
65713
|
+
for (const child of element.children) {
|
|
65714
|
+
const childElement = lookup(child);
|
|
65715
|
+
if (childElement !== void 0 && childElement.type !== "anchor") writeBoxes(childElement);
|
|
65716
|
+
}
|
|
65717
|
+
}
|
|
65718
|
+
/**
|
|
65719
|
+
* Applies an element and everything under it the way the solve applies a root: a new element
|
|
65720
|
+
* spawns its components, a moved live one is committed and plays its `change` hooks. A nested
|
|
65721
|
+
* anchor is left to its own place in the pass.
|
|
65722
|
+
*
|
|
65723
|
+
* @param element - The anchor or an element under it.
|
|
65724
|
+
*/
|
|
65725
|
+
function applyTree(element) {
|
|
65726
|
+
jsx.applyAnchored(element, false);
|
|
65727
|
+
for (const child of element.children) {
|
|
65728
|
+
const childElement = lookup(child);
|
|
65729
|
+
if (childElement !== void 0 && childElement.type !== "anchor") applyTree(childElement);
|
|
65730
|
+
}
|
|
65731
|
+
}
|
|
65732
|
+
/**
|
|
65733
|
+
* Applies what a relayout of an anchor's subtree moved. A child carried along only writes its
|
|
65734
|
+
* `Box`; one laid out anew is applied as the solve applies it, with its `change` hooks, unless
|
|
65735
|
+
* the anchor's size followed its targets: then it takes its rect and its rest pose with no motion.
|
|
65736
|
+
*
|
|
65737
|
+
* @param parent - The element whose children were laid out, its anchor moved by `shift`.
|
|
65738
|
+
* @param followed - Whether the anchor's size changed by following its targets.
|
|
65739
|
+
*/
|
|
65740
|
+
function applyUnder(parent, followed) {
|
|
65741
|
+
for (const child of parent.children) {
|
|
65742
|
+
const element = lookup(child);
|
|
65743
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65744
|
+
if (!element.live) jsx.applyAnchored(element, false);
|
|
65745
|
+
else if (element.moved && !relaidOut(element, shift)) {
|
|
65746
|
+
writeBox(element);
|
|
65747
|
+
element.moved = false;
|
|
65748
|
+
} else if (element.moved && followed) {
|
|
65749
|
+
jsx.applyAnchored(element, true);
|
|
65750
|
+
settlePose(element);
|
|
65751
|
+
} else if (element.moved) jsx.applyAnchored(element, false);
|
|
65752
|
+
applyUnder(element, followed);
|
|
65753
|
+
}
|
|
65754
|
+
}
|
|
65755
|
+
/**
|
|
65756
|
+
* Brings an element under an anchor to the rest pose a follow gave it, with no motion: a `Transform`
|
|
65757
|
+
* a motion is on is taken through a 0 ms rest track, which cuts a finite motion and re-bases a
|
|
65758
|
+
* loop, as a repose does; one nothing moves is written at once.
|
|
65759
|
+
*
|
|
65760
|
+
* @param element - The element, its rest pose recorded.
|
|
65761
|
+
*/
|
|
65762
|
+
function settlePose(element) {
|
|
65763
|
+
if (!element.live || element.type === "content" || !ecs.has(element.entity, Transform)) return;
|
|
65764
|
+
if (motionOn(element) === "none") ecs.set(element.entity, Transform, {
|
|
65765
|
+
...element.rest,
|
|
65766
|
+
pivot: { ...element.rest.pivot }
|
|
65767
|
+
});
|
|
65768
|
+
else handleOf(ctx, element)?.toRest(Transform, { ms: 0 });
|
|
65769
|
+
}
|
|
65770
|
+
/**
|
|
65771
|
+
* Carries a motion that ends by how far the targets moved since it began: the position the motion
|
|
65772
|
+
* wrote this frame, moved by the rest's shift from where the motion lands. The motion writes its
|
|
65773
|
+
* own value again in the next frame, and the carry is added once more, so it lands on the moved
|
|
65774
|
+
* rest instead of jumping there at its end.
|
|
65775
|
+
*
|
|
65776
|
+
* @param element - The anchor.
|
|
65777
|
+
* @param anchor - Its record.
|
|
65778
|
+
* @param pose - Its stored `Transform`.
|
|
65779
|
+
*/
|
|
65780
|
+
function carry(element, anchor, pose) {
|
|
65781
|
+
const { aim: aimed, track, wrote } = anchor;
|
|
65782
|
+
const rest = element.rest;
|
|
65783
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) ecs.set(element.entity, Transform, { pivot: {
|
|
65784
|
+
x: rest.pivot.x,
|
|
65785
|
+
y: rest.pivot.y
|
|
65786
|
+
} });
|
|
65787
|
+
if (pose.x !== wrote.x) track.x = pose.x;
|
|
65788
|
+
if (pose.y !== wrote.y) track.y = pose.y;
|
|
65789
|
+
const x = track.x + rest.x - aimed.x;
|
|
65790
|
+
const y = track.y + rest.y - aimed.y;
|
|
65791
|
+
if (x === pose.x && y === pose.y) return;
|
|
65792
|
+
pose.x = x;
|
|
65793
|
+
pose.y = y;
|
|
65794
|
+
wrote.x = x;
|
|
65795
|
+
wrote.y = y;
|
|
65796
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65797
|
+
}
|
|
65798
|
+
/**
|
|
65799
|
+
* Writes the anchor's `Transform` from its rest pose. While a motion that ends plays (the glide of
|
|
65800
|
+
* a change of targets, a look tween), the motion is carried by the follow and lands on the rest;
|
|
65801
|
+
* the pose is owed to the rest until it ends. Under a loop the follow holds `x` and `y` from every
|
|
65802
|
+
* track while it moves (`world.projection.mute`), and the loop goes on from where the anchor
|
|
65803
|
+
* stands once it is let go. Each field is written on the stored value.
|
|
65804
|
+
*
|
|
65805
|
+
* @param element - The anchor.
|
|
65806
|
+
* @param anchor - Its record.
|
|
65807
|
+
*/
|
|
65808
|
+
function writePose(element, anchor) {
|
|
65809
|
+
const pose = ecs.get(element.entity, Transform);
|
|
65810
|
+
if (!element.live || pose === void 0) return;
|
|
65811
|
+
const motion = motionOn(element);
|
|
65812
|
+
if (motion === "finite") {
|
|
65813
|
+
anchor.owed = true;
|
|
65814
|
+
carry(element, anchor, pose);
|
|
65815
|
+
return;
|
|
65816
|
+
}
|
|
65817
|
+
anchor.owed = false;
|
|
65818
|
+
if (motion === "endless" && anchor.held === void 0) anchor.held = projection.mute(element.entity, Transform, FOLLOWED_FIELDS);
|
|
65819
|
+
const rest = element.rest;
|
|
65820
|
+
if (samePose(pose, rest)) return;
|
|
65821
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) {
|
|
65822
|
+
ecs.set(element.entity, Transform, {
|
|
65823
|
+
...rest,
|
|
65824
|
+
pivot: { ...rest.pivot }
|
|
65825
|
+
});
|
|
65826
|
+
return;
|
|
65827
|
+
}
|
|
65828
|
+
pose.x = rest.x;
|
|
65829
|
+
pose.y = rest.y;
|
|
65830
|
+
pose.rotation = rest.rotation;
|
|
65831
|
+
pose.scale = rest.scale;
|
|
65832
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65833
|
+
}
|
|
65834
|
+
/**
|
|
65835
|
+
* Moves the anchor's rest pose to where its rect and its parent's put it now, its size, and so its
|
|
65836
|
+
* pivot, unchanged: the position of `restTransform`, worked out here, since a fractional number
|
|
65837
|
+
* handed to or returned from a call is boxed. The rest is written in place, and the world's copy
|
|
65838
|
+
* of it is left behind until the anchor stands still. Then the `Transform` follows.
|
|
65839
|
+
*
|
|
65840
|
+
* @param element - The anchor.
|
|
65841
|
+
* @param anchor - Its record.
|
|
65842
|
+
* @returns True when the rest pose moved.
|
|
65843
|
+
*/
|
|
65844
|
+
function follow(element, anchor) {
|
|
65845
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65846
|
+
const { rect, rest, style } = element;
|
|
65847
|
+
const centreX = rect.w / 2;
|
|
65848
|
+
const centreY = rect.h / 2;
|
|
65849
|
+
const x = rect.x - (parent?.rect.x ?? 0) + centreX + (rest.pivot.x + (style.offsetX ?? 0) - centreX);
|
|
65850
|
+
const y = rect.y - (parent?.rect.y ?? 0) + centreY + (rest.pivot.y + (style.offsetY ?? 0) - centreY);
|
|
65851
|
+
if (x === rest.x && y === rest.y) return false;
|
|
65852
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65853
|
+
rest.x = x;
|
|
65854
|
+
rest.y = y;
|
|
65855
|
+
anchor.stale = true;
|
|
65856
|
+
writePose(element, anchor);
|
|
65857
|
+
return true;
|
|
65858
|
+
}
|
|
65859
|
+
/**
|
|
65860
|
+
* Places an anchor for the first time: its rect, its subtree laid out, and everything applied as
|
|
65861
|
+
* a new root is, so its components spawn with their rects and its `enter` hooks play.
|
|
65862
|
+
*
|
|
65863
|
+
* @param element - The anchor.
|
|
65864
|
+
* @param anchor - Its record, `next` holding its rect.
|
|
65865
|
+
*/
|
|
65866
|
+
function place(element, anchor) {
|
|
65867
|
+
const { next } = anchor;
|
|
65868
|
+
element.fit = 1;
|
|
65869
|
+
writeRect(element, next);
|
|
65870
|
+
layOut(element);
|
|
65871
|
+
applyTree(element);
|
|
65872
|
+
aim(element, anchor);
|
|
65873
|
+
anchor.placed = true;
|
|
65874
|
+
}
|
|
65875
|
+
/**
|
|
65876
|
+
* Moves an anchor to its new targets the way a solve moves an element: its `change.Box` motion
|
|
65877
|
+
* plays, and so do the hooks of what moved under it.
|
|
65878
|
+
*
|
|
65879
|
+
* @param element - The anchor.
|
|
65880
|
+
* @param anchor - Its record, `next` holding its new rect.
|
|
65881
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65882
|
+
*/
|
|
65883
|
+
function retarget(element, anchor, relayout) {
|
|
65884
|
+
const next = anchor.next;
|
|
65885
|
+
const rect = element.rect;
|
|
65886
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65887
|
+
shift.x = next.x - rect.x;
|
|
65888
|
+
shift.y = next.y - rect.y;
|
|
65889
|
+
writeRect(element, next);
|
|
65890
|
+
if (resized || relayout) layOut(element);
|
|
65891
|
+
else shiftUnder(element, true);
|
|
65892
|
+
anchor.owed = false;
|
|
65893
|
+
anchor.stale = false;
|
|
65894
|
+
letGo(anchor);
|
|
65895
|
+
applyTree(element);
|
|
65896
|
+
aim(element, anchor);
|
|
65897
|
+
}
|
|
65898
|
+
/**
|
|
65899
|
+
* Keeps an anchor on targets that moved, resized or stood: no motion starts. A pure move writes
|
|
65900
|
+
* every number in place and leaves the `Box` values for the frame the anchor stands (a fractional
|
|
65901
|
+
* number written into a stored `Box` field is boxed); a new size or a dirty node lays the
|
|
65902
|
+
* subtree out again.
|
|
65903
|
+
*
|
|
65904
|
+
* @param element - The anchor.
|
|
65905
|
+
* @param anchor - Its record, `next` holding its rect of this frame.
|
|
65906
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65907
|
+
* @returns True when the anchor's rest pose moved.
|
|
65908
|
+
*/
|
|
65909
|
+
function keep(element, anchor, relayout) {
|
|
65910
|
+
const { next } = anchor;
|
|
65911
|
+
const rect = element.rect;
|
|
65912
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65913
|
+
shift.x = next.x - rect.x;
|
|
65914
|
+
shift.y = next.y - rect.y;
|
|
65915
|
+
writeRect(element, next);
|
|
65916
|
+
if (resized) {
|
|
65917
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65918
|
+
layOut(element);
|
|
65919
|
+
jsx.applyAnchored(element, true);
|
|
65920
|
+
anchor.stale = false;
|
|
65921
|
+
writePose(element, anchor);
|
|
65922
|
+
applyUnder(element, true);
|
|
65923
|
+
return true;
|
|
65924
|
+
}
|
|
65925
|
+
if (relayout) {
|
|
65926
|
+
layOut(element);
|
|
65927
|
+
applyUnder(element, false);
|
|
65928
|
+
writeBox(element);
|
|
65929
|
+
} else if (shift.x !== 0 || shift.y !== 0) {
|
|
65930
|
+
shiftUnder(element, false);
|
|
65931
|
+
anchor.boxes = true;
|
|
65932
|
+
}
|
|
65933
|
+
element.moved = false;
|
|
65934
|
+
return follow(element, anchor);
|
|
65935
|
+
}
|
|
65936
|
+
/**
|
|
65937
|
+
* Places one anchor for this frame: its targets resolved, then placed the first time, moved to
|
|
65938
|
+
* new targets, kept on moving ones, or hidden while none is shown. Its owed pose and the world's
|
|
65939
|
+
* copy of its rest catch up once nothing moves it.
|
|
65940
|
+
*
|
|
65941
|
+
* @param entity - The anchor's entity.
|
|
65942
|
+
* @param anchor - Its record.
|
|
65943
|
+
*/
|
|
65944
|
+
function placeAnchor(entity, anchor) {
|
|
65945
|
+
const element = lookup(entity);
|
|
65946
|
+
if (element === void 0) return;
|
|
65947
|
+
if (leaving(element)) {
|
|
65948
|
+
letGo(anchor);
|
|
65949
|
+
return;
|
|
65950
|
+
}
|
|
65951
|
+
if (projection.isBuilding(element.root)) return;
|
|
65952
|
+
readNode(element, anchor);
|
|
65953
|
+
if (!resolve(element, anchor) || !mapInto(element, anchor)) {
|
|
65954
|
+
hide(element, anchor);
|
|
65955
|
+
return;
|
|
65956
|
+
}
|
|
65957
|
+
const relayout = layout.byEntity.get(entity)?.isDirty() === true;
|
|
65958
|
+
if (!anchor.placed) {
|
|
65959
|
+
place(element, anchor);
|
|
65960
|
+
retargeted(anchor);
|
|
65961
|
+
anchor.hidden = false;
|
|
65962
|
+
return;
|
|
65963
|
+
}
|
|
65964
|
+
let moved = false;
|
|
65965
|
+
if (retargeted(anchor)) retarget(element, anchor, relayout);
|
|
65966
|
+
else moved = keep(element, anchor, relayout);
|
|
65967
|
+
show(element, anchor);
|
|
65968
|
+
if (anchor.owed && !moved) writePose(element, anchor);
|
|
65969
|
+
if (moved) return;
|
|
65970
|
+
if (anchor.stale) {
|
|
65971
|
+
ctx.deps.world.projection.setRest(entity, Transform, element.rest);
|
|
65972
|
+
anchor.stale = false;
|
|
65973
|
+
}
|
|
65974
|
+
if (anchor.boxes) {
|
|
65975
|
+
writeBoxes(element);
|
|
65976
|
+
anchor.boxes = false;
|
|
65977
|
+
}
|
|
65978
|
+
letGo(anchor);
|
|
65979
|
+
}
|
|
65980
|
+
return () => {
|
|
65981
|
+
if (state.anchors.size === 0) return;
|
|
65982
|
+
for (const entity of state.anchors.keys()) {
|
|
65983
|
+
const anchor = state.anchors.get(entity);
|
|
65984
|
+
if (anchor !== void 0) placeAnchor(entity, anchor);
|
|
65985
|
+
}
|
|
65986
|
+
};
|
|
65987
|
+
}
|
|
65988
|
+
//#endregion
|
|
64665
65989
|
//#region src/plugins/ui/hot.ts
|
|
64666
65990
|
/** The global the footer of `@moku-labs/game/hot` calls. */
|
|
64667
65991
|
const HOT_GLOBAL = "__moku_hot";
|
|
@@ -65213,7 +66537,7 @@ function drawsViews(ctx) {
|
|
|
65213
66537
|
return ctx.deps.renderer.host.kind() !== "none";
|
|
65214
66538
|
}
|
|
65215
66539
|
/**
|
|
65216
|
-
* Opens the
|
|
66540
|
+
* Opens the three systems of phase `layout`, the system `ui.enter` of phase `sync`, the seven world
|
|
65217
66541
|
* hooks of `Tree`, `Box`, `Pressed` and `PointerOver`, the two that tell the hosting step a view
|
|
65218
66542
|
* lost its `Parent` or its `Held` (a view freed so may hang under its host again), the listener
|
|
65219
66543
|
* that asks for every root to be built again after a restore or a load, the two effect handlers,
|
|
@@ -65224,7 +66548,8 @@ function drawsViews(ctx) {
|
|
|
65224
66548
|
* control, so the cursor shows a hand over a local-state button, and, with a renderer that draws,
|
|
65225
66549
|
* `ui`'s part of a scene build (`onBuild`: the roots built aside are reconciled and solved, spec
|
|
65226
66550
|
* 31). On an agent page also the tap counter of `DebugTrigger` and its check of a view that takes
|
|
65227
|
-
* no press.
|
|
66551
|
+
* no press. The third system of `layout`, `ui.anchor`, runs after the solve and places every
|
|
66552
|
+
* `<anchor>` on its targets.
|
|
65228
66553
|
*
|
|
65229
66554
|
* The `Box` hook plays an element's enter hook and queues it, so the game's systems see its start
|
|
65230
66555
|
* pose (F49); `ui.enter` starts its loop after them and before the frame is drawn, and plays the
|
|
@@ -65238,6 +66563,7 @@ function drawsViews(ctx) {
|
|
|
65238
66563
|
function openRegistrations(ctx, jsx, layout) {
|
|
65239
66564
|
const ecs = ctx.deps.world.ecs;
|
|
65240
66565
|
const projection = ctx.deps.world.projection;
|
|
66566
|
+
const anchors = createAnchorPass(ctx, jsx);
|
|
65241
66567
|
ctx.state.layout.cleanups.push(ecs.system(system({
|
|
65242
66568
|
name: "ui.reconcile",
|
|
65243
66569
|
phase: "layout",
|
|
@@ -65248,6 +66574,11 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
65248
66574
|
phase: "layout",
|
|
65249
66575
|
query: [],
|
|
65250
66576
|
run: (_rows, frame) => jsx.solve(frame.time)
|
|
66577
|
+
})), ecs.system(system({
|
|
66578
|
+
name: "ui.anchor",
|
|
66579
|
+
phase: "layout",
|
|
66580
|
+
query: [],
|
|
66581
|
+
run: anchors
|
|
65251
66582
|
})), ecs.system(system({
|
|
65252
66583
|
name: "ui.enter",
|
|
65253
66584
|
phase: "sync",
|
|
@@ -65315,6 +66646,7 @@ function stopUi(state) {
|
|
|
65315
66646
|
state.jsx.risen.clear();
|
|
65316
66647
|
state.jsx.released.clear();
|
|
65317
66648
|
state.jsx.scrolls.clear();
|
|
66649
|
+
state.jsx.anchors.clear();
|
|
65318
66650
|
state.jsx.remount = false;
|
|
65319
66651
|
state.jsx.asideRoots = 0;
|
|
65320
66652
|
state.jsx.hints.length = 0;
|
|
@@ -65594,121 +66926,21 @@ function createModules(ctx) {
|
|
|
65594
66926
|
};
|
|
65595
66927
|
}
|
|
65596
66928
|
/**
|
|
65597
|
-
* Creates the ui API: the
|
|
66929
|
+
* Creates the ui API: the six members a game calls, flat.
|
|
65598
66930
|
*
|
|
65599
66931
|
* @param ctx - Kernel context of the ui plugin.
|
|
65600
66932
|
* @returns The plugin API.
|
|
65601
66933
|
*/
|
|
65602
66934
|
function createUiApi(ctx) {
|
|
65603
|
-
const
|
|
66935
|
+
const uctx = withDeps(ctx);
|
|
66936
|
+
const { jsx } = createModules(uctx);
|
|
65604
66937
|
return {
|
|
65605
66938
|
tree: jsx.tree,
|
|
65606
66939
|
find: jsx.find,
|
|
65607
66940
|
lint: jsx.lint,
|
|
65608
66941
|
fill: jsx.fill,
|
|
65609
|
-
scroll: jsx.scroll
|
|
65610
|
-
|
|
65611
|
-
}
|
|
65612
|
-
//#endregion
|
|
65613
|
-
//#region src/plugins/ui/jsx/state.ts
|
|
65614
|
-
/**
|
|
65615
|
-
* Creates an empty map. Its own non-exported function, because lint rule L5 refuses a collection
|
|
65616
|
-
* built inside an exported declaration.
|
|
65617
|
-
*
|
|
65618
|
-
* @returns A map with nothing in it.
|
|
65619
|
-
*/
|
|
65620
|
-
function emptyMap$1() {
|
|
65621
|
-
return /* @__PURE__ */ new Map();
|
|
65622
|
-
}
|
|
65623
|
-
/**
|
|
65624
|
-
* Creates an empty set, for the same reason as `emptyMap`.
|
|
65625
|
-
*
|
|
65626
|
-
* @returns A set with nothing in it.
|
|
65627
|
-
*/
|
|
65628
|
-
function emptySet() {
|
|
65629
|
-
return /* @__PURE__ */ new Set();
|
|
65630
|
-
}
|
|
65631
|
-
/**
|
|
65632
|
-
* Creates the text input branch: no hidden input, nothing edited, an empty mirror.
|
|
65633
|
-
*
|
|
65634
|
-
* @returns The text state.
|
|
65635
|
-
*/
|
|
65636
|
-
function createTextState() {
|
|
65637
|
-
return {
|
|
65638
|
-
element: void 0,
|
|
65639
|
-
editing: void 0,
|
|
65640
|
-
mirror: {
|
|
65641
|
-
value: "",
|
|
65642
|
-
selectionStart: 0,
|
|
65643
|
-
selectionEnd: 0,
|
|
65644
|
-
direction: "none"
|
|
65645
|
-
},
|
|
65646
|
-
composing: void 0,
|
|
65647
|
-
keyboard: {
|
|
65648
|
-
inset: 0,
|
|
65649
|
-
innerHeight: 0,
|
|
65650
|
-
lift: 0
|
|
65651
|
-
},
|
|
65652
|
-
lifted: void 0,
|
|
65653
|
-
placed: void 0,
|
|
65654
|
-
watching: void 0,
|
|
65655
|
-
cleanups: []
|
|
65656
|
-
};
|
|
65657
|
-
}
|
|
65658
|
-
/**
|
|
65659
|
-
* Creates the jsx branch of the ui state. Everything starts empty: the registry is filled in
|
|
65660
|
-
* `onStart` from the `ui` key of every feature.
|
|
65661
|
-
*
|
|
65662
|
-
* @returns The module state.
|
|
65663
|
-
* @example
|
|
65664
|
-
* ```ts
|
|
65665
|
-
* createJsxState().roots.size; // 0
|
|
65666
|
-
* ```
|
|
65667
|
-
*/
|
|
65668
|
-
function createJsxState() {
|
|
65669
|
-
return {
|
|
65670
|
-
components: emptyMap$1(),
|
|
65671
|
-
roots: emptyMap$1(),
|
|
65672
|
-
elements: emptyMap$1(),
|
|
65673
|
-
byIdentity: emptyMap$1(),
|
|
65674
|
-
byKey: emptyMap$1(),
|
|
65675
|
-
instances: emptyMap$1(),
|
|
65676
|
-
exiting: emptySet(),
|
|
65677
|
-
leading: emptySet(),
|
|
65678
|
-
removing: emptySet(),
|
|
65679
|
-
hosts: emptySet(),
|
|
65680
|
-
hosted: emptyMap$1(),
|
|
65681
|
-
hostsVersion: 0,
|
|
65682
|
-
hostsSeen: -1,
|
|
65683
|
-
membershipSeen: -1,
|
|
65684
|
-
risen: emptySet(),
|
|
65685
|
-
released: emptySet(),
|
|
65686
|
-
building: void 0,
|
|
65687
|
-
reconciles: 0,
|
|
65688
|
-
focus: {
|
|
65689
|
-
entity: void 0,
|
|
65690
|
-
ring: void 0,
|
|
65691
|
-
drawn: void 0,
|
|
65692
|
-
tapping: false,
|
|
65693
|
-
ringless: false
|
|
65694
|
-
},
|
|
65695
|
-
fields: emptyMap$1(),
|
|
65696
|
-
text: createTextState(),
|
|
65697
|
-
hints: [],
|
|
65698
|
-
entering: {
|
|
65699
|
-
list: [],
|
|
65700
|
-
count: 0
|
|
65701
|
-
},
|
|
65702
|
-
scrolls: emptySet(),
|
|
65703
|
-
windowRenders: 0,
|
|
65704
|
-
remount: false,
|
|
65705
|
-
epoch: 0,
|
|
65706
|
-
styled: 0,
|
|
65707
|
-
written: 0,
|
|
65708
|
-
debugTaps: [],
|
|
65709
|
-
debugWarned: false,
|
|
65710
|
-
overlays: emptySet(),
|
|
65711
|
-
asideRoots: 0
|
|
66942
|
+
scroll: jsx.scroll,
|
|
66943
|
+
rectOf: (target) => rectOfTargets(uctx, target)
|
|
65712
66944
|
};
|
|
65713
66945
|
}
|
|
65714
66946
|
//#endregion
|