@moku-labs/game 0.15.102 → 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 (34) hide show
  1. package/README.md +1 -1
  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-C2JXDkUV.d.mts → commands-CYXJyv3w.d.mts} +5 -5
  9. package/dist/control.d.mts +4 -4
  10. package/dist/{define-DNF9A0ce.d.mts → define-Cq8Df0_C.d.mts} +2 -2
  11. package/dist/{headless-CEG1oR5D.d.mts → headless-DRiVyv9T.d.mts} +1 -1
  12. package/dist/{index-DtbI1op8.d.mts → index-BIofySGI.d.mts} +37 -7
  13. package/dist/index.d.mts +5 -5
  14. package/dist/index.mjs +3 -3
  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-CcHPrVBm.d.mts → runtime-DuAOUZ-z.d.mts} +1 -1
  20. package/dist/{sources-BJyIJf_X.mjs → sources-JeKXYU_y.mjs} +1 -1
  21. package/dist/{src-CilP057R.mjs → src-BJBCs69P.mjs} +1553 -467
  22. package/dist/testing.d.mts +4 -4
  23. package/dist/testing.mjs +1 -1
  24. package/dist/{types-IJXSUFJa.d.mts → types-BT8kKhan.d.mts} +4 -4
  25. package/dist/{types-C1B7-x7p.d.mts → types-BlXBiM8d.d.mts} +191 -36
  26. package/dist/{types-Cdzw3as5.d.mts → types-C1-VCBhy.d.mts} +23 -5
  27. package/dist/{types-C612npUH.d.mts → types-Ca90Yo7d.d.mts} +2 -2
  28. package/dist/{types-Ce5W0gZe.d.mts → types-CayM8xne.d.mts} +1 -1
  29. package/dist/{visual-BoSpJLWP.d.mts → visual-B_3sVlRK.d.mts} +6 -6
  30. package/dist/{visual-DhqD6W3v.mjs → visual-fyUJwUJf.mjs} +163 -4
  31. package/dist/visual.d.mts +1 -1
  32. package/dist/visual.mjs +1 -1
  33. package/llms.txt +3 -3
  34. package/package.json +2 -2
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { i as systemSource, r as MAX_TIMER_MS, t as memory } from "./memory-DeD9wis6.mjs";
3
3
  import { a as finishDrafts, i as enableDraftPatches, n as deepFreeze$1, o as openDrafts, r as dropDrafts } from "./drafts-BawpSaVp.mjs";
4
4
  import { _ as compact, c as collectFlows, d as findNode, f as framePath, g as slotNames, h as restlessCapOf, i as servePaused, l as describeGraph, m as isRestCheckpoint, n as captureFrame, o as epochOf, p as graphHash, r as serveCaptures, s as pageNow$1, t as cancelCaptures, v as pushEntry } from "./capture-BtS6_oWr.mjs";
5
- import { $ as Shape, A as Countdown, B as isLeaving, C as uiFor, D as isTextFormat, E as formatBound, G as rootPoseInto, H as parentOf$1, J as HudPart, K as rootPoseOf, L as readStyle, N as builtInStyles, O as unitOf, Q as Parent, R as textFor, U as poseUnder, V as localPoseOf, W as rootPointOf, X as Overlay, Y as NineSlice, Z as OverlayLevel, _ as LocalWrite, a as fieldsLeftAlone, at as Exiting, b as UI_OWNER, c as namesFormat, ct as Order, d as visualOf$1, et as Sprite, f as visualRectOf, ft as resource, g as Escapable, h as DebugTrigger, ht as tag, i as drawnRect, j as Text, k as wholeValue, l as restValueOf, lt as Tree, m as Covered, mt as systemsFor, n as CONTENT$1, nt as arcDefaults, o as fitScaleOf, ot as Layer, p as Box, pt as system, q as Display, r as bindOf, rt as componentsFor, s as livePatch, st as Now, tt as Transform, u as samePose, ut as component, v as Scroll, x as UiCounters, y as ScrollState, z as applyPose } from "./visual-DhqD6W3v.mjs";
5
+ import { $ as Parent, A as Countdown, B as applyPose, C as uiFor, D as isTextFormat, E as formatBound, G as rootPointOf, H as localPoseOf, J as Display, K as rootPoseInto, N as boldLookOf, O as unitOf, P as builtInStyles, Q as OverlayLevel, R as readStyle, U as parentOf$1, V as isLeaving, W as poseUnder, X as NineSlice, Y as HudPart, Z as Overlay, _ as LocalWrite, a as fieldsLeftAlone, b as UI_OWNER, c as namesFormat, ct as Now, d as visualOf$1, dt as component, et as Shape, f as visualRectOf, g as Escapable, gt as tag, h as DebugTrigger, ht as systemsFor, i as drawnRect, it as componentsFor, j as Text, k as wholeValue, l as restValueOf, lt as Order, m as Covered, mt as system, n as CONTENT$1, nt as Transform, o as fitScaleOf, ot as Exiting, p as Box, pt as resource, q as rootPoseOf, r as bindOf, rt as arcDefaults, s as livePatch, st as Layer, tt as Sprite, u as samePose, ut as Tree, v as Scroll, x as UiCounters, y as ScrollState, z as textFor } from "./visual-fyUJwUJf.mjs";
6
6
  import { a as isDev } from "./dev-BNndV-hU.mjs";
7
7
  import { n as isComponentDefinition } from "./component-DGg5DqKK.mjs";
8
8
  import { n as flatten } from "./flatten-nUX9PpGo.mjs";
@@ -27052,7 +27052,7 @@ const MAX_RADIUS = 30;
27052
27052
  /** The radius of a kernel, in sigmas. */
27053
27053
  const RADIUS_SIGMAS = 3;
27054
27054
  /** The widest blur, in texels of the shot: its radius is the widest the uniform holds. */
27055
- const MAX_SIGMA = MAX_RADIUS / RADIUS_SIGMAS;
27055
+ const MAX_SIGMA$1 = MAX_RADIUS / RADIUS_SIGMAS;
27056
27056
  /** Taps a side of an exact box: each averages two source pixels, at 2 texels from the next. */
27057
27057
  const BOX_TAPS = 2;
27058
27058
  /** Taps a side of any other hop, spread evenly over it. */
