narraleaf-react 0.42.3 → 0.43.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.
@@ -11,7 +11,18 @@ export type BlindsOrientation = "horizontal" | "vertical";
11
11
  export declare function clamp01(value: number): number;
12
12
  /** The `mask-image` triplet, mirrored to the `-webkit-` prefix for WebKit. */
13
13
  export declare function maskStyle(image: string, size?: string, repeat?: string): CSSProps;
14
- /** Full-bleed positioning for a synthetic colour overlay layer. */
14
+ /**
15
+ * Full-bleed positioning for a synthetic colour overlay layer.
16
+ *
17
+ * The box reaches {@link OVERLAY_BLEED} past the frame on every side. The stage scales by a
18
+ * non-integer factor, so the images this covers are laid out at fractional sizes and the browser
19
+ * draws their outermost row of pixels with partial coverage; a colour box that matches the frame
20
+ * exactly stops at the whole pixel inside that row and leaves it showing, as a hairline of the
21
+ * picture along the top or the bottom edge. For a fade *through* a colour - which is meant to
22
+ * reach a frame of solid colour and hand the images over behind it - that hairline is the one
23
+ * thing the frame must not have. The layer is synthetic and has no content to distort, so
24
+ * growing it costs nothing.
25
+ */
15
26
  export declare function overlayBase(color: string): CSSProps;
16
27
  /** CSS gradient direction keyword for a wipe travelling toward `direction`. */
17
28
  export declare function wipeGradientDir(direction: TransformDefinitions.WipeDirection): string;
