narraleaf-react 0.33.1 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -410,6 +410,14 @@ export type GameConfig = {
410
410
  */
411
411
  guard: GuardConfig;
412
412
  };
413
+ /**
414
+ * Turn off text scaling for the whole game.
415
+ *
416
+ * Dialogue text is kept inside its box by being set down as it is typed. Turning this on
417
+ * leaves every line at the size it was written at, and a line longer than its box overflows it.
418
+ * @default false
419
+ */
420
+ disableTextScaling: boolean;
413
421
  /**
414
422
  * Override the default stage
415
423
  * @default null
@@ -36,6 +36,29 @@ export type TextAppearanceProps = {
36
36
  * @default true
37
37
  */
38
38
  tateChuYoko?: TateChuYoko;
39
+ /**
40
+ * Keep the line inside the box it is placed in by setting it down as it is typed.
41
+ *
42
+ * The line is set at `fontSize` and stays there for as long as it fits, so a short line is
43
+ * never set small. Once the text reaches the end of the box, every further character is
44
+ * measured and the size comes down by what it takes to fit, to no less than
45
+ * {@link autoFitMinFontSize}. A line that still overflows at that size is left overflowing.
46
+ *
47
+ * Sizes carried by the sentence or by a single word are scaled with the line rather than
48
+ * replaced, so their relative weights hold at any size, and a run set larger or smaller inside
49
+ * the line is accounted for by having been drawn rather than by being predicted.
50
+ *
51
+ * The box is the container's parent, which needs a size of its own for anything to be fitted
52
+ * to. {@link GameConfig.disableTextScaling} turns this off for the whole game.
53
+ * @default true
54
+ */
55
+ autoFit?: boolean;
56
+ /**
57
+ * The smallest size text scaling sets, in px. A line that still overflows at it is left
58
+ * overflowing.
59
+ * @default 12
60
+ */
61
+ autoFitMinFontSize?: number;
39
62
  };
40
63
  export type BaseTextsProps = TextAppearanceProps & {
41
64
  className?: string;
@@ -0,0 +1,49 @@
1
+ import React from "react";
2
+ /** Smallest size text scaling sets when the line does not say otherwise. */
3
+ export declare const DEFAULT_AUTO_FIT_MIN_FONT_SIZE = 12;
4
+ /**
5
+ * The multiplier every size in the line is written against.
6
+ *
7
+ * One custom property drives the container and every word inside it, so a candidate size is one
8
+ * write rather than a walk over the elements, and a word that carries a size of its own keeps its
9
+ * weight against the rest of the line at every scale.
10
+ */
11
+ export declare const AUTO_FIT_SCALE_VAR = "--nl-text-scale";
12
+ export declare const AUTO_FIT_SCALE_MULTIPLIER = "var(--nl-text-scale, 1)";
13
+ /** The same length, scaled by the line's current multiplier, whatever unit it was written in. */
14
+ export declare function scaledFontSize(value: React.CSSProperties["fontSize"]): React.CSSProperties["fontSize"];
15
+ /** What the line is set at when it inherits its size: the inherited size, scaled. */
16
+ export declare function inheritedScaledFontSize(): React.CSSProperties["fontSize"];
17
+ export type AutoFitOptions = {
18
+ enabled: boolean;
19
+ /** The floor, in px. A line that overflows at this size is left overflowing rather than set smaller. */
20
+ minFontSize: number;
21
+ /** Vertical writing swaps the axes: the columns advance across the box, not down it. */
22
+ vertical: boolean;
23
+ /**
24
+ * What has been typed so far. The line is measured again every time this changes, which is what
25
+ * makes the size follow the text rather than a guess made before it existed.
26
+ */
27
+ revealed: number;
28
+ };
29
+ export type AutoFitState = {
30
+ containerRef: React.MutableRefObject<HTMLDivElement | null>;
31
+ /** The share of the authored size the line is currently set at. */
32
+ scale: number;
33
+ };
34
+ /**
35
+ * Keeps a line inside its box while it is being typed.
36
+ *
37
+ * The line is set at the size it was written at and stays there for as long as it fits, so a short
38
+ * line is never set small "just in case". The moment the text reaches the bottom of the box, the
39
+ * next character brings the size down by whatever it takes to fit, and every character after it is
40
+ * measured again. So the size follows what is actually on screen: a run of larger or smaller words
41
+ * inside the line is accounted for by having been rendered, not by being predicted.
42
+ *
43
+ * Within one line the size only ever comes down, since the text only ever grows. A change in the
44
+ * size of the box starts the line over at its authored size.
45
+ *
46
+ * The box is the container's parent, which is the element the host sized. A parent with no height
47
+ * of its own leaves the line at its authored size.
48
+ */
49
+ export declare function useAutoFitScale({ enabled, minFontSize, vertical, revealed }: AutoFitOptions): AutoFitState;