@@ -27142,7 +27142,7 @@ function gaussianTaps(sigma) {
27142
27142
  * ```
27143
27143
  */
27144
27144
  function sigmaOf(blur, width, frameWidth) {
27145
- return frameWidth > 0 ? Math.min(blur * width / frameWidth, MAX_SIGMA) : 0;
27145
+ return frameWidth > 0 ? Math.min(blur * width / frameWidth, MAX_SIGMA$1) : 0;
27146
27146
  }
27147
27147
  /**
27148
27148
  * The uniform of a hop. A hop of a factor of 4 takes two taps a side at +-1 source pixel: an exact box of 4 x 4. The
@@ -45112,7 +45112,7 @@ function enteredCover(cover, enter) {
45112
45112
  * lookOf({ texture: "ui.loader.ring", projection: "loading" }); // { projection: "loading" }
45113
45113
  * ```
45114
45114
  */
45115
- function lookOf(loader) {
45115
+ function lookOf$1(loader) {
45116
45116
  if (loader.projection !== void 0) return { projection: loader.projection };
45117
45117
  if (loader.texture !== void 0) return { texture: loader.texture };
45118
45118
  return {};
@@ -45138,7 +45138,7 @@ function loaderOver(below, over) {
45138
45138
  const named = over.texture !== void 0 || over.projection !== void 0;
45139
45139
  const merged = {
45140
45140
  afterMs: over.afterMs ?? base.afterMs,
45141
- ...lookOf(named ? over : base)
45141
+ ...lookOf$1(named ? over : base)
45142
45142
  };
45143
45143
  const holdMs = over.holdMs ?? base.holdMs ?? 0;
45144
45144
  if (holdMs > 0) merged.holdMs = holdMs;
@@ -50278,7 +50278,11 @@ function propertyOf(target, name) {
50278
50278
  */
50279
50279
  function listedDefinition(input, stage) {
50280
50280
  const candidate = propertyOf(stage, "filter");
50281
- for (const listed of input.stages) if (listed.filter === candidate) return listed.filter;
50281
+ const { stages } = input;
50282
+ for (let index = 0; index < stages.length; index += 1) {
50283
+ const listed = stages[index];
50284
+ if (listed !== void 0 && listed.filter === candidate) return listed.filter;
50285
+ }
50282
50286
  }
50283
50287
  /**
50284
50288
  * The uniform of a definition by its name.
@@ -50288,7 +50292,11 @@ function listedDefinition(input, stage) {
50288
50292
  * @returns The uniform, or `undefined`.
50289
50293
  */
50290
50294
  function uniformNamed(definition, name) {
50291
- for (const uniform of definition.uniforms) if (uniform.name === name) return uniform;
50295
+ const { uniforms } = definition;
50296
+ for (let index = 0; index < uniforms.length; index += 1) {
50297
+ const uniform = uniforms[index];
50298
+ if (uniform?.name === name) return uniform;
50299
+ }
50292
50300
  }
50293
50301
  /**
50294
50302
  * Tells whether a step's value fits the form of a uniform: a number for a number or a colour, a
@@ -50305,7 +50313,11 @@ function uniformNamed(definition, name) {
50305
50313
  function fitsForm(uniform, value) {
50306
50314
  if (uniform.form !== "vector") return typeof value === "number";
50307
50315
  if (!Array.isArray(value) || value.length !== uniform.size) return false;
50308
- for (const entry of value) if (typeof entry !== "number" || !Number.isFinite(entry)) return false;
50316
+ const entries = value;
50317
+ for (let index = 0; index < entries.length; index += 1) {
50318
+ const entry = entries[index];
50319
+ if (typeof entry !== "number" || !Number.isFinite(entry)) return false;
50320
+ }
50309
50321
  return true;
50310
50322
  }
50311
50323
  /**
@@ -50324,11 +50336,12 @@ function stepProblem(input, step, index) {
50324
50336
  const id = propertyOf(propertyOf(stage, "filter"), "id") ?? propertyOf(stage, "componentName");
50325
50337
  return `input "${name}" names stage "${String(id)}", which is not in its stages: only listed stages are checked and warmed up before they draw.`;
50326
50338
  }
50327
- const scale = propertyOf(step, "scale");
50339
+ const scale = typeof step === "object" && step !== null && "scale" in step ? step.scale : propertyOf(step, "scale");
50328
50340
  if (typeof scale !== "number" || !Number.isFinite(scale) || scale <= 0 || scale > 1) return `input "${name}": step ${index} has scale ${String(scale)}; a scale is a share of the input's resolution above 0 and at most 1.`;
50329
50341
  const uniforms = propertyOf(step, "uniforms");
50330
50342
  if (typeof uniforms !== "object" || uniforms === null) return void 0;
50331
- for (const key of Object.keys(uniforms)) {
50343
+ for (const key in uniforms) {
50344
+ if (!Object.hasOwn(uniforms, key)) continue;
50332
50345
  const uniform = uniformNamed(definition, key);
50333
50346
  if (uniform === void 0) return `input "${name}": step ${index} gives "${key}", which stage "${definition.id}" does not declare.`;
50334
50347
  if (!fitsForm(uniform, Reflect.get(uniforms, key))) return `input "${name}": step ${index} gives "${key}" a value of another form.`;
@@ -50346,8 +50359,8 @@ function stepsProblem(input, steps) {
50346
50359
  if (!Array.isArray(steps)) return `input "${input.name}": chain must return an array of steps.`;
50347
50360
  const list = steps;
50348
50361
  if (list.length > MAX_STEPS) return `input "${input.name}": chain returned ${list.length} steps; at most ${MAX_STEPS}.`;
50349
- for (const [index, step] of list.entries()) {
50350
- const problem = stepProblem(input, step, index);
50362
+ for (let index = 0; index < list.length; index += 1) {
50363
+ const problem = stepProblem(input, list[index], index);
50351
50364
  if (problem !== void 0) return problem;
50352
50365
  }
50353
50366
  }
@@ -50391,14 +50404,11 @@ function writeStep(place, step) {
50391
50404
  * @param places - The places of the input, changed in place.
50392
50405
  * @param at - The slot of the step.
50393
50406
  * @param step - The step.
50394
- * @returns The place, and true in `built` when it was built for this step.
50407
+ * @returns The place: the one at the slot when kept, a new one, put in the slot, when built for this step.
50395
50408
  */
50396
50409
  function placeFor(pixi, retired, places, at, step) {
50397
50410
  const kept = places[at];
50398
- if (kept?.definition === step.stage.filter) return {
50399
- place: kept,
50400
- built: false
50401
- };
50411
+ if (kept?.definition === step.stage.filter) return kept;
50402
50412
  if (kept !== void 0) retired.push(kept.body);
50403
50413
  const place = {
50404
50414
  definition: step.stage.filter,
@@ -50406,10 +50416,25 @@ function placeFor(pixi, retired, places, at, step) {
50406
50416
  scale: step.scale
50407
50417
  };
50408
50418
  places[at] = place;
50409
- return {
50410
- place,
50411
- built: true
50412
- };
50419
+ return place;
50420
+ }
50421
+ /**
50422
+ * Retires the places of an input past its steps, by index, and cuts them off: `splice` would answer an array of them
50423
+ * in every frame.
50424
+ *
50425
+ * @param retired - The bodies to destroy after the frame.
50426
+ * @param places - The places of the input, changed in place.
50427
+ * @param count - How many steps the chain returned.
50428
+ * @returns True when a place was retired.
50429
+ */
50430
+ function retireLeft(retired, places, count) {
50431
+ if (places.length <= count) return false;
50432
+ for (let at = count; at < places.length; at += 1) {
50433
+ const left = places[at];
50434
+ if (left !== void 0) retired.push(left.body);
50435
+ }
50436
+ places.length = count;
50437
+ return true;
50413
50438
  }
50414
50439
  /**
50415
50440
  * Walks the steps of one input with its places: a place that draws the step's stage is kept and
@@ -50427,19 +50452,19 @@ function placeSteps(pixi, inputs, index, steps) {
50427
50452
  const places = inputs.places[index] ?? [];
50428
50453
  let changed = false;
50429
50454
  let rebuilt = false;
50430
- for (const [at, step] of steps.entries()) {
50431
- const { place, built } = placeFor(pixi, inputs.retired, places, at, step);
50432
- if (built) rebuilt = true;
50455
+ for (let at = 0; at < steps.length; at += 1) {
50456
+ const step = steps[at];
50457
+ if (step === void 0) continue;
50458
+ const before = places[at];
50459
+ const place = placeFor(pixi, inputs.retired, places, at, step);
50460
+ if (place !== before) rebuilt = true;
50433
50461
  if (writeStep(place, step)) changed = true;
50434
50462
  if (place.scale !== step.scale) {
50435
50463
  place.scale = step.scale;
50436
50464
  changed = true;
50437
50465
  }
50438
50466
  }
50439
- for (const left of places.splice(steps.length)) {
50440
- inputs.retired.push(left.body);
50441
- rebuilt = true;
50442
- }
50467
+ if (retireLeft(inputs.retired, places, steps.length)) rebuilt = true;
50443
50468
  if (rebuilt) inputs.slot = Object.freeze({
50444
50469
  ...inputs.slot,
50445
50470
  stages: stagesOf(inputs)
@@ -50464,7 +50489,10 @@ function evaluate(ectx, pixi, instance, inputs, resolution, backResolution) {
50464
50489
  const kind = ectx.state.kinds.get(instance.kindId);
50465
50490
  let changed = resolution !== inputs.resolution || backResolution !== inputs.backResolution;
50466
50491
  let passes = 1;
50467
- for (const [index, input] of instance.definition.inputs.entries()) {
50492
+ const declared = instance.definition.inputs;
50493
+ for (let index = 0; index < declared.length; index += 1) {
50494
+ const input = declared[index];
50495
+ if (input === void 0) continue;
50468
50496
  let steps;
50469
50497
  inputs.context.resolution = input.from === "back" ? backResolution : resolution;
50470
50498
  try {
@@ -54411,9 +54439,54 @@ function isElementNode(value) {
54411
54439
  return typeof value === "object" && value !== null && "type" in value && "props" in value && "children" in value;
54412
54440
  }
54413
54441
  /**
54442
+ * Escapes every `<` of a text parameter the way the tag pass of `text` reads a literal `<`, so a
54443
+ * player's name is never markup. A text without `<` comes back as the same string. It is the twin
54444
+ * of `escapeTags` in `text/tags.ts` (`i18n` sits below `text` and cannot import it): a change
54445
+ * edits both, and `tests/integration/escape-params.test.ts` holds them together.
54446
+ *
54447
+ * @param text - The parameter read as text.
54448
+ * @returns The text with every `<` written as `\<`.
54449
+ * @example
54450
+ * ```ts
54451
+ * escapeTags("<b>x"); // "\\<b>x"
54452
+ * ```
54453
+ */
54454
+ function escapeTags$1(text) {
54455
+ return text.includes("<") ? text.replaceAll("<", String.raw`\<`) : text;
54456
+ }
54457
+ /**
54458
+ * Tells whether one item of a list parameter is a string with a `<` in it.
54459
+ *
54460
+ * @param item - The item.
54461
+ * @returns True when the item needs escaping.
54462
+ * @example
54463
+ * ```ts
54464
+ * hasTag("<b>Ann"); // true
54465
+ * ```
54466
+ */
54467
+ function hasTag(item) {
54468
+ return typeof item === "string" && item.includes("<");
54469
+ }
54470
+ /**
54471
+ * Escapes every `<` of every string item of a list parameter, so a name in a list is never
54472
+ * markup either. A list with no `<` in any item comes back as the same array.
54473
+ *
54474
+ * @param items - The list parameter.
54475
+ * @returns The items, every `<` written as `\<`.
54476
+ * @example
54477
+ * ```ts
54478
+ * escapeItems(["<b>Ann", "Bob"]); // ["\\<b>Ann", "Bob"]
54479
+ * ```
54480
+ */
54481
+ function escapeItems(items) {
54482
+ for (const item of items) if (hasTag(item)) return items.map((each) => escapeTags$1(each));
54483
+ return items;
54484
+ }
54485
+ /**
54414
54486
  * One plain argument of a compiled message as a part: an element node keeps its place in the
54415
54487
  * sentence, a list goes through `Intl.ListFormat` and a number through `Intl.NumberFormat` of the
54416
- * kit's locale, anything else is read as text. A generated `strings.<locale>.ts` imports it as
54488
+ * kit's locale, anything else is read as text. Every `<` of a text or of a list item is escaped
54489
+ * as `\<`, so the tag pass of `text` never reads a parameter as markup. A generated `strings.<locale>.ts` imports it as
54417
54490
  * `argument` for a message with `{name}`.
54418
54491
  *
54419
54492
  * @param value - The parameter of the message.
@@ -54421,18 +54494,23 @@ function isElementNode(value) {
54421
54494
  * @returns The part.
54422
54495
  * @example
54423
54496
  * ```ts
54424
- * // A compiled module written by hand, the shape `moku-game keys` writes for "Host: {name}".
54497
+ * // A compiled module written by hand, the shape `moku-game keys` writes for "Host: {name}",
54498
+ * // registered as the strings of `en`; `coin` is an icon element a game builds.
54425
54499
  * const lobby: I18n.CompiledMessages = {
54426
54500
  * "lobby.host": (p, intl) => [{ kind: "text", text: "Host: " }, messageArgument(p.name, intl)]
54427
54501
  * };
54502
+ * const coin: ElementNode = { type: "icon", props: { name: "hud.coin" }, children: [] };
54428
54503
  * app.i18n.plain(tr("lobby.host", { name: ["Ann", "Bob", "Cy"] })); // "Host: Ann, Bob, and Cy"
54429
54504
  * app.i18n.format(tr("lobby.host", { name: coin })); // [{ kind: "text", text: "Host: " }, { kind: "element", node: coin }]
54505
+ * app.i18n.format(tr("lobby.host", { name: "<b>x" })); // [{ kind: "text", text: "Host: \\<b>x" }]
54506
+ * app.i18n.plain(tr("lobby.host", { name: "<b>x" })); // "Host: <b>x"
54507
+ * app.i18n.format(tr("lobby.host", { name: ["<b>Ann", "Bob"] })); // [{ kind: "text", text: "Host: \\<b>Ann and Bob" }]
54430
54508
  * ```
54431
54509
  */
54432
54510
  function messageArgument(value, intl) {
54433
54511
  if (Array.isArray(value)) return {
54434
54512
  kind: "text",
54435
- text: intl.list().format(value)
54513
+ text: intl.list().format(escapeItems(value))
54436
54514
  };
54437
54515
  if (typeof value === "number") return {
54438
54516
  kind: "text",
@@ -54444,7 +54522,7 @@ function messageArgument(value, intl) {
54444
54522
  };
54445
54523
  return {
54446
54524
  kind: "text",
54447
- text: String(value)
54525
+ text: escapeTags$1(String(value))
54448
54526
  };
54449
54527
  }
54450
54528
  /**
@@ -54763,6 +54841,20 @@ function formatIn(ctx, message, locale) {
54763
54841
  return mergeParts(compiled(message.params ?? {}, kitOf(ctx.state, target)));
54764
54842
  }
54765
54843
  /**
54844
+ * Joins the text parts of a sentence, elements dropped, and reads every `\<` as the `<` it
54845
+ * escapes, so plain text shows a parameter as the player wrote it.
54846
+ *
54847
+ * @param parts - What `formatIn` answered.
54848
+ * @returns The sentence as text.
54849
+ * @example
54850
+ * ```ts
54851
+ * plainOf([{ kind: "text", text: "Host: \\<b>x" }]); // "Host: <b>x"
54852
+ * ```
54853
+ */
54854
+ function plainOf$1(parts) {
54855
+ return parts.map((part) => part.kind === "text" ? part.text : "").join("").replaceAll(String.raw`\<`, "<");
54856
+ }
54857
+ /**
54766
54858
  * Switches the current locale on the queue: load what is lazy (the modules of the held bundles
54767
54859
  * included), set the locale, send the event.
54768
54860
  *
@@ -54870,7 +54962,7 @@ function createI18nApi(ctx) {
54870
54962
  locale: () => ctx.state.locale,
54871
54963
  setLocale: (locale) => setLocale(ctx, locale),
54872
54964
  format: (message, locale) => formatIn(ctx, message, locale),
54873
- plain: (message) => formatIn(ctx, message).map((part) => part.kind === "text" ? part.text : "").join(""),
54965
+ plain: (message) => plainOf$1(formatIn(ctx, message)),
54874
54966
  has: (key) => resolve$1(ctx.state, key, ctx.state.locale, ctx.config.fallback) !== void 0,
54875
54967
  isKey: (value) => isKnownKey(ctx.state, ctx.config.fallback, value),
54876
54968
  duration: (ms, style = "short") => kitOf(ctx.state, ctx.state.locale).duration({
@@ -58254,11 +58346,443 @@ const platformPlugin = /*#__PURE__*/ createPlugin$1("platform", {
58254
58346
  onStop: ({ state }) => stopPlatform(state)
58255
58347
  });
58256
58348
  //#endregion
58349
+ //#region src/plugins/text/lines.ts
58350
+ /** Line height of a style whose font is not loaded, as a share of the style size. */
58351
+ const FALLBACK_LINE = 1.2;
58352
+ /** Baseline of a font that names none, or of a style whose font is not loaded, as a share of the size. */
58353
+ const FALLBACK_BASE = .8;
58354
+ /**
58355
+ * The look one run measures and draws in, one of the objects already stored: the style its span
58356
+ * borrows (the paragraph's when it is in none, or in one of a key no style has), or the bold look
58357
+ * of that style for a `<b>` run when the style has `boldStyle`. Silent: the layout warns of an
58358
+ * unknown key once per string.
58359
+ *
58360
+ * @param paragraph - The style of the label.
58361
+ * @param run - The run.
58362
+ * @param styles - The style table, by name; left out, every span is the paragraph's.
58363
+ * @param looks - The bold looks, by the style they belong to.
58364
+ * @returns The look of the run.
58365
+ * @example
58366
+ * ```ts
58367
+ * const run: Run = { kind: "icon", key: "hud.coin", span: "price.22" };
58368
+ *
58369
+ * lookOf(bodyStyle, run, new Map([["price.22", priceStyle]]), new Map()); // priceStyle
58370
+ * ```
58371
+ */
58372
+ function lookOf(paragraph, run, styles, looks) {
58373
+ const own = (run.span === void 0 ? void 0 : styles?.get(run.span)) ?? paragraph;
58374
+ if (run.kind === "icon" || !run.bold) return own;
58375
+ return looks?.get(own) ?? own;
58376
+ }
58377
+ /**
58378
+ * The look of a run under the style table and the bold looks a layout was handed.
58379
+ *
58380
+ * @param style - The style of the label.
58381
+ * @param run - The run.
58382
+ * @param options - What the layout was handed.
58383
+ * @returns The look of the run.
58384
+ */
58385
+ function lookIn(style, run, options) {
58386
+ return lookOf(style, run, options.styles, options.looks);
58387
+ }
58388
+ /**
58389
+ * The font one run is drawn with: the bold or italic font when its look names it, else the
58390
+ * font of the look.
58391
+ *
58392
+ * @param style - The look of the run: the style of the label, or what `lookOf` answered.
58393
+ * @param run - The run to draw.
58394
+ * @returns The asset key of the font.
58395
+ * @example
58396
+ * ```ts
58397
+ * const run: TextRun = {
58398
+ * kind: "text", text: "a", bold: true, italic: false, color: undefined, span: undefined
58399
+ * };
58400
+ *
58401
+ * fontOfRun(bodyStyle, run); // "ui.font-body": the body style names no bold font, so the bold is synthetic
58402
+ * ```
58403
+ */
58404
+ function fontOfRun(style, run) {
58405
+ if (run.bold && style.bold !== void 0) return style.bold;
58406
+ if (run.italic && style.italic !== void 0) return style.italic;
58407
+ return style.font;
58408
+ }
58409
+ /**
58410
+ * The font whose metrics a run stands in its line by. A run in a look of its own, a span's style or
58411
+ * a bold look of `boldStyle`, stands by the font its glyphs are drawn with (the bold or italic one
58412
+ * when the look names it). A run in the paragraph's look, a plain `<b>` or `<i>` included, stands
58413
+ * by the paragraph's own font, as every label did before runs had looks. An icon stands by the
58414
+ * font of its look.
58415
+ *
58416
+ * @param paragraph - The style of the label.
58417
+ * @param look - The look of the run, what `lookOf` answered.
58418
+ * @param run - The run.
58419
+ * @returns The asset key of the font.
58420
+ * @example
58421
+ * ```ts
58422
+ * const body = builtInStyles({ body: "ui.font-body", digits: "ui.font-digits" }).body;
58423
+ * const row = { ...body, bold: "ui.font-bold" };
58424
+ * const bold: Run = { kind: "text", text: "1", bold: true, italic: false, color: undefined, span: undefined };
58425
+ *
58426
+ * metricsFontOf(row, row, bold); // "ui.font-body": a plain <b> keeps the paragraph's line
58427
+ * metricsFontOf(row, { ...row, size: 16 }, bold); // "ui.font-bold": a look of its own stands by its font
58428
+ * ```
58429
+ */
58430
+ function metricsFontOf(paragraph, look, run) {
58431
+ return run.kind === "icon" || look === paragraph ? look.font : fontOfRun(look, run);
58432
+ }
58433
+ /**
58434
+ * The height of one line of a style: `lineHeight × size` when the style names its line, else the
58435
+ * line of the font at the style size, its own font unless another is named.
58436
+ *
58437
+ * @param style - The style of the label, or the look of a run.
58438
+ * @param tables - The advance tables that are loaded.
58439
+ * @param font - The font whose line it is: what `metricsFontOf` answers for a run.
58440
+ * @returns The line height in reference pixels.
58441
+ * @example
58442
+ * ```ts
58443
+ * lineHeightOf(bodyStyle, new Map()); // 38.4: 1.2 em of a 32 px style with no font loaded
58444
+ * ```
58445
+ */
58446
+ function lineHeightOf(style, tables, font = style.font) {
58447
+ return style.lineHeight === void 0 ? fontLineOf(style, tables, font) : style.lineHeight * style.size;
58448
+ }
58449
+ /**
58450
+ * The height of one line of a font at the style size, whatever line the style names: what the
58451
+ * glyphs are drawn into, so the gap to `lineHeightOf` is the leading.
58452
+ *
58453
+ * @param style - The style of the label, or the look of a run.
58454
+ * @param tables - The advance tables that are loaded.
58455
+ * @param font - The font whose line it is; the style's own when left out.
58456
+ * @returns The font's line height in reference pixels.
58457
+ * @example
58458
+ * ```ts
58459
+ * fontLineOf({ ...bodyStyle, lineHeight: 1.5 }, new Map()); // 38.4: the font's 1.2 em, not 48
58460
+ * ```
58461
+ */
58462
+ function fontLineOf(style, tables, font = style.font) {
58463
+ const table = tables.get(font);
58464
+ return table === void 0 ? FALLBACK_LINE * style.size : table.lineHeight * (style.size / table.size);
58465
+ }
58466
+ /**
58467
+ * How far the baseline sits below the top of a font's line: the `base` of the font at the style
58468
+ * size, or 0.8 em while the font is not loaded.
58469
+ *
58470
+ * @param style - The look of a run.
58471
+ * @param tables - The advance tables that are loaded.
58472
+ * @param font - The font the run is drawn with; the style's own when left out.
58473
+ * @returns The ascent in reference pixels.
58474
+ * @example
58475
+ * ```ts
58476
+ * ascentOf(bodyStyle, new Map()); // 25.6: 0.8 em of a 32 px style with no font loaded
58477
+ * ```
58478
+ */
58479
+ function ascentOf(style, tables, font = style.font) {
58480
+ const table = tables.get(font);
58481
+ return table === void 0 ? FALLBACK_BASE * style.size : table.base * (style.size / table.size);
58482
+ }
58483
+ /**
58484
+ * Half the leading of a style: how far below the top of its line its font's line starts, as CSS
58485
+ * centres the glyphs in a line taller or shorter than the font's.
58486
+ *
58487
+ * @param style - The look of a run.
58488
+ * @param tables - The advance tables that are loaded.
58489
+ * @param font - The font the run is drawn with; the style's own when left out.
58490
+ * @returns The half-leading in reference pixels; below 0 in a line shorter than the font's.
58491
+ * @example
58492
+ * ```ts
58493
+ * leadingOf({ ...bodyStyle, lineHeight: 2 }, new Map()); // 12.8: (64 - 38.4) / 2
58494
+ * ```
58495
+ */
58496
+ function leadingOf(style, tables, font = style.font) {
58497
+ return (lineHeightOf(style, tables, font) - fontLineOf(style, tables, font)) / 2;
58498
+ }
58499
+ /**
58500
+ * Writes the line box of every line, as CSS builds it: each run stands in the line of its look,
58501
+ * the line of its metrics font (`metricsFontOf`) centred in it, and its baseline that font's
58502
+ * `ascent` below that line's top. Every line holds a strut too, an empty piece of the paragraph's
58503
+ * look, so a line is never shorter than the paragraph's line and its baseline never higher. The
58504
+ * baseline of the line is the lowest of them, and the line reaches as far below it as the deepest.
58505
+ * A line no run reaches past the strut, a line of the paragraph's look and an empty one included,
58506
+ * is exactly the paragraph's line, to the last bit.
58507
+ *
58508
+ * @param lines - The lines of the block.
58509
+ * @param style - The style of the label.
58510
+ * @param tables - The advance tables that are loaded.
58511
+ * @param options - The styles and bold looks a run may take.
58512
+ */
58513
+ function boxLines(lines, style, tables, options) {
58514
+ const strutRaise = leadingOf(style, tables) + ascentOf(style, tables);
58515
+ const strutBox = lineHeightOf(style, tables);
58516
+ const strutBelow = strutBox - strutRaise;
58517
+ for (const line of lines) {
58518
+ let above = strutRaise;
58519
+ let below = strutBelow;
58520
+ for (const run of line.runs) {
58521
+ const look = lookIn(style, run, options);
58522
+ const font = metricsFontOf(style, look, run);
58523
+ const raise = leadingOf(look, tables, font) + ascentOf(look, tables, font);
58524
+ above = Math.max(above, raise);
58525
+ below = Math.max(below, lineHeightOf(look, tables, font) - raise);
58526
+ }
58527
+ const strutOnly = above === strutRaise && below === strutBelow;
58528
+ line.baseline = strutOnly ? strutRaise : above;
58529
+ line.height = strutOnly ? strutBox : above + below;
58530
+ }
58531
+ }
58532
+ /**
58533
+ * The height of a block: the sum of its lines, or the count times the line when every line is
58534
+ * as high, which is to the last bit what a block of one look measured before lines had boxes.
58535
+ *
58536
+ * @param lines - The lines, their boxes written.
58537
+ * @returns The height in reference pixels.
58538
+ * @example
58539
+ * ```ts
58540
+ * blockHeight([{ runs: [], width: 0, height: 40, baseline: 32 }]); // 40
58541
+ * ```
58542
+ */
58543
+ function blockHeight(lines) {
58544
+ const first = lines[0]?.height ?? 0;
58545
+ let sum = 0;
58546
+ let even = true;
58547
+ for (const line of lines) {
58548
+ sum += line.height;
58549
+ even &&= line.height === first;
58550
+ }
58551
+ return even ? lines.length * first : sum;
58552
+ }
58553
+ //#endregion
58554
+ //#region src/plugins/text/tags.ts
58555
+ /** Matches an opening colour tag. Six hex digits: `#rgb` is not accepted. */
58556
+ const COLOR_TAG = /^color=#([\da-f]{6})$/i;
58557
+ /** Matches an inline icon tag, which has no closing tag. */
58558
+ const ICON_TAG = /^icon=(\S+)$/;
58559
+ /** Matches an opening span tag. The key is unquoted: `style="x"` is not this grammar. */
58560
+ const SPAN_TAG = /^span style=([^\s"']+)$/;
58561
+ /**
58562
+ * Reads an opening tag.
58563
+ *
58564
+ * @param body - What stood between the angle brackets.
58565
+ * @returns The tag, or `undefined` when it is not one this grammar knows.
58566
+ * @example
58567
+ * ```ts
58568
+ * openTag("color=#ff0000"); // { name: "color", color: 16711680, span: undefined }
58569
+ * ```
58570
+ */
58571
+ function openTag(body) {
58572
+ if (body === "b" || body === "i") return {
58573
+ name: body,
58574
+ color: void 0,
58575
+ span: void 0
58576
+ };
58577
+ const span = SPAN_TAG.exec(body);
58578
+ if (span !== null) return {
58579
+ name: "span",
58580
+ color: void 0,
58581
+ span: span[1]
58582
+ };
58583
+ const colour = COLOR_TAG.exec(body);
58584
+ if (colour === null) return void 0;
58585
+ return {
58586
+ name: "color",
58587
+ color: Number.parseInt(colour[1] ?? "0", 16),
58588
+ span: void 0
58589
+ };
58590
+ }
58591
+ /**
58592
+ * The key of the innermost open span: a nested span wins over the one around it.
58593
+ *
58594
+ * @param stack - The tags that are open.
58595
+ * @returns The style key, or `undefined` outside a span.
58596
+ * @example
58597
+ * ```ts
58598
+ * spanOf([{ name: "span", color: undefined, span: "price.22" }]); // "price.22"
58599
+ * ```
58600
+ */
58601
+ function spanOf(stack) {
58602
+ let span;
58603
+ for (const open of stack) if (open.name === "span") span = open.span;
58604
+ return span;
58605
+ }
58606
+ /**
58607
+ * Tells whether two glyph runs are drawn in the same look: the same bold, italic, colour and span.
58608
+ * Only then may their text be one run: the parse, the layout and the draw all ask this.
58609
+ *
58610
+ * @param first - One glyph run.
58611
+ * @param second - The other.
58612
+ * @returns True when nothing but the text tells them apart.
58613
+ */
58614
+ function sameLook(first, second) {
58615
+ return first.bold === second.bold && first.italic === second.italic && first.color === second.color && first.span === second.span;
58616
+ }
58617
+ /**
58618
+ * Appends text to the runs, merging it into the last one when it is in the same look.
58619
+ *
58620
+ * @param runs - The runs built so far.
58621
+ * @param text - The characters to append.
58622
+ * @param stack - The tags that are open around them.
58623
+ */
58624
+ function pushText(runs, text, stack) {
58625
+ let color;
58626
+ for (const open of stack) if (open.name === "color") color = open.color;
58627
+ const piece = {
58628
+ kind: "text",
58629
+ text,
58630
+ bold: stack.some((open) => open.name === "b"),
58631
+ italic: stack.some((open) => open.name === "i"),
58632
+ color,
58633
+ span: spanOf(stack)
58634
+ };
58635
+ const last = runs.at(-1);
58636
+ if (last?.kind === "text" && sameLook(last, piece)) {
58637
+ last.text += text;
58638
+ return;
58639
+ }
58640
+ runs.push(piece);
58641
+ }
58642
+ /**
58643
+ * Reports one source string once, whatever is wrong with it.
58644
+ *
58645
+ * @param state - The parse in progress.
58646
+ * @param message - The log event.
58647
+ * @param tag - The tag that was wrong.
58648
+ */
58649
+ function complain(state, message, tag) {
58650
+ if (state.warned) return;
58651
+ state.warned = true;
58652
+ state.warn(`tag:${state.source}`, message, {
58653
+ tag,
58654
+ text: state.source
58655
+ });
58656
+ }
58657
+ /**
58658
+ * Writes what was read so far into a run.
58659
+ *
58660
+ * @param state - The parse in progress.
58661
+ */
58662
+ function flush(state) {
58663
+ if (state.buffer.length === 0) return;
58664
+ pushText(state.runs, state.buffer, state.stack);
58665
+ state.buffer = "";
58666
+ }
58667
+ /**
58668
+ * Applies one tag: an icon run, an opening tag, a matching close, or, when it is none of those,
58669
+ * literal text and one warning.
58670
+ *
58671
+ * @param state - The parse in progress.
58672
+ * @param body - What stood between the angle brackets.
58673
+ */
58674
+ function applyTag(state, body) {
58675
+ const icon = ICON_TAG.exec(body);
58676
+ if (icon !== null) {
58677
+ flush(state);
58678
+ state.runs.push({
58679
+ kind: "icon",
58680
+ key: icon[1] ?? "",
58681
+ span: spanOf(state.stack)
58682
+ });
58683
+ return;
58684
+ }
58685
+ const open = openTag(body);
58686
+ if (open !== void 0) {
58687
+ flush(state);
58688
+ state.stack.push(open);
58689
+ return;
58690
+ }
58691
+ const closes = body.startsWith("/");
58692
+ const at = closes ? state.stack.map((entry) => entry.name).lastIndexOf(body.slice(1)) : -1;
58693
+ if (at !== -1) {
58694
+ flush(state);
58695
+ state.stack.splice(at, 1);
58696
+ return;
58697
+ }
58698
+ complain(state, closes ? "text: stray closing tag" : "text: unknown tag", body);
58699
+ state.buffer += `<${body}>`;
58700
+ }
58701
+ /**
58702
+ * Tells whether the character at an index starts the escape `\<`, a literal `<`.
58703
+ *
58704
+ * @param source - The resolved string.
58705
+ * @param index - Where the parse stands.
58706
+ * @returns True for a backslash right before a `<`.
58707
+ * @example
58708
+ * ```ts
58709
+ * isEscape(String.raw`a\<b`, 1); // true
58710
+ * ```
58711
+ */
58712
+ function isEscape(source, index) {
58713
+ return source[index] === "\\" && source[index + 1] === "<";
58714
+ }
58715
+ /**
58716
+ * Writes a plain string so the grammar reads it as exactly these characters: every `<` becomes
58717
+ * the escape `\<`. A string without `<` comes back as it is. A typed field value goes through it.
58718
+ *
58719
+ * @param text - The plain string.
58720
+ * @returns The string `parseTags` reads as one run of the same characters.
58721
+ * @example
58722
+ * ```ts
58723
+ * escapeTags("<b>x"); // "\\<b>x"
58724
+ * ```
58725
+ */
58726
+ function escapeTags(text) {
58727
+ return text.includes("<") ? text.replaceAll("<", String.raw`\<`) : text;
58728
+ }
58729
+ /**
58730
+ * Turns a resolved string into runs of glyphs and inline icons. Everything the grammar does not
58731
+ * know stays visible: the tag is kept as literal text and the source is reported once. A run in a
58732
+ * `<span style=KEY>` carries `KEY`; whether a style has that key is the layout's question.
58733
+ *
58734
+ * @param source - The resolved string, as it was written or formatted.
58735
+ * @param warn - Called at most once per source, with the key `tag:<source>`.
58736
+ * @returns The runs, in reading order, with equal neighbours merged.
58737
+ * @example
58738
+ * ```ts
58739
+ * parseTags("<b>a</b><span style=price.22>b</span>", () => undefined);
58740
+ * // [{ kind: "text", text: "a", bold: true, italic: false, color: undefined, span: undefined },
58741
+ * // { kind: "text", text: "b", bold: false, italic: false, color: undefined, span: "price.22" }]
58742
+ * ```
58743
+ */
58744
+ function parseTags(source, warn) {
58745
+ const state = {
58746
+ source,
58747
+ runs: [],
58748
+ stack: [],
58749
+ buffer: "",
58750
+ warned: false,
58751
+ warn
58752
+ };
58753
+ let index = 0;
58754
+ while (index < source.length) {
58755
+ if (isEscape(source, index)) {
58756
+ state.buffer += "<";
58757
+ index += 2;
58758
+ continue;
58759
+ }
58760
+ const char = source[index] ?? "";
58761
+ const close = char === "<" ? source.indexOf(">", index + 1) : -1;
58762
+ if (close === -1) {
58763
+ state.buffer += char;
58764
+ index += 1;
58765
+ continue;
58766
+ }
58767
+ applyTag(state, source.slice(index + 1, close));
58768
+ index = close + 1;
58769
+ }
58770
+ flush(state);
58771
+ if (state.stack.length > 0) complain(state, "text: unclosed tag", state.stack[0]?.name ?? "");
58772
+ return state.runs;
58773
+ }
58774
+ //#endregion
58257
58775
  //#region src/plugins/text/measure.ts
58776
+ /**
58777
+ * @file text plugin — the measurement. A `.fnt` becomes an advance table, runs become lines, and
58778
+ * a block becomes a size in reference pixels. Pure and canvas-free: the same numbers on a screen
58779
+ * and in plain Bun, which is what keeps `ui.layout` honest. A character the font has no glyph for
58780
+ * measures 0 wide, because Pixi draws nothing for it. Every run measures in its look: the
58781
+ * paragraph's style, the style its `<span>` borrows, or the bold look of either; and every line is
58782
+ * a CSS line box, as high as its looks need, all of them on one baseline.
58783
+ */
58258
58784
  /** Advance of a glyph no table knows, as a share of the style size. */
58259
58785
  const FALLBACK_ADVANCE = .6;
58260
- /** Line height of a style whose font is not loaded, as a share of the style size. */
58261
- const FALLBACK_LINE = 1.2;
58262
58786
  /**
58263
58787
  * How much wider than its box a line of a `"box"` style may be. `ui` lays a text out in whole units
58264
58788
  * and rounds its measure with this tolerance, so a line that adds up to a hair over a whole unit
@@ -58349,14 +58873,30 @@ function readJson(fnt) {
58349
58873
  if (!isRecord$1(data) || !isRecord$1(data.info) || !Array.isArray(data.chars)) return void 0;
58350
58874
  const size = Math.abs(numberOf(data.info.size) ?? 0);
58351
58875
  if (size <= 0) return void 0;
58352
- const common = isRecord$1(data.common) ? numberOf(data.common.lineHeight) ?? 0 : 0;
58876
+ const common = isRecord$1(data.common) ? data.common : {};
58877
+ const lineHeight = numberOf(common.lineHeight) ?? 0;
58353
58878
  return {
58354
58879
  size,
58355
- lineHeight: common > 0 ? common : size,
58880
+ lineHeight: lineHeight > 0 ? lineHeight : size,
58881
+ base: baseOf(numberOf(common.base), size),
58356
58882
  advances: readChars(data.chars)
58357
58883
  };
58358
58884
  }
58359
58885
  /**
58886
+ * The baseline a file names, or 0.8 of its size when it names none above 0.
58887
+ *
58888
+ * @param base - The `base` of the file's `common` block, as it was read.
58889
+ * @param size - The export size of the font.
58890
+ * @returns How far the baseline sits below the top of a line, at the export size.
58891
+ * @example
58892
+ * ```ts
58893
+ * baseOf(undefined, 40); // 32
58894
+ * ```
58895
+ */
58896
+ function baseOf(base, size) {
58897
+ return base !== void 0 && base > 0 ? base : FALLBACK_BASE * size;
58898
+ }
58899
+ /**
58360
58900
  * Creates the empty glyph table. Its own function because lint rule L5 refuses a collection built
58361
58901
  * inside an exported declaration.
58362
58902
  *
@@ -58387,6 +58927,7 @@ function readXml(fnt) {
58387
58927
  const size = Math.abs(attribute(fnt, /<info[^>]*\ssize="(-?\d+)"/) ?? 0);
58388
58928
  if (size <= 0) return void 0;
58389
58929
  const lineHeight = attribute(fnt, /<common[^>]*\slineHeight="(-?\d+)"/) ?? 0;
58930
+ const base = attribute(fnt, /<common[^>]*\sbase="(-?\d+)"/);
58390
58931
  const advances = emptyAdvances();
58391
58932
  for (const match of fnt.matchAll(/<char\s(?:[^>"]|"[^"]*")*>/g)) {
58392
58933
  const tag = match[0];
@@ -58398,6 +58939,7 @@ function readXml(fnt) {
58398
58939
  return {
58399
58940
  size,
58400
58941
  lineHeight: lineHeight > 0 ? lineHeight : size,
58942
+ base: baseOf(base, size),
58401
58943
  advances
58402
58944
  };
58403
58945
  }
@@ -58407,12 +58949,12 @@ function readXml(fnt) {
58407
58949
  *
58408
58950
  * @param fnt - The `.fnt` file as text, in BMFont XML or BMFont JSON.
58409
58951
  * @param key - The asset key of the font, for the error.
58410
- * @returns The export size, the line height and one advance per character.
58952
+ * @returns The export size, the line height, the baseline and one advance per character.
58411
58953
  * @throws {Error} When the file is in neither format.
58412
58954
  * @example
58413
58955
  * ```ts
58414
- * parseAdvances('{"info":{"size":32},"common":{"lineHeight":40},"chars":[]}', "ui.font-body");
58415
- * // { size: 32, lineHeight: 40, advances: Map(0) }
58956
+ * parseAdvances('{"info":{"size":32},"common":{"lineHeight":40,"base":30},"chars":[]}', "ui.font-body");
58957
+ * // { size: 32, lineHeight: 40, base: 30, advances: Map(0) }
58416
58958
  * ```
58417
58959
  */
58418
58960
  function parseAdvances(fnt, key) {
@@ -58421,60 +58963,11 @@ function parseAdvances(fnt, key) {
58421
58963
  return table;
58422
58964
  }
58423
58965
  /**
58424
- * The font one run is drawn with: the bold or italic font when the style names it, else the
58425
- * font of the style.
58426
- *
58427
- * @param style - The style of the label.
58428
- * @param run - The run to draw.
58429
- * @returns The asset key of the font.
58430
- * @example
58431
- * ```ts
58432
- * fontOfRun(bodyStyle, { kind: "text", text: "a", bold: true, italic: false, color: undefined });
58433
- * // "ui.font-body": the body style names no bold font, so the bold is synthetic
58434
- * ```
58435
- */
58436
- function fontOfRun(style, run) {
58437
- if (run.bold && style.bold !== void 0) return style.bold;
58438
- if (run.italic && style.italic !== void 0) return style.italic;
58439
- return style.font;
58440
- }
58441
- /**
58442
- * The height of one line of a style: `lineHeight × size` when the style names its line, else the
58443
- * line of its own font.
58444
- *
58445
- * @param style - The style of the label.
58446
- * @param tables - The advance tables that are loaded.
58447
- * @returns The line height in reference pixels.
58448
- * @example
58449
- * ```ts
58450
- * lineHeightOf(bodyStyle, new Map()); // 38.4: 1.2 em of a 32 px style with no font loaded
58451
- * ```
58452
- */
58453
- function lineHeightOf(style, tables) {
58454
- return style.lineHeight === void 0 ? fontLineOf(style, tables) : style.lineHeight * style.size;
58455
- }
58456
- /**
58457
- * The height of one line of a style's own font, whatever line the style names: what the glyphs
58458
- * are drawn into, so the gap to `lineHeightOf` is the leading.
58459
- *
58460
- * @param style - The style of the label.
58461
- * @param tables - The advance tables that are loaded.
58462
- * @returns The font's line height in reference pixels.
58463
- * @example
58464
- * ```ts
58465
- * fontLineOf({ ...bodyStyle, lineHeight: 1.5 }, new Map()); // 38.4: the font's 1.2 em, not 48
58466
- * ```
58467
- */
58468
- function fontLineOf(style, tables) {
58469
- const table = tables.get(style.font);
58470
- return table === void 0 ? FALLBACK_LINE * style.size : table.lineHeight * (style.size / table.size);
58471
- }
58472
- /**
58473
58966
  * The width of one character, letter spacing included. A character the loaded font has no glyph
58474
58967
  * for is 0 wide, spacing and all: Pixi skips it when it lays the run out and draws nothing.
58475
58968
  *
58476
58969
  * @param char - The character.
58477
- * @param style - The style of the label.
58970
+ * @param style - The look of the run.
58478
58971
  * @param fontKey - The font of the run.
58479
58972
  * @param tables - The advance tables that are loaded.
58480
58973
  * @param options - Where a warning goes.
@@ -58496,35 +58989,37 @@ function advanceOf(char, style, fontKey, tables, options) {
58496
58989
  return 0;
58497
58990
  }
58498
58991
  /**
58499
- * The width of one run: the advances of its glyphs, or a square at the line height for an icon.
58992
+ * The width of one run in its look: the advances of its glyphs, or a square at the line of the
58993
+ * look for an icon.
58500
58994
  *
58501
58995
  * @param run - The run to measure.
58502
58996
  * @param style - The style of the label.
58503
58997
  * @param tables - The advance tables that are loaded.
58504
- * @param options - Where a warning goes.
58998
+ * @param options - Where a warning goes, and the styles and bold looks a run may take.
58505
58999
  * @returns The width in reference pixels.
58506
59000
  * @example
58507
59001
  * ```ts
58508
- * measureRun({ kind: "icon", key: "hud.coin" }, bodyStyle, new Map(), options); // 38.4
59002
+ * measureRun({ kind: "icon", key: "hud.coin", span: undefined }, bodyStyle, new Map(), options); // 38.4
58509
59003
  * ```
58510
59004
  */
58511
59005
  function measureRun(run, style, tables, options) {
58512
- if (run.kind === "icon") return lineHeightOf(style, tables) + style.letterSpacing;
58513
- const fontKey = fontOfRun(style, run);
59006
+ const look = lookIn(style, run, options);
59007
+ if (run.kind === "icon") return lineHeightOf(look, tables) + look.letterSpacing;
59008
+ const fontKey = fontOfRun(look, run);
58514
59009
  let width = 0;
58515
- for (const char of run.text) width += advanceOf(char, style, fontKey, tables, options);
59010
+ for (const char of run.text) width += advanceOf(char, look, fontKey, tables, options);
58516
59011
  return width;
58517
59012
  }
58518
59013
  /**
58519
59014
  * Tells whether a glyph piece may join the last run of a line: both glyphs, with the same bold,
58520
- * italic and colour. An icon never merges.
59015
+ * italic, colour and span. An icon never merges.
58521
59016
  *
58522
59017
  * @param last - The last run of the line, if any.
58523
59018
  * @param piece - The glyph piece to append.
58524
59019
  * @returns True when the piece's text may be added to `last`.
58525
59020
  */
58526
59021
  function canMerge(last, piece) {
58527
- return last?.kind === "text" && last.bold === piece.bold && last.italic === piece.italic && last.color === piece.color;
59022
+ return last?.kind === "text" && sameLook(last, piece);
58528
59023
  }
58529
59024
  /**
58530
59025
  * Appends a piece to a line, merging glyphs into the last run when both are glyphs with the same
@@ -58544,7 +59039,42 @@ function appendRun(runs, piece) {
58544
59039
  runs.push(piece.kind === "text" ? { ...piece } : piece);
58545
59040
  }
58546
59041
  /**
58547
- * Lays runs out with no wrapping: one line per `\n` segment.
59042
+ * Creates one line whose box is not measured yet: `boxLines` writes its height and baseline.
59043
+ *
59044
+ * @param runs - The runs of the line.
59045
+ * @param width - How wide they are, the indent of the first line included.
59046
+ * @returns The line.
59047
+ * @example
59048
+ * ```ts
59049
+ * openLine([], 0); // { runs: [], width: 0, height: 0, baseline: 0 }
59050
+ * ```
59051
+ */
59052
+ function openLine(runs, width) {
59053
+ return {
59054
+ runs,
59055
+ width,
59056
+ height: 0,
59057
+ baseline: 0
59058
+ };
59059
+ }
59060
+ /**
59061
+ * The width of a line with the indent it starts at: the first line of a block that holds a run is
59062
+ * as wide as its runs plus the indent, every other line as its runs.
59063
+ *
59064
+ * @param runs - The runs of the line.
59065
+ * @param width - How wide they are.
59066
+ * @param indent - The indent the line starts at: `textIndent` on the first line, else 0.
59067
+ * @returns The width of the line.
59068
+ * @example
59069
+ * ```ts
59070
+ * indentedWidth([], 0, 20); // 0: an empty first line takes no indent
59071
+ * ```
59072
+ */
59073
+ function indentedWidth(runs, width, indent) {
59074
+ return runs.length > 0 ? indent + width : width;
59075
+ }
59076
+ /**
59077
+ * Lays runs out with no wrapping: one line per `\n` segment, the first one shifted by the indent.
58548
59078
  *
58549
59079
  * @param runs - The runs of the block.
58550
59080
  * @param style - The style of the label.
@@ -58557,10 +59087,8 @@ function layoutFixed(runs, style, tables, options) {
58557
59087
  let current = [];
58558
59088
  let width = 0;
58559
59089
  const push = () => {
58560
- lines.push({
58561
- runs: current,
58562
- width
58563
- });
59090
+ const indent = lines.length === 0 ? style.textIndent ?? 0 : 0;
59091
+ lines.push(openLine(current, indentedWidth(current, width, indent)));
58564
59092
  current = [];
58565
59093
  width = 0;
58566
59094
  };
@@ -58715,17 +59243,15 @@ function pushSoft(tokens, hyphen, metrics) {
58715
59243
  });
58716
59244
  }
58717
59245
  /**
58718
- * Closes the open line and starts a new one.
59246
+ * Closes the open line and starts a new one at the edge.
58719
59247
  *
58720
59248
  * @param builder - The lines built so far.
58721
59249
  */
58722
59250
  function commit(builder) {
58723
- builder.lines.push({
58724
- runs: builder.runs,
58725
- width: builder.width
58726
- });
59251
+ builder.lines.push(openLine(builder.runs, indentedWidth(builder.runs, builder.width, builder.indent)));
58727
59252
  builder.runs = [];
58728
59253
  builder.width = 0;
59254
+ builder.indent = 0;
58729
59255
  }
58730
59256
  /**
58731
59257
  * Puts a whole token on the open line.
@@ -58745,7 +59271,8 @@ function add(builder, token) {
58745
59271
  * @returns The pieces, in reading order.
58746
59272
  * @example
58747
59273
  * ```ts
58748
- * glyphsOf({ kind: "icon", key: "hud.coin" }); // [{ kind: "icon", key: "hud.coin" }]
59274
+ * glyphsOf({ kind: "icon", key: "hud.coin", span: undefined });
59275
+ * // [{ kind: "icon", key: "hud.coin", span: undefined }]
58749
59276
  * ```
58750
59277
  */
58751
59278
  function glyphsOf(run) {
@@ -58756,7 +59283,20 @@ function glyphsOf(run) {
58756
59283
  }));
58757
59284
  }
58758
59285
  /**
58759
- * Places a word that is wider than the wrap, glyph by glyph. An icon is one glyph.
59286
+ * Tells whether a piece of this width no longer fits on the open line: the line holds something
59287
+ * already, and its indent, its runs and the piece stand past the wrap. The first piece of a line
59288
+ * always fits, so a glyph wider than the wrap gets a line of its own.
59289
+ *
59290
+ * @param builder - The lines built so far.
59291
+ * @param width - The width of the piece.
59292
+ * @param wrap - The wrap width in reference pixels.
59293
+ * @returns True when the piece goes to the next line.
59294
+ */
59295
+ function overflows(builder, width, wrap) {
59296
+ return builder.runs.length > 0 && builder.indent + builder.width + width > wrap;
59297
+ }
59298
+ /**
59299
+ * Places a word that is wider than the room of its line, glyph by glyph. An icon is one glyph.
58760
59300
  *
58761
59301
  * @param builder - The lines built so far.
58762
59302
  * @param token - The word to break.
@@ -58766,7 +59306,7 @@ function glyphsOf(run) {
58766
59306
  function breakWord(builder, token, wrap, metrics) {
58767
59307
  for (const part of token.runs) for (const piece of glyphsOf(part)) {
58768
59308
  const glyph = measureRun(piece, metrics.style, metrics.tables, metrics.options);
58769
- if (builder.runs.length > 0 && builder.width + glyph > wrap) commit(builder);
59309
+ if (overflows(builder, glyph, wrap)) commit(builder);
58770
59310
  appendRun(builder.runs, piece);
58771
59311
  builder.width += glyph;
58772
59312
  }
@@ -58774,8 +59314,9 @@ function breakWord(builder, token, wrap, metrics) {
58774
59314
  /**
58775
59315
  * Places one word: on the open line when it still fits there with the spaces before it and the
58776
59316
  * hyphen a break after it would draw, on the next one when it does not, and glyph by glyph when
58777
- * it fits on no line at all. A break inside a word stands before it with no width: the line ends
58778
- * there with the `-` of a soft hyphen, and the word goes on with nothing between when it fits.
59317
+ * it fits on no line at all, or as the first word of a block not in the room its indent leaves. A
59318
+ * break inside a word stands before it with no width: the line ends there with the `-` of a soft
59319
+ * hyphen, and the word goes on with nothing between when it fits.
58779
59320
  *
58780
59321
  * @param builder - The lines built so far.
58781
59322
  * @param token - The word to place.
@@ -58786,11 +59327,11 @@ function breakWord(builder, token, wrap, metrics) {
58786
59327
  function placeWord(builder, token, pending, wrap, metrics) {
58787
59328
  const space = pending?.kind === "space" ? pending : void 0;
58788
59329
  const lead = space?.width ?? 0;
58789
- if (builder.runs.length > 0 && builder.width + lead + token.width + token.tail > wrap) {
59330
+ if (builder.runs.length > 0 && builder.indent + builder.width + lead + token.width + token.tail > wrap) {
58790
59331
  if (pending?.kind === "soft") add(builder, pending);
58791
59332
  commit(builder);
58792
59333
  } else if (space !== void 0) add(builder, space);
58793
- if (token.width <= wrap) add(builder, token);
59334
+ if (builder.indent + token.width <= wrap) add(builder, token);
58794
59335
  else breakWord(builder, token, wrap, metrics);
58795
59336
  }
58796
59337
  /**
@@ -58807,7 +59348,8 @@ function wrapTokens(tokens, metrics, wrap) {
58807
59348
  const builder = {
58808
59349
  lines: [],
58809
59350
  runs: [],
58810
- width: 0
59351
+ width: 0,
59352
+ indent: metrics.style.textIndent ?? 0
58811
59353
  };
58812
59354
  let pending;
58813
59355
  for (const token of tokens) {
@@ -58847,9 +59389,42 @@ function widestWord(tokens) {
58847
59389
  return widest;
58848
59390
  }
58849
59391
  /**
59392
+ * The narrowest line the first word of a block stands on whole after the indent: the word, the
59393
+ * `-` a break after it draws, and the indent. 0 for a block whose first line holds no word.
59394
+ *
59395
+ * @param tokens - The tokens of the block.
59396
+ * @param indent - The `textIndent` of the style.
59397
+ * @returns The width in reference pixels.
59398
+ * @example
59399
+ * ```ts
59400
+ * firstWord([{ kind: "word", runs: [], width: 50, tail: 0 }], 45); // 95
59401
+ * ```
59402
+ */
59403
+ function firstWord(tokens, indent) {
59404
+ for (const token of tokens) {
59405
+ if (token.kind === "break") return 0;
59406
+ if (token.kind === "word") return token.width + token.tail + indent;
59407
+ }
59408
+ return 0;
59409
+ }
59410
+ /**
59411
+ * Tells whether a block of this many lines is evened out: 2 to 6, as Chrome.
59412
+ *
59413
+ * @param count - The number of greedy lines.
59414
+ * @returns True when the balance searches a narrower width.
59415
+ * @example
59416
+ * ```ts
59417
+ * isBalanced(7); // false: past six lines a block keeps its greedy lines
59418
+ * ```
59419
+ */
59420
+ function isBalanced(count) {
59421
+ return count >= 2 && count <= BALANCE_MAX_LINES;
59422
+ }
59423
+ /**
58850
59424
  * Evens the greedy lines of a balanced style: the narrowest width in `[widest word, wrap]` that
58851
- * keeps their number, found in 16 halvings, and the lines at that width. A block of one line or of
58852
- * more than six, or with a word that does not fit the wrap whole, keeps its greedy lines.
59425
+ * keeps their number, found in 16 halvings, and the lines at that width. The first word stands
59426
+ * whole after the indent at every width tried. A block of one line or of more than six, or with
59427
+ * a word that does not fit the wrap whole, keeps its greedy lines.
58853
59428
  *
58854
59429
  * @param tokens - The tokens of the block, as the greedy pass read them.
58855
59430
  * @param greedy - The greedy lines at the wrap.
@@ -58859,9 +59434,10 @@ function widestWord(tokens) {
58859
59434
  */
58860
59435
  function balanceLines(tokens, greedy, metrics, wrap) {
58861
59436
  const count = greedy.length;
58862
- let low = widestWord(tokens);
59437
+ if (!isBalanced(count)) return greedy;
59438
+ let low = Math.max(widestWord(tokens), firstWord(tokens, metrics.style.textIndent ?? 0));
58863
59439
  let high = wrap;
58864
- if (count < 2 || count > BALANCE_MAX_LINES || low >= high) return greedy;
59440
+ if (low >= high) return greedy;
58865
59441
  for (let step = 0; step < BALANCE_STEPS; step += 1) {
58866
59442
  const middle = (low + high) / 2;
58867
59443
  if (wrapTokens(tokens, metrics, middle).length <= count) high = middle;
@@ -58891,11 +59467,14 @@ function layoutWrapped(runs, metrics, wrap) {
58891
59467
  */
58892
59468
  function onceOnly(options) {
58893
59469
  const seen = emptyKeys();
58894
- return { warn: (key, message, data) => {
58895
- if (seen.has(key)) return;
58896
- seen.add(key);
58897
- options.warn(key, message, data);
58898
- } };
59470
+ return {
59471
+ ...options,
59472
+ warn: (key, message, data) => {
59473
+ if (seen.has(key)) return;
59474
+ seen.add(key);
59475
+ options.warn(key, message, data);
59476
+ }
59477
+ };
58899
59478
  }
58900
59479
  /**
58901
59480
  * Creates the empty key set of one layout, for the same reason as `emptyAdvances`.
@@ -58923,21 +59502,22 @@ function wrapOf(style, box) {
58923
59502
  return box > 0 ? box + BOX_SLACK : void 0;
58924
59503
  }
58925
59504
  /**
58926
- * Lays a block of runs out: the lines, the width of the widest one and the total height. The
58927
- * alignment of the style changes nothing here; it moves the lines when they are drawn. A style
58928
- * with `wrap: "box"` wraps at `box`, the width `ui` laid its text element out at, and is one line
58929
- * without one; any other style ignores `box`.
59505
+ * Lays a block of runs out: the lines with their boxes, the width of the widest one and the total
59506
+ * height. The alignment of the style changes nothing here; it moves the lines when they are
59507
+ * drawn. A style with `wrap: "box"` wraps at `box`, the width `ui` laid its text element out at,
59508
+ * and is one line without one; any other style ignores `box`. `options` carries the style table
59509
+ * and the bold looks a run in a span or in `<b>` takes its look from.
58930
59510
  *
58931
59511
  * @param runs - What `parseTags` made of the resolved string.
58932
59512
  * @param style - The style of the label.
58933
59513
  * @param tables - The advance tables that are loaded, by font key.
58934
- * @param options - Where a warning goes.
59514
+ * @param options - Where a warning goes, and the styles and bold looks a run may take.
58935
59515
  * @param box - The width a `"box"` style wraps at, in reference pixels; 0 for none.
58936
59516
  * @returns The lines and the size of the block in reference pixels.
58937
59517
  * @example
58938
59518
  * ```ts
58939
59519
  * layoutRuns([], bodyStyle, new Map(), { warn: () => undefined });
58940
- * // { lines: [{ runs: [], width: 0 }], width: 0, height: 38.4 }
59520
+ * // { lines: [{ runs: [], width: 0, height: 38.4, baseline: 25.6 }], width: 0, height: 38.4 }
58941
59521
  * ```
58942
59522
  */
58943
59523
  function layoutRuns(runs, style, tables, options, box = 0) {
@@ -58948,167 +59528,14 @@ function layoutRuns(runs, style, tables, options, box = 0) {
58948
59528
  tables,
58949
59529
  options: once
58950
59530
  }, wrap);
59531
+ boxLines(lines, style, tables, once);
58951
59532
  let width = 0;
58952
59533
  for (const line of lines) width = Math.max(width, line.width);
58953
59534
  return {
58954
59535
  lines,
58955
59536
  width,
58956
- height: lines.length * lineHeightOf(style, tables)
58957
- };
58958
- }
58959
- //#endregion
58960
- //#region src/plugins/text/tags.ts
58961
- /** Matches an opening colour tag. Six hex digits: `#rgb` is not accepted. */
58962
- const COLOR_TAG = /^color=#([\da-f]{6})$/i;
58963
- /** Matches an inline icon tag, which has no closing tag. */
58964
- const ICON_TAG = /^icon=(\S+)$/;
58965
- /**
58966
- * Reads an opening tag.
58967
- *
58968
- * @param body - What stood between the angle brackets.
58969
- * @returns The tag, or `undefined` when it is not one this grammar knows.
58970
- * @example
58971
- * ```ts
58972
- * openTag("color=#ff0000"); // { name: "color", color: 16711680 }
58973
- * ```
58974
- */
58975
- function openTag(body) {
58976
- if (body === "b" || body === "i") return {
58977
- name: body,
58978
- color: void 0
58979
- };
58980
- const colour = COLOR_TAG.exec(body);
58981
- if (colour === null) return void 0;
58982
- return {
58983
- name: "color",
58984
- color: Number.parseInt(colour[1] ?? "0", 16)
58985
- };
58986
- }
58987
- /**
58988
- * Appends text to the runs, merging it into the last one when the flags are the same.
58989
- *
58990
- * @param runs - The runs built so far.
58991
- * @param text - The characters to append.
58992
- * @param stack - The tags that are open around them.
58993
- */
58994
- function pushText(runs, text, stack) {
58995
- let color;
58996
- for (const open of stack) if (open.name === "color") color = open.color;
58997
- const piece = {
58998
- kind: "text",
58999
- text,
59000
- bold: stack.some((open) => open.name === "b"),
59001
- italic: stack.some((open) => open.name === "i"),
59002
- color
59003
- };
59004
- const last = runs.at(-1);
59005
- if (last !== void 0 && last.kind === "text" && last.bold === piece.bold && last.italic === piece.italic && last.color === piece.color) {
59006
- last.text += text;
59007
- return;
59008
- }
59009
- runs.push(piece);
59010
- }
59011
- /**
59012
- * Reports one source string once, whatever is wrong with it.
59013
- *
59014
- * @param state - The parse in progress.
59015
- * @param message - The log event.
59016
- * @param tag - The tag that was wrong.
59017
- */
59018
- function complain(state, message, tag) {
59019
- if (state.warned) return;
59020
- state.warned = true;
59021
- state.warn(`tag:${state.source}`, message, {
59022
- tag,
59023
- text: state.source
59024
- });
59025
- }
59026
- /**
59027
- * Writes what was read so far into a run.
59028
- *
59029
- * @param state - The parse in progress.
59030
- */
59031
- function flush(state) {
59032
- if (state.buffer.length === 0) return;
59033
- pushText(state.runs, state.buffer, state.stack);
59034
- state.buffer = "";
59035
- }
59036
- /**
59037
- * Applies one tag: an icon run, an opening tag, a matching close, or, when it is none of those,
59038
- * literal text and one warning.
59039
- *
59040
- * @param state - The parse in progress.
59041
- * @param body - What stood between the angle brackets.
59042
- */
59043
- function applyTag(state, body) {
59044
- const icon = ICON_TAG.exec(body);
59045
- if (icon !== null) {
59046
- flush(state);
59047
- state.runs.push({
59048
- kind: "icon",
59049
- key: icon[1] ?? ""
59050
- });
59051
- return;
59052
- }
59053
- const open = openTag(body);
59054
- if (open !== void 0) {
59055
- flush(state);
59056
- state.stack.push(open);
59057
- return;
59058
- }
59059
- const closes = body.startsWith("/");
59060
- const at = closes ? state.stack.map((entry) => entry.name).lastIndexOf(body.slice(1)) : -1;
59061
- if (at !== -1) {
59062
- flush(state);
59063
- state.stack.splice(at, 1);
59064
- return;
59065
- }
59066
- complain(state, closes ? "text: stray closing tag" : "text: unknown tag", body);
59067
- state.buffer += `<${body}>`;
59068
- }
59069
- /**
59070
- * Turns a resolved string into runs of glyphs and inline icons. Everything the grammar does not
59071
- * know stays visible: the tag is kept as literal text and the source is reported once.
59072
- *
59073
- * @param source - The resolved string, as it was written or formatted.
59074
- * @param warn - Called at most once per source, with the key `tag:<source>`.
59075
- * @returns The runs, in reading order, with equal neighbours merged.
59076
- * @example
59077
- * ```ts
59078
- * parseTags("<b>a</b>b", () => undefined);
59079
- * // [{ kind: "text", text: "a", bold: true, italic: false, color: undefined },
59080
- * // { kind: "text", text: "b", bold: false, italic: false, color: undefined }]
59081
- * ```
59082
- */
59083
- function parseTags(source, warn) {
59084
- const state = {
59085
- source,
59086
- runs: [],
59087
- stack: [],
59088
- buffer: "",
59089
- warned: false,
59090
- warn
59537
+ height: blockHeight(lines)
59091
59538
  };
59092
- let index = 0;
59093
- while (index < source.length) {
59094
- const char = source[index] ?? "";
59095
- if (char === "\\" && source[index + 1] === "<") {
59096
- state.buffer += "<";
59097
- index += 2;
59098
- continue;
59099
- }
59100
- const close = char === "<" ? source.indexOf(">", index + 1) : -1;
59101
- if (close === -1) {
59102
- state.buffer += char;
59103
- index += 1;
59104
- continue;
59105
- }
59106
- applyTag(state, source.slice(index + 1, close));
59107
- index = close + 1;
59108
- }
59109
- flush(state);
59110
- if (state.stack.length > 0) complain(state, "text: unclosed tag", state.stack[0]?.name ?? "");
59111
- return state.runs;
59112
59539
  }
59113
59540
  //#endregion
59114
59541
  //#region src/plugins/text/resolve.ts
@@ -59118,13 +59545,17 @@ const CACHE_SEPARATOR = String.fromCodePoint(0);
59118
59545
  const CACHE_LIMIT = 1024;
59119
59546
  /** How every inline icon tag starts. A resolved text without it holds no icon. */
59120
59547
  const ICON_OPEN = "<icon=";
59548
+ /** How every span tag starts. A resolved text without it holds no span. */
59549
+ const SPAN_OPEN = "<span";
59550
+ /** How every bold tag starts. A resolved text without it holds no bold run. */
59551
+ const BOLD_OPEN = "<b>";
59121
59552
  /** The name the system is registered under; it shows up in a world error message. */
59122
59553
  const TEXT_SYSTEM_NAME = "text.resolve";
59123
59554
  /**
59124
59555
  * Writes one dev warning per key. Every warning of this plugin goes through here, so a font, a
59125
59556
  * style, a glyph or a bad tag is reported once and never floods a frame.
59126
59557
  *
59127
- * @param ctx - Domain context of the text plugin.
59558
+ * @param ctx - Kernel or domain context of the text plugin.
59128
59559
  * @param key - What makes this warning unique.
59129
59560
  * @param message - The log event.
59130
59561
  * @param data - What to log with it.
@@ -59137,7 +59568,7 @@ function warnOnce(ctx, key, message, data) {
59137
59568
  /**
59138
59569
  * The warning the pure modules are handed, bound to this app's `warned` set.
59139
59570
  *
59140
- * @param ctx - Domain context of the text plugin.
59571
+ * @param ctx - Kernel or domain context of the text plugin.
59141
59572
  * @returns A warning that repeats nothing.
59142
59573
  */
59143
59574
  function warnFor(ctx) {
@@ -59168,9 +59599,42 @@ function wrapsAtBox(ctx, styleName) {
59168
59599
  return (ctx.state.styles.get(styleName) ?? ctx.state.styles.get("body"))?.wrap === "box";
59169
59600
  }
59170
59601
  /**
59602
+ * What the pure layout and the draw are handed: the warning, the style table a span borrows its
59603
+ * look from, and the bold looks. Built once per domain context, so a draw builds none.
59604
+ *
59605
+ * @param ctx - Kernel context of the text plugin.
59606
+ * @returns The layout options of this app.
59607
+ */
59608
+ function layoutOptionsOf(ctx) {
59609
+ return {
59610
+ warn: warnFor(ctx),
59611
+ styles: ctx.state.styles,
59612
+ looks: ctx.state.looks
59613
+ };
59614
+ }
59615
+ /**
59616
+ * Reports the first span of a resolved string whose key no style has, once per string. Such a
59617
+ * run is laid out and drawn in the look of the paragraph.
59618
+ *
59619
+ * @param ctx - Domain context of the text plugin.
59620
+ * @param resolved - The tagged string.
59621
+ * @param runs - What `parseTags` made of it.
59622
+ */
59623
+ function warnUnknownSpan(ctx, resolved, runs) {
59624
+ for (const run of runs) {
59625
+ if (run.span === void 0 || ctx.state.styles.has(run.span)) continue;
59626
+ warnOnce(ctx, `span:${resolved}`, "text: unknown span style", {
59627
+ style: run.span,
59628
+ text: resolved
59629
+ });
59630
+ return;
59631
+ }
59632
+ }
59633
+ /**
59171
59634
  * The layout of one resolved string in one style, from the cache or freshly laid out. The cache
59172
59635
  * is what makes `measure` cheap enough for `ui` to ask per invalidation. A `"box"` style with a
59173
- * box is cached per width too; any other style ignores the box and keeps one layout.
59636
+ * box is cached per width too; any other style ignores the box and keeps one layout. A span whose
59637
+ * key no style has is reported here, where the string is in hand, once per string.
59174
59638
  *
59175
59639
  * @param ctx - Domain context of the text plugin.
59176
59640
  * @param resolved - The tagged string.
@@ -59183,16 +59647,28 @@ function layoutFor(ctx, resolved, styleName, box = 0) {
59183
59647
  const key = width > 0 ? `${styleName}${CACHE_SEPARATOR}${width}${CACHE_SEPARATOR}${resolved}` : `${styleName}${CACHE_SEPARATOR}${resolved}`;
59184
59648
  const hit = ctx.state.cache.get(key);
59185
59649
  if (hit !== void 0) return hit;
59186
- const warn = warnFor(ctx);
59187
- const layout = layoutRuns(parseTags(resolved, warn), styleOf$1(ctx, styleName), ctx.state.tables, { warn }, width);
59188
- if (ctx.state.cache.size >= CACHE_LIMIT) {
59189
- const oldest = ctx.state.cache.keys().next().value;
59190
- if (oldest !== void 0) ctx.state.cache.delete(oldest);
59191
- }
59192
- ctx.state.cache.set(key, layout);
59650
+ const options = ctx.layoutOptions;
59651
+ const runs = parseTags(resolved, options.warn);
59652
+ if (resolved.includes(SPAN_OPEN)) warnUnknownSpan(ctx, resolved, runs);
59653
+ const layout = layoutRuns(runs, styleOf$1(ctx, styleName), ctx.state.tables, options, width);
59654
+ keepLayout(ctx.state.cache, key, layout);
59193
59655
  return layout;
59194
59656
  }
59195
59657
  /**
59658
+ * Keeps a fresh layout in the cache, the oldest one dropped first when the cache is full.
59659
+ *
59660
+ * @param cache - The layout cache of the plugin.
59661
+ * @param key - The style, the box and the string the layout is for.
59662
+ * @param layout - The layout.
59663
+ */
59664
+ function keepLayout(cache, key, layout) {
59665
+ if (cache.size >= CACHE_LIMIT) {
59666
+ const oldest = cache.keys().next().value;
59667
+ if (oldest !== void 0) cache.delete(oldest);
59668
+ }
59669
+ cache.set(key, layout);
59670
+ }
59671
+ /**
59196
59672
  * Whether the font of a style has a glyph for one character, the lookup Pixi draws by: a
59197
59673
  * character the font lacks is drawn as nothing and measures 0 wide. While the font is not loaded
59198
59674
  * every character counts, as the fallback measures it.
@@ -59473,20 +59949,63 @@ function boxMoved(ctx, seen, text) {
59473
59949
  return false;
59474
59950
  }
59475
59951
  /**
59476
- * Keeps the measured size of a label: made once, then overwritten in place.
59952
+ * Drops every cached layout and moves the epoch, so a layout a label kept is stale too. Every
59953
+ * place that throws the layouts away goes through here.
59954
+ *
59955
+ * @param state - The plugin state.
59956
+ */
59957
+ function dropLayouts(state) {
59958
+ state.cache.clear();
59959
+ state.epoch += 1;
59960
+ }
59961
+ /**
59962
+ * Lays out what a label shows and keeps its measured size and that layout, with what it was laid
59963
+ * out from, so the draw of the label in the same frame takes it. Both records are made once per
59964
+ * label, then overwritten in place.
59477
59965
  *
59478
59966
  * @param ctx - Domain context of the text plugin.
59479
59967
  * @param entity - The entity.
59480
- * @param layout - The layout of what the label shows now.
59968
+ * @param resolved - The string the label shows now.
59969
+ * @param style - The style name it shows it in.
59970
+ * @param box - The box of its `Text`.
59481
59971
  */
59482
- function keepSize(ctx, entity, layout) {
59972
+ function keepSize(ctx, entity, resolved, style, box) {
59973
+ const layout = layoutFor(ctx, resolved, style, box);
59483
59974
  const size = ctx.state.measured.get(entity);
59484
- if (size === void 0) {
59485
- ctx.state.measured.set(entity, sizeOf(layout));
59975
+ if (size === void 0) ctx.state.measured.set(entity, sizeOf(layout));
59976
+ else {
59977
+ size.width = layout.width;
59978
+ size.height = layout.height;
59979
+ }
59980
+ const shown = ctx.state.shown.get(entity);
59981
+ if (shown === void 0) {
59982
+ ctx.state.shown.set(entity, {
59983
+ resolved,
59984
+ style,
59985
+ box,
59986
+ epoch: ctx.state.epoch,
59987
+ layout
59988
+ });
59486
59989
  return;
59487
59990
  }
59488
- size.width = layout.width;
59489
- size.height = layout.height;
59991
+ shown.resolved = resolved;
59992
+ shown.style = style;
59993
+ shown.box = box;
59994
+ shown.epoch = ctx.state.epoch;
59995
+ shown.layout = layout;
59996
+ }
59997
+ /**
59998
+ * The layout of a value a label shows: the one the text step kept for its entity when it was laid
59999
+ * out from the same string, style and box under the same cache epoch, else from the cache.
60000
+ *
60001
+ * @param ctx - Domain context of the text plugin.
60002
+ * @param entity - The entity of the label, when the draw knows it.
60003
+ * @param value - The component value to draw.
60004
+ * @returns The layout.
60005
+ */
60006
+ function shownLayoutOf(ctx, entity, value) {
60007
+ const shown = entity === void 0 ? void 0 : ctx.state.shown.get(entity);
60008
+ return shown !== void 0 && shown.epoch === ctx.state.epoch && shown.resolved === value.resolved && shown.style === value.style && shown.box === value.box ? shown.layout : layoutFor(ctx, value.resolved, value.style, value.box);
59490
60009
  }
59491
60010
  /**
59492
60011
  * Tells whether a bound label already shows what its value would build: the same unit, style and
@@ -59517,14 +60036,27 @@ function isShown(seen, text, unit, worded, frame) {
59517
60036
  function showBound(ctx, entity, text, next, value, style = text.style) {
59518
60037
  const restyled = style !== text.style;
59519
60038
  const changed = restyled || next !== text.resolved;
59520
- if (changed) {
59521
- ctx.deps.world.ecs.set(entity, Text, restyled ? {
59522
- resolved: next,
59523
- style
59524
- } : { resolved: next });
59525
- if (value !== void 0 && text.bind !== void 0 && isCountdownLeft(text.bind)) ctx.deps.world.ecs.set(entity, Countdown, { left: value });
59526
- }
59527
- if (changed || !ctx.state.measured.has(entity)) keepSize(ctx, entity, layoutFor(ctx, next, style, text.box));
60039
+ if (changed) writeBound(ctx, entity, text, next, value, restyled ? style : void 0);
60040
+ if (changed || !ctx.state.measured.has(entity)) keepSize(ctx, entity, next, style, text.box);
60041
+ }
60042
+ /**
60043
+ * Writes the new string of a bound label, its new style when a named format picked another, and
60044
+ * for a countdown the time left.
60045
+ *
60046
+ * @param ctx - Domain context of the text plugin.
60047
+ * @param entity - The entity.
60048
+ * @param text - Its component value.
60049
+ * @param next - The string the label shows now.
60050
+ * @param value - The bound number, the time left for a countdown.
60051
+ * @param style - The style a named format picked, when it is another than `Text.style`.
60052
+ */
60053
+ function writeBound(ctx, entity, text, next, value, style) {
60054
+ ctx.deps.world.ecs.set(entity, Text, style === void 0 ? { resolved: next } : {
60055
+ resolved: next,
60056
+ style
60057
+ });
60058
+ if (value === void 0 || text.bind === void 0 || !isCountdownLeft(text.bind)) return;
60059
+ ctx.deps.world.ecs.set(entity, Countdown, { left: value });
59528
60060
  }
59529
60061
  /**
59530
60062
  * Writes the string a bound label already shows once more, and measures it again. A mark on a
@@ -59538,7 +60070,7 @@ function showBound(ctx, entity, text, next, value, style = text.style) {
59538
60070
  */
59539
60071
  function showAgain(ctx, entity, text) {
59540
60072
  ctx.deps.world.ecs.set(entity, Text, { resolved: text.resolved });
59541
- keepSize(ctx, entity, layoutFor(ctx, text.resolved, text.style, text.box));
60073
+ keepSize(ctx, entity, text.resolved, text.style, text.box);
59542
60074
  }
59543
60075
  /**
59544
60076
  * Reports a bound label whose style is not a digits style, once per style. An unknown style name
@@ -59589,9 +60121,9 @@ function stepBound(ctx, entity, text, bind, frame) {
59589
60121
  }
59590
60122
  /**
59591
60123
  * One frame of a label whose bind names a format a feature registered. Its unit is the whole value.
59592
- * While that, the locale, the bind and the style stand the frame is reads and compares: the format
59593
- * is not called, a mark included, and nothing is kept. Else it is asked once, and its answer is
59594
- * written only when it differs. The format picks the style, so no style is checked for digits. A
60124
+ * While the whole value, the locale, the bind and the style stand still, the frame only reads and
60125
+ * compares: the format is not called, even for a marked label, and nothing is kept. Else the
60126
+ * format is asked once, and its answer is written only when it differs. The format picks the style, so no style is checked for digits. A
59595
60127
  * bound field that holds no number shows nothing, as under a built-in format.
59596
60128
  *
59597
60129
  * @param ctx - Domain context of the text plugin.
@@ -59631,9 +60163,9 @@ function stepNamed(ctx, entity, text, bind, format, value, frame) {
59631
60163
  * @param marked - Whether the label was marked this frame.
59632
60164
  */
59633
60165
  function standStill(ctx, entity, text, seen, marked) {
60166
+ if (!marked && !boxMoved(ctx, seen, text)) return;
59634
60167
  if (marked) showAgain(ctx, entity, text);
59635
- else if (boxMoved(ctx, seen, text)) keepSize(ctx, entity, layoutFor(ctx, text.resolved, text.style, text.box));
59636
- else return;
60168
+ else keepSize(ctx, entity, text.resolved, text.style, text.box);
59637
60169
  seen.box = text.box;
59638
60170
  }
59639
60171
  /**
@@ -59667,7 +60199,7 @@ function stepText(ctx, entity, text, frame) {
59667
60199
  return;
59668
60200
  }
59669
60201
  if (!isStale(ctx, entity, text, frame)) return;
59670
- keepSize(ctx, entity, layoutFor(ctx, resolveContent(ctx, entity, text), text.style, text.box));
60202
+ keepSize(ctx, entity, resolveContent(ctx, entity, text), text.style, text.box);
59671
60203
  ctx.state.dirty.delete(entity);
59672
60204
  remember(ctx, entity, text, frame);
59673
60205
  }
@@ -59841,10 +60373,11 @@ function markDirty(ctx, keep = () => true) {
59841
60373
  return marked;
59842
60374
  }
59843
60375
  /**
59844
- * Tells whether a label is drawn with one of the asset keys: a font its style names, or an inline
59845
- * icon of its resolved text. The text is read through the tag grammar, the way it is drawn, so an
59846
- * escaped `\<icon=…>` is text and not an icon. A text that holds no `<icon=` at all is not read:
59847
- * most labels have no icon, and this runs for every label of a swap.
60376
+ * Tells whether a label is drawn with one of the asset keys: a font its style names, an inline
60377
+ * icon of its resolved text, or the font a run of it draws with in its look, a span's or a bold
60378
+ * one. The text is read through the tag grammar, the way it is drawn, so an escaped `\<icon=…>`
60379
+ * is text and not an icon. A text that holds no icon, no span and, for a style with `boldStyle`,
60380
+ * no bold tag is not read: most labels have none, and this runs for every label of a swap.
59848
60381
  *
59849
60382
  * @param ctx - Domain context of the text plugin.
59850
60383
  * @param text - The component value of the label.
@@ -59858,8 +60391,24 @@ function drawsWith(ctx, text, keys) {
59858
60391
  style.bold,
59859
60392
  style.italic
59860
60393
  ].some((font) => font !== void 0 && keys.includes(font))) return true;
59861
- if (!text.resolved.includes(ICON_OPEN)) return false;
59862
- return parseTags(text.resolved, warnFor(ctx)).some((run) => run.kind === "icon" && keys.includes(run.key));
60394
+ const resolved = text.resolved;
60395
+ if (!(style.boldStyle !== void 0 && resolved.includes(BOLD_OPEN)) && !resolved.includes(ICON_OPEN) && !resolved.includes(SPAN_OPEN)) return false;
60396
+ return parseTags(resolved, ctx.layoutOptions.warn).some((run) => runDrawsWith(ctx, style, run, keys));
60397
+ }
60398
+ /**
60399
+ * Tells whether one run is drawn with one of the asset keys: an icon of that key, or glyphs in a
60400
+ * font of that key in the look of the run.
60401
+ *
60402
+ * @param ctx - Domain context of the text plugin.
60403
+ * @param style - The style of the label.
60404
+ * @param run - One run of its text.
60405
+ * @param keys - The asset keys to look for.
60406
+ * @returns True when the run draws with one of `keys`.
60407
+ */
60408
+ function runDrawsWith(ctx, style, run, keys) {
60409
+ if (run.kind === "icon") return keys.includes(run.key);
60410
+ const look = lookIn(style, run, ctx.layoutOptions);
60411
+ return keys.includes(fontOfRun(look, run));
59863
60412
  }
59864
60413
  /**
59865
60414
  * Forgets an entity whose `Text` left. Works on the state alone, because it is also what the
@@ -59871,6 +60420,7 @@ function drawsWith(ctx, text, keys) {
59871
60420
  function forgetText(state, entity) {
59872
60421
  state.seen.delete(entity);
59873
60422
  state.measured.delete(entity);
60423
+ state.shown.delete(entity);
59874
60424
  state.dirty.delete(entity);
59875
60425
  }
59876
60426
  //#endregion
@@ -59954,7 +60504,7 @@ function releaseFonts(ctx, keys) {
59954
60504
  * @param ctx - Domain context of the text plugin.
59955
60505
  */
59956
60506
  function refresh(ctx) {
59957
- ctx.state.cache.clear();
60507
+ dropLayouts(ctx.state);
59958
60508
  markDirty(ctx);
59959
60509
  }
59960
60510
  /**
@@ -60019,29 +60569,51 @@ function reinstallFonts(ctx, fonts, reload) {
60019
60569
  */
60020
60570
  function applyReplaced(ctx, keys, reload = reloadPage) {
60021
60571
  const fonts = keys.filter((key) => ctx.state.fontKeys.has(key));
60022
- if (fonts.length > 0) ctx.state.cache.clear();
60572
+ if (fonts.length > 0) dropLayouts(ctx.state);
60023
60573
  if (!reinstallFonts(ctx, fonts, reload)) return;
60024
60574
  if (markDirty(ctx, (text) => drawsWith(ctx, text, keys)) === 0) return;
60025
60575
  ctx.state.generation += 1;
60026
60576
  }
60027
60577
  /**
60028
- * Where a line starts inside the widest one.
60578
+ * The width the lines of a block align in, and its anchor moves by: the widest line, or for a
60579
+ * `"box"` style laid out at a box the box when it is wider (F153). `measure` answers the widest
60580
+ * line either way.
60029
60581
  *
60030
60582
  * @param style - The style of the label.
60031
- * @param layout - The block the line belongs to.
60583
+ * @param layout - The laid-out block.
60584
+ * @param box - The box the label was laid out at; 0 for none.
60585
+ * @returns The width in reference pixels.
60586
+ * @example
60587
+ * ```ts
60588
+ * alignWidthOf({ ...bodyStyle, wrap: "box" }, { lines: [], width: 200, height: 0 }, 300); // 300
60589
+ * ```
60590
+ */
60591
+ function alignWidthOf(style, layout, box) {
60592
+ return style.wrap === "box" && box > 0 ? Math.max(layout.width, box) : layout.width;
60593
+ }
60594
+ /**
60595
+ * Where a line starts inside the width the block aligns in. The first line of an indented block
60596
+ * counts its indent in its width, so it aligns in the room after the indent.
60597
+ *
60598
+ * @param style - The style of the label.
60599
+ * @param width - The width the block aligns in.
60032
60600
  * @param line - The line.
60033
60601
  * @returns The offset in reference pixels.
60602
+ * @example
60603
+ * ```ts
60604
+ * alignOffset({ ...bodyStyle, align: "center" }, 300, { runs: [], width: 200, height: 0, baseline: 0 }); // 50
60605
+ * ```
60034
60606
  */
60035
- function alignOffset(style, layout, line) {
60607
+ function alignOffset(style, width, line) {
60036
60608
  if (style.align === "left") return 0;
60037
- const slack = layout.width - line.width;
60609
+ const slack = width - line.width;
60038
60610
  return style.align === "center" ? slack / 2 : slack;
60039
60611
  }
60040
60612
  /**
60041
- * The rings of copies one run is drawn over, bottom first: the outline of a stroked style, then the
60042
- * synthetic bold in the fill when the style names no bold font.
60613
+ * The rings of copies one run is drawn over, bottom first: the outline of a stroked look, then the
60614
+ * synthetic bold in the fill when the look names no bold font.
60043
60615
  *
60044
- * @param style - The style of the label.
60616
+ * @param style - The look of the run.
60045
60617
  * @param run - The run to draw.
60046
60618
  * @param fill - The colour the run is filled with.
60047
60619
  * @returns The rings, none for a plain run.
@@ -60083,34 +60655,35 @@ function iconTexture(ctx, pixi, run) {
60083
60655
  return ctx.deps.assets.texture(run.key) ?? pixi.Texture.EMPTY;
60084
60656
  }
60085
60657
  /**
60086
- * Sizes the sprite of one inline icon square at the line height and puts it where the icon
60658
+ * Sizes the sprite of one inline icon square at the line of its look and puts it where the icon
60087
60659
  * starts.
60088
60660
  *
60089
60661
  * @param ctx - Domain context of the text plugin.
60090
60662
  * @param sprite - The sprite of the icon.
60091
- * @param style - The style of the label.
60092
- * @param at - Where the icon starts, in the local space of the block.
60663
+ * @param style - The look of the icon.
60664
+ * @param x - Where the icon starts across, in the local space of the block.
60665
+ * @param y - Where it starts down.
60093
60666
  */
60094
- function placeIcon(ctx, sprite, style, at) {
60667
+ function placeIcon(ctx, sprite, style, x, y) {
60095
60668
  const side = lineHeightOf(style, ctx.state.tables);
60096
60669
  sprite.width = side;
60097
60670
  sprite.height = side;
60098
- sprite.x = at.x;
60099
- sprite.y = at.y;
60671
+ sprite.x = x;
60672
+ sprite.y = y;
60100
60673
  }
60101
60674
  /**
60102
- * Builds the sprite of one inline icon, square at the line height.
60675
+ * Builds the sprite of one inline icon, square at the line of its look.
60103
60676
  *
60104
60677
  * @param ctx - Domain context of the text plugin.
60105
60678
  * @param pixi - The Pixi module the renderer loaded.
60106
60679
  * @param run - The icon to draw.
60107
- * @param style - The style of the label.
60680
+ * @param style - The look of the icon.
60108
60681
  * @param at - Where the icon starts, in the local space of the block.
60109
60682
  * @returns The sprite.
60110
60683
  */
60111
60684
  function buildIcon(ctx, pixi, run, style, at) {
60112
60685
  const sprite = new pixi.Sprite(iconTexture(ctx, pixi, run));
60113
- placeIcon(ctx, sprite, style, at);
60686
+ placeIcon(ctx, sprite, style, at.x, at.y);
60114
60687
  return sprite;
60115
60688
  }
60116
60689
  /**
@@ -60119,7 +60692,7 @@ function buildIcon(ctx, pixi, run, style, at) {
60119
60692
  *
60120
60693
  * @param pixi - The Pixi module the renderer loaded.
60121
60694
  * @param run - The glyphs to draw.
60122
- * @param style - The style of the label.
60695
+ * @param style - The look of the run.
60123
60696
  * @param fill - The colour of the glyphs.
60124
60697
  * @param at - Where the run starts, in the local space of the block.
60125
60698
  * @returns The display object.
@@ -60145,8 +60718,8 @@ function buildGlyphs(pixi, run, style, fill, at) {
60145
60718
  *
60146
60719
  * @param pixi - The Pixi module the renderer loaded.
60147
60720
  * @param run - The glyphs that cast the shadow.
60148
- * @param style - The style of the label.
60149
- * @param shadow - The shadow of the style.
60721
+ * @param style - The look of the run.
60722
+ * @param shadow - The shadow of the look.
60150
60723
  * @param at - Where the run starts, in the local space of the block.
60151
60724
  * @returns The display object, to be drawn under the run.
60152
60725
  */
@@ -60189,7 +60762,7 @@ function ringSpots(ring, at) {
60189
60762
  *
60190
60763
  * @param pixi - The Pixi module the renderer loaded.
60191
60764
  * @param run - The glyphs the ring surrounds.
60192
- * @param style - The style of the label.
60765
+ * @param style - The look of the run.
60193
60766
  * @param ring - The width and colour of the ring.
60194
60767
  * @param at - Where the run starts, in the local space of the block.
60195
60768
  * @returns The copies, to be drawn under the run.
@@ -60202,32 +60775,13 @@ function buildRing(pixi, run, style, ring, at) {
60202
60775
  });
60203
60776
  }
60204
60777
  /**
60205
- * Where every object of one glyph run sits, in the order `buildRun` adds them: its shadow, the
60206
- * copies of its rings, then the run itself.
60207
- *
60208
- * @param style - The style of the label.
60209
- * @param run - The glyph run.
60210
- * @param at - Where the run starts, in the local space of the block.
60211
- * @returns One point per object.
60212
- */
60213
- function glyphSpots(style, run, at) {
60214
- const shadow = style.shadow;
60215
- const spots = shadow === void 0 ? [] : [{
60216
- x: at.x + shadow.dx,
60217
- y: at.y + shadow.dy
60218
- }];
60219
- for (const ring of ringsOf(style, run, run.color ?? style.fill)) spots.push(...ringSpots(ring, at));
60220
- spots.push(at);
60221
- return spots;
60222
- }
60223
- /**
60224
60778
  * Builds the Pixi objects of one run, bottom first: an icon is one sprite, and a glyph run is its
60225
- * shadow when the style has one, its outline and synthetic bold rings, then the glyphs.
60779
+ * shadow when its look has one, its outline and synthetic bold rings, then the glyphs.
60226
60780
  *
60227
60781
  * @param ctx - Domain context of the text plugin.
60228
60782
  * @param pixi - The Pixi module the renderer loaded.
60229
60783
  * @param run - The run to draw.
60230
- * @param style - The style of the label.
60784
+ * @param style - The look of the run.
60231
60785
  * @param at - Where the run starts, in the local space of the block.
60232
60786
  * @returns The display objects in drawing order.
60233
60787
  */
@@ -60254,53 +60808,143 @@ function isOutsideLayout(ctx, style, value) {
60254
60808
  return (value.box ?? 0) <= 0 && value.resolved !== "" && !ctx.state.laidOut.has(value.style);
60255
60809
  }
60256
60810
  /**
60257
- * The style and the laid-out block of one component value, under the generation of this moment.
60258
- * A `"box"` style wraps at the box `ui` wrote; with none it is one line, and a dev warning says
60259
- * so once per style unless a layout measured that style at a width (a label that fits its row).
60811
+ * The style one component value is drawn in. A `"box"` style wraps at the box `ui` wrote; with
60812
+ * none it is one line, and a dev warning says so once per style unless a layout measured that
60813
+ * style at a width (a label that fits its row).
60260
60814
  *
60261
60815
  * @param ctx - Domain context of the text plugin.
60262
60816
  * @param value - The component value.
60263
- * @returns What the container is filled from.
60817
+ * @returns The style.
60264
60818
  */
60265
- function labelOf(ctx, value) {
60819
+ function drawnStyleOf(ctx, value) {
60266
60820
  const style = styleOf$1(ctx, value.style);
60267
60821
  if (isOutsideLayout(ctx, style, value)) warnOnce(ctx, `wrap-box:${value.style}`, "text: wrap \"box\" outside layout", { style: value.style });
60822
+ return style;
60823
+ }
60824
+ /**
60825
+ * The style and the laid-out block of one component value, under the generation of this moment:
60826
+ * what a new container is filled from.
60827
+ *
60828
+ * @param ctx - Domain context of the text plugin.
60829
+ * @param value - The component value.
60830
+ * @param entity - The entity the label sits on, when the draw knows it.
60831
+ * @returns What the container is filled from.
60832
+ */
60833
+ function labelOf(ctx, value, entity) {
60268
60834
  return {
60269
- style,
60270
- layout: layoutFor(ctx, value.resolved, value.style, value.box),
60271
- generation: ctx.state.generation
60835
+ style: drawnStyleOf(ctx, value),
60836
+ layout: shownLayoutOf(ctx, entity, value),
60837
+ generation: ctx.state.generation,
60838
+ entity
60272
60839
  };
60273
60840
  }
60274
60841
  /**
60275
- * Calls `visit` with every run of a laid-out block and where it starts, anchored by the
60276
- * component, line after line. A run of glyphs starts half the leading lower, so the glyphs sit in
60277
- * the middle of a line taller or shorter than the font's; an icon starts on the line it fills.
60842
+ * The width of one run of a laid-out block: measured on its first draw and kept for the run.
60843
+ *
60844
+ * @param ctx - Domain context of the text plugin.
60845
+ * @param run - A run of a cached layout.
60846
+ * @param style - The style of the label.
60847
+ * @returns The width in reference pixels.
60848
+ */
60849
+ function widthOfRun(ctx, run, style) {
60850
+ const kept = ctx.state.runWidths.get(run);
60851
+ if (kept !== void 0) return kept;
60852
+ const width = measureRun(run, style, ctx.state.tables, ctx.layoutOptions);
60853
+ ctx.state.runWidths.set(run, width);
60854
+ return width;
60855
+ }
60856
+ /**
60857
+ * Calls `visit` with every run of a laid-out block, its look and where it starts, anchored by the
60858
+ * component, line after line. The line of a run's look stands so that the run's baseline is the
60859
+ * line's: a run of glyphs starts half its leading below the top of that line, so the glyphs sit in
60860
+ * the middle of a line taller or shorter than the font's, and an icon starts on the line it fills.
60861
+ * A run in a look of its own stands by the font it is drawn with, one in the paragraph's look by
60862
+ * the paragraph's font (`metricsFontOf`). In a line no run reaches past the paragraph's line every
60863
+ * run of the paragraph's look starts on the top of the line, as before lines had boxes. The first
60864
+ * line starts after the indent.
60278
60865
  *
60279
60866
  * @param ctx - Domain context of the text plugin.
60280
60867
  * @param label - The style and the laid-out block.
60281
- * @param anchor - The anchor of the component.
60282
- * @param visit - Called once per run, in reading order.
60868
+ * @param value - The component value: its anchor, and the box it was laid out at.
60869
+ * @param visit - Called once per run, in reading order: a module function, so no draw builds a
60870
+ * closure; it reaches the container through `state.cursor`.
60283
60871
  */
60284
- function eachRun(ctx, label, anchor, visit) {
60872
+ function eachRun(ctx, label, value, visit) {
60285
60873
  const { style, layout } = label;
60286
- const height = lineHeightOf(style, ctx.state.tables);
60287
- const leading = (height - fontLineOf(style, ctx.state.tables)) / 2;
60288
- const options = { warn: warnFor(ctx) };
60289
- const left = -anchor.x * layout.width;
60290
- let y = -anchor.y * layout.height;
60874
+ const tables = ctx.state.tables;
60875
+ const options = ctx.layoutOptions;
60876
+ const at = ctx.state.cursor.at;
60877
+ const width = alignWidthOf(style, layout, value.box ?? 0);
60878
+ const left = -value.anchor.x * width;
60879
+ let top = -value.anchor.y * layout.height;
60880
+ let indent = style.textIndent ?? 0;
60291
60881
  for (const line of layout.lines) {
60292
- let x = left + alignOffset(style, layout, line);
60882
+ let x = left + alignOffset(style, width, line) + indent;
60293
60883
  for (const run of line.runs) {
60294
- visit(run, {
60295
- x,
60296
- y: run.kind === "text" ? y + leading : y
60297
- });
60298
- x += measureRun(run, style, ctx.state.tables, options);
60884
+ const look = lookIn(style, run, options);
60885
+ const font = metricsFontOf(style, look, run);
60886
+ const leading = leadingOf(look, tables, font);
60887
+ const lift = line.baseline - (leading + ascentOf(look, tables, font));
60888
+ at[0] = x;
60889
+ at[1] = run.kind === "text" ? top + lift + leading : top + lift;
60890
+ visit(ctx, run, look);
60891
+ x += widthOfRun(ctx, run, style);
60299
60892
  }
60300
- y += height;
60893
+ top += line.height;
60894
+ indent = 0;
60301
60895
  }
60302
60896
  }
60303
60897
  /**
60898
+ * Points the draw cursor at a container before a fill or a retext walks its runs.
60899
+ *
60900
+ * @param ctx - Domain context of the text plugin.
60901
+ * @param pixi - The Pixi module the renderer loaded.
60902
+ * @param container - The container of this label.
60903
+ * @returns The cursor, at the first child.
60904
+ */
60905
+ function openCursor(ctx, pixi, container) {
60906
+ const cursor = ctx.state.cursor;
60907
+ cursor.container = container;
60908
+ cursor.pixi = pixi;
60909
+ cursor.index = 0;
60910
+ return cursor;
60911
+ }
60912
+ /**
60913
+ * Lets the draw cursor go of its container, so the state holds no Pixi object between draws.
60914
+ *
60915
+ * @param cursor - The cursor of the plugin.
60916
+ */
60917
+ function closeCursor(cursor) {
60918
+ cursor.container = void 0;
60919
+ cursor.pixi = void 0;
60920
+ }
60921
+ /**
60922
+ * Tells whether the draw cursor points at a container, as it does inside a fill or a retext.
60923
+ *
60924
+ * @param cursor - The cursor of the plugin.
60925
+ * @returns True when a container and the Pixi module are set.
60926
+ */
60927
+ function isOpen(cursor) {
60928
+ return cursor.container !== void 0 && cursor.pixi !== void 0;
60929
+ }
60930
+ /**
60931
+ * Builds the objects of one run into the container of the cursor.
60932
+ *
60933
+ * @param ctx - Domain context of the text plugin.
60934
+ * @param run - The run; where it starts is in `state.cursor.at`.
60935
+ * @param look - The look of the run.
60936
+ */
60937
+ function fillRun(ctx, run, look) {
60938
+ const cursor = ctx.state.cursor;
60939
+ if (!isOpen(cursor)) return;
60940
+ const { container, pixi, at } = cursor;
60941
+ const spot = {
60942
+ x: at[0] ?? 0,
60943
+ y: at[1] ?? 0
60944
+ };
60945
+ for (const object of buildRun(ctx, pixi, run, look, spot)) container.addChild(object);
60946
+ }
60947
+ /**
60304
60948
  * Fills a container with the objects of every run of the laid-out block, anchored by the
60305
60949
  * component, and remembers what it was filled from. A shadow sits in the same container as its
60306
60950
  * run, so it follows every update, reflow and destroy of it.
@@ -60312,40 +60956,122 @@ function eachRun(ctx, label, anchor, visit) {
60312
60956
  * @param label - Its style and laid-out block.
60313
60957
  */
60314
60958
  function fill(ctx, pixi, container, value, label) {
60315
- eachRun(ctx, label, value.anchor, (run, at) => {
60316
- for (const object of buildRun(ctx, pixi, run, label.style, at)) container.addChild(object);
60317
- });
60959
+ const cursor = openCursor(ctx, pixi, container);
60960
+ eachRun(ctx, label, value, fillRun);
60961
+ closeCursor(cursor);
60318
60962
  ctx.state.drawn.set(container, label);
60319
60963
  }
60320
60964
  /**
60321
60965
  * Tells whether two runs are drawn with the same objects: an icon of the same key, or glyphs with
60322
- * the same bold, italic and colour. Only the text of a glyph run may differ.
60966
+ * the same bold, italic and colour, both in the same span. Only the text of a glyph run may
60967
+ * differ: a run of another span is in another look, with other fonts and copies.
60323
60968
  *
60324
60969
  * @param first - One run.
60325
60970
  * @param second - The other, or nothing.
60326
60971
  * @returns True when the objects of `first` can draw `second`.
60327
60972
  */
60328
60973
  function sameObjects(first, second) {
60329
- if (second === void 0 || first.kind !== second.kind) return false;
60974
+ if (second === void 0 || first.kind !== second.kind || first.span !== second.span) return false;
60330
60975
  if (first.kind === "icon") return second.kind === "icon" && first.key === second.key;
60331
60976
  return second.kind === "text" && first.bold === second.bold && first.italic === second.italic && first.color === second.color;
60332
60977
  }
60333
60978
  /**
60334
- * Tells whether two laid-out blocks have the same lines, each with the same runs.
60979
+ * Tells whether two lines hold the same runs, one by one.
60980
+ *
60981
+ * @param drawn - A line the container was filled from.
60982
+ * @param next - The line at its place now, if any.
60983
+ * @returns True when the objects of `drawn` can draw `next`.
60984
+ */
60985
+ function sameLine(drawn, next) {
60986
+ if (next === void 0 || drawn.runs.length !== next.runs.length) return false;
60987
+ for (let at = 0; at < drawn.runs.length; at += 1) {
60988
+ const run = drawn.runs[at];
60989
+ if (run === void 0 || !sameObjects(run, next.runs[at])) return false;
60990
+ }
60991
+ return true;
60992
+ }
60993
+ /**
60994
+ * Tells whether two laid-out blocks have the same lines, each with the same runs. Index loops: an
60995
+ * update of a ticking label asks this every time and builds nothing.
60335
60996
  *
60336
60997
  * @param drawn - The block the container was filled from.
60337
60998
  * @param next - The block to draw now.
60338
60999
  * @returns True when the objects of `drawn` can draw `next`.
60339
61000
  */
60340
61001
  function sameShape(drawn, next) {
60341
- return drawn.lines.length === next.lines.length && drawn.lines.every((line, index) => {
60342
- const runs = next.lines[index]?.runs ?? [];
60343
- return line.runs.length === runs.length && line.runs.every((run, at) => sameObjects(run, runs[at]));
60344
- });
61002
+ if (drawn.lines.length !== next.lines.length) return false;
61003
+ for (let index = 0; index < drawn.lines.length; index += 1) {
61004
+ const line = drawn.lines[index];
61005
+ if (line === void 0 || !sameLine(line, next.lines[index])) return false;
61006
+ }
61007
+ return true;
61008
+ }
61009
+ /**
61010
+ * Writes the text of a glyph run into the next child of the cursor and moves it to a spot.
61011
+ *
61012
+ * @param cursor - The draw cursor, its container set.
61013
+ * @param container - The container of the cursor.
61014
+ * @param text - The glyphs of the run.
61015
+ * @param x - The spot across.
61016
+ * @param y - The spot down.
61017
+ */
61018
+ function moveCopy(cursor, container, text, x, y) {
61019
+ const glyphs = container.getChildAt(cursor.index);
61020
+ glyphs.text = text;
61021
+ glyphs.x = x;
61022
+ glyphs.y = y;
61023
+ cursor.index += 1;
61024
+ }
61025
+ /**
61026
+ * Moves the copies of one ring around a run, in the order `ringSpots` placed them.
61027
+ *
61028
+ * @param cursor - The draw cursor, its container set.
61029
+ * @param container - The container of the cursor.
61030
+ * @param text - The glyphs of the run.
61031
+ * @param width - The radius of the ring.
61032
+ * @param x - Where the run starts across.
61033
+ * @param y - Where it starts down.
61034
+ */
61035
+ function moveRing(cursor, container, text, width, x, y) {
61036
+ const count = copiesFor(width);
61037
+ for (let index = 0; index < count; index += 1) {
61038
+ const angle = index / count * Math.PI * 2;
61039
+ moveCopy(cursor, container, text, x + Math.cos(angle) * width, y + Math.sin(angle) * width);
61040
+ }
61041
+ }
61042
+ /**
61043
+ * Writes a new block's run into the objects already in the container, in the order `buildRun`
61044
+ * added them: an icon's texture, size and spot; a glyph run's shadow, outline ring, synthetic bold
61045
+ * ring and glyphs, each with the new text at its spot. Walks the spots by index, so it builds
61046
+ * nothing.
61047
+ *
61048
+ * @param ctx - Domain context of the text plugin.
61049
+ * @param run - The run; where it starts is in `state.cursor.at`.
61050
+ * @param look - The look of the run.
61051
+ */
61052
+ function retextRun(ctx, run, look) {
61053
+ const cursor = ctx.state.cursor;
61054
+ if (!isOpen(cursor)) return;
61055
+ const { container, pixi } = cursor;
61056
+ const x = cursor.at[0] ?? 0;
61057
+ const y = cursor.at[1] ?? 0;
61058
+ if (run.kind === "icon") {
61059
+ const sprite = container.getChildAt(cursor.index);
61060
+ sprite.texture = iconTexture(ctx, pixi, run);
61061
+ placeIcon(ctx, sprite, look, x, y);
61062
+ cursor.index += 1;
61063
+ return;
61064
+ }
61065
+ const shadow = look.shadow;
61066
+ if (shadow !== void 0) moveCopy(cursor, container, run.text, x + shadow.dx, y + shadow.dy);
61067
+ if (look.strokeWidth > 0) moveRing(cursor, container, run.text, look.strokeWidth, x, y);
61068
+ if (run.bold && look.bold === void 0) moveRing(cursor, container, run.text, look.size / SYNTHETIC_BOLD, x, y);
61069
+ moveCopy(cursor, container, run.text, x, y);
60345
61070
  }
60346
61071
  /**
60347
61072
  * Writes a new block into the objects already in the container, in the order `fill` added them:
60348
- * the text and the spots of every glyph object, the texture, size and spot of every icon.
61073
+ * the text and the spots of every glyph object, the texture, size and spot of every icon. The
61074
+ * label record is the drawn one, its layout already written.
60349
61075
  *
60350
61076
  * @param ctx - Domain context of the text plugin.
60351
61077
  * @param pixi - The Pixi module the renderer loaded.
@@ -60354,24 +61080,9 @@ function sameShape(drawn, next) {
60354
61080
  * @param label - Its style and laid-out block, of the same shape as the drawn one.
60355
61081
  */
60356
61082
  function retext(ctx, pixi, container, value, label) {
60357
- let index = 0;
60358
- eachRun(ctx, label, value.anchor, (run, at) => {
60359
- if (run.kind === "icon") {
60360
- const sprite = container.getChildAt(index);
60361
- sprite.texture = iconTexture(ctx, pixi, run);
60362
- placeIcon(ctx, sprite, label.style, at);
60363
- index += 1;
60364
- return;
60365
- }
60366
- for (const spot of glyphSpots(label.style, run, at)) {
60367
- const glyphs = container.getChildAt(index);
60368
- glyphs.text = run.text;
60369
- glyphs.x = spot.x;
60370
- glyphs.y = spot.y;
60371
- index += 1;
60372
- }
60373
- });
60374
- ctx.state.drawn.set(container, label);
61083
+ const cursor = openCursor(ctx, pixi, container);
61084
+ eachRun(ctx, label, value, retextRun);
61085
+ closeCursor(cursor);
60375
61086
  }
60376
61087
  /**
60377
61088
  * Tells whether two anchors are the same point.
@@ -60388,7 +61099,9 @@ function samePoint(first, second) {
60388
61099
  * was last updated with, drawn with the style object that is current and under the generation
60389
61100
  * that is current, and for a `"box"` style at the same box. A replaced style is a new object under
60390
61101
  * the same name. A font or an icon a dev hot swap replaced moves the generation, because the
60391
- * objects hold textures that are destroyed. The box of any other style changes nothing drawn.
61102
+ * objects hold textures that are destroyed, and so does a styles swap, because a span or a bold
61103
+ * look of the label may have changed under a style that stood. The box of any other style changes
61104
+ * nothing drawn.
60392
61105
  *
60393
61106
  * @param ctx - Domain context of the text plugin.
60394
61107
  * @param container - The container of this label.
@@ -60404,9 +61117,10 @@ function isCurrent(ctx, container, previous, next) {
60404
61117
  /**
60405
61118
  * Draws a changed value into a container that holds a label already. A ticking counter keeps its
60406
61119
  * objects: with the same style object, the same generation, the same anchor and the same lines
60407
- * and runs, the new text and spots are written into them. Anything else frees the children and
60408
- * fills the container again. A label of an older generation is always filled again: writing the
60409
- * string it shows already into a `BitmapText` rebuilds no glyph.
61120
+ * and runs, the new text and spots are written into them and the new layout into the drawn
61121
+ * record, so the update builds nothing. Anything else frees the children and fills the container
61122
+ * again. A label of an older generation is always filled again: writing the string it shows
61123
+ * already into a `BitmapText` rebuilds no glyph.
60410
61124
  *
60411
61125
  * @param ctx - Domain context of the text plugin.
60412
61126
  * @param pixi - The Pixi module the renderer loaded.
@@ -60416,16 +61130,24 @@ function isCurrent(ctx, container, previous, next) {
60416
61130
  */
60417
61131
  function redraw(ctx, pixi, container, previous, next) {
60418
61132
  const drawn = ctx.state.drawn.get(container);
60419
- const label = labelOf(ctx, next);
60420
- if (drawn?.style === label.style && drawn.generation === label.generation && samePoint(previous.anchor, next.anchor) && sameShape(drawn.layout, label.layout)) {
60421
- retext(ctx, pixi, container, next, label);
61133
+ const style = drawnStyleOf(ctx, next);
61134
+ const layout = shownLayoutOf(ctx, drawn?.entity, next);
61135
+ const generation = ctx.state.generation;
61136
+ if (drawn?.style === style && drawn.generation === generation && samePoint(previous.anchor, next.anchor) && sameShape(drawn.layout, layout)) {
61137
+ drawn.layout = layout;
61138
+ retext(ctx, pixi, container, next, drawn);
60422
61139
  return;
60423
61140
  }
60424
61141
  for (const child of container.removeChildren()) child.destroy({
60425
61142
  children: true,
60426
61143
  texture: false
60427
61144
  });
60428
- fill(ctx, pixi, container, next, label);
61145
+ fill(ctx, pixi, container, next, {
61146
+ style,
61147
+ layout,
61148
+ generation,
61149
+ entity: drawn?.entity
61150
+ });
60429
61151
  }
60430
61152
  /**
60431
61153
  * How a `Text` becomes Pixi objects. The renderer parents, orders and frees the container like a
@@ -60439,12 +61161,12 @@ function redraw(ctx, pixi, container, previous, next) {
60439
61161
  */
60440
61162
  function createTextAdapter(ctx) {
60441
61163
  return {
60442
- create: (value) => {
61164
+ create: (value, entity) => {
60443
61165
  const pixi = ctx.deps.renderer.host.pixi();
60444
61166
  if (pixi === void 0) return void 0;
60445
61167
  const container = new pixi.Container();
60446
61168
  container.alpha = value.alpha;
60447
- fill(ctx, pixi, container, value, labelOf(ctx, value));
61169
+ fill(ctx, pixi, container, value, labelOf(ctx, value, entity));
60448
61170
  return container;
60449
61171
  },
60450
61172
  update: (object, previous, next) => {
@@ -60507,7 +61229,8 @@ function resolveDeps$1(ctx) {
60507
61229
  };
60508
61230
  }
60509
61231
  /**
60510
- * Builds the domain context the API, the hooks and the frame step share.
61232
+ * Builds the domain context the API, the hooks and the frame step share, with the layout options
61233
+ * every layout and draw reads, made here once.
60511
61234
  *
60512
61235
  * @param ctx - Kernel context of the text plugin.
60513
61236
  * @returns The domain context of the text plugin.
@@ -60515,7 +61238,8 @@ function resolveDeps$1(ctx) {
60515
61238
  function withDeps$1(ctx) {
60516
61239
  return {
60517
61240
  ...ctx,
60518
- deps: resolveDeps$1(ctx)
61241
+ deps: resolveDeps$1(ctx),
61242
+ layoutOptions: layoutOptionsOf(ctx)
60519
61243
  };
60520
61244
  }
60521
61245
  /**
@@ -60528,6 +61252,20 @@ function isStyleMap(entry) {
60528
61252
  return typeof entry === "object" && entry !== null && "kind" in entry && entry.kind === "textStyles" && "map" in entry && typeof entry.map === "object" && entry.map !== null;
60529
61253
  }
60530
61254
  /**
61255
+ * Refuses a style name a second feature defines. A built-in name is free: a feature may
61256
+ * override it.
61257
+ *
61258
+ * @param state - The plugin state, its owners so far.
61259
+ * @param name - The style name.
61260
+ * @param feature - The feature that defines it now.
61261
+ * @throws {Error} When another feature defined the name already.
61262
+ */
61263
+ function checkOwner(state, name, feature) {
61264
+ const owner = state.styleOwner.get(name);
61265
+ if (owner === void 0 || owner === BUILT_IN) return;
61266
+ throw new Error(`[game] Text style "${name}" is defined by features "${owner}" and "${feature}".\n Keep it in one feature or rename one of them.`);
61267
+ }
61268
+ /**
60531
61269
  * Fills the style table: the two built-ins first, then the styles of every feature in feature
60532
61270
  * order. A feature may override a built-in; two features may not share a name.
60533
61271
  *
@@ -60543,8 +61281,7 @@ function buildStyles(ctx) {
60543
61281
  const entry = feature.description.textStyles;
60544
61282
  if (!isStyleMap(entry)) continue;
60545
61283
  for (const [name, value] of Object.entries(entry.map)) {
60546
- const owner = ctx.state.styleOwner.get(name);
60547
- if (owner !== void 0 && owner !== BUILT_IN) throw new Error(`[game] Text style "${name}" is defined by features "${owner}" and "${feature.name}".\n Keep it in one feature or rename one of them.`);
61284
+ checkOwner(ctx.state, name, feature.name);
60548
61285
  const style = readStyle(name, value);
60549
61286
  if (style === void 0) continue;
60550
61287
  ctx.state.styles.set(name, style);
@@ -60553,6 +61290,16 @@ function buildStyles(ctx) {
60553
61290
  }
60554
61291
  }
60555
61292
  /**
61293
+ * Builds the bold look of every style that has `boldStyle`, and forgets the looks of styles that
61294
+ * are gone: a hot swap replaces the style objects the looks are keyed by.
61295
+ *
61296
+ * @param state - The plugin state, its style table filled.
61297
+ */
61298
+ function buildLooks(state) {
61299
+ state.looks.clear();
61300
+ for (const style of state.styles.values()) if (style.boldStyle !== void 0) state.looks.set(style, boldLookOf(style, style.boldStyle));
61301
+ }
61302
+ /**
60556
61303
  * Tells whether a feature entry is a format map `text` can read.
60557
61304
  *
60558
61305
  * @param entry - What the feature put under its `textFormats` key.
@@ -60604,8 +61351,8 @@ function buildFormats(ctx) {
60604
61351
  }
60605
61352
  }
60606
61353
  /**
60607
- * Collects every font a style can draw with: the two of the config, then the regular, bold and
60608
- * italic font of every registered style.
61354
+ * Collects every font a style can draw with: the two of the config, then the regular, bold,
61355
+ * italic and `boldStyle` font of every registered style.
60609
61356
  *
60610
61357
  * @param ctx - Domain context of the text plugin.
60611
61358
  */
@@ -60616,13 +61363,15 @@ function collectFonts(ctx) {
60616
61363
  ctx.state.fontKeys.add(style.font);
60617
61364
  if (style.bold !== void 0) ctx.state.fontKeys.add(style.bold);
60618
61365
  if (style.italic !== void 0) ctx.state.fontKeys.add(style.italic);
61366
+ if (style.boldStyle?.font !== void 0) ctx.state.fontKeys.add(style.boldStyle.font);
60619
61367
  }
60620
61368
  }
60621
61369
  /**
60622
61370
  * Writes the styles of a saved styles file over the table: a known name keeps its owner, a new
60623
- * name is added. Then the fonts of the new styles are read, the layouts measured with the old
60624
- * styles are dropped, and every label is marked, so the next frame lays it out again and the
60625
- * display adapter redraws it with the new style object.
61371
+ * name is added, and the bold looks are built again. Then the fonts of the new styles are read,
61372
+ * the layouts measured with the old styles are dropped, every label is marked and the generation
61373
+ * moves, so the next frame lays every label out again and the display adapter builds it again: a
61374
+ * label whose own style stood still may draw a span or a bold look that changed.
60626
61375
  *
60627
61376
  * @param ctx - Domain context of the text plugin.
60628
61377
  * @param styles - What `defineTextStyles` returned in the saved module.
@@ -60634,9 +61383,11 @@ function replaceStyles(ctx, styles) {
60634
61383
  ctx.state.styles.set(name, style);
60635
61384
  if (!ctx.state.styleOwner.has(name)) ctx.state.styleOwner.set(name, HOT_SWAP);
60636
61385
  }
61386
+ buildLooks(ctx.state);
60637
61387
  collectFonts(ctx);
60638
61388
  installFonts(ctx);
60639
- ctx.state.cache.clear();
61389
+ dropLayouts(ctx.state);
61390
+ ctx.state.generation += 1;
60640
61391
  markDirty(ctx);
60641
61392
  ctx.deps.time.wake();
60642
61393
  }
@@ -60657,6 +61408,7 @@ function startText(ctx) {
60657
61408
  const ecs = tctx.deps.world.ecs;
60658
61409
  const frame = createTextFrame(tctx);
60659
61410
  buildStyles(tctx);
61411
+ buildLooks(tctx.state);
60660
61412
  buildFormats(tctx);
60661
61413
  collectFonts(tctx);
60662
61414
  tctx.state.removers.push(ecs.system(createTextSystem(tctx, frame)), tctx.deps.time.onFrame("layout", () => resolveAdded(tctx, frame)), ecs.onAdded(Text, (entity) => noteAdded(tctx, entity)), ecs.onRemoved(Text, (entity) => {
@@ -60675,6 +61427,7 @@ function stopText(state) {
60675
61427
  for (const off of state.removers) off();
60676
61428
  state.removers.length = 0;
60677
61429
  state.styles.clear();
61430
+ state.looks.clear();
60678
61431
  state.styleOwner.clear();
60679
61432
  state.formats.clear();
60680
61433
  state.formatOwner.clear();
@@ -60684,7 +61437,9 @@ function stopText(state) {
60684
61437
  state.seen.clear();
60685
61438
  state.bindTypes.clear();
60686
61439
  state.measured.clear();
60687
- state.cache.clear();
61440
+ dropLayouts(state);
61441
+ state.shown.clear();
61442
+ closeCursor(state.cursor);
60688
61443
  state.dirty.clear();
60689
61444
  state.added.length = 0;
60690
61445
  state.rewrite.length = 0;
@@ -60791,7 +61546,7 @@ function createHandlers(ctx, reload) {
60791
61546
  "i18n:locale-changed": (_payload) => {
60792
61547
  const tctx = domain();
60793
61548
  markDirty(tctx, (label) => typeof label.content !== "string");
60794
- tctx.state.cache.clear();
61549
+ dropLayouts(tctx.state);
60795
61550
  tctx.deps.time.wake();
60796
61551
  }
60797
61552
  };
@@ -60831,6 +61586,7 @@ function emptyWeakMap() {
60831
61586
  function createTextState$1() {
60832
61587
  return {
60833
61588
  styles: emptyMap$2(),
61589
+ looks: emptyMap$2(),
60834
61590
  styleOwner: emptyMap$2(),
60835
61591
  formats: emptyMap$2(),
60836
61592
  formatOwner: emptyMap$2(),
@@ -60841,6 +61597,15 @@ function createTextState$1() {
60841
61597
  bindTypes: emptyMap$2(),
60842
61598
  measured: emptyMap$2(),
60843
61599
  cache: emptyMap$2(),
61600
+ epoch: 0,
61601
+ shown: emptyMap$2(),
61602
+ cursor: {
61603
+ container: void 0,
61604
+ pixi: void 0,
61605
+ index: 0,
61606
+ at: /* @__PURE__ */ new Float64Array(2)
61607
+ },
61608
+ runWidths: emptyWeakMap(),
60844
61609
  drawn: emptyWeakMap(),
60845
61610
  dirty: emptySet$1(),
60846
61611
  added: [],
@@ -61194,6 +61959,10 @@ function rectOfTargets(ctx, to) {
61194
61959
  //#endregion
61195
61960
  //#region src/plugins/ui/jsx/field-layout.ts
61196
61961
  /**
61962
+ * @file ui/jsx — where the parts of a text field go, and how far the keyboard lifts it. Pure: the
61963
+ * mirror, the measured prefixes and the box in, numbers out. No ctx, no state, no DOM.
61964
+ */
61965
+ /**
61197
61966
  * The four edges of a resolved padding.
61198
61967
  *
61199
61968
  * @param padding - One number for every edge, the edges a style names, or nothing.
@@ -61421,6 +62190,18 @@ function insetOf(viewport) {
61421
62190
  function liftOf(input) {
61422
62191
  return Math.max(0, input.fieldBottom + input.margin - (input.innerHeight - input.inset));
61423
62192
  }
62193
+ /**
62194
+ * A typed value as `text` takes it: plain text, where `<` is never markup. It is `text`'s own
62195
+ * `escapeTags`, so a field writes a `<` the way the tag grammar reads a literal one; a value
62196
+ * without one is handed as it is. Only the string for `text` changes, never the indices of the
62197
+ * caret and the selection.
62198
+ *
62199
+ * @example
62200
+ * ```ts
62201
+ * literalText("<b>x"); // "\\<b>x"
62202
+ * ```
62203
+ */
62204
+ const literalText = escapeTags;
61424
62205
  /** A high surrogate: the first half of a character outside the Basic Multilingual Plane. */
61425
62206
  const OPEN_SURROGATE = /[\uD800-\uDBFF]$/;
61426
62207
  /**
@@ -61951,6 +62732,8 @@ const KINDS = [
61951
62732
  const PLACEHOLDER_ALPHA = .5;
61952
62733
  /** The separator between the inputs of a field's fingerprint. */
61953
62734
  const FIELD_SEPARATOR = "\0";
62735
+ /** What a fingerprint holds for an input the field has not: no mirror, no composing range. */
62736
+ const NO_INPUT = "-";
61954
62737
  /**
61955
62738
  * Reads the props of an `input` tag.
61956
62739
  *
@@ -62070,7 +62853,8 @@ function boxPart(box, fill, alpha) {
62070
62853
  * The component values of the four parts of a laid-out field.
62071
62854
  *
62072
62855
  * @param layout - Where the parts go.
62073
- * @param content - What the text part draws: the value, or the placeholder at half alpha.
62856
+ * @param content - What the text part draws: the value as plain text, or the placeholder at half
62857
+ * alpha.
62074
62858
  * @param textStyle - The text style of the field.
62075
62859
  * @param look - The caret, selection and underline look of the config.
62076
62860
  * @returns The values, per part.
@@ -62089,6 +62873,33 @@ function partValues(layout, content, textStyle, look) {
62089
62873
  };
62090
62874
  }
62091
62875
  /**
62876
+ * Where a rect of reference units is on the page: its rect in screen px, and its bottom edge as
62877
+ * the viewport maps it, which the keyboard lift is measured from.
62878
+ *
62879
+ * @param viewport - The viewport of the renderer.
62880
+ * @param drawn - The rect in reference units.
62881
+ * @returns The rect in screen px and its bottom.
62882
+ */
62883
+ function screenRectOf(viewport, drawn) {
62884
+ const topLeft = viewport.toScreen({
62885
+ x: drawn.x,
62886
+ y: drawn.y
62887
+ });
62888
+ const bottomRight = viewport.toScreen({
62889
+ x: drawn.x + drawn.w,
62890
+ y: drawn.y + drawn.h
62891
+ });
62892
+ return {
62893
+ rect: {
62894
+ x: topLeft.x,
62895
+ y: topLeft.y,
62896
+ w: bottomRight.x - topLeft.x,
62897
+ h: bottomRight.y - topLeft.y
62898
+ },
62899
+ bottom: bottomRight.y
62900
+ };
62901
+ }
62902
+ /**
62092
62903
  * A cheap fingerprint of what a field is laid out from: the selection and the composing range
62093
62904
  * while it is edited, the box, the padding, the text style, the placeholder and the value. The
62094
62905
  * value goes last, so no character of it can shift another input.
@@ -62101,9 +62912,9 @@ function partValues(layout, content, textStyle, look) {
62101
62912
  * @returns The fingerprint.
62102
62913
  */
62103
62914
  function inputsOf(field, element, mirror, composing, value) {
62915
+ const selection = mirror === void 0 ? NO_INPUT : `${mirror.selectionStart},${mirror.selectionEnd},${mirror.direction}`;
62916
+ const range = composing === void 0 ? NO_INPUT : `${composing.start},${composing.end}`;
62104
62917
  const pad = paddingOf(element.style.padding);
62105
- const selection = mirror === void 0 ? "-" : `${mirror.selectionStart},${mirror.selectionEnd},${mirror.direction}`;
62106
- const range = composing === void 0 ? "-" : `${composing.start},${composing.end}`;
62107
62918
  const box = `${element.rect.w},${element.rect.h},${pad.top},${pad.right},${pad.bottom},${pad.left}`;
62108
62919
  const placeholder = JSON.stringify(field.placeholder ?? "");
62109
62920
  return [
@@ -62456,7 +63267,7 @@ function createFields(ctx, links) {
62456
63267
  lineHeight: measure("").height,
62457
63268
  caretWidth: look.caretWidth,
62458
63269
  underline: look.composingUnderline,
62459
- prefix: (piece) => measure(piece).width,
63270
+ prefix: (piece) => measure(literalText(piece)).width,
62460
63271
  hasGlyph: (char) => ctx.deps.text.hasGlyph(char, field.textStyle)
62461
63272
  });
62462
63273
  }
@@ -62471,7 +63282,7 @@ function createFields(ctx, links) {
62471
63282
  */
62472
63283
  function drawField(field, layout, value, inputs) {
62473
63284
  const look = ctx.config.textInput;
62474
- const content = layout.content === "placeholder" ? field.placeholder ?? "" : value;
63285
+ const content = layout.content === "placeholder" ? field.placeholder ?? "" : literalText(value);
62475
63286
  const values = partValues(layout, content, field.textStyle, look);
62476
63287
  const drawn = JSON.stringify({
62477
63288
  layout,
@@ -62555,24 +63366,10 @@ function createFields(ctx, links) {
62555
63366
  return;
62556
63367
  }
62557
63368
  const viewport = ctx.deps.renderer.viewport;
62558
- const drawn = rootRectOf(ctx, state, field, lookup);
62559
- const topLeft = viewport.toScreen({
62560
- x: drawn.x,
62561
- y: drawn.y
62562
- });
62563
- const bottomRight = viewport.toScreen({
62564
- x: drawn.x + drawn.w,
62565
- y: drawn.y + drawn.h
62566
- });
62567
- const rect = {
62568
- x: topLeft.x,
62569
- y: topLeft.y,
62570
- w: bottomRight.x - topLeft.x,
62571
- h: bottomRight.y - topLeft.y
62572
- };
63369
+ const { rect, bottom } = screenRectOf(viewport, rootRectOf(ctx, state, field, lookup));
62573
63370
  const keyboard = text.keyboard;
62574
63371
  keyboard.lift = keyboard.inset <= 0 ? 0 : liftOf({
62575
- fieldBottom: bottomRight.y,
63372
+ fieldBottom: bottom,
62576
63373
  margin: ctx.config.textInput.keyboardMargin,
62577
63374
  innerHeight: keyboard.innerHeight,
62578
63375
  inset: keyboard.inset
@@ -74567,6 +75364,295 @@ void main() {
74567
75364
  },
74568
75365
  padding: "spread"
74569
75366
  });
75367
+ //#endregion
75368
+ //#region src/plugins/effects/set/stages.ts
75369
+ /**
75370
+ * @file effects/set — the shared stages a chain member of the set draws its second texture with: `BloomDown` (what is
75371
+ * above a threshold, boxed down in one pass) and `BloomBlur` (a 13-tap blur in two dimensions, one pass). Each is a
75372
+ * `defineFilter` that draws alone, listed in a member's `inputs` and named by its chain's steps; none is a root
75373
+ * export (a game that wants a chain writes its own stages). Before each body the set head and `inputTexel()`.
75374
+ */
75375
+ /**
75376
+ * The WGSL the stages put between the set head and their bodies: `inputTexel()`, one texel of the input in the 0..1 of
75377
+ * `inputPlace`. Live a stage's input is a share of a pooled texture, its clamp half a texel in from the frame, so one
75378
+ * texel of uv (`uInputPixel.zw`) over the clamp's span is one texel of the frame on both axes.
75379
+ */
75380
+ const STAGE_WGSL = `fn inputTexel() -> vec2<f32> {
75381
+ return gfu.uInputPixel.zw / (gfu.uInputClamp.zw - gfu.uInputClamp.xy);
75382
+ }
75383
+
75384
+ `;
75385
+ /** The GLSL twin of `STAGE_WGSL`. */
75386
+ const STAGE_GLSL = `vec2 inputTexel() {
75387
+ return uInputPixel.zw / (uInputClamp.zw - uInputClamp.xy);
75388
+ }
75389
+
75390
+ `;
75391
+ /**
75392
+ * A stage's WGSL body with the set head and `inputTexel()` before it. A call, so a bundle that drops the stage drops
75393
+ * the text too.
75394
+ *
75395
+ * @param body - The stage's WGSL body.
75396
+ * @returns The head, the helper, then the body.
75397
+ * @example
75398
+ * ```ts
75399
+ * withStageWgsl("@fragment fn mainFragment").includes("fn inputTexel()"); // true
75400
+ * ```
75401
+ */
75402
+ function withStageWgsl(body) {
75403
+ return withSetWgsl(STAGE_WGSL + body);
75404
+ }
75405
+ /**
75406
+ * A stage's GLSL body with the set head and `inputTexel()` before it, for the same reason as `withStageWgsl`.
75407
+ *
75408
+ * @param body - The stage's GLSL body.
75409
+ * @returns The head, the helper, then the body.
75410
+ * @example
75411
+ * ```ts
75412
+ * withStageGlsl("void main() {}").includes("vec2 inputTexel()"); // true
75413
+ * ```
75414
+ */
75415
+ function withStageGlsl(body) {
75416
+ return withSetGlsl(STAGE_GLSL + body);
75417
+ }
75418
+ /**
75419
+ * The WGSL body of `BloomDown`: drawn at ¼ or ⅛ of the view's input, it reads that input with 4 taps on the diagonals
75420
+ * of its pixel, `reach` texels out on each axis (1 at ¼, 2 at ⅛: the centres of the four quarters of its footprint).
75421
+ * Each tap stands on the corner of 4 texels, so the linear sampler reads a 2 × 2 block. Each tap is cut by
75422
+ * `threshold` of its own alpha, premultiplied, `max(c.rgb − threshold × c.a, 0)`, so a half-transparent edge is cut at
75423
+ * its share of the threshold, and its alpha is its brightest channel: light covers as much as it shines, and where
75424
+ * nothing is bright the cut is transparent black. The four cuts are averaged. The corner turns a quarter each tap.
75425
+ */
75426
+ const BLOOM_DOWN_WGSL = `@fragment
75427
+ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
75428
+ let n = inputPlace(uv);
75429
+ let d = fu.reach * inputTexel();
75430
+ var sum = vec4<f32>(0.0);
75431
+ var corner = vec2<f32>(1.0);
75432
+
75433
+ for (var k = 0; k < 4; k++) {
75434
+ let c = sampleInput(n + corner * d);
75435
+ let cut = max(c.rgb - fu.threshold * c.a, vec3<f32>(0.0));
75436
+ let light = max(max(cut.r, cut.g), cut.b);
75437
+ sum += vec4<f32>(cut, light);
75438
+ corner = vec2<f32>(-corner.y, corner.x);
75439
+ }
75440
+
75441
+ return sum * 0.25;
75442
+ }
75443
+ `;
75444
+ /** The GLSL twin of `BLOOM_DOWN_WGSL`. */
75445
+ const BLOOM_DOWN_GLSL = `void main() {
75446
+ vec2 n = inputPlace(vTextureCoord);
75447
+ vec2 d = reach * inputTexel();
75448
+ vec4 sum = vec4(0.0);
75449
+ vec2 corner = vec2(1.0);
75450
+
75451
+ for (int k = 0; k < 4; k++) {
75452
+ vec4 c = sampleInput(n + corner * d);
75453
+ vec3 cut = max(c.rgb - threshold * c.a, vec3(0.0));
75454
+ float light = max(max(cut.r, cut.g), cut.b);
75455
+ sum += vec4(cut, light);
75456
+ corner = vec2(-corner.y, corner.x);
75457
+ }
75458
+
75459
+ finalColor = sum * 0.25;
75460
+ }
75461
+ `;
75462
+ /**
75463
+ * The WGSL body of `BloomBlur`, a blur in two dimensions, in one pass at the scale of its input: the centre and two
75464
+ * rings of 6 taps, the inner one at `0.5 × sigma` texels, the outer one at `sigma`. A tap `d` texels out weighs
75465
+ * `exp(−d² / (2 × sigma²))`: `exp(−1 / 8)` on the inner ring, `exp(−1 / 2)` on the outer, 1 at the centre, and the sum
75466
+ * is divided by the 13 weights' sum. The outer ring stands at 15° + 60° × k, the inner one 30° further, turned 60° a
75467
+ * tap: at the chain's sigmas (8, 5.25 at the phone's 2.625) no tap stands on a texel's row or column, so the linear
75468
+ * sampler reads the 4 texels around each. The chain caps sigma at 8.
75469
+ */
75470
+ const BLOOM_BLUR_WGSL = `@fragment
75471
+ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
75472
+ let n = inputPlace(uv);
75473
+ let far = fu.sigma * inputTexel();
75474
+ let near = far * 0.5;
75475
+ let nearWeight = exp(-0.125);
75476
+ let farWeight = exp(-0.5);
75477
+ var sum = sampleInput(n);
75478
+ var outer = vec2<f32>(0.9659258, 0.258819);
75479
+
75480
+ for (var k = 0; k < 6; k++) {
75481
+ let inner = vec2<f32>(0.8660254 * outer.x - 0.5 * outer.y, 0.5 * outer.x + 0.8660254 * outer.y);
75482
+ sum += sampleInput(n + inner * near) * nearWeight + sampleInput(n + outer * far) * farWeight;
75483
+ outer = vec2<f32>(0.5 * outer.x - 0.8660254 * outer.y, 0.8660254 * outer.x + 0.5 * outer.y);
75484
+ }
75485
+
75486
+ return sum / (1.0 + 6.0 * (nearWeight + farWeight));
75487
+ }
75488
+ `;
75489
+ /** The GLSL twin of `BLOOM_BLUR_WGSL`. */
75490
+ const BLOOM_BLUR_GLSL = `void main() {
75491
+ vec2 n = inputPlace(vTextureCoord);
75492
+ vec2 far = sigma * inputTexel();
75493
+ vec2 near = far * 0.5;
75494
+ float nearWeight = exp(-0.125);
75495
+ float farWeight = exp(-0.5);
75496
+ vec4 sum = sampleInput(n);
75497
+ vec2 outer = vec2(0.9659258, 0.258819);
75498
+
75499
+ for (int k = 0; k < 6; k++) {
75500
+ vec2 inner = vec2(0.8660254 * outer.x - 0.5 * outer.y, 0.5 * outer.x + 0.8660254 * outer.y);
75501
+ sum += sampleInput(n + inner * near) * nearWeight + sampleInput(n + outer * far) * farWeight;
75502
+ outer = vec2(0.5 * outer.x - 0.8660254 * outer.y, 0.8660254 * outer.x + 0.5 * outer.y);
75503
+ }
75504
+
75505
+ finalColor = sum / (1.0 + 6.0 * (nearWeight + farWeight));
75506
+ }
75507
+ `;
75508
+ /** The whole WGSL `BloomDown` is defined with: the set head, the stages' helper, then the body. */
75509
+ const BLOOM_DOWN_SOURCE = /*#__PURE__*/ withStageWgsl(BLOOM_DOWN_WGSL);
75510
+ /** The whole GLSL `BloomDown` is defined with. */
75511
+ const BLOOM_DOWN_GLSL_SOURCE = /*#__PURE__*/ withStageGlsl(BLOOM_DOWN_GLSL);
75512
+ /** The whole WGSL `BloomBlur` is defined with. */
75513
+ const BLOOM_BLUR_SOURCE = /*#__PURE__*/ withStageWgsl(BLOOM_BLUR_WGSL);
75514
+ /** The whole GLSL `BloomBlur` is defined with. */
75515
+ const BLOOM_BLUR_GLSL_SOURCE = /*#__PURE__*/ withStageGlsl(BLOOM_BLUR_GLSL);
75516
+ /**
75517
+ * The first stage of `Bloom`: what is above `threshold` of the view's input, premultiplied, boxed down to the step's
75518
+ * scale in one pass. 4 samples, `reach` texels out.
75519
+ */
75520
+ const BloomDown = /*#__PURE__*/ defineFilter("effects.bloomDown", {
75521
+ wgsl: BLOOM_DOWN_SOURCE,
75522
+ glsl: BLOOM_DOWN_GLSL_SOURCE,
75523
+ uniforms: {
75524
+ threshold: .7,
75525
+ reach: 1
75526
+ }
75527
+ });
75528
+ /** The second stage of `Bloom`: a blur of `sigma` texels in both dimensions at once, 13 samples. */
75529
+ const BloomBlur = /*#__PURE__*/ defineFilter("effects.bloomBlur", {
75530
+ wgsl: BLOOM_BLUR_SOURCE,
75531
+ glsl: BLOOM_BLUR_GLSL_SOURCE,
75532
+ uniforms: { sigma: 0 }
75533
+ });
75534
+ //#endregion
75535
+ //#region src/plugins/effects/set/bloom.ts
75536
+ /**
75537
+ * @file effects/set — `Bloom`: light around the bright parts of a view. The one member with a chain: its input `bright`
75538
+ * is the view's light above `threshold`, cut and boxed down to ¼ (⅛ for a wide radius) in one pass and blurred there in
75539
+ * one more; the body adds it back by `strength`. 3 passes at any radius and resolution. A chain member never rides the
75540
+ * quad: a value change runs the chain again and redraws the kept picture's filter (stage 3).
75541
+ */
75542
+ /** The most texels the blur's sigma may reach: past it the rings stand too far apart on the boxed-down light. */
75543
+ const MAX_SIGMA = 8;
75544
+ /** The scale of the ladder for a radius of at most `MAX_SIGMA` texels at it. */
75545
+ const QUARTER = 1 / 4;
75546
+ /** The scale of the ladder for a wider radius: one more halving, so sigma stays under its cap longer. */
75547
+ const EIGHTH = 1 / 8;
75548
+ /**
75549
+ * The WGSL body of `Bloom`: the view's own pixel, plus the blurred light of `bright` at the same place times
75550
+ * `strength`, at least 0. Both are premultiplied, so the sum is too; over an opaque pixel the light adds to its colour.
75551
+ */
75552
+ const BLOOM_WGSL = `@fragment
75553
+ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
75554
+ let c = sampleInput(inputPlace(uv));
75555
+
75556
+ return c + sampleBright(uv) * max(fu.strength, 0.0);
75557
+ }
75558
+ `;
75559
+ /** The GLSL twin of `BLOOM_WGSL`. */
75560
+ const BLOOM_GLSL = `void main() {
75561
+ vec4 c = sampleInput(inputPlace(vTextureCoord));
75562
+
75563
+ finalColor = c + sampleBright(vTextureCoord) * max(strength, 0.0);
75564
+ }
75565
+ `;
75566
+ /**
75567
+ * Makes one ladder: the cut boxed down to `scale`, then the blur at the same scale.
75568
+ *
75569
+ * @param scale - The scale both steps draw at.
75570
+ * @param reach - How far out the down step's taps stand, in texels of the view's input: a quarter of its footprint,
75571
+ * `1 / (4 × scale)`. A whole number, written as one: a fraction in a uniform comes back boxed at each read of a frame.
75572
+ * @returns The ladder, its steps frozen, its uniform objects open to the chain.
75573
+ */
75574
+ function ladderAt(scale, reach) {
75575
+ const down = {
75576
+ threshold: 0,
75577
+ reach
75578
+ };
75579
+ const blur = { sigma: 0 };
75580
+ return {
75581
+ steps: Object.freeze([Object.freeze({
75582
+ stage: BloomDown,
75583
+ scale,
75584
+ uniforms: down
75585
+ }), Object.freeze({
75586
+ stage: BloomBlur,
75587
+ scale,
75588
+ uniforms: blur
75589
+ })]),
75590
+ scale,
75591
+ down,
75592
+ blur
75593
+ };
75594
+ }
75595
+ /**
75596
+ * Makes the two ladders of the chain, once. A function: the module-scope rule sees no collection literal, and a bundle
75597
+ * that drops `Bloom` drops the call and the stages with it.
75598
+ *
75599
+ * @returns The ladder at ¼ and the one at ⅛.
75600
+ */
75601
+ function bloomLadders() {
75602
+ return {
75603
+ quarter: ladderAt(QUARTER, 1),
75604
+ eighth: ladderAt(EIGHTH, 2)
75605
+ };
75606
+ }
75607
+ /** The two ladders, made at module scope once: the chain answers one of them, written in place, on every call. */
75608
+ const LADDERS = /*#__PURE__*/ bloomLadders();
75609
+ /**
75610
+ * The chain of `bright`: the ladder at ⅛ when the radius in texels at ¼ is over `MAX_SIGMA`, otherwise the one at ¼;
75611
+ * sigma is the radius in texels at the ladder's scale, capped at `MAX_SIGMA`, so past it the bloom stops widening.
75612
+ * The answer is one of two arrays made once, its threshold and sigma written in place: the engine copies what it
75613
+ * reads, and a strength tween, which runs the chain in every frame, allocates nothing here.
75614
+ *
75615
+ * @param value - The stored value of the `Bloom`.
75616
+ * @param context - The resolution of the view's input.
75617
+ * @returns The two steps, the same array for every call of a ladder.
75618
+ */
75619
+ function bloomChain(value, context) {
75620
+ const texels = value.radius * context.resolution;
75621
+ const ladder = texels * QUARTER > MAX_SIGMA ? LADDERS.eighth : LADDERS.quarter;
75622
+ ladder.down.threshold = value.threshold;
75623
+ ladder.blur.sigma = Math.min(Math.max(texels * ladder.scale, 0), MAX_SIGMA);
75624
+ return ladder.steps;
75625
+ }
75626
+ /**
75627
+ * Light around the bright parts of a view and its subtree: what is above `threshold` (0..1) of its light, blurred
75628
+ * `radius` CSS px wide, added back by `strength` (0..2). For a reward, a gem, a lit lamp: an object, not the screen
75629
+ * (over the A26's screen its passes fill 1.9 Mpx a frame at 2.625). List it in a feature's `filters`, as a game's own
75630
+ * filter. It reads a second texture drawn by a chain of two stages, the light cut and boxed down to ¼ (⅛ when the
75631
+ * radius is over 8 texels at ¼: radius 16 at the phone's 2.625, 32 at 2) and blurred there: 3 passes at any radius.
75632
+ * A still view is kept as a picture; a tween of any field runs the chain again and redraws the picture's filter, 3
75633
+ * passes, in every frame it moves: it never draws on the view's quad. Past a sigma of 8 texels at ⅛ the bloom stops
75634
+ * widening.
75635
+ *
75636
+ * @example
75637
+ * ```ts
75638
+ * // features/shop/feature.ts lists it: filters: [Bloom]. A reward card blooms gold, then a motion fades it out.
75639
+ * Bloom.filter.inputs[0]?.chain({ ...Bloom().value }, { resolution: 2 }).length; // 2
75640
+ * view.tween(Bloom, { strength: 0 }, { ms: 400 });
75641
+ * ```
75642
+ */
75643
+ const Bloom = /*#__PURE__*/ defineFilter("effects.bloom", {
75644
+ wgsl: /* @__PURE__ */ withSetWgsl(BLOOM_WGSL),
75645
+ glsl: /* @__PURE__ */ withSetGlsl(BLOOM_GLSL),
75646
+ uniforms: {
75647
+ strength: .6,
75648
+ threshold: .7,
75649
+ radius: 16
75650
+ },
75651
+ inputs: { bright: {
75652
+ stages: [BloomDown, BloomBlur],
75653
+ chain: bloomChain
75654
+ } }
75655
+ });
74570
75656
  /**
74571
75657
  * A view eaten away by a noise of `scale` cells across: `progress` 0 keeps all of it, 1 none, and the edge of what is
74572
75658
  * left glows in `edgeColor` over `edge` (0..1 of the noise). The noise has no time: the same cells go first at every
@@ -75168,4 +76254,4 @@ const screen = [
75168
76254
  uiPlugin
75169
76255
  ];
75170
76256
  //#endregion
75171
- export { defineAnimation as $, frameAt as $t, types_exports$1 as A, i18nPlugin as At, types_exports$11 as B, Noise as Bt, flattenFeatures as C, Pressable as Ct, load as D, Touchable as Dt, defineBundles as E, Tappable as Et, types_exports$6 as F, Alpha as Ft, types_exports$16 as G, scenesPlugin as Gt, types_exports$13 as H, defineFilter as Ht, types_exports$7 as I, Blur as It, resolve as J, AnimPlayer as Jt, types_exports$17 as K, assetsPlugin as Kt, types_exports$8 as L, ColorMatrix as Lt, types_exports$3 as M, messageDuration as Mt, types_exports$4 as N, effectsPlugin as Nt, ready as O, Traceable as Ot, types_exports$5 as P, Emitter as Pt, HAPTIC_KINDS as Q, PASS_KINDS as Qt, types_exports$9 as R, Displacement as Rt, defineFeature as S, PointerOver as St, music as T, Swipeable as Tt, types_exports$14 as U, debugPlugin as Ut, types_exports$12 as V, Outline as Vt, types_exports$15 as W, audioPlugin as Wt, textPlugin as X, Frames as Xt, defineMotion as Y, Animation as Yt, platformPlugin as Z, rendererPlugin as Zt, hint as _, SaveUnreadableError as _n, Draggable as _t, Vignette as a, SHADER_WHATS as an, play$1 as at, defineScene as b, clockPlugin as bn, Hovered as bt, RevealLine as c, worldPlugin as cn, sfx as ct, Flash as d, contribution as dn, stagger as dt, MONITOR_SECTIONS as en, external as et, Dissolve as f, exit as fn, stopSfx as ft, guide as g, modelPlugin as gn, inputPlugin as gt, defineEffect as h, type as hn, wait as ht, screen as i, PROBLEM_RULES as in, parallel as it, types_exports$2 as j, messageArgument as jt, types_exports as k, Traced as kt, Grade as l, flowPlugin as ln, spawn as lt, cubicBezier as m, to as mn, use as mt, createPlugin as n, PERF_GAP_BUCKETS as nn, haptic as nt, Shine as o, CANVAS_RESTARTS as on, sequence as ot, Aura as p, slot as pn, tween as pt, uiPlugin as q, animPlugin as qt, defineGame as r, PERF_LOG_VERSION as rn, mark as rt, RevealRound as s, DEMAND_REASONS as sn, set as st, createApp as t, PERF_CAUSES as tn, frames as tt, Fold as u, refuseStart as un, spawned as ut, schedule as v, lifecyclePlugin as vn, DropTarget as vt, defineEmitter as w, Pressed as wt, tr as x, Pointer as xt, projection as y, timePlugin as yn, Held as yt, types_exports$10 as z, Glow as zt };
76257
+ export { HAPTIC_KINDS as $, PASS_KINDS as $t, types_exports as A, Traced as At, types_exports$10 as B, Glow as Bt, defineFeature as C, PointerOver as Ct, defineBundles as D, Tappable as Dt, music as E, Swipeable as Et, types_exports$5 as F, Emitter as Ft, types_exports$15 as G, audioPlugin as Gt, types_exports$12 as H, Outline as Ht, types_exports$6 as I, Alpha as It, uiPlugin as J, animPlugin as Jt, types_exports$16 as K, scenesPlugin as Kt, types_exports$7 as L, Blur as Lt, types_exports$2 as M, messageArgument as Mt, types_exports$3 as N, messageDuration as Nt, load as O, Touchable as Ot, types_exports$4 as P, effectsPlugin as Pt, platformPlugin as Q, rendererPlugin as Qt, types_exports$8 as R, ColorMatrix as Rt, tr as S, Pointer as St, defineEmitter as T, Pressed as Tt, types_exports$13 as U, defineFilter as Ut, types_exports$11 as V, Noise as Vt, types_exports$14 as W, debugPlugin as Wt, defineMotion as X, Animation as Xt, resolve as Y, AnimPlayer as Yt, textPlugin as Z, Frames as Zt, guide as _, modelPlugin as _n, inputPlugin as _t, Vignette as a, PROBLEM_RULES as an, parallel as at, projection as b, timePlugin as bn, Held as bt, RevealLine as c, DEMAND_REASONS as cn, set as ct, Flash as d, refuseStart as dn, spawned as dt, frameAt as en, defineAnimation as et, Dissolve as f, contribution as fn, stagger as ft, defineEffect as g, type as gn, wait as gt, cubicBezier as h, to as hn, use as ht, screen as i, PERF_LOG_VERSION as in, mark as it, types_exports$1 as j, i18nPlugin as jt, ready as k, Traceable as kt, Grade as l, worldPlugin as ln, sfx as lt, Aura as m, slot as mn, tween as mt, createPlugin as n, PERF_CAUSES as nn, frames as nt, Shine as o, SHADER_WHATS as on, play$1 as ot, Bloom as p, exit as pn, stopSfx as pt, types_exports$17 as q, assetsPlugin as qt, defineGame as r, PERF_GAP_BUCKETS as rn, haptic as rt, RevealRound as s, CANVAS_RESTARTS as sn, sequence as st, createApp as t, MONITOR_SECTIONS as tn, external as tt, Fold as u, flowPlugin as un, spawn as ut, hint as v, SaveUnreadableError as vn, Draggable as vt, flattenFeatures as w, Pressable as wt, defineScene as x, clockPlugin as xn, Hovered as xt, schedule as y, lifecyclePlugin as yn, DropTarget as yt, types_exports$9 as z, Displacement as zt };