@moku-labs/game 0.15.103 → 0.15.104

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 (33) hide show
  1. package/dist/app/page.d.mts +1 -1
  2. package/dist/app/page.mjs +1 -1
  3. package/dist/app/system.d.mts +3 -3
  4. package/dist/app.d.mts +3 -3
  5. package/dist/app.mjs +1 -1
  6. package/dist/assets.d.mts +1 -1
  7. package/dist/{commands-TSyhs2-E.d.mts → commands-CYXJyv3w.d.mts} +5 -5
  8. package/dist/control.d.mts +4 -4
  9. package/dist/{define-DNF9A0ce.d.mts → define-Cq8Df0_C.d.mts} +2 -2
  10. package/dist/{headless-CEG1oR5D.d.mts → headless-DRiVyv9T.d.mts} +1 -1
  11. package/dist/{index-DDZ9K9qO.d.mts → index-BIofySGI.d.mts} +16 -6
  12. package/dist/index.d.mts +5 -5
  13. package/dist/index.mjs +2 -2
  14. package/dist/inspect.d.mts +6 -6
  15. package/dist/inspect.mjs +1 -1
  16. package/dist/jsx-dev-runtime.d.mts +1 -1
  17. package/dist/jsx-runtime.d.mts +1 -1
  18. package/dist/{runtime-CcHPrVBm.d.mts → runtime-DuAOUZ-z.d.mts} +1 -1
  19. package/dist/{sources-BJyIJf_X.mjs → sources-JeKXYU_y.mjs} +1 -1
  20. package/dist/{src-DVJ0d04R.mjs → src-BJBCs69P.mjs} +1209 -440
  21. package/dist/testing.d.mts +4 -4
  22. package/dist/testing.mjs +1 -1
  23. package/dist/{types-CMag4vDu.d.mts → types-BT8kKhan.d.mts} +4 -4
  24. package/dist/{types-C1B7-x7p.d.mts → types-BlXBiM8d.d.mts} +191 -36
  25. package/dist/{types-BvgY7Ncf.d.mts → types-C1-VCBhy.d.mts} +2 -2
  26. package/dist/{types-C612npUH.d.mts → types-Ca90Yo7d.d.mts} +2 -2
  27. package/dist/{types-Ce5W0gZe.d.mts → types-CayM8xne.d.mts} +1 -1
  28. package/dist/{visual-PsEr2KD-.d.mts → visual-B_3sVlRK.d.mts} +6 -6
  29. package/dist/{visual-DhqD6W3v.mjs → visual-fyUJwUJf.mjs} +163 -4
  30. package/dist/visual.d.mts +1 -1
  31. package/dist/visual.mjs +1 -1
  32. package/llms.txt +1 -1
  33. package/package.json +2 -2
@@ -761,10 +761,104 @@ function isLineHeight(lineHeight) {
761
761
  if (lineHeight === void 0) return true;
762
762
  return typeof lineHeight === "number" && Number.isFinite(lineHeight) && lineHeight > 0;
763
763
  }