@@ -433,6 +433,22 @@ export type GameConfig = {
433
433
  * @default false
434
434
  */
435
435
  disableTextScaling: boolean;
436
+ /**
437
+ * How long a newly typed character takes to fade in, in milliseconds. `0` turns it off.
438
+ *
439
+ * Dialogue text is normally typed at full strength, one character appearing after another. With
440
+ * a duration here, each character arrives faded and comes up over that time while the typewriter
441
+ * carries on, so the few newest characters of a line are always part-way in and the line has a
442
+ * soft edge rather than a hard one.
443
+ *
444
+ * The fade never outlasts the gap between two characters by more than a little: a player who
445
+ * raises the typing speed gets a shorter fade, and one who raises it a long way gets none worth
446
+ * seeing, which is what asking for fast text means. It applies only to text actually being typed
447
+ * - a line revealed at once, skipped, or drawn again from a save is not faded in - and a player
448
+ * whose system asks for reduced motion never sees it.
449
+ * @default 0
450
+ */
451
+ textRevealDuration: number;
436
452
  /**
437
453
  * Override the default stage
438
454
  * @default null
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Text reveal: the soft edge of the typewriter.
3
+ *
4
+ * With it on, a character does not appear at full strength — it fades in over a moment while the
5
+ * typewriter moves on, so a few of the newest characters are always part-way in. The effect is
6
+ * driven entirely by the typewriter's own cadence: a character's fade starts when its element is
7
+ * mounted and runs as a one-shot CSS animation, so nothing here schedules anything.
8
+ *
9
+ * Two numbers come out of this module, and both exist to keep that cheap:
10
+ *
11
+ * - the duration a fade actually runs for, which is the authored one brought down to what fits
12
+ * between characters. A fade may last at most {@link MAX_REVEAL_INTERVALS} character intervals,
13
+ * so raising the typing speed shortens it rather than piling up half-lit characters;
14
+ * - how many of the most recently revealed characters are still fading, which is how many of them
15
+ * have to be elements of their own. Everything before that is settled text and is drawn as it
16
+ * always was — one text node — so the line's markup is bounded whatever its length.
17
+ *
18
+ * The count carries one character of margin past the fade's own length, so a character is always
19
+ * finished fading before it is folded back into the settled text and its element goes away. Losing
20
+ * that margin is what a half-lit character snapping to full looks like.
21
+ */
22
+ /**
23
+ * The longest a fade may run, counted in the gap between two characters.
24
+ *
25
+ * It bounds two things at once: how many characters can be fading at any moment (and so how many
26
+ * extra elements a line carries), and how far behind the typewriter the soft edge can trail before
27
+ * it stops reading as the same line being typed.
28
+ */
29
+ export declare const MAX_REVEAL_INTERVALS = 8;
30
+ /** The custom property the container writes the fade's length to. */
31
+ export declare const REVEAL_DURATION_VAR = "--nl-reveal-duration";
32
+ /**
33
+ * The class a still-fading character carries.
34
+ *
35
+ * The animation is declared in the engine's stylesheet against this class rather than written into
36
+ * each element's `style`: an inline animation shorthand that changed between two renders would be
37
+ * a new animation on an element that is already running one, and the character would start over.
38
+ * Reading the length from a custom property on the container leaves every character's own style
39
+ * untouched for as long as it lives.
40
+ */
41
+ export declare const REVEAL_CLASS_NAME = "__narraleaf_text_reveal";
42
+ export type RevealTiming = {
43
+ /** How long one character's fade runs, in ms. `0` when nothing fades. */
44
+ duration: number;
45
+ /** How many of the most recently revealed characters are still fading. `0` when nothing does. */
46
+ inFlight: number;
47
+ };
48
+ /**
49
+ * What the authored duration comes to at the speed the line is actually being typed at.
50
+ *
51
+ * @param authored the game's `textRevealDuration`, in ms
52
+ * @param cps characters per second, from the player's preferences
53
+ * @param gameSpeed the speed multiplier, from the player's preferences
54
+ */
55
+ export declare function resolveRevealTiming(authored: number | undefined, cps: number, gameSpeed: number): RevealTiming;
56
+ /**
57
+ * How many of a word's trailing characters are still fading.
58
+ *
59
+ * The fading characters are the last few of the *line*, so a word only holds some of them, and a
60
+ * word the typewriter has long passed holds none. `offset` is where the word starts in the line,
61
+ * counted the way the line counts its own revealed characters.
62
+ */
63
+ export declare function revealTailFor(timing: RevealTiming, offset: number, length: number, revealed: number): number;
@@ -68,9 +68,25 @@ export declare function segmentVerticalText(text: string, maxLength: number): Ve
68
68
  */
69
69
  export declare function wordBreakStyleFor(): React.CSSProperties;
70
70
  /**
71
- * Renders a word's text with its short runs set upright.
71
+ * The smallest pieces of a word that may fade in on their own.
72
72
  *
73
- * Returns the string itself when nothing would be combined, so horizontal text - and vertical text
74
- * with no Latin in it - is one text node, exactly as before.
73
+ * A character each, except where the text has already been combined: a tate-chu-yoko run is one
74
+ * glyph cluster set across the column and has to arrive as one, or it would be laid on its side for
75
+ * as long as its halves were fading separately. Characters are taken by code point rather than by
76
+ * code unit so a surrogate pair is never cut in half.
75
77
  */
76
- export declare function renderWordText(text: string, vertical: boolean, tateChuYoko: TateChuYoko | undefined): React.ReactNode;
78
+ export declare function revealAtoms(segments: VerticalTextSegment[]): VerticalTextSegment[];
79
+ /**
80
+ * Renders a word's text with its short runs set upright, and its newest characters still fading.
81
+ *
82
+ * Returns the string itself when nothing would be combined and nothing is fading, so horizontal
83
+ * text - and vertical text with no Latin in it - is one text node, exactly as before.
84
+ *
85
+ * `revealTail` is how many of the word's trailing characters are still fading. Each of those gets
86
+ * an element of its own so that mounting it starts its animation; everything before them is one
87
+ * settled run again, which is what keeps the markup of a long line from growing with it. The
88
+ * elements are `display: inline` - which they are by default, and which is the whole reason this
89
+ * splits at all: an `inline-block` per character would let the line break between any two of them
90
+ * and take a Latin word apart. Nothing here may be given a transform for the same reason.
91
+ */
92
+ export declare function renderWordText(text: string, vertical: boolean, tateChuYoko: TateChuYoko | undefined, revealTail?: number): React.ReactNode;