@moku-labs/game 0.15.118 → 0.15.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +10 -0
  2. package/dist/app/page.d.mts +1 -1
  3. package/dist/app/page.mjs +1 -1
  4. package/dist/app/system.d.mts +3 -3
  5. package/dist/app.d.mts +3 -3
  6. package/dist/app.mjs +1 -1
  7. package/dist/assets.d.mts +1 -1
  8. package/dist/{commands-B16wtdhf.d.mts → commands-Cwxtb672.d.mts} +5 -5
  9. package/dist/control.d.mts +4 -4
  10. package/dist/{define-OPEOQ5MS.d.mts → define-BLFk9wyQ.d.mts} +2 -2
  11. package/dist/{headless-C5kxf9oU.d.mts → headless-DjvkUuv6.d.mts} +1 -1
  12. package/dist/{index-Fth_AFjs.d.mts → index-DSTbAOZZ.d.mts} +9 -7
  13. package/dist/index.d.mts +5 -5
  14. package/dist/index.mjs +2 -2
  15. package/dist/inspect.d.mts +6 -6
  16. package/dist/inspect.mjs +1 -1
  17. package/dist/jsx-dev-runtime.d.mts +1 -1
  18. package/dist/jsx-runtime.d.mts +1 -1
  19. package/dist/{runtime-DylBqKWf.d.mts → runtime-Dl3k95wc.d.mts} +1 -1
  20. package/dist/{sources-WiVMRhXq.mjs → sources-CuG-Vma9.mjs} +1 -1
  21. package/dist/{src-CvM4Qhtr.mjs → src-CvDV2vqI.mjs} +185 -78
  22. package/dist/testing.d.mts +4 -4
  23. package/dist/testing.mjs +1 -1
  24. package/dist/{types-ktcMr5ce.d.mts → types-CKCNyjAI.d.mts} +4 -4
  25. package/dist/{types-CMFC7k5L.d.mts → types-DOsd3uSB.d.mts} +60 -14
  26. package/dist/{types-DIdCmTQx.d.mts → types-DmOnlY66.d.mts} +14 -8
  27. package/dist/{types-BUR4LWSa.d.mts → types-TmWmx6Ca.d.mts} +51 -6
  28. package/dist/{types-CATC2vK8.d.mts → types-ohTEXbrA.d.mts} +2 -2
  29. package/dist/{visual-m6n16q7E.d.mts → visual-DFxSs-Vp.d.mts} +6 -6
  30. package/dist/{visual-CvFDvkA_.mjs → visual-x0TPowBE.mjs} +187 -56
  31. package/dist/visual.d.mts +1 -1
  32. package/dist/visual.mjs +1 -1
  33. package/llms.txt +2 -2
  34. package/package.json +1 -1
@@ -1,4 +1,35 @@
1
1
  import { t as defineComponent } from "./component-DGg5DqKK.mjs";
2
+ //#region src/plugins/world/neutral.ts
3
+ /** The key under which a component type holds the neutral value of its optional numeric fields. Engine-internal. */
4
+ const NEUTRAL = Symbol("moku.neutral");
5
+ /**
6
+ * Gives a component type the neutral value of its optional numeric fields: the number a field means while a stored value
7
+ * leaves it out (`Transform`'s `scaleX` is 1). Engine-internal, not a root export: a tween that starts from a missing
8
+ * field and `toRest` read it through `neutralOf`. The value hangs on the type object under a symbol, so it is neither
9
+ * enumerable nor part of the type's public shape.
10
+ *
11
+ * @param type - The component type.
12
+ * @param neutral - The neutral value of each field.
13
+ * @returns The same type.
14
+ */
15
+ function withNeutral(type, neutral) {
16
+ Object.defineProperty(type, NEUTRAL, { value: Object.freeze({ ...neutral }) });
17
+ return type;
18
+ }
19
+ /**
20
+ * The neutral value of a field of a component type, set by `withNeutral`.
21
+ *
22
+ * @param type - The component type, or any handle.
23
+ * @param field - The field name.
24
+ * @returns The neutral value, or `undefined` when the type declares none for the field.
25
+ */
26
+ function neutralOf(type, field) {
27
+ const held = Reflect.get(type, NEUTRAL);
28
+ if (typeof held !== "object" || held === null) return void 0;
29
+ const value = Reflect.get(held, field);
30
+ return typeof value === "number" ? value : void 0;
31
+ }
32
+ //#endregion
2
33
  //#region src/plugins/world/ecs/define.ts
3
34
  /**
4
35
  * Declares a component type. The defaults give the TypeScript type, the JSON shape and the
@@ -254,10 +285,13 @@ const spriteDefaults = {
254
285
  fit: "fill"
255
286
  };
256
287
  /**
257
- * Where a view sits: reference units, radians, uniform scale, and the local point it turns
258
- * around.
288
+ * Where a view sits: reference units, radians, uniform scale (with an optional factor per axis), and the local point it
289
+ * turns around.
259
290
  */
260
- const Transform = /*#__PURE__*/ component("Transform", transformDefaults);
291
+ const Transform = /*#__PURE__*/ withNeutral(component("Transform", transformDefaults), {
292
+ scaleX: 1,
293
+ scaleY: 1
294
+ });
261
295
  /**
262
296
  * One textured quad. `texture` is an asset key, resolved through the texture providers; a size
263
297
  * and a `fit` draw it into a box. `blend: "add"` or `"screen"` lays it over what is under it.
@@ -423,17 +457,37 @@ function isLeaving(ecs, entity) {
423
457
  return false;
424
458
  }
425
459
  /**
460
+ * Gives a fresh pose the per-axis factors a pose that may reach the ECS carries: a key only when the factor is not 1 or
461
+ * the stored value already has it, so a merge never leaves a stale factor and a plain view gains no key.
462
+ *
463
+ * @param pose - The fresh pose, written in place.
464
+ * @param factorX - The composed X factor.
465
+ * @param factorY - The composed Y factor.
466
+ * @param keepX - Whether the stored value already has `scaleX`.
467
+ * @param keepY - Whether the stored value already has `scaleY`.
468
+ * @returns The same pose.
469
+ * @example
470
+ * ```ts
471
+ * withFactors({ x: 0, y: 0, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } }, 2, 1, false, false).scaleX; // 2
472
+ * ```
473
+ */
474
+ function withFactors(pose, factorX, factorY, keepX, keepY) {
475
+ if (factorX !== 1 || keepX) pose.scaleX = factorX;
476
+ if (factorY !== 1 || keepY) pose.scaleY = factorY;
477
+ return pose;
478
+ }
479
+ /**
426
480
  * A fresh copy of a pose, so a caller may change what it got without touching the world.
427
481
  *
428
482
  * @param pose - The pose to copy.
429
- * @returns The same numbers in new objects.
483
+ * @returns The same numbers in new objects; a factor only where the pose has one.
430
484
  * @example
431
485
  * ```ts
432
486
  * copyPose({ x: 1, y: 2, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } }).pivot.x; // 0
433
487
  * ```
434
488
  */