764
+ /** The fields `boldStyle` may name: the glyph look of a run. */
765
+ const RUN_STYLE_KEYS = Object.freeze([
766
+ "font",
767
+ "size",
768
+ "fill",
769
+ "letterSpacing",
770
+ "stroke",
771
+ "strokeWidth",
772
+ "shadow"
773
+ ]);
774
+ /**
775
+ * Tells whether a value is a finite number.
776
+ *
777
+ * @param value - A field of a style, as it was stored.
778
+ * @returns True for a number that is not `NaN` or infinite.
779
+ * @example
780
+ * ```ts
781
+ * isFiniteNumber(Number.NaN); // false
782
+ * ```
783
+ */
784
+ function isFiniteNumber(value) {
785
+ return typeof value === "number" && Number.isFinite(value);
786
+ }
787
+ /**
788
+ * Builds the error of one bad `boldStyle` field.
789
+ *
790
+ * @param name - The style name.
791
+ * @param field - The field and its value, as the message shows them.
792
+ * @param fix - What to write instead.
793
+ * @returns The error to throw.
794
+ */
795
+ function boldStyleError(name, field, fix) {
796
+ return /* @__PURE__ */ new Error(`[game] Text style "${name}" has boldStyle${field}.\n ${fix}`);
797
+ }
798
+ /**
799
+ * Refuses a field of `boldStyle` that is not one of the seven, and a value a run cannot be drawn
800
+ * with: a size that is not a number above 0, a spacing or an outline width that is not finite, a
801
+ * font that is not a key, a colour that is not a number, a shadow that is no shadow.
802
+ *
803
+ * @param name - The style name, for the error.
804
+ * @param record - What the game wrote under `boldStyle`.
805
+ * @throws {Error} When a field is unknown or its value is bad.
806
+ */
807
+ function checkRunStyle(name, record) {
808
+ const unknown = Object.keys(record).find((key) => !RUN_STYLE_KEYS.includes(key));
809
+ if (unknown !== void 0) throw boldStyleError(name, `.${unknown}`, "Use only font, size, fill, letterSpacing, stroke, strokeWidth and shadow.");
810
+ const { font, size, fill, letterSpacing, stroke, strokeWidth, shadow } = record;
811
+ if (size !== void 0 && !(isFiniteNumber(size) && size > 0)) throw boldStyleError(name, `.size ${String(size)}`, "Use a size above 0.");
812
+ for (const [key, value] of [
813
+ ["letterSpacing", letterSpacing],
814
+ ["strokeWidth", strokeWidth],
815
+ ["fill", fill],
816
+ ["stroke", stroke]
817
+ ]) if (value !== void 0 && !isFiniteNumber(value)) throw boldStyleError(name, `.${key} ${String(value)}`, "Use a finite number.");
818
+ if (font !== void 0 && typeof font !== "string") throw boldStyleError(name, `.font ${String(font)}`, "Use the asset key of a font.");
819
+ if (shadow !== void 0 && readShadow(shadow) === void 0) throw boldStyleError(name, ".shadow", "Use { color, dx, dy, alpha? } of numbers.");
820
+ }
821
+ /**
822
+ * Checks the `boldStyle` of a style and stores the fields the game gave, the shadow with its
823
+ * alpha filled. A field left out stays out, so the stored look equals what the game wrote.
824
+ *
825
+ * @param name - The style name, for the error.
826
+ * @param input - What the game wrote under `boldStyle`, when it wrote one.
827
+ * @returns The look to store, or `undefined` for none.
828
+ * @throws {Error} When `boldStyle` is not a plain object, names another field, or has a bad value.
829
+ */
830
+ function runStyleOf(name, input) {
831
+ if (input === void 0) return void 0;
832
+ if (!isRecord(input)) throw boldStyleError(name, ` ${JSON.stringify(input) ?? String(input)}`, "Use an object of font, size, fill, letterSpacing, stroke, strokeWidth and shadow.");
833
+ checkRunStyle(name, input);
834
+ const look = input;
835
+ const stored = {};
836
+ if (look.font !== void 0) stored.font = look.font;
837
+ if (look.size !== void 0) stored.size = look.size;
838
+ if (look.fill !== void 0) stored.fill = look.fill;
839
+ if (look.letterSpacing !== void 0) stored.letterSpacing = look.letterSpacing;
840
+ if (look.stroke !== void 0) stored.stroke = look.stroke;
841
+ if (look.strokeWidth !== void 0) stored.strokeWidth = look.strokeWidth;
842
+ const shadow = shadowOf(look.shadow);
843
+ if (shadow !== void 0) stored.shadow = shadow;
844
+ return stored;
845
+ }
846
+ /**
847
+ * Refuses a first-line indent that is below 0 or not finite.
848
+ *
849
+ * @param name - The style name, for the error.
850
+ * @param textIndent - What the game wrote, when it wrote one.
851
+ * @throws {Error} When the indent is not a finite number of 0 or more.
852
+ */
853
+ function checkIndent(name, textIndent) {
854
+ if (textIndent === void 0 || isFiniteNumber(textIndent) && textIndent >= 0) return;
855
+ throw new Error(`[game] Text style "${name}" has textIndent ${String(textIndent)}.\n Use reference px of 0 or more, such as 20.`);
856
+ }
764
857
  /**
765
858
  * Fills the defaults of one style and refuses a wrap that is not a width, `"box"` or `"none"`,
766
- * a line height that is not a number above zero, and a balance that is not true or false. The
767
- * stored style carries `balance` only when it balances.
859
+ * a line height that is not a number above zero, a balance that is not true or false, a bad
860
+ * `boldStyle` and a bad `textIndent`. The stored style carries `balance` only when it balances,
861
+ * `boldStyle` only when the game gave one and `textIndent` only above 0.
768
862
  *
769
863
  * @param name - The style name, for the error.
770
864
  * @param input - What the game wrote.
@@ -772,12 +866,15 @@ function isLineHeight(lineHeight) {
772
866
  * @throws {Error} When `wrap` is a number that is not greater than zero, or another word.
773
867
  * @throws {Error} When `lineHeight` is not a finite number greater than zero.
774
868
  * @throws {Error} When `balance` is neither left out nor a boolean.
869
+ * @throws {Error} When `boldStyle` or `textIndent` is bad: see `runStyleOf` and `checkIndent`.
775
870
  */
