@moku-labs/game 0.15.47 → 0.15.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/page.d.mts +1 -1
- package/dist/app/page.mjs +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-C2-V2uKy.d.mts → commands-4ZPA_54H.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-BIDag1mb.d.mts} +3 -3
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/inspect.d.mts +6 -6
- package/dist/inspect.mjs +1 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime--I74mwMY.d.mts → runtime-BBACzetr.d.mts} +2 -2
- package/dist/{sources-MfRpM8sV.mjs → sources-Cjrzga6S.mjs} +1 -1
- package/dist/{src-CI77RUzT.mjs → src-Ddq1jS-4.mjs} +1349 -138
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-RX1bYaqD.d.mts → types-AIu9QkEJ.d.mts} +2 -2
- package/dist/{types-D4Q5MH_l.d.mts → types-BA-vO4zD.d.mts} +32 -4
- package/dist/{types-Bc_re3rB.d.mts → types-D0uITVZD.d.mts} +15 -1
- package/dist/{types-CiSVMR89.d.mts → types-SbQM-OCV.d.mts} +103 -3
- package/dist/{types-dF8Qmn7P.d.mts → types-vhOiA6D7.d.mts} +4 -4
- package/dist/{visual-wSjsCu_W.d.mts → visual-BDfG9Rgh.d.mts} +6 -6
- package/dist/{visual-ClVRMUAi.mjs → visual-LFiLc3GH.mjs} +5 -2
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +1 -1
- package/llms.txt +2 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { r as systemSource, t as memory } from "./memory-CWlqhS7l.mjs";
|
|
3
3
|
import { a as finishDrafts, i as enableDraftPatches, n as deepFreeze$1, o as openDrafts, r as dropDrafts } from "./drafts-BawpSaVp.mjs";
|
|
4
4
|
import { _ as compact, c as collectFlows, d as findNode, f as framePath, g as slotNames, h as restlessCapOf, i as servePaused, l as describeGraph, m as isRestCheckpoint, n as captureFrame, o as epochOf, p as graphHash, r as serveCaptures, s as pageNow$1, t as cancelCaptures, v as pushEntry } from "./capture-BtS6_oWr.mjs";
|
|
5
|
-
import { $ as
|
|
5
|
+
import { $ as Tree, A as isLeaving, B as Overlay, D as readStyle, F as rootPoseInto, G as Transform, H as Parent, I as rootPoseOf, K as arcDefaults, L as Display, M as parentOf$1, N as poseUnder, O as textFor, P as rootPointOf, Q as Order, R as HudPart, S as Text, U as Shape, V as OverlayLevel, W as Sprite, X as Layer, Y as Exiting, Z as Now, a as samePose, at as tag, c as Box, d as Escapable, et as component, f as LocalWrite, g as UiCounters, h as UI_OWNER, i as fitScaleOf, it as systemsFor, j as localPoseOf, k as applyPose, l as Covered, m as ScrollState, n as CONTENT$1, nt as resource, o as visualOf$1, p as Scroll, q as componentsFor, r as drawnRect, rt as system, s as visualRectOf, u as DebugTrigger, v as uiFor, w as builtInStyles, x as Countdown, z as NineSlice } from "./visual-LFiLc3GH.mjs";
|
|
6
6
|
import { a as isDev } from "./dev-BNndV-hU.mjs";
|
|
7
7
|
import { n as isComponentDefinition } from "./component-DGg5DqKK.mjs";
|
|
8
8
|
import { n as flatten } from "./flatten-nUX9PpGo.mjs";
|
|
@@ -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;
|
|
@@ -31882,7 +31882,7 @@ function stepParts(sctx) {
|
|
|
31882
31882
|
//#endregion
|
|
31883
31883
|
//#region src/plugins/renderer/sync/overlay.ts
|
|
31884
31884
|
/** How deep a `Parent` chain or a walk up the tree goes. */
|
|
31885
|
-
const MAX_DEPTH$
|
|
31885
|
+
const MAX_DEPTH$4 = 32;
|
|
31886
31886
|
/** The owner `ui` gives the entities it spawns: the only overlays honoured (O4.8). */
|
|
31887
31887
|
const UI_OWNER_NAME = "ui";
|
|
31888
31888
|
/**
|
|
@@ -31955,7 +31955,7 @@ function clampInto(sctx, entity, into, raw) {
|
|
|
31955
31955
|
function rootOf(sctx, entity) {
|
|
31956
31956
|
const ecs = sctx.ctx.deps.world.ecs;
|
|
31957
31957
|
let current = entity;
|
|
31958
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
31958
|
+
for (let depth = 0; depth < MAX_DEPTH$4; depth += 1) {
|
|
31959
31959
|
const parent = parentOf$1(ecs, current);
|
|
31960
31960
|
if (parent === 0) return current;
|
|
31961
31961
|
current = parent;
|
|
@@ -32168,7 +32168,7 @@ function drawnAlpha(sctx, record) {
|
|
|
32168
32168
|
const alphaFilter = sctx.deps.host.pixi()?.AlphaFilter;
|
|
32169
32169
|
let alpha = 1;
|
|
32170
32170
|
let node = view.wrapper ?? view.object;
|
|
32171
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
32171
|
+
for (let depth = 0; depth < MAX_DEPTH$4 && node !== null; depth += 1) {
|
|
32172
32172
|
if (node === root) return alpha;
|
|
32173
32173
|
if (!node.visible) return 0;
|
|
32174
32174
|
const owner = state.viewOfTop.get(node);
|
|
@@ -47888,7 +47888,7 @@ const EFFECTS_OWNER = Object.freeze({
|
|
|
47888
47888
|
name: "effects"
|
|
47889
47889
|
});
|
|
47890
47890
|
/** How deep a parent chain is followed, as `rootPoseOf` does; deeper is treated as a loop. */
|
|
47891
|
-
const MAX_DEPTH$
|
|
47891
|
+
const MAX_DEPTH$3 = 32;
|
|
47892
47892
|
/**
|
|
47893
47893
|
* The one dynamic set of an emitter container (P9): positions, frames, rotations and colours
|
|
47894
47894
|
* upload every frame; `uvs` stays static, because a frame is set at birth and the same `update()`
|
|
@@ -47931,7 +47931,7 @@ function bornFields(size) {
|
|
|
47931
47931
|
*/
|
|
47932
47932
|
function topOf(ecs, host) {
|
|
47933
47933
|
let top = host;
|
|
47934
|
-
for (let depth = 0; depth < MAX_DEPTH$
|
|
47934
|
+
for (let depth = 0; depth < MAX_DEPTH$3; depth += 1) {
|
|
47935
47935
|
const parent = parentOf$1(ecs, top);
|
|
47936
47936
|
if (parent === 0) break;
|
|
47937
47937
|
top = parent;
|
|
@@ -50162,7 +50162,7 @@ const Pointer = /*#__PURE__*/ resource("Pointer", pointerDefaults);
|
|
|
50162
50162
|
* point: a view drawn over a scroll from another root keeps its press.
|
|
50163
50163
|
*/
|
|
50164
50164
|
/** How deep a `Parent` chain is followed; deeper is treated as a loop. */
|
|
50165
|
-
const MAX_DEPTH = 32;
|
|
50165
|
+
const MAX_DEPTH$2 = 32;
|
|
50166
50166
|
/**
|
|
50167
50167
|
* Resolves what `app.input.*` was pointed at. A `{ projection, key }` goes through
|
|
50168
50168
|
* `world.projection.entityOf`, which answers for live views only, so a view in the despawn queue
|
|
@@ -50258,7 +50258,7 @@ function findPressed(ctx, x, y) {
|
|
|
50258
50258
|
function movingScrollOf(ctx, entity) {
|
|
50259
50259
|
const { ecs } = ctx.deps.world;
|
|
50260
50260
|
let current = entity;
|
|
50261
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50261
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
50262
50262
|
if (ecs.get(current, Scrollable)?.moving === true && !ecs.has(current, Exiting)) return current;
|
|
50263
50263
|
current = parentOf$1(ecs, current);
|
|
50264
50264
|
}
|
|
@@ -50277,7 +50277,7 @@ function movingScrollOf(ctx, entity) {
|
|
|
50277
50277
|
function scrollOnAxisOf(ctx, entity, axis) {
|
|
50278
50278
|
const { ecs } = ctx.deps.world;
|
|
50279
50279
|
let current = entity;
|
|
50280
|
-
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
50280
|
+
for (let depth = 0; depth < MAX_DEPTH$2 && current !== 0; depth += 1) {
|
|
50281
50281
|
if (ecs.get(current, Scrollable)?.axis === axis && !ecs.has(current, Exiting)) return current;
|
|
50282
50282
|
current = parentOf$1(ecs, current);
|
|
50283
50283
|
}
|
|
@@ -55345,6 +55345,301 @@ const textPlugin = /*#__PURE__*/ createPlugin$1("text", {
|
|
|
55345
55345
|
onStop: ({ state }) => stopText(state)
|
|
55346
55346
|
});
|
|
55347
55347
|
//#endregion
|
|
55348
|
+
//#region src/plugins/ui/drawn.ts
|
|
55349
|
+
/**
|
|
55350
|
+
* @file ui plugin — where a target is drawn, in screen reference units: the one resolver the
|
|
55351
|
+
* `<anchor>` pass and `app.ui.rectOf` share. A target's local box goes through its root pose, the
|
|
55352
|
+
* `Transform` of every entity on its way up composed, so a scroll's offset, a fit, a slot and the
|
|
55353
|
+
* motion of an ancestor move it. Axis-aligned: the rotation is left out. A ui element spawned in
|
|
55354
|
+
* this frame has no `Transform` until the flush of the phase: its rest pose stands in, so it is
|
|
55355
|
+
* found in the frame it is laid out. The frame path allocates nothing: every answer is written into
|
|
55356
|
+
* the caller's objects, and no fractional number crosses a call. `rectOf` answers a new rect.
|
|
55357
|
+
*/
|
|
55358
|
+
/** How deep a chain is followed; deeper is treated as a loop. */
|
|
55359
|
+
const MAX_DEPTH$1 = 32;
|
|
55360
|
+
/** The alpha a target is drawn at below which it counts as not shown, as the hit test reads it. */
|
|
55361
|
+
const MIN_ALPHA = .01;
|
|
55362
|
+
/**
|
|
55363
|
+
* The reader of a running `ui`, over its world and its own state.
|
|
55364
|
+
*
|
|
55365
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55366
|
+
* @returns The reader; it holds the live maps, so it stays current.
|
|
55367
|
+
*/
|
|
55368
|
+
function readerOf(ctx) {
|
|
55369
|
+
return {
|
|
55370
|
+
ecs: ctx.deps.world.ecs,
|
|
55371
|
+
projection: ctx.deps.world.projection,
|
|
55372
|
+
elements: ctx.state.jsx.elements,
|
|
55373
|
+
roots: ctx.state.jsx.roots,
|
|
55374
|
+
exiting: ctx.state.jsx.exiting
|
|
55375
|
+
};
|
|
55376
|
+
}
|
|
55377
|
+
/**
|
|
55378
|
+
* The entity an entity is drawn under: the parent of a ui element, the slot of a root element laid
|
|
55379
|
+
* out in one, the `Parent` of any other view.
|
|
55380
|
+
*
|
|
55381
|
+
* @param reader - What the resolver reads.
|
|
55382
|
+
* @param entity - The entity.
|
|
55383
|
+
* @returns The entity above it, or 0 when it hangs in its layer.
|
|
55384
|
+
*/
|
|
55385
|
+
function upOf(reader, entity) {
|
|
55386
|
+
const element = reader.elements.get(entity);
|
|
55387
|
+
if (element === void 0) return parentOf$1(reader.ecs, entity);
|
|
55388
|
+
return element.parent ?? reader.roots.get(element.root)?.slot ?? 0;
|
|
55389
|
+
}
|
|
55390
|
+
/**
|
|
55391
|
+
* The pose an entity is drawn with: its `Transform`, or the rest pose of a ui element whose
|
|
55392
|
+
* `Transform` waits for the flush.
|
|
55393
|
+
*
|
|
55394
|
+
* @param reader - What the resolver reads.
|
|
55395
|
+
* @param entity - The entity.
|
|
55396
|
+
* @returns The pose, or `undefined` for a view with no `Transform`.
|
|
55397
|
+
*/
|
|
55398
|
+
function poseOf(reader, entity) {
|
|
55399
|
+
return reader.ecs.get(entity, Transform) ?? reader.elements.get(entity)?.rest;
|
|
55400
|
+
}
|
|
55401
|
+
/**
|
|
55402
|
+
* Writes where an entity really is: its pose composed through every entity it is drawn under,
|
|
55403
|
+
* the arithmetic of `rootPoseInto`, over `upOf`. The answer keeps the entity's own pivot. Kept in
|
|
55404
|
+
* step with `rootPoseInto` of `renderer/sync/pose.ts`: the same composition, step by step, over the
|
|
55405
|
+
* parents of `ui` elements and the rest pose of an element whose `Transform` has not landed.
|
|
55406
|
+
*
|
|
55407
|
+
* @param reader - What the resolver reads.
|
|
55408
|
+
* @param entity - The entity.
|
|
55409
|
+
* @param out - The pose to write, its `pivot` included.
|
|
55410
|
+
* @returns False for a view with no `Transform`: `out` is not written.
|
|
55411
|
+
*/
|
|
55412
|
+
function drawnPoseInto(reader, entity, out) {
|
|
55413
|
+
const own = poseOf(reader, entity);
|
|
55414
|
+
if (own === void 0) return false;
|
|
55415
|
+
out.x = own.x;
|
|
55416
|
+
out.y = own.y;
|
|
55417
|
+
out.rotation = own.rotation;
|
|
55418
|
+
out.scale = own.scale;
|
|
55419
|
+
out.pivot.x = own.pivot.x;
|
|
55420
|
+
out.pivot.y = own.pivot.y;
|
|
55421
|
+
let current = entity;
|
|
55422
|
+
for (let depth = 0; depth < MAX_DEPTH$1; depth += 1) {
|
|
55423
|
+
const parent = upOf(reader, current);
|
|
55424
|
+
if (parent === 0) break;
|
|
55425
|
+
const above = poseOf(reader, parent) ?? Transform.defaults;
|
|
55426
|
+
const cos = Math.cos(above.rotation);
|
|
55427
|
+
const sin = Math.sin(above.rotation);
|
|
55428
|
+
const dx = out.x - above.pivot.x;
|
|
55429
|
+
const dy = out.y - above.pivot.y;
|
|
55430
|
+
out.x = above.x + above.scale * (dx * cos - dy * sin);
|
|
55431
|
+
out.y = above.y + above.scale * (dx * sin + dy * cos);
|
|
55432
|
+
out.rotation += above.rotation;
|
|
55433
|
+
out.scale *= above.scale;
|
|
55434
|
+
current = parent;
|
|
55435
|
+
}
|
|
55436
|
+
return true;
|
|
55437
|
+
}
|
|
55438
|
+
/**
|
|
55439
|
+
* Tells whether an entity belongs to a scene built aside or a held warm window: the entity itself,
|
|
55440
|
+
* or the root of a ui element, as the reconcile asks it.
|
|
55441
|
+
*
|
|
55442
|
+
* @param reader - What the resolver reads.
|
|
55443
|
+
* @param entity - The entity.
|
|
55444
|
+
* @returns True while it is not on the screen yet.
|
|
55445
|
+
*/
|
|
55446
|
+
function building(reader, entity) {
|
|
55447
|
+
const element = reader.elements.get(entity);
|
|
55448
|
+
return reader.projection.isBuilding(entity) || element !== void 0 && reader.projection.isBuilding(element.root);
|
|
55449
|
+
}
|
|
55450
|
+
/**
|
|
55451
|
+
* Tells whether the player can see an entity: neither it nor anything it is drawn under is on its
|
|
55452
|
+
* way out, and the alphas of their visuals (`Shape`, `NineSlice`, `Sprite` or `Text`) multiply to
|
|
55453
|
+
* more than 0.01. The alpha of a visual fades the entity's children with it, as the renderer draws
|
|
55454
|
+
* it.
|
|
55455
|
+
*
|
|
55456
|
+
* @param reader - What the resolver reads.
|
|
55457
|
+
* @param entity - The entity.
|
|
55458
|
+
* @returns True when it is shown.
|
|
55459
|
+
*/
|
|
55460
|
+
function visible(reader, entity) {
|
|
55461
|
+
const ecs = reader.ecs;
|
|
55462
|
+
let alpha = 1;
|
|
55463
|
+
let current = entity;
|
|
55464
|
+
for (let depth = 0; depth < MAX_DEPTH$1 && current !== 0; depth += 1) {
|
|
55465
|
+
if (reader.exiting.has(current) || ecs.has(current, Exiting)) return false;
|
|
55466
|
+
alpha *= ecs.get(current, Shape)?.alpha ?? ecs.get(current, NineSlice)?.alpha ?? ecs.get(current, Sprite)?.alpha ?? ecs.get(current, Text)?.alpha ?? 1;
|
|
55467
|
+
current = upOf(reader, current);
|
|
55468
|
+
}
|
|
55469
|
+
return alpha > MIN_ALPHA;
|
|
55470
|
+
}
|
|
55471
|
+
/**
|
|
55472
|
+
* Moves a local box of an entity into root space, in place: moved by the pose, scaled around its
|
|
55473
|
+
* pivot, the rotation left out. The numbers stay in the rect: a fractional number handed to a call
|
|
55474
|
+
* is boxed.
|
|
55475
|
+
*
|
|
55476
|
+
* @param pose - The root pose of the entity.
|
|
55477
|
+
* @param out - The box in the entity's own units, written in root space.
|
|
55478
|
+
*/
|
|
55479
|
+
function toRoot(pose, out) {
|
|
55480
|
+
out.x = pose.x + pose.scale * (out.x - pose.pivot.x);
|
|
55481
|
+
out.y = pose.y + pose.scale * (out.y - pose.pivot.y);
|
|
55482
|
+
out.w *= pose.scale;
|
|
55483
|
+
out.h *= pose.scale;
|
|
55484
|
+
}
|
|
55485
|
+
/**
|
|
55486
|
+
* Writes the box of an entity in its own units, by what it draws: the layout box of a ui element,
|
|
55487
|
+
* the panel of a nine-slice, the rectangle of a shape, the anchor box of a sprite.
|
|
55488
|
+
*
|
|
55489
|
+
* @param reader - What the resolver reads.
|
|
55490
|
+
* @param entity - The entity.
|
|
55491
|
+
* @param out - The rect written, its `x` and `y` at 0 when the call starts.
|
|
55492
|
+
* @returns False for an entity that draws none of them.
|
|
55493
|
+
*/
|
|
55494
|
+
function ownBoxInto(reader, entity, out) {
|
|
55495
|
+
const element = reader.elements.get(entity);
|
|
55496
|
+
if (element !== void 0) {
|
|
55497
|
+
out.w = element.rect.w;
|
|
55498
|
+
out.h = element.rect.h;
|
|
55499
|
+
return true;
|
|
55500
|
+
}
|
|
55501
|
+
const panel = reader.ecs.get(entity, NineSlice);
|
|
55502
|
+
if (panel !== void 0) {
|
|
55503
|
+
out.w = panel.width;
|
|
55504
|
+
out.h = panel.height;
|
|
55505
|
+
return true;
|
|
55506
|
+
}
|
|
55507
|
+
const shape = reader.ecs.get(entity, Shape);
|
|
55508
|
+
if (shape !== void 0) {
|
|
55509
|
+
out.w = shape.w;
|
|
55510
|
+
out.h = shape.h;
|
|
55511
|
+
return true;
|
|
55512
|
+
}
|
|
55513
|
+
const sprite = reader.ecs.get(entity, Sprite);
|
|
55514
|
+
if (sprite === void 0) return false;
|
|
55515
|
+
out.w = sprite.width;
|
|
55516
|
+
out.h = sprite.height;
|
|
55517
|
+
out.x = -sprite.anchor.x * sprite.width;
|
|
55518
|
+
out.y = -sprite.anchor.y * sprite.height;
|
|
55519
|
+
return true;
|
|
55520
|
+
}
|
|
55521
|
+
/**
|
|
55522
|
+
* Writes the box an entity draws in root space: its own box through its root pose.
|
|
55523
|
+
*
|
|
55524
|
+
* @param reader - What the resolver reads.
|
|
55525
|
+
* @param entity - The entity.
|
|
55526
|
+
* @param pose - Its root pose.
|
|
55527
|
+
* @param out - The rect written, in root space.
|
|
55528
|
+
* @returns False for an entity that draws no box.
|
|
55529
|
+
*/
|
|
55530
|
+
function localBoxInto(reader, entity, pose, out) {
|
|
55531
|
+
out.x = 0;
|
|
55532
|
+
out.y = 0;
|
|
55533
|
+
if (!ownBoxInto(reader, entity, out)) return false;
|
|
55534
|
+
toRoot(pose, out);
|
|
55535
|
+
return true;
|
|
55536
|
+
}
|
|
55537
|
+
/**
|
|
55538
|
+
* Writes where an entity is drawn, in screen reference units, when it is shown. Not shown: the
|
|
55539
|
+
* entity belongs to a scene built aside, it or something it is drawn under is leaving, the alphas
|
|
55540
|
+
* on its way up multiply to 0.01 or less, it draws no box, or the box has no area.
|
|
55541
|
+
*
|
|
55542
|
+
* @param reader - What the resolver reads.
|
|
55543
|
+
* @param entity - The entity of the target.
|
|
55544
|
+
* @param out - The rect written.
|
|
55545
|
+
* @param pose - A pose the resolver writes on its way, kept by the caller.
|
|
55546
|
+
* @returns True when the target is shown and `out` holds its rect.
|
|
55547
|
+
*/
|
|
55548
|
+
function drawnInto(reader, entity, out, pose) {
|
|
55549
|
+
if (building(reader, entity) || !visible(reader, entity)) return false;
|
|
55550
|
+
if (!drawnPoseInto(reader, entity, pose) || !localBoxInto(reader, entity, pose, out)) return false;
|
|
55551
|
+
return out.w > 0 && out.h > 0;
|
|
55552
|
+
}
|
|
55553
|
+
/**
|
|
55554
|
+
* Grows a rect to hold another one.
|
|
55555
|
+
*
|
|
55556
|
+
* @param out - The rect grown in place.
|
|
55557
|
+
* @param part - The rect it must hold.
|
|
55558
|
+
*/
|
|
55559
|
+
function unionInto(out, part) {
|
|
55560
|
+
const right = Math.max(out.x + out.w, part.x + part.w);
|
|
55561
|
+
const bottom = Math.max(out.y + out.h, part.y + part.h);
|
|
55562
|
+
out.x = Math.min(out.x, part.x);
|
|
55563
|
+
out.y = Math.min(out.y, part.y);
|
|
55564
|
+
out.w = right - out.x;
|
|
55565
|
+
out.h = bottom - out.y;
|
|
55566
|
+
}
|
|
55567
|
+
/**
|
|
55568
|
+
* Tells a list of targets from one target.
|
|
55569
|
+
*
|
|
55570
|
+
* @param to - What `to` or `rectOf` was given, or nothing.
|
|
55571
|
+
* @returns True for a list.
|
|
55572
|
+
* @example
|
|
55573
|
+
* ```ts
|
|
55574
|
+
* isTargetList([{ projection: "hud", key: "coins" }]); // true
|
|
55575
|
+
* ```
|
|
55576
|
+
*/
|
|
55577
|
+
function isTargetList(to) {
|
|
55578
|
+
return Array.isArray(to);
|
|
55579
|
+
}
|
|
55580
|
+
/**
|
|
55581
|
+
* Writes the rect of one target or the bounding rect of the shown ones of a list.
|
|
55582
|
+
*
|
|
55583
|
+
* @param reader - What the resolver reads.
|
|
55584
|
+
* @param to - One target or a list of them.
|
|
55585
|
+
* @param out - The rect written.
|
|
55586
|
+
* @param scratch - The part and the pose the resolver writes on its way.
|
|
55587
|
+
* @param scratch.part - The rect of one target.
|
|
55588
|
+
* @param scratch.pose - The pose of one target.
|
|
55589
|
+
* @returns True when at least one target is shown.
|
|
55590
|
+
*/
|
|
55591
|
+
function targetsInto(reader, to, out, scratch) {
|
|
55592
|
+
const list = isTargetList(to) ? to : [to];
|
|
55593
|
+
let shown = false;
|
|
55594
|
+
for (const target of list) {
|
|
55595
|
+
const entity = reader.projection.entityOf(target.projection, target.key);
|
|
55596
|
+
if (entity === void 0 || !drawnInto(reader, entity, scratch.part, scratch.pose)) continue;
|
|
55597
|
+
if (shown) unionInto(out, scratch.part);
|
|
55598
|
+
else {
|
|
55599
|
+
out.x = scratch.part.x;
|
|
55600
|
+
out.y = scratch.part.y;
|
|
55601
|
+
out.w = scratch.part.w;
|
|
55602
|
+
out.h = scratch.part.h;
|
|
55603
|
+
shown = true;
|
|
55604
|
+
}
|
|
55605
|
+
}
|
|
55606
|
+
return shown;
|
|
55607
|
+
}
|
|
55608
|
+
/**
|
|
55609
|
+
* Where a target, or the shown targets of a list, are drawn: `app.ui.rectOf`. Not a frame path:
|
|
55610
|
+
* every call answers a new rect.
|
|
55611
|
+
*
|
|
55612
|
+
* @param ctx - Domain context of the ui plugin.
|
|
55613
|
+
* @param to - One target or a list of them.
|
|
55614
|
+
* @returns The rect in screen reference units, or `undefined` when no target is shown.
|
|
55615
|
+
*/
|
|
55616
|
+
function rectOfTargets(ctx, to) {
|
|
55617
|
+
const out = {
|
|
55618
|
+
x: 0,
|
|
55619
|
+
y: 0,
|
|
55620
|
+
w: 0,
|
|
55621
|
+
h: 0
|
|
55622
|
+
};
|
|
55623
|
+
return targetsInto(readerOf(ctx), to, out, {
|
|
55624
|
+
part: {
|
|
55625
|
+
x: 0,
|
|
55626
|
+
y: 0,
|
|
55627
|
+
w: 0,
|
|
55628
|
+
h: 0
|
|
55629
|
+
},
|
|
55630
|
+
pose: {
|
|
55631
|
+
x: 0,
|
|
55632
|
+
y: 0,
|
|
55633
|
+
rotation: 0,
|
|
55634
|
+
scale: 1,
|
|
55635
|
+
pivot: {
|
|
55636
|
+
x: 0,
|
|
55637
|
+
y: 0
|
|
55638
|
+
}
|
|
55639
|
+
}
|
|
55640
|
+
}) ? out : void 0;
|
|
55641
|
+
}
|
|
55642
|
+
//#endregion
|
|
55348
55643
|
//#region src/plugins/ui/jsx/field-layout.ts
|
|
55349
55644
|
/**
|
|
55350
55645
|
* The four edges of a resolved padding.
|
|
@@ -60102,6 +60397,186 @@ function sameValue(left, right) {
|
|
|
60102
60397
|
return sameFieldsDeep(left, right);
|
|
60103
60398
|
}
|
|
60104
60399
|
//#endregion
|
|
60400
|
+
//#region src/plugins/ui/jsx/state.ts
|
|
60401
|
+
/**
|
|
60402
|
+
* Creates an empty map. Its own non-exported function, because lint rule L5 refuses a collection
|
|
60403
|
+
* built inside an exported declaration.
|
|
60404
|
+
*
|
|
60405
|
+
* @returns A map with nothing in it.
|
|
60406
|
+
*/
|
|
60407
|
+
function emptyMap$1() {
|
|
60408
|
+
return /* @__PURE__ */ new Map();
|
|
60409
|
+
}
|
|
60410
|
+
/**
|
|
60411
|
+
* Creates an empty set, for the same reason as `emptyMap`.
|
|
60412
|
+
*
|
|
60413
|
+
* @returns A set with nothing in it.
|
|
60414
|
+
*/
|
|
60415
|
+
function emptySet() {
|
|
60416
|
+
return /* @__PURE__ */ new Set();
|
|
60417
|
+
}
|
|
60418
|
+
/**
|
|
60419
|
+
* Creates the text input branch: no hidden input, nothing edited, an empty mirror.
|
|
60420
|
+
*
|
|
60421
|
+
* @returns The text state.
|
|
60422
|
+
*/
|
|
60423
|
+
function createTextState() {
|
|
60424
|
+
return {
|
|
60425
|
+
element: void 0,
|
|
60426
|
+
editing: void 0,
|
|
60427
|
+
mirror: {
|
|
60428
|
+
value: "",
|
|
60429
|
+
selectionStart: 0,
|
|
60430
|
+
selectionEnd: 0,
|
|
60431
|
+
direction: "none"
|
|
60432
|
+
},
|
|
60433
|
+
composing: void 0,
|
|
60434
|
+
keyboard: {
|
|
60435
|
+
inset: 0,
|
|
60436
|
+
innerHeight: 0,
|
|
60437
|
+
lift: 0
|
|
60438
|
+
},
|
|
60439
|
+
lifted: void 0,
|
|
60440
|
+
placed: void 0,
|
|
60441
|
+
watching: void 0,
|
|
60442
|
+
cleanups: []
|
|
60443
|
+
};
|
|
60444
|
+
}
|
|
60445
|
+
/**
|
|
60446
|
+
* Creates the jsx branch of the ui state. Everything starts empty: the registry is filled in
|
|
60447
|
+
* `onStart` from the `ui` key of every feature.
|
|
60448
|
+
*
|
|
60449
|
+
* @returns The module state.
|
|
60450
|
+
* @example
|
|
60451
|
+
* ```ts
|
|
60452
|
+
* createJsxState().roots.size; // 0
|
|
60453
|
+
* ```
|
|
60454
|
+
*/
|
|
60455
|
+
function createJsxState() {
|
|
60456
|
+
return {
|
|
60457
|
+
components: emptyMap$1(),
|
|
60458
|
+
roots: emptyMap$1(),
|
|
60459
|
+
elements: emptyMap$1(),
|
|
60460
|
+
byIdentity: emptyMap$1(),
|
|
60461
|
+
byKey: emptyMap$1(),
|
|
60462
|
+
instances: emptyMap$1(),
|
|
60463
|
+
exiting: emptySet(),
|
|
60464
|
+
leading: emptySet(),
|
|
60465
|
+
removing: emptySet(),
|
|
60466
|
+
hosts: emptySet(),
|
|
60467
|
+
hosted: emptyMap$1(),
|
|
60468
|
+
hostsVersion: 0,
|
|
60469
|
+
hostsSeen: -1,
|
|
60470
|
+
membershipSeen: -1,
|
|
60471
|
+
risen: emptySet(),
|
|
60472
|
+
released: emptySet(),
|
|
60473
|
+
building: void 0,
|
|
60474
|
+
reconciles: 0,
|
|
60475
|
+
focus: {
|
|
60476
|
+
entity: void 0,
|
|
60477
|
+
ring: void 0,
|
|
60478
|
+
drawn: void 0,
|
|
60479
|
+
tapping: false,
|
|
60480
|
+
ringless: false
|
|
60481
|
+
},
|
|
60482
|
+
fields: emptyMap$1(),
|
|
60483
|
+
text: createTextState(),
|
|
60484
|
+
hints: [],
|
|
60485
|
+
entering: {
|
|
60486
|
+
list: [],
|
|
60487
|
+
count: 0
|
|
60488
|
+
},
|
|
60489
|
+
scrolls: emptySet(),
|
|
60490
|
+
windowRenders: 0,
|
|
60491
|
+
remount: false,
|
|
60492
|
+
epoch: 0,
|
|
60493
|
+
styled: 0,
|
|
60494
|
+
written: 0,
|
|
60495
|
+
debugTaps: [],
|
|
60496
|
+
debugWarned: false,
|
|
60497
|
+
overlays: emptySet(),
|
|
60498
|
+
asideRoots: 0,
|
|
60499
|
+
anchors: emptyMap$1()
|
|
60500
|
+
};
|
|
60501
|
+
}
|
|
60502
|
+
/**
|
|
60503
|
+
* Creates a rect the anchor pass writes in every frame. Its keys come in an order of their own
|
|
60504
|
+
* (`w`, `h`, `x`, `y`): V8 gives every `{ x, y, w, h }` object one hidden shape, the frozen `Box`
|
|
60505
|
+
* values among them, and in that shape `x` and `y` hold boxed numbers, so each fractional number
|
|
60506
|
+
* written there allocates 16 B. In a shape of its own the four fields take a double in place.
|
|
60507
|
+
*
|
|
60508
|
+
* @param x - The left.
|
|
60509
|
+
* @param y - The top.
|
|
60510
|
+
* @param w - The width.
|
|
60511
|
+
* @param h - The height.
|
|
60512
|
+
* @returns The rect.
|
|
60513
|
+
* @example
|
|
60514
|
+
* ```ts
|
|
60515
|
+
* ownRect(40, 1500, 116, 120).x; // 40
|
|
60516
|
+
* ```
|
|
60517
|
+
*/
|
|
60518
|
+
function ownRect(x, y, w, h) {
|
|
60519
|
+
return {
|
|
60520
|
+
w,
|
|
60521
|
+
h,
|
|
60522
|
+
x,
|
|
60523
|
+
y
|
|
60524
|
+
};
|
|
60525
|
+
}
|
|
60526
|
+
/**
|
|
60527
|
+
* Creates what the anchor pass keeps for a new `<anchor>`: nothing read yet, not placed.
|
|
60528
|
+
*
|
|
60529
|
+
* @returns The record, every rect and the pose zeroed.
|
|
60530
|
+
*/
|
|
60531
|
+
function createAnchor() {
|
|
60532
|
+
return {
|
|
60533
|
+
node: void 0,
|
|
60534
|
+
to: void 0,
|
|
60535
|
+
retarget: false,
|
|
60536
|
+
seen: [],
|
|
60537
|
+
shown: [],
|
|
60538
|
+
count: 0,
|
|
60539
|
+
shownCount: 0,
|
|
60540
|
+
screen: ownRect(0, 0, 0, 0),
|
|
60541
|
+
part: ownRect(0, 0, 0, 0),
|
|
60542
|
+
next: ownRect(0, 0, 0, 0),
|
|
60543
|
+
pose: {
|
|
60544
|
+
x: 0,
|
|
60545
|
+
y: 0,
|
|
60546
|
+
rotation: 0,
|
|
60547
|
+
scale: 1,
|
|
60548
|
+
pivot: {
|
|
60549
|
+
x: 0,
|
|
60550
|
+
y: 0
|
|
60551
|
+
}
|
|
60552
|
+
},
|
|
60553
|
+
placed: false,
|
|
60554
|
+
hidden: false,
|
|
60555
|
+
missing: 0,
|
|
60556
|
+
owed: false,
|
|
60557
|
+
stale: false,
|
|
60558
|
+
boxes: false,
|
|
60559
|
+
held: void 0,
|
|
60560
|
+
aim: {
|
|
60561
|
+
x: 0,
|
|
60562
|
+
y: 0
|
|
60563
|
+
},
|
|
60564
|
+
track: {
|
|
60565
|
+
x: 0,
|
|
60566
|
+
y: 0
|
|
60567
|
+
},
|
|
60568
|
+
wrote: {
|
|
60569
|
+
x: NaN,
|
|
60570
|
+
y: NaN
|
|
60571
|
+
},
|
|
60572
|
+
warned: {
|
|
60573
|
+
missing: false,
|
|
60574
|
+
own: false,
|
|
60575
|
+
style: false
|
|
60576
|
+
}
|
|
60577
|
+
};
|
|
60578
|
+
}
|
|
60579
|
+
//#endregion
|
|
60105
60580
|
//#region src/plugins/ui/jsx/reconcile.ts
|
|
60106
60581
|
/**
|
|
60107
60582
|
* @file ui/jsx — the reconcile: a description tree diffed by identity into the entities `ui`
|
|
@@ -60589,6 +61064,22 @@ function identitySet(identities) {
|
|
|
60589
61064
|
return new Set(identities);
|
|
60590
61065
|
}
|
|
60591
61066
|
/**
|
|
61067
|
+
* Tells whether an element is an `<anchor>` or lies under one: the anchor pass places it after
|
|
61068
|
+
* the solve, by its targets, so the solve leaves it alone.
|
|
61069
|
+
*
|
|
61070
|
+
* @param element - The element.
|
|
61071
|
+
* @param lookup - How a parent entity becomes its element.
|
|
61072
|
+
* @returns True for an anchor and everything under it.
|
|
61073
|
+
*/
|
|
61074
|
+
function isAnchored(element, lookup) {
|
|
61075
|
+
let current = element;
|
|
61076
|
+
while (current !== void 0) {
|
|
61077
|
+
if (current.type === "anchor") return true;
|
|
61078
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
61079
|
+
}
|
|
61080
|
+
return false;
|
|
61081
|
+
}
|
|
61082
|
+
/**
|
|
60592
61083
|
* Tells whether an element whose `Box` just came arrives with an enter: new, and not a row a
|
|
60593
61084
|
* range change scrolled in.
|
|
60594
61085
|
*
|
|
@@ -60639,6 +61130,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60639
61130
|
let rendered = 0;
|
|
60640
61131
|
const isAside = (entity) => ctx.deps.world.projection.isBuilding(entity);
|
|
60641
61132
|
let released = false;
|
|
61133
|
+
let anchoring = false;
|
|
60642
61134
|
let asideSeen = -1;
|
|
60643
61135
|
let enteredSeen = -1;
|
|
60644
61136
|
let heldEnters = -1;
|
|
@@ -60771,6 +61263,7 @@ function createReconciler(ctx, modules, fields) {
|
|
|
60771
61263
|
state.scrolls.add(entity);
|
|
60772
61264
|
element.scroll = scrollMotionOf(node);
|
|
60773
61265
|
}
|
|
61266
|
+
if (element.type === "anchor") state.anchors.set(entity, createAnchor());
|
|
60774
61267
|
modules.layout.attach(element);
|
|
60775
61268
|
element.basis = {
|
|
60776
61269
|
epoch: state.epoch,
|
|
@@ -61339,6 +61832,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61339
61832
|
if (hostsOf(element.node).length > 0) hostsMoved(state);
|
|
61340
61833
|
state.hosts.delete(element.entity);
|
|
61341
61834
|
state.scrolls.delete(element.entity);
|
|
61835
|
+
state.anchors.get(element.entity)?.held?.();
|
|
61836
|
+
state.anchors.delete(element.entity);
|
|
61342
61837
|
state.exiting.delete(element.entity);
|
|
61343
61838
|
state.leading.delete(element.entity);
|
|
61344
61839
|
state.overlays.delete(element.entity);
|
|
@@ -61457,12 +61952,14 @@ function createReconciler(ctx, modules, fields) {
|
|
|
61457
61952
|
}
|
|
61458
61953
|
}
|
|
61459
61954
|
/**
|
|
61460
|
-
* Applies the solved rect of one element: a live one moves, a new one spawns its components.
|
|
61955
|
+
* Applies the solved rect of one element: a live one moves, a new one spawns its components. An
|
|
61956
|
+
* `<anchor>` and everything under it wait for the anchor pass, which places them by their targets.
|
|
61461
61957
|
*
|
|
61462
61958
|
* @param element - The element to apply.
|
|
61463
61959
|
* @param quiet - Whether a live element takes its rect with no motion.
|
|
61464
61960
|
*/
|
|
61465
61961
|
function applyElement(element, quiet) {
|
|
61962
|
+
if (!anchoring && state.anchors.size > 0 && isAnchored(element, lookup)) return;
|
|
61466
61963
|
const parent = parentRect(element);
|
|
61467
61964
|
if (element.live) applyLive(element, parent, quiet);
|
|
61468
61965
|
else applyFirst(element, parent);
|
|
@@ -62174,6 +62671,21 @@ function createReconciler(ctx, modules, fields) {
|
|
|
62174
62671
|
hostsMoved(state);
|
|
62175
62672
|
}
|
|
62176
62673
|
/**
|
|
62674
|
+
* Applies the rect the anchor pass gave one element of an `<anchor>` subtree, as the solve
|
|
62675
|
+
* applies any other element.
|
|
62676
|
+
*
|
|
62677
|
+
* @param element - The anchor or an element under it.
|
|
62678
|
+
* @param quiet - Whether a live element takes its rect with no motion.
|
|
62679
|
+
*/
|
|
62680
|
+
function applyAnchored(element, quiet) {
|
|
62681
|
+
anchoring = true;
|
|
62682
|
+
try {
|
|
62683
|
+
applyElement(element, quiet);
|
|
62684
|
+
} finally {
|
|
62685
|
+
anchoring = false;
|
|
62686
|
+
}
|
|
62687
|
+
}
|
|
62688
|
+
/**
|
|
62177
62689
|
* Re-resolves the style of one element whose pointer or focus flag changed: a press, a release,
|
|
62178
62690
|
* the mouse coming over it or leaving it, the keyboard focus arriving or leaving. A new rect
|
|
62179
62691
|
* waits for the solve; a new look and a new rest pose apply now. Only this element is restyled:
|
|
@@ -62212,7 +62724,8 @@ function createReconciler(ctx, modules, fields) {
|
|
|
62212
62724
|
playEntered,
|
|
62213
62725
|
sweep,
|
|
62214
62726
|
converged,
|
|
62215
|
-
asideBuilt
|
|
62727
|
+
asideBuilt,
|
|
62728
|
+
applyAnchored
|
|
62216
62729
|
};
|
|
62217
62730
|
}
|
|
62218
62731
|
//#endregion
|
|
@@ -62370,6 +62883,7 @@ function createJsxApi(ctx, modules) {
|
|
|
62370
62883
|
playEntered: frame.playEntered,
|
|
62371
62884
|
converged: frame.converged,
|
|
62372
62885
|
asideBuilt: frame.asideBuilt,
|
|
62886
|
+
applyAnchored: frame.applyAnchored,
|
|
62373
62887
|
key: (input) => focus.key(input),
|
|
62374
62888
|
blur: focus.blur
|
|
62375
62889
|
};
|
|
@@ -63148,7 +63662,9 @@ function freeNode(state, element) {
|
|
|
63148
63662
|
}
|
|
63149
63663
|
/**
|
|
63150
63664
|
* 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).
|
|
63665
|
+
* reconcile — per exiting child it made a thousand-row churn quadratic (spike P4, point 4). An
|
|
63666
|
+
* `<anchor>` is left out: its node is a tree of its own, which the anchor pass lays out at the
|
|
63667
|
+
* size of its targets, so it takes no room in the flow of its parent.
|
|
63152
63668
|
*
|
|
63153
63669
|
* @param state - The layout state.
|
|
63154
63670
|
* @param parent - The element whose child list changed.
|
|
@@ -63161,7 +63677,7 @@ function placeChildren(state, parent, children) {
|
|
|
63161
63677
|
let index = 0;
|
|
63162
63678
|
for (const child of children) {
|
|
63163
63679
|
const childNode = state.byEntity.get(child.entity);
|
|
63164
|
-
if (childNode === void 0) continue;
|
|
63680
|
+
if (childNode === void 0 || child.type === "anchor") continue;
|
|
63165
63681
|
node.insertChild(childNode, index);
|
|
63166
63682
|
index += 1;
|
|
63167
63683
|
}
|
|
@@ -64018,7 +64534,7 @@ function releaseVelocity(state) {
|
|
|
64018
64534
|
* @param motion - Its motion.
|
|
64019
64535
|
* @param owned - Whether the samples are this press's.
|
|
64020
64536
|
*/
|
|
64021
|
-
function letGo(state, container, motion, owned) {
|
|
64537
|
+
function letGo$1(state, container, motion, owned) {
|
|
64022
64538
|
const velocity = owned ? releaseVelocity(state) : 0;
|
|
64023
64539
|
const snap = snapOf(container);
|
|
64024
64540
|
if (snap !== void 0) {
|
|
@@ -64165,7 +64681,7 @@ function stepOne(ctx, state, container, lookup, pointer, time) {
|
|
|
64165
64681
|
const content = contentOf(container, lookup);
|
|
64166
64682
|
if (content === void 0 || !ecs.has(container.entity, Scroll)) return false;
|
|
64167
64683
|
if (pressed) hold(state, container, motion, pointer);
|
|
64168
|
-
else if (motion.mode === "held") letGo(state, container, motion, released);
|
|
64684
|
+
else if (motion.mode === "held") letGo$1(state, container, motion, released);
|
|
64169
64685
|
if (motion.mode === "fling") fling(motion, time);
|
|
64170
64686
|
else if (motion.mode === "glide") glide(motion, time);
|
|
64171
64687
|
show(ctx, state, container, content, motion);
|
|
@@ -64419,7 +64935,8 @@ function frameOf(state, rect, node) {
|
|
|
64419
64935
|
};
|
|
64420
64936
|
}
|
|
64421
64937
|
/**
|
|
64422
|
-
* Walks the element tree and writes the rect of every element in root coordinates.
|
|
64938
|
+
* Walks the element tree and writes the rect of every element in root coordinates. An `<anchor>`
|
|
64939
|
+
* and everything under it are left to the anchor pass, which places them by their targets.
|
|
64423
64940
|
*
|
|
64424
64941
|
* @param state - The layout state, for the node of each element.
|
|
64425
64942
|
* @param element - The element to place.
|
|
@@ -64429,7 +64946,7 @@ function frameOf(state, rect, node) {
|
|
|
64429
64946
|
*/
|
|
64430
64947
|
function place(state, element, frame, lookup) {
|
|
64431
64948
|
const node = state.byEntity.get(element.entity);
|
|
64432
|
-
if (node === void 0) return false;
|
|
64949
|
+
if (node === void 0 || element.type === "anchor") return false;
|
|
64433
64950
|
const width = node.getComputedWidth();
|
|
64434
64951
|
const height = node.getComputedHeight();
|
|
64435
64952
|
const fitted = element.style.fit === "contain" ? fitInto(frame.content, width, height) : void 0;
|
|
@@ -64662,6 +65179,792 @@ function createLayoutApi(ctx) {
|
|
|
64662
65179
|
};
|
|
64663
65180
|
}
|
|
64664
65181
|
//#endregion
|
|
65182
|
+
//#region src/plugins/ui/anchor.ts
|
|
65183
|
+
/**
|
|
65184
|
+
* @file ui plugin — the anchor pass, the system `ui.anchor` of phase `layout`, right after `ui.solve`.
|
|
65185
|
+
* Every `<anchor>` takes the drawn rect of its targets (`drawn.ts`), padded and mapped into the space
|
|
65186
|
+
* of its parent, in the frame its targets were laid out. Its subtree is a Yoga tree of its own, laid
|
|
65187
|
+
* out only when the anchor's size changed or a node of it is dirty (a child restyled, measured
|
|
65188
|
+
* again, added or taken out); a pure move shifts the rects in place. A change of the targets applies the subtree as the solve applies any element, so the
|
|
65189
|
+
* anchor's `change.Box` motion plays; following a target never starts a motion. A frame of a still
|
|
65190
|
+
* anchor, and of one that follows a moving target, allocates nothing.
|
|
65191
|
+
*/
|
|
65192
|
+
/** How deep a parent chain is followed; deeper is treated as a loop. */
|
|
65193
|
+
const MAX_DEPTH = 32;
|
|
65194
|
+
/** How far a rect may move off a pure shift and still count as one: rounding, not a relayout. */
|
|
65195
|
+
const SHIFT_EPSILON = 1e-6;
|
|
65196
|
+
/** The patch that only marks a component changed: its fields were written in place. */
|
|
65197
|
+
const NO_PATCH = Object.freeze({});
|
|
65198
|
+
/** The fields of the anchor's `Transform` a follow writes, held from a loop while it follows. */
|
|
65199
|
+
const FOLLOWED_FIELDS = Object.freeze(["x", "y"]);
|
|
65200
|
+
/** The style fields an anchor takes from its targets: a style that sets one is ignored there. */
|
|
65201
|
+
const PLACED_FIELDS = [
|
|
65202
|
+
"width",
|
|
65203
|
+
"height",
|
|
65204
|
+
"position",
|
|
65205
|
+
"left",
|
|
65206
|
+
"top",
|
|
65207
|
+
"right",
|
|
65208
|
+
"bottom"
|
|
65209
|
+
];
|
|
65210
|
+
/**
|
|
65211
|
+
* Tells whether a value is a target: an object with a string `projection` and a string `key`.
|
|
65212
|
+
*
|
|
65213
|
+
* @param value - One entry of `to`.
|
|
65214
|
+
* @returns True for a target.
|
|
65215
|
+
* @example
|
|
65216
|
+
* ```ts
|
|
65217
|
+
* isTarget({ projection: "hud", key: "coins" }); // true
|
|
65218
|
+
* ```
|
|
65219
|
+
*/
|
|
65220
|
+
function isTarget(value) {
|
|
65221
|
+
if (typeof value !== "object" || value === null) return false;
|
|
65222
|
+
const target = value;
|
|
65223
|
+
return typeof target.projection === "string" && typeof target.key === "string";
|
|
65224
|
+
}
|
|
65225
|
+
/**
|
|
65226
|
+
* The targets a `to` prop names, when it names one or a list of them.
|
|
65227
|
+
*
|
|
65228
|
+
* @param to - What the render wrote.
|
|
65229
|
+
* @returns The target or the list, or `undefined` for anything else: the anchor is not shown.
|
|
65230
|
+
* @example
|
|
65231
|
+
* ```ts
|
|
65232
|
+
* targetsOf("seat0"); // undefined
|
|
65233
|
+
* ```
|
|
65234
|
+
*/
|
|
65235
|
+
function targetsOf(to) {
|
|
65236
|
+
if (isTarget(to)) return to;
|
|
65237
|
+
return Array.isArray(to) && to.every((entry) => isTarget(entry)) ? to : void 0;
|
|
65238
|
+
}
|
|
65239
|
+
/**
|
|
65240
|
+
* Tells whether two rects are the same in every field.
|
|
65241
|
+
*
|
|
65242
|
+
* @param first - One rect.
|
|
65243
|
+
* @param second - The other.
|
|
65244
|
+
* @returns True when nothing differs.
|
|
65245
|
+
* @example
|
|
65246
|
+
* ```ts
|
|
65247
|
+
* sameRect({ x: 0, y: 0, w: 4, h: 4 }, { x: 0, y: 0, w: 4, h: 4 }); // true
|
|
65248
|
+
* ```
|
|
65249
|
+
*/
|
|
65250
|
+
function sameRect(first, second) {
|
|
65251
|
+
return first.x === second.x && first.y === second.y && first.w === second.w && first.h === second.h;
|
|
65252
|
+
}
|
|
65253
|
+
/**
|
|
65254
|
+
* Tells whether the targets of an anchor are others than the last time it was shown: a new `to`,
|
|
65255
|
+
* or keys that resolve to other entities. The entities of this frame become the shown ones.
|
|
65256
|
+
*
|
|
65257
|
+
* @param anchor - Its record.
|
|
65258
|
+
* @returns True when the set changed.
|
|
65259
|
+
*/
|
|
65260
|
+
function retargeted(anchor) {
|
|
65261
|
+
let changed = anchor.retarget || anchor.count !== anchor.shownCount;
|
|
65262
|
+
for (let index = 0; index < anchor.count; index += 1) {
|
|
65263
|
+
const entity = anchor.seen[index] ?? 0;
|
|
65264
|
+
if (anchor.shown[index] !== entity) changed = true;
|
|
65265
|
+
if (index < anchor.shown.length) anchor.shown[index] = entity;
|
|
65266
|
+
else anchor.shown.push(entity);
|
|
65267
|
+
}
|
|
65268
|
+
anchor.shownCount = anchor.count;
|
|
65269
|
+
anchor.retarget = false;
|
|
65270
|
+
return changed;
|
|
65271
|
+
}
|
|
65272
|
+
/**
|
|
65273
|
+
* Notes where the motion that starts now lands: the anchor's rest pose. A follow while it plays
|
|
65274
|
+
* carries it by how far the rest moved since.
|
|
65275
|
+
*
|
|
65276
|
+
* @param element - The anchor, its rest pose recorded.
|
|
65277
|
+
* @param anchor - Its record.
|
|
65278
|
+
*/
|
|
65279
|
+
function aim(element, anchor) {
|
|
65280
|
+
anchor.aim.x = element.rest.x;
|
|
65281
|
+
anchor.aim.y = element.rest.y;
|
|
65282
|
+
anchor.wrote.x = NaN;
|
|
65283
|
+
anchor.wrote.y = NaN;
|
|
65284
|
+
}
|
|
65285
|
+
/**
|
|
65286
|
+
* Gives the position of an anchor back to its tracks, when a follow held it from a loop.
|
|
65287
|
+
*
|
|
65288
|
+
* @param anchor - Its record.
|
|
65289
|
+
*/
|
|
65290
|
+
function letGo(anchor) {
|
|
65291
|
+
anchor.held?.();
|
|
65292
|
+
anchor.held = void 0;
|
|
65293
|
+
}
|
|
65294
|
+
/**
|
|
65295
|
+
* Creates the set of rects the anchor pass made. Its own function, because lint rule L5 refuses a
|
|
65296
|
+
* collection built inside an exported declaration.
|
|
65297
|
+
*
|
|
65298
|
+
* @returns An empty set.
|
|
65299
|
+
*/
|
|
65300
|
+
function rectSet() {
|
|
65301
|
+
return /* @__PURE__ */ new WeakSet();
|
|
65302
|
+
}
|
|
65303
|
+
/**
|
|
65304
|
+
* Tells whether an element moved by more than the shift of its anchor: it was laid out anew, not
|
|
65305
|
+
* only carried along.
|
|
65306
|
+
*
|
|
65307
|
+
* @param element - An element under an anchor whose rect was written.
|
|
65308
|
+
* @param shift - How far the anchor moved.
|
|
65309
|
+
* @returns True when its size or its place inside the anchor changed.
|
|
65310
|
+
*/
|
|
65311
|
+
function relaidOut(element, shift) {
|
|
65312
|
+
const { rect, previous } = element;
|
|
65313
|
+
return rect.w !== previous.w || rect.h !== previous.h || Math.abs(rect.x - previous.x - shift.x) > SHIFT_EPSILON || Math.abs(rect.y - previous.y - shift.y) > SHIFT_EPSILON;
|
|
65314
|
+
}
|
|
65315
|
+
/**
|
|
65316
|
+
* Tells whether a motion that can end still plays on an element, or one that never ends.
|
|
65317
|
+
*
|
|
65318
|
+
* @param element - The element.
|
|
65319
|
+
* @returns `"finite"` while a motion that ends plays, `"endless"` while the element runs a loop or
|
|
65320
|
+
* only a track that repeats forever plays, `"none"` otherwise.
|
|
65321
|
+
*/
|
|
65322
|
+
function motionOn(element) {
|
|
65323
|
+
if (!still(element)) return "finite";
|
|
65324
|
+
if (element.loop !== void 0) return "endless";
|
|
65325
|
+
for (const handle of element.handles) if (handle.active()) return "endless";
|
|
65326
|
+
return "none";
|
|
65327
|
+
}
|
|
65328
|
+
/**
|
|
65329
|
+
* Builds the anchor pass. Its records live in the jsx state, made when an anchor enters and
|
|
65330
|
+
* dropped when it despawns.
|
|
65331
|
+
*
|
|
65332
|
+
* @param ctx - Domain context of the ui plugin.
|
|
65333
|
+
* @param jsx - The jsx module, which applies a rect the way the solve does.
|
|
65334
|
+
* @returns The step the system `ui.anchor` runs once a frame.
|
|
65335
|
+
*/
|
|
65336
|
+
function createAnchorPass(ctx, jsx) {
|
|
65337
|
+
const state = ctx.state.jsx;
|
|
65338
|
+
const layout = ctx.state.layout;
|
|
65339
|
+
const ecs = ctx.deps.world.ecs;
|
|
65340
|
+
const projection = ctx.deps.world.projection;
|
|
65341
|
+
const reader = readerOf(ctx);
|
|
65342
|
+
const lookup = (entity) => state.elements.get(entity);
|
|
65343
|
+
const found = {
|
|
65344
|
+
shown: false,
|
|
65345
|
+
missing: false,
|
|
65346
|
+
own: void 0
|
|
65347
|
+
};
|
|
65348
|
+
const owned = rectSet();
|
|
65349
|
+
const slot = ownRect(0, 0, 0, 0);
|
|
65350
|
+
const shift = {
|
|
65351
|
+
x: 0,
|
|
65352
|
+
y: 0
|
|
65353
|
+
};
|
|
65354
|
+
/**
|
|
65355
|
+
* Moves an element to a rect: its `previous` takes the rect it had, by value, and its rect the new
|
|
65356
|
+
* numbers, both in place. The first time, the element gets two rects of the pass's own shape, so
|
|
65357
|
+
* every later frame writes doubles with no allocation. A rect that changes marks the element moved.
|
|
65358
|
+
*
|
|
65359
|
+
* @param element - The element.
|
|
65360
|
+
* @param to - The new rect, in root coordinates.
|
|
65361
|
+
*/
|
|
65362
|
+
function writeRect(element, to) {
|
|
65363
|
+
if (!owned.has(element.rect)) {
|
|
65364
|
+
const { rect, previous } = element;
|
|
65365
|
+
element.rect = ownRect(rect.x, rect.y, rect.w, rect.h);
|
|
65366
|
+
element.previous = ownRect(previous.x, previous.y, previous.w, previous.h);
|
|
65367
|
+
owned.add(element.rect);
|
|
65368
|
+
}
|
|
65369
|
+
const { rect, previous } = element;
|
|
65370
|
+
if (sameRect(rect, to)) return;
|
|
65371
|
+
previous.x = rect.x;
|
|
65372
|
+
previous.y = rect.y;
|
|
65373
|
+
previous.w = rect.w;
|
|
65374
|
+
previous.h = rect.h;
|
|
65375
|
+
rect.x = to.x;
|
|
65376
|
+
rect.y = to.y;
|
|
65377
|
+
rect.w = to.w;
|
|
65378
|
+
rect.h = to.h;
|
|
65379
|
+
element.moved = true;
|
|
65380
|
+
}
|
|
65381
|
+
/**
|
|
65382
|
+
* Tells whether an element or one above it is leaving: it no longer follows anything.
|
|
65383
|
+
*
|
|
65384
|
+
* @param element - The anchor.
|
|
65385
|
+
* @returns True while it or an ancestor plays its exit.
|
|
65386
|
+
*/
|
|
65387
|
+
function leaving(element) {
|
|
65388
|
+
let current = element;
|
|
65389
|
+
while (current !== void 0) {
|
|
65390
|
+
if (state.exiting.has(current.entity)) return true;
|
|
65391
|
+
current = current.parent === void 0 ? void 0 : lookup(current.parent);
|
|
65392
|
+
}
|
|
65393
|
+
return false;
|
|
65394
|
+
}
|
|
65395
|
+
/**
|
|
65396
|
+
* Reads the props of a new render of an anchor: another `to` retargets it, and a dev build names
|
|
65397
|
+
* a style that sets what the targets decide, once.
|
|
65398
|
+
*
|
|
65399
|
+
* @param element - The anchor.
|
|
65400
|
+
* @param anchor - Its record.
|
|
65401
|
+
*/
|
|
65402
|
+
function readNode(element, anchor) {
|
|
65403
|
+
if (element.node === anchor.node) return;
|
|
65404
|
+
const to = targetsOf(element.node.props.to);
|
|
65405
|
+
if (anchor.node !== void 0 && !sameValue(anchor.to, to)) anchor.retarget = true;
|
|
65406
|
+
anchor.node = element.node;
|
|
65407
|
+
anchor.to = to;
|
|
65408
|
+
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__) warnStyle(element, anchor);
|
|
65409
|
+
}
|
|
65410
|
+
/**
|
|
65411
|
+
* Names, once, an anchor whose style sets what its targets decide. Its own function: a closure
|
|
65412
|
+
* over `element` in `readNode` would make every call of it, every frame, allocate its context.
|
|
65413
|
+
*
|
|
65414
|
+
* @param element - The anchor.
|
|
65415
|
+
* @param anchor - Its record.
|
|
65416
|
+
*/
|
|
65417
|
+
function warnStyle(element, anchor) {
|
|
65418
|
+
if (anchor.warned.style || !PLACED_FIELDS.some((field) => element.style[field] !== void 0)) return;
|
|
65419
|
+
anchor.warned.style = true;
|
|
65420
|
+
ctx.log.warn("ui:anchor-style", { key: element.key ?? element.identity });
|
|
65421
|
+
}
|
|
65422
|
+
/**
|
|
65423
|
+
* Tells whether an entity is the anchor or drawn under it.
|
|
65424
|
+
*
|
|
65425
|
+
* @param entity - A target's entity.
|
|
65426
|
+
* @param anchor - The anchor's entity.
|
|
65427
|
+
* @returns True for the anchor and everything in its subtree.
|
|
65428
|
+
*/
|
|
65429
|
+
function within(entity, anchor) {
|
|
65430
|
+
let current = entity;
|
|
65431
|
+
for (let depth = 0; depth < MAX_DEPTH && current !== 0; depth += 1) {
|
|
65432
|
+
if (current === anchor) return true;
|
|
65433
|
+
current = upOf(reader, current);
|
|
65434
|
+
}
|
|
65435
|
+
return false;
|
|
65436
|
+
}
|
|
65437
|
+
/**
|
|
65438
|
+
* Resolves one target: notes the entity its key names, and adds its drawn rect to the union when
|
|
65439
|
+
* it is shown. A key that names no entity, and a target under the anchor itself, add nothing.
|
|
65440
|
+
*
|
|
65441
|
+
* @param element - The anchor.
|
|
65442
|
+
* @param anchor - Its record.
|
|
65443
|
+
* @param target - One entry of `to`.
|
|
65444
|
+
*/
|
|
65445
|
+
function visit(element, anchor, target) {
|
|
65446
|
+
const entity = projection.entityOf(target.projection, target.key);
|
|
65447
|
+
const at = anchor.count;
|
|
65448
|
+
if (at < anchor.seen.length) anchor.seen[at] = entity ?? 0;
|
|
65449
|
+
else anchor.seen.push(entity ?? 0);
|
|
65450
|
+
anchor.count += 1;
|
|
65451
|
+
if (entity === void 0) {
|
|
65452
|
+
found.missing = true;
|
|
65453
|
+
return;
|
|
65454
|
+
}
|
|
65455
|
+
if (within(entity, element.entity)) {
|
|
65456
|
+
found.own = target;
|
|
65457
|
+
return;
|
|
65458
|
+
}
|
|
65459
|
+
if (!drawnInto(reader, entity, anchor.part, anchor.pose)) return;
|
|
65460
|
+
if (found.shown) unionInto(anchor.screen, anchor.part);
|
|
65461
|
+
else {
|
|
65462
|
+
anchor.screen.x = anchor.part.x;
|
|
65463
|
+
anchor.screen.y = anchor.part.y;
|
|
65464
|
+
anchor.screen.w = anchor.part.w;
|
|
65465
|
+
anchor.screen.h = anchor.part.h;
|
|
65466
|
+
found.shown = true;
|
|
65467
|
+
}
|
|
65468
|
+
}
|
|
65469
|
+
/**
|
|
65470
|
+
* Resolves the targets of an anchor into the union of the shown ones, in screen reference units,
|
|
65471
|
+
* and logs what a dev build or the author must know: a key that named no entity for two frames in
|
|
65472
|
+
* a row, a target under the anchor itself.
|
|
65473
|
+
*
|
|
65474
|
+
* @param element - The anchor.
|
|
65475
|
+
* @param anchor - Its record.
|
|
65476
|
+
* @returns True when at least one target is shown.
|
|
65477
|
+
*/
|
|
65478
|
+
function resolve(element, anchor) {
|
|
65479
|
+
const to = anchor.to;
|
|
65480
|
+
found.shown = false;
|
|
65481
|
+
found.missing = false;
|
|
65482
|
+
found.own = void 0;
|
|
65483
|
+
anchor.count = 0;
|
|
65484
|
+
if (isTargetList(to)) for (const target of to) visit(element, anchor, target);
|
|
65485
|
+
else if (to !== void 0) visit(element, anchor, to);
|
|
65486
|
+
anchor.missing = found.missing ? anchor.missing + 1 : 0;
|
|
65487
|
+
if (anchor.missing >= 2) warnMissing(element, anchor);
|
|
65488
|
+
if (found.own !== void 0) refuseOwn(element, anchor, found.own);
|
|
65489
|
+
return found.shown;
|
|
65490
|
+
}
|
|
65491
|
+
/**
|
|
65492
|
+
* Names, in a dev build, an anchor a key of which named no entity two frames in a row, once.
|
|
65493
|
+
*
|
|
65494
|
+
* @param element - The anchor.
|
|
65495
|
+
* @param anchor - Its record.
|
|
65496
|
+
*/
|
|
65497
|
+
function warnMissing(element, anchor) {
|
|
65498
|
+
if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__ || anchor.warned.missing) return;
|
|
65499
|
+
anchor.warned.missing = true;
|
|
65500
|
+
ctx.log.warn("ui:anchor-target-missing", {
|
|
65501
|
+
key: element.key ?? element.identity,
|
|
65502
|
+
to: anchor.to
|
|
65503
|
+
});
|
|
65504
|
+
}
|
|
65505
|
+
/**
|
|
65506
|
+
* Logs, once per anchor, a target that lies inside the anchor itself: it is treated as not shown.
|
|
65507
|
+
*
|
|
65508
|
+
* @param element - The anchor.
|
|
65509
|
+
* @param anchor - Its record.
|
|
65510
|
+
* @param target - The target under the anchor.
|
|
65511
|
+
*/
|
|
65512
|
+
function refuseOwn(element, anchor, target) {
|
|
65513
|
+
if (anchor.warned.own) return;
|
|
65514
|
+
anchor.warned.own = true;
|
|
65515
|
+
ctx.log.error("ui:anchor-own-child", {
|
|
65516
|
+
key: element.key ?? element.identity,
|
|
65517
|
+
target: target.key
|
|
65518
|
+
}, /* @__PURE__ */ new Error(`[game] An anchor cannot point at its own child "${target.key}".\n Point it at an element outside the anchor.`));
|
|
65519
|
+
}
|
|
65520
|
+
/**
|
|
65521
|
+
* Maps the union of the targets into the root coordinates of the anchor: through the root pose of
|
|
65522
|
+
* the entity it is drawn under (its parent, or the slot of its root), then by its parent's rect,
|
|
65523
|
+
* then padded outward.
|
|
65524
|
+
*
|
|
65525
|
+
* @param element - The anchor.
|
|
65526
|
+
* @param anchor - Its record: `screen` is read, `next` written.
|
|
65527
|
+
* @returns False when the space it is drawn in is collapsed: nothing of it could be seen.
|
|
65528
|
+
*/
|
|
65529
|
+
function mapInto(element, anchor) {
|
|
65530
|
+
const above = element.parent ?? state.roots.get(element.root)?.slot ?? 0;
|
|
65531
|
+
const pose = anchor.pose;
|
|
65532
|
+
if (above === 0 || !drawnPoseInto(reader, above, pose)) {
|
|
65533
|
+
pose.x = 0;
|
|
65534
|
+
pose.y = 0;
|
|
65535
|
+
pose.scale = 1;
|
|
65536
|
+
pose.pivot.x = 0;
|
|
65537
|
+
pose.pivot.y = 0;
|
|
65538
|
+
}
|
|
65539
|
+
const scale = pose.scale;
|
|
65540
|
+
if (scale <= 0) return false;
|
|
65541
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65542
|
+
const given = element.node.props.pad;
|
|
65543
|
+
const pad = typeof given === "number" && Number.isFinite(given) ? given : 0;
|
|
65544
|
+
const { screen, next } = anchor;
|
|
65545
|
+
next.x = pose.pivot.x + (screen.x - pose.x) / scale + (parent?.rect.x ?? 0) - pad;
|
|
65546
|
+
next.y = pose.pivot.y + (screen.y - pose.y) / scale + (parent?.rect.y ?? 0) - pad;
|
|
65547
|
+
next.w = screen.w / scale + 2 * pad;
|
|
65548
|
+
next.h = screen.h / scale + 2 * pad;
|
|
65549
|
+
return next.w > 0 && next.h > 0;
|
|
65550
|
+
}
|
|
65551
|
+
/**
|
|
65552
|
+
* Writes the alpha of the anchor's visual, which fades its subtree with it: 0 hides the anchor the
|
|
65553
|
+
* way a transparent element is hidden, out of the draw and the hit test. Only a value that
|
|
65554
|
+
* differs is written.
|
|
65555
|
+
*
|
|
65556
|
+
* @param element - The anchor.
|
|
65557
|
+
* @param alpha - The alpha to draw it at.
|
|
65558
|
+
*/
|
|
65559
|
+
function fadeTo(element, alpha) {
|
|
65560
|
+
const shape = ecs.get(element.entity, Shape);
|
|
65561
|
+
if (shape !== void 0) {
|
|
65562
|
+
if (shape.alpha === alpha) return;
|
|
65563
|
+
shape.alpha = alpha;
|
|
65564
|
+
ecs.set(element.entity, Shape, NO_PATCH);
|
|
65565
|
+
return;
|
|
65566
|
+
}
|
|
65567
|
+
const panel = ecs.get(element.entity, NineSlice);
|
|
65568
|
+
if (panel === void 0 || panel.alpha === alpha) return;
|
|
65569
|
+
panel.alpha = alpha;
|
|
65570
|
+
ecs.set(element.entity, NineSlice, NO_PATCH);
|
|
65571
|
+
}
|
|
65572
|
+
/**
|
|
65573
|
+
* Hides an anchor none of whose targets is shown. A placed one stays, drawn at alpha 0; one never
|
|
65574
|
+
* placed waits with no components.
|
|
65575
|
+
*
|
|
65576
|
+
* @param element - The anchor.
|
|
65577
|
+
* @param anchor - Its record.
|
|
65578
|
+
*/
|
|
65579
|
+
function hide(element, anchor) {
|
|
65580
|
+
anchor.hidden = true;
|
|
65581
|
+
if (anchor.placed) fadeTo(element, 0);
|
|
65582
|
+
}
|
|
65583
|
+
/**
|
|
65584
|
+
* Shows an anchor again at the alpha of its style.
|
|
65585
|
+
*
|
|
65586
|
+
* @param element - The anchor.
|
|
65587
|
+
* @param anchor - Its record.
|
|
65588
|
+
*/
|
|
65589
|
+
function show(element, anchor) {
|
|
65590
|
+
if (!anchor.hidden) return;
|
|
65591
|
+
anchor.hidden = false;
|
|
65592
|
+
fadeTo(element, element.style.alpha ?? 1);
|
|
65593
|
+
}
|
|
65594
|
+
/**
|
|
65595
|
+
* Writes an element's `Box` from its rect, field by field on the stored value. Nothing is written
|
|
65596
|
+
* while it holds the same numbers, or before the `Box` landed.
|
|
65597
|
+
*
|
|
65598
|
+
* @param element - The element.
|
|
65599
|
+
*/
|
|
65600
|
+
function writeBox(element) {
|
|
65601
|
+
const box = ecs.get(element.entity, Box);
|
|
65602
|
+
if (box === void 0 || sameRect(box, element.rect)) return;
|
|
65603
|
+
box.x = element.rect.x;
|
|
65604
|
+
box.y = element.rect.y;
|
|
65605
|
+
box.w = element.rect.w;
|
|
65606
|
+
box.h = element.rect.h;
|
|
65607
|
+
ecs.set(element.entity, Box, NO_PATCH);
|
|
65608
|
+
}
|
|
65609
|
+
/**
|
|
65610
|
+
* Lays the subtree of an anchor out in its rect: one Yoga calculation of the anchor's own tree at
|
|
65611
|
+
* its size, then the rects of everything under it written in place.
|
|
65612
|
+
*
|
|
65613
|
+
* @param element - The anchor, its rect set.
|
|
65614
|
+
*/
|
|
65615
|
+
function layOut(element) {
|
|
65616
|
+
const yoga = layout.yoga;
|
|
65617
|
+
const node = layout.byEntity.get(element.entity);
|
|
65618
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65619
|
+
node.setWidth(element.rect.w);
|
|
65620
|
+
node.setHeight(element.rect.h);
|
|
65621
|
+
node.calculateLayout(element.rect.w, element.rect.h, yoga.DIRECTION_LTR);
|
|
65622
|
+
layout.solves += 1;
|
|
65623
|
+
placeUnder(element);
|
|
65624
|
+
}
|
|
65625
|
+
/**
|
|
65626
|
+
* Writes the rects of the children of a laid-out element in root coordinates, and of everything
|
|
65627
|
+
* under them: the computed offsets from its rect, a fitted child centred in its content box at
|
|
65628
|
+
* the scale that fits it. A nested anchor is left to its own place in the pass.
|
|
65629
|
+
*
|
|
65630
|
+
* @param parent - The element whose rect is written.
|
|
65631
|
+
*/
|
|
65632
|
+
function placeUnder(parent) {
|
|
65633
|
+
const yoga = layout.yoga;
|
|
65634
|
+
const node = layout.byEntity.get(parent.entity);
|
|
65635
|
+
if (yoga === void 0 || node === void 0) return;
|
|
65636
|
+
const left = node.getComputedPadding(yoga.EDGE_LEFT);
|
|
65637
|
+
const top = node.getComputedPadding(yoga.EDGE_TOP);
|
|
65638
|
+
const content = {
|
|
65639
|
+
x: parent.rect.x + left,
|
|
65640
|
+
y: parent.rect.y + top,
|
|
65641
|
+
w: parent.rect.w - left - node.getComputedPadding(yoga.EDGE_RIGHT),
|
|
65642
|
+
h: parent.rect.h - top - node.getComputedPadding(yoga.EDGE_BOTTOM)
|
|
65643
|
+
};
|
|
65644
|
+
for (const child of parent.children) {
|
|
65645
|
+
const element = lookup(child);
|
|
65646
|
+
const childNode = element === void 0 ? void 0 : layout.byEntity.get(element.entity);
|
|
65647
|
+
if (element === void 0 || childNode === void 0 || element.type === "anchor") continue;
|
|
65648
|
+
const w = childNode.getComputedWidth();
|
|
65649
|
+
const h = childNode.getComputedHeight();
|
|
65650
|
+
const fitted = element.style.fit === "contain" ? fitInto(content, w, h) : void 0;
|
|
65651
|
+
slot.x = fitted?.rect.x ?? parent.rect.x + childNode.getComputedLeft();
|
|
65652
|
+
slot.y = fitted?.rect.y ?? parent.rect.y + childNode.getComputedTop();
|
|
65653
|
+
slot.w = w;
|
|
65654
|
+
slot.h = h;
|
|
65655
|
+
writeRect(element, slot);
|
|
65656
|
+
if ((fitted?.fit ?? 1) !== element.fit) {
|
|
65657
|
+
element.fit = fitted?.fit ?? 1;
|
|
65658
|
+
element.moved = true;
|
|
65659
|
+
}
|
|
65660
|
+
placeUnder(element);
|
|
65661
|
+
}
|
|
65662
|
+
}
|
|
65663
|
+
/**
|
|
65664
|
+
* Carries everything under an element along by a shift, rects in place. A nested anchor is left
|
|
65665
|
+
* to its own place in the pass.
|
|
65666
|
+
*
|
|
65667
|
+
* @param parent - The element whose children move, by `shift`.
|
|
65668
|
+
* @param mark - Whether they stay marked moved, for an application that follows.
|
|
65669
|
+
*/
|
|
65670
|
+
function shiftUnder(parent, mark) {
|
|
65671
|
+
for (const child of parent.children) {
|
|
65672
|
+
const element = lookup(child);
|
|
65673
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65674
|
+
const { rect } = element;
|
|
65675
|
+
slot.x = rect.x + shift.x;
|
|
65676
|
+
slot.y = rect.y + shift.y;
|
|
65677
|
+
slot.w = rect.w;
|
|
65678
|
+
slot.h = rect.h;
|
|
65679
|
+
writeRect(element, slot);
|
|
65680
|
+
if (!mark) element.moved = false;
|
|
65681
|
+
shiftUnder(element, mark);
|
|
65682
|
+
}
|
|
65683
|
+
}
|
|
65684
|
+
/**
|
|
65685
|
+
* Writes the `Box` of an element and of everything under it from their rects. A nested anchor is
|
|
65686
|
+
* left to its own place in the pass.
|
|
65687
|
+
*
|
|
65688
|
+
* @param element - The anchor or an element under it.
|
|
65689
|
+
*/
|
|
65690
|
+
function writeBoxes(element) {
|
|
65691
|
+
writeBox(element);
|
|
65692
|
+
for (const child of element.children) {
|
|
65693
|
+
const childElement = lookup(child);
|
|
65694
|
+
if (childElement !== void 0 && childElement.type !== "anchor") writeBoxes(childElement);
|
|
65695
|
+
}
|
|
65696
|
+
}
|
|
65697
|
+
/**
|
|
65698
|
+
* Applies an element and everything under it the way the solve applies a root: a new element
|
|
65699
|
+
* spawns its components, a moved live one is committed and plays its `change` hooks. A nested
|
|
65700
|
+
* anchor is left to its own place in the pass.
|
|
65701
|
+
*
|
|
65702
|
+
* @param element - The anchor or an element under it.
|
|
65703
|
+
*/
|
|
65704
|
+
function applyTree(element) {
|
|
65705
|
+
jsx.applyAnchored(element, false);
|
|
65706
|
+
for (const child of element.children) {
|
|
65707
|
+
const childElement = lookup(child);
|
|
65708
|
+
if (childElement !== void 0 && childElement.type !== "anchor") applyTree(childElement);
|
|
65709
|
+
}
|
|
65710
|
+
}
|
|
65711
|
+
/**
|
|
65712
|
+
* Applies what a relayout of an anchor's subtree moved. A child carried along only writes its
|
|
65713
|
+
* `Box`; one laid out anew is applied as the solve applies it, with its `change` hooks, unless
|
|
65714
|
+
* the anchor's size followed its targets: then it takes its rect and its rest pose with no motion.
|
|
65715
|
+
*
|
|
65716
|
+
* @param parent - The element whose children were laid out, its anchor moved by `shift`.
|
|
65717
|
+
* @param followed - Whether the anchor's size changed by following its targets.
|
|
65718
|
+
*/
|
|
65719
|
+
function applyUnder(parent, followed) {
|
|
65720
|
+
for (const child of parent.children) {
|
|
65721
|
+
const element = lookup(child);
|
|
65722
|
+
if (element === void 0 || element.type === "anchor") continue;
|
|
65723
|
+
if (!element.live) jsx.applyAnchored(element, false);
|
|
65724
|
+
else if (element.moved && !relaidOut(element, shift)) {
|
|
65725
|
+
writeBox(element);
|
|
65726
|
+
element.moved = false;
|
|
65727
|
+
} else if (element.moved && followed) {
|
|
65728
|
+
jsx.applyAnchored(element, true);
|
|
65729
|
+
settlePose(element);
|
|
65730
|
+
} else if (element.moved) jsx.applyAnchored(element, false);
|
|
65731
|
+
applyUnder(element, followed);
|
|
65732
|
+
}
|
|
65733
|
+
}
|
|
65734
|
+
/**
|
|
65735
|
+
* Brings an element under an anchor to the rest pose a follow gave it, with no motion: a `Transform`
|
|
65736
|
+
* a motion is on is taken through a 0 ms rest track, which cuts a finite motion and re-bases a
|
|
65737
|
+
* loop, as a repose does; one nothing moves is written at once.
|
|
65738
|
+
*
|
|
65739
|
+
* @param element - The element, its rest pose recorded.
|
|
65740
|
+
*/
|
|
65741
|
+
function settlePose(element) {
|
|
65742
|
+
if (!element.live || element.type === "content" || !ecs.has(element.entity, Transform)) return;
|
|
65743
|
+
if (motionOn(element) === "none") ecs.set(element.entity, Transform, {
|
|
65744
|
+
...element.rest,
|
|
65745
|
+
pivot: { ...element.rest.pivot }
|
|
65746
|
+
});
|
|
65747
|
+
else handleOf(ctx, element)?.toRest(Transform, { ms: 0 });
|
|
65748
|
+
}
|
|
65749
|
+
/**
|
|
65750
|
+
* Carries a motion that ends by how far the targets moved since it began: the position the motion
|
|
65751
|
+
* wrote this frame, moved by the rest's shift from where the motion lands. The motion writes its
|
|
65752
|
+
* own value again in the next frame, and the carry is added once more, so it lands on the moved
|
|
65753
|
+
* rest instead of jumping there at its end.
|
|
65754
|
+
*
|
|
65755
|
+
* @param element - The anchor.
|
|
65756
|
+
* @param anchor - Its record.
|
|
65757
|
+
* @param pose - Its stored `Transform`.
|
|
65758
|
+
*/
|
|
65759
|
+
function carry(element, anchor, pose) {
|
|
65760
|
+
const { aim: aimed, track, wrote } = anchor;
|
|
65761
|
+
const rest = element.rest;
|
|
65762
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) ecs.set(element.entity, Transform, { pivot: {
|
|
65763
|
+
x: rest.pivot.x,
|
|
65764
|
+
y: rest.pivot.y
|
|
65765
|
+
} });
|
|
65766
|
+
if (pose.x !== wrote.x) track.x = pose.x;
|
|
65767
|
+
if (pose.y !== wrote.y) track.y = pose.y;
|
|
65768
|
+
const x = track.x + rest.x - aimed.x;
|
|
65769
|
+
const y = track.y + rest.y - aimed.y;
|
|
65770
|
+
if (x === pose.x && y === pose.y) return;
|
|
65771
|
+
pose.x = x;
|
|
65772
|
+
pose.y = y;
|
|
65773
|
+
wrote.x = x;
|
|
65774
|
+
wrote.y = y;
|
|
65775
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65776
|
+
}
|
|
65777
|
+
/**
|
|
65778
|
+
* Writes the anchor's `Transform` from its rest pose. While a motion that ends plays (the glide of
|
|
65779
|
+
* a change of targets, a look tween), the motion is carried by the follow and lands on the rest;
|
|
65780
|
+
* the pose is owed to the rest until it ends. Under a loop the follow holds `x` and `y` from every
|
|
65781
|
+
* track while it moves (`world.projection.mute`), and the loop goes on from where the anchor
|
|
65782
|
+
* stands once it is let go. Each field is written on the stored value.
|
|
65783
|
+
*
|
|
65784
|
+
* @param element - The anchor.
|
|
65785
|
+
* @param anchor - Its record.
|
|
65786
|
+
*/
|
|
65787
|
+
function writePose(element, anchor) {
|
|
65788
|
+
const pose = ecs.get(element.entity, Transform);
|
|
65789
|
+
if (!element.live || pose === void 0) return;
|
|
65790
|
+
const motion = motionOn(element);
|
|
65791
|
+
if (motion === "finite") {
|
|
65792
|
+
anchor.owed = true;
|
|
65793
|
+
carry(element, anchor, pose);
|
|
65794
|
+
return;
|
|
65795
|
+
}
|
|
65796
|
+
anchor.owed = false;
|
|
65797
|
+
if (motion === "endless" && anchor.held === void 0) anchor.held = projection.mute(element.entity, Transform, FOLLOWED_FIELDS);
|
|
65798
|
+
const rest = element.rest;
|
|
65799
|
+
if (samePose(pose, rest)) return;
|
|
65800
|
+
if (pose.pivot.x !== rest.pivot.x || pose.pivot.y !== rest.pivot.y) {
|
|
65801
|
+
ecs.set(element.entity, Transform, {
|
|
65802
|
+
...rest,
|
|
65803
|
+
pivot: { ...rest.pivot }
|
|
65804
|
+
});
|
|
65805
|
+
return;
|
|
65806
|
+
}
|
|
65807
|
+
pose.x = rest.x;
|
|
65808
|
+
pose.y = rest.y;
|
|
65809
|
+
pose.rotation = rest.rotation;
|
|
65810
|
+
pose.scale = rest.scale;
|
|
65811
|
+
ecs.set(element.entity, Transform, NO_PATCH);
|
|
65812
|
+
}
|
|
65813
|
+
/**
|
|
65814
|
+
* Moves the anchor's rest pose to where its rect and its parent's put it now, its size, and so its
|
|
65815
|
+
* pivot, unchanged: the position of `restTransform`, worked out here, since a fractional number
|
|
65816
|
+
* handed to or returned from a call is boxed. The rest is written in place, and the world's copy
|
|
65817
|
+
* of it is left behind until the anchor stands still. Then the `Transform` follows.
|
|
65818
|
+
*
|
|
65819
|
+
* @param element - The anchor.
|
|
65820
|
+
* @param anchor - Its record.
|
|
65821
|
+
* @returns True when the rest pose moved.
|
|
65822
|
+
*/
|
|
65823
|
+
function follow(element, anchor) {
|
|
65824
|
+
const parent = element.parent === void 0 ? void 0 : lookup(element.parent);
|
|
65825
|
+
const { rect, rest, style } = element;
|
|
65826
|
+
const centreX = rect.w / 2;
|
|
65827
|
+
const centreY = rect.h / 2;
|
|
65828
|
+
const x = rect.x - (parent?.rect.x ?? 0) + centreX + (rest.pivot.x + (style.offsetX ?? 0) - centreX);
|
|
65829
|
+
const y = rect.y - (parent?.rect.y ?? 0) + centreY + (rest.pivot.y + (style.offsetY ?? 0) - centreY);
|
|
65830
|
+
if (x === rest.x && y === rest.y) return false;
|
|
65831
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65832
|
+
rest.x = x;
|
|
65833
|
+
rest.y = y;
|
|
65834
|
+
anchor.stale = true;
|
|
65835
|
+
writePose(element, anchor);
|
|
65836
|
+
return true;
|
|
65837
|
+
}
|
|
65838
|
+
/**
|
|
65839
|
+
* Places an anchor for the first time: its rect, its subtree laid out, and everything applied as
|
|
65840
|
+
* a new root is, so its components spawn with their rects and its `enter` hooks play.
|
|
65841
|
+
*
|
|
65842
|
+
* @param element - The anchor.
|
|
65843
|
+
* @param anchor - Its record, `next` holding its rect.
|
|
65844
|
+
*/
|
|
65845
|
+
function place(element, anchor) {
|
|
65846
|
+
const { next } = anchor;
|
|
65847
|
+
element.fit = 1;
|
|
65848
|
+
writeRect(element, next);
|
|
65849
|
+
layOut(element);
|
|
65850
|
+
applyTree(element);
|
|
65851
|
+
aim(element, anchor);
|
|
65852
|
+
anchor.placed = true;
|
|
65853
|
+
}
|
|
65854
|
+
/**
|
|
65855
|
+
* Moves an anchor to its new targets the way a solve moves an element: its `change.Box` motion
|
|
65856
|
+
* plays, and so do the hooks of what moved under it.
|
|
65857
|
+
*
|
|
65858
|
+
* @param element - The anchor.
|
|
65859
|
+
* @param anchor - Its record, `next` holding its new rect.
|
|
65860
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65861
|
+
*/
|
|
65862
|
+
function retarget(element, anchor, relayout) {
|
|
65863
|
+
const next = anchor.next;
|
|
65864
|
+
const rect = element.rect;
|
|
65865
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65866
|
+
shift.x = next.x - rect.x;
|
|
65867
|
+
shift.y = next.y - rect.y;
|
|
65868
|
+
writeRect(element, next);
|
|
65869
|
+
if (resized || relayout) layOut(element);
|
|
65870
|
+
else shiftUnder(element, true);
|
|
65871
|
+
anchor.owed = false;
|
|
65872
|
+
anchor.stale = false;
|
|
65873
|
+
letGo(anchor);
|
|
65874
|
+
applyTree(element);
|
|
65875
|
+
aim(element, anchor);
|
|
65876
|
+
}
|
|
65877
|
+
/**
|
|
65878
|
+
* Keeps an anchor on targets that moved, resized or stood: no motion starts. A pure move writes
|
|
65879
|
+
* every number in place and leaves the `Box` values for the frame the anchor stands (a fractional
|
|
65880
|
+
* number written into a stored `Box` field is boxed); a new size or a dirty node lays the
|
|
65881
|
+
* subtree out again.
|
|
65882
|
+
*
|
|
65883
|
+
* @param element - The anchor.
|
|
65884
|
+
* @param anchor - Its record, `next` holding its rect of this frame.
|
|
65885
|
+
* @param relayout - Whether a node of its subtree is dirty.
|
|
65886
|
+
* @returns True when the anchor's rest pose moved.
|
|
65887
|
+
*/
|
|
65888
|
+
function keep(element, anchor, relayout) {
|
|
65889
|
+
const { next } = anchor;
|
|
65890
|
+
const rect = element.rect;
|
|
65891
|
+
const resized = next.w !== rect.w || next.h !== rect.h;
|
|
65892
|
+
shift.x = next.x - rect.x;
|
|
65893
|
+
shift.y = next.y - rect.y;
|
|
65894
|
+
writeRect(element, next);
|
|
65895
|
+
if (resized) {
|
|
65896
|
+
if (!anchor.owed) aim(element, anchor);
|
|
65897
|
+
layOut(element);
|
|
65898
|
+
jsx.applyAnchored(element, true);
|
|
65899
|
+
anchor.stale = false;
|
|
65900
|
+
writePose(element, anchor);
|
|
65901
|
+
applyUnder(element, true);
|
|
65902
|
+
return true;
|
|
65903
|
+
}
|
|
65904
|
+
if (relayout) {
|
|
65905
|
+
layOut(element);
|
|
65906
|
+
applyUnder(element, false);
|
|
65907
|
+
writeBox(element);
|
|
65908
|
+
} else if (shift.x !== 0 || shift.y !== 0) {
|
|
65909
|
+
shiftUnder(element, false);
|
|
65910
|
+
anchor.boxes = true;
|
|
65911
|
+
}
|
|
65912
|
+
element.moved = false;
|
|
65913
|
+
return follow(element, anchor);
|
|
65914
|
+
}
|
|
65915
|
+
/**
|
|
65916
|
+
* Places one anchor for this frame: its targets resolved, then placed the first time, moved to
|
|
65917
|
+
* new targets, kept on moving ones, or hidden while none is shown. Its owed pose and the world's
|
|
65918
|
+
* copy of its rest catch up once nothing moves it.
|
|
65919
|
+
*
|
|
65920
|
+
* @param entity - The anchor's entity.
|
|
65921
|
+
* @param anchor - Its record.
|
|
65922
|
+
*/
|
|
65923
|
+
function placeAnchor(entity, anchor) {
|
|
65924
|
+
const element = lookup(entity);
|
|
65925
|
+
if (element === void 0) return;
|
|
65926
|
+
if (leaving(element)) {
|
|
65927
|
+
letGo(anchor);
|
|
65928
|
+
return;
|
|
65929
|
+
}
|
|
65930
|
+
if (projection.isBuilding(element.root)) return;
|
|
65931
|
+
readNode(element, anchor);
|
|
65932
|
+
if (!resolve(element, anchor) || !mapInto(element, anchor)) {
|
|
65933
|
+
hide(element, anchor);
|
|
65934
|
+
return;
|
|
65935
|
+
}
|
|
65936
|
+
const relayout = layout.byEntity.get(entity)?.isDirty() === true;
|
|
65937
|
+
if (!anchor.placed) {
|
|
65938
|
+
place(element, anchor);
|
|
65939
|
+
retargeted(anchor);
|
|
65940
|
+
anchor.hidden = false;
|
|
65941
|
+
return;
|
|
65942
|
+
}
|
|
65943
|
+
let moved = false;
|
|
65944
|
+
if (retargeted(anchor)) retarget(element, anchor, relayout);
|
|
65945
|
+
else moved = keep(element, anchor, relayout);
|
|
65946
|
+
show(element, anchor);
|
|
65947
|
+
if (anchor.owed && !moved) writePose(element, anchor);
|
|
65948
|
+
if (moved) return;
|
|
65949
|
+
if (anchor.stale) {
|
|
65950
|
+
ctx.deps.world.projection.setRest(entity, Transform, element.rest);
|
|
65951
|
+
anchor.stale = false;
|
|
65952
|
+
}
|
|
65953
|
+
if (anchor.boxes) {
|
|
65954
|
+
writeBoxes(element);
|
|
65955
|
+
anchor.boxes = false;
|
|
65956
|
+
}
|
|
65957
|
+
letGo(anchor);
|
|
65958
|
+
}
|
|
65959
|
+
return () => {
|
|
65960
|
+
if (state.anchors.size === 0) return;
|
|
65961
|
+
for (const entity of state.anchors.keys()) {
|
|
65962
|
+
const anchor = state.anchors.get(entity);
|
|
65963
|
+
if (anchor !== void 0) placeAnchor(entity, anchor);
|
|
65964
|
+
}
|
|
65965
|
+
};
|
|
65966
|
+
}
|
|
65967
|
+
//#endregion
|
|
64665
65968
|
//#region src/plugins/ui/hot.ts
|
|
64666
65969
|
/** The global the footer of `@moku-labs/game/hot` calls. */
|
|
64667
65970
|
const HOT_GLOBAL = "__moku_hot";
|
|
@@ -65213,7 +66516,7 @@ function drawsViews(ctx) {
|
|
|
65213
66516
|
return ctx.deps.renderer.host.kind() !== "none";
|
|
65214
66517
|
}
|
|
65215
66518
|
/**
|
|
65216
|
-
* Opens the
|
|
66519
|
+
* Opens the three systems of phase `layout`, the system `ui.enter` of phase `sync`, the seven world
|
|
65217
66520
|
* hooks of `Tree`, `Box`, `Pressed` and `PointerOver`, the two that tell the hosting step a view
|
|
65218
66521
|
* lost its `Parent` or its `Held` (a view freed so may hang under its host again), the listener
|
|
65219
66522
|
* that asks for every root to be built again after a restore or a load, the two effect handlers,
|
|
@@ -65224,7 +66527,8 @@ function drawsViews(ctx) {
|
|
|
65224
66527
|
* control, so the cursor shows a hand over a local-state button, and, with a renderer that draws,
|
|
65225
66528
|
* `ui`'s part of a scene build (`onBuild`: the roots built aside are reconciled and solved, spec
|
|
65226
66529
|
* 31). On an agent page also the tap counter of `DebugTrigger` and its check of a view that takes
|
|
65227
|
-
* no press.
|
|
66530
|
+
* no press. The third system of `layout`, `ui.anchor`, runs after the solve and places every
|
|
66531
|
+
* `<anchor>` on its targets.
|
|
65228
66532
|
*
|
|
65229
66533
|
* The `Box` hook plays an element's enter hook and queues it, so the game's systems see its start
|
|
65230
66534
|
* pose (F49); `ui.enter` starts its loop after them and before the frame is drawn, and plays the
|
|
@@ -65238,6 +66542,7 @@ function drawsViews(ctx) {
|
|
|
65238
66542
|
function openRegistrations(ctx, jsx, layout) {
|
|
65239
66543
|
const ecs = ctx.deps.world.ecs;
|
|
65240
66544
|
const projection = ctx.deps.world.projection;
|
|
66545
|
+
const anchors = createAnchorPass(ctx, jsx);
|
|
65241
66546
|
ctx.state.layout.cleanups.push(ecs.system(system({
|
|
65242
66547
|
name: "ui.reconcile",
|
|
65243
66548
|
phase: "layout",
|
|
@@ -65248,6 +66553,11 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
65248
66553
|
phase: "layout",
|
|
65249
66554
|
query: [],
|
|
65250
66555
|
run: (_rows, frame) => jsx.solve(frame.time)
|
|
66556
|
+
})), ecs.system(system({
|
|
66557
|
+
name: "ui.anchor",
|
|
66558
|
+
phase: "layout",
|
|
66559
|
+
query: [],
|
|
66560
|
+
run: anchors
|
|
65251
66561
|
})), ecs.system(system({
|
|
65252
66562
|
name: "ui.enter",
|
|
65253
66563
|
phase: "sync",
|
|
@@ -65315,6 +66625,7 @@ function stopUi(state) {
|
|
|
65315
66625
|
state.jsx.risen.clear();
|
|
65316
66626
|
state.jsx.released.clear();
|
|
65317
66627
|
state.jsx.scrolls.clear();
|
|
66628
|
+
state.jsx.anchors.clear();
|
|
65318
66629
|
state.jsx.remount = false;
|
|
65319
66630
|
state.jsx.asideRoots = 0;
|
|
65320
66631
|
state.jsx.hints.length = 0;
|
|
@@ -65594,121 +66905,21 @@ function createModules(ctx) {
|
|
|
65594
66905
|
};
|
|
65595
66906
|
}
|
|
65596
66907
|
/**
|
|
65597
|
-
* Creates the ui API: the
|
|
66908
|
+
* Creates the ui API: the six members a game calls, flat.
|
|
65598
66909
|
*
|
|
65599
66910
|
* @param ctx - Kernel context of the ui plugin.
|
|
65600
66911
|
* @returns The plugin API.
|
|
65601
66912
|
*/
|
|
65602
66913
|
function createUiApi(ctx) {
|
|
65603
|
-
const
|
|
66914
|
+
const uctx = withDeps(ctx);
|
|
66915
|
+
const { jsx } = createModules(uctx);
|
|
65604
66916
|
return {
|
|
65605
66917
|
tree: jsx.tree,
|
|
65606
66918
|
find: jsx.find,
|
|
65607
66919
|
lint: jsx.lint,
|
|
65608
66920
|
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
|
|
66921
|
+
scroll: jsx.scroll,
|
|
66922
|
+
rectOf: (target) => rectOfTargets(uctx, target)
|
|
65712
66923
|
};
|
|
65713
66924
|
}
|
|
65714
66925
|
//#endregion
|