435
489
  function copyPose(pose) {
436
- return {
490
+ return withFactors({
437
491
  x: pose.x,
438
492
  y: pose.y,
439
493
  rotation: pose.rotation,
@@ -442,7 +496,7 @@ function copyPose(pose) {
442
496
  x: pose.pivot.x,
443
497
  y: pose.pivot.y
444
498
  }
445
- };
499
+ }, pose.scaleX ?? 1, pose.scaleY ?? 1, pose.scaleX !== void 0, pose.scaleY !== void 0);
446
500
  }
447
501
  /**
448
502
  * Moves a point out of the local space of a pose, into the space the pose sits in.
@@ -454,13 +508,16 @@ function copyPose(pose) {
454
508
  * ```ts
455
509
  * applyPose({ x: 10, y: 0, rotation: 0, scale: 2, pivot: { x: 5, y: 0 } }, { x: 5, y: 1 });
456
510
  * // { x: 10, y: 2 }
511
+ * // The same pose stretched 3 times on X: a point 4 right of the pivot lands 24 right of the position.
512
+ * applyPose({ x: 10, y: 0, rotation: 0, scale: 2, scaleX: 3, pivot: { x: 5, y: 0 } }, { x: 9, y: 0 });
513
+ * // { x: 34, y: 0 }
457
514
  * ```
458
515
  */