776
871
  function normalizeStyle(name, input) {
777
872
  const wrap = input.wrap ?? "none";
778
873
  if (!isWrap(wrap)) throw new Error(`[game] Text style "${name}" has wrap ${wrap}.\n Use a width in reference px, "box" or "none".`);
779
874
  if (!isLineHeight(input.lineHeight)) throw new Error(`[game] Text style "${name}" has lineHeight ${input.lineHeight}.\n Use a multiple of size above 0, such as 1.2.`);
780
875
  if (input.balance !== void 0 && typeof input.balance !== "boolean") throw new Error(`[game] Text style "${name}" has balance ${String(input.balance)}.\n Use true or false.`);
876
+ checkIndent(name, input.textIndent);
877
+ const boldStyle = runStyleOf(name, input.boldStyle);
781
878
  const style = {
782
879
  font: input.font,
783
880
  bold: input.bold,
@@ -794,9 +891,45 @@ function normalizeStyle(name, input) {
794
891
  lineHeight: input.lineHeight
795
892
  };
796
893
  if (input.balance === true) style.balance = true;
894
+ if (boldStyle !== void 0) style.boldStyle = boldStyle;
895
+ if (input.textIndent !== void 0 && input.textIndent > 0) style.textIndent = input.textIndent;
797
896
  return style;
798
897
  }
799
898
  /**
899
+ * The look of the `<b>` runs of a style: the style with the glyph fields of its `boldStyle` laid
900
+ * over it. The bold font is `boldStyle.font`, else the style's own `bold`; the font, the italic,
901
+ * the line and the paragraph fields stay the style's. Built once per style, at start and on every
902
+ * hot swap, so a layout and a draw read it and build nothing.
903
+ *
904
+ * @param style - A stored style.
905
+ * @param bold - Its `boldStyle`.
906
+ * @returns The look a `<b>` run of the style measures and draws with.
907
+ * @example
908
+ * ```ts
909
+ * const row = builtInStyles({ body: "ui.fonts.text-medium", digits: "ui.font-digits" }).body;
910
+ *
911
+ * boldLookOf(row, { font: "ui.fonts.alt-bold", size: 16 }).bold; // "ui.fonts.alt-bold"
912
+ * boldLookOf(row, { font: "ui.fonts.alt-bold", size: 16 }).font; // "ui.fonts.text-medium"
913
+ * ```
914
+ */
915
+ function boldLookOf(style, bold) {
916
+ return {
917
+ font: style.font,
918
+ bold: bold.font ?? style.bold,
919
+ italic: style.italic,
920
+ size: bold.size ?? style.size,
921
+ fill: bold.fill ?? style.fill,
922
+ stroke: bold.stroke ?? style.stroke,
923
+ strokeWidth: bold.strokeWidth ?? style.strokeWidth,
924
+ letterSpacing: bold.letterSpacing ?? style.letterSpacing,
925
+ align: style.align,
926
+ wrap: style.wrap,
927
+ digits: style.digits,
928
+ shadow: shadowOf(bold.shadow) ?? style.shadow,
929
+ lineHeight: style.lineHeight
930
+ };
931
+ }
932
+ /**
800
933
  * Declares the text styles of a feature. The result goes under the `textStyles` key of the
801
934
  * feature description, and `text` reads it in `onStart`.
802
935
  *
@@ -805,6 +938,7 @@ function normalizeStyle(name, input) {
805
938
  * @throws {Error} When a style names a wrap that is not a width, `"box"` or `"none"`.
806
939
  * @throws {Error} When a style names a lineHeight that is not a number above 0.
807
940
  * @throws {Error} When a style names a balance that is not true or false.
941
+ * @throws {Error} When a style names a bad `boldStyle` or a `textIndent` below 0.
808
942
  * @example
809
943
  * ```ts
810
944
  * defineTextStyles({ "hud.digits": { font: "ui.font-digits", size: 40, fill: 0xffe082 } });
@@ -890,7 +1024,9 @@ function readStyle(name, value) {
890
1024
  digits: value.digits,
891
1025
  shadow: readShadow(value.shadow),
892
1026
  lineHeight: value.lineHeight,
893
- balance: value.balance
1027
+ balance: value.balance,
1028
+ boldStyle: readRunStyle(value.boldStyle),
1029
+ textIndent: value.textIndent
894
1030
  };
895
1031
  return normalizeStyle(name, {
896
1032
  ...input,
@@ -924,6 +1060,29 @@ function readShadow(value) {
924
1060
  };
925
1061
  }
926
1062
  /**
1063
+ * Reads the `boldStyle` of a registered style back: the seven fields of a plain record, the shadow
1064
+ * through `readShadow`. Anything else is handed on as it is, so `normalizeStyle` refuses it.
1065
+ *
1066
+ * @param value - The `boldStyle` field of a stored style.
1067
+ * @returns The look as a game writes it, or the value to refuse.
1068
+ * @example
1069
+ * ```ts
1070
+ * readRunStyle({ font: "ui.fonts.alt-bold", size: 16 }); // { font: "ui.fonts.alt-bold", size: 16 }
1071
+ * ```
1072
+ */
1073
+ function readRunStyle(value) {
1074
+ if (!isRecord(value)) return value;
1075
+ return pruned({
1076
+ font: value.font,
1077
+ size: value.size,
1078
+ fill: value.fill,
1079
+ letterSpacing: value.letterSpacing,
1080
+ stroke: value.stroke,
1081
+ strokeWidth: value.strokeWidth,
1082
+ shadow: readShadow(value.shadow)
1083
+ });
1084
+ }
1085
+ /**
927
1086
  * Drops the fields a style did not name, so the defaults win over an explicit `undefined`.
928
1087
  *
929
1088
  * @param fields - The optional fields of a style, as they were stored.
@@ -1738,4 +1897,4 @@ function drawnRect(pose, local) {
1738
1897
  };
1739
1898
  }
1740
1899
  //#endregion
1741
- export { Shape as $, Countdown as A, isLeaving as B, uiFor as C, isTextFormat as D, formatBound as E, defineTextStyles as F, rootPoseInto as G, parentOf as H, label as I, HudPart as J, rootPoseOf as K, readStyle as L, bind as M, builtInStyles as N, unitOf as O, defineTextFormats as P, Parent as Q, textFor as R, popup as S, defineStyle as T, poseUnder as U, localPoseOf as V, rootPointOf as W, Overlay as X, NineSlice as Y, OverlayLevel as Z, LocalWrite as _, fieldsLeftAlone as a, Exiting as at, UI_OWNER as b, namesFormat as c, Order as ct, visualOf as d, mut as dt, Sprite as et, visualRectOf as f, resource as ft, Escapable as g, DebugTrigger as h, tag as ht, drawnRect as i, sprite as it, Text as j, wholeValue as k, restValueOf as l, Tree as lt, Covered as m, systemsFor as mt, CONTENT as n, arcDefaults as nt, fitScaleOf as o, Layer as ot, Box as p, system as pt, Display as q, bindOf as r, componentsFor as rt, livePatch as s, Now as st, ANCHOR as t, Transform as tt, samePose as u, component as ut, Scroll as v, defineTokens as w, UiCounters as x, ScrollState as y, applyPose as z };
1900
+ 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 };
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-PsEr2KD-.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-B_3sVlRK.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-BJyIJf_X.mjs";
2
+ import { n as read, t as sources } from "./sources-JeKXYU_y.mjs";
3
3
  import { n as commands, t as run } from "./run-pCQlIaNP.mjs";
4
4
  import path from "node:path";
5
5
  import { createBrandConsole } from "@moku-labs/common/cli";
package/llms.txt CHANGED
@@ -599,7 +599,7 @@ A screen is a projection whose `view` returns JSX. The game's `tsconfig.json` se
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.
602
- - Text: `Text` component, `label({ text, style, at, anchor? })` for board text in a projection view, `defineTextStyles({ "hud.digits": { font, size, fill, bold?, italic?, stroke?, strokeWidth?, letterSpacing?, align?, wrap? (a width, "none" or "box": wrap at the laid-out width of its ui element; lines break between words, after a hyphen inside a word and at a soft hyphen U+00AD, drawn as `-` only where the line breaks), digits?, lineHeight? (the line as a multiple of size above 0, such as 1.28; glyphs sit in the middle of the line; absent: the font's own line), balance? (true evens a wrapped block of 2–6 lines at the narrowest width that keeps its number of lines, like CSS `text-wrap: balance`; never wider than the wrap; one line, more than 6 or a word wider than the wrap stay greedy) } })` under the feature's `textStyles` key. Tags inside a string: `<b>`, `<i>`, `<color=#rrggbb>`, `<icon=key>`, `\<`, `\n`. Built-in styles `body` and `digits` from config `fonts: { body: "ui.font-body", digits: "ui.font-digits" }`. `app.text.measure(content, style, width?)` gives the same numbers in a browser and in Bun. `app.text.replaceStyles(styles)` is the dev hot swap of a saved `defineTextStyles` value. A game's own number format: `defineTextFormats({ "pill.number": value => ({ content, style }) })` under the feature's `textFormats` key, named by the `bind` of `defineGame` (`GameTypes.textFormats`): `bind(Counter, "value", { format: "pill.number" })`. It takes the whole value, is pure over value and language, is not called while the whole value and the locale stand, and owns `Text.style`; a `Countdown` calls it every frame. `app.text.formatted(name, value)` answers `{ text, style }`, `undefined` for an unknown or built-in name and for a format that threw. A saved module exporting formats reloads the page.
602
+ - Text: `Text` component, `label({ text, style, at, anchor? })` for board text in a projection view, `defineTextStyles({ "hud.digits": { font, size, fill, bold?, italic?, stroke?, strokeWidth?, letterSpacing?, align?, wrap? (a width, "none" or "box": wrap at the laid-out width of its ui element; lines break between words, after a hyphen inside a word and at a soft hyphen U+00AD, drawn as `-` only where the line breaks), digits?, lineHeight? (the line as a multiple of size above 0, such as 1.28; glyphs sit in the middle of the line; absent: the font's own line), balance? (true evens a wrapped block of 2–6 lines at the narrowest width that keeps its number of lines, like CSS `text-wrap: balance`; never wider than the wrap; one line, more than 6 or a word wider than the wrap stay greedy), boldStyle? (a `TextRunStyle` of `font`, `size`, `fill`, `letterSpacing`, `stroke`, `strokeWidth`, `shadow`: the look of the `<b>` runs of the style, laid over it; `font` wins over `bold`), textIndent? (the indent of the first line in reference px, ≥ 0, like CSS `text-indent`; a line after `\n` starts at the edge; counted in the width) } })` under the feature's `textStyles` key. Tags inside a string: `<b>`, `<i>`, `<color=#rrggbb>`, `<span style=KEY>` (the glyph look of the style `KEY`: font, size, fill, spacing, outline, shadow, line; unquoted key; an unknown key draws in the text's own look and warns once), `<icon=key>`, `\<`, `\n`. Every piece of a line stands on one baseline, and a larger piece makes its line taller. Built-in styles `body` and `digits` from config `fonts: { body: "ui.font-body", digits: "ui.font-digits" }`. `app.text.measure(content, style, width?)` gives the same numbers in a browser and in Bun. `app.text.replaceStyles(styles)` is the dev hot swap of a saved `defineTextStyles` value. A game's own number format: `defineTextFormats({ "pill.number": value => ({ content, style }) })` under the feature's `textFormats` key, named by the `bind` of `defineGame` (`GameTypes.textFormats`): `bind(Counter, "value", { format: "pill.number" })`. It takes the whole value, is pure over value and language, is not called while the whole value and the locale stand, and owns `Text.style`; a `Countdown` calls it every frame. `app.text.formatted(name, value)` answers `{ text, style }`, `undefined` for an unknown or built-in name and for a format that threw. A saved module exporting formats reloads the page.
603
603
  - Animation is data: `defineAnimation(id, { slots: { name: type<Anim.Target>() }, build: (slots, { at }) => Step })`. Steps: `sequence(...)`, `parallel(...)`, `stagger(items, ms, item => Step)`, `tween(target, Component, to, { ms, ease?, delayMs?, additive?, space?, reduced? })`, `set(target, Component, patch)`, `wait(ms)`, `mark(name)`, `frames(target, { keys, fps, loop? })`, `sfx(key, { bus? })`, `haptic(kind)`, `use(animation, slots, tools?)`, `spawn` (a temporary entity, flying coins, that the timeline despawns when it ends; see the anim README). `Frames({ keys, fps, loop, playing })` is a component that walks a sprite through its textures for the entity's whole life. A target is `{ projection, key }` or an entity. A timeline resolves each `{ projection, key }` target once, when it starts: every step writes the view that held the key then, also after a commit removed it and while its exit plays, until it despawns; a view spawned again under the same key is not followed, and a key nothing held at the start is looked up at its step. `reduced: "keep"` (on a `tween` step, `transition` and `loop` of `defineMotion`, `TweenOptions`, `RestOptions`) plays a track as written under reduced motion, a fade for one; the default `"cut"` lands it at once or holds a loop on its first key. A node plays it with `await fx(play(animation, slots))`; in fast mode it finishes at once. `defineMotion({ states, transition?, on: { enter?, exit?, change? }, when? })` builds the enter, exit and change hooks for a projection or the `motion` prop of a tag; `when: "change"` plays enter and exit only for a commit, so an element that comes or goes with its screen stands at rest and leaves without a motion (default `"always"`). Events `anim:mark` `{ animation, mark }` and `anim:finished` `{ animation }`. `app.anim.replace(definition)` is the dev hot swap: the next `play` builds the new tree. A system cannot `require` a plugin, so it plays through the resource `AnimPlayer`: `res(AnimPlayer).play(animation, slots)` returns the same handle as `app.anim.play`, and the registered animation of `animation.id` wins, so a hot swap reaches the system. Play on a change, never every frame; from phase `input` the tree moves in `animate` of the same frame. Before `anim` starts it throws `[game] AnimPlayer is not ready: anim has not started.` Config `maxTracks: 2000`.
604
604
  - A `tween` step takes `segments` and `repeat` as `ViewHandle.tween` does: `tween(chest, Transform, { y: 0, scale: 0 }, { ms: 2400, additive: true, repeat: "forever", segments: [{ at: 0.08, ease: "out", to: { y: -14, scale: 0.06 } }, { at: 1, to: { y: 0, scale: 0 } }] })`. Segments walk over `ms` on one clock, `to` is where the last one ends, an additive walk names offsets; a number counts the extra runs. A definition error throws for empty segments, an `at` outside 0..1 or out of order, a last segment before 1, a bad repeat, and a `sequence` step after one that never ends. A forever step ends only by cancel or finish (a finish and a fast world land it on its start pose), does not play under reduced motion `"cut"`, writes nothing while its view is unseen, and lets the clock idle; a system plays it once through `AnimPlayer` and keeps the handle.
605
605
  - Audio is opt-in: `plugins: [...screen, audioPlugin]`. `fx(sfx("orders.complete"))` resolves when the sound started. `await fx(music("board.theme"))` cross-fades; `music(null)` fades out; a scene's `music` key switches the track on `scenes:changed`. Buses `master`, `music`, `sfx`. Volumes come from the committed player: config `volumes: player => (player as Player).settings.audio`, applied on every `model:committed`. `app.audio`: `setVolume(bus, value)`, `volume(bus)`, `mute(bus, on)`, `muted(bus)`, `unlocked()`, `journal()` (the last started sounds, empty unless config `journal` is above 0). Config: `buses: { master: 1, music: 0.6, sfx: 1 }`, `musicFadeMs: 600`, `volumes`, `context`, `journal: 0`, `music: "decode" | "stream"` default `"decode"` (gapless buffer; `"stream"` is an `<audio>` element, less memory, a gap at every loop), `session: "ambient" | "playback" | "auto"` default `"ambient"` (iOS only: ambient mixes with other apps and obeys the silent switch). The context is asked to run at start: where the shell lets audio play (a native webview with the gesture requirement off) `unlocked()` is true with no touch; a browser that wants a gesture unlocks on the first `pointerdown` or `touchend`. iOS: after a pause the touch unlock stays armed until the context really runs (WebKit holds `resume()` pending after a screenshot or Control Center); on a return from the background (WebKit with `navigator.audioSession`, a touch screen, `session` not `"playback"`) the plugin renews its context one second later or at the first touch: session `"auto"`, old context closed, `session` again, a new context from `config.context` (called again, so return a new context each call) at the same volumes, decoded buffers kept, the scene's music restarted, sounds in flight dropped. Without `audio` every `sfx` and `music` effect resolves `undefined` at once, so the same node runs in a game with no sound. Named sounds: `sfx(key, { bus?, id?, fadeMs? })` with an `id` plays through its own gain, and the next sound with the same `id` fades the old one out over `fadeMs`, else config `sfxFadeMs` (default `120`, real milliseconds); `fx.start(stopSfx(id, { fadeMs? }))` and `app.audio.stop(id, { fadeMs? })` fade it out and end it (`fadeMs: 0` cuts it); an `id` nothing plays under changes nothing, and a sound of that `id` still decoding never starts. Without `id` an `sfx` plays to its end as before.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/game",
3
- "version": "0.15.103",
3
+ "version": "0.15.104",
4
4
  "description": "2D puzzle game engine on TypeScript and PixiJS, built on @moku-labs/core.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -163,7 +163,7 @@
163
163
  "@moku-labs/common": "0.3.11",
164
164
  "@moku-labs/core": "1.7.6",
165
165
  "@moku-labs/native": "0.3.15",
166
- "@moku-labs/system": "0.3.7",
166
+ "@moku-labs/system": "0.3.8",
167
167
  "@types/bun": "1.4.2",
168
168
  "@vitest/coverage-istanbul": "4.0.18",
169
169
  "eslint": "9.39.3",