narraleaf-react 0.34.0 → 0.36.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.
@@ -9,6 +9,17 @@ export type DarknessOptions = {
9
9
  to: number;
10
10
  /** Duration in milliseconds. */
11
11
  duration: number;
12
+ /**
13
+ * Time held at `from` before the brightness starts moving, in milliseconds, taken out of
14
+ * `duration`. `{from: 1, to: 0, duration: 3000, holdMs: 2000}` is two seconds of black and
15
+ * then a one-second lift out of it.
16
+ *
17
+ * The hold sits at `from` and not at `to` because `from` is where the image swap happens -
18
+ * the incoming frame is already on screen at the very first tick. That makes this the same
19
+ * thing {@link ThroughColor} and {@link Exposure} call a hold: the window the swap hides in.
20
+ * @default 0
21
+ */
22
+ holdMs?: number;
12
23
  easing?: TransformDefinitions.EasingDefinition;
13
24
  };
14
25
  /**
@@ -18,11 +29,24 @@ export type DarknessOptions = {
18
29
  *
19
30
  * This is what backs `image.darken(amount, duration)` — darkening an image in
20
31
  * place is expressed as a transition from its current darkness to the new one.
32
+ *
33
+ * ⚠ The brightness is only worn for as long as the transition runs. What a
34
+ * settled element looks like is the element's own business — an image renders at
35
+ * `Image.state.darkness`, a scene root at nothing at all — so a run ending at a
36
+ * `to` above zero snaps back to full brightness on its last frame unless
37
+ * something else is holding that darkness. Ending dark is what a black
38
+ * background (or {@link ThroughColor} with no uncover) is for; this is a way
39
+ * *through* a darkness, not a way to sit in one.
40
+ *
41
+ * The channel is a linear 0-1 progress and the easing is applied by hand, so
42
+ * that {@link DarknessOptions.holdMs} can be real time rather than a share of an
43
+ * eased curve.
21
44
  */
