@moku-labs/game 0.2.0 → 0.3.0

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 (35) hide show
  1. package/README.md +2 -0
  2. package/dist/assets.d.mts +181 -22
  3. package/dist/assets.mjs +1186 -160
  4. package/dist/{commands-C0BljsM5.d.mts → commands-DYO22lzi.d.mts} +22 -5
  5. package/dist/control.d.mts +3 -3
  6. package/dist/control.mjs +3 -3
  7. package/dist/{define-CjP_4H0G.d.mts → define-BKWjWgyQ.d.mts} +1 -1
  8. package/dist/dev-CQYJPmcD.mjs +1183 -0
  9. package/dist/flatten-BkXuscAV.mjs +100 -0
  10. package/dist/index.d.mts +85 -31
  11. package/dist/index.mjs +3208 -490
  12. package/dist/{session-DmAxY6Ll.mjs → input-CK4nxBO1.mjs} +41 -12
  13. package/dist/inspect.d.mts +32 -9
  14. package/dist/inspect.mjs +2 -2
  15. package/dist/jsx-dev-runtime.d.mts +1 -1
  16. package/dist/jsx-dev-runtime.mjs +1 -1
  17. package/dist/jsx-runtime.d.mts +1 -1
  18. package/dist/jsx-runtime.mjs +1 -1
  19. package/dist/{run-tlcn1w7y.mjs → run-BfuMLahc.mjs} +489 -213
  20. package/dist/{runtime-Bn5TXNxP.d.mts → runtime-Bhu442L8.d.mts} +1 -1
  21. package/dist/{runtime-DRlwxkIv.mjs → runtime-CBZgWgzx.mjs} +1 -57
  22. package/dist/{sources-BooL2MsX.mjs → sources-C1uGjz4l.mjs} +198 -21
  23. package/dist/testing.d.mts +5 -5
  24. package/dist/testing.mjs +5 -4
  25. package/dist/{types-CxZy7Pi4.d.mts → types-BnWH-75b.d.mts} +95 -21
  26. package/dist/{types-CqkrEY06.d.mts → types-CVUHPvMB.d.mts} +5 -434
  27. package/dist/{types-DmhTHRVW.d.mts → types-DtmFVCHf.d.mts} +1 -1
  28. package/dist/{types-BZ1OLf24.d.mts → types-Dy1xB68L.d.mts} +2318 -1169
  29. package/dist/{types-X9jXjka3.d.mts → types-VErbiEXy.d.mts} +867 -198
  30. package/dist/{visual-NPrDkvUk.mjs → visual-DUvvPPCt.mjs} +51 -1
  31. package/llms.txt +5 -5
  32. package/package.json +5 -5
  33. package/dist/component-DGg5DqKK.mjs +0 -44
  34. package/dist/dev-CcwFrwok.mjs +0 -413
  35. package/dist/types-C47fKNcn.d.mts +0 -695
@@ -1,439 +1,9 @@
1
- import { A as TrackSegment, At as Json, E as NumericFields, F as ComponentHandle, I as ComponentType, M as AnyComponent, P as AnyComponentValue, R as Entity, St as Api, T as MotionHandle, _t as TypeTag, h as Api$2, k as TrackOptions, nn as Require, q as Api$1, t as Api$3, x as Ease } from "./types-BZ1OLf24.mjs";
2
- import { o as Events$1, t as Api$4 } from "./types-C47fKNcn.mjs";
3
- import { F as Events$2, H as InputApi, I as I18nApi, L as Message, c as UiNode, i as Finding, n as ElementChange, o as JsxState, r as ElementMotion, v as StylesState } from "./types-X9jXjka3.mjs";
1
+ import { $ as Ease, I as AnyComponentValue, Kt as Json, L as ComponentHandle, Nt as TypeTag, P as AnyComponent, Rt as Api, V as Entity, ct as TrackSegment, it as NumericFields, k as Api$2, m as Api$3, rt as MotionHandle, st as TrackOptions, ut as Api$1, vn as Require, z as ComponentType } from "./types-Dy1xB68L.mjs";
2
+ import { D as TextApi, H as InputApi, I as I18nApi, c as UiNode, i as Finding, n as ElementChange, o as JsxState, r as ElementMotion, v as StylesState } from "./types-VErbiEXy.mjs";
4
3
  import { Log } from "@moku-labs/common/browser";