459
516
  function applyPose(pose, point) {
460
517
  const cos = Math.cos(pose.rotation);
461
518
  const sin = Math.sin(pose.rotation);
462
- const dx = point.x - pose.pivot.x;
463
- const dy = point.y - pose.pivot.y;
519
+ const dx = (point.x - pose.pivot.x) * (pose.scaleX ?? 1);
520
+ const dy = (point.y - pose.pivot.y) * (pose.scaleY ?? 1);
464
521
  return {
465
522
  x: pose.x + pose.scale * (dx * cos - dy * sin),
466
523
  y: pose.y + pose.scale * (dx * sin + dy * cos)
@@ -473,7 +530,8 @@ function applyPose(pose, point) {
473
530
  *
474
531
  * @param above - The parent pose.
475
532
  * @param local - The pose under it.
476
- * @returns The composed pose; it keeps the local pivot.
533
+ * @returns The composed pose; it keeps the local pivot. The factors multiply per axis; a key is there only when the
534
+ * product is not 1 or `local` has it.
477
535
  * @example
478
536
  * ```ts
479
537
  * poseUnder(
@@ -484,7 +542,7 @@ function applyPose(pose, point) {
484
542
  */
485
543
  function poseUnder(above, local) {
486
544
  const landed = applyPose(above, local);
487
- return {
545
+ return withFactors({
488
546
  x: landed.x,
489
547
  y: landed.y,
490
548
  rotation: local.rotation + above.rotation,
@@ -493,12 +551,13 @@ function poseUnder(above, local) {
493
551
  x: local.pivot.x,
494
552
  y: local.pivot.y
495
553
  }
496
- };
554
+ }, (local.scaleX ?? 1) * (above.scaleX ?? 1), (local.scaleY ?? 1) * (above.scaleY ?? 1), local.scaleX !== void 0, local.scaleY !== void 0);
497
555
  }
498
556
  /**
499
557
  * Where an entity really is, written into the caller's pose: its `Transform` composed through the `Parent` chain,
500
558
  * every pivot on the way applied, the numbers of `rootPoseOf` (the same steps in the same order). The answer keeps the
501
- * entity's own pivot. Allocates nothing: a reader that asks every frame passes the same object.
559
+ * entity's own pivot. Allocates nothing: a reader that asks every frame passes the same object. Both per-axis factors
560
+ * are written on every call, 1 for an entity without them, so a reused pose never keeps the factor of the entity before.
502
561
  *
503
562
  * @param ecs - The world read, `world.ecs`.
504
563
  * @param entity - The entity to place.
@@ -508,9 +567,9 @@ function poseUnder(above, local) {
508
567
  * @example
509
568
  * ```ts
510
569
  * // `effects` follows a host every frame: the slot sits at (40, 60) scaled 0.5, the host at (100, 200) inside it.
511
- * const pose = { x: 0, y: 0, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } };
570
+ * const pose = { x: 0, y: 0, rotation: 0, scale: 1, scaleX: 1, scaleY: 1, pivot: { x: 0, y: 0 } };
512
571
  * rootPoseInto(ctx.require(worldPlugin).ecs, host, pose);
513
- * // pose is { x: 90, y: 160, rotation: 0, scale: 0.5, pivot: { x: 0, y: 0 } }
572
+ * // pose is { x: 90, y: 160, rotation: 0, scale: 0.5, scaleX: 1, scaleY: 1, pivot: { x: 0, y: 0 } }
514
573
  * ```
515
574
  */
516
575
  function rootPoseInto(ecs, entity, out, own) {
@@ -519,6 +578,8 @@ function rootPoseInto(ecs, entity, out, own) {
519
578
  out.y = start.y;
520
579
  out.rotation = start.rotation;
521
580
  out.scale = start.scale;
581
+ out.scaleX = "scaleX" in start ? start.scaleX ?? 1 : 1;
582
+ out.scaleY = "scaleY" in start ? start.scaleY ?? 1 : 1;
522
583
  out.pivot.x = start.pivot.x;
523
584
  out.pivot.y = start.pivot.y;
524
585
  let current = entity;
@@ -528,16 +589,33 @@ function rootPoseInto(ecs, entity, out, own) {
528
589
  const above = ecs.get(parent, Transform) ?? Transform.defaults;
529
590
  const cos = Math.cos(above.rotation);
530
591
  const sin = Math.sin(above.rotation);
531
- const dx = out.x - above.pivot.x;
532
- const dy = out.y - above.pivot.y;
592
+ const factorX = "scaleX" in above ? above.scaleX ?? 1 : 1;
593
+ const factorY = "scaleY" in above ? above.scaleY ?? 1 : 1;
594
+ const dx = (out.x - above.pivot.x) * factorX;
595
+ const dy = (out.y - above.pivot.y) * factorY;
533
596
  out.x = above.x + above.scale * (dx * cos - dy * sin);
534
597
  out.y = above.y + above.scale * (dx * sin + dy * cos);
535
598
  out.rotation = out.rotation + above.rotation;
536
599
  out.scale = out.scale * above.scale;
600
+ out.scaleX = out.scaleX * factorX;
601
+ out.scaleY = out.scaleY * factorY;
537
602
  current = parent;
538
603
  }
539
604
  return out;
540
605
  }
606
+ /** The scratch of `rootPoseOf`: one walk at a time, nothing of it leaves, so the call needs no pose of its own. */
607
+ const walked = {
608
+ x: 0,
609
+ y: 0,
610
+ rotation: 0,
611
+ scale: 1,
612
+ scaleX: 1,
613
+ scaleY: 1,
614
+ pivot: {
615
+ x: 0,
616
+ y: 0
617
+ }
618
+ };
541
619
  /**
542
620
  * Where an entity really is: its `Transform` composed through the `Parent` chain, every pivot on
543
621
  * the way applied. The answer keeps the entity's own pivot, so it can be written straight into the
@@ -546,7 +624,9 @@ function rootPoseInto(ecs, entity, out, own) {
546
624
  * @param ecs - The world read, `world.ecs`.
547
625
  * @param entity - The entity to place.
548
626
  * @param own - A pose to use in place of the entity's own `Transform`, such as its rest pose.
549
- * @returns The pose in root space, a fresh object. An entity without a `Transform` sits at the identity pose.
627
+ * @returns The pose in root space, a fresh object. An entity without a `Transform` sits at the identity pose. It has
628
+ * `scaleX` / `scaleY` only where the composed factor is not 1 or the entity's own pose has the key, so a plain view
629
+ * gains no key when this is written back.
550
630
  * @example
551
631
  * ```ts
552
632
  * // `input` lifts a board cell out of its slot: the slot sits at (40, 60) scaled 0.5,
@@ -556,16 +636,18 @@ function rootPoseInto(ecs, entity, out, own) {
556
636
  * ```
557
637
  */
558
638
  function rootPoseOf(ecs, entity, own) {
559
- return rootPoseInto(ecs, entity, {
560
- x: 0,
561
- y: 0,
562
- rotation: 0,
563
- scale: 1,
639
+ const start = own ?? ecs.get(entity, Transform);
640
+ const pose = rootPoseInto(ecs, entity, walked, own);
641
+ return withFactors({
642
+ x: pose.x,
643
+ y: pose.y,
644
+ rotation: pose.rotation,
645
+ scale: pose.scale,
564
646
  pivot: {
565
- x: 0,
566
- y: 0
647
+ x: pose.pivot.x,
648
+ y: pose.pivot.y
567
649
  }
568
- }, own);
650
+ }, pose.scaleX, pose.scaleY, start?.scaleX !== void 0, start?.scaleY !== void 0);
569
651
  }
570
652
  /**
571
653
  * The inverse of `rootPoseOf`: the local pose under `parent` that puts an entity at a root pose.
@@ -574,8 +656,8 @@ function rootPoseOf(ecs, entity, own) {
574
656
  * @param ecs - The world read, `world.ecs`.
575
657
  * @param parent - The entity to hang under; `0` for none, which answers the root pose itself.
576
658
  * @param root - The pose in root space.
577
- * @returns The local pose. A parent collapsed to scale 0 counts as scale 1, so the answer stays
578
- * finite.
659
+ * @returns The local pose. A parent collapsed to scale 0, or a factor of 0, counts as 1, so the answer stays finite. The
660
+ * per-axis factors divide per axis; a key is there only where the result is not 1 or `root` has it.
579
661
  * @example
580
662
  * ```ts
581
663
  * // `input` drops the cell back into the slot at (40, 60) scaled 0.5, where the finger left it.
@@ -589,20 +671,22 @@ function localPoseOf(ecs, parent, root) {
589
671
  if (parent === 0) return copyPose(root);
590
672
  const above = rootPoseOf(ecs, parent);
591
673
  const scale = above.scale === 0 ? 1 : above.scale;
674
+ const factorX = above.scaleX === void 0 || above.scaleX === 0 ? 1 : above.scaleX;
675
+ const factorY = above.scaleY === void 0 || above.scaleY === 0 ? 1 : above.scaleY;
592
676
  const cos = Math.cos(-above.rotation);
593
677
  const sin = Math.sin(-above.rotation);
594
678
  const dx = root.x - above.x;
595
679
  const dy = root.y - above.y;
596
- return {
597
- x: above.pivot.x + (dx * cos - dy * sin) / scale,
598
- y: above.pivot.y + (dx * sin + dy * cos) / scale,
680
+ return withFactors({
681
+ x: above.pivot.x + (dx * cos - dy * sin) / (scale * factorX),
682
+ y: above.pivot.y + (dx * sin + dy * cos) / (scale * factorY),
599
683
  rotation: root.rotation - above.rotation,
600
684
  scale: root.scale / scale,
601
685
  pivot: {
602
686
  x: root.pivot.x,
603
687
  y: root.pivot.y
604
688
  }
605
- };
689
+ }, (root.scaleX ?? 1) / factorX, (root.scaleY ?? 1) / factorY, root.scaleX !== void 0, root.scaleY !== void 0);
606
690
  }
607
691
  /**
608
692
  * Where a local point of an entity lands in root (reference) space: the point posed through the
@@ -1253,11 +1337,13 @@ function formatBound(value, format, duration) {
1253
1337
  * Declares one style. The work is the type: a field outside the vocabulary, or a value outside
1254
1338
  * its union, is an error where the style is written, not where it is used.
1255
1339
  *
1256
- * @param style - The style, with its `is` and `when` variants.
1340
+ * @param style - The style, with its `is` and `when` variants; the style of a text may name its
1341
+ * text style key, in its base and in its `when` variants.
1257
1342
  * @returns The same object, frozen.
1258
1343
  * @example
1259
1344
  * ```ts
1260
1345
  * defineStyle({ direction: "row", gap: 12 }).gap; // 12
1346
+ * defineStyle({ text: "title.19", when: { tall: { text: "title.20.5" } } }).when.tall.text; // "title.20.5"
1261
1347
  * ```
1262
1348
  */
1263
1349
  function defineStyle(style) {
@@ -1465,6 +1551,36 @@ const FITS = [
1465
1551
  "cover",
1466
1552
  "fill"
1467
1553
  ];
1554
+ /** What a text is drawn in when its markup names no text style key. */
1555
+ const DEFAULT_TEXT_STYLE = "body";
1556
+ /**
1557
+ * The text style key the markup of a text names (F182): the key its resolved style took from its
1558
+ * base or from a `when` variant of this frame, else its `style` prop while that is a key. A
1559
+ * property read and a type check: nothing is built.
1560
+ *
1561
+ * @param style - The resolved style of the text.
1562
+ * @param property - Its `style` prop.
1563
+ * @returns The key, or `undefined` when the markup names none.
1564
+ * @example
1565
+ * ```ts
1566
+ * namedKeyOf({ text: "title.20.5" }, "title.19"); // "title.20.5"
1567
+ * ```
1568
+ */
1569
+ function namedKeyOf(style, property) {
1570
+ if (typeof style.text === "string") return style.text;
1571
+ return typeof property === "string" ? property : void 0;
1572
+ }
1573
+ /**
1574
+ * The text style key a text's markup writes into `Text.style` and is measured with until the
1575
+ * entity carries its `Text`: the key it names, else `body`. One reader for the measure, the
1576
+ * `Text` write and `lint()`; a format of a game still answers its own style where it does.
1577
+ *
1578
+ * @param element - The text, its style of this frame resolved.
1579
+ * @returns The key.
1580
+ */
1581
+ function writtenKeyOf(element) {
1582
+ return namedKeyOf(element.style, element.node.props.style) ?? DEFAULT_TEXT_STYLE;
1583
+ }
1468
1584
  /**
1469
1585
  * Tells whether a tag draws nothing of its own, so its `Shape` is invisible unless its style fills.
1470
1586
  *
@@ -1711,7 +1827,7 @@ function fieldsLeftAlone(element, type, owned) {
1711
1827
  /**
1712
1828
  * The visual component of an element: a sprite for an image or an icon (at alpha 0 while its style
1713
1829
  * states a size the layout makes 0: the renderer draws a sprite of width 0 at its texture's size,
1714
- * so the size alone cannot say "nothing"), the text for a text (with
1830
+ * so the size alone cannot say "nothing"), the text for a text (in the key of `writtenKeyOf`, with
1715
1831
  * its laid-out width as the box a `"box"` style wraps at), the nine-slice of its style (outlined
1716
1832
  * when the style sets `debug`, its rim alone when it sets `hollow`; the sprite and the nine-slice
1717
1833
  * blended by the style's `blend`), or a rounded rectangle, a triangle with `shape: "triangle"`, its
@@ -1747,19 +1863,16 @@ function visualOf(element) {
1747
1863
  ...blendOf(element, style.blend)
1748
1864
  })];
1749
1865
  }
1750
- if (type === "text") {
1751
- const styleKey = typeof node.props.style === "string" ? node.props.style : "body";
1752
- return [Text({
1753
- content: contentOf(node.props),
1754
- style: styleKey,
1755
- bind: node.props.bind,
1756
- anchor: {
1757
- x: 0,
1758
- y: 0
1759
- },
1760
- ...boxOf(element)
1761
- })];
1762
- }
1866
+ if (type === "text") return [Text({
1867
+ content: contentOf(node.props),
1868
+ style: writtenKeyOf(element),
1869
+ bind: node.props.bind,
1870
+ anchor: {
1871
+ x: 0,
1872
+ y: 0
1873
+ },
1874
+ ...boxOf(element)
1875
+ })];
1763
1876
  const clip = type === "scroll" || style.overflow === "hidden";
1764
1877
  if (style.nineSlice !== void 0 && !clip) return [NineSlice({
1765
1878
  texture: style.nineSlice,
@@ -1862,7 +1975,7 @@ function visualRectOf(element, lookup) {
1862
1975
  return scaleByFits(element.rect, chainOf(element, lookup));
1863
1976
  }
1864
1977
  /**
1865
- * Tells whether two transforms put a view in the same place.
1978
+ * Tells whether two transforms put a view in the same place. A missing `scaleX` or `scaleY` counts as 1.
1866
1979
  *
1867
1980
  * @param first - One pose.
1868
1981
  * @param second - The other.
@@ -1871,16 +1984,25 @@ function visualRectOf(element, lookup) {
1871
1984
  * ```ts
1872
1985
  * samePose(
1873
1986
  * { x: 1, y: 2, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } },
1874
- * { x: 1, y: 2, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } }
1987
+ * { x: 1, y: 2, rotation: 0, scale: 1, scaleX: 1, pivot: { x: 0, y: 0 } }
1875
1988
  * ); // true
1989
+ * samePose(
1990
+ * { x: 1, y: 2, rotation: 0, scale: 1, pivot: { x: 0, y: 0 } },
1991
+ * { x: 1, y: 2, rotation: 0, scale: 1, scaleX: 0.5, pivot: { x: 0, y: 0 } }
1992
+ * ); // false
1876
1993
  * ```
1877
1994
  */
1878
1995
  function samePose(first, second) {
1879
- return first.x === second.x && first.y === second.y && first.rotation === second.rotation && first.scale === second.scale && first.pivot.x === second.pivot.x && first.pivot.y === second.pivot.y;
1996
+ const firstX = "scaleX" in first ? first.scaleX ?? 1 : 1;
1997
+ const secondX = "scaleX" in second ? second.scaleX ?? 1 : 1;
1998
+ const firstY = "scaleY" in first ? first.scaleY ?? 1 : 1;
1999
+ const secondY = "scaleY" in second ? second.scaleY ?? 1 : 1;
2000
+ return first.x === second.x && first.y === second.y && first.rotation === second.rotation && first.scale === second.scale && firstX === secondX && firstY === secondY && first.pivot.x === second.pivot.x && first.pivot.y === second.pivot.y;
1880
2001
  }
1881
2002
  /**
1882
- * Where a local box of a view lands in root space: moved by the pose, scaled around its pivot.
1883
- * A guide hole is axis-aligned, so the rotation is left out.
2003
+ * Where a local box of a view lands in root space: moved by the pose, scaled around its pivot, per axis
2004
+ * (`scale × scaleX` wide, `scale × scaleY` tall). A guide hole is axis-aligned, so the rotation is left out. A size is
2005
+ * a magnitude: a view flipped by a negative factor keeps its width and starts at its left edge.
1884
2006
  *
1885
2007
  * @param pose - The root pose of the view, `rootPoseOf` of `renderer`.
1886
2008
  * @param local - The box in the view's local units.
@@ -1889,15 +2011,24 @@ function samePose(first, second) {
1889
2011
  * ```ts
1890
2012
  * drawnRect({ x: 200, y: 200, rotation: 0, scale: 0.8, pivot: { x: 250, y: 250 } },
1891
2013
  * { x: 50, y: 50, w: 100, h: 100 }); // { x: 40, y: 40, w: 80, h: 80 }
2014
+ * // A ribbon of 200 x 40 squeezed to half its width about its left edge.
2015
+ * drawnRect({ x: 0, y: 0, rotation: 0, scale: 1, scaleX: 0.5, pivot: { x: 0, y: 0 } },
2016
+ * { x: 0, y: 0, w: 200, h: 40 }); // { x: 0, y: 0, w: 100, h: 40 }
1892
2017
  * ```
1893
2018
  */
1894
2019
  function drawnRect(pose, local) {
2020
+ const factorX = pose.scale * (pose.scaleX ?? 1);
2021
+ const factorY = pose.scale * (pose.scaleY ?? 1);
2022
+ const w = local.w * Math.abs(factorX);
2023
+ const h = local.h * Math.abs(factorY);
2024
+ const left = pose.x + factorX * (local.x - pose.pivot.x);
2025
+ const top = pose.y + factorY * (local.y - pose.pivot.y);
1895
2026
  return {
1896
- x: pose.x + pose.scale * (local.x - pose.pivot.x),
1897
- y: pose.y + pose.scale * (local.y - pose.pivot.y),
1898
- w: local.w * pose.scale,
1899
- h: local.h * pose.scale
2027
+ x: factorX < 0 ? left - w : left,
2028
+ y: factorY < 0 ? top - h : top,
2029
+ w,
2030
+ h
1900
2031
  };
1901
2032
  }
1902
2033
  //#endregion
1903
- export { Parent as $, Countdown as A, applyPose as B, uiFor as C, isTextFormat as D, formatBound as E, defineTextFormats as F, rootPointOf as G, localPoseOf as H, defineTextStyles as I, Display as J, rootPoseInto as K, label as L, bind as M, boldLookOf as N, unitOf as O, builtInStyles as P, OverlayLevel as Q, readStyle as R, popup as S, defineStyle as T, parentOf as U, isLeaving as V, poseUnder as W, NineSlice as X, HudPart as Y, Overlay as Z, LocalWrite as _, fieldsLeftAlone as a, sprite as at, UI_OWNER as b, namesFormat as c, Now as ct, visualOf as d, component as dt, Shape as et, visualRectOf as f, mut as ft, Escapable as g, tag as gt, DebugTrigger as h, systemsFor as ht, drawnRect as i, componentsFor as it, Text as j, wholeValue as k, restValueOf as l, Order as lt, Covered as m, system as mt, CONTENT as n, Transform as nt, fitScaleOf as o, Exiting as ot, Box as p, resource as pt, rootPoseOf as q, bindOf as r, arcDefaults as rt, livePatch as s, Layer as st, ANCHOR as t, Sprite as tt, samePose as u, Tree as ut, Scroll as v, defineTokens as w, UiCounters as x, ScrollState as y, textFor as z };
2034
+ export { Overlay as $, unitOf as A, readStyle as B, UiCounters as C, defineStyle as D, defineTokens as E, boldLookOf as F, parentOf as G, applyPose as H, builtInStyles as I, rootPoseInto as J, poseUnder as K, defineTextFormats as L, Countdown as M, Text as N, formatBound as O, bind as P, NineSlice as Q, defineTextStyles as R, UI_OWNER as S, uiFor as T, isLeaving as U, textFor as V, localPoseOf as W, Display as X, rootPoseOf as Y, HudPart as Z, DebugTrigger as _, systemsFor as _t, fieldsLeftAlone as a, arcDefaults as at, Scroll as b, namedKeyOf as c, Exiting as ct, samePose as d, Order as dt, OverlayLevel as et, visualOf as f, Tree as ft, Covered as g, system as gt, Box as h, resource as ht, drawnRect as i, Transform as it, wholeValue as j, isTextFormat as k, namesFormat as l, Layer as lt, writtenKeyOf as m, mut as mt, CONTENT as n, Shape as nt, fitScaleOf as o, componentsFor as ot, visualRectOf as p, component as pt, rootPointOf as q, bindOf as r, Sprite as rt, livePatch as s, sprite as st, ANCHOR as t, Parent as tt, restValueOf as u, Now as ut, Escapable as v, tag as vt, popup as w, ScrollState as x, LocalWrite as y, neutralOf as yt, label as z };
package/dist/visual.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-m6n16q7E.mjs";
1
+ import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-DFxSs-Vp.mjs";
2
2
  export { type CheckpointResult, type VisualApp, type VisualOptions, type VisualPage, type VisualRenderer, type VisualReport, type VisualSetup, type VisualStart, type VisualStep, type VisualTest, type VisualTestResult, type VisualTolerance, defineVisualTest, parseVisualArgv, runVisualTests };
package/dist/visual.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as VISUAL_CLOCK } from "./fake-hnJcJeYf.mjs";
2
- import { n as read, t as sources } from "./sources-WiVMRhXq.mjs";
2
+ import { n as read, t as sources } from "./sources-CuG-Vma9.mjs";
3
3
  import { n as commands, t as run } from "./run-CeZj5UAg.mjs";
4
4
  import path from "node:path";
5
5
  import { createBrandConsole } from "@moku-labs/common/cli";
package/llms.txt CHANGED
@@ -27,7 +27,7 @@ Root exports:
27
27
  - Class: `SaveUnreadableError`.
28
28
  - Plugin instances: `timePlugin`, `lifecyclePlugin`, `modelPlugin`, `clockPlugin`, `flowPlugin`, `worldPlugin`, `rendererPlugin`, `inputPlugin`, `assetsPlugin`, `scenesPlugin`, `animPlugin`, `i18nPlugin`, `textPlugin`, `uiPlugin`, `audioPlugin`, `effectsPlugin`, `platformPlugin`; the list `screen` = `world`, `renderer`, `input`, `assets`, `scenes`, `anim`, `i18n`, `text`, `ui`. `effects`, `audio` and `platform` are opt-in: `plugins: [...screen, effectsPlugin, audioPlugin, platformPlugin]`, `platform` last.
29
29
  - Screen helpers from the root: `component`, `tag`, `resource`, `mut`, `system`, `projection`, `Layer`, `Order`, `Exiting`, `Tree`, `Now`, `Transform`, `Sprite`, `NineSlice`, `Shape`, `Parent`, `Display`, `Overlay`, `HudPart`, `sprite`, `Tappable`, `Pressable`, `Draggable`, `DropTarget`, `Swipeable`, `Traceable`, `Touchable`, `Held`, `Hovered`, `PointerOver`, `Pressed`, `Pointer`, `Traced`, `defineBundles`, `load`, `defineScene`.
30
- - Interface helpers from the root (V3): `defineAnimation`, `sequence`, `parallel`, `stagger`, `tween`, `set`, `wait`, `mark`, `frames`, `sfx`, `haptic`, `use`, `spawn`, `spawned`, `play`, `external`, `defineMotion`, `Animation`, `Frames`, the resource `AnimPlayer`; `tr`, `messageArgument`, `messageDuration`; `Text`, `label`, `defineTextStyles`, `defineTextFormats`, `bind`, `Countdown` and the types `BindOptions`, `CountdownValue`, `TextFormat`, `TextFormats`, `TextFormatAnswer`, `TextFormatFunction`, `FormattedNumber`; `defineComponent`, `popup`, `defineStyle`, `defineTokens`, `resolve`, `Box`, `LocalWrite`, `DebugTrigger`, `ScrollState`; `music`. Also `stopSfx(id, { fadeMs? })` (ends a named sound, see audio) and `cubicBezier(x1, y1, x2, y2)` (a CSS-style easing curve for `tween`'s `ease`).
30
+ - Interface helpers from the root (V3): `defineAnimation`, `sequence`, `parallel`, `stagger`, `tween`, `set`, `wait`, `mark`, `frames`, `sfx`, `haptic`, `use`, `spawn`, `spawned`, `play`, `external`, `defineMotion`, `Animation`, `Frames`, the resource `AnimPlayer`; `tr`, `messageArgument`, `messageDuration`; `Text`, `label`, `defineTextStyles`, `defineTextFormats`, `bind`, `Countdown` and the types `BindOptions`, `CountdownValue`, `TextFormat`, `TextFormats`, `TextFormatAnswer`, `TextFormatFunction`, `FormattedNumber`; `defineComponent`, `popup`, `defineStyle` and the type `TextTagStyle`, `defineTokens`, `resolve`, `Box`, `LocalWrite`, `DebugTrigger`, `ScrollState`; `music`. Also `stopSfx(id, { fadeMs? })` (ends a named sound, see audio) and `cubicBezier(x1, y1, x2, y2)` (a CSS-style easing curve for `tween`'s `ease`).
31
31
  - Effects helpers from the root (V5): `defineEmitter`, `Emitter`, `defineFilter`, `Glow`, `Outline`, `Blur`, `ColorMatrix`, `Noise`, `Displacement`, `Alpha`; the effect set `Flash`, `Grade`, `Vignette`, `RevealLine`, `RevealRound`, `Dissolve`, `Shine`, `Aura`, `Fold`, `Bloom` and their value types `FlashValue`, `GradeValue`, `VignetteValue`, `RevealLineValue`, `RevealRoundValue`, `DissolveValue`, `ShineValue`, `AuraValue`, `FoldValue`, `BloomValue`.
32
32
  - Platform from the root (V6): the types `PlatformProvider`, `BackResult`, `HapticKind` and the frozen list `HAPTIC_KINDS`.
33
33
  - `defineGame<Types>()` returns, typed by the game's `player`, `session`, `assets`, `bundles`, `scenes`, `strings`, `textStyles` and `textFormats`: `defineNode`, `defineFlow`, `defineFeature`, `projection`, `sprite`, `Sprite`, `NineSlice`, `defineBundles`, `load`, `defineScene`, `defineAnimation`, `frames`, `sfx`, `play`, `tr`, `label`, `bind`, `defineTextStyles`, `defineTextFormats`, `defineComponent`, `defineStyle`, `defineTokens`, `popup`, `music`, `Frames`, `defineEmitter`, `Emitter`, `Displacement`, and `system` (its `ctx.snapshot` typed by `player` and `session`), `volumes` (the `audio` config's reader of the typed player), `key` (string keys from data, below). `Types` is `{ player; session; assets: string; bundles?: string; scenes?: string; strings: Record<string, unknown>; textStyles?: string; textFormats?: string; emitters?: string }`.
@@ -595,7 +595,7 @@ The graph. Modules `runner`, `gate`, `inbox`, `fx`, `features`. Runner methods s
595
595
  A screen is a projection whose `view` returns JSX. The game's `tsconfig.json` sets `"jsx": "react-jsx"` and `"jsxImportSource": "@moku-labs/game"`; screens are `.tsx` files. There is no DOM and no React.
596
596
 
597
597
  - Tags: `screen`, `layer`, `row`, `column`, `stack`, `spacer`, `panel` (swallows taps), `image` (`texture`, `fit?: "contain" | "cover" | "fill"`), `icon` (`name`, `fit?`), `text` (`content: string | Message`, or `bind={bind(Counter, "value")}` with `components={[Counter({ value })]}`; formats `int`, `mm:ss`, `h:mm:ss`, `duration`; `Countdown({ until })` with `bind(Countdown, "left", { format: "mm:ss" })` counts down to a `clock` moment; `style` is a text style key), `button` (`intent` + `payload`, or `local`, never both; `point` beside `intent` adds `payload.point: { x, y }` of a finger tap, the press-down point in the button's own units, (0, 0) its top-left corner, absent for keyboard taps: `<button intent="kitTap" point />`), `scroll` (`axis?: "x" | "y"` (`"y"`), fixed at spawn, another one later warns `ui:scroll-axis-fixed`; children for a short list, laid out as a column on `y` and a row on `x`, or the windowed form `rows`, `rowHeight`, `overscan?` (5), `row: index => node`, on `y` only: `axis: "x"` with `rows` throws `[game] A windowed scroll moves on y only.`; row state belongs in the model, a row that leaves the window loses its local state; `snap?: number[]` stops in offsets, kept inside `0..max`: a release glides to the stop nearest `offset + v × 260` (v in units a ms) on `1 − (1 − p)³` over `min(620, 260 + distance × 1.1)` ms; without `snap` a release flings, `v ×= 0.998` a ms until under 0.02, 0 when the finger rested over 50 ms; `offset?: number` (0) where it stands from the start, drawn there in its first frame, a new value glides there, the same value does nothing; `jump?: boolean` makes a new `offset` value of that render stand there at once, in the same solve as the content's new rects (track and offset shifted 82 together keep the cards in place), its fling or glide stopped, `moving: false`; a held scroll only remembers it; left out, a new value glides; hard edges, nothing passes on to a parent scroll; a press on a child that leaves the tap slop along the scroll's axis goes to the scroll and the child answers nothing, a finger on a moving scroll only stops it; every number in `time.delta` ms, so a time scale applies; the public component `ScrollState { offset, max, moving }` on its entity, whole units `0..max`, written when it changes and once with `moving: false` when it stops, read by a system and by `game.explain`; `app.ui.scroll(key, to)` and the visual step `{ scroll: { key, to } }` set it at once), `input` (a text field; its text lives in the component's `local`, see the ui README), `anchor` (`to: AnchorTarget | AnchorTarget[]`, `AnchorTarget` = `{ projection, key }`, a ui element keyed under its root's projection; `pad?: number` (0) outward in its root's units: its rect is where its targets are drawn, the union of the shown ones, in the frame they are laid out, scrolled or moved, through fits, slots and ancestor motion, rotation left out; children lay out inside it; a `width`/`height`/`position` in its style is ignored (`ui:anchor-style`, dev); with no target shown it is drawn at alpha 0 and takes no tap, stays, and comes back with its target; `ui:anchor-target-missing` `{ key, to }` once (dev) after a key named nothing two frames in a row; a target inside the anchor is refused, `[game] An anchor cannot point at its own child "key".`; its `change.Box` motion plays only when its targets change (a new `to`, a key naming another entity), never on a follow, and a glide that runs is carried so it lands on the moving target; 0 B a frame still or following: `<anchor key="window" to={{ projection: "board.strip", key: "seat0" }} pad={4} motion={glide}>`). Common props: `key`, `style`, `state: { active?, disabled?, selected? }`, `motion`, `components` (extra component values for the element's entity, such as a filter: `components={[Glow({ strength: 2 })]}`, or `DebugTrigger()`: five taps within 3000 ms of wall time on that view call `app.debug.overlay.open()` on a page with the agent flag, nothing elsewhere; put it on a `button` naming nothing); containers take `hosts?: string[]` (projections drawn inside the element: world views hang under it from the slot's first frame; a JSX projection is laid out in the slot's content box). Children draw and are hit in markup order at equal `zIndex`; the roots of a scene draw in the order of its `projections` (the `ui` layer sorts by `Order`; `ui: { sort: "none" }` keeps insertion order). `defineMotion({ when: "change" })` plays its `enter` and `exit` only for a commit or a popup, never when its screen mounts or unmounts; declare a motion at module level (`ui:motion-rebuilt` names a loop rebuilt in a view). `motion.change` plays `Box` (the rects), `Transform` (the rest poses), the visual the element is drawn with (`Shape`, `Sprite`, `NineSlice`, `Text`, when a render or a restyle moves a number of it: `sweep`, `alpha`, `w`; a returned motion brings the numbers home from where they stand and the other fields land at once; the last motion of that name is cancelled first) and each extra of `components`, each as `(view, previous, next, hint)`; a dev build names any other `change` hook once, `ui:change-never-plays` `{ key, name }`. An element a render replaces (a root whose view returns another key or tag, a child of another key or tag) plays its exit with `"change"`, everything under it plays its own, and it leaves `find` at once, so the new element takes the keys they share. Style adds `nineSlice`, `tint`, `offsetX`, `offsetY`, `scale`, `origin`, `fit: "contain"`; state variants `is: { hover, pressed, disabled, active, selected, covered }`. `popup(Component, props, { over })` stacks a popup over a kept one.
598
- - Style vocabulary (`defineStyle`, plain data): flow `direction`, `wrap`, `justify`, `align`, `alignSelf`, `gap`, `grow`, `shrink`; box `padding`, `margin`, `width`, `height`, `minWidth`, `minHeight`, `maxWidth`, `maxHeight`, `aspect`, `overflow`; position `position`, `left`, `top`, `right`, `bottom`, `reason`; visual `fill`, `stroke`, `strokeWidth`, `radius`, `alpha`, `shape: "rect" | "triangle" | "arc"` (`"rect"`; a triangle fills the box pointing right; an arc is only a `stroke` of `strokeWidth` on the circle inscribed in the box, `min(width, height) − strokeWidth` across, from 12 o'clock clockwise over `sweep`), `dash` (dash length of the stroke, gaps of half a dash; not on an arc), `sweep` (0..1, default 1, clamped; 0 draws nothing, 1 a closed ring), `cap: "round" | "butt"` (`"round"`; the ends of an open arc); variants `is: { pressed?, disabled?, active?, selected? }` and `when: { portrait?, landscape?, tall?, wide? }`, each a partial style merged in when the flag holds. Lengths are reference units or `"safeArea.top" | "safeArea.right" | "safeArea.bottom" | "safeArea.left"`. No font size here: it comes from the text style.
598
+ - Style vocabulary (`defineStyle`, plain data): flow `direction`, `wrap`, `justify`, `align`, `alignSelf`, `gap`, `grow`, `shrink`; box `padding`, `margin`, `width`, `height`, `minWidth`, `minHeight`, `maxWidth`, `maxHeight`, `aspect`, `overflow`; position `position`, `left`, `top`, `right`, `bottom`, `reason`; visual `fill`, `stroke`, `strokeWidth`, `radius`, `alpha`, `shape: "rect" | "triangle" | "arc"` (`"rect"`; a triangle fills the box pointing right; an arc is only a `stroke` of `strokeWidth` on the circle inscribed in the box, `min(width, height) − strokeWidth` across, from 12 o'clock clockwise over `sweep`), `dash` (dash length of the stroke, gaps of half a dash; not on an arc), `sweep` (0..1, default 1, clamped; 0 draws nothing, 1 a closed ring), `cap: "round" | "butt"` (`"round"`; the ends of an open arc); variants `is: { pressed?, disabled?, active?, selected? }` and `when: { portrait?, landscape?, tall?, wide? }`, each a partial style merged in when the flag holds. Lengths are reference units or `"safeArea.top" | "safeArea.right" | "safeArea.bottom" | "safeArea.left"`. No font size here: it comes from the text style. A `<text>` style object (type `TextTagStyle`) also takes `text: "<text style key>"`, in its base and in `when` (not `is`): `style={{ text: "title.19", when: { tall: { text: "title.20.5" } } }}` draws one text with the key of the frame (F182).
599
599
  - `defineComponent(name, { local?, outcomes?, view(props, local) })`. A component with `outcomes` is a popup: `await fx(popup(Component, props))` opens the gate for its outcomes and resolves with `{ intent, payload, at }` of the pressed button, `at` the clock moment of the answer. A button with `local` writes into the nearest component instance; it never reaches the graph.
600
600
  - `tr(key, params?)` returns a frozen `Message` `{ key, params }`; no locale is read at the call site. Strings live in `strings/<locale>.json` of any feature or sub-feature, as ICU MessageFormat 1 (`{n, plural, one {# order} other {# orders}}`, `select`, `selectordinal`, `number`, `date`, `time`; no skeletons, no `currency`). `bun run assets:keys` compiles them. The keys of the top-level features and the layers go into `generated/strings.<locale>.ts`, which one feature registers; a sub-feature's keys start with `<name>.` (`ep01.title`) and go into `generated/strings.<name>.<locale>.ts`, which the sub-feature registers lazily, `strings: { en: () => import("@generated/strings.ep01.en"), ru: () => import("@generated/strings.ep01.ru") }`. With `assets` composed those modules load and unload with the bundle named like the sub-feature: every way the bundle comes (a node entry, a scene's `bundles`, `load`, a restore, the `safeNode`) brings its strings, a locale switch brings them in the new locale, and while the bundle is not loaded a key of it gives `⟦key⟧` and `has(key)` is false. A compiled module calls the root helpers `messageArgument(value, intl)` (an element stays an element part, a list goes through `Intl.ListFormat`, a number through `Intl.NumberFormat`, else text) and `messageDuration(ms)` (`95_000` gives `{ minutes: 1, seconds: 35 }`). `app.i18n`: `locale()`, `setLocale(locale)` (async, emits `i18n:locale-changed`), `format(message, locale?)` returns `Part[]`, `plain(message)` returns a string, `has(key)`, `isKey(value)`, `locales()`, `replace(locale, messages)` (dev hot swap of a generated strings file). Config: `locale: "en"`, `fallback: "en"`, `locales: {}`.
601
601
  - Keys that come from data: `I18n.TextKey<Strings>` is the keys of the generated `Strings` without parameters (nothing new is generated). A data table types its keys `TextKey` or builds them with the kit's `key("board.hint.red")`; the kit's `tr` never takes a plain `string`. A key read back from a save is checked where the app is (an effect handler, app or page code, loading a save) with one `isKey(value)`: `defineGameApp({ ..., strings: type<Strings>() })` types the game's `app.i18n`, so a true `app.i18n.isKey(value)` narrows the value to `TextKey`; `ctx.require(i18nPlugin).isKey(value)` in a plugin narrows to `string`. `app.i18n.isKey(value)` answers true for a key of the loaded tables of the current locale or the fallback, and for the `<feature>.` prefix of a sub-feature whose strings are not loaded yet; a key that takes parameters answers true too.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/game",
3
- "version": "0.15.118",
3
+ "version": "0.15.120",
4
4
  "description": "2D puzzle game engine on TypeScript and PixiJS, built on @moku-labs/core.",
5
5
  "type": "module",
6
6
  "sideEffects": [