22
45
  export declare class Darkness extends ImageTransition<AnimationType> {
23
46
  private from;
24
47
  private to;
25
48
  private duration;
49
+ private holdMs;
26
50
  private easing?;
27
51
  constructor(options: DarknessOptions);
28
52
  createTask(): TransitionTask<HTMLImageElement, AnimationType>;
@@ -20,7 +20,20 @@ export type ExposureOptions = {
20
20
  * carries the shadows up without touching the frame at rest. @default 0.04
21
21
  */
22
22
  lift?: number;
23
- /** Fraction (0–1) of the duration spent fully blown out. @default 0 */
23
+ /**
24
+ * Time spent fully blown out, in milliseconds, taken out of `duration` and split evenly off
25
+ * the burn and the cool-down. `{duration: 3000, holdMs: 1500}` burns for 750ms, holds white
26
+ * for a second and a half, and comes back down over the last 750ms.
27
+ *
28
+ * Real time, not a share of an eased curve - see {@link ThroughColor} for why the run is
29
+ * linear. @default 0
30
+ */
31
+ holdMs?: number;
32
+ /**
33
+ * Fraction (0–1) of the duration spent fully blown out.
34
+ * @default 0
35
+ * @deprecated Use {@link holdMs}. Read only when `holdMs` is absent.
36
+ */
24
37
  hold?: number;
25
38
  easing?: TransformDefinitions.EasingDefinition;
26
39
  };
@@ -44,6 +57,7 @@ export declare class Exposure extends ImageTransition<AnimationType> {
44
57
  private ev;
45
58
  private lift;
46
59
  private hold;
60
+ private holdMs;
47
61
  private easing?;
48
62
  constructor(options: ExposureOptions);
49
63
  /**
@@ -18,7 +18,22 @@ export type ThroughColorOptions = {
18
18
  duration: number;
19
19
  /** Hold colour. @default "#000000" */
20
20
  color?: string;
21
- /** Fraction (0–1) of the duration spent fully covered by the colour. @default 0.3 */
21
+ /**
22
+ * Time spent fully covered by the colour, in milliseconds, taken out of `duration` and split
23
+ * evenly off the cover and uncover halves. `{duration: 4000, holdMs: 2000}` is one second in,
24
+ * two seconds of solid colour, one second out.
25
+ *
26
+ * Real time, not a share of an eased curve: see {@link ThroughColor} on why the run is linear.
27
+ * @default 0.3 × duration
28
+ */
29
+ holdMs?: number;
30
+ /**
31
+ * Fraction (0–1) of the duration spent fully covered by the colour.
32
+ * @default 0.3
33
+ * @deprecated Use {@link holdMs}. A fraction cannot say how long the colour is actually held:
34
+ * it is a share of the run, so the seconds it buys move whenever the duration does. Read only
35
+ * when `holdMs` is absent.
36
+ */
22
37
  hold?: number;
23
38
  /**
24
39
  * The coverage geometry the colour covers the frame through. See
@@ -44,14 +59,22 @@ export type ThroughColorOptions = {
44
59
  *
45
60
  * The geometry lives entirely in the `pattern` option (see {@link Mask});
46
61
  * without one, the colour simply fades in and out (fade-to-black/white, or a
47
- * flash with `hold: 0`). {@link Reveal} is the direct-cut counterpart that
62
+ * flash with `holdMs: 0`). {@link Reveal} is the direct-cut counterpart that
48
63
  * takes the same patterns. The `uncover` option picks how the second half
49
64
  * plays: see {@link ThroughColorUncover}.
65
+ *
66
+ * The animation channel is deliberately **linear** and the easing is applied to
67
+ * each moving half by hand. Easing the whole run would make the hold a band of
68
+ * *progress* rather than of time, and every eased curve crosses the middle at
69
+ * its fastest: under the driver's default `easeInOut` a nominal 30% hold plays
70
+ * as 17.8% of the wall clock. `holdMs` can only mean milliseconds because of
71
+ * this - see `heldRunCurve`.
50
72
  */
51
73
  export declare class ThroughColor extends ImageTransition<AnimationType> {
52
74
  private duration;
53
75
  private color;
54
76
  private hold;
77
+ private holdMs;
55
78
  private pattern;
56
79
  private inverted;
57
80
  private uncover;
@@ -17,3 +17,50 @@ export declare function overlayBase(color: string): CSSProps;
17
17
  export declare function wipeGradientDir(direction: TransformDefinitions.WipeDirection): string;
18
18
  /** Gradient axis for blinds slats of a given orientation. */
19
19
  export declare function blindsAxis(orientation: BlindsOrientation): string;
20
+ /**
21
+ * The curve an {@link TransformDefinitions.EasingDefinition} names, as a plain function.
22
+ *
23
+ * A transition that carves a *held* segment out of its run cannot let the animation driver ease the
24
+ * whole 0-1 progress: the hold would then be a band of eased progress rather than of wall-clock
25
+ * time, and an eased curve crosses the middle - exactly where the hold sits - at its fastest. Such
26
+ * a transition asks the driver for a linear channel and eases each moving half itself, which is
27
+ * what this resolves the curve for.
28
+ *
29
+ * The fallback is `easeInOut` and not `linear`, because that is what the driver applies when no
30
+ * ease is given (motion's keyframes generator defaults to it): a transition easing its own halves
31
+ * has to land on the same feel as one that does not.
32
+ */
33
+ export declare function resolveEasing(ease?: TransformDefinitions.EasingDefinition): (t: number) => number;
34
+ /**
35
+ * How far a cover -> hold -> uncover run has travelled at a given point of a LINEAR run: `0` is
36
+ * untouched, `1` is at the extreme (fully covered by the colour, fully blown out). Shared by
37
+ * {@link ThroughColor} and {@link Exposure}, which differ only in what they do with the number.
38
+ *
39
+ * The hold is wall-clock time, carved out of `duration` and split evenly off the two moving halves,
40
+ * so `holdMs: 2000` on a 4s run is two seconds at the extreme with a second either side. That is
41
+ * only true because the run itself is linear and the easing is applied to each half here. Eased as
42
+ * a whole - which is what asking the driver for an eased channel does - the hold is a band of
43
+ * *progress* instead, and the curve crosses it at its fastest: under the default `easeInOut` a
44
+ * nominal 30% hold plays as 17.8% of the wall clock, and 50% as 30.8%.
45
+ *
46
+ * `hold`, the fraction of the duration, is the older spelling and is read only when `holdMs` is
47
+ * absent.
48
+ */
49
+ export declare function heldRunCurve(options: {
50
+ duration: number;
51
+ hold?: number;
52
+ holdMs?: number;
53
+ easing?: TransformDefinitions.EasingDefinition;
54
+ }): (progress: number) => number;
55
+ /**
56
+ * The share of a run spent held at the extreme: `holdMs` measured against the duration, or the
57
+ * legacy `hold` fraction when no absolute time is given.
58
+ *
59
+ * A zero-length run has no share to measure, so any positive hold takes all of it - the transition
60
+ * is then a cut to the extreme and back, which is what a zero duration asks for.
61
+ */
62
+ export declare function holdFraction(options: {
63
+ duration: number;
64
+ hold?: number;
65
+ holdMs?: number;
66
+ }): number;
@@ -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;