5
4
  import { PluginCtx } from "@moku-labs/core";
6
5
  import { Node, Yoga } from "yoga-layout/load";
7
6
 
8
- //#region src/plugins/text/types.d.ts
9
- declare namespace types_d_exports$2 {
10
- export { AdvanceTable, BundleLoaded, BundleUnloaded, Config$2 as Config, Deps$2 as Deps, DrawnLabel, IconRun, KernelSlice$2 as KernelSlice, LayoutOptions, Line, LocaleChanged, Point, Run, SeenText, Size, State$2 as State, TextAlign, TextApi, TextBind, TextCtx, TextLayout, TextRun, TextShadow, TextStyle, TextStyleInput, TextStyles, TextValue, TextWrap, Warn };
11
- }
12
- /**
13
- * A point in reference units: where a label sits, and which point of the block sits there.
14
- *
15
- * @example
16
- * ```ts
17
- * const anchor: Point = { x: 0.5, y: 0.5 };
18
- * ```
19
- */
20
- type Point = {
21
- x: number;
22
- y: number;
23
- };
24
- /**
25
- * The size of a measured block, in reference pixels.
26
- *
27
- * @example
28
- * ```ts
29
- * const size: Size = { width: 57.6, height: 38.4 };
30
- * ```
31
- */
32
- type Size = {
33
- width: number;
34
- height: number;
35
- };
36
- /**
37
- * Which numeric component field a label shows. The component is named, not imported: a HUD is
38
- * written before the game's components are in scope.
39
- *
40
- * @example
41
- * ```ts
42
- * const bind: TextBind = { component: "Counter", field: "value" };
43
- * ```
44
- */
45
- type TextBind = {
46
- component: string;
47
- field: string;
48
- };
49
- /**
50
- * What the `Text` component holds. `resolved` is engine-owned: a game writes `content`, `style`,
51
- * `bind`, `anchor` and `alpha`, and reads `resolved`. `alpha` fades every run, shadow and icon of
52
- * the block together, 1 by default; a change is written in place and a tween can drive it.
53
- *
54
- * @example
55
- * ```ts
56
- * const value: TextValue = {
57
- * content: "+5", style: "body", bind: undefined, anchor: { x: 0.5, y: 0.5 }, alpha: 1,
58
- * resolved: "+5"
59
- * };
60
- * // The hint of an empty name field, at half alpha.
61
- * const hint: TextValue = { ...value, content: "Your name", alpha: 0.5, resolved: "Your name" };
62
- * ```
63
- */
64
- type TextValue = {
65
- content: string | Message;
66
- style: string;
67
- bind: TextBind | undefined;
68
- anchor: Point;
69
- alpha: number;
70
- resolved: string;
71
- };
72
- /**
73
- * Where the lines of a block sit inside the widest of them.
74
- *
75
- * @example
76
- * ```ts
77
- * const align: TextAlign = "center";
78
- * ```
79
- */
80
- type TextAlign = "left" | "center" | "right";
81
- /**
82
- * The wrap width of a style in reference pixels, or `"none"` for one line per `\n` segment.
83
- *
84
- * @example
85
- * ```ts
86
- * const wrap: TextWrap = 480;
87
- * ```
88
- */
89
- type TextWrap = number | "none";
90
- /**
91
- * The drop shadow of a style as the plugin stores it: a copy of every glyph run in `color`, at
92
- * `alpha`, moved by `dx` and `dy` reference pixels.
93
- *
94
- * @example
95
- * ```ts
96
- * const shadow: TextShadow = { color: 0x5b3a1e, dx: 0, dy: 4, alpha: 1 };
97
- * ```
98
- */
99
- type TextShadow = {
100
- color: number;
101
- dx: number;
102
- dy: number;
103
- alpha: number;
104
- };
105
- /**
106
- * One style as a game writes it: the font and the size are required, the rest has defaults.
107
- *
108
- * @example
109
- * ```ts
110
- * // A popup title: cream display glyphs over a brown shadow 4 px down.
111
- * const title: TextStyleInput = {
112
- * font: "ui.font-display", size: 56, fill: 0xfff3d6, shadow: { color: 0x5b3a1e, dx: 0, dy: 4 }
113
- * };
114
- *
115
- * defineTextStyles({ "popup.title": title }).map["popup.title"]?.shadow;
116
- * // { color: 0x5b3a1e, dx: 0, dy: 4, alpha: 1 }
117
- * ```
118
- */
119
- type TextStyleInput = {
120
- font: string;
121
- bold?: string;
122
- italic?: string;
123
- size: number;
124
- fill: number; /** The outline colour. Drawn only when `strokeWidth` is above 0. */
125
- stroke?: number;
126
- /**
127
- * The outline width in reference px: 8 copies of each glyph run on a circle this wide (12 from 6
128
- * on), tinted `stroke`. 0 draws none. It never changes what `measure` answers.
129
- */
130
- strokeWidth?: number;
131
- letterSpacing?: number;
132
- align?: TextAlign;
133
- wrap?: TextWrap;
134
- digits?: boolean;
135
- /**
136
- * A drop shadow under every glyph run, in reference px at the style size. `alpha` is 1 when
137
- * left out. It never changes what `measure` answers.
138
- */
139
- shadow?: {
140
- color: number;
141
- dx: number;
142
- dy: number;
143
- alpha?: number;
144
- };
145
- };
146
- /**
147
- * One style as the plugin stores it: every field filled, `bold` and `italic` only when the game
148
- * shipped those MSDF fonts, `shadow` only when the style has one.
149
- *
150
- * @example
151
- * ```ts
152
- * const style: TextStyle = {
153
- * font: "ui.font-body", bold: undefined, italic: undefined, size: 32, fill: 0xffffff,
154
- * stroke: 0x000000, strokeWidth: 0, letterSpacing: 0, align: "left", wrap: "none",
155
- * digits: false, shadow: undefined
156
- * };
157
- * ```
158
- */
159
- type TextStyle = {
160
- font: string;
161
- bold: string | undefined;
162
- italic: string | undefined;
163
- size: number;
164
- fill: number;
165
- stroke: number;
166
- strokeWidth: number;
167
- letterSpacing: number;
168
- align: TextAlign;
169
- wrap: TextWrap;
170
- digits: boolean;
171
- shadow: TextShadow | undefined;
172
- };
173
- /**
174
- * What `defineTextStyles` returns and a feature registers under its `textStyles` key. Structural
175
- * on purpose: `flow` carries the map, `text` reads it.
176
- *
177
- * @example
178
- * ```ts
179
- * const styles: TextStyles = { kind: "textStyles", map: { "hud.title": bodyStyle } };
180
- * ```
181
- */
182
- type TextStyles = {
183
- readonly kind: "textStyles";
184
- readonly map: Record<string, TextStyle>;
185
- };
186
- /**
187
- * The advances of one font at the size the `.fnt` was exported with. Widths scale by
188
- * `style.size / size`; kerning pairs are ignored.
189
- *
190
- * @example
191
- * ```ts
192
- * const table: AdvanceTable = { size: 32, lineHeight: 40, advances: new Map([["1", 18]]) };
193
- * ```
194
- */
195
- type AdvanceTable = {
196
- size: number;
197
- lineHeight: number;
198
- advances: Map<string, number>;
199
- };
200
- /**
201
- * One run of glyphs: the text and the flags every glyph in it shares.
202
- *
203
- * @example
204
- * ```ts
205
- * const run: TextRun = { kind: "text", text: "+5", bold: true, italic: false, color: 0xffe082 };
206
- * ```
207
- */
208
- type TextRun = {
209
- kind: "text";
210
- text: string;
211
- bold: boolean;
212
- italic: boolean;
213
- color: number | undefined;
214
- };
215
- /**
216
- * One inline icon: an asset key drawn square at the line height.
217
- *
218
- * @example
219
- * ```ts
220
- * const run: IconRun = { kind: "icon", key: "hud.coin" };
221
- * ```
222
- */
223
- type IconRun = {
224
- kind: "icon";
225
- key: string;
226
- };
227
- /**
228
- * A piece of a line: glyphs or one inline icon.
229
- *
230
- * @example
231
- * ```ts
232
- * const runs: Run[] = [{ kind: "icon", key: "hud.coin" }];
233
- * ```
234
- */
235
- type Run = TextRun | IconRun;
236
- /**
237
- * One laid-out line and how wide it is.
238
- *
239
- * @example
240
- * ```ts
241
- * const line: Line = { runs: [{ kind: "icon", key: "hud.coin" }], width: 38.4 };
242
- * ```
243
- */
244
- type Line = {
245
- runs: Run[];
246
- width: number;
247
- };
248
- /**
249
- * A laid-out block: its lines and the size `measure` answers with.
250
- *
251
- * @example
252
- * ```ts
253
- * const layout: TextLayout = { lines: [], width: 0, height: 0 };
254
- * ```
255
- */
256
- type TextLayout = {
257
- lines: Line[];
258
- width: number;
259
- height: number;
260
- };
261
- /**
262
- * What one label container was last filled from: the style object and the laid-out block. An
263
- * update with the same style object, the same anchor and the same lines and runs writes the new
264
- * text and positions into the objects already there.
265
- */
266
- type DrawnLabel = {
267
- style: TextStyle;
268
- layout: TextLayout;
269
- };
270
- /**
271
- * A dev warning that is written once per key. Pure modules take it as an argument, so nothing
272
- * below the plugin context reaches the log itself.
273
- *
274
- * @example
275
- * ```ts
276
- * const warn: Warn = (key, message) => seen.has(key) || log.warn(message);
277
- * ```
278
- */
279
- type Warn = (key: string, message: string, data?: Record<string, unknown>) => void;
280
- /**
281
- * What the pure layout needs next to the runs, the style and the tables.
282
- *
283
- * @example
284
- * ```ts
285
- * const options: LayoutOptions = { warn: () => undefined };
286
- * ```
287
- */
288
- type LayoutOptions = {
289
- warn: Warn;
290
- };
291
- /**
292
- * What was resolved for one entity last, so the frame step knows whether anything moved.
293
- *
294
- * @example
295
- * ```ts
296
- * const seen: SeenText = { content: "+5", style: "body", bind: undefined, locale: "ru" };
297
- * ```
298
- */
299
- type SeenText = {
300
- content: unknown;
301
- style: string;
302
- bind: string | undefined;
303
- locale: string;
304
- };
305
- /**
306
- * text plugin config.
307
- *
308
- * @example
309
- * ```ts
310
- * createApp({ pluginConfigs: { text: { fonts: { body: "ui.body", digits: "ui.digits" } } } });
311
- * ```
312
- */
313
- type Config$2 = {
314
- /** The two fonts every game ships in its boot bundle. They back the built-in styles. */fonts: {
315
- body: string;
316
- digits: string;
317
- };
318
- };
319
- /**
320
- * text plugin state.
321
- */
322
- type State$2 = {
323
- /** Built-in styles first, then the styles of every feature in feature order. */styles: Map<string, TextStyle>; /** Style name to the feature that brought it, for the duplicate error. */
324
- styleOwner: Map<string, string>; /** The config fonts plus every `font`, `bold` and `italic` of every style. */
325
- fontKeys: Set<string>; /** The parsed advance table per font key, filled when `assets` has the font. */
326
- tables: Map<string, AdvanceTable>; /** The font keys handed to `renderer.sync.fonts.install`. */
327
- installed: Set<string>; /** What was resolved for an entity last. */
328
- seen: Map<Entity, SeenText>; /** `bind.component` to its world type; `undefined` after the one warning. */
329
- bindTypes: Map<string, AnyComponent | undefined>; /** The measured size of every live label, for `ui`. */
330
- measured: Map<Entity, Size>; /** Layout per `style + resolved`, oldest dropped first. */
331
- cache: Map<string, TextLayout>; /** What every live label container was last filled from, by container. */
332
- drawn: WeakMap<object, DrawnLabel>; /** Entities to re-resolve in the next layout phase. */
333
- dirty: Set<Entity>; /** Warning keys already written, so a style, a tag, a glyph or a font warns once. */
334
- warned: Set<string>; /** The system, the two world hooks and the display adapter. */
335
- removers: Array<() => void>;
336
- };
337
- /**
338
- * text plugin API, `app.text`. Two questions: how big a piece of text is, and which styles the
339
- * game registered. Everything else happens in the frame.
340
- *
341
- * @example
342
- * ```ts
343
- * app.text.measure("120", "digits"); // { width: 57.6, height: 38.4 }
344
- * app.text.styles(); // ["body", "digits"]
345
- * ```
346
- */
347
- type TextApi = {
348
- /**
349
- * The size of a piece of text in reference pixels, from the advance table of the style's font.
350
- * A `Message` is formatted in the current locale first. Never touches a canvas, so the answer
351
- * is the same in a browser and in plain Bun. Cached per style and resolved string.
352
- *
353
- * @param content - A plain string, or what `tr` returned.
354
- * @param style - A registered style name. An unknown one warns once and measures as `body`.
355
- * @returns The width and height of the block.
356
- * @example
357
- * ```ts
358
- * // `ui.layout` asks once per invalidation, from the Yoga measure function of a text element.
359
- * const text = ctx.require(textPlugin);
360
- *
361
- * text.measure("120", "digits"); // { width: 57.6, height: 38.4 } on the 0.6 em fallback
362
- * ```
363
- */
364
- measure(content: string | Message, style: string): Size;
365
- /**
366
- * Whether the font of a style has a glyph for one character, the lookup Pixi draws by. A
367
- * character its font lacks is drawn as nothing and `measure` counts it 0 wide. While the font is
368
- * not loaded every character counts, as the 0.6 em fallback measures it. An unknown style warns
369
- * once and looks up `body`.
370
- *
371
- * @param char - One character, a whole code point.
372
- * @param style - A registered style name.
373
- * @returns False only for a character a loaded font has no glyph for.
374
- * @example
375
- * ```ts
376
- * // `ui` measures the caret of a text field over the characters the font draws.
377
- * const text = ctx.require(textPlugin);
378
- *
379
- * text.hasGlyph("A", "body"); // true
380
- * text.hasGlyph("😀", "body"); // false once the body font is loaded: it has no emoji glyph
381
- * ```
382
- */
383
- hasGlyph(char: string, style: string): boolean;
384
- /**
385
- * The registered style names: the two built-ins first, then the styles of every feature in
386
- * feature order.
387
- *
388
- * @returns A frozen list of style names.
389
- * @example
390
- * ```ts
391
- * // A dev overlay lists what a game may write in a `style` prop.
392
- * app.text.styles(); // ["body", "digits", "hud.digits"]
393
- * ```
394
- */
395
- styles(): readonly string[];
396
- };
397
- /**
398
- * Resolved dependency APIs.
399
- */
400
- type Deps$2 = {
401
- time: Api;
402
- flow: Api$1;
403
- world: Api$2;
404
- renderer: Api$3;
405
- assets: Api$4;
406
- i18n: I18nApi;
407
- };
408
- /**
409
- * What the kernel context offers before the deps are attached.
410
- *
411
- * `text` owns no event, so `emit` is the kernel's and never called here.
412
- */
413
- type KernelSlice$2 = PluginCtx<Config$2, State$2> & {
414
- readonly global: object;
415
- readonly log: Log.LogApi;
416
- readonly require: Require;
417
- };
418
- /**
419
- * Domain context shared by the files of the plugin: the kernel slice plus the resolved deps.
420
- */
421
- type TextCtx = KernelSlice$2 & {
422
- readonly deps: Deps$2;
423
- };
424
- /**
425
- * Payload of the `assets:bundle-loaded` hook: a bundle landed, so a font may be readable now.
426
- */
427
- type BundleLoaded = Events$1["assets:bundle-loaded"];
428
- /**
429
- * Payload of the `assets:bundle-unloaded` hook: `keys` names the assets that left.
430
- */
431
- type BundleUnloaded = Events$1["assets:bundle-unloaded"];
432
- /**
433
- * Payload of the `i18n:locale-changed` hook: every message has to be resolved again.
434
- */
435
- type LocaleChanged = Events$2["i18n:locale-changed"];
436
- //#endregion
437
7
  //#region src/plugins/ui/layout/types.d.ts
