narraleaf-react 0.34.0 → 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
@@ -37,18 +37,25 @@ export type TextAppearanceProps = {
37
37
  */
38
38
  tateChuYoko?: TateChuYoko;
39
39
  /**
40
- * Set the line down until the whole of it fits the box it is placed in.
40
+ * Keep the line inside the box it is placed in by setting it down as it is typed.
41
41
  *
42
- * `fontSize` becomes a ceiling rather than a fixed size: the line is set at it whenever the
43
- * finished line fits, and smaller when it does not, down to {@link autoFitMinFontSize}. Sizes
44
- * carried by the sentence or by a single word scale with it, so their relative weights hold.
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.
45
46
  *
46
- * The box is the container's parent, which needs a size of its own for anything to be fitted to.
47
- * @default false
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
48
54
  */
49
55
  autoFit?: boolean;
50
56
  /**
51
- * The smallest size auto fit sets, in px. A line that still overflows at it is left overflowing.
57
+ * The smallest size text scaling sets, in px. A line that still overflows at it is left
58
+ * overflowing.
52
59
  * @default 12
53
60
  */
54
61
  autoFitMinFontSize?: number;
@@ -1,43 +1,49 @@
1
1
  import React from "react";
2
- /** Smallest size auto fit sets when the line does not say otherwise. */
2
+ /** Smallest size text scaling sets when the line does not say otherwise. */
3
3
  export declare const DEFAULT_AUTO_FIT_MIN_FONT_SIZE = 12;
4
- /** Set on the measuring copy so every explicit word size scales with one write. */
5
- export declare const AUTO_FIT_SCALE_VAR = "--nl-auto-fit-scale";
6
4
  /**
7
- * The same length, scaled, whatever unit it was written in.
5
+ * The multiplier every size in the line is written against.
8
6
  *
9
- * The multiplier is a number for the line on screen and the scale custom property for the copy
10
- * being measured, where one write has to resize every word at once.
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.
11
10
  */
12
- export declare function scaledFontSize(value: React.CSSProperties["fontSize"], scale: number | string): React.CSSProperties["fontSize"];
13
- /** The multiplier the measuring copy scales by, readable from every word inside it. */
14
- export declare const AUTO_FIT_SCALE_MULTIPLIER = "var(--nl-auto-fit-scale, 1)";
15
- /** What the line is set at when it inherits its size: a share of the size it inherits. */
16
- export declare function inheritedScaledFontSize(scale: number): React.CSSProperties["fontSize"] | undefined;
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
17
  export type AutoFitOptions = {
18
18
  enabled: boolean;
19
19
  /** The floor, in px. A line that overflows at this size is left overflowing rather than set smaller. */
20
20
  minFontSize: number;
21
21
  /** Vertical writing swaps the axes: the columns advance across the box, not down it. */
22
22
  vertical: boolean;
23
- /** Everything that changes the laid-out result without changing the box. */
24
- signature: string;
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;
25
28
  };
26
29
  export type AutoFitState = {
27
30
  containerRef: React.MutableRefObject<HTMLDivElement | null>;
28
- mirrorRef: React.MutableRefObject<HTMLDivElement | null>;
29
- /** The share of the authored size the line is set at. */
31
+ /** The share of the authored size the line is currently set at. */
30
32
  scale: number;
31
33
  };
32
34
  /**
33
- * Finds the largest size at which a whole line still fits the box it is placed in.
35
+ * Keeps a line inside its box while it is being typed.
34
36
  *
35
- * The line being typed is not what has to fit - the finished line is - so the search runs against a
36
- * hidden copy holding every word, laid out under the same box, the same typeface and the same
37
- * wrapping rules. The copy is what the bisection resizes; the visible line is set once, when the
38
- * answer is known, and stays there for the rest of the line.
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.
39
42
  *
40
- * The box is the container's parent: a dialog box has a size of its own, and the line is what has
41
- * to live inside it. A parent with no height of its own leaves the scale at 1.
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.
42
48
  */
43
- export declare function useAutoFitScale({ enabled, minFontSize, vertical, signature }: AutoFitOptions): AutoFitState;
49
+ export declare function useAutoFitScale({ enabled, minFontSize, vertical, revealed }: AutoFitOptions): AutoFitState;