@moku-labs/game 0.15.103 → 0.15.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/page.d.mts +1 -1
- package/dist/app/page.mjs +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-TSyhs2-E.d.mts → commands-CYXJyv3w.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-DNF9A0ce.d.mts → define-Cq8Df0_C.d.mts} +2 -2
- package/dist/{headless-CEG1oR5D.d.mts → headless-DRiVyv9T.d.mts} +1 -1
- package/dist/{index-DDZ9K9qO.d.mts → index-BIofySGI.d.mts} +16 -6
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/inspect.d.mts +6 -6
- package/dist/inspect.mjs +1 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-CcHPrVBm.d.mts → runtime-DuAOUZ-z.d.mts} +1 -1
- package/dist/{sources-BJyIJf_X.mjs → sources-JeKXYU_y.mjs} +1 -1
- package/dist/{src-DVJ0d04R.mjs → src-BJBCs69P.mjs} +1209 -440
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-CMag4vDu.d.mts → types-BT8kKhan.d.mts} +4 -4
- package/dist/{types-C1B7-x7p.d.mts → types-BlXBiM8d.d.mts} +191 -36
- package/dist/{types-BvgY7Ncf.d.mts → types-C1-VCBhy.d.mts} +2 -2
- package/dist/{types-C612npUH.d.mts → types-Ca90Yo7d.d.mts} +2 -2
- package/dist/{types-Ce5W0gZe.d.mts → types-CayM8xne.d.mts} +1 -1
- package/dist/{visual-PsEr2KD-.d.mts → visual-B_3sVlRK.d.mts} +6 -6
- package/dist/{visual-DhqD6W3v.mjs → visual-fyUJwUJf.mjs} +163 -4
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +1 -1
- package/llms.txt +1 -1
- 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
|
|
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";
|
|
@@ -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;
|
|
@@ -54439,9 +54439,54 @@ function isElementNode(value) {
|
|
|
54439
54439
|
return typeof value === "object" && value !== null && "type" in value && "props" in value && "children" in value;
|
|
54440
54440
|
}
|
|
54441
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
|
+
/**
|
|
54442
54486
|
* One plain argument of a compiled message as a part: an element node keeps its place in the
|
|
54443
54487
|
* sentence, a list goes through `Intl.ListFormat` and a number through `Intl.NumberFormat` of the
|
|
54444
|
-
* kit's locale, anything else is read as text.
|
|
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
|
|
54445
54490
|
* `argument` for a message with `{name}`.
|
|
54446
54491
|
*
|
|
54447
54492
|
* @param value - The parameter of the message.
|
|
@@ -54449,18 +54494,23 @@ function isElementNode(value) {
|
|
|
54449
54494
|
* @returns The part.
|
|
54450
54495
|
* @example
|
|
54451
54496
|
* ```ts
|
|
54452
|
-
* // 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.
|
|
54453
54499
|
* const lobby: I18n.CompiledMessages = {
|
|
54454
54500
|
* "lobby.host": (p, intl) => [{ kind: "text", text: "Host: " }, messageArgument(p.name, intl)]
|
|
54455
54501
|
* };
|
|
54502
|
+
* const coin: ElementNode = { type: "icon", props: { name: "hud.coin" }, children: [] };
|
|
54456
54503
|
* app.i18n.plain(tr("lobby.host", { name: ["Ann", "Bob", "Cy"] })); // "Host: Ann, Bob, and Cy"
|
|
54457
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" }]
|
|
54458
54508
|
* ```
|
|
54459
54509
|
*/
|
|
54460
54510
|
function messageArgument(value, intl) {
|
|
54461
54511
|
if (Array.isArray(value)) return {
|
|
54462
54512
|
kind: "text",
|
|
54463
|
-
text: intl.list().format(value)
|
|
54513
|
+
text: intl.list().format(escapeItems(value))
|
|
54464
54514
|
};
|
|
54465
54515
|
if (typeof value === "number") return {
|
|
54466
54516
|
kind: "text",
|
|
@@ -54472,7 +54522,7 @@ function messageArgument(value, intl) {
|
|
|
54472
54522
|
};
|
|
54473
54523
|
return {
|
|
54474
54524
|
kind: "text",
|
|
54475
|
-
text: String(value)
|
|
54525
|
+
text: escapeTags$1(String(value))
|
|
54476
54526
|
};
|
|
54477
54527
|
}
|
|
54478
54528
|
/**
|
|
@@ -54791,6 +54841,20 @@ function formatIn(ctx, message, locale) {
|
|
|
54791
54841
|
return mergeParts(compiled(message.params ?? {}, kitOf(ctx.state, target)));
|
|
54792
54842
|
}
|
|
54793
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
|
+
/**
|
|
54794
54858
|
* Switches the current locale on the queue: load what is lazy (the modules of the held bundles
|
|
54795
54859
|
* included), set the locale, send the event.
|
|
54796
54860
|
*
|
|
@@ -54898,7 +54962,7 @@ function createI18nApi(ctx) {
|
|
|
54898
54962
|
locale: () => ctx.state.locale,
|
|
54899
54963
|
setLocale: (locale) => setLocale(ctx, locale),
|
|
54900
54964
|
format: (message, locale) => formatIn(ctx, message, locale),
|
|
54901
|
-
plain: (message) => formatIn(ctx, message)
|
|
54965
|
+
plain: (message) => plainOf$1(formatIn(ctx, message)),
|
|
54902
54966
|
has: (key) => resolve$1(ctx.state, key, ctx.state.locale, ctx.config.fallback) !== void 0,
|
|
54903
54967
|
isKey: (value) => isKnownKey(ctx.state, ctx.config.fallback, value),
|
|
54904
54968
|
duration: (ms, style = "short") => kitOf(ctx.state, ctx.state.locale).duration({
|
|
@@ -58282,11 +58346,443 @@ const platformPlugin = /*#__PURE__*/ createPlugin$1("platform", {
|
|
|
58282
58346
|
onStop: ({ state }) => stopPlatform(state)
|
|
58283
58347
|
});
|
|
58284
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
|
|
58285
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
|
+
*/
|
|
58286
58784
|
/** Advance of a glyph no table knows, as a share of the style size. */
|
|
58287
58785
|
const FALLBACK_ADVANCE = .6;
|
|
58288
|
-
/** Line height of a style whose font is not loaded, as a share of the style size. */
|
|
58289
|
-
const FALLBACK_LINE = 1.2;
|
|
58290
58786
|
/**
|
|
58291
58787
|
* How much wider than its box a line of a `"box"` style may be. `ui` lays a text out in whole units
|
|
58292
58788
|
* and rounds its measure with this tolerance, so a line that adds up to a hair over a whole unit
|
|
@@ -58377,14 +58873,30 @@ function readJson(fnt) {
|
|
|
58377
58873
|
if (!isRecord$1(data) || !isRecord$1(data.info) || !Array.isArray(data.chars)) return void 0;
|
|
58378
58874
|
const size = Math.abs(numberOf(data.info.size) ?? 0);
|
|
58379
58875
|
if (size <= 0) return void 0;
|
|
58380
|
-
const common = isRecord$1(data.common) ?
|
|
58876
|
+
const common = isRecord$1(data.common) ? data.common : {};
|
|
58877
|
+
const lineHeight = numberOf(common.lineHeight) ?? 0;
|
|
58381
58878
|
return {
|
|
58382
58879
|
size,
|
|
58383
|
-
lineHeight:
|
|
58880
|
+
lineHeight: lineHeight > 0 ? lineHeight : size,
|
|
58881
|
+
base: baseOf(numberOf(common.base), size),
|
|
58384
58882
|
advances: readChars(data.chars)
|
|
58385
58883
|
};
|
|
58386
58884
|
}
|
|
58387
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
|
+
/**
|
|
58388
58900
|
* Creates the empty glyph table. Its own function because lint rule L5 refuses a collection built
|
|
58389
58901
|
* inside an exported declaration.
|
|
58390
58902
|
*
|
|
@@ -58415,6 +58927,7 @@ function readXml(fnt) {
|
|
|
58415
58927
|
const size = Math.abs(attribute(fnt, /<info[^>]*\ssize="(-?\d+)"/) ?? 0);
|
|
58416
58928
|
if (size <= 0) return void 0;
|
|
58417
58929
|
const lineHeight = attribute(fnt, /<common[^>]*\slineHeight="(-?\d+)"/) ?? 0;
|
|
58930
|
+
const base = attribute(fnt, /<common[^>]*\sbase="(-?\d+)"/);
|
|
58418
58931
|
const advances = emptyAdvances();
|
|
58419
58932
|
for (const match of fnt.matchAll(/<char\s(?:[^>"]|"[^"]*")*>/g)) {
|
|
58420
58933
|
const tag = match[0];
|
|
@@ -58426,6 +58939,7 @@ function readXml(fnt) {
|
|
|
58426
58939
|
return {
|
|
58427
58940
|
size,
|
|
58428
58941
|
lineHeight: lineHeight > 0 ? lineHeight : size,
|
|
58942
|
+
base: baseOf(base, size),
|
|
58429
58943
|
advances
|
|
58430
58944
|
};
|
|
58431
58945
|
}
|
|
@@ -58435,12 +58949,12 @@ function readXml(fnt) {
|
|
|
58435
58949
|
*
|
|
58436
58950
|
* @param fnt - The `.fnt` file as text, in BMFont XML or BMFont JSON.
|
|
58437
58951
|
* @param key - The asset key of the font, for the error.
|
|
58438
|
-
* @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.
|
|
58439
58953
|
* @throws {Error} When the file is in neither format.
|
|
58440
58954
|
* @example
|
|
58441
58955
|
* ```ts
|
|
58442
|
-
* parseAdvances('{"info":{"size":32},"common":{"lineHeight":40},"chars":[]}', "ui.font-body");
|
|
58443
|
-
* // { 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) }
|
|
58444
58958
|
* ```
|
|
58445
58959
|
*/
|
|
58446
58960
|
function parseAdvances(fnt, key) {
|
|
@@ -58449,60 +58963,11 @@ function parseAdvances(fnt, key) {
|
|
|
58449
58963
|
return table;
|
|
58450
58964
|
}
|
|
58451
58965
|
/**
|
|
58452
|
-
* The font one run is drawn with: the bold or italic font when the style names it, else the
|
|
58453
|
-
* font of the style.
|
|
58454
|
-
*
|
|
58455
|
-
* @param style - The style of the label.
|
|
58456
|
-
* @param run - The run to draw.
|
|
58457
|
-
* @returns The asset key of the font.
|
|
58458
|
-
* @example
|
|
58459
|
-
* ```ts
|
|
58460
|
-
* fontOfRun(bodyStyle, { kind: "text", text: "a", bold: true, italic: false, color: undefined });
|
|
58461
|
-
* // "ui.font-body": the body style names no bold font, so the bold is synthetic
|
|
58462
|
-
* ```
|
|
58463
|
-
*/
|
|
58464
|
-
function fontOfRun(style, run) {
|
|
58465
|
-
if (run.bold && style.bold !== void 0) return style.bold;
|
|
58466
|
-
if (run.italic && style.italic !== void 0) return style.italic;
|
|
58467
|
-
return style.font;
|
|
58468
|
-
}
|
|
58469
|
-
/**
|
|
58470
|
-
* The height of one line of a style: `lineHeight × size` when the style names its line, else the
|
|
58471
|
-
* line of its own font.
|
|
58472
|
-
*
|
|
58473
|
-
* @param style - The style of the label.
|
|
58474
|
-
* @param tables - The advance tables that are loaded.
|
|
58475
|
-
* @returns The line height in reference pixels.
|
|
58476
|
-
* @example
|
|
58477
|
-
* ```ts
|
|
58478
|
-
* lineHeightOf(bodyStyle, new Map()); // 38.4: 1.2 em of a 32 px style with no font loaded
|
|
58479
|
-
* ```
|
|
58480
|
-
*/
|
|
58481
|
-
function lineHeightOf(style, tables) {
|
|
58482
|
-
return style.lineHeight === void 0 ? fontLineOf(style, tables) : style.lineHeight * style.size;
|
|
58483
|
-
}
|
|
58484
|
-
/**
|
|
58485
|
-
* The height of one line of a style's own font, whatever line the style names: what the glyphs
|
|
58486
|
-
* are drawn into, so the gap to `lineHeightOf` is the leading.
|
|
58487
|
-
*
|
|
58488
|
-
* @param style - The style of the label.
|
|
58489
|
-
* @param tables - The advance tables that are loaded.
|
|
58490
|
-
* @returns The font's line height in reference pixels.
|
|
58491
|
-
* @example
|
|
58492
|
-
* ```ts
|
|
58493
|
-
* fontLineOf({ ...bodyStyle, lineHeight: 1.5 }, new Map()); // 38.4: the font's 1.2 em, not 48
|
|
58494
|
-
* ```
|
|
58495
|
-
*/
|
|
58496
|
-
function fontLineOf(style, tables) {
|
|
58497
|
-
const table = tables.get(style.font);
|
|
58498
|
-
return table === void 0 ? FALLBACK_LINE * style.size : table.lineHeight * (style.size / table.size);
|
|
58499
|
-
}
|
|
58500
|
-
/**
|
|
58501
58966
|
* The width of one character, letter spacing included. A character the loaded font has no glyph
|
|
58502
58967
|
* for is 0 wide, spacing and all: Pixi skips it when it lays the run out and draws nothing.
|
|
58503
58968
|
*
|
|
58504
58969
|
* @param char - The character.
|
|
58505
|
-
* @param style - The
|
|
58970
|
+
* @param style - The look of the run.
|
|
58506
58971
|
* @param fontKey - The font of the run.
|
|
58507
58972
|
* @param tables - The advance tables that are loaded.
|
|
58508
58973
|
* @param options - Where a warning goes.
|
|
@@ -58524,35 +58989,37 @@ function advanceOf(char, style, fontKey, tables, options) {
|
|
|
58524
58989
|
return 0;
|
|
58525
58990
|
}
|
|
58526
58991
|
/**
|
|
58527
|
-
* The width of one run: the advances of its glyphs, or a square at the line
|
|
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.
|
|
58528
58994
|
*
|
|
58529
58995
|
* @param run - The run to measure.
|
|
58530
58996
|
* @param style - The style of the label.
|
|
58531
58997
|
* @param tables - The advance tables that are loaded.
|
|
58532
|
-
* @param options - Where a warning goes.
|
|
58998
|
+
* @param options - Where a warning goes, and the styles and bold looks a run may take.
|
|
58533
58999
|
* @returns The width in reference pixels.
|
|
58534
59000
|
* @example
|
|
58535
59001
|
* ```ts
|
|
58536
|
-
* 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
|
|
58537
59003
|
* ```
|
|
58538
59004
|
*/
|
|
58539
59005
|
function measureRun(run, style, tables, options) {
|
|
58540
|
-
|
|
58541
|
-
|
|
59006
|
+
const look = lookIn(style, run, options);
|
|
59007
|
+
if (run.kind === "icon") return lineHeightOf(look, tables) + look.letterSpacing;
|
|
59008
|
+
const fontKey = fontOfRun(look, run);
|
|
58542
59009
|
let width = 0;
|
|
58543
|
-
for (const char of run.text) width += advanceOf(char,
|
|
59010
|
+
for (const char of run.text) width += advanceOf(char, look, fontKey, tables, options);
|
|
58544
59011
|
return width;
|
|
58545
59012
|
}
|
|
58546
59013
|
/**
|
|
58547
59014
|
* Tells whether a glyph piece may join the last run of a line: both glyphs, with the same bold,
|
|
58548
|
-
* italic and
|
|
59015
|
+
* italic, colour and span. An icon never merges.
|
|
58549
59016
|
*
|
|
58550
59017
|
* @param last - The last run of the line, if any.
|
|
58551
59018
|
* @param piece - The glyph piece to append.
|
|
58552
59019
|
* @returns True when the piece's text may be added to `last`.
|
|
58553
59020
|
*/
|
|
58554
59021
|
function canMerge(last, piece) {
|
|
58555
|
-
return last?.kind === "text" && last
|
|
59022
|
+
return last?.kind === "text" && sameLook(last, piece);
|
|
58556
59023
|
}
|
|
58557
59024
|
/**
|
|
58558
59025
|
* Appends a piece to a line, merging glyphs into the last run when both are glyphs with the same
|
|
@@ -58572,7 +59039,42 @@ function appendRun(runs, piece) {
|
|
|
58572
59039
|
runs.push(piece.kind === "text" ? { ...piece } : piece);
|
|
58573
59040
|
}
|
|
58574
59041
|
/**
|
|
58575
|
-
*
|
|
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.
|
|
58576
59078
|
*
|
|
58577
59079
|
* @param runs - The runs of the block.
|
|
58578
59080
|
* @param style - The style of the label.
|
|
@@ -58585,10 +59087,8 @@ function layoutFixed(runs, style, tables, options) {
|
|
|
58585
59087
|
let current = [];
|
|
58586
59088
|
let width = 0;
|
|
58587
59089
|
const push = () => {
|
|
58588
|
-
lines.
|
|
58589
|
-
|
|
58590
|
-
width
|
|
58591
|
-
});
|
|
59090
|
+
const indent = lines.length === 0 ? style.textIndent ?? 0 : 0;
|
|
59091
|
+
lines.push(openLine(current, indentedWidth(current, width, indent)));
|
|
58592
59092
|
current = [];
|
|
58593
59093
|
width = 0;
|
|
58594
59094
|
};
|
|
@@ -58743,17 +59243,15 @@ function pushSoft(tokens, hyphen, metrics) {
|
|
|
58743
59243
|
});
|
|
58744
59244
|
}
|
|
58745
59245
|
/**
|
|
58746
|
-
* Closes the open line and starts a new one.
|
|
59246
|
+
* Closes the open line and starts a new one at the edge.
|
|
58747
59247
|
*
|
|
58748
59248
|
* @param builder - The lines built so far.
|
|
58749
59249
|
*/
|
|
58750
59250
|
function commit(builder) {
|
|
58751
|
-
builder.lines.push(
|
|
58752
|
-
runs: builder.runs,
|
|
58753
|
-
width: builder.width
|
|
58754
|
-
});
|
|
59251
|
+
builder.lines.push(openLine(builder.runs, indentedWidth(builder.runs, builder.width, builder.indent)));
|
|
58755
59252
|
builder.runs = [];
|
|
58756
59253
|
builder.width = 0;
|
|
59254
|
+
builder.indent = 0;
|
|
58757
59255
|
}
|
|
58758
59256
|
/**
|
|
58759
59257
|
* Puts a whole token on the open line.
|
|
@@ -58773,7 +59271,8 @@ function add(builder, token) {
|
|
|
58773
59271
|
* @returns The pieces, in reading order.
|
|
58774
59272
|
* @example
|
|
58775
59273
|
* ```ts
|
|
58776
|
-
* glyphsOf({ kind: "icon", key: "hud.coin"
|
|
59274
|
+
* glyphsOf({ kind: "icon", key: "hud.coin", span: undefined });
|
|
59275
|
+
* // [{ kind: "icon", key: "hud.coin", span: undefined }]
|
|
58777
59276
|
* ```
|
|
58778
59277
|
*/
|
|
58779
59278
|
function glyphsOf(run) {
|
|
@@ -58784,7 +59283,20 @@ function glyphsOf(run) {
|
|
|
58784
59283
|
}));
|
|
58785
59284
|
}
|
|
58786
59285
|
/**
|
|
58787
|
-
*
|
|
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.
|
|
58788
59300
|
*
|
|
58789
59301
|
* @param builder - The lines built so far.
|
|
58790
59302
|
* @param token - The word to break.
|
|
@@ -58794,7 +59306,7 @@ function glyphsOf(run) {
|
|
|
58794
59306
|
function breakWord(builder, token, wrap, metrics) {
|
|
58795
59307
|
for (const part of token.runs) for (const piece of glyphsOf(part)) {
|
|
58796
59308
|
const glyph = measureRun(piece, metrics.style, metrics.tables, metrics.options);
|
|
58797
|
-
if (builder
|
|
59309
|
+
if (overflows(builder, glyph, wrap)) commit(builder);
|
|
58798
59310
|
appendRun(builder.runs, piece);
|
|
58799
59311
|
builder.width += glyph;
|
|
58800
59312
|
}
|
|
@@ -58802,8 +59314,9 @@ function breakWord(builder, token, wrap, metrics) {
|
|
|
58802
59314
|
/**
|
|
58803
59315
|
* Places one word: on the open line when it still fits there with the spaces before it and the
|
|
58804
59316
|
* hyphen a break after it would draw, on the next one when it does not, and glyph by glyph when
|
|
58805
|
-
* it fits on no line at all
|
|
58806
|
-
*
|
|
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.
|
|
58807
59320
|
*
|
|
58808
59321
|
* @param builder - The lines built so far.
|
|
58809
59322
|
* @param token - The word to place.
|
|
@@ -58814,11 +59327,11 @@ function breakWord(builder, token, wrap, metrics) {
|
|
|
58814
59327
|
function placeWord(builder, token, pending, wrap, metrics) {
|
|
58815
59328
|
const space = pending?.kind === "space" ? pending : void 0;
|
|
58816
59329
|
const lead = space?.width ?? 0;
|
|
58817
|
-
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) {
|
|
58818
59331
|
if (pending?.kind === "soft") add(builder, pending);
|
|
58819
59332
|
commit(builder);
|
|
58820
59333
|
} else if (space !== void 0) add(builder, space);
|
|
58821
|
-
if (token.width <= wrap) add(builder, token);
|
|
59334
|
+
if (builder.indent + token.width <= wrap) add(builder, token);
|
|
58822
59335
|
else breakWord(builder, token, wrap, metrics);
|
|
58823
59336
|
}
|
|
58824
59337
|
/**
|
|
@@ -58835,7 +59348,8 @@ function wrapTokens(tokens, metrics, wrap) {
|
|
|
58835
59348
|
const builder = {
|
|
58836
59349
|
lines: [],
|
|
58837
59350
|
runs: [],
|
|
58838
|
-
width: 0
|
|
59351
|
+
width: 0,
|
|
59352
|
+
indent: metrics.style.textIndent ?? 0
|
|
58839
59353
|
};
|
|
58840
59354
|
let pending;
|
|
58841
59355
|
for (const token of tokens) {
|
|
@@ -58875,9 +59389,42 @@ function widestWord(tokens) {
|
|
|
58875
59389
|
return widest;
|
|
58876
59390
|
}
|
|
58877
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
|
+
/**
|
|
58878
59424
|
* Evens the greedy lines of a balanced style: the narrowest width in `[widest word, wrap]` that
|
|
58879
|
-
* keeps their number, found in 16 halvings, and the lines at that width.
|
|
58880
|
-
*
|
|
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.
|
|
58881
59428
|
*
|
|
58882
59429
|
* @param tokens - The tokens of the block, as the greedy pass read them.
|
|
58883
59430
|
* @param greedy - The greedy lines at the wrap.
|
|
@@ -58887,9 +59434,10 @@ function widestWord(tokens) {
|
|
|
58887
59434
|
*/
|
|
58888
59435
|
function balanceLines(tokens, greedy, metrics, wrap) {
|
|
58889
59436
|
const count = greedy.length;
|
|
58890
|
-
|
|
59437
|
+
if (!isBalanced(count)) return greedy;
|
|
59438
|
+
let low = Math.max(widestWord(tokens), firstWord(tokens, metrics.style.textIndent ?? 0));
|
|
58891
59439
|
let high = wrap;
|
|
58892
|
-
if (
|
|
59440
|
+
if (low >= high) return greedy;
|
|
58893
59441
|
for (let step = 0; step < BALANCE_STEPS; step += 1) {
|
|
58894
59442
|
const middle = (low + high) / 2;
|
|
58895
59443
|
if (wrapTokens(tokens, metrics, middle).length <= count) high = middle;
|
|
@@ -58919,11 +59467,14 @@ function layoutWrapped(runs, metrics, wrap) {
|
|
|
58919
59467
|
*/
|
|
58920
59468
|
function onceOnly(options) {
|
|
58921
59469
|
const seen = emptyKeys();
|
|
58922
|
-
return {
|
|
58923
|
-
|
|
58924
|
-
|
|
58925
|
-
|
|
58926
|
-
|
|
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
|
+
};
|
|
58927
59478
|
}
|
|
58928
59479
|
/**
|
|
58929
59480
|
* Creates the empty key set of one layout, for the same reason as `emptyAdvances`.
|
|
@@ -58951,21 +59502,22 @@ function wrapOf(style, box) {
|
|
|
58951
59502
|
return box > 0 ? box + BOX_SLACK : void 0;
|
|
58952
59503
|
}
|
|
58953
59504
|
/**
|
|
58954
|
-
* Lays a block of runs out: the lines, the width of the widest one and the total
|
|
58955
|
-
* alignment of the style changes nothing here; it moves the lines when they are
|
|
58956
|
-
* with `wrap: "box"` wraps at `box`, the width `ui` laid its text element out at,
|
|
58957
|
-
* 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.
|
|
58958
59510
|
*
|
|
58959
59511
|
* @param runs - What `parseTags` made of the resolved string.
|
|
58960
59512
|
* @param style - The style of the label.
|
|
58961
59513
|
* @param tables - The advance tables that are loaded, by font key.
|
|
58962
|
-
* @param options - Where a warning goes.
|
|
59514
|
+
* @param options - Where a warning goes, and the styles and bold looks a run may take.
|
|
58963
59515
|
* @param box - The width a `"box"` style wraps at, in reference pixels; 0 for none.
|
|
58964
59516
|
* @returns The lines and the size of the block in reference pixels.
|
|
58965
59517
|
* @example
|
|
58966
59518
|
* ```ts
|
|
58967
59519
|
* layoutRuns([], bodyStyle, new Map(), { warn: () => undefined });
|
|
58968
|
-
* // { 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 }
|
|
58969
59521
|
* ```
|
|
58970
59522
|
*/
|
|
58971
59523
|
function layoutRuns(runs, style, tables, options, box = 0) {
|
|
@@ -58976,167 +59528,14 @@ function layoutRuns(runs, style, tables, options, box = 0) {
|
|
|
58976
59528
|
tables,
|
|
58977
59529
|
options: once
|
|
58978
59530
|
}, wrap);
|
|
59531
|
+
boxLines(lines, style, tables, once);
|
|
58979
59532
|
let width = 0;
|
|
58980
59533
|
for (const line of lines) width = Math.max(width, line.width);
|
|
58981
59534
|
return {
|
|
58982
59535
|
lines,
|
|
58983
59536
|
width,
|
|
58984
|
-
height: lines
|
|
58985
|
-
};
|
|
58986
|
-
}
|
|
58987
|
-
//#endregion
|
|
58988
|
-
//#region src/plugins/text/tags.ts
|
|
58989
|
-
/** Matches an opening colour tag. Six hex digits: `#rgb` is not accepted. */
|
|
58990
|
-
const COLOR_TAG = /^color=#([\da-f]{6})$/i;
|
|
58991
|
-
/** Matches an inline icon tag, which has no closing tag. */
|
|
58992
|
-
const ICON_TAG = /^icon=(\S+)$/;
|
|
58993
|
-
/**
|
|
58994
|
-
* Reads an opening tag.
|
|
58995
|
-
*
|
|
58996
|
-
* @param body - What stood between the angle brackets.
|
|
58997
|
-
* @returns The tag, or `undefined` when it is not one this grammar knows.
|
|
58998
|
-
* @example
|
|
58999
|
-
* ```ts
|
|
59000
|
-
* openTag("color=#ff0000"); // { name: "color", color: 16711680 }
|
|
59001
|
-
* ```
|
|
59002
|
-
*/
|
|
59003
|
-
function openTag(body) {
|
|
59004
|
-
if (body === "b" || body === "i") return {
|
|
59005
|
-
name: body,
|
|
59006
|
-
color: void 0
|
|
59537
|
+
height: blockHeight(lines)
|
|
59007
59538
|
};
|
|
59008
|
-
const colour = COLOR_TAG.exec(body);
|
|
59009
|
-
if (colour === null) return void 0;
|
|
59010
|
-
return {
|
|
59011
|
-
name: "color",
|
|
59012
|
-
color: Number.parseInt(colour[1] ?? "0", 16)
|
|
59013
|
-
};
|
|
59014
|
-
}
|
|
59015
|
-
/**
|
|
59016
|
-
* Appends text to the runs, merging it into the last one when the flags are the same.
|
|
59017
|
-
*
|
|
59018
|
-
* @param runs - The runs built so far.
|
|
59019
|
-
* @param text - The characters to append.
|
|
59020
|
-
* @param stack - The tags that are open around them.
|
|
59021
|
-
*/
|
|
59022
|
-
function pushText(runs, text, stack) {
|
|
59023
|
-
let color;
|
|
59024
|
-
for (const open of stack) if (open.name === "color") color = open.color;
|
|
59025
|
-
const piece = {
|
|
59026
|
-
kind: "text",
|
|
59027
|
-
text,
|
|
59028
|
-
bold: stack.some((open) => open.name === "b"),
|
|
59029
|
-
italic: stack.some((open) => open.name === "i"),
|
|
59030
|
-
color
|
|
59031
|
-
};
|
|
59032
|
-
const last = runs.at(-1);
|
|
59033
|
-
if (last !== void 0 && last.kind === "text" && last.bold === piece.bold && last.italic === piece.italic && last.color === piece.color) {
|
|
59034
|
-
last.text += text;
|
|
59035
|
-
return;
|
|
59036
|
-
}
|
|
59037
|
-
runs.push(piece);
|
|
59038
|
-
}
|
|
59039
|
-
/**
|
|
59040
|
-
* Reports one source string once, whatever is wrong with it.
|
|
59041
|
-
*
|
|
59042
|
-
* @param state - The parse in progress.
|
|
59043
|
-
* @param message - The log event.
|
|
59044
|
-
* @param tag - The tag that was wrong.
|
|
59045
|
-
*/
|
|
59046
|
-
function complain(state, message, tag) {
|
|
59047
|
-
if (state.warned) return;
|
|
59048
|
-
state.warned = true;
|
|
59049
|
-
state.warn(`tag:${state.source}`, message, {
|
|
59050
|
-
tag,
|
|
59051
|
-
text: state.source
|
|
59052
|
-
});
|
|
59053
|
-
}
|
|
59054
|
-
/**
|
|
59055
|
-
* Writes what was read so far into a run.
|
|
59056
|
-
*
|
|
59057
|
-
* @param state - The parse in progress.
|
|
59058
|
-
*/
|
|
59059
|
-
function flush(state) {
|
|
59060
|
-
if (state.buffer.length === 0) return;
|
|
59061
|
-
pushText(state.runs, state.buffer, state.stack);
|
|
59062
|
-
state.buffer = "";
|
|
59063
|
-
}
|
|
59064
|
-
/**
|
|
59065
|
-
* Applies one tag: an icon run, an opening tag, a matching close, or, when it is none of those,
|
|
59066
|
-
* literal text and one warning.
|
|
59067
|
-
*
|
|
59068
|
-
* @param state - The parse in progress.
|
|
59069
|
-
* @param body - What stood between the angle brackets.
|
|
59070
|
-
*/
|
|
59071
|
-
function applyTag(state, body) {
|
|
59072
|
-
const icon = ICON_TAG.exec(body);
|
|
59073
|
-
if (icon !== null) {
|
|
59074
|
-
flush(state);
|
|
59075
|
-
state.runs.push({
|
|
59076
|
-
kind: "icon",
|
|
59077
|
-
key: icon[1] ?? ""
|
|
59078
|
-
});
|
|
59079
|
-
return;
|
|
59080
|
-
}
|
|
59081
|
-
const open = openTag(body);
|
|
59082
|
-
if (open !== void 0) {
|
|
59083
|
-
flush(state);
|
|
59084
|
-
state.stack.push(open);
|
|
59085
|
-
return;
|
|
59086
|
-
}
|
|
59087
|
-
const closes = body.startsWith("/");
|
|
59088
|
-
const at = closes ? state.stack.map((entry) => entry.name).lastIndexOf(body.slice(1)) : -1;
|
|
59089
|
-
if (at !== -1) {
|
|
59090
|
-
flush(state);
|
|
59091
|
-
state.stack.splice(at, 1);
|
|
59092
|
-
return;
|
|
59093
|
-
}
|
|
59094
|
-
complain(state, closes ? "text: stray closing tag" : "text: unknown tag", body);
|
|
59095
|
-
state.buffer += `<${body}>`;
|
|
59096
|
-
}
|
|
59097
|
-
/**
|
|
59098
|
-
* Turns a resolved string into runs of glyphs and inline icons. Everything the grammar does not
|
|
59099
|
-
* know stays visible: the tag is kept as literal text and the source is reported once.
|
|
59100
|
-
*
|
|
59101
|
-
* @param source - The resolved string, as it was written or formatted.
|
|
59102
|
-
* @param warn - Called at most once per source, with the key `tag:<source>`.
|
|
59103
|
-
* @returns The runs, in reading order, with equal neighbours merged.
|
|
59104
|
-
* @example
|
|
59105
|
-
* ```ts
|
|
59106
|
-
* parseTags("<b>a</b>b", () => undefined);
|
|
59107
|
-
* // [{ kind: "text", text: "a", bold: true, italic: false, color: undefined },
|
|
59108
|
-
* // { kind: "text", text: "b", bold: false, italic: false, color: undefined }]
|
|
59109
|
-
* ```
|
|
59110
|
-
*/
|
|
59111
|
-
function parseTags(source, warn) {
|
|
59112
|
-
const state = {
|
|
59113
|
-
source,
|
|
59114
|
-
runs: [],
|
|
59115
|
-
stack: [],
|
|
59116
|
-
buffer: "",
|
|
59117
|
-
warned: false,
|
|
59118
|
-
warn
|
|
59119
|
-
};
|
|
59120
|
-
let index = 0;
|
|
59121
|
-
while (index < source.length) {
|
|
59122
|
-
const char = source[index] ?? "";
|
|
59123
|
-
if (char === "\\" && source[index + 1] === "<") {
|
|
59124
|
-
state.buffer += "<";
|
|
59125
|
-
index += 2;
|
|
59126
|
-
continue;
|
|
59127
|
-
}
|
|
59128
|
-
const close = char === "<" ? source.indexOf(">", index + 1) : -1;
|
|
59129
|
-
if (close === -1) {
|
|
59130
|
-
state.buffer += char;
|
|
59131
|
-
index += 1;
|
|
59132
|
-
continue;
|
|
59133
|
-
}
|
|
59134
|
-
applyTag(state, source.slice(index + 1, close));
|
|
59135
|
-
index = close + 1;
|
|
59136
|
-
}
|
|
59137
|
-
flush(state);
|
|
59138
|
-
if (state.stack.length > 0) complain(state, "text: unclosed tag", state.stack[0]?.name ?? "");
|
|
59139
|
-
return state.runs;
|
|
59140
59539
|
}
|
|
59141
59540
|
//#endregion
|
|
59142
59541
|
//#region src/plugins/text/resolve.ts
|
|
@@ -59146,13 +59545,17 @@ const CACHE_SEPARATOR = String.fromCodePoint(0);
|
|
|
59146
59545
|
const CACHE_LIMIT = 1024;
|
|
59147
59546
|
/** How every inline icon tag starts. A resolved text without it holds no icon. */
|
|
59148
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>";
|
|
59149
59552
|
/** The name the system is registered under; it shows up in a world error message. */
|
|
59150
59553
|
const TEXT_SYSTEM_NAME = "text.resolve";
|
|
59151
59554
|
/**
|
|
59152
59555
|
* Writes one dev warning per key. Every warning of this plugin goes through here, so a font, a
|
|
59153
59556
|
* style, a glyph or a bad tag is reported once and never floods a frame.
|
|
59154
59557
|
*
|
|
59155
|
-
* @param ctx -
|
|
59558
|
+
* @param ctx - Kernel or domain context of the text plugin.
|
|
59156
59559
|
* @param key - What makes this warning unique.
|
|
59157
59560
|
* @param message - The log event.
|
|
59158
59561
|
* @param data - What to log with it.
|
|
@@ -59165,7 +59568,7 @@ function warnOnce(ctx, key, message, data) {
|
|
|
59165
59568
|
/**
|
|
59166
59569
|
* The warning the pure modules are handed, bound to this app's `warned` set.
|
|
59167
59570
|
*
|
|
59168
|
-
* @param ctx -
|
|
59571
|
+
* @param ctx - Kernel or domain context of the text plugin.
|
|
59169
59572
|
* @returns A warning that repeats nothing.
|
|
59170
59573
|
*/
|
|
59171
59574
|
function warnFor(ctx) {
|
|
@@ -59196,9 +59599,42 @@ function wrapsAtBox(ctx, styleName) {
|
|
|
59196
59599
|
return (ctx.state.styles.get(styleName) ?? ctx.state.styles.get("body"))?.wrap === "box";
|
|
59197
59600
|
}
|
|
59198
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
|
+
/**
|
|
59199
59634
|
* The layout of one resolved string in one style, from the cache or freshly laid out. The cache
|
|
59200
59635
|
* is what makes `measure` cheap enough for `ui` to ask per invalidation. A `"box"` style with a
|
|
59201
|
-
* 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.
|
|
59202
59638
|
*
|
|
59203
59639
|
* @param ctx - Domain context of the text plugin.
|
|
59204
59640
|
* @param resolved - The tagged string.
|
|
@@ -59211,16 +59647,28 @@ function layoutFor(ctx, resolved, styleName, box = 0) {
|
|
|
59211
59647
|
const key = width > 0 ? `${styleName}${CACHE_SEPARATOR}${width}${CACHE_SEPARATOR}${resolved}` : `${styleName}${CACHE_SEPARATOR}${resolved}`;
|
|
59212
59648
|
const hit = ctx.state.cache.get(key);
|
|
59213
59649
|
if (hit !== void 0) return hit;
|
|
59214
|
-
const
|
|
59215
|
-
const
|
|
59216
|
-
if (
|
|
59217
|
-
|
|
59218
|
-
|
|
59219
|
-
}
|
|
59220
|
-
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);
|
|
59221
59655
|
return layout;
|
|
59222
59656
|
}
|
|
59223
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
|
+
/**
|
|
59224
59672
|
* Whether the font of a style has a glyph for one character, the lookup Pixi draws by: a
|
|
59225
59673
|
* character the font lacks is drawn as nothing and measures 0 wide. While the font is not loaded
|
|
59226
59674
|
* every character counts, as the fallback measures it.
|
|
@@ -59501,20 +59949,63 @@ function boxMoved(ctx, seen, text) {
|
|
|
59501
59949
|
return false;
|
|
59502
59950
|
}
|
|
59503
59951
|
/**
|
|
59504
|
-
*
|
|
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.
|
|
59505
59965
|
*
|
|
59506
59966
|
* @param ctx - Domain context of the text plugin.
|
|
59507
59967
|
* @param entity - The entity.
|
|
59508
|
-
* @param
|
|
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`.
|
|
59509
59971
|
*/
|
|
59510
|
-
function keepSize(ctx, entity,
|
|
59972
|
+
function keepSize(ctx, entity, resolved, style, box) {
|
|
59973
|
+
const layout = layoutFor(ctx, resolved, style, box);
|
|
59511
59974
|
const size = ctx.state.measured.get(entity);
|
|
59512
|
-
if (size === void 0)
|
|
59513
|
-
|
|
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
|
+
});
|
|
59514
59989
|
return;
|
|
59515
59990
|
}
|
|
59516
|
-
|
|
59517
|
-
|
|
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);
|
|
59518
60009
|
}
|
|
59519
60010
|
/**
|
|
59520
60011
|
* Tells whether a bound label already shows what its value would build: the same unit, style and
|
|
@@ -59545,14 +60036,27 @@ function isShown(seen, text, unit, worded, frame) {
|
|
|
59545
60036
|
function showBound(ctx, entity, text, next, value, style = text.style) {
|
|
59546
60037
|
const restyled = style !== text.style;
|
|
59547
60038
|
const changed = restyled || next !== text.resolved;
|
|
59548
|
-
if (changed)
|
|
59549
|
-
|
|
59550
|
-
|
|
59551
|
-
|
|
59552
|
-
|
|
59553
|
-
|
|
59554
|
-
|
|
59555
|
-
|
|
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 });
|
|
59556
60060
|
}
|
|
59557
60061
|
/**
|
|
59558
60062
|
* Writes the string a bound label already shows once more, and measures it again. A mark on a
|
|
@@ -59566,7 +60070,7 @@ function showBound(ctx, entity, text, next, value, style = text.style) {
|
|
|
59566
60070
|
*/
|
|
59567
60071
|
function showAgain(ctx, entity, text) {
|
|
59568
60072
|
ctx.deps.world.ecs.set(entity, Text, { resolved: text.resolved });
|
|
59569
|
-
keepSize(ctx, entity,
|
|
60073
|
+
keepSize(ctx, entity, text.resolved, text.style, text.box);
|
|
59570
60074
|
}
|
|
59571
60075
|
/**
|
|
59572
60076
|
* Reports a bound label whose style is not a digits style, once per style. An unknown style name
|
|
@@ -59617,9 +60121,9 @@ function stepBound(ctx, entity, text, bind, frame) {
|
|
|
59617
60121
|
}
|
|
59618
60122
|
/**
|
|
59619
60123
|
* One frame of a label whose bind names a format a feature registered. Its unit is the whole value.
|
|
59620
|
-
* While
|
|
59621
|
-
* is not called, a
|
|
59622
|
-
* 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
|
|
59623
60127
|
* bound field that holds no number shows nothing, as under a built-in format.
|
|
59624
60128
|
*
|
|
59625
60129
|
* @param ctx - Domain context of the text plugin.
|
|
@@ -59659,9 +60163,9 @@ function stepNamed(ctx, entity, text, bind, format, value, frame) {
|
|
|
59659
60163
|
* @param marked - Whether the label was marked this frame.
|
|
59660
60164
|
*/
|
|
59661
60165
|
function standStill(ctx, entity, text, seen, marked) {
|
|
60166
|
+
if (!marked && !boxMoved(ctx, seen, text)) return;
|
|
59662
60167
|
if (marked) showAgain(ctx, entity, text);
|
|
59663
|
-
else
|
|
59664
|
-
else return;
|
|
60168
|
+
else keepSize(ctx, entity, text.resolved, text.style, text.box);
|
|
59665
60169
|
seen.box = text.box;
|
|
59666
60170
|
}
|
|
59667
60171
|
/**
|
|
@@ -59695,7 +60199,7 @@ function stepText(ctx, entity, text, frame) {
|
|
|
59695
60199
|
return;
|
|
59696
60200
|
}
|
|
59697
60201
|
if (!isStale(ctx, entity, text, frame)) return;
|
|
59698
|
-
keepSize(ctx, entity,
|
|
60202
|
+
keepSize(ctx, entity, resolveContent(ctx, entity, text), text.style, text.box);
|
|
59699
60203
|
ctx.state.dirty.delete(entity);
|
|
59700
60204
|
remember(ctx, entity, text, frame);
|
|
59701
60205
|
}
|
|
@@ -59869,10 +60373,11 @@ function markDirty(ctx, keep = () => true) {
|
|
|
59869
60373
|
return marked;
|
|
59870
60374
|
}
|
|
59871
60375
|
/**
|
|
59872
|
-
* Tells whether a label is drawn with one of the asset keys: a font its style names,
|
|
59873
|
-
* icon of its resolved text
|
|
59874
|
-
*
|
|
59875
|
-
*
|
|
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.
|
|
59876
60381
|
*
|
|
59877
60382
|
* @param ctx - Domain context of the text plugin.
|
|
59878
60383
|
* @param text - The component value of the label.
|
|
@@ -59886,8 +60391,24 @@ function drawsWith(ctx, text, keys) {
|
|
|
59886
60391
|
style.bold,
|
|
59887
60392
|
style.italic
|
|
59888
60393
|
].some((font) => font !== void 0 && keys.includes(font))) return true;
|
|
59889
|
-
|
|
59890
|
-
|
|
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));
|
|
59891
60412
|
}
|
|
59892
60413
|
/**
|
|
59893
60414
|
* Forgets an entity whose `Text` left. Works on the state alone, because it is also what the
|
|
@@ -59899,6 +60420,7 @@ function drawsWith(ctx, text, keys) {
|
|
|
59899
60420
|
function forgetText(state, entity) {
|
|
59900
60421
|
state.seen.delete(entity);
|
|
59901
60422
|
state.measured.delete(entity);
|
|
60423
|
+
state.shown.delete(entity);
|
|
59902
60424
|
state.dirty.delete(entity);
|
|
59903
60425
|
}
|
|
59904
60426
|
//#endregion
|
|
@@ -59982,7 +60504,7 @@ function releaseFonts(ctx, keys) {
|
|
|
59982
60504
|
* @param ctx - Domain context of the text plugin.
|
|
59983
60505
|
*/
|
|
59984
60506
|
function refresh(ctx) {
|
|
59985
|
-
ctx.state
|
|
60507
|
+
dropLayouts(ctx.state);
|
|
59986
60508
|
markDirty(ctx);
|
|
59987
60509
|
}
|
|
59988
60510
|
/**
|
|
@@ -60047,29 +60569,51 @@ function reinstallFonts(ctx, fonts, reload) {
|
|
|
60047
60569
|
*/
|
|
60048
60570
|
function applyReplaced(ctx, keys, reload = reloadPage) {
|
|
60049
60571
|
const fonts = keys.filter((key) => ctx.state.fontKeys.has(key));
|
|
60050
|
-
if (fonts.length > 0) ctx.state
|
|
60572
|
+
if (fonts.length > 0) dropLayouts(ctx.state);
|
|
60051
60573
|
if (!reinstallFonts(ctx, fonts, reload)) return;
|
|
60052
60574
|
if (markDirty(ctx, (text) => drawsWith(ctx, text, keys)) === 0) return;
|
|
60053
60575
|
ctx.state.generation += 1;
|
|
60054
60576
|
}
|
|
60055
60577
|
/**
|
|
60056
|
-
*
|
|
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.
|
|
60057
60581
|
*
|
|
60058
60582
|
* @param style - The style of the label.
|
|
60059
|
-
* @param layout - The block
|
|
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.
|
|
60060
60600
|
* @param line - The line.
|
|
60061
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
|
+
* ```
|
|
60062
60606
|
*/
|
|
60063
|
-
function alignOffset(style,
|
|
60607
|
+
function alignOffset(style, width, line) {
|
|
60064
60608
|
if (style.align === "left") return 0;
|
|
60065
|
-
const slack =
|
|
60609
|
+
const slack = width - line.width;
|
|
60066
60610
|
return style.align === "center" ? slack / 2 : slack;
|
|
60067
60611
|
}
|
|
60068
60612
|
/**
|
|
60069
|
-
* The rings of copies one run is drawn over, bottom first: the outline of a stroked
|
|
60070
|
-
* synthetic bold in the fill when the
|
|
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.
|
|
60071
60615
|
*
|
|
60072
|
-
* @param style - The
|
|
60616
|
+
* @param style - The look of the run.
|
|
60073
60617
|
* @param run - The run to draw.
|
|
60074
60618
|
* @param fill - The colour the run is filled with.
|
|
60075
60619
|
* @returns The rings, none for a plain run.
|
|
@@ -60111,34 +60655,35 @@ function iconTexture(ctx, pixi, run) {
|
|
|
60111
60655
|
return ctx.deps.assets.texture(run.key) ?? pixi.Texture.EMPTY;
|
|
60112
60656
|
}
|
|
60113
60657
|
/**
|
|
60114
|
-
* Sizes the sprite of one inline icon square at the line
|
|
60658
|
+
* Sizes the sprite of one inline icon square at the line of its look and puts it where the icon
|
|
60115
60659
|
* starts.
|
|
60116
60660
|
*
|
|
60117
60661
|
* @param ctx - Domain context of the text plugin.
|
|
60118
60662
|
* @param sprite - The sprite of the icon.
|
|
60119
|
-
* @param style - The
|
|
60120
|
-
* @param
|
|
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.
|
|
60121
60666
|
*/
|
|
60122
|
-
function placeIcon(ctx, sprite, style,
|
|
60667
|
+
function placeIcon(ctx, sprite, style, x, y) {
|
|
60123
60668
|
const side = lineHeightOf(style, ctx.state.tables);
|
|
60124
60669
|
sprite.width = side;
|
|
60125
60670
|
sprite.height = side;
|
|
60126
|
-
sprite.x =
|
|
60127
|
-
sprite.y =
|
|
60671
|
+
sprite.x = x;
|
|
60672
|
+
sprite.y = y;
|
|
60128
60673
|
}
|
|
60129
60674
|
/**
|
|
60130
|
-
* Builds the sprite of one inline icon, square at the line
|
|
60675
|
+
* Builds the sprite of one inline icon, square at the line of its look.
|
|
60131
60676
|
*
|
|
60132
60677
|
* @param ctx - Domain context of the text plugin.
|
|
60133
60678
|
* @param pixi - The Pixi module the renderer loaded.
|
|
60134
60679
|
* @param run - The icon to draw.
|
|
60135
|
-
* @param style - The
|
|
60680
|
+
* @param style - The look of the icon.
|
|
60136
60681
|
* @param at - Where the icon starts, in the local space of the block.
|
|
60137
60682
|
* @returns The sprite.
|
|
60138
60683
|
*/
|
|
60139
60684
|
function buildIcon(ctx, pixi, run, style, at) {
|
|
60140
60685
|
const sprite = new pixi.Sprite(iconTexture(ctx, pixi, run));
|
|
60141
|
-
placeIcon(ctx, sprite, style, at);
|
|
60686
|
+
placeIcon(ctx, sprite, style, at.x, at.y);
|
|
60142
60687
|
return sprite;
|
|
60143
60688
|
}
|
|
60144
60689
|
/**
|
|
@@ -60147,7 +60692,7 @@ function buildIcon(ctx, pixi, run, style, at) {
|
|
|
60147
60692
|
*
|
|
60148
60693
|
* @param pixi - The Pixi module the renderer loaded.
|
|
60149
60694
|
* @param run - The glyphs to draw.
|
|
60150
|
-
* @param style - The
|
|
60695
|
+
* @param style - The look of the run.
|
|
60151
60696
|
* @param fill - The colour of the glyphs.
|
|
60152
60697
|
* @param at - Where the run starts, in the local space of the block.
|
|
60153
60698
|
* @returns The display object.
|
|
@@ -60173,8 +60718,8 @@ function buildGlyphs(pixi, run, style, fill, at) {
|
|
|
60173
60718
|
*
|
|
60174
60719
|
* @param pixi - The Pixi module the renderer loaded.
|
|
60175
60720
|
* @param run - The glyphs that cast the shadow.
|
|
60176
|
-
* @param style - The
|
|
60177
|
-
* @param shadow - The shadow of the
|
|
60721
|
+
* @param style - The look of the run.
|
|
60722
|
+
* @param shadow - The shadow of the look.
|
|
60178
60723
|
* @param at - Where the run starts, in the local space of the block.
|
|
60179
60724
|
* @returns The display object, to be drawn under the run.
|
|
60180
60725
|
*/
|
|
@@ -60217,7 +60762,7 @@ function ringSpots(ring, at) {
|
|
|
60217
60762
|
*
|
|
60218
60763
|
* @param pixi - The Pixi module the renderer loaded.
|
|
60219
60764
|
* @param run - The glyphs the ring surrounds.
|
|
60220
|
-
* @param style - The
|
|
60765
|
+
* @param style - The look of the run.
|
|
60221
60766
|
* @param ring - The width and colour of the ring.
|
|
60222
60767
|
* @param at - Where the run starts, in the local space of the block.
|
|
60223
60768
|
* @returns The copies, to be drawn under the run.
|
|
@@ -60230,32 +60775,13 @@ function buildRing(pixi, run, style, ring, at) {
|
|
|
60230
60775
|
});
|
|
60231
60776
|
}
|
|
60232
60777
|
/**
|
|
60233
|
-
* Where every object of one glyph run sits, in the order `buildRun` adds them: its shadow, the
|
|
60234
|
-
* copies of its rings, then the run itself.
|
|
60235
|
-
*
|
|
60236
|
-
* @param style - The style of the label.
|
|
60237
|
-
* @param run - The glyph run.
|
|
60238
|
-
* @param at - Where the run starts, in the local space of the block.
|
|
60239
|
-
* @returns One point per object.
|
|
60240
|
-
*/
|
|
60241
|
-
function glyphSpots(style, run, at) {
|
|
60242
|
-
const shadow = style.shadow;
|
|
60243
|
-
const spots = shadow === void 0 ? [] : [{
|
|
60244
|
-
x: at.x + shadow.dx,
|
|
60245
|
-
y: at.y + shadow.dy
|
|
60246
|
-
}];
|
|
60247
|
-
for (const ring of ringsOf(style, run, run.color ?? style.fill)) spots.push(...ringSpots(ring, at));
|
|
60248
|
-
spots.push(at);
|
|
60249
|
-
return spots;
|
|
60250
|
-
}
|
|
60251
|
-
/**
|
|
60252
60778
|
* Builds the Pixi objects of one run, bottom first: an icon is one sprite, and a glyph run is its
|
|
60253
|
-
* shadow when
|
|
60779
|
+
* shadow when its look has one, its outline and synthetic bold rings, then the glyphs.
|
|
60254
60780
|
*
|
|
60255
60781
|
* @param ctx - Domain context of the text plugin.
|
|
60256
60782
|
* @param pixi - The Pixi module the renderer loaded.
|
|
60257
60783
|
* @param run - The run to draw.
|
|
60258
|
-
* @param style - The
|
|
60784
|
+
* @param style - The look of the run.
|
|
60259
60785
|
* @param at - Where the run starts, in the local space of the block.
|
|
60260
60786
|
* @returns The display objects in drawing order.
|
|
60261
60787
|
*/
|
|
@@ -60282,53 +60808,143 @@ function isOutsideLayout(ctx, style, value) {
|
|
|
60282
60808
|
return (value.box ?? 0) <= 0 && value.resolved !== "" && !ctx.state.laidOut.has(value.style);
|
|
60283
60809
|
}
|
|
60284
60810
|
/**
|
|
60285
|
-
* The style
|
|
60286
|
-
*
|
|
60287
|
-
*
|
|
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).
|
|
60288
60814
|
*
|
|
60289
60815
|
* @param ctx - Domain context of the text plugin.
|
|
60290
60816
|
* @param value - The component value.
|
|
60291
|
-
* @returns
|
|
60817
|
+
* @returns The style.
|
|
60292
60818
|
*/
|
|
60293
|
-
function
|
|
60819
|
+
function drawnStyleOf(ctx, value) {
|
|
60294
60820
|
const style = styleOf$1(ctx, value.style);
|
|
60295
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) {
|
|
60296
60834
|
return {
|
|
60297
|
-
style,
|
|
60298
|
-
layout:
|
|
60299
|
-
generation: ctx.state.generation
|
|
60835
|
+
style: drawnStyleOf(ctx, value),
|
|
60836
|
+
layout: shownLayoutOf(ctx, entity, value),
|
|
60837
|
+
generation: ctx.state.generation,
|
|
60838
|
+
entity
|
|
60300
60839
|
};
|
|
60301
60840
|
}
|
|
60302
60841
|
/**
|
|
60303
|
-
*
|
|
60304
|
-
*
|
|
60305
|
-
*
|
|
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.
|
|
60306
60865
|
*
|
|
60307
60866
|
* @param ctx - Domain context of the text plugin.
|
|
60308
60867
|
* @param label - The style and the laid-out block.
|
|
60309
|
-
* @param
|
|
60310
|
-
* @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`.
|
|
60311
60871
|
*/
|
|
60312
|
-
function eachRun(ctx, label,
|
|
60872
|
+
function eachRun(ctx, label, value, visit) {
|
|
60313
60873
|
const { style, layout } = label;
|
|
60314
|
-
const
|
|
60315
|
-
const
|
|
60316
|
-
const
|
|
60317
|
-
const
|
|
60318
|
-
|
|
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;
|
|
60319
60881
|
for (const line of layout.lines) {
|
|
60320
|
-
let x = left + alignOffset(style,
|
|
60882
|
+
let x = left + alignOffset(style, width, line) + indent;
|
|
60321
60883
|
for (const run of line.runs) {
|
|
60322
|
-
|
|
60323
|
-
|
|
60324
|
-
|
|
60325
|
-
|
|
60326
|
-
|
|
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);
|
|
60327
60892
|
}
|
|
60328
|
-
|
|
60893
|
+
top += line.height;
|
|
60894
|
+
indent = 0;
|
|
60329
60895
|
}
|
|
60330
60896
|
}
|
|
60331
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
|
+
/**
|
|
60332
60948
|
* Fills a container with the objects of every run of the laid-out block, anchored by the
|
|
60333
60949
|
* component, and remembers what it was filled from. A shadow sits in the same container as its
|
|
60334
60950
|
* run, so it follows every update, reflow and destroy of it.
|
|
@@ -60340,40 +60956,122 @@ function eachRun(ctx, label, anchor, visit) {
|
|
|
60340
60956
|
* @param label - Its style and laid-out block.
|
|
60341
60957
|
*/
|
|
60342
60958
|
function fill(ctx, pixi, container, value, label) {
|
|
60343
|
-
|
|
60344
|
-
|
|
60345
|
-
|
|
60959
|
+
const cursor = openCursor(ctx, pixi, container);
|
|
60960
|
+
eachRun(ctx, label, value, fillRun);
|
|
60961
|
+
closeCursor(cursor);
|
|
60346
60962
|
ctx.state.drawn.set(container, label);
|
|
60347
60963
|
}
|
|
60348
60964
|
/**
|
|
60349
60965
|
* Tells whether two runs are drawn with the same objects: an icon of the same key, or glyphs with
|
|
60350
|
-
* the same bold, italic and colour. Only the text of a glyph run may
|
|
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.
|
|
60351
60968
|
*
|
|
60352
60969
|
* @param first - One run.
|
|
60353
60970
|
* @param second - The other, or nothing.
|
|
60354
60971
|
* @returns True when the objects of `first` can draw `second`.
|
|
60355
60972
|
*/
|
|
60356
60973
|
function sameObjects(first, second) {
|
|
60357
|
-
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;
|
|
60358
60975
|
if (first.kind === "icon") return second.kind === "icon" && first.key === second.key;
|
|
60359
60976
|
return second.kind === "text" && first.bold === second.bold && first.italic === second.italic && first.color === second.color;
|
|
60360
60977
|
}
|
|
60361
60978
|
/**
|
|
60362
|
-
* Tells whether two
|
|
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.
|
|
60363
60996
|
*
|
|
60364
60997
|
* @param drawn - The block the container was filled from.
|
|
60365
60998
|
* @param next - The block to draw now.
|
|
60366
60999
|
* @returns True when the objects of `drawn` can draw `next`.
|
|
60367
61000
|
*/
|
|
60368
61001
|
function sameShape(drawn, next) {
|
|
60369
|
-
|
|
60370
|
-
|
|
60371
|
-
|
|
60372
|
-
|
|
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);
|
|
60373
61070
|
}
|
|
60374
61071
|
/**
|
|
60375
61072
|
* Writes a new block into the objects already in the container, in the order `fill` added them:
|
|
60376
|
-
* 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.
|
|
60377
61075
|
*
|
|
60378
61076
|
* @param ctx - Domain context of the text plugin.
|
|
60379
61077
|
* @param pixi - The Pixi module the renderer loaded.
|
|
@@ -60382,24 +61080,9 @@ function sameShape(drawn, next) {
|
|
|
60382
61080
|
* @param label - Its style and laid-out block, of the same shape as the drawn one.
|
|
60383
61081
|
*/
|
|
60384
61082
|
function retext(ctx, pixi, container, value, label) {
|
|
60385
|
-
|
|
60386
|
-
eachRun(ctx, label, value
|
|
60387
|
-
|
|
60388
|
-
const sprite = container.getChildAt(index);
|
|
60389
|
-
sprite.texture = iconTexture(ctx, pixi, run);
|
|
60390
|
-
placeIcon(ctx, sprite, label.style, at);
|
|
60391
|
-
index += 1;
|
|
60392
|
-
return;
|
|
60393
|
-
}
|
|
60394
|
-
for (const spot of glyphSpots(label.style, run, at)) {
|
|
60395
|
-
const glyphs = container.getChildAt(index);
|
|
60396
|
-
glyphs.text = run.text;
|
|
60397
|
-
glyphs.x = spot.x;
|
|
60398
|
-
glyphs.y = spot.y;
|
|
60399
|
-
index += 1;
|
|
60400
|
-
}
|
|
60401
|
-
});
|
|
60402
|
-
ctx.state.drawn.set(container, label);
|
|
61083
|
+
const cursor = openCursor(ctx, pixi, container);
|
|
61084
|
+
eachRun(ctx, label, value, retextRun);
|
|
61085
|
+
closeCursor(cursor);
|
|
60403
61086
|
}
|
|
60404
61087
|
/**
|
|
60405
61088
|
* Tells whether two anchors are the same point.
|
|
@@ -60416,7 +61099,9 @@ function samePoint(first, second) {
|
|
|
60416
61099
|
* was last updated with, drawn with the style object that is current and under the generation
|
|
60417
61100
|
* that is current, and for a `"box"` style at the same box. A replaced style is a new object under
|
|
60418
61101
|
* the same name. A font or an icon a dev hot swap replaced moves the generation, because the
|
|
60419
|
-
* objects hold textures that are destroyed
|
|
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.
|
|
60420
61105
|
*
|
|
60421
61106
|
* @param ctx - Domain context of the text plugin.
|
|
60422
61107
|
* @param container - The container of this label.
|
|
@@ -60432,9 +61117,10 @@ function isCurrent(ctx, container, previous, next) {
|
|
|
60432
61117
|
/**
|
|
60433
61118
|
* Draws a changed value into a container that holds a label already. A ticking counter keeps its
|
|
60434
61119
|
* objects: with the same style object, the same generation, the same anchor and the same lines
|
|
60435
|
-
* and runs, the new text and spots are written into them
|
|
60436
|
-
*
|
|
60437
|
-
*
|
|
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.
|
|
60438
61124
|
*
|
|
60439
61125
|
* @param ctx - Domain context of the text plugin.
|
|
60440
61126
|
* @param pixi - The Pixi module the renderer loaded.
|
|
@@ -60444,16 +61130,24 @@ function isCurrent(ctx, container, previous, next) {
|
|
|
60444
61130
|
*/
|
|
60445
61131
|
function redraw(ctx, pixi, container, previous, next) {
|
|
60446
61132
|
const drawn = ctx.state.drawn.get(container);
|
|
60447
|
-
const
|
|
60448
|
-
|
|
60449
|
-
|
|
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);
|
|
60450
61139
|
return;
|
|
60451
61140
|
}
|
|
60452
61141
|
for (const child of container.removeChildren()) child.destroy({
|
|
60453
61142
|
children: true,
|
|
60454
61143
|
texture: false
|
|
60455
61144
|
});
|
|
60456
|
-
fill(ctx, pixi, container, next,
|
|
61145
|
+
fill(ctx, pixi, container, next, {
|
|
61146
|
+
style,
|
|
61147
|
+
layout,
|
|
61148
|
+
generation,
|
|
61149
|
+
entity: drawn?.entity
|
|
61150
|
+
});
|
|
60457
61151
|
}
|
|
60458
61152
|
/**
|
|
60459
61153
|
* How a `Text` becomes Pixi objects. The renderer parents, orders and frees the container like a
|
|
@@ -60467,12 +61161,12 @@ function redraw(ctx, pixi, container, previous, next) {
|
|
|
60467
61161
|
*/
|
|
60468
61162
|
function createTextAdapter(ctx) {
|
|
60469
61163
|
return {
|
|
60470
|
-
create: (value) => {
|
|
61164
|
+
create: (value, entity) => {
|
|
60471
61165
|
const pixi = ctx.deps.renderer.host.pixi();
|
|
60472
61166
|
if (pixi === void 0) return void 0;
|
|
60473
61167
|
const container = new pixi.Container();
|
|
60474
61168
|
container.alpha = value.alpha;
|
|
60475
|
-
fill(ctx, pixi, container, value, labelOf(ctx, value));
|
|
61169
|
+
fill(ctx, pixi, container, value, labelOf(ctx, value, entity));
|
|
60476
61170
|
return container;
|
|
60477
61171
|
},
|
|
60478
61172
|
update: (object, previous, next) => {
|
|
@@ -60535,7 +61229,8 @@ function resolveDeps$1(ctx) {
|
|
|
60535
61229
|
};
|
|
60536
61230
|
}
|
|
60537
61231
|
/**
|
|
60538
|
-
* 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.
|
|
60539
61234
|
*
|
|
60540
61235
|
* @param ctx - Kernel context of the text plugin.
|
|
60541
61236
|
* @returns The domain context of the text plugin.
|
|
@@ -60543,7 +61238,8 @@ function resolveDeps$1(ctx) {
|
|
|
60543
61238
|
function withDeps$1(ctx) {
|
|
60544
61239
|
return {
|
|
60545
61240
|
...ctx,
|
|
60546
|
-
deps: resolveDeps$1(ctx)
|
|
61241
|
+
deps: resolveDeps$1(ctx),
|
|
61242
|
+
layoutOptions: layoutOptionsOf(ctx)
|
|
60547
61243
|
};
|
|
60548
61244
|
}
|
|
60549
61245
|
/**
|
|
@@ -60556,6 +61252,20 @@ function isStyleMap(entry) {
|
|
|
60556
61252
|
return typeof entry === "object" && entry !== null && "kind" in entry && entry.kind === "textStyles" && "map" in entry && typeof entry.map === "object" && entry.map !== null;
|
|
60557
61253
|
}
|
|
60558
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
|
+
/**
|
|
60559
61269
|
* Fills the style table: the two built-ins first, then the styles of every feature in feature
|
|
60560
61270
|
* order. A feature may override a built-in; two features may not share a name.
|
|
60561
61271
|
*
|
|
@@ -60571,8 +61281,7 @@ function buildStyles(ctx) {
|
|
|
60571
61281
|
const entry = feature.description.textStyles;
|
|
60572
61282
|
if (!isStyleMap(entry)) continue;
|
|
60573
61283
|
for (const [name, value] of Object.entries(entry.map)) {
|
|
60574
|
-
|
|
60575
|
-
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);
|
|
60576
61285
|
const style = readStyle(name, value);
|
|
60577
61286
|
if (style === void 0) continue;
|
|
60578
61287
|
ctx.state.styles.set(name, style);
|
|
@@ -60581,6 +61290,16 @@ function buildStyles(ctx) {
|
|
|
60581
61290
|
}
|
|
60582
61291
|
}
|
|
60583
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
|
+
/**
|
|
60584
61303
|
* Tells whether a feature entry is a format map `text` can read.
|
|
60585
61304
|
*
|
|
60586
61305
|
* @param entry - What the feature put under its `textFormats` key.
|
|
@@ -60632,8 +61351,8 @@ function buildFormats(ctx) {
|
|
|
60632
61351
|
}
|
|
60633
61352
|
}
|
|
60634
61353
|
/**
|
|
60635
|
-
* Collects every font a style can draw with: the two of the config, then the regular, bold
|
|
60636
|
-
* 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.
|
|
60637
61356
|
*
|
|
60638
61357
|
* @param ctx - Domain context of the text plugin.
|
|
60639
61358
|
*/
|
|
@@ -60644,13 +61363,15 @@ function collectFonts(ctx) {
|
|
|
60644
61363
|
ctx.state.fontKeys.add(style.font);
|
|
60645
61364
|
if (style.bold !== void 0) ctx.state.fontKeys.add(style.bold);
|
|
60646
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);
|
|
60647
61367
|
}
|
|
60648
61368
|
}
|
|
60649
61369
|
/**
|
|
60650
61370
|
* Writes the styles of a saved styles file over the table: a known name keeps its owner, a new
|
|
60651
|
-
* name is added. Then the fonts of the new styles are read,
|
|
60652
|
-
* styles are dropped,
|
|
60653
|
-
*
|
|
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.
|
|
60654
61375
|
*
|
|
60655
61376
|
* @param ctx - Domain context of the text plugin.
|
|
60656
61377
|
* @param styles - What `defineTextStyles` returned in the saved module.
|
|
@@ -60662,9 +61383,11 @@ function replaceStyles(ctx, styles) {
|
|
|
60662
61383
|
ctx.state.styles.set(name, style);
|
|
60663
61384
|
if (!ctx.state.styleOwner.has(name)) ctx.state.styleOwner.set(name, HOT_SWAP);
|
|
60664
61385
|
}
|
|
61386
|
+
buildLooks(ctx.state);
|
|
60665
61387
|
collectFonts(ctx);
|
|
60666
61388
|
installFonts(ctx);
|
|
60667
|
-
ctx.state
|
|
61389
|
+
dropLayouts(ctx.state);
|
|
61390
|
+
ctx.state.generation += 1;
|
|
60668
61391
|
markDirty(ctx);
|
|
60669
61392
|
ctx.deps.time.wake();
|
|
60670
61393
|
}
|
|
@@ -60685,6 +61408,7 @@ function startText(ctx) {
|
|
|
60685
61408
|
const ecs = tctx.deps.world.ecs;
|
|
60686
61409
|
const frame = createTextFrame(tctx);
|
|
60687
61410
|
buildStyles(tctx);
|
|
61411
|
+
buildLooks(tctx.state);
|
|
60688
61412
|
buildFormats(tctx);
|
|
60689
61413
|
collectFonts(tctx);
|
|
60690
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) => {
|
|
@@ -60703,6 +61427,7 @@ function stopText(state) {
|
|
|
60703
61427
|
for (const off of state.removers) off();
|
|
60704
61428
|
state.removers.length = 0;
|
|
60705
61429
|
state.styles.clear();
|
|
61430
|
+
state.looks.clear();
|
|
60706
61431
|
state.styleOwner.clear();
|
|
60707
61432
|
state.formats.clear();
|
|
60708
61433
|
state.formatOwner.clear();
|
|
@@ -60712,7 +61437,9 @@ function stopText(state) {
|
|
|
60712
61437
|
state.seen.clear();
|
|
60713
61438
|
state.bindTypes.clear();
|
|
60714
61439
|
state.measured.clear();
|
|
60715
|
-
state
|
|
61440
|
+
dropLayouts(state);
|
|
61441
|
+
state.shown.clear();
|
|
61442
|
+
closeCursor(state.cursor);
|
|
60716
61443
|
state.dirty.clear();
|
|
60717
61444
|
state.added.length = 0;
|
|
60718
61445
|
state.rewrite.length = 0;
|
|
@@ -60819,7 +61546,7 @@ function createHandlers(ctx, reload) {
|
|
|
60819
61546
|
"i18n:locale-changed": (_payload) => {
|
|
60820
61547
|
const tctx = domain();
|
|
60821
61548
|
markDirty(tctx, (label) => typeof label.content !== "string");
|
|
60822
|
-
tctx.state
|
|
61549
|
+
dropLayouts(tctx.state);
|
|
60823
61550
|
tctx.deps.time.wake();
|
|
60824
61551
|
}
|
|
60825
61552
|
};
|
|
@@ -60859,6 +61586,7 @@ function emptyWeakMap() {
|
|
|
60859
61586
|
function createTextState$1() {
|
|
60860
61587
|
return {
|
|
60861
61588
|
styles: emptyMap$2(),
|
|
61589
|
+
looks: emptyMap$2(),
|
|
60862
61590
|
styleOwner: emptyMap$2(),
|
|
60863
61591
|
formats: emptyMap$2(),
|
|
60864
61592
|
formatOwner: emptyMap$2(),
|
|
@@ -60869,6 +61597,15 @@ function createTextState$1() {
|
|
|
60869
61597
|
bindTypes: emptyMap$2(),
|
|
60870
61598
|
measured: emptyMap$2(),
|
|
60871
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(),
|
|
60872
61609
|
drawn: emptyWeakMap(),
|
|
60873
61610
|
dirty: emptySet$1(),
|
|
60874
61611
|
added: [],
|
|
@@ -61222,6 +61959,10 @@ function rectOfTargets(ctx, to) {
|
|
|
61222
61959
|
//#endregion
|
|
61223
61960
|
//#region src/plugins/ui/jsx/field-layout.ts
|
|
61224
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
|
+
/**
|
|
61225
61966
|
* The four edges of a resolved padding.
|
|
61226
61967
|
*
|
|
61227
61968
|
* @param padding - One number for every edge, the edges a style names, or nothing.
|
|
@@ -61449,6 +62190,18 @@ function insetOf(viewport) {
|
|
|
61449
62190
|
function liftOf(input) {
|
|
61450
62191
|
return Math.max(0, input.fieldBottom + input.margin - (input.innerHeight - input.inset));
|
|
61451
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;
|
|
61452
62205
|
/** A high surrogate: the first half of a character outside the Basic Multilingual Plane. */
|
|
61453
62206
|
const OPEN_SURROGATE = /[\uD800-\uDBFF]$/;
|
|
61454
62207
|
/**
|
|
@@ -61979,6 +62732,8 @@ const KINDS = [
|
|
|
61979
62732
|
const PLACEHOLDER_ALPHA = .5;
|
|
61980
62733
|
/** The separator between the inputs of a field's fingerprint. */
|
|
61981
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 = "-";
|
|
61982
62737
|
/**
|
|
61983
62738
|
* Reads the props of an `input` tag.
|
|
61984
62739
|
*
|
|
@@ -62098,7 +62853,8 @@ function boxPart(box, fill, alpha) {
|
|
|
62098
62853
|
* The component values of the four parts of a laid-out field.
|
|
62099
62854
|
*
|
|
62100
62855
|
* @param layout - Where the parts go.
|
|
62101
|
-
* @param content - What the text part draws: the value, or the placeholder at half
|
|
62856
|
+
* @param content - What the text part draws: the value as plain text, or the placeholder at half
|
|
62857
|
+
* alpha.
|
|
62102
62858
|
* @param textStyle - The text style of the field.
|
|
62103
62859
|
* @param look - The caret, selection and underline look of the config.
|
|
62104
62860
|
* @returns The values, per part.
|
|
@@ -62117,6 +62873,33 @@ function partValues(layout, content, textStyle, look) {
|
|
|
62117
62873
|
};
|
|
62118
62874
|
}
|
|
62119
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
|
+
/**
|
|
62120
62903
|
* A cheap fingerprint of what a field is laid out from: the selection and the composing range
|
|
62121
62904
|
* while it is edited, the box, the padding, the text style, the placeholder and the value. The
|
|
62122
62905
|
* value goes last, so no character of it can shift another input.
|
|
@@ -62129,9 +62912,9 @@ function partValues(layout, content, textStyle, look) {
|
|
|
62129
62912
|
* @returns The fingerprint.
|
|
62130
62913
|
*/
|
|
62131
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}`;
|
|
62132
62917
|
const pad = paddingOf(element.style.padding);
|
|
62133
|
-
const selection = mirror === void 0 ? "-" : `${mirror.selectionStart},${mirror.selectionEnd},${mirror.direction}`;
|
|
62134
|
-
const range = composing === void 0 ? "-" : `${composing.start},${composing.end}`;
|
|
62135
62918
|
const box = `${element.rect.w},${element.rect.h},${pad.top},${pad.right},${pad.bottom},${pad.left}`;
|
|
62136
62919
|
const placeholder = JSON.stringify(field.placeholder ?? "");
|
|
62137
62920
|
return [
|
|
@@ -62484,7 +63267,7 @@ function createFields(ctx, links) {
|
|
|
62484
63267
|
lineHeight: measure("").height,
|
|
62485
63268
|
caretWidth: look.caretWidth,
|
|
62486
63269
|
underline: look.composingUnderline,
|
|
62487
|
-
prefix: (piece) => measure(piece).width,
|
|
63270
|
+
prefix: (piece) => measure(literalText(piece)).width,
|
|
62488
63271
|
hasGlyph: (char) => ctx.deps.text.hasGlyph(char, field.textStyle)
|
|
62489
63272
|
});
|
|
62490
63273
|
}
|
|
@@ -62499,7 +63282,7 @@ function createFields(ctx, links) {
|
|
|
62499
63282
|
*/
|
|
62500
63283
|
function drawField(field, layout, value, inputs) {
|
|
62501
63284
|
const look = ctx.config.textInput;
|
|
62502
|
-
const content = layout.content === "placeholder" ? field.placeholder ?? "" : value;
|
|
63285
|
+
const content = layout.content === "placeholder" ? field.placeholder ?? "" : literalText(value);
|
|
62503
63286
|
const values = partValues(layout, content, field.textStyle, look);
|
|
62504
63287
|
const drawn = JSON.stringify({
|
|
62505
63288
|
layout,
|
|
@@ -62583,24 +63366,10 @@ function createFields(ctx, links) {
|
|
|
62583
63366
|
return;
|
|
62584
63367
|
}
|
|
62585
63368
|
const viewport = ctx.deps.renderer.viewport;
|
|
62586
|
-
const
|
|
62587
|
-
const topLeft = viewport.toScreen({
|
|
62588
|
-
x: drawn.x,
|
|
62589
|
-
y: drawn.y
|
|
62590
|
-
});
|
|
62591
|
-
const bottomRight = viewport.toScreen({
|
|
62592
|
-
x: drawn.x + drawn.w,
|
|
62593
|
-
y: drawn.y + drawn.h
|
|
62594
|
-
});
|
|
62595
|
-
const rect = {
|
|
62596
|
-
x: topLeft.x,
|
|
62597
|
-
y: topLeft.y,
|
|
62598
|
-
w: bottomRight.x - topLeft.x,
|
|
62599
|
-
h: bottomRight.y - topLeft.y
|
|
62600
|
-
};
|
|
63369
|
+
const { rect, bottom } = screenRectOf(viewport, rootRectOf(ctx, state, field, lookup));
|
|
62601
63370
|
const keyboard = text.keyboard;
|
|
62602
63371
|
keyboard.lift = keyboard.inset <= 0 ? 0 : liftOf({
|
|
62603
|
-
fieldBottom:
|
|
63372
|
+
fieldBottom: bottom,
|
|
62604
63373
|
margin: ctx.config.textInput.keyboardMargin,
|
|
62605
63374
|
innerHeight: keyboard.innerHeight,
|
|
62606
63375
|
inset: keyboard.inset
|