438
8
  /**
439
9
  * layout module state. `nodes` is attach minus detach: Yoga 3.2.1 has no instance counter.
@@ -598,7 +168,8 @@ type UiApi = {
598
168
  * The live screen as plain data: every root in layer order, every element in child order, with
599
169
  * its rect in root coordinates, its resolved style and its seven state flags. A rect is natural:
600
170
  * under a `fit: "contain"` element it is the rect before that scale, and the fitted element
601
- * adds `fitScale`. Works headless.
171
+ * adds `fitScale`. A windowed scroll adds `window`, and its content lists the live rows only.
172
+ * Works headless.
602
173
  *
603
174
  * @returns The root node; several roots come back under one `screen` node.
604
175
  * @example
@@ -1731,4 +1302,4 @@ type AnimCtx = KernelSlice & {
1731
1302
  readonly deps: Deps;
1732
1303
  };
1733
1304
  //#endregion
1734
- export { UiApi as A, spawned as C, wait as D, use as E, TextApi as F, TextStyleInput as I, TextStyles as L, Config$2 as M, Point as N, Config$1 as O, State$2 as P, TextValue as R, spawn as S, tween as T, parallel as _, State as a, set as b, HapticKind as c, HAPTIC_KINDS as d, defineAnimation as f, mark as g, haptic as h, MotionKeyframe as i, types_d_exports$1 as j, State$1 as k, SfxDescriptor as l, frames as m, Config as n, Target as o, external as p, FramesValue as r, types_d_exports as s, AnimApi as t, Step as u, play as v, stagger as w, sfx as x, sequence as y, types_d_exports$2 as z };
1305
+ export { UiApi as A, spawned as C, wait as D, use as E, Config$1 as O, spawn as S, tween as T, parallel as _, State as a, set as b, HapticKind as c, HAPTIC_KINDS as d, defineAnimation as f, mark as g, haptic as h, MotionKeyframe as i, types_d_exports$1 as j, State$1 as k, SfxDescriptor as l, frames as m, Config as n, Target as o, external as p, FramesValue as r, types_d_exports as s, AnimApi as t, Step as u, play as v, stagger as w, sfx as x, sequence as y };
@@ -1,4 +1,4 @@
1
- import { At as Json, Ht as RngState, St as Api, ft as FlowState, ht as RouteStep, pt as JournalEntry, q as Api$1, xt as Answer, zt as Snapshot } from "./types-BZ1OLf24.mjs";
1
+ import { At as JournalEntry, Kt as Json, Lt as Answer, Rt as Api, in as RngState, jt as RouteStep, kt as FlowState, tn as Snapshot, ut as Api$1 } from "./types-Dy1xB68L.mjs";
2
2
  import { Log } from "@moku-labs/common/browser";
3
3
 
4
4
  //#region src/plugins/flow/headless